views:

21

answers:

1

Hello All.

I have a problem about the font in iphone/ipad

Everyone knows UILabel can't do rich text.

So I choose FrontLabel http://github.com/zynga/FontLabel/blob/master/README

I guess what FrontLabel is doing is something like NSAttributedString and core text framework, and also, it is quite low level. But anyway, I have a problem.

If I want to display a mixed language text, let's say English + Chinese, and give the whole string a font of "ArialMT", then all Chinese characters are displayed like small squares.

I have tried, if I assign "STHeitiTC-Light" font to the text, no problem, both Chinese and English can be displayed, because STHeitiTC-Light is a Chinese font in iphone/ipad.

I think FrontLabel can't automatically select best font for non-latin text if the given font does not apply.

If I use UILabel and assign it as "ArialMT", and let it display text of Chinese or Japanese, NO problem, right? I guess apple is detecting font for different language?

Please give me some clues how can I solve this problem if I want to use FrontLabel?

Thanks

+1  A: 

Hi Jack, author of FontLabel here.

You're right, FontLabel does not do automatic font fallback if the glyph cannot be found in the selected font. Implementing such a behavior was outside the scope of the project, as it can be quite complex. UILabel does perform this, as it uses WebKit to do the actual text rendering and WebKit supports font fallback. I am unsure if CoreText provides this or if it behaves like FontLabel. In any case, if you need multiple fonts in FontLabel, you can specify different fonts for different ranges of your ZAttributedString. Unfortunately there's no easy way to determine which ranges are necessary without inspecting your string directly. If you know you're only working with English and Chinese, you could iterate over the characters in your string to determine if they're likely to be english or chinese characters, and use that to determine which ranges to assign fonts to. The alternative would be to teach FontLabel how to perform font fallback, but as I said before, that's quite complicated.

Alternatively, if you're comfortable require 4.0 or above on iPhone, you can try using CoreText. As I said before, I'm unsure if it does font fallback, but it's worth investigating.

Kevin Ballard
Hello Kevin, thanks for making FontLabel. It is a very good class and very easy to use. Unfortunately, I just have to deal with multiple languages. I am right now using Three20, heavy but did the job. Thanks for your explanation.
Jack