From 9843fc0d82c68c78059ccb167e8402def5a4ee1f Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sat, 15 Aug 2020 09:10:54 -0400 Subject: fontsrv: fix handling of colored glyphs (emoji) Drawing as white on black to produce a mask only works if the white on black is the inversion of black on white. Emoji that force use of specific colors don't respect that. Draw black on white and invert to mask separately. --- src/cmd/fontsrv/mac.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/cmd/fontsrv/mac.c') diff --git a/src/cmd/fontsrv/mac.c b/src/cmd/fontsrv/mac.c index 9829b5a8..c5a2e0f1 100644 --- a/src/cmd/fontsrv/mac.c +++ b/src/cmd/fontsrv/mac.c @@ -75,6 +75,17 @@ mac2r(CGRect r, int size, int unit) return rr; } +void +meminvert(Memimage *m) +{ + uchar *p, *ep; + + p = byteaddr(m, m->r.min); + ep = p + 4*m->width*Dy(m->r); + for(; p < ep; p++) + *p ^= 0xff; +} + void loadfonts(void) { @@ -223,8 +234,8 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias) int i, height, ascent; Fontchar *fc, *fc0; Memsubfont *sf; - CGFloat whitef[] = { 1.0, 1.0 }; - CGColorRef white; + CGFloat blackf[] = { 0.0, 1.0 }; + CGColorRef black; s = c2mac(name); desc = CTFontDescriptorCreateWithNameAndSize(s, size); @@ -267,7 +278,7 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias) color = CGColorSpaceCreateWithName(kCGColorSpaceGenericGray); ctxt = CGBitmapContextCreate(byteaddr(mc, mc->r.min), Dx(mc->r), Dy(mc->r), 8, mc->width*sizeof(u32int), color, kCGImageAlphaNone); - white = CGColorCreate(color, whitef); + black = CGColorCreate(color, blackf); CGColorSpaceRelease(color); if(ctxt == nil) { freememimage(m); @@ -293,7 +304,7 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias) CGRect r; CGPoint p1; CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName }; - CFTypeRef values[] = { font, white }; + CFTypeRef values[] = { font, black }; sprint(buf, "%C", (Rune)mapUnicode(name, i)); str = c2mac(buf); @@ -310,7 +321,7 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias) line = CTLineCreateWithAttributedString(attrString); CGContextSetTextPosition(ctxt, 0, y0); r = CTLineGetImageBounds(line, ctxt); - memfillcolor(mc, DBlack); + memfillcolor(mc, DWhite); CTLineDraw(line, ctxt); CFRelease(line); @@ -330,6 +341,7 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias) continue; } + meminvert(mc); memimagedraw(m, Rect(x, 0, x + p1.x, y), mc, ZP, memopaque, ZP, S); fc->width = p1.x; fc->left = 0; -- cgit v1.2.3