aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fontsrv
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2020-08-15 09:10:54 -0400
committerRuss Cox <rsc@swtch.com>2020-08-15 09:10:54 -0400
commit9843fc0d82c68c78059ccb167e8402def5a4ee1f (patch)
tree82355f2af9864213eaca3b27d3ffaca182e50812 /src/cmd/fontsrv
parent977b25a76ae8263e53fb4eb1abfc395769f23e3d (diff)
downloadplan9port-9843fc0d82c68c78059ccb167e8402def5a4ee1f.tar.gz
plan9port-9843fc0d82c68c78059ccb167e8402def5a4ee1f.tar.bz2
plan9port-9843fc0d82c68c78059ccb167e8402def5a4ee1f.zip
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.
Diffstat (limited to 'src/cmd/fontsrv')
-rw-r--r--src/cmd/fontsrv/mac.c22
1 files changed, 17 insertions, 5 deletions
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
@@ -76,6 +76,17 @@ mac2r(CGRect r, int size, int unit)
}
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)
{
int i, n;
@@ -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;