gpt4 book ai didi

iphone - iOS Quartz 在 pdf 中嵌入字体

转载 作者:可可西里 更新时间:2023-11-01 03:32:32 24 4
gpt4 key购买 nike

我正在尝试使用自定义字体生成包含具有自定义符号(例如“€”)的文本的 PDF 页面。我使用 UIGraphicsBeginPDFContextToData 和 UIGraphicsBeginPDFPage 创建了一个 PDF 上下文和页面。我用于呈现文本的代码类似于:

NSString *fontFile = [[NSBundle mainBundle] pathForResource:@"somefont.otf" ofType:nil];
CGDataProviderRef dataProvider = CGDataProviderCreateWithFilename([fontFile cStringUsingEncoding:NSASCIIStringEncoding]);
CGFontRef cgfont = CGFontCreateWithDataProvider(dataProvider);
CTFontRef ctfont = CTFontCreateWithGraphicsFont(cgfont, 10, NULL, NULL);
CFRelease(dataProvider);

NSString *text = @"Hello €";
int len = [text length];
CGGlyph glyphs[len];
CTFontGetGlyphsForCharacters(ctfont, (const unichar*)[text cStringUsingEncoding:NSUnicodeStringEncoding], glyphs, len);
CGContextSetTextDrawingMode(_context, kCGTextFill);
CGContextShowGlyphsAtPoint(_context, 10, 10, glyphs, len);
CFRelease(cgfont);
CFRelease(ctfont);

呈现 € 符号有效(因为 CTFontGetGlyphsForCharacters),但字体未嵌入 pdf 中。有什么办法吗?

最佳答案

我为此纠结了很长一段时间,结果发现 TTF 是自动嵌入的,而 OTF 不是。转换我的字体就可以了。

关于iphone - iOS Quartz 在 pdf 中嵌入字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9600085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com