Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

iphone - Custom Arabic font in iOS

I am trying to make an iphone application that displays mainly Arabic language content. I want to use a custom Arabic font for displaying that content, not the iPhone default Arabic font. I used the following code:

- (void)viewDidLoad {
    [super viewDidLoad];
    [arabicLabel setFont: [UIFont fontWithName: @"Simple Indust Shaded" size: 20]];
    arabicLabel.text = @"?????? ?????";
}

where arabicLabel is an IBOutlet UILabel. I put the label in the App resources and add it to the info.plist file as UIAppFont array item. Also the font is Unicode.

When I run this code on the simulator, the label displayed the default Arabic font (not my custom font); however it set its size to 20 as stated in the code!

I don't understand what I did wrong here... I know that in the info.plist file I must add the font file name with extension (ttf), and I did that. Also, I know that in the previous code I had to put the actual font name not file name, so I opened the file in my Mac and used the title that appeared when the file is opened (Simple Indust Shaded).

Am I missing something? Are there any extra requirements for custom fonts other than being Unicode?

NB: I did the same procedure for custom English font, and it worked!...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Short answer

This seems to be a bug in iOS.

Long answer

As you may know, the arabic text needs to be shaped before it can be rendered, that means converting the basic letters (Unicode:0600-06FF) to their proper corresponding contextual letters (Unicode:FE70-FEFF).

iOS does this preprocessing automatically for arabic text, but for some reason, it forgets about the custom font and just uses system default font when it renders the connected letters.

So, it's a bug in iOS and you should wait for it to be solved.

Workaround

Though, if you can't wait, you can use this workaround: Do the preprocessing of the text manually before rendering it. This will allow skipping iOS preprocessing phase which causes this issue and thus rendering the text using your custom font.

If you want to test this solution, just copy this following line and try it in your project:

arabicLabel.text = @"????? ?????";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...