On 1 Jun 2010, at 02:42, James Maxwell wrote:

> Okay, so the simple solution isn't simple.
> 
> this:
> 
> NSFont* artFont_2 = [NSFont fontWithName:@"Sonara" size:30.0];
> NSLog(@"what's up? %i", [artFont_1 glyphWithName:@"FULL STOP"]);
> 
> prints the glyph as "0" (which is NOT the glyph ID)
> 
> So what gives?

I think you're confused about the glyph names.  The names in Character Viewer 
are the Unicode character names, *not* glyph names (which are either rule-based 
or come from the "post" table in the font).  The conventional name for the full 
stop glyph is "period", though in fonts with a format 2 "post" table it's 
possible that it might be called something else (which would be mischievous and 
would probably break some things, but I wouldn't put it past *someone* to 
design a font that way).

Normally you'd be drawing using higher-level APIs that take Unicode code 
points/units rather than glyph indices; in that case, if you *really* needed a 
glyph ID for some reason, you could get NSLayoutManager or Core Text to map 
your Unicode data to glyphs for you.

Mapping glyphs yourself is a little on the painful side; it *is* possible to do 
it, but you'd have to grab the font's tables and parse them yourself... I 
wouldn't recommend it if you can get something else to do glyph mapping for 
you.  Further, if you want to support advanced layout features like OpenType or 
AAT, it will rapidly become an *extremely* unpleasant and complicated exercise.

> Simple question: since using the Glyph ID (i.e., from the Character viewer) 
> directly at least **works**, is there any real reason why the same font, on 
> different systems, would have different Glyph IDs for the same character? Or 
> was this possibly just some form of font corruption?

The glyph IDs are generally speaking up to the font; there are a few predefined 
ones - 0 is reserved for the undefined/missing character glyph, and index 1 is 
the null glyph.

> If looking up the Glyph ID and using it directly is supposed to be safe 
> across machines, I'll just go back to that, as this glyphWithName business is 
> way too annoying...

If you can guarantee that you're always using the same version of the font, and 
nobody is going to change the glyph IDs, then you can use them directly if you 
must.  However, if the font you're using supports it, you'd be better off using 
the Unicode "Musical Symbols" block at U+1D100, because that frees you from 
relying on knowing specific glyph IDs; it also means you can use the 
higher-level rendering machinery, which gets you all kinds of advantages like 
automatic support for kerning, ligatures, positioning and so on.

Essentially, using glyph IDs directly ties you to a particular font (and maybe 
to a particular *version* of that font, since there's nothing stopping the 
designer from changing the glyph IDs), and may create a lot of extra work for 
you if you need support for modern layout features.

Kind regards,

Alastair.

-- 
http://alastairs-place.net



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to