Skip to content

Instantly share code, notes, and snippets.

@mariusae
Last active April 3, 2019 01:32
Show Gist options
  • Save mariusae/d3856206297706ea90d30abc177a7100 to your computer and use it in GitHub Desktop.
Save mariusae/d3856206297706ea90d30abc177a7100 to your computer and use it in GitHub Desktop.
Support for slashed zeros in LucidaGrande
diff --git a/src/cmd/fontsrv/osx.c b/src/cmd/fontsrv/osx.c
index e1c3ff69..154f0bf1 100644
--- a/src/cmd/fontsrv/osx.c
+++ b/src/cmd/fontsrv/osx.c
@@ -388,6 +388,9 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias)
Memsubfont *sf;
CGFloat whitef[] = { 1.0, 1.0 };
CGColorRef white;
+ char bufx[20];
+ CFStringRef baseString ;
+ CTGlyphInfoRef glyphInfo;
s = c2mac(name);
desc = CTFontDescriptorCreateWithNameAndSize(s, size);
@@ -402,6 +405,9 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias)
if(font == nil)
return nil;
+ sprint(bufx, "%C", (Rune)mapUnicode(name, 48));
+ baseString = c2mac(bufx);
+ glyphInfo = CTGlyphInfoCreateWithGlyph(1082, font, baseString);
bbox = CTFontGetBoundingBox(font);
x = (int)(bbox.size.width*2 + 0.99999999);
@@ -459,15 +465,20 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias)
CTLineRef line;
CGRect r;
CGPoint p1;
- CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName };
- CFTypeRef values[] = { font, white };
+ CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName, kCTGlyphInfoAttributeName };
+ CFTypeRef values[] = { font, white, glyphInfo };
+ int size = 2;
+
+ if(strcmp(name, "LucidaGrande") == 0) {
+ size = 3;
+ }
sprint(buf, "%C", (Rune)mapUnicode(name, i));
str = c2mac(buf);
// See https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/CoreText_Programming/LayoutOperations/LayoutOperations.html#//apple_ref/doc/uid/TP40005533-CH12-SW2
attrs = CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys,
- (const void**)&values, sizeof(keys) / sizeof(keys[0]),
+ (const void**)&values, size,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
attrString = CFAttributedStringCreate(kCFAllocatorDefault, str, attrs);
@@ -527,5 +538,8 @@ mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias)
sf->info = fc0;
sf->bits = m1;
+ CFRelease(baseString);
+ CFRelease(glyphInfo);
+
return sf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment