gpt4 book ai didi

objective-c - PDF:字符代码 -> 字形名称 -> NSString

转载 作者:搜寻专家 更新时间:2023-10-30 19:46:26 24 4
gpt4 key购买 nike

在跟进我之前的问题时,尝试使用 CGPDF* 函数从 PDF 文件中提取文本,具有:

CGPDFStringRef pdfString

我发现它可以转换成这样的字符代码数组:

const unsigned char *characterCodes = CGPDFStringGetBytePtr(pdfString);

现在,我要提取的文本是用 14 种 1 类基本字体之一编写的,它没有在 PDF 本身中编码。因此,我已经为该字体解析了相关的 AFM 文件,为我提供了从字符代码到字形名称的映射,它的尺寸如下所示:

C 61 ; WX 600 ; N equal ; B 80 138 520 376 ;
C 63 ; WX 600 ; N question ; B 129 -15 492 572 ;
C 64 ; WX 600 ; N at ; B 77 -15 533 622 ;
C 65 ; WX 600 ; N A ; B 3 0 597 562 ;
C 66 ; WX 600 ; N B ; B 43 0 559 562 ;

我的问题是,知道字符代码,比如:"61" 我如何从它的字形名称:"equal"NSString @ “=”。特别是当该字符代码被 PDF 的字体编码选项重新映射到其他字形名称时,例如:“question”

以前的问题: iOS PDF parsing Type 1 Fonts metricsiOS PDF to plain text parser

最佳答案

我没有测试过这个,但在我看来你需要使用 Adobe Glyph Naming convention为此:

The purpose of the Adobe Glyph Naming convention is to support the computation of a Unicode character string from a sequence of glyphs. This is achieved by specifying a mapping from glyph names to character strings.

glyphlist.txt该页面上的链接似乎与您的问题相关。
示例片段:

...
epsilon;03B5
epsilontonos;03AD
equal;003D
equalmonospace;FF1D
equalsmall;FE66
equalsuperior;207C
...

那么您需要做的就是putting those unicode values in your NSString instance .

编辑:
确认上面提供的信息,我在PDF Reference Document from Adobe上找到了如下解释,第 5.9 节 - 提取文本内容:

If the font is a simple font that uses one of the predefined encodings MacRomanEncoding, MacExpertEncoding, or WinAnsiEncoding, or that has an encoding whose Differences array includes only character names taken from the Adobe standard Latin character set and the set of named characters in the Symbol font (see Appendix D):

  1. Map the character code to a character name according to Table D.1 on page 996 and the font’s Differences array.
  2. Look up the character name in the Adobe Glyph List (see the Bibliography) to obtain the corresponding Unicode value.

关于objective-c - PDF:字符代码 -> 字形名称 -> NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12795525/

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