如何在iPhone上显示带有石英/核心图形的国际口音 [英] How to Display International Accents with Quartz/Core Graphics on iPhone

查看:103
本文介绍了如何在iPhone上显示带有石英/核心图形的国际口音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为iPhone本地化了一个应用程序.毫不奇怪,本地化包含一些重音符号:

I've localized an app for the iPhone. No surprise, the localization includes some accents:

"触摸卡以进行选择.然后触摸 'Bid'."=" Touchez les cartes pour les 选举人,puis touchez'Miser'."

"Touch cards to select. Then touch 'Bid'." = "Touchez les cartes pour les sélectionner, puis touchez 'Miser'.";

在高级内容中,这些效果很好,例如当我将文本放入表格中时,但是当我尝试将它们手动写入UIView时,重音就会被弄乱:

These work fine in high-level stuff, like when I put the text into a table, but when I try to write them to a UIView by hand, the accents get mangled:

我使用的是kCGEncodingMacRoman和UTF8,我认为它们都应该支持重音符号,但是我显然缺少了一些东西:

I'm using kCGEncodingMacRoman and UTF8, both of which should support accents, I think, but I'm clearly missing something:

CGContextSelectFont(ctx,fontName,thisWriting.fontSize,kCGEncodingMacRoman);
CGContextShowTextAtPoint(ctx,
                        thisWriting.center.x - floor(thisTextSize.width/2),
                        yThusFar,
                        [thisText UTF8String],
                        [thisText length]);

字体是ArialMT的某些变体. thisText只是一个NSString.

The font is some variant of ArialMT. thisText is just an NSString.

推荐答案

要进一步解释sorin所说的话:Quartz/Core Graphics不支持Unicode文本,其中包括您需要使用外语的重音符号.传统上,有许多替代方法可以解决此问题,但目前最好的答案是使用Core Text,该Core Text可以像我在此处所做的那样直接写入图形上下文.

To expand on what sorin said: Quartz/Core Graphics do not support Unicode text, which includes the accents you need for foreign languages. There have traditionally been a number of alternative ways to resolve this, but currently the best answer is to use Core Text, which can write directly to a graphical context, as I was doing here.

Core Text中的主要元素是NSAttributedString或NSMutableAttributed String类.

The main element in Core Text is the NSAttributedString or NSMutableAttributed String class.

这里的代码与我对Core Text的代码类似:

Here's similar code to what I had for Core Text:

CTLineRef thisLine = CTLineCreateWithAttributedString((CFAttributedStringRef)thisAText);
CGContextSetTextPosition(ctx, self.center.x - floor(thisTextSize.width/2), yThusFar);
CTLineDraw(thisLine, ctx);

字体已经被使用,因为它是NSAttributedString(或CFAttributedStringRef,它是免费的桥接等效语言)的一部分.

The font is already taken care of, because it's part of that NSAttributedString (or CFAttributedStringRef, which is a toll-free bridged equivalent).

结果如下:

这篇关于如何在iPhone上显示带有石英/核心图形的国际口音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆