Files
magpie/internal/gui/icons_sharp_test.go
T
yetone 870f16265b gui: Antigravity's and WorkBuddy's icons are sharp in WebKit (no SVG filter)
@lexrus on X: the Antigravity icons (Antigravity, agy-cli) are blurry in
the GUI. WebKit (WKWebView, and Playwright's WebKit) draws an <img> SVG
that holds an SVG filter at one device pixel per CSS pixel and scales it
up, so on Retina the whole icon, its edges too, comes out soft. Chromium
draws it sharp. Antigravity's lobe-icons SVG was 11 feGaussianBlur blobs
under a mask; WorkBuddy's had a blurred yellow glow.

- antigravity-color.svg is rebuilt from https://antigravity.google/favicon.svg
  (same A path and blobs, base #3186FF). Each blurred blob is a circle
  under the blob's own transform, filled by a radialGradient whose stops
  follow a disk blurred by a Gaussian (15 stops, radius 1+3 sigma); the
  irregular blob is an equal-moment ellipse. The A is a vector clipPath.
  Mean difference from the official favicon in Chromium at 256px: 3.9/255
  per channel. The site's copy (site/public/icons) is the same file.
- workbuddy-color.svg: the filtered glow is the same kind of gradient
  circle, clipped to the tile as WorkBuddy.app's own icon is.
- TestIconsStaySharp fails on any <filter>/feGaussianBlur in the GUI's or
  the site's icons, and on a PNG icon under 2x the largest size the GUI
  draws (26px). Red on the old code, naming antigravity-color.svg (both
  copies) and workbuddy-color.svg.
- The tray's mono logo tests cover both icons; the old Antigravity SVG
  drew in the menu bar with a stray line, the new one as a clean A.

Siblings: no other SVG in the repo has a filter or an embedded <image>,
and every PNG icon is 64px or more.

Run (on mote):
- go test -timeout 45m ./... at 705d67efc+this: exit 0, 101 packages ok.
- gofmt -l clean; go vet ./internal/gui; GOOS=linux (nogui) and
  GOOS=windows go vet.
- After rebasing on 9cd5f3652: gofmt, go vet ./internal/gui and
  TestIconsStaySharp|TestTrayImage ok.
- GUI: 345 files (every test naming antigravity, workbuddy, agy or
  icons/, and every skill/library test), both engines: 6557 pass, 267
  fail in 22 files. Those 22 files rerun at head and at the base
  705d67efc, same load: 265 vs 268 fail, the same files and tests red
  at the base; images-codex-one passed in both. Each is filed (#6709,
  #6373, #6559, #6029, #6658, #6372, #6514, #6659, #4097, #6027, #4566,
  #6597, #6353, #6667, #6687, #6668, #5859, #6561, #6003, #5262).
- Before/after renders: the Library Skills page and the icons at 14-26px
  in WebKit and Chromium at DPR 2, light and dark; tray renders.

Not tried: WebKitGTK on Linux, the live app. The site is not deployed.
2026-11-15 12:25:47 +08:00

60 lines
1.8 KiB
Go

package gui
import (
"image"
_ "image/png"
"os"
"path/filepath"
"strings"
"testing"
)
// The largest an icon is drawn in the GUI: the Routing page's nodes, 26px
// (plugins/routing/routing.css). Retina draws it at twice that.
const largestIconPx = 26
// Icons stay sharp at every size the GUI draws them (lexrus on X: the
// Antigravity icons were blurry in Library → Skills).
//
// An SVG drawn through <img> with an SVG filter in it (Antigravity's
// blurred colour blobs, WorkBuddy's glow) is rasterised by WebKit at one
// device pixel per CSS pixel and scaled up, so on a Retina screen the
// whole icon, edges included, is soft. Chromium draws it sharp, which is
// why it passes a Chromium-only look. A soft blob is a radial gradient
// instead. A PNG icon is at least twice its largest display size.
func TestIconsStaySharp(t *testing.T) {
for _, dir := range []string{"assets/icons", "../../site/public/icons"} {
svgs, _ := filepath.Glob(filepath.Join(dir, "*.svg"))
if len(svgs) == 0 {
t.Fatalf("no SVG icons in %s", dir)
}
for _, f := range svgs {
b, err := os.ReadFile(f)
if err != nil {
t.Fatal(err)
}
if s := string(b); strings.Contains(s, "<filter") || strings.Contains(s, "feGaussianBlur") {
t.Errorf("%s has an SVG filter, which WebKit draws at 1x: blurry on Retina", f)
}
}
}
pngs, _ := filepath.Glob("assets/icons/*.png")
if len(pngs) == 0 {
t.Fatal("no PNG icons in assets/icons")
}
for _, f := range pngs {
r, err := os.Open(f)
if err != nil {
t.Fatal(err)
}
c, _, err := image.DecodeConfig(r)
r.Close()
if err != nil {
t.Fatalf("%s: %v", f, err)
}
if min(c.Width, c.Height) < 2*largestIconPx {
t.Errorf("%s is %dx%d, under twice the %dpx it can be drawn at", f, c.Width, c.Height, largestIconPx)
}
}
}