|
|
|
@@ -20,6 +20,7 @@ from math import copysign
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
|
|
import pdfminer
|
|
|
|
|
import pdfminer.encodingdb
|
|
|
|
|
import pdfminer.pdfdevice
|
|
|
|
|
import pdfminer.pdfinterp
|
|
|
|
@@ -36,51 +37,54 @@ from ..exceptions import EncryptedPdfError
|
|
|
|
|
STRIP_NAME = re.compile(r'[0-9]+')
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Unconditional pdfminer patches
|
|
|
|
|
# pdfminer 20181108 patches
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if pdfminer.__version__ == '20181108':
|
|
|
|
|
|
|
|
|
|
def name2unicode(name):
|
|
|
|
|
"""Fix pdfminer's name2unicode function
|
|
|
|
|
def name2unicode(name):
|
|
|
|
|
"""Fix pdfminer's name2unicode function
|
|
|
|
|
|
|
|
|
|
Font cids that are mapped to names of the form /g123 seem to be, by convention
|
|
|
|
|
characters with no corresponding Unicode entry. These can be subsetted fonts
|
|
|
|
|
or symbolic fonts. There seems to be no way to map /g123 fonts to Unicode,
|
|
|
|
|
barring a ToUnicode data structure.
|
|
|
|
|
"""
|
|
|
|
|
if name in glyphname2unicode:
|
|
|
|
|
return glyphname2unicode[name]
|
|
|
|
|
if name.startswith('g') or name.startswith('a'):
|
|
|
|
|
raise KeyError(name)
|
|
|
|
|
if name.startswith('uni'):
|
|
|
|
|
try:
|
|
|
|
|
return chr(int(name[3:], 16))
|
|
|
|
|
except ValueError: # Not hexadecimal
|
|
|
|
|
Font cids that are mapped to names of the form /g123 seem to be, by convention
|
|
|
|
|
characters with no corresponding Unicode entry. These can be subsetted fonts
|
|
|
|
|
or symbolic fonts. There seems to be no way to map /g123 fonts to Unicode,
|
|
|
|
|
barring a ToUnicode data structure.
|
|
|
|
|
"""
|
|
|
|
|
if name in glyphname2unicode:
|
|
|
|
|
return glyphname2unicode[name]
|
|
|
|
|
if name.startswith('g') or name.startswith('a'):
|
|
|
|
|
raise KeyError(name)
|
|
|
|
|
m = STRIP_NAME.search(name)
|
|
|
|
|
if not m:
|
|
|
|
|
raise KeyError(name)
|
|
|
|
|
return chr(int(m.group(0)))
|
|
|
|
|
if name.startswith('uni'):
|
|
|
|
|
try:
|
|
|
|
|
return chr(int(name[3:], 16))
|
|
|
|
|
except ValueError: # Not hexadecimal
|
|
|
|
|
raise KeyError(name)
|
|
|
|
|
m = STRIP_NAME.search(name)
|
|
|
|
|
if not m:
|
|
|
|
|
raise KeyError(name)
|
|
|
|
|
return chr(int(m.group(0)))
|
|
|
|
|
|
|
|
|
|
pdfminer.encodingdb.name2unicode = name2unicode
|
|
|
|
|
|
|
|
|
|
pdfminer.encodingdb.name2unicode = name2unicode
|
|
|
|
|
original_PDFFont_init = PDFFont.__init__
|
|
|
|
|
|
|
|
|
|
original_PDFFont_init = PDFFont.__init__
|
|
|
|
|
def PDFFont__init__(self, descriptor, widths, default_width=None):
|
|
|
|
|
original_PDFFont_init(self, descriptor, widths, default_width)
|
|
|
|
|
# PDF spec says descent should be negative
|
|
|
|
|
# A font with a positive descent implies it floats entirely above the
|
|
|
|
|
# baseline, i.e. it's not really a baseline anymore. I have fonts that
|
|
|
|
|
# claim a positive descent, but treating descent as positive always seems
|
|
|
|
|
# to misposition text.
|
|
|
|
|
if self.descent > 0:
|
|
|
|
|
self.descent = -self.descent
|
|
|
|
|
|
|
|
|
|
PDFFont.__init__ = PDFFont__init__
|
|
|
|
|
|
|
|
|
|
def PDFFont__init__(self, descriptor, widths, default_width=None):
|
|
|
|
|
original_PDFFont_init(self, descriptor, widths, default_width)
|
|
|
|
|
# PDF spec says descent should be negative
|
|
|
|
|
# A font with a positive descent implies it floats entirely above the
|
|
|
|
|
# baseline, i.e. it's not really a baseline anymore. I have fonts that
|
|
|
|
|
# claim a positive descent, but treating descent as positive always seems
|
|
|
|
|
# to misposition text.
|
|
|
|
|
if self.descent > 0:
|
|
|
|
|
self.descent = -self.descent
|
|
|
|
|
#
|
|
|
|
|
# end of pdfminer 20181108 patches
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PDFFont.__init__ = PDFFont__init__
|
|
|
|
|
|
|
|
|
|
original_PDFSimpleFont_init = PDFSimpleFont.__init__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -97,6 +101,7 @@ def PDFSimpleFont__init__(self, descriptor, widths, spec):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PDFSimpleFont.__init__ = PDFSimpleFont__init__
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# pdfminer patches when creator is PScript5.dll
|
|
|
|
|
#
|
|
|
|
|