• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to know if an NSFont can draw an NSString?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to know if an NSFont can draw an NSString?


  • Subject: Re: How to know if an NSFont can draw an NSString?
  • From: Ken Thomases <email@hidden>
  • Date: Fri, 09 Dec 2016 18:51:02 -0600

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


  • Follow-Ups:
    • Re: How to know if an NSFont can draw an NSString?
      • From: "Douglas R. Davidson" <email@hidden>
References: 
 >How to know if an NSFont can draw an NSString? (From: Sean McBride <email@hidden>)

  • Prev by Date: How to know if an NSFont can draw an NSString?
  • Next by Date: Re: How to know if an NSFont can draw an NSString?
  • Previous by thread: How to know if an NSFont can draw an NSString?
  • Next by thread: Re: How to know if an NSFont can draw an NSString?
  • Index(es):
    • Date
    • Thread