On Aug 28, 2013, at 16:02 , Graham Cox <graham....@bigpond.com> wrote:

> It seems overall that I was right in that once you can get to a stream (font 
> file) or a name, you're home and dry.

"Home and dry" might be overstating things a bit :-)   You’re at the starting 
line.

> CGFontCreateWithDataProvider obviously implements an awful lot of magic to 
> deal with the really nasty stuff.

It interprets the actual font files, Type 1, TrueType, etc.

> One final follow-up question though - how do I go from the character strings 
> referenced by Tj and friends to an array of glyphs?

More fun!  

> I see a great function in Core Text: CTFontGetGlyphsForCharacters, but I'm 
> not sure whether I can simply use a CGFontRef here or whether using Core Text 
> is the right way ahead.

Several issues here:  the encoding inside the font (the one created by 
CGFontCreateWithDataProvider() may not be the encoding that is used.   The 
/Font has an encoding, specified as a predefined encoding ( MacRoman, …)  
and/or an encoding array, either of these map characters to glyph names.  Then 
you need to map the glyph names back to glyph indexes for your particular font.

Other times (especially with TrueType fonts), there is no encoding vector and 
instead you need to figure out the mapping from data inside the font.  Type0 
fonts, on the other hand, have cmaps that define the mapping of characters to 
font / glyph pairs (and how characters are assembled from the strings).

> Since my ultimate aim isn't to render the PDF but to create a set of 
> corresponding editable objects, it might be possible to assemble an 
> NSAttributedString object and try and figure out what its bounding box would 
> have ended up as had it been rendered.

Then you need to map from PDF characters to Unicode.  If the /Font has a 
ToUnicode entry you’re in luck, because that will contain a cmap that does what 
it says on the tin.  If it isn’t, you have to hope that the Encoding vector is 
valid and not obscured, otherwise you’re going have to do n-gram analysis or 
look at character shapes…

Cheers,

Marcel

_______________________________________________

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

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

Reply via email to