tags:

views:

39

answers:

2

Hi, I am trying to write heaps of text to the screen using a custom font. It all works well but I am having a bit of trouble getting it to work with strings containing a Umlaut. I tried all sorts of encodings with no success. This is what I did... I think it goes wrong when getting the C-Version of a string. the cars-array doesnt contain that character then, hence it wont get added to the glyphs array and finally NOT drawn... :-(

Any suggestions? Thanks Tom

 CGGlyph* Glyphs = malloc(sizeof(CGGlyph) * [textToDraw length]);
 char* Chars = malloc(sizeof(char) * ([textToDraw length] + 1));
 [textToDraw getCString:Chars maxLength: ([textToDraw length] + 1) encoding: NSNEXTSTEPStringEncoding];

 for(int CurrentChar = 0; CurrentChar < [textToDraw length]; ++CurrentChar)
 {
  Glyphs[CurrentChar] = Chars[CurrentChar]- 29;
 }
 CGContextShowGlyphs(UIGraphicsGetCurrentContext(), Glyphs, [textToDraw length])
A: 

If I understand correctly you are trying to store non-asci characters in a file that is being compiled. You can't do that. You have to escape the string like so:

@"The Greek letter Beta looks like this: \u03b2"

See How do I escape a Unicode character in my source code?

Benedict Cohen
No, I am trying to write a string containing umlaut-characters to the screen using CGContextShowGlyphs...But I am happy for any other (fast) way how to determine the length of my (Umlaut-)string.
Tom
+1  A: 

NSNextStepStringEncoding? Does that have an encodings for umlaut characters? If not, your conversion will fail (or at least skip the characters it can't convert).

JeremyP
exactly. but other encodings wont work as well.whats the correct way to draw a string containing umlaut characters with CGContextShowGlyphs?????? (or measure a string containing umlaut characters)
Tom
I wouldn't use CGContextShowGlyphs. I'd use the text drawing functions. If you really need to use the glyphs directly, you'll need to convert the characters one by one into the glyph numbers. Be careful that even in UTF-16, not all characters are represented by one unichar.
JeremyP
thanks for your input. well I have to measure the length of the string I am drawing. Thats why I have to use this CGContextShowGlyphs-function. but of course if you know a nicer way doing that, please let me know.
Tom