diff --git a/docs/frontend.md b/docs/frontend.md index 00d257b..e8eea6b 100644 --- a/docs/frontend.md +++ b/docs/frontend.md @@ -38,3 +38,11 @@ Neue Farben als Token in beiden Dark-Blöcken von `plenario.css` pflegen; auf de Der Wake Lock ist standardmäßig an (braucht keine Nutzergeste); nur ein bewusstes Ausschalten wird gemerkt. Die Seite lädt bei Folienwechsel neu: der Wake Lock wird per `sessionStorage` (`plenario-wakelock`) wieder angefordert, Vollbild braucht eine Nutzergeste und muss nach dem Wechsel ggf. neu gewählt werden. + +## Favicon + +Das Logo (`.brand__mark` in `plenario.css`) ist auch das Favicon: `webroot/favicon.svg` (moderne Browser), `favicon.ico` +(16/32/48 px, Fallback) und `apple-touch-icon.png` (180 px, iOS, deckend ohne Rundung, die macht iOS selbst). Eingebunden über +`templates/element/favicon.php` in allen drei Layouts (default, present, error). Die Dateien sind statisch und werden aus +einer Geometrie erzeugt: Ändert sich das Logo, `php resources/favicon/generate.php webroot` ausführen (braucht `ext-gd`) +und Farben/Anteile im Skript an `.brand__mark` angleichen. Test: `FaviconTest.php`. diff --git a/resources/favicon/generate.php b/resources/favicon/generate.php new file mode 100644 index 0000000..a45beb6 --- /dev/null +++ b/resources/favicon/generate.php @@ -0,0 +1,144 @@ + $stop) { + [$x1, $y1] = $point($prev); + [$x2, $y2] = $point($stop); + $large = ($stop - $prev) > 0.5 ? 1 : 0; + $paths .= sprintf( + " \n", + $colors[$i], + $c, + $c, + $x1, + $y1, + $R, + $R, + $large, + $x2, + $y2, + ); + $prev = $stop; +} +$rx = round($size * $radiusRatio, 2); +$svg = << + PlenarIO + + +{$paths} + + +SVG; +file_put_contents($out . '/favicon.svg', $svg); + +// ---- PNG / ICO (GD, 4x4 supersampling) --------------------------------------------------- +$rgb = fn(string $hex): array => [hexdec(substr($hex, 1, 2)), hexdec(substr($hex, 3, 2)), hexdec(substr($hex, 5, 2))]; +$palette = array_map($rgb, $colors); + +$render = function (int $n, float $padding = 0.0) use ($stops, $palette, $radiusRatio): string { + $img = imagecreatetruecolor($n, $n); + imagealphablending($img, false); + imagesavealpha($img, true); + $ss = 4; + $inner = $n * (1 - 2 * $padding); + $r = $inner * $radiusRatio; + $offset = $n * $padding; + for ($y = 0; $y < $n; $y++) { + for ($x = 0; $x < $n; $x++) { + $sum = [0.0, 0.0, 0.0]; + $cover = 0; + for ($sy = 0; $sy < $ss; $sy++) { + for ($sx = 0; $sx < $ss; $sx++) { + $px = $x + ($sx + 0.5) / $ss - $offset; + $py = $y + ($sy + 0.5) / $ss - $offset; + if ($px < 0 || $py < 0 || $px > $inner || $py > $inner) { + continue; + } + // rounded corners + $cx = min(max($px, $r), $inner - $r); + $cy = min(max($py, $r), $inner - $r); + if (($px - $cx) ** 2 + ($py - $cy) ** 2 > $r ** 2) { + continue; + } + $angle = atan2($px - $inner / 2, -($py - $inner / 2)); // 0 = top, clockwise + $f = fmod($angle / (2 * M_PI) + 1, 1); + $k = 0; + while ($k < 3 && $f >= $stops[$k]) { + $k++; + } + foreach ($palette[$k] as $j => $v) { + $sum[$j] += $v; + } + $cover++; + } + } + $total = $ss * $ss; + if ($cover === 0) { + $col = imagecolorallocatealpha($img, 0, 0, 0, 127); + } else { + $col = imagecolorallocatealpha( + $img, + (int)round($sum[0] / $cover), + (int)round($sum[1] / $cover), + (int)round($sum[2] / $cover), + (int)round(127 * (1 - $cover / $total)), + ); + } + imagesetpixel($img, $x, $y, $col); + } + } + ob_start(); + imagepng($img, null, 9); + $png = (string)ob_get_clean(); + + return $png; +}; + +// favicon.ico with 16, 32 and 48 px (PNG compressed entries) +$sizes = [16, 32, 48]; +$images = array_map(fn(int $n): string => $render($n), $sizes); +$ico = pack('vvv', 0, 1, count($sizes)); +$offset = 6 + 16 * count($sizes); +foreach ($sizes as $i => $n) { + $ico .= pack('CCCCvvVV', $n, $n, 0, 0, 1, 32, strlen($images[$i]), $offset); + $offset += strlen($images[$i]); +} +file_put_contents($out . '/favicon.ico', $ico . implode('', $images)); + +// iOS ignores transparency (fills black) and rounds the corners itself: opaque full-bleed square. +$apple = imagecreatetruecolor(180, 180); +$stopsPx = $stops; +for ($y = 0; $y < 180; $y++) { + for ($x = 0; $x < 180; $x++) { + $angle = atan2($x + 0.5 - 90, -($y + 0.5 - 90)); + $f = fmod($angle / (2 * M_PI) + 1, 1); + $k = 0; + while ($k < 3 && $f >= $stopsPx[$k]) { + $k++; + } + imagesetpixel($apple, $x, $y, imagecolorallocate($apple, ...$palette[$k])); + } +} +imagepng($apple, $out . '/apple-touch-icon.png', 9); +echo "ok\n"; diff --git a/templates/element/favicon.php b/templates/element/favicon.php new file mode 100644 index 0000000..9fc4e92 --- /dev/null +++ b/templates/element/favicon.php @@ -0,0 +1,12 @@ + $this->Url->assetUrl($file, ['pathPrefix' => '']); +?> + + + diff --git a/templates/layout/default.php b/templates/layout/default.php index d386449..26cf63f 100644 --- a/templates/layout/default.php +++ b/templates/layout/default.php @@ -17,7 +17,7 @@ $title = $this->fetch('title'); <?= $title ? h($title) . ' · ' : '' ?>PlenarIO element('theme_init') ?> - Html->meta('icon') ?> + element('favicon') ?> Html->css(['normalize.min', 'plenario']) ?> fetch('meta') ?> fetch('css') ?> diff --git a/templates/layout/error.php b/templates/layout/error.php index 6c762b0..3bc27f5 100644 --- a/templates/layout/error.php +++ b/templates/layout/error.php @@ -13,7 +13,7 @@ <?= h($this->fetch('title')) ?> · PlenarIO element('theme_init') ?> - Html->meta('icon') ?> + element('favicon') ?> Html->css(['normalize.min', 'plenario']) ?> diff --git a/templates/layout/present.php b/templates/layout/present.php index 2b2e958..dd025c4 100644 --- a/templates/layout/present.php +++ b/templates/layout/present.php @@ -14,7 +14,7 @@ <?= h($this->fetch('title')) ?> · PlenarIO element('theme_init', ['key' => 'plenario-theme-present', 'fallback' => 'dark']) ?> - Html->meta('icon') ?> + element('favicon') ?> Html->css(['normalize.min', 'plenario']) ?> diff --git a/tests/TestCase/Controller/FaviconTest.php b/tests/TestCase/Controller/FaviconTest.php new file mode 100644 index 0000000..ac604c4 --- /dev/null +++ b/tests/TestCase/Controller/FaviconTest.php @@ -0,0 +1,55 @@ + + */ + protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; + + public function testAllLayoutsLinkTheIcons(): void + { + [$poll, $token] = $this->createPoll(); + $this->createSlide($poll); + + // default, present and error layout + foreach (['/', '/admin/' . $token . '/present', '/does-not-exist'] as $url) { + $this->get($url); + // Root-relative, no "img/" prefix (static files live directly in webroot/). + $this->assertResponseRegExp('##', $url); + $this->assertResponseRegExp('##', $url); + $this->assertResponseRegExp('##', $url); + } + } + + public function testIconFilesAreValid(): void + { + $svg = (string)file_get_contents(WWW_ROOT . 'favicon.svg'); + $this->assertStringContainsString('assertNotFalse(simplexml_load_string($svg), 'favicon.svg is not well-formed XML'); + + // ICO: reserved 0, type 1, three images; each entry's data starts with the PNG signature. + $ico = (string)file_get_contents(WWW_ROOT . 'favicon.ico'); + $header = unpack('vreserved/vtype/vcount', $ico); + $this->assertSame([0, 1, 3], [$header['reserved'], $header['type'], $header['count']]); + for ($i = 0; $i < $header['count']; $i++) { + $entry = unpack('Voffset', $ico, 6 + 16 * $i + 12); + $this->assertSame("\x89PNG", substr($ico, $entry['offset'], 4)); + } + + $this->assertSame([180, 180], array_slice(getimagesize(WWW_ROOT . 'apple-touch-icon.png'), 0, 2)); + } +} diff --git a/webroot/apple-touch-icon.png b/webroot/apple-touch-icon.png new file mode 100644 index 0000000..0b29dc5 Binary files /dev/null and b/webroot/apple-touch-icon.png differ diff --git a/webroot/favicon.ico b/webroot/favicon.ico index 49a060f..16bb0cf 100644 Binary files a/webroot/favicon.ico and b/webroot/favicon.ico differ diff --git a/webroot/favicon.svg b/webroot/favicon.svg new file mode 100644 index 0000000..3fa3c86 --- /dev/null +++ b/webroot/favicon.svg @@ -0,0 +1,10 @@ + + PlenarIO + + + + + + + +