java欧元货币输出符号位置,如何在PDF中输出欧元符号

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:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值