Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7722b99f70 | ||
|
|
66b5fea65c | ||
|
|
659b19dae9 | ||
|
|
337c1b4a76 | ||
|
|
76deefb9dc | ||
|
|
e51618231d |
No files matched your search
+9
-1
@@ -4,7 +4,15 @@ WK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd $WK_DIR
|
||||
cd ..
|
||||
|
||||
sh bin/clean/sh
|
||||
sh bin/clean.sh
|
||||
|
||||
python setup.py sdist bdist_wheel
|
||||
|
||||
git add .
|
||||
git commit -m "Deployong new version - $(cat .version)"
|
||||
git push
|
||||
|
||||
git tag $(cat .version)
|
||||
git push -u origin $(cat .version)
|
||||
|
||||
twine upload dist/*
|
||||
@@ -27,3 +27,7 @@ def update_pdfmajor__init___(version: str, doc: str):
|
||||
long_description=doc,
|
||||
version_tuple=re.sub(r"\.", ", ", version, count=2)
|
||||
))
|
||||
|
||||
def update_current_version_lock(version: str):
|
||||
with open(".version", 'w') as file:
|
||||
file.write("v"+version)
|
||||
@@ -75,7 +75,7 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
||||
__version__ = (1, 1, 1)
|
||||
__version__ = (1, 1, 4)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(
|
||||
|
||||
@@ -42,8 +42,8 @@ class HTMLConverter(PDFConverter):
|
||||
self.__current_width = None
|
||||
self.write_header()
|
||||
|
||||
def write(self, text: str):
|
||||
text = " "*self.__levels_deep + text + '\n'
|
||||
def write(self, text: str, lineend: str = '\n', deep_space: str = ' '):
|
||||
text = deep_space*self.__levels_deep + text + lineend
|
||||
self.write_raw(text)
|
||||
|
||||
def write_raw(self, text):
|
||||
@@ -78,7 +78,13 @@ class HTMLConverter(PDFConverter):
|
||||
self.__levels_deep -= 1
|
||||
|
||||
@contextmanager
|
||||
def place_elm_with_child(self, tag_name: str, attr_dict: Dict[str, str] = {}, css: Dict[str, str] = None):
|
||||
def place_elm_with_child(self, tag_name: str, attr_dict: Dict[str, str] = {}, css: Dict[str, str] = None, no_additional_char = False):
|
||||
lineend = '\n'
|
||||
deep_space = ' '
|
||||
if no_additional_char:
|
||||
lineend = ''
|
||||
deep_space = ''
|
||||
|
||||
if css is not None:
|
||||
attr_dict['style'] = ";".join([
|
||||
f'{name}: {value}'
|
||||
@@ -88,11 +94,11 @@ class HTMLConverter(PDFConverter):
|
||||
f'{name}="{value}"'
|
||||
for name, value in attr_dict.items()
|
||||
])
|
||||
self.write(f"<{tag_name} {attrs}>")
|
||||
self.write(f"<{tag_name} {attrs}>", lineend=lineend)
|
||||
self.__levels_deep += 1
|
||||
yield
|
||||
self.__levels_deep -= 1
|
||||
self.write(f"</{tag_name}>")
|
||||
self.write(f"</{tag_name}>", deep_space=deep_space)
|
||||
|
||||
def place_elm_close(self, tag_name: str, attr_dict: Dict[str, str] = {}, css: Dict[str, str] = None, as_childless = True):
|
||||
if css is not None:
|
||||
@@ -201,28 +207,39 @@ class HTMLConverter(PDFConverter):
|
||||
self.place_image(item)
|
||||
elif isinstance(item, LTChar):
|
||||
with self.place_elm_with_child('span', { 'class': 'char' }, {
|
||||
'font-size': f'{item.size}px',
|
||||
'font-family': item.fontname,
|
||||
'font-weight': 'bold' if 'bold' in item.fontname.lower() else '',
|
||||
'color': get_color(item.graphicstate.ncolor),
|
||||
'position': 'absolute',
|
||||
'left': f'{item.x0}',
|
||||
'bottom': f'{item.y0}',
|
||||
'transform': f'skew({item.font.italic_angle}deg, 0deg)'
|
||||
'width': item.width,
|
||||
'min-width': item.width,
|
||||
'max-width': item.width,
|
||||
'height': item.height,
|
||||
'min-height': item.height,
|
||||
'max-height': item.height,
|
||||
}):
|
||||
self.write(item.get_text())
|
||||
elif isinstance(item, LTCharBlock):
|
||||
with self.place_elm_with_child('span', { 'class': 'char-block' }, {
|
||||
'font-size': f'{item.size}px',
|
||||
'font-family': item.fontname,
|
||||
'font-weight': 'bold' if 'bold' in item.fontname.lower() else '',
|
||||
'color': get_color(item.graphicstate.ncolor),
|
||||
'position': 'absolute',
|
||||
'left': f'{item.x0}',
|
||||
'bottom': f'{item.y0}',
|
||||
'transform': f'skew({item.font.italic_angle}deg, 0deg)'
|
||||
}):
|
||||
self.write(item.get_text())
|
||||
'position': 'absolute',
|
||||
'left': f'{item.x0}',
|
||||
'bottom': f'{item.y0}',
|
||||
'text-align': 'justify',
|
||||
'font-size': f'{item.size}px',
|
||||
'font-family': item.fontname,
|
||||
'font-weight': item.font.font_weight,
|
||||
'color': get_color(item.graphicstate.ncolor),
|
||||
'width': item.width,
|
||||
'min-width': item.width,
|
||||
'max-width': item.width,
|
||||
'height': item.height,
|
||||
'min-height': item.height,
|
||||
'max-height': item.height,
|
||||
'transform': f'skew({item.font.italic_angle}deg, 0deg)',
|
||||
'text-align': 'center',
|
||||
'display': 'flex',
|
||||
'flex-flow': 'row nowrap',
|
||||
'justify-content': 'space-between',
|
||||
'padding-left': item.font.leading
|
||||
}):
|
||||
for char in item:
|
||||
render(char)
|
||||
render(ltpage)
|
||||
|
||||
def close(self):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
from typing import Dict
|
||||
|
||||
@@ -30,6 +31,12 @@ def get_color(col: PDFGraphicStateColor):
|
||||
return f'gray({color_val})'
|
||||
return ""
|
||||
|
||||
FIRST_CAP_RE = re.compile('(.)([A-Z][a-z]+)')
|
||||
ALL_CAP_RE = re.compile('([a-z0-9])([A-Z])')
|
||||
def convert_capcase_to_camelcase(text: str) -> str:
|
||||
s1 = FIRST_CAP_RE.sub(r'\1_\2', text)
|
||||
return ALL_CAP_RE.sub(r'\1_\2', s1).lower()
|
||||
|
||||
class XMLConverter(PDFConverter):
|
||||
def __init__(self,
|
||||
rsrcmgr,
|
||||
@@ -113,23 +120,29 @@ class XMLConverter(PDFConverter):
|
||||
})
|
||||
|
||||
def place_text(self, char: LTChar):
|
||||
tag_name = 'char'
|
||||
if isinstance(char, LTCharBlock):
|
||||
tag_name = 'char-block'
|
||||
attr = {
|
||||
'size': char.size,
|
||||
"color": get_color(char.graphicstate.ncolor),
|
||||
"x0": char.x0,
|
||||
"x1": char.x1,
|
||||
"y0": char.y0,
|
||||
"y1": char.y1,
|
||||
}
|
||||
for key, value in char.font.descriptor.items():
|
||||
if key != "Type" and "FontFile" not in key:
|
||||
attr["font-" + key] = value
|
||||
with self.place_elm_with_child(tag_name, attr, no_additional_char=True):
|
||||
with self.place_elm_with_child('char', {
|
||||
'width': char.width,
|
||||
'height': char.height,
|
||||
}, no_additional_char=True):
|
||||
self.write(char.get_text(), lineend='', deep_space="")
|
||||
|
||||
def render_char_block(self, char_block: LTCharBlock):
|
||||
attr = {
|
||||
'size': char_block.size,
|
||||
"color": get_color(char_block.graphicstate.ncolor),
|
||||
"x0": char_block.x0,
|
||||
"x1": char_block.x1,
|
||||
"y0": char_block.y0,
|
||||
"y1": char_block.y1,
|
||||
"is_bold": char_block.font.is_bold,
|
||||
}
|
||||
for key, value in char_block.font.descriptor.items():
|
||||
if key != "Type" and "FontFile" not in key:
|
||||
attr[convert_capcase_to_camelcase(key)] = value
|
||||
with self.place_elm_with_child("char-block", attr):
|
||||
for char in char_block:
|
||||
self.place_text(char)
|
||||
|
||||
def render_curve(self, item: LTCurve):
|
||||
attr = {
|
||||
"x0": item.x0,
|
||||
@@ -164,8 +177,8 @@ class XMLConverter(PDFConverter):
|
||||
render(child)
|
||||
elif isinstance(item, LTImage):
|
||||
self.place_image(item)
|
||||
elif isinstance(item, LTChar) or isinstance(item, LTCharBlock):
|
||||
self.place_text(item)
|
||||
elif isinstance(item, LTCharBlock):
|
||||
self.render_char_block(item)
|
||||
render(ltpage)
|
||||
|
||||
def close(self):
|
||||
|
||||
@@ -531,6 +531,19 @@ class PDFFont(object):
|
||||
@abstractmethod
|
||||
def to_unichr(self, cid):
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def font_weight(self):
|
||||
if 'FontWeight' in self.descriptor.keys():
|
||||
return self.descriptor['FontWeight']
|
||||
elif 'bold' in self.fontname.lower():
|
||||
return 'bold'
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def is_bold(self):
|
||||
return self.font_weight == 'bold' or self.font_weight > 549
|
||||
|
||||
|
||||
# PDFSimpleFont
|
||||
|
||||
@@ -26,7 +26,7 @@ from .PDFGraphicState import PDFGraphicState
|
||||
from .PDFTextState import PDFTextState
|
||||
from .PDFContentParser import PDFContentParser
|
||||
|
||||
from ..utils import settings, mult_matrix, MATRIX_IDENTITY
|
||||
from ..utils import mult_matrix, MATRIX_IDENTITY
|
||||
from .constants import LITERAL_FORM, LITERAL_IMAGE
|
||||
from .types import CurvePoint, CurvePath
|
||||
|
||||
@@ -303,8 +303,7 @@ class PDFPageInterpreter(object):
|
||||
try:
|
||||
self.scs = self.csmap[literal_name(name)]
|
||||
except KeyError:
|
||||
if settings.STRICT:
|
||||
raise PDFInterpreterError('Undefined ColorSpace: %r' % name)
|
||||
raise PDFInterpreterError('Undefined ColorSpace: %r' % name)
|
||||
return
|
||||
|
||||
# setcolorspace-non-strokine
|
||||
@@ -312,8 +311,7 @@ class PDFPageInterpreter(object):
|
||||
try:
|
||||
self.ncs = self.csmap[literal_name(name)]
|
||||
except KeyError:
|
||||
if settings.STRICT:
|
||||
raise PDFInterpreterError('Undefined ColorSpace: %r' % name)
|
||||
raise PDFInterpreterError('Undefined ColorSpace: %r' % name)
|
||||
return
|
||||
|
||||
# setgray-stroking
|
||||
@@ -357,9 +355,7 @@ class PDFPageInterpreter(object):
|
||||
if self.scs:
|
||||
n = self.scs.ncomponents
|
||||
else:
|
||||
if settings.STRICT:
|
||||
raise PDFInterpreterError('No colorspace specified!')
|
||||
n = 1
|
||||
raise PDFInterpreterError('No colorspace specified!')
|
||||
self.pop(n)
|
||||
return
|
||||
|
||||
@@ -367,9 +363,7 @@ class PDFPageInterpreter(object):
|
||||
if self.ncs:
|
||||
n = self.ncs.ncomponents
|
||||
else:
|
||||
if settings.STRICT:
|
||||
raise PDFInterpreterError('No colorspace specified!')
|
||||
n = 1
|
||||
raise PDFInterpreterError('No colorspace specified!')
|
||||
self.pop(n)
|
||||
return
|
||||
|
||||
@@ -432,6 +426,8 @@ class PDFPageInterpreter(object):
|
||||
def do_Tw(self, space):
|
||||
self.textstate.wordspace = space
|
||||
return
|
||||
|
||||
# def do_Th(self, )
|
||||
|
||||
# textscale
|
||||
def do_Tz(self, scale):
|
||||
@@ -448,9 +444,8 @@ class PDFPageInterpreter(object):
|
||||
try:
|
||||
self.textstate.font = self.fontmap[literal_name(fontid)]
|
||||
except KeyError:
|
||||
if settings.STRICT:
|
||||
raise PDFInterpreterError('Undefined Font id: %r' % fontid)
|
||||
self.textstate.font = self.rsrcmgr.get_font(None, {})
|
||||
raise PDFInterpreterError('Undefined Font id: %r' % fontid)
|
||||
# self.textstate.font = self.rsrcmgr.get_font(None, {})
|
||||
self.textstate.fontsize = fontsize
|
||||
return
|
||||
|
||||
@@ -495,9 +490,7 @@ class PDFPageInterpreter(object):
|
||||
# show-pos
|
||||
def do_TJ(self, seq: bytearray):
|
||||
if self.textstate.font is None:
|
||||
if settings.STRICT:
|
||||
raise PDFInterpreterError('No font specified!')
|
||||
return
|
||||
raise PDFInterpreterError('No font specified!')
|
||||
self.device.render_string(self.textstate.copy(), seq, self.ncs, self.graphicstate.copy())
|
||||
return
|
||||
|
||||
@@ -540,9 +533,7 @@ class PDFPageInterpreter(object):
|
||||
try:
|
||||
xobj = PDFStream.validated_stream(self.xobjmap[xobjid])
|
||||
except KeyError:
|
||||
if settings.STRICT:
|
||||
raise PDFInterpreterError('Undefined xobject id: %r' % xobjid)
|
||||
return
|
||||
raise PDFInterpreterError('Undefined xobject id: %r' % xobjid)
|
||||
log.info('Processing xobj: %r', xobj)
|
||||
subtype = xobj.get('Subtype')
|
||||
if subtype is LITERAL_FORM and 'BBox' in xobj:
|
||||
@@ -618,8 +609,7 @@ class PDFPageInterpreter(object):
|
||||
log.debug('exec: %s', name)
|
||||
func()
|
||||
else:
|
||||
if settings.STRICT:
|
||||
raise PDFInterpreterError('Unknown operator: %r' % name)
|
||||
raise PDFInterpreterError('Unknown operator: %r' % name)
|
||||
else:
|
||||
self.push(obj)
|
||||
return
|
||||
@@ -60,6 +60,9 @@ class LTCharBlock(LTComponent):
|
||||
def __repr__(self):
|
||||
return f"""<{self.__class__.__name__} font="{self.fontname}" text="{self.get_text()}"/>"""
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.chars)
|
||||
|
||||
def get_text(self):
|
||||
return "".join([ c.get_text() for c in self.chars ])
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import sys
|
||||
with open('README.md') as readme_file:
|
||||
SETUP = {
|
||||
"name": "pdfmajor",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.4",
|
||||
"packages": find_packages(include=['pdfmajor*']),
|
||||
"install_requires": [
|
||||
'pycryptodome',
|
||||
@@ -46,8 +46,9 @@ with open('README.md') as readme_file:
|
||||
# ==============
|
||||
# Update __init__.py
|
||||
# ==============
|
||||
from bin.recreate_init import update_pdfmajor__init___
|
||||
from bin.recreate_init import update_pdfmajor__init___, update_current_version_lock
|
||||
update_pdfmajor__init___(SETUP["version"], SETUP["long_description"])
|
||||
update_current_version_lock(SETUP["version"])
|
||||
|
||||
# ==============
|
||||
# Run Setup
|
||||
|
||||
Reference in new issue
Block a user