我正在尝试使用 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);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
const char *ctext = [@"€" cStringUsingEncoding:NSMacOSRomanStringEncoding];
CGContextShowTextAtPoint(pdfContext, 10, 10, ctext, strlen(ctext));
最佳答案
那是因为 MacRomanEncoding
默认情况下不包含欧元符号,请参阅“PDF 引用 1.7”(第 D.1 节拉丁字符集和编码)中的引用:
- In PDF 1.3, the euro character was added to the Adobe standard Latin character set. It is encoded as 200 in WinAnsiEncoding and 240 in PDFDocEncoding, assigning codes that were previously unused. Apple changed the Mac OS Latin-text encoding for code 333 from the currency character to the euro character. However, this incompatible change has not been reflected in PDF’s MacRomanEncoding, which continues to map code 333 to currency. If the euro character is desired, an encoding dictionary can be used to specify this single difference from MacRomanEncoding.
关于iphone - 如何在 PDF 中输出欧元符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7505143/