diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 958b4512..1cd7d7ac 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -21,6 +21,7 @@ v9.0.5 - The primary Docker image (jbarlow83/ocrmypdf) has been improved to take on the extra features that used to be exclusive to the Alpine image. - No changes to application code. +- pdfminer.six version 20191020 is now supported. v9.0.4 ====== diff --git a/requirements/main.txt b/requirements/main.txt index eec5dc7a..f7c2275f 100644 --- a/requirements/main.txt +++ b/requirements/main.txt @@ -3,7 +3,7 @@ # installation cffi == 1.13.2 img2pdf == 0.3.3 -pdfminer.six == 20181108 +pdfminer.six == 20191020 pikepdf == 1.6.5 Pillow >= 6.2.0 reportlab == 3.5.32 diff --git a/setup.py b/setup.py index b7d2e2d7..1dcebd40 100644 --- a/setup.py +++ b/setup.py @@ -96,7 +96,7 @@ setup( 'chardet >= 3.0.4, < 4', # unlisted requirement of pdfminer.six 20181108 'cffi >= 1.9.1', # must be a setup and install requirement 'img2pdf >= 0.3.0, < 0.4', # pure Python, so track HEAD closely - 'pdfminer.six == 20181108', + 'pdfminer.six >= 20181108, <= 20191020', 'pikepdf >= 1.6.5, < 2', 'Pillow >= 6.2.0', 'reportlab >= 3.3.0', # oldest released version with sane image handling diff --git a/src/ocrmypdf/pdfinfo/layout.py b/src/ocrmypdf/pdfinfo/layout.py index 9bb7f3a5..31d0e8eb 100644 --- a/src/ocrmypdf/pdfinfo/layout.py +++ b/src/ocrmypdf/pdfinfo/layout.py @@ -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 #