Skip to content

Commit

Permalink
annotate pdffont
Browse files Browse the repository at this point in the history
  • Loading branch information
0xabu committed Sep 4, 2021
1 parent 4b689f1 commit 0ab5863
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 113 deletions.
14 changes: 8 additions & 6 deletions pdfminer/encodingdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import re
from typing import Any, Dict, Iterable, Optional, cast

from .glyphlist import glyphname2unicode
from .latin_enc import ENCODING
Expand Down Expand Up @@ -72,10 +73,10 @@ def raise_key_error_for_invalid_unicode(unicode_digit: int) -> None:

class EncodingDB:

std2unicode = {}
mac2unicode = {}
win2unicode = {}
pdf2unicode = {}
std2unicode: Dict[int, str] = {}
mac2unicode: Dict[int, str] = {}
win2unicode: Dict[int, str] = {}
pdf2unicode: Dict[int, str] = {}
for (name, std, mac, win, pdf) in ENCODING:
c = name2unicode(name)
if std:
Expand All @@ -95,7 +96,8 @@ class EncodingDB:
}

@classmethod
def get_encoding(cls, name, diff=None):
def get_encoding(cls, name: str, diff: Optional[Iterable[Any]] = None
) -> Dict[int, str]:
cid2unicode = cls.encodings.get(name, cls.std2unicode)
if diff:
cid2unicode = cid2unicode.copy()
Expand All @@ -105,7 +107,7 @@ def get_encoding(cls, name, diff=None):
cid = x
elif isinstance(x, PSLiteral):
try:
cid2unicode[cid] = name2unicode(x.name)
cid2unicode[cid] = name2unicode(cast(str, x.name))
except (KeyError, ValueError) as e:
log.debug(str(e))
cid += 1
Expand Down
7 changes: 6 additions & 1 deletion pdfminer/latin_enc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"""

ENCODING = [
from typing import List, Optional, Tuple

EncodingRow = \
Tuple[str, Optional[int], Optional[int], Optional[int], Optional[int]]

ENCODING: List[EncodingRow] = [
# (name, std, mac, win, pdf)
('A', 65, 65, 65, 65),
('AE', 225, 174, 198, 198),
Expand Down
Loading

0 comments on commit 0ab5863

Please sign in to comment.