Skip to content

Commit 18fb7f9

Browse files
emabreyMottie
authored andcommitted
Fix Github Font Preview mini glyph fill color (#14)
The font preview userscript was previously drawing the glyphs within the preview pages without specifying the fill color as was done when drawing the large glyph. This worked fine when the default fill color was the standard black, but when the color was very light, like it is in dark themes such as Github Dark, this resulted in having nearly-white glyphs drawn on top of a nearly-white background. The readability problem this caused has been fixed by drawing all the glyphs, both the small preview glyphs and the large detail glyph, using a specific color. That color is controlled by the "glyphFillColor" variable, which is simply a rename of the "bigGlyphFillColor" variable but still using the same default color. You can see a before/after of the UI changes involved in the fix here: https://imgur.com/1K7Tb7j Signed-off-by: Emily Mabrey <[email protected]>
1 parent b960033 commit 18fb7f9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

github-font-preview.user.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
const fontExt = /\.(otf|ttf|woff)$/i,
3434

3535
// canvas colors
36+
glyphFillColor = '#808080', // (big) (mini) fill color
3637
bigGlyphStrokeColor = '#111111', // (big) stroke color
37-
bigGlyphFillColor = '#808080', // (big) fill color
3838
bigGlyphMarkerColor = '#f00', // (big) min & max width marker
3939
miniGlyphMarkerColor = '#606060', // (mini) glyph index (bottom left corner)
4040
glyphRulerColor = '#a0a0a0'; // (mini) min & max width marker & (big) glyph horizontal lines
@@ -502,7 +502,7 @@
502502

503503
ctx.fillStyle = bigGlyphStrokeColor;
504504
path = glyph.getPath(x0, glyphBaseline, glyphSize);
505-
path.fill = bigGlyphFillColor;
505+
path.fill = glyphFillColor;
506506
path.stroke = bigGlyphStrokeColor;
507507
path.strokeWidth = 1.5;
508508
drawPathWithArrows(ctx, path);
@@ -534,7 +534,9 @@
534534
ctx.fillRect(xmax, fontBaseline, 1, cellMarkSize);
535535

536536
ctx.fillStyle = '#000000';
537-
glyph.draw(ctx, x0, fontBaseline, fontSize);
537+
let path = glyph.getPath(x0, fontBaseline, fontSize);
538+
path.fill = glyphFillColor;
539+
path.draw(ctx);
538540
}
539541

540542
function displayGlyphPage(pageNum) {

0 commit comments

Comments
 (0)