diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e76209142070..356fa5b0c404 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -220,12 +220,12 @@ jobs: with: python-version: "3.13" - # Pillow draws the frames. The fonts are for the three locales Nunito cannot - # set - hindi, japanese and chinese - which frame-screenshots.py refuses to + # storeframe draws the frames. The fonts are for the three locales Nunito cannot + # set - hindi, japanese and chinese - which storeframe refuses to # draw as tofu, so a runner without them fails rather than shipping squares. - name: python and fonts run: | - python3 -m pip install --quiet Pillow + python3 -m pip install --quiet -r scripts/requirements.txt sudo apt-get update -qq sudo apt-get install -y -qq fonts-noto-core fonts-noto-cjk diff --git a/README.md b/README.md index 21423ca485ba..4f6912d4a8be 100644 --- a/README.md +++ b/README.md @@ -172,10 +172,11 @@ The release run takes the store screenshots from the build it ships. Nothing is Six screens on a phone and a tablet in fifteen locales, plus a feature graphic per locale drawn from the first screenshot. The tablet set fills both tablet slots. -To take them by hand you need one emulator on adb running **Android 15 or newer** and Pillow: +To take them by hand you need one emulator on adb running **Android 15 or newer** and +[storeframe](https://github.com/andiwand/storeframe): ```sh -python3 -m pip install Pillow +python3 -m pip install -r scripts/requirements.txt bundle exec fastlane android screenshots # every locale, phone ODR_SCREENSHOT_DEVICE=tablet bundle exec fastlane android screenshots ODR_SCREENSHOT_LANGUAGES=en-US,de-DE bundle exec fastlane android screenshots @@ -183,8 +184,9 @@ ODR_SCREENSHOT_LANGUAGES=en-US,de-DE bundle exec fastlane android screenshots `ANDROID_SERIAL` picks the device when several are attached. Raw captures land in `fastlane/screenshots/`, the framed set and feature graphics in `fastlane/framed/`. Running -`scripts/frame-screenshots.py` alone re-frames the captures, so a changed headline in -`fastlane/frames/frames.json` costs seconds. Below API 35 the status bar has a white clock on +`python3 -m storeframe frame fastlane/frames/frames.json --platform android --captured +fastlane/screenshots --out fastlane/framed --feature-graphic` alone re-frames the captures, +so a changed headline in `fastlane/frames/frames.json` costs seconds. Below API 35 the status bar has a white clock on a white bar, so `ScreenshotTests` refuses to run there. `hi-IN`, `ja-JP` and `zh-CN` are set in a system font. On Debian install `fonts-noto-core` diff --git a/app/src/androidTest/java/app/opendocument/droid/test/ScreenshotTests.kt b/app/src/androidTest/java/app/opendocument/droid/test/ScreenshotTests.kt index c10e13d9e14c..cc19277afa96 100644 --- a/app/src/androidTest/java/app/opendocument/droid/test/ScreenshotTests.kt +++ b/app/src/androidTest/java/app/opendocument/droid/test/ScreenshotTests.kt @@ -63,8 +63,8 @@ import org.junit.runner.RunWith * The pictures the play store shows. * * Six screens, in every locale the listing is written in, on whichever device the runner is - * driving. The edit is taken twice, the second time as lite shows it - see [editing]. - * `scripts/frame-screenshots.py` then frames what this writes and `scripts/store_screenshots.py` + * driving. The edit is taken twice, the second time as lite shows it - see [editing]. storeframe + * (`scripts/requirements.txt`) then frames what this writes and `scripts/store_screenshots.py` * checks the set and stages it for supply - the names below are the names those expect, and their * order is the order the store shows them in. * diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 6fd4ed5063c3..93445c097a17 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -33,7 +33,8 @@ SCREENSHOT_DIR = File.join(ROOT, "fastlane", "screenshots").freeze FRAMED_DIR = File.join(ROOT, "fastlane", "framed").freeze MAKE_DOCUMENTS = File.join(ROOT, "scripts", "make-screenshot-documents.py").freeze -FRAME_SCREENSHOTS = File.join(ROOT, "scripts", "frame-screenshots.py").freeze +# The design storeframe frames the captures with (scripts/requirements.txt). +FRAMES_DESIGN = File.join(ROOT, "fastlane", "frames", "frames.json").freeze STORE_SCREENSHOTS = File.join(ROOT, "scripts", "store_screenshots.py").freeze # The devices the store keeps a set for. The name is written into every file the @@ -370,10 +371,11 @@ platform :android do UI.message("took #{taken.length} screenshots") # A raw capture is not what the store shows. The framing is separate from the - # photography so that changing a headline costs a second of Pillow rather than - # a quarter hour of emulators - rerun this script alone after an edit to - # fastlane/frames/frames.json. - sh("python3", FRAME_SCREENSHOTS) + # photography so that changing a headline costs seconds of storeframe rather + # than a quarter hour of emulators - rerun this step alone (see README.md) + # after an edit to fastlane/frames/frames.json. + sh("python3", "-m", "storeframe", "frame", FRAMES_DESIGN, "--platform", "android", + "--captured", SCREENSHOT_DIR, "--out", FRAMED_DIR, "--feature-graphic") # what came out is what the store would be given, so it is checked here rather # than at upload time on the other side of the run diff --git a/fastlane/frames/Nunito[wght].ttf b/fastlane/frames/Nunito[wght].ttf deleted file mode 100644 index 2ec1f4b0676c..000000000000 Binary files a/fastlane/frames/Nunito[wght].ttf and /dev/null differ diff --git a/fastlane/frames/OFL.txt b/fastlane/frames/OFL.txt deleted file mode 100644 index c8210f08ca3c..000000000000 --- a/fastlane/frames/OFL.txt +++ /dev/null @@ -1,93 +0,0 @@ -Copyright 2014 The Nunito Project Authors (https://github.com/googlefonts/nunito) - -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/fastlane/frames/frames.json b/fastlane/frames/frames.json index b906b266d729..ae82b20ed594 100644 --- a/fastlane/frames/frames.json +++ b/fastlane/frames/frames.json @@ -1,7 +1,8 @@ { "_comment": [ "What the play store pictures show, and what they say in every language.", - "scripts/frame-screenshots.py draws them; see that file for the geometry.", + "storeframe (scripts/requirements.txt) draws them, in its tabs style; see", + "https://github.com/andiwand/storeframe for the geometry.", "", "One entry per screen, in the order the store shows them, named as the", "screenshot test writes them. `headline` is two lines: the first is set", @@ -10,9 +11,8 @@ "", "Fifteen locales, the ones scripts/store-listing.py names. Nunito sets", "eleven of them; hi-IN, ja-JP and zh-CN are set in a system font, which is", - "the one thing frame-screenshots.py needs that is not in this directory." + "the one thing storeframe needs that does not come with it." ], - "font": "Nunito[wght].ttf", "backgrounds": { "orange": [ "#f4b663", @@ -248,6 +248,7 @@ }, { "name": "04-edit", + "aliases": ["04-edit-lite"], "background": "blue", "chips": [ "odt" diff --git a/scripts/frame-screenshots.py b/scripts/frame-screenshots.py deleted file mode 100755 index f5c661efc0a5..000000000000 --- a/scripts/frame-screenshots.py +++ /dev/null @@ -1,885 +0,0 @@ -#!/usr/bin/env python3 -# Frame app captures and generate localized Play feature graphics. - -import argparse -import bisect -import functools -import json -import math -import shutil -import sys -from pathlib import Path - -import store_screenshots as store - -try: - from PIL import Image, ImageChops, ImageDraw, ImageFilter, ImageFont -except ImportError: - sys.exit("this needs Pillow: python3 -m pip install Pillow") - -ROOT = Path(__file__).resolve().parent.parent -FRAMES = ROOT / "fastlane" / "frames" -CAPTURED = ROOT / "fastlane" / "screenshots" -FRAMED = ROOT / "fastlane" / "framed" - -# The design, as fractions of the canvas rather than pixels, so that one canvas -# size becomes another and the same numbers describe both devices. -# -# How far down something sits is a fraction of the height; how big it is, and -# how far across, is a fraction of the width. So a taller canvas gives -# everything more room without stretching any of it. -# -# The canvas is a size of our own rather than the capture's: play refuses a -# screenshot whose long side is more than twice its short one, and a Pixel 9 Pro -# XL is 1344x2992 - 2.23:1 - before anything is drawn around it. -# `store_screenshots.CANVASES` is what the picture comes out as; the capture is a -# picture inside it, which leaves the device room to fit whole rather than be -# cropped past the buttons the app puts in the bottom right corner. -LAYOUT = { - "phone": { - "headline_top": 0.048, - "headline_size": 0.058, # before it is shrunk to fit - "headline_width": 0.86, # what it is shrunk to fit inside - "headline_leading": 1.06, - "screen_left": 0.308, - "screen_top": 0.200, - "screen_width": 0.600, # as wide as it may be; `foot` is the other limit - "foot": 0.036, # ground left under the device, of the height - # A Pixel 9 Pro XL, from its published dimensions: a 1344px screen at - # 486ppi is 70.2mm across a 76.6mm body, which leaves 3.2mm of aluminium - # and black border on every side - half again what an iPhone carries - - # and the display corner is a good deal tighter than Apple's. - "bezel": 0.0268, # screen edge to the outside of the body - # Of that, less than half is the black mask and the rest is the polished - # frame. Which way round this sits is most of whether the drawing reads - # as a current phone. - "rim": 0.42, # how much of the bezel is the black border - "corner": 0.122, # screen corner, of the screen's width - "corner_easing": 2.2, # near a circular arc - see squircle() - "hole": 0.046, # the front camera, of the screen's width - "hole_top": 0.028, - # Nothing at all on the left edge: a Pixel keeps both its keys on the - # right, and the tray is what the left carries - low on the edge, where - # the device has it. - "buttons": [], - "tray": (0.620, 0.075), # how far down the body, how long - # The power key and the volume rocker, on the right edge: (how far down - # the body, how long), both of the body's height. - "buttons_right": [(0.175, 0.055), (0.250, 0.105)], - "chip_top": 0.430, - "chip_size": (0.230, 0.140), - "chip_step": 0.157, - "chip_text": 0.107, - "dash_stroke": 0.0056, - "dash_on": 0.0236, - "dash_off": 0.0098, - # The line crossing every screen: each picture takes it in at the height - # the one before let it out at and hands it on, so no two screens carry - # the same line and the gallery still reads as one. One height per seam, - # which is one more than there are screens, and every one of them in the - # band between the foot of the headline and the top of the device - the - # only band that is neither written on nor covered up. - "seams": [0.148, 0.176, 0.158, 0.180, 0.152, 0.172, 0.164], - # What the line does between the two seams it has to join. "in" is the - # height it arrived at and "out" the one it has to leave at; anything - # else is a height of its own. One step each, at a different place, and - # two of them dip a little way down first - only the left quarter is - # free below the band, the device covers the rest, and a dip has to come - # back up left of the body's edge (0.255 here) or it goes behind the - # device and never comes out. - "routes": [ - [(0.34, "in"), (0.34, "out")], - [(0.17, "in"), (0.17, "out")], - [(0.52, "in"), (0.52, "out")], - [(0.10, "in"), (0.10, 0.245), (0.21, 0.245), (0.21, "out")], - [(0.26, "in"), (0.26, "out"), (0.60, "out")], - [(0.13, "in"), (0.13, 0.235), (0.23, 0.235), (0.23, "out")], - ], - "radii": [0.078, 0.066, 0.086, 0.062, 0.072, 0.070], - # The lower line: in from off the canvas, around a corner and out again. - # Points are (x, y) in canvas fractions and a point past 1 is off the - # edge on purpose. A y of "chips" hangs the line off the top of the tabs - # so it runs behind however many there are and comes out underneath - - # anchored to a number, a screen with one tab starts it in mid air, so a - # screen with no tabs takes one of the routes that does not need them. - "decorations": [ - [("chips", "chips"), ("chips", 0.930), (0.55, 0.930)], - [(-0.2, 0.700), (0.155, 0.700), (0.155, 0.930), (0.62, 0.930)], - [("chips", "chips"), ("chips", 0.880), (-0.2, 0.880)], - [(-0.2, 0.845), (0.185, 0.845), (0.185, 0.640), (0.58, 0.640)], - ], - }, - "tablet": { - "headline_top": 0.060, - "headline_size": 0.052, - "headline_width": 0.80, - "headline_leading": 1.06, - "screen_left": 0.235, - "screen_top": 0.240, - "screen_width": 0.700, - "foot": 0.036, - "corner_easing": 2.2, - # A Pixel Tablet: a 2560px screen at 276mm of body leaves about 14.5mm - # of border on every side - four times the phone's, and the thing anyone - # who has held one would name first. Its display corners are rounder - # than a phone's are relative to the screen, and its keys are on the edge - # that becomes the top in portrait, which this frame does not show. No - # sim tray either: it is a wifi tablet. - "bezel": 0.0470, - # the other way round from the phone: a tablet's border really is mostly - # black mask, with the frame a thin bright edge outside it - "rim": 0.86, - "corner": 0.030, - "buttons": [], - "chip_top": 0.430, - "chip_size": (0.170, 0.0900), - "chip_step": 0.1010, - "chip_text": 0.080, - "dash_stroke": 0.0040, - "dash_on": 0.0147, - "dash_off": 0.0061, - "seams": [0.152, 0.186, 0.166, 0.192, 0.156, 0.180, 0.170], - "routes": [ - [(0.30, "in"), (0.30, "out")], - [(0.115, "in"), (0.115, "out")], - [(0.46, "in"), (0.46, "out")], - [(0.06, "in"), (0.06, 0.250), (0.15, 0.250), (0.15, "out")], - [(0.20, "in"), (0.20, "out"), (0.54, "out")], - [(0.08, "in"), (0.08, 0.240), (0.16, 0.240), (0.16, "out")], - ], - "radii": [0.060, 0.052, 0.068, 0.050, 0.056, 0.054], - "decorations": [ - [("chips", "chips"), ("chips", 0.930), (0.52, 0.930)], - [(-0.2, 0.620), (0.105, 0.620), (0.105, 0.930), (0.58, 0.930)], - [("chips", "chips"), ("chips", 0.880), (-0.2, 0.880)], - [(-0.2, 0.810), (0.125, 0.810), (0.125, 0.520), (0.54, 0.520)], - ], - }, -} - -# What the phone is, as opposed to where it stands: the parts of a layout that -# describe the device itself and read the same on any canvas, because each is a -# fraction of the screen or of the body rather than of the picture. -DEVICE_PARTS = ("rim", "corner", "corner_easing", "hole", "hole_top", - "buttons", "buttons_right", "tray") - -# The feature graphic, which is not a screenshot: one picture per locale, above -# the listing rather than in the gallery, and landscape where every other picture -# here stands up. So it is laid out rather than fitted - the phone to the right of -# the copy instead of below it - out of the same parts, and drawn from the first -# screenshot's capture so that it says what the app looks like today. -FEATURE = { - **{key: LAYOUT["phone"][key] for key in DEVICE_PARTS}, - "headline_top": 0.105, - "headline_size": 0.046, - "headline_width": 0.42, - "headline_leading": 1.18, - "headline_middle": 0.315, # the copy has its own column, left of the phone - "screen_left": 0.700, - "screen_top": 0.100, - "screen_width": 0.175, - "foot": 0.070, - "chip_top": 0.470, - "chip_size": (0.140, 0.070), - "chip_step": 0.080, - "chip_text": 0.041, - "dash_stroke": 0.0040, - "dash_on": 0.0166, - "dash_off": 0.0069, - # The one line, drawn once rather than handed on: there is no next picture to - # hand it to. In from the left between the copy and the tabs, down the gap - # the copy leaves before the phone, and out along the foot - behind the - # device, which is drawn over it, and out the other side. - "decoration": [(-0.2, 0.395), (0.600, 0.395), (0.600, 0.900), (1.2, 0.900)], - "radius": 0.040, -} - -# The bezel is the one number of the phone's that cannot simply be carried over: -# it is a fraction of the canvas' width, and the phone is less than a third as wide -# across this canvas as it is across a screenshot's, so the phone's own would draw -# a border three times too fat. Scaled with the device instead, and derived rather -# than written down, so that a phone made bigger here keeps its own proportions. -FEATURE["bezel"] = ( - LAYOUT["phone"]["bezel"] * FEATURE["screen_width"] / LAYOUT["phone"]["screen_width"] -) - -# The device, which is drawn rather than photographed. The rim is read across the -# body's width: bright where the edge turns towards the light, dark on the flat. -BODY = "#08080a" -# How warm the frame is, as a multiplier per channel: a Pixel's aluminium is a -# warm grey. Small on purpose - past about a twentieth it stops being aluminium -# and starts being gold. -ALUMINIUM = (1.035, 1.0, 0.955) -# The metal the keys wear. They read as a step in the edge rather than as marks -# on it, which is what they are. -BUTTON = ("#d8d8d6", "#a9a9a7", "#c4c4c2") -# The sim tray, which is a seam rather than a key: the same metal, a shade darker -# so it reads as a line cut into the edge instead of one standing off it. -TRAY = ("#9a9a98", "#7c7c7a", "#909090") -GLASS = 96 # how brightly the screen's edge catches the light, of 255 - -# The shadow the device casts. Black rather than a colour of its own, which was -# mixed for the green ground and went muddy on the orange one, and offset down -# and right instead of sitting square behind the body, where the body covers it. -SHADOW = (0, 0, 0, 105) -SHADOW_OFFSET = (0.30, 0.65) # of the bezel, across and down -SHADOW_BLUR = 0.85 # of the bezel - - -@functools.lru_cache(maxsize=None) -def design(): - text = json.loads((FRAMES / "frames.json").read_text()) - text.pop("_comment", None) - return text - - -# The scripts Nunito cannot set, and where to find one that can. -# -# Nunito covers Latin and Cyrillic, which is eleven of the fifteen locales. It -# has no Devanagari and no CJK, and a font that has them is ten to sixteen -# megabytes per language - not something to put in a git history when every -# machine that runs this is an apt-get away from one. So these three are looked -# for on the system, and a machine without one is told what to install rather -# than handed a headline full of tofu. -# -# A candidate is (regular, bold, marker). The marker picks a face out of a .ttc -# by family name: the Noto collections hold every CJK language at once and which -# index is which is not fixed, so it is searched for rather than counted to. -NOTO_CJK = "/usr/share/fonts/opentype/noto/NotoSansCJK-%s.ttc" - -# The last resort on a mac: Hiragino Sans and PingFang are downloadable rather than -# installed, so a machine that never asked for them has neither at a fixed path, while -# this one has been in /Library/Fonts since forever. One weight only, so the second -# headline line comes out light - a picture to look at, not one to ship. -ARIAL_UNICODE = "/Library/Fonts/Arial Unicode.ttf" - -SCRIPTS = { - "devanagari": ( - "fonts-noto-core on debian, or Devanagari Sangam MN on macos", - [ - ("/usr/share/fonts/truetype/noto/NotoSansDevanagari-Regular.ttf", - "/usr/share/fonts/truetype/noto/NotoSansDevanagari-Bold.ttf", None), - ("/System/Library/Fonts/Supplemental/Devanagari Sangam MN.ttc", - "/System/Library/Fonts/Supplemental/Devanagari Sangam MN.ttc", None), - ("/System/Library/Fonts/Kohinoor.ttc", "/System/Library/Fonts/Kohinoor.ttc", None), - ], - ), - "japanese": ( - "fonts-noto-cjk on debian, or Hiragino Sans on macos", - [ - (NOTO_CJK % "Regular", NOTO_CJK % "Bold", "JP"), - ("/System/Library/Fonts/Hiragino Sans W4.ttc", - "/System/Library/Fonts/Hiragino Sans W7.ttc", None), - (ARIAL_UNICODE, ARIAL_UNICODE, None), - ], - ), - "chinese": ( - "fonts-noto-cjk on debian, or PingFang on macos", - [ - (NOTO_CJK % "Regular", NOTO_CJK % "Bold", "SC"), - ("/System/Library/Fonts/PingFang.ttc", "/System/Library/Fonts/PingFang.ttc", "SC"), - ("/System/Library/Fonts/Hiragino Sans GB.ttc", - "/System/Library/Fonts/Hiragino Sans GB.ttc", None), - (ARIAL_UNICODE, ARIAL_UNICODE, None), - ], - ), -} - -# The locales written in one of them. Everything else is Nunito. -WRITTEN_IN = {"hi-IN": "devanagari", "ja-JP": "japanese", "zh-CN": "chinese"} - -# What the feature graphic is drawn from: the phone's first screen, which is the -# app's landing screen and already carries the line the listing opens with. So -# there is no copy of its own to write, and none to translate fifteen times. -FEATURE_FROM = f"phone-{store.SCREENS[0]}" - - -def face_in(path, size, marker): - """One face of a font file, picked out of a collection by family name. - - A .ttc holds several faces and the order is the font's business, not ours - - so the index is searched for. Without a marker the first face is the file's - own answer to what it is. - """ - if marker is None: - return ImageFont.truetype(path, size) - - for index in range(12): - try: - found = ImageFont.truetype(path, size, index=index) - except (OSError, ValueError): - break - if marker in "".join(part or "" for part in found.getname()): - return found - - raise OSError(f"{path} holds no {marker} face") - - -@functools.lru_cache(maxsize=None) -def font(size, weight, locale=None): - """The headline font at one weight, in the script the language is written in. - - Nunito ships as a single variable file these days, so both weights come out - of it by name; a system font is two files, or one that has only the weight it - has, which is why a missing variation is not an error. - """ - script = WRITTEN_IN.get(locale) - if script is None: - found = ImageFont.truetype(str(FRAMES / design()["font"]), size) - else: - wanted, candidates = SCRIPTS[script] - found = None - for regular, bold, marker in candidates: - path = bold if weight == "Bold" else regular - if not Path(path).exists(): - continue - try: - found = face_in(path, size, marker) - break - except OSError: - continue - - if found is None: - raise SystemExit( - f"nothing on this machine can set {script}, which {locale}'s headline " - f"is written in. Install {wanted}." - ) - - try: - found.set_variation_by_name(weight) - except (OSError, ValueError): - # not a variable font: it is already the weight its file says it is - pass - - return found - - -def gradient(size, top, bottom): - """The ground: the same colour top to bottom, a little darker at the foot.""" - width, height = size - strip = Image.new("RGB", (1, height)) - start = Image.new("RGB", (1, 1), top).getpixel((0, 0)) - end = Image.new("RGB", (1, 1), bottom).getpixel((0, 0)) - for y in range(height): - share = y / max(1, height - 1) - strip.putpixel((0, y), tuple(round(start[i] + (end[i] - start[i]) * share) for i in range(3))) - - return strip.resize((width, height)).convert("RGBA") - - -def rounded_path(points, radius, per_corner=24): - """A polyline with its corners rounded off, as points to walk along.""" - walk = [points[0]] - for before, corner, after in zip(points, points[1:], points[2:]): - into = math.hypot(corner[0] - before[0], corner[1] - before[1]) - out = math.hypot(after[0] - corner[0], after[1] - corner[1]) - r = min(radius, into / 2, out / 2) - start = (corner[0] + (before[0] - corner[0]) * r / into, - corner[1] + (before[1] - corner[1]) * r / into) - end = (corner[0] + (after[0] - corner[0]) * r / out, - corner[1] + (after[1] - corner[1]) * r / out) - walk.append(start) - for i in range(1, per_corner): - t = i / per_corner - # one quadratic bend, with the corner itself as the control point - walk.append(( - (1 - t) ** 2 * start[0] + 2 * (1 - t) * t * corner[0] + t ** 2 * end[0], - (1 - t) ** 2 * start[1] + 2 * (1 - t) * t * corner[1] + t ** 2 * end[1], - )) - walk.append(end) - walk.append(points[-1]) - - return walk - - -def dashed(canvas, points, stroke, on, off, colour=(255, 255, 255, 255), phase=0.0): - """Lays dashes along a path, so a dash carries on around a corner. - - Counted out from the start of the path rather than accumulated as it walks, - because a step that rounds to nothing next to a distance already travelled - is a step that never arrives. - """ - reached = [0.0] - for before, after in zip(points, points[1:]): - reached.append(reached[-1] + math.hypot(after[0] - before[0], after[1] - before[1])) - total = reached[-1] - if not total: - return - - def at(distance): - """The point that far along the path.""" - index = max(1, min(len(reached) - 1, bisect.bisect_left(reached, distance))) - span = reached[index] - reached[index - 1] - share = 0.0 if not span else (distance - reached[index - 1]) / span - before, after = points[index - 1], points[index] - - return (before[0] + (after[0] - before[0]) * share, - before[1] + (after[1] - before[1]) * share) - - draw = ImageDraw.Draw(canvas) - width = max(1, round(stroke)) - - period = on + off - phase = phase % period - for number in range(int((total + phase) // period) + 2): - start = number * period - phase - end = min(start + on, total) - if start >= total: - break - start = max(start, 0.0) - if start >= end: - continue - - # the path's own corners inside this dash, so a dash that lands on a - # bend is drawn bent rather than as a chord across it - run = [at(start)] - run += [point for point, so_far in zip(points, reached) if start < so_far < end] - run.append(at(end)) - draw.line(run, fill=colour, width=width, joint="curve") - - -def squircle(box, radius, exponent=2.2, per_corner=40): - """A rounded rectangle whose corners are superellipse quadrants. - - The exponent is what shape of phone this is, and the difference is not - subtle at this size: a continuous curve, easing into the straight edge, takes - around 5 and is an iPhone corner. A Pixel's is near enough a circular arc, - which is 2 - 2.2 here, since a touch of easing is what the glass does where - it meets the frame and an exact circle reads as a render. - """ - x0, y0, x1, y1 = box - r = min(radius, (x1 - x0) / 2, (y1 - y0) / 2) - points = [] - - # each corner as (centre, x sign, y sign), going clockwise from bottom right. - # Two of the four are walked backwards, so that every quadrant leaves off - # where the next one starts and the outline closes. - for (cx, cy), sx, sy in (((x1 - r, y1 - r), 1, 1), ((x0 + r, y1 - r), -1, 1), - ((x0 + r, y0 + r), -1, -1), ((x1 - r, y0 + r), 1, -1)): - for step in range(per_corner + 1): - share = step / per_corner if sx * sy > 0 else 1 - step / per_corner - angle = math.pi / 2 * share - points.append(( - cx + sx * r * math.cos(angle) ** (2 / exponent), - cy + sy * r * math.sin(angle) ** (2 / exponent), - )) - - return points - - -def outset(points, distance): - """The same outline, moved out by a fixed distance along its own normals. - - A squircle grown by raising its radius is not parallel to the one it grew - from - the gap opens up around the corner and closes down the sides - so a - bezel drawn that way is visibly fatter at the corners. - """ - walked = list(zip(points, points[1:] + points[:1])) - facing = 1.0 if sum(x0 * y1 - x1 * y0 for (x0, y0), (x1, y1) in walked) > 0 else -1.0 - moved = [] - - for index, (x, y) in enumerate(points): - (ax, ay), (bx, by) = points[index - 1], points[(index + 1) % len(points)] - run, rise = bx - ax, by - ay - length = math.hypot(run, rise) or 1.0 - moved.append((x + facing * rise / length * distance, y - facing * run / length * distance)) - - return moved - - -def stencil(size, points, supersample=3): - """An antialiased mask of one shape. Pillow's polygon has hard edges, so it - is drawn large and shrunk, which is cheaper than it sounds on a mask.""" - big = Image.new("L", (size[0] * supersample, size[1] * supersample), 0) - ImageDraw.Draw(big).polygon([(x * supersample, y * supersample) for x, y in points], fill=255) - - return big.resize(size, Image.LANCZOS) - - -def chamfer(share): - """The metal's colour that far across the band, outside edge to black. - - A Pixel Pro's frame is polished aluminium: a narrow specular right at the - outer edge, a hard drop behind it, a weaker sheen where the flat turns down - to the glass, and dark where it meets the black surround. Brushed metal - one - broad highlight two thirds of the way in - is somebody else's phone, and a - flat fill is a grey stripe. - """ - stops = ((0.00, 150), (0.10, 240), (0.22, 208), (0.42, 138), (0.66, 192), (0.85, 164), (1.00, 96)) - place = bisect.bisect_right([at for at, _ in stops], share) - if place == 0: - level = stops[0][1] - elif place == len(stops): - level = stops[-1][1] - else: - (before, low), (after, high) = stops[place - 1], stops[place] - level = low + (high - low) * (share - before) / (after - before) - - return tuple(min(255, round(level * warm)) for warm in ALUMINIUM) - - -def brushed(size, colours): - """The rim: a metal that catches the light differently across its width.""" - width, height = size - strip = Image.new("RGB", (len(colours), 1)) - for index, colour in enumerate(colours): - strip.putpixel((index, 0), Image.new("RGB", (1, 1), colour).getpixel((0, 0))) - - return strip.resize((width, height), Image.BICUBIC) - - -def crossing(layout, order, size): - """The line this screen hands on: in at one height, out at the next.""" - width, height = size - seams = layout["seams"] - enters = seams[order % len(seams)] * height - leaves = seams[(order + 1) % len(seams)] * height - route = layout["routes"][order % len(layout["routes"])] - - def down(y): - return enters if y == "in" else leaves if y == "out" else y * height - - return ( - [(-0.2 * width, enters)] - + [(x * width, down(y)) for x, y in route] - + [(1.2 * width, leaves)] - ) - - -def walked(points): - """How far a path runs, so the next one can pick the dashes up.""" - return sum( - math.hypot(after[0] - before[0], after[1] - before[1]) - for before, after in zip(points, points[1:]) - ) - - -def device_body(canvas, shot, layout): - """The device: the capture behind glass, in a metal body. - - Drawn rather than pasted from a mockup, so it is the shape of whatever was - captured - a downloaded frame is the wrong shape for the next device. - - Built in its own image and composited once, so the parts can be masked - against each other without the ground showing through the seams. - """ - width, height = canvas.size - bezel = layout["bezel"] * width # screen edge to the outside of the body - rim = bezel * layout["rim"] # how much of that is metal - - left, top = layout["screen_left"] * width, layout["screen_top"] * height - - # Two limits rather than one fraction: `screen_width` is as wide as it may - # be, and `foot` is how much ground has to be left under it. Sized by the - # fraction alone, a device a little taller than the one the number was picked - # for runs its bottom rim off the canvas and a shorter one leaves a stripe of - # ground - neither of which is a decision anybody made. - standing = (height - layout["foot"] * height) - top - bezel - screen_width = min(layout["screen_width"] * width, standing * shot.width / shot.height) - screen_height = screen_width * shot.height / shot.width - - screen = (left, top, left + screen_width, top + screen_height) - corner = layout["corner"] * screen_width - - body = (screen[0] - bezel, screen[1] - bezel, screen[2] + bezel, screen[3] + bezel) - - # its own canvas, with room either side for the keys that stand proud - margin = round(bezel * 3) - origin = (round(body[0]) - margin, round(body[1]) - margin) - size = (round(body[2]) - origin[0] + margin, round(body[3]) - origin[1] + margin) - here = lambda box: tuple(v - origin[i % 2] for i, v in enumerate(box)) - - device = Image.new("RGBA", size, (0, 0, 0, 0)) - - # the buttons first, so the body's own edge covers where they meet it - stand = screen_width * 0.0061 # how far a key stands proud, about 2.7pt - tall_as = body[3] - body[1] - - def along(edge, keys, proud): - marks = Image.new("L", size, 0) - draw = ImageDraw.Draw(marks) - for at_height, tall in keys: - y = here(body)[1] + tall_as * at_height - draw.rounded_rectangle((edge - proud, y, edge + proud, y + tall_as * tall), - radius=proud * 0.55, fill=255) - - return marks - - keys = Image.new("L", size, 0) - for edge, side in ((here(body)[0], layout["buttons"]), - (here(body)[2], layout.get("buttons_right", []))): - keys = ImageChops.lighter(keys, along(edge, side, stand)) - device.paste(brushed(size, BUTTON), (0, 0), keys) - - # The sim tray, which sits flush rather than proud - it is a seam in the edge, - # so it is drawn narrower and darker than a key and does not stand off the body - if layout.get("tray"): - device.paste( - brushed(size, TRAY), - (0, 0), - along(here(body)[0], [layout["tray"]], stand * 0.45), - ) - - # Every edge is the screen's own outline moved out, so the black border and - # the metal around it are the same width the whole way round - which is what - # they are on the device, and not what a bigger squircle would give. - face = squircle(here(screen), corner, layout["corner_easing"]) - outline = outset(face, bezel) - - # The metal, lit across the band's own width rather than the body's: the - # band is filled as rings, each the colour ``chamfer`` gives for how far in - # it sits, so the highlight follows the edge the whole way round. - band = bezel - rim - lit = Image.new("RGB", size, chamfer(1.0)) - rings = ImageDraw.Draw(lit) - steps = max(8, round(band)) - for step in range(steps + 1): - share = step / steps - rings.polygon(outset(face, bezel - band * share), fill=chamfer(share)) - - device.paste(lit, (0, 0), stencil(size, outline)) - - # the black surround the glass sits in, and then the glass - device.paste(Image.new("RGB", size, BODY), (0, 0), stencil(size, outset(face, rim))) - - fitted = shot.resize((round(screen_width), round(screen_height)), Image.LANCZOS).convert("RGBA") - inside = here(screen) - device.paste(fitted, (round(inside[0]), round(inside[1])), - stencil(size, face).crop( - (round(inside[0]), round(inside[1]), - round(inside[0]) + fitted.width, round(inside[1]) + fitted.height))) - - # The hairline where the glass meets the surround, which a real device - # catches the light along. Without it a screen that is dark at the top runs - # into the black bezel and the two read as one fat border. - hair = max(1.0, screen_width * 0.0012) - halo = ImageChops.subtract( - stencil(size, face), stencil(size, outset(face, -hair)) - ).point(lambda level: level * GLASS // 255) - device.paste(Image.new("RGB", size, "white"), (0, 0), halo) - - # The hole the front camera sits in, in the gap the status bar leaves for - # it. A circle rather than a pill, which is a Pixel and not an iPhone. - if layout.get("hole"): - across = layout["hole"] * screen_width - middle = (inside[0] + inside[2]) / 2 - hole_top = inside[1] + layout["hole_top"] * screen_width - ImageDraw.Draw(device).ellipse( - (middle - across / 2, hole_top, middle + across / 2, hole_top + across), fill=BODY - ) - - shadow = Image.new("RGBA", size, (0, 0, 0, 0)) - shadow.paste(Image.new("RGB", size, SHADOW[:3]), (0, 0), - stencil(size, outline).point(lambda v: v * SHADOW[3] // 255)) - canvas.alpha_composite( - shadow.filter(ImageFilter.GaussianBlur(bezel * SHADOW_BLUR)), - (origin[0] + round(bezel * SHADOW_OFFSET[0]), origin[1] + round(bezel * SHADOW_OFFSET[1]))) - canvas.alpha_composite(device, origin) - - -def headline(canvas, lines, layout, locale): - """Two lines, light over bold, centred and shrunk until they fit. - - Fitted rather than set at a fixed size because the same sentence is a third - longer in German than in English, and a line that runs off the picture is - worse than one set a little smaller. - """ - width, height = canvas.size - size = round(layout["headline_size"] * width) - allowed = layout["headline_width"] * width - weights = ("Regular", "Bold") - draw = ImageDraw.Draw(canvas) - - faces = [font(size, weight, locale) for weight in weights] - while size > 8: - if max(draw.textlength(line, font=face) for line, face in zip(lines, faces)) <= allowed: - break - size -= 2 - faces = [font(size, weight, locale) for weight in weights] - - leading = size * layout["headline_leading"] - middle = layout.get("headline_middle", 0.5) * width - y = layout["headline_top"] * height - for line, face in zip(lines, faces): - draw.text((middle, y), line, font=face, fill="white", anchor="ma") - y += leading - - -def chips(canvas, names, palette, layout): - """The odt/ods/odp tabs, running off the left edge as the design has them.""" - width, height = canvas.size - least, chip_height = (share * width for share in layout["chip_size"]) - face = font(round(layout["chip_text"] * width), "Bold") - draw = ImageDraw.Draw(canvas) - - # As wide as the longest word in the whole design needs, and no narrower - # than the design's own tab: measured across every format rather than the - # two or three on this screen, so the tabs are one length through the - # gallery rather than stepping in and out as the reader swipes. - padding = layout["chip_text"] * width * 0.42 - chip_width = max([least] + [draw.textlength(name, font=face) + 2 * padding for name in palette]) - - for index, name in enumerate(names): - top = layout["chip_top"] * height + layout["chip_step"] * width * index - draw.rectangle((-2, top, chip_width, top + chip_height), fill=palette[name]) - draw.text((chip_width / 2, top + chip_height / 2), name, font=face, fill="white", anchor="mm") - - return chip_width - - -def frame(shot, device, screen, locale, spec, order=0): - """One picture: ground, decorations, device, tabs, headline.""" - if device not in LAYOUT: - raise ValueError(f"no layout for {device} - one of {', '.join(LAYOUT)}") - - layout = LAYOUT[device] - size = store.CANVASES[device] - width, height = size - canvas = gradient(size, *spec["backgrounds"][screen["background"]]) - - on, off = layout["dash_on"] * width, layout["dash_off"] * width - stroke = layout["dash_stroke"] * width - radius = layout["radii"][order % len(layout["radii"])] * width - - # The crossing line, and the dash pattern picked up where the screens before - # it left off, so the dashes carry on across the gallery rather than - # restarting at every picture. - before = sum(walked(crossing(layout, index, size)) for index in range(order)) - dashed( - canvas, rounded_path(crossing(layout, order, size), radius), stroke, on, off, phase=before - ) - - lower = layout["decorations"][order % len(layout["decorations"])] - - # a line hanging off tabs that are not there reads as a line starting in mid - # air, so a screen without them takes one that comes in from the edge - if not screen["chips"] and any("chips" in point for point in lower): - lower = next( - points for points in layout["decorations"] if not any("chips" in p for p in points) - ) - - # "chips" is the middle of the tabs, so the line runs behind however many - # there are and comes out underneath - placed = [ - (layout["chip_size"][0] / 2 if x == "chips" else x, - layout["chip_top"] if y == "chips" else y) - for x, y in lower - ] - dashed( - canvas, - rounded_path([(x * width, y * height) for x, y in placed], radius), - stroke, on, off, - ) - - device_body(canvas, shot, layout) - chips(canvas, screen["chips"], spec["chips"], layout) - headline(canvas, copy(screen, locale), layout, locale) - - return canvas.convert("RGB") - - -def feature(shot, screen, locale, spec): - """The picture above the listing: the app on a phone, beside the copy. - - The same parts as a screenshot and the same phone, laid out across instead of - down - which is the whole of what a 1024x500 canvas changes. - """ - layout = FEATURE - size = store.FEATURE_CANVAS - width, height = size - canvas = gradient(size, *spec["backgrounds"][screen["background"]]) - - dashed( - canvas, - rounded_path([(x * width, y * height) for x, y in layout["decoration"]], - layout["radius"] * width), - layout["dash_stroke"] * width, - layout["dash_on"] * width, - layout["dash_off"] * width, - ) - - device_body(canvas, shot, layout) - chips(canvas, screen["chips"], spec["chips"], layout) - headline(canvas, copy(screen, locale), layout, locale) - - return canvas.convert("RGB") - - -def copy(screen, locale): - """This screen's two lines in that language, or the English if it has none.""" - lines = screen["headline"].get(locale) or screen["headline"][store.FALLBACK] - - return lines - - -def main(argv=None): - parser = argparse.ArgumentParser(description="Frame the captured play store screenshots.") - parser.add_argument("--captured", metavar="DIR", default=CAPTURED, - help=f"where the capture run wrote (default {CAPTURED.relative_to(ROOT)})") - parser.add_argument("--framed", metavar="DIR", default=FRAMED, - help=f"where to write the framed set (default {FRAMED.relative_to(ROOT)})") - parser.add_argument("--locale", action="append", - help="only this locale, repeatable; default is everything captured") - args = parser.parse_args(argv) - - spec = design() - screens = {screen["name"]: screen for screen in spec["screens"]} - captured, framed = Path(args.captured), Path(args.framed) - - wanted = args.locale or store.languages() - written = graphics = 0 - - for locale in wanted: - folder = captured / locale - if not folder.is_dir(): - print(f"{locale}: no {folder}", file=sys.stderr) - continue - - # emptied rather than written over, so a screen that was renamed does - # not leave yesterday's picture behind for the release to find - out = framed / locale - shutil.rmtree(out, ignore_errors=True) - out.mkdir(parents=True, exist_ok=True) - - for path in sorted(folder.glob("*.png")): - # the capture run writes the device into the name, being the only - # thing that knows which emulator it was driving - device, name = store.named(path.stem) - # lite's edit is framed as the screen it stands in for: the same - # headline, and the same place on the line that crosses the set - name = next((pro for pro, lite in store.LITE.items() if lite == name), name) - if device is None or name not in screens: - print(f"{locale}: skipping {path.name}, which no screen is named after", - file=sys.stderr) - continue - - with Image.open(path) as shot: - picture = frame( - shot.convert("RGB"), device, screens[name], locale, spec, - order=list(screens).index(name), - ) - - picture.save(out / path.name) - written += 1 - - # The feature graphic, off the same capture the first screenshot is drawn - # from. Only the run that photographed the phone has one to draw it from, - # and only that half of a release writes it - which is why nothing here - # fails without it. - source = folder / f"{FEATURE_FROM}.png" - if source.is_file() and store.SCREENS[0] in screens: - with Image.open(source) as shot: - picture = feature( - shot.convert("RGB"), screens[store.SCREENS[0]], locale, spec - ) - - picture.save(out / f"{store.FEATURE}.png") - graphics += 1 - - print(f"framed {written} screenshots and {graphics} feature graphics into {framed}") - - return 0 if written else 1 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 000000000000..b6d304328ca7 --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,5 @@ +# The store screenshots and feature graphics are framed by storeframe +# (https://pypi.org/project/storeframe/). Pinned, so a release run frames the +# same pictures as the last one. +# python3 -m pip install -r scripts/requirements.txt +storeframe==0.1.0 diff --git a/scripts/store_screenshots.py b/scripts/store_screenshots.py index 2ddc6477321e..5eda967a4569 100755 --- a/scripts/store_screenshots.py +++ b/scripts/store_screenshots.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # Validate and stage the phone and tablet screenshot sets for Play. The underscore in the -# filename lets frame-screenshots.py import this module. +# filename lets make-screenshot-documents.py import this module. import argparse import os @@ -83,7 +83,7 @@ # What the framed picture is, per device, in pixels. Not the size of the capture: # play refuses a screenshot whose long side is more than twice its short one, and # a Pixel 9 Pro XL is 1344x2992 - 2.23:1 - before anything is drawn around it. So -# `frame-screenshots.py` draws onto a canvas of its own and the capture is a +# storeframe draws onto a canvas of its own and the capture is a # picture inside it, which is what the frame is for anyway. # # 16:9 for the phone, 16:10 for the tablet, both the proportions of the device @@ -99,7 +99,7 @@ # The feature graphic: the one picture play shows above the listing rather than in # the gallery, and the only listing asset that is not a screenshot. It is drawn -# from a capture like they are - see `frame-screenshots.py` - because the one that +# from a capture like they are - by storeframe - because the one that # was committed here instead was a mockup of the app as it looked before the 4.14 # redesign, and nothing in a release would ever have told us so. #