Re: Drawing Chinese text to PDF
Re: Drawing Chinese text to PDF
- Subject: Re: Drawing Chinese text to PDF
- From: David Duncan <email@hidden>
- Date: Thu, 11 Aug 2011 11:04:14 -0700
On Aug 11, 2011, at 10:57 AM, Stevo Brock wrote:
> We have an existing PDF Report creation module in one of our apps that is working great... for English text. This is what we are doing:
>
> NSFont* font = [NSFont fontWithName:@"Helvetica" size:12.0];
> CGContextSelectFont(state->mContextRef, [[font fontName] UTF8String], [font pointSize], kCGEncodingMacRoman);
>
> NSData* data = [string dataUsingEncoding:NSMacOSRomanStringEncoding];
> CGContextShowTextAtPoint(state->mContextRef, drawPt.x, drawPt.y, (char*) data.bytes, data.length);
>
> We have a user who is entering Chinese text, which is obviously not making it to the PDF through this mechanism.
Chinese text (and most non-Western text) can't be represented in MacRoman. As a general rule, this method of drawing text is highly discouraged, at minimum because of its limited text support.
> What is the recommended approach for taking an NSString* of text and drawing it to a CGContextRef where the text may contain characters of any language?
For simple needs, the NSString additions (on either Mac OS X or iOS) would be recommended. There are platform specific methods for making a CGContextRef current. For more complex needs, NSLayoutManager (Mac OS X only) or Core Text (both) can be used as well.
--
David Duncan
_______________________________________________
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