对于不同系统文字乱码的情况的分析:主要是因为每个地区都使用自己的编码标准,虽然相同的二进制码,但在不同的语言系统中对应的字符却不一样。如何解决全球字符统一的问题呢? UNICODE就是为此而诞生的。
现在我就谈一下MAC平台下XCODE对UNICODE的显示支持。MAC操作系统从X系列后就开始支持UNICODE的显示了。如何在XCODE中对UNICODE码做显示呢?
苹果下的绘图环境分为QuickDraw 和 Quartz,但是两者都是建立在OpenGL的绘图环境上的,都是对OpenGL的封装。
每一个绘图环境都有一个对应的Context,相当于Windows 下得DC,这个绘图环境可以指向窗口,也可以指向BMP文件,或是内存文件。
1:Get a Context
首先要获取一个Context。 QuickDraw下可以通过通过QDBeginCGContext 函数将一个Cgrafpt 的对象穿换成一个 Context 对象,整个结束后可以通过QDEndCGContext来释放。
2:Creating a Text layout Object
Object: ATSUTextLayout myTextLayout;
Create: ATSUCreateTextLayoutWithTextPtr(
(UniChar *)dataPtr, // point Unicode data
KATSUFromTextBeginning, // offset from beginning
myTextBlockLength, // length of the text range
1, // number of style runs
KATSUToTextEnd, // length of the style run
&myArrayOfStyleObjects,
&myTextLayout);
3:Set the layout Object attributes
Line Object:
ATSUAttributeTag theTags[] = {KATSULineFlushFactorTag,
KATSULineJustificationFactorTag};
ByteCount theSizes[] = {sizeof(Fract), sizeof(Fract)};
Fract myFlushFactor = KATSUStartAlignment;
Fract myJustFactor = KatsuFullJustification;
ATSUAttributeValuePtr theValue[] = {& myFlushFactor, & myJustFactor};
Associate the line and layout Attributes with text layout:
ATSUSetLayoutControl ( myTextLayout, 2,
theTags, theSizes, theValuse);
Context Object:
ATSUAttributeTag theTags[0] = {KATSUCGContextTag};
ByteCount theSize[0] = sizeof(CGContextRef);
ATSUAttributeValuePtr theValue[] = &myCGContext;
Associate the line and layout Attributes with text layout:
ATSUSetLayoutControl ( myTextLayout, 1,
theTags, theSizes, theValuse);
4: Drawing Text
ATSUDrawText( myTextLayout, KATSUFromTextBeginning, KATSUToTextEnd,
myXLocation, myYLocation);
OK!以上就是XCODE下对UNICODE的显示支持,希望能帮助大家。