Retrieving an NSFont from an OTF in bundle Resources
Retrieving an NSFont from an OTF in bundle Resources
- Subject: Retrieving an NSFont from an OTF in bundle Resources
- From: Elliott Cable <email@hidden>
- Date: Wed, 9 Jun 2010 07:31:32 -0800
I’m trying to do something pretty simple (or so I would think). I need
to get an `NSFont` (to apply to portion of an
`NSMutableAttributedString`) from an OpenType file in the Resources
folder of my bundle.
First, I grab an `NSURL`:
NSURL *fontURL = [NSURL fileURLWithPath: [[self bundle]
pathForResource: @"FertigoPro-Regular"
ofType: @"otf"
inDirectory: @"Fonts"]];
Then, I use this chain of Core Foundation methods to convert that into
an NSFont:
NSFont *radixFont =
CTFontCreateWithGraphicsFont(
CGFontCreateWithDataProvider(
CGDataProviderCreateWithURL((CFURLRef)fontURL)), 14.0, NULL, NULL);
Finally, I apply that NSFont to an NSMutableAttributedString:
[attributedSolCount addAttribute: NSFontAttributeName value:
radixFont range: radixRange];
When I `NSLog()` the `NSFont` (`radixFont`), I get the following:
6/9 6 35 57 SystemUIServer[31898] radixFont: "FertigoPro-Regular
14.00 pt. P [] (0x10015ea40) fobj=0x10015ea40, spc=3.32"
So. All that said, everything seems well and good, right? Except… that
it’s not. When displayed, that NSAttributedString appears to be
falling back to Courier or Monaco or Menlo or something (cf.
http://drp.ly/19VR3t, using the above dance, and http://drp.ly/19W01O
using a direct `[NSFont fontWithName:@"FertigoPro-Regular" size:
14.0]` instead). Do any of y’all have any ideas as to what might be
going wrong? There’s no errors, warnings, log messages… nothing. I
have no idea how to begin to go about debugging this… the font just
*doesn’t work*. And, in my experience, “just *doesn’t work*” is the
absolute worst kind of bug you can run into… barring, perhaps, “works
for me, but unreliably, not for this other person.”
Any help of any sort would be much appreciated.
P.S. If I missed any information you might need to be able to help,
the entire codebase is very small, and is available online. The most
recent commit as of this e-mail (i.e. the one exhibiting this problem)
is: http://github.com/elliottcable/Solcounter.menu/tree/d2613c - there
are also comprehensive instructions for compiling that code, if you
want to see the problem for yourself. The relevant fontfile (or
rather, a truncated version, as requested by the designer of the
typeface) is also vendored into that repository.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden