如何在PDF中输出欧元符号 [英] How to output a Euro symbol in a PDF

查看:390
本文介绍了如何在PDF中输出欧元符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Core Graphics输出欧元符号到PDF。我有以下代码,它使用NSMacOSRomanStringEncoding(我不得不使用这个来获得£和$符号出现正确),但欧元符号出来作为

  CGRect pageRect = CGRectMake(0,0,800,1150); 
CFMutableDataRef pdfData =(CFMutableDataRef)[NSMutableData dataWithCapacity:0];
CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData(pdfData);
CGContextRef pdfContext = CGPDFContextCreate(dataConsumer,& pageRect,nil);

CGContextSelectFont(pdfContext,Helvetica,15,kCGEncodingMacRoman);
CGContext SetTextDrawingMode(pdfContext,kCGTextFill);
CGContextSetRGBFillColor(pdfContext,0,0,0,1);
const char * ctext = [@€cscringUsingEncoding:NSMacOSRomanStringEncoding];
CGContextShowTextAtPoint(pdfContext,10,10,ctext,strlen(ctext));


解决方案

您应该能够使用 CGContextShowGlyphsAtPoint 来绘制欧元符号。 catch是你需要传递该函数 CGGlyph 作为输入,而不是一个Unicode字符。此外,从Unicode字符到 CGGlyphs 的映射是与字体相关的,并且通常是非平凡的。 (有时它是一个简单的偏移,你可以猜测基于试验和错误。)



看起来像Core Text有一个函数 CTFontGetGlyphsForCharacters 其可以执行变换;我从未在实践中使用它:



http://developer.apple.com/library/mac/#documentation/Carbon/Reference/CTFontRef/Reference/reference.html

此外:如果使用 CGContextShowGlyphsAtPoint ,您需要将调用替换为 CGContextSelectFont CGContextSetFont CGContextSetFontSize


I am trying to output a Euro symbol to a PDF using Core Graphics. I have the following code, which uses NSMacOSRomanStringEncoding (I had to use this to get £ and $ symbols to appear correctly), but the Euro symbol comes out as ¤

CGRect pageRect = CGRectMake(0, 0, 800, 1150);
CFMutableDataRef pdfData = (CFMutableDataRef) [NSMutableData dataWithCapacity:0];                     
CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData(pdfData);
CGContextRef pdfContext = CGPDFContextCreate(dataConsumer, &pageRect, nil);

CGContextSelectFont(pdfContext, "Helvetica", 15, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
const char *ctext = [@"€" cStringUsingEncoding:NSMacOSRomanStringEncoding];
CGContextShowTextAtPoint(pdfContext, 10, 10, ctext, strlen(ctext));

解决方案

You should be able to use CGContextShowGlyphsAtPoint to draw the Euro symbol. The catch is that you need to pass that function a CGGlyph as input, rather than a Unicode character. Furthermore, the mapping from Unicode characters to CGGlyphs is font-dependent and often nontrivial. (Sometimes it's a simple offset that you can guess based on trial and error.)

It looks like Core Text has a function CTFontGetGlyphsForCharacters which might perform the transformation; I've never used it in practice, though:

http://developer.apple.com/library/mac/#documentation/Carbon/Reference/CTFontRef/Reference/reference.html

Also: if you use CGContextShowGlyphsAtPoint you will need to replace the call to CGContextSelectFont with CGContextSetFont and CGContextSetFontSize instead.

这篇关于如何在PDF中输出欧元符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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