Re: How to know if an NSFont can draw an NSString?
Re: How to know if an NSFont can draw an NSString?
- Subject: Re: How to know if an NSFont can draw an NSString?
- From: "Douglas R. Davidson" <email@hidden>
- Date: Fri, 09 Dec 2016 17:01:34 -0800
At the AppKit level, this sort of thing is handled as part of attribute fixing on NSAttributedString, which is covered in the documentation in the “Attributed String Programming Guide”, under the heading of “Fixing Inconsistencies”.
Douglas Davidson
> On Dec 9, 2016, at 4:51 PM, Ken Thomases <email@hidden> wrote:
>
> On Dec 9, 2016, at 5:15 PM, Sean McBride <email@hidden> wrote:
>>
>> I use an open source OpenGL-based library to do some drawing, and sometimes I need to draw some text. This library takes UTF-8 as input and a path to a font file to use. I use [NSFont systemFontOfSize:0.0] and get its path using kCTFontURLAttribute.
>>
>> This all works great for many characters, but notably fails for Japanese characters (and others). I'm trying to understand why. Could it be that the system font doesn't have every unicode character under the sun?
>
> Indeed it does not. Most fonts don't. Unicode is huge and font designers are only human.
>
> The text system uses a "cascade list" of fonts for when a given font doesn't include a glyph for a particular character. The search continues in the next font in the cascade list, etc.
>
>> If so, is there a way to choose an NSFont based on the contents of an NSString?
>
> Dropping down to Core Text and CTFont, there's CTFontCopyDefaultCascadeListForLanguages() to get the cascade list. More simply, there's CTFontCreateForString(). The issue there, though, is that no single font may be appropriate for all of the characters of a string. So, you may need to break the string up into runs that can be represented by a single font. I think that CTLine and CTRun can work for that: CTLineCreateWithAttributedString(), CTLineGetGlyphRuns(), CTRunGetStringRange() to map runs back to portions of the original string, and CTRunGetAttributes() to get the font for each run.
>
> Regards,
> Ken
>
>
> _______________________________________________
>
> 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
_______________________________________________
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