Theme icons: pixel-art glyphs render with crisp edges

A glyph made only of axis-aligned rectangles (M, h, v, z) is pixel art: its SVG gets
shape-rendering="crispEdges", so a 16-cell glyph stays sharp at sizes that are not a whole multiple
of its grid (X's rail draws 26px icons, the action bar 18.75px).
This commit is contained in:
CRTkafa 2026-10-01 16:59:03 +07:00
parent 60cb4f17ac
commit dffeb3f159

View file

@ -216,7 +216,11 @@ export function glyphSvg(glyph: IconGlyph, style: IconStyle, colors: RoleColors
if (def) defs.push(def); if (def) defs.push(def);
return `<path d="${esc(layer.d)}" fill="${attr}"${layer.opacity !== undefined ? ` opacity="${layer.opacity}"` : ''}${layer.rule ? ' fill-rule="evenodd"' : ''}/>`; return `<path d="${esc(layer.d)}" fill="${attr}"${layer.opacity !== undefined ? ` opacity="${layer.opacity}"` : ''}${layer.rule ? ' fill-rule="evenodd"' : ''}/>`;
}); });
return `${open}${defs.length ? `<defs>${defs.join('')}</defs>` : ''}${paths.join('')}</svg>`; // Pixel art (every layer made of axis-aligned rectangles: M, h, v, z only) stays crisp when the
// 24px box is drawn at a size that is not a whole multiple of its grid (X's rail draws 26px icons).
const pixel = glyph.layers.every(layer => /^[MmHhVvZz0-9eE\s,.+-]+$/.test(layer.d));
const svg = pixel ? open.replace('<svg ', '<svg shape-rendering="crispEdges" ') : open;
return `${svg}${defs.length ? `<defs>${defs.join('')}</defs>` : ''}${paths.join('')}</svg>`;
} }
return null; return null;
} }