iOS 中的自定义阿拉伯字体
我正在尝试制作一个主要显示阿拉伯语内容的 iPhone 应用程序。我想使用自定义阿拉伯字体来显示该内容,而不是 iPhone 默认的阿拉伯字体。我使用了以下代码:
- (void)viewDidLoad {
[super viewDidLoad];
[arabicLabel setFont: [UIFont fontWithName: @"Simple Indust Shaded" size: 20]];
arabicLabel.text = @"السلام عليكم";
}
其中 arabicLabel 是 IBOutlet UILabel。我将标签放入应用程序资源中,并将其作为 UIAppFont 数组项添加到 info.plist 文件中。字体也是 Unicode。
当我在模拟器上运行此代码时,标签显示默认的阿拉伯字体(不是我的自定义字体);然而,如代码中所述,它将其大小设置为 20!
我不明白我在这里做错了什么...我知道在 info.plist 文件中我必须添加带有扩展名(ttf)的字体文件名,我就是这么做的。另外,我知道在前面的代码中我必须输入实际的字体名称而不是文件名,因此我在 Mac 中打开该文件并使用打开文件时出现的标题(Simple Indust Shaded)。
我错过了什么吗?除了 Unicode 之外,自定义字体还有其他要求吗?
注意:我对自定义英文字体做了相同的过程,并且成功了!...
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!...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短回答
这似乎是 iOS 中的一个错误。
长答案
如您所知,阿拉伯文本需要在渲染之前进行整形,这意味着转换基本字母 (Unicode:0600-06FF) 到其正确对应的上下文字母 (统一码:FE70-FEFF)。
iOS 自动对阿拉伯语文本进行此预处理,但由于某种原因,它会忘记自定义字体,而在渲染连接的字母时仅使用系统默认字体。
所以,这是iOS的一个bug,你应该等待它被解决。
解决方法
不过,如果您等不及,可以使用以下解决方法:
手动对文本进行预处理 在渲染之前。这将允许跳过导致此问题的 iOS 预处理阶段,从而使用您的自定义字体渲染文本。
如果您想测试此解决方案,只需复制以下行并在您的项目中尝试:
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:
这个答案适用于 iOS 7 以下。
我也经历过这种情况,您可以创建自己的哈希映射方法,用您的自定义字体替换 0600-06ff 字符,但为此您需要检查 TTF 中的字形是否已映射针对 0600-06FF 比你需要修改你的字形映射的 unicode 除了 0600-06ff
例如,如果我制作了一个 TTF 并使用 unicode 0627 映射了“œ”,并且当我尝试查看键入的 unicode 0627 字符的效果时(当我键入“??”它必须显示“??”)它不会应用我的自定义图像,因为 ios6 不允许您更改特定范围内的字形。但如果我将这个自定义字符映射到 Fxxx 系列或 0600-06ff 以外的其他字符,它将很容易地允许我进行自定义更改
阿拉伯语(0600—06FF,255 个字符),您无法在此范围内播放或更改这些字形的图像图像与您的自定义图像
所以将你的字形映射到下面的阿拉伯语 unicode
阿拉伯语增补(0750—077F,48 个字符)
阿拉伯语扩展-A(08A0—08FF,39 个字符)
阿拉伯语演示形式-A(FB50—FDFF,608 个字符)
阿拉伯语演示文稿表格-B(FE70—FEFF,140 个字符)
这里是使用自定义阿拉伯语类完成的类似操作的链接,我也从中获得了帮助
阿拉伯语自定义字体类
THIS ANSWER IS FOR BELOW IOS 7.
I have also gone through this situation u can create your own hash map method for the replacement of 0600-06ff char with ur custom font but for that u need to check if your glyph in the TTF is mapped against 0600-06FF than u need to modify ur glyph mapped unicode except from 0600-06ff
for example if i made a TTF and mapped 'و' with unicode 0627 and when i try to see the effect of typed unicode 0627 char i.e(when i type 'ا' it must show 'و') it will not apply my custom image against it because ios6 will not allow u to change the glyph on the particular range . but if i would have mapped this custom char with Fxxx series or other than of 0600-06ff it will easily allow me to made custom change
Arabic(0600—06FF, 255 characters) u cannot play on this range or change the image of these glyph image with your custom image
so mapped your glyph against the below arabic unicode
Arabic Supplement (0750—077F, 48 characters)
Arabic Extended-A (08A0—08FF, 39 characters)
Arabic Presentation Forms-A (FB50—FDFF, 608 characters)
Arabic Presentation Forms-B (FE70—FEFF, 140 characters)
here is the link for the similar type of thing done using custom arabic class and i also took help from it
arabic custom font class