Skip to content

Instantly share code, notes, and snippets.

@jjgod
Created December 2, 2009 03:40
Show Gist options
  • Save jjgod/246909 to your computer and use it in GitHub Desktop.
Save jjgod/246909 to your computer and use it in GitHub Desktop.
CTFontRef displayFont = CTFontCreateWithName(CFSTR("Andale Mono"), 18.0, NULL);
float charWidth = 18.0;
CFTypeRef keys[1];
CFTypeRef values[1];
keys[0] = kCTFontFixedAdvanceAttribute;
values[0] = CFNumberCreate(nil, kCFNumberFloatType, (void *)&charWidth);
CFDictionaryRef fontAttributes = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL);
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithAttributes(fontAttributes);
CTFontRef displayFont2 = CTFontCreateCopyWithAttributes(displayFont, 0.0, NULL, fontDescriptor);
// use the font
CFAttributedStringSetAttribute(attrString, CFRangeMake(0, len), kCTFontAttributeName, displayFont2);
CFRelease(fontDescriptor);
CFRelease(fontAttributes);
CFRelease(displayFont2);
CFRelease(displayFont);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment