diff --git a/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml b/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml index 601df181..860241f6 100644 --- a/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml +++ b/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml @@ -1,13 +1,15 @@ + - + android:viewportWidth="1024" + android:viewportHeight="1024"> + android:pathData="M0,0h1024v1024h-1024z"/> + diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/widgets/AppLogoDrawableJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/widgets/AppLogoDrawableJvmTest.kt new file mode 100644 index 00000000..00e08d1a --- /dev/null +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/widgets/AppLogoDrawableJvmTest.kt @@ -0,0 +1,87 @@ +package mobi.giza.compose.ui.composable.widgets + +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.size +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toPixelMap +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.captureToImage +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.runDesktopComposeUiTest +import androidx.compose.ui.unit.dp +import mobi.giza.compose.resources.Res +import mobi.giza.compose.resources.compose_multiplatform +import org.jetbrains.compose.resources.painterResource +import kotlin.math.abs +import kotlin.test.Test +import kotlin.test.assertTrue + +/** + * The in-app logo -- `compose-multiplatform.xml`, drawn in the middle of every QR code and as + * the desktop window's icon -- is the sphinx from docs/brand/giza-sphinx.svg on black. + * + * The drawable is generated (docs/scripts/app-icons.py), and nothing else would notice it + * going wrong: a QR code with the wrong mark in it still scans. So this samples it where the + * master is unambiguous -- each point sits in the middle of an 11 px patch of one colour in + * ImageMagick's 256 px render of the master -- and asks for the master's colour back: + * + * - sand in the face and in the disc, which a dropped or recoloured mark changes; + * - black in a cutout inside the disc (the band between the left lappet's stripes), which a + * master whose cutouts filled in changes. Today's master has no nested sub-paths, so its + * fill rule does not matter; a redraw that nests them would, and this is where it shows; + * - black in the corner, which a dropped background changes. + * + * The test density is 1, so 256.dp is 256 pixels and the points are the render's own. + * See docs/giza-app-icon.md, Phase 2. + */ +@OptIn(ExperimentalTestApi::class) +class AppLogoDrawableJvmTest { + + // The brand's own two colours, which the drawable is checked against. + private val sand = Color(0xFFD2AB5E) + private val black = Color(0xFF000000) + + private val expected = listOf( + Triple("the face", Point(128, 140), sand), + Triple("the disc", Point(62, 62), sand), + Triple("a cutout inside the disc", Point(61, 146), black), + Triple("the corner", Point(10, 10), black), + ) + + @Test + fun `the logo is the sphinx on black`() = runDesktopComposeUiTest(width = 256, height = 256) { + setContent { + Image( + painter = painterResource(Res.drawable.compose_multiplatform), + contentDescription = null, + modifier = Modifier.size(256.dp).testTag(Logo), + ) + } + + // A resource painter is empty until the file has been read, which happens off the + // composition. Wait for the background to arrive rather than for idleness. + waitUntil(timeoutMillis = 10_000) { + onNodeWithTag(Logo).captureToImage().toPixelMap()[10, 10].alpha > 0.99f + } + + val pixels = onNodeWithTag(Logo).captureToImage().toPixelMap() + expected.forEach { (where, at, colour) -> + val seen = pixels[at.x, at.y] + assertTrue(seen.near(colour), "$where at (${at.x}, ${at.y}): expected $colour, saw $seen") + } + } + + private data class Point(val x: Int, val y: Int) + + /** Within two 8-bit steps per channel, for antialiasing and colour-space rounding. */ + private fun Color.near(other: Color) = + abs(red - other.red) < 2.5f / 255 && + abs(green - other.green) < 2.5f / 255 && + abs(blue - other.blue) < 2.5f / 255 + + private companion object { + const val Logo = "logo" + } +} diff --git a/docs/giza-app-icon.md b/docs/giza-app-icon.md index 05d898fb..5f46ed34 100644 --- a/docs/giza-app-icon.md +++ b/docs/giza-app-icon.md @@ -247,7 +247,7 @@ dock and ⌘-Tab. `packageDeb` can be checked on this machine; the `.dmg` and `. |---|---| | 0 | done. `giza` merged in (`a4f54ad4`, Android's icon). The master is `docs/brand/giza-sphinx.svg`, the designer's *Transparent Cutouts* file unchanged; its path equals the `pathData` of both `ic_launcher_foreground.xml` and `ic_launcher_monochrome.xml`, 1,567 characters each. Baseline at `e00d0f80`: `jvmTest` 1,407 run, 0 failed, 0 skipped; `m3Audit` all budgets met, adaptive APIs 12 (floor 12), navigation components 2 (floor 2). Measuring the path also showed its thirteen sub-paths are disjoint, so the fill rule is not load-bearing; the facts above say so | | 1 | done. `docs/scripts/app-icons.py`, with `--only ios|desktop|xml`, `--root` (to write somewhere other than the tree) and `--sheet`. Run twice into two scratch roots it wrote byte-identical files. The light icon is RGB with no alpha, the dark RGBA, the tinted grayscale; the `.ico` holds eight entries, 256 as PNG; the `.icns` parses as eight PNG chunks, `ic07`–`ic14`, with the sizes the table names. The contact sheet left 0.68 and 0.80 as they were: the stripes stay apart down to 32 px and merge, as expected, at 16 | -| 2 | not started | +| 2 | built. `compose-multiplatform.xml` is generated (`--only xml`): a black square and the sand mark, with a comment naming the script and the master. `AppLogoDrawableJvmTest` passes, and fails at line 54 when the previous drawable is put back. **Not yet checked:** a phone camera reading a QR code with the new logo, in light and dark theme — the logo covers the same share of the code as before | | 3 | not started | | 4 | not started | | 5 | not started |