You might give https://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_text/dq_text.html a closer read.
You can draw any encoding using CGContextShowGlyphsAtPoint
instead of CContextShowTextAtPoint
so you can tell it what the encoding is. If the user types it then you'll be getting the string as an NSString which is a Unicode string underneath. Probably the easiest is going to be to get the utf8 encoding of that user entered string via NSString
's UTF8String
method.
If you really want to stick with the very limited MacRoman for some reason, then use NSString
's cStringUsingEncoding:
passing in NSMacOSRomanStringEncoding
to get a MacRoman string. Read the documentation on this in NSString
though. Will return null if the user string can't be encoded in MacRoman losslessly. As it discusses you can use dataUsingEncoding:allowLossyConversion:
and canBeConvertedToEncoding:
to check. Read the cautions in the Discussion for cStringUsingEncoding:
about about lifecycle of the returned strings though. getCString:maxLength:encoding:
might end up being a better choice for you. All discussed in the class documentation for NSString
.