Re: -glyphWithName:
Re: -glyphWithName:
- Subject: Re: -glyphWithName:
- From: Kyle Sluder <email@hidden>
- Date: Sat, 23 Aug 2014 16:30:21 -0500
On Sat, Aug 23, 2014, at 11:26 AM, Raglan T. Tiger wrote:
>
> > So the question I have is: what are you actually trying to do?
>
> Generally speaking, display the NSFontPanel with an accessory view
> containing a NSTextField, OK and Cancel buttons.
>
> The user picks a font, types a phrase and clicks OK.
>
> I now take the phrase and get the glyphs for each character in the
> phrase.
So the user types "abcdef" into your field and hits OK; you dismiss the
font panel and try to get the glyphs for "a", "b", "c", "d", "e", and
"f"?
>
> Glyhs are gotten by name.
If my above understanding is correct, this is almost certainly the wrong
way to go about it. The Cocoa text system can go directly from Unicode
strings to glyphs; there's no need to convert the string to some sort of
intermediary form.
But I'm also concerned that you might not be aware of some of the more
complicated areas of Unicode-aware text rendering that make your desired
goal somewhat dubious.
There is not a 1-to-1 mapping of "characters" (what Unicode refers to as
"graphemes") and glyphs. See Apple's documentation about grapheme
clusters:
<https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Strings/Articles/stringsClusters.html>
"""In many writing systems, a single character may be composed of a base
letter plus an accent or other decoration. […] However, even if a string
is fully precomposed, there are still many combinations that must be
represented using a base character and combining marks. For most text
processing, substring ranges should be arranged so that their boundaries
do not separate a base character from its associated combining marks."""
So what to the user might look like a single character (ö, for example),
might actually be generated from two separate glyphs. The header
comments for -[NSLayoutManager
characterRangeForGlyphRange:actualGlyphRange:] reinforces this:
"""For example, if the text storage contains the character (o-umlaut)
and the glyph store contains the two atomic glyphs "o" and (umlaut), and
if the glyph range given encloses only the first or second glyph, then
actualGlyphRange will be set to enclose both glyphs."""
What glyphs get generated for any given character sequence (composed or
not) depend on the font and the glyph generator.
--Kyle Sluder
_______________________________________________
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