Special Characters (German Umlaute) won't display correctly using a different font
Hi,
I'm displaying a German text with some special characters (so-called Umlaute: ä, ö, ü, Ä, Ö, Ü) in a custom font (Droid). The font itself includes those characters and it works just fine using an UILabel.
But OHAttributedLabel displays these characters in the system font.
An example: https://img.skitch.com/20111228-d3amjt7impaya3nnrh3j6puu1p.jpg
A fix would be highly appreciated.
Thanks!
Hello and thanks for this bug report
I already had this kind of issue too (I am french and writing letters with accents sometimes had this behavior with some fonts) and already investigated this... but unfortunately this is not an issue of OHAttributedLabel, but one of CoreText itself! This means that there is no official fix except changing the font used and file a bugreport to bugreport.apple.com to make them fix this in CoreText.framework.
Note that fonts included in the CoreText framework are sometimes not exactly the same as the ones in UIKit (maybe missing some umlaute characters especially, that are present in the UIKit variation but not the CoreText variation?).
Maybe as a workaround try to use the decomposed form of the unicode character instead of the precomposed form, as the decomposed form makes the glyph to be drawn in two steps (the base letter and the accent/umlaut separately), probably have more chance to be drawn using the correct font (as the base letter and the standalone umlaut glyph are probably both present in the CoreText) whereas the precomposed form draws the already-precomposed ü or ä character (and if this precomposed glyph is not present in the CoreText font CoreText probably substitute the font with the system font?)
This makes the text need some preprocessing in the NSAttributedString but there is already all the methods needed in the framework to decompose an Unicode NSString so this should not be too complicated depending on how you build your NSAttributedString.
(see pages like this http://jongampark.wordpress.com/2008/07/21/unicode-normalization-and-nsstring/ found on Google and many others)
Hi,
thanks for the explanation and the possible workaround. I tried your suggestions but using the decomposedStringWithXYZMapping methods didn't show any effect. I guess I either have to live with it or I should look into displaying the text with an UIWebView.
Keep the great work up, developing apps without your Label would be pain :)
I figured it out!
The problem was that the text contained a decomposed form of those characters in the first place. Funny enough, NSString could not fix that with it's precomposedStringWith
So thank you!
Cool, thanks for the feedback !
Strange that precomposedStringWith<X>Mapping doesn't fix it !
Did you try to use CoreFoundation and some ICU to transform the string to its NFC form?
CFMutableStringRef cfMutStr = (CFMutableStringRef)yourNSMutableString;
CFStringNormalize(cfMutStr, kCFStringNormalizationFormC); // or kCFStringNormalizationFormKC ?
That's what precomposedStringWith<X>Mapping is supposed to do, but in last resort…