0

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])
Vladimir
  • 170,431
  • 36
  • 387
  • 313
Tom
  • 65
  • 3
  • 8
  • Why in the world are you using the NextStep Latin string encoding? – Chuck Oct 18 '10 at 17:29
  • Because this encoding gives me at least all the characters back, except Umlaut(e). other encodings like utf8 or ascii provided me with an worse result... – Tom Oct 20 '10 at 11:37

2 Answers2

1

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
  • 84,577
  • 15
  • 123
  • 161
  • 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 Oct 20 '10 at 11:38
  • 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 Oct 20 '10 at 12:24
  • 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 Oct 20 '10 at 13:09
-1

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?

Community
  • 1
  • 1
Benedict Cohen
  • 11,912
  • 7
  • 55
  • 67
  • 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 Oct 20 '10 at 11:42