From 5f2eeb785575b5b9c6549c3620baf0704cc00bff Mon Sep 17 00:00:00 2001 From: Ariel Sosnovsky Date: Wed, 17 Oct 2018 11:23:52 -0400 Subject: [PATCH] - better curve extraction - better color detection - better curve/color visualization --- .gitignore | 4 +- pdfmajor/converters/HTMLConverter.py | 43 +- pdfmajor/converters/JSONConverter.py | 6 +- pdfmajor/converters/PDFConverter.py | 1 - pdfmajor/converters/XMLConverter.py | 6 +- pdfmajor/interpreter/PDFColorSpace.py | 6 +- pdfmajor/interpreter/PDFPage.py | 15 +- pdfmajor/interpreter/PDFPageInterpreter.py | 64 +- pdfmajor/interpreter/PDFParser.py | 4 +- pdfmajor/interpreter/PDFResourceManager.py | 2 +- pdfmajor/interpreter/PDFTextState.py | 18 +- pdfmajor/interpreter/PDFdevice.py | 50 +- .../interpreter/PSStackParser/PSBaseParser.py | 72 +- .../interpreter/PSStackParser/__init__.py | 3 +- pdfmajor/interpreter/PSStackParser/types.py | 1 + pdfmajor/interpreter/types.py | 27 + pdfmajor/layouts/LTCurves.py | 36 +- pdfmajor/layouts/__init__.py | 116 +- samples/convert_samples.py | 5 +- samples/output/html/bar-charts.html | 1630 ++++++++++++++--- samples/output/html/colors.html | 48 +- samples/output/html/line-charts.html | 0 samples/output/html/tables.html | 1042 +++++------ 23 files changed, 2264 insertions(+), 935 deletions(-) create mode 100644 pdfmajor/interpreter/types.py delete mode 100644 samples/output/html/line-charts.html diff --git a/.gitignore b/.gitignore index 4873f85..c44034b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ docs/_build tests/*.xml tests/*.txt .idea/ -.vscode \ No newline at end of file +.vscode +samples/output +samples/pdfmajor \ No newline at end of file diff --git a/pdfmajor/converters/HTMLConverter.py b/pdfmajor/converters/HTMLConverter.py index 57c8421..62e0ee6 100644 --- a/pdfmajor/converters/HTMLConverter.py +++ b/pdfmajor/converters/HTMLConverter.py @@ -6,7 +6,7 @@ from contextlib import contextmanager from ..layouts import LTPage from ..layouts import LTItem -from ..layouts import LTCurve +from ..layouts import LTCurve, LTLine, LTRect, CurvePath from ..layouts import LTFigure from ..layouts import LTImage from ..layouts import LTChar @@ -127,10 +127,43 @@ class HTMLConverter(PDFConverter): 'bottom': f'{item.y0}px', 'width': f'{item.width}px', 'height': f'{item.height}px', - "border-color": get_color(item.stroke), - "background-color": get_color(item.fill), } - self.place_elm_close('div', {'class': 'curve'}, css) + if isinstance(item, LTRect): + pass + # self.place_elm_close('div', {'class': 'curve rect'}, {**css, + # "border-color": get_color(item.stroke), + # "background-color": get_color(item.fill), + # }) + elif isinstance(item, LTLine): + self.place_elm_close('div', {'class': 'curve line'}, {**css, + "background-color": get_color(item.fill), + "border-color": get_color(item.stroke), + }) + else: + path = "" + + + dx = (item.width/item.height)/(item.x1-item.x0) + dy = 1.0/(item.y1-item.y0) + + for p in item.paths: + if p.method == CurvePath.METHOD.MOVE_TO: + path += f'M{" ".join( f"{(item.width - (p.x-item.x0) )*dx} {(item.height- (p.y-item.y0) )*dy}" for p in p.points )} ' + if p.method == CurvePath.METHOD.LINE_TO: + path += f'L{" ".join( f"{(item.width - (p.x-item.x0) )*dx} {( item.height - (p.y-item.y0) )*dy}" for p in p.points )} ' + if p.method == CurvePath.METHOD.CLOSE_PATH: + path += 'Z' + with self.place_elm_with_child('svg', { + 'class': 'curve', + "viewBox": f"0 0 {item.width/item.height} 1", + 'width': f'{item.width}px', + 'height': f'{item.height}px', + }, css): + self.place_elm_close('path', { + "d": path, + 'stroke': get_color(item.stroke), + 'fill': get_color(item.fill), + }) def receive_layout(self, ltpage: LTPage): def render(item: LTItem): @@ -158,7 +191,7 @@ class HTMLConverter(PDFConverter): with self.place_elm_with_child('span', { 'class': 'char' }, { 'font-size': f'{item.size}px', 'font-family': item.fontname, - 'color': get_color(item.graphicstate.scolor), + 'color': get_color(item.graphicstate.ncolor), 'position': 'absolute', 'left': f'{item.x0}', 'bottom': f'{item.y0}', diff --git a/pdfmajor/converters/JSONConverter.py b/pdfmajor/converters/JSONConverter.py index c06c744..620cfb9 100644 --- a/pdfmajor/converters/JSONConverter.py +++ b/pdfmajor/converters/JSONConverter.py @@ -138,8 +138,10 @@ class JSONConverter(PDFConverter): return self.place_elm_close('line', attr) with self.place_elm_with_child('curve', attr): - for x, y in item.pts: - self.place_elm_close('point', { 'x': x, 'y': y }) + for path in item.paths: + with self.place_elm_with_child('path', { "type": path.method.name }): + for point in path.points: + self.place_elm_close('point', { 'x': point.x, 'y': point.y }) def receive_layout(self, ltpage: LTPage): def render(item: LTItem): diff --git a/pdfmajor/converters/PDFConverter.py b/pdfmajor/converters/PDFConverter.py index 0f9b592..080cff1 100644 --- a/pdfmajor/converters/PDFConverter.py +++ b/pdfmajor/converters/PDFConverter.py @@ -50,7 +50,6 @@ class PDFConverter(PDFLayoutAnalyzer): log.debug("Reading pages....") pages = PDFPage.get_pages(input_file, pagenos=pagenos, maxpages=maxpages, password=password, caching=caching, check_extractable=check_extractable) for idx, page in enumerate(pages): - print(f"processing pages page #{idx}") interpreter.process_page(page) device.close() return output_file diff --git a/pdfmajor/converters/XMLConverter.py b/pdfmajor/converters/XMLConverter.py index feaaa70..a9a0da7 100644 --- a/pdfmajor/converters/XMLConverter.py +++ b/pdfmajor/converters/XMLConverter.py @@ -135,8 +135,10 @@ class XMLConverter(PDFConverter): return self.place_elm_close('line', attr) with self.place_elm_with_child('curve', attr): - for x, y in item.pts: - self.place_elm_close('point', { 'x': x, 'y': y }) + for path in item.paths: + with self.place_elm_with_child('path', { "type": path.method.name }): + for point in path.points: + self.place_elm_close('point', { 'x': point.x, 'y': point.y }) def receive_layout(self, ltpage: LTPage): def render(item: LTItem): diff --git a/pdfmajor/interpreter/PDFColorSpace.py b/pdfmajor/interpreter/PDFColorSpace.py index 80368ad..0ce2482 100644 --- a/pdfmajor/interpreter/PDFColorSpace.py +++ b/pdfmajor/interpreter/PDFColorSpace.py @@ -10,9 +10,9 @@ LITERAL_DEVICE_CMYK = LIT('DeviceCMYK') class PDFColorSpace(object): - def __init__(self, name, ncomponents): - self.name = name - self.ncomponents = ncomponents + def __init__(self, name: str, ncomponents: int): + self.name: str = name + self.ncomponents: int = ncomponents return def __repr__(self): diff --git a/pdfmajor/interpreter/PDFPage.py b/pdfmajor/interpreter/PDFPage.py index 95df3c5..e6098ea 100644 --- a/pdfmajor/interpreter/PDFPage.py +++ b/pdfmajor/interpreter/PDFPage.py @@ -37,7 +37,7 @@ class PDFPage(object): beads: a chain that represents natural reading order. """ - def __init__(self, doc, pageid, attrs): + def __init__(self, doc: PDFDocument, pageid, attrs): """Initialize a page object. doc: a PDFDocument object. @@ -72,7 +72,7 @@ class PDFPage(object): INHERITABLE_ATTRS = set(['Resources', 'MediaBox', 'CropBox', 'Rotate']) @classmethod - def create_pages(klass, document): + def create_pages(cls, document): def search(obj, parent): if isinstance(obj, int): objid = obj @@ -81,7 +81,7 @@ class PDFPage(object): objid = obj.objid tree = dict_value(obj).copy() for (k, v) in parent.items(): - if k in klass.INHERITABLE_ATTRS and k not in tree: + if k in cls.INHERITABLE_ATTRS and k not in tree: tree[k] = v tree_type = tree.get('Type') @@ -96,10 +96,11 @@ class PDFPage(object): elif tree_type is LITERAL_PAGE: log.info('Page: %r', tree) yield (objid, tree) + pages = False if 'Pages' in document.catalog: for (objid, tree) in search(document.catalog['Pages'], document.catalog): - yield klass(document, objid, tree) + yield cls(document, objid, tree) pages = True if not pages: # fallback when /Pages is missing. @@ -108,13 +109,13 @@ class PDFPage(object): try: obj = document.getobj(objid) if isinstance(obj, dict) and obj.get('Type') is LITERAL_PAGE: - yield klass(document, objid, obj) + yield cls(document, objid, obj) except PDFObjectNotFound: pass return @classmethod - def get_pages(klass, fp, + def get_pages(cls, fp, pagenos=None, maxpages=0, password='', caching=True, check_extractable=True): # Create a PDF parser object associated with the file object. @@ -125,7 +126,7 @@ class PDFPage(object): if check_extractable and not doc.is_extractable: raise PDFTextExtractionNotAllowed('Text extraction is not allowed: %r' % fp) # Process each page contained in the document. - for (pageno, page) in enumerate(klass.create_pages(doc)): + for (pageno, page) in enumerate(cls.create_pages(doc)): if pagenos and (pageno not in pagenos): continue yield page diff --git a/pdfmajor/interpreter/PDFPageInterpreter.py b/pdfmajor/interpreter/PDFPageInterpreter.py index ce2847f..ee78321 100644 --- a/pdfmajor/interpreter/PDFPageInterpreter.py +++ b/pdfmajor/interpreter/PDFPageInterpreter.py @@ -1,6 +1,8 @@ import logging import operator +from typing import List + from .PDFColorSpace import PDFColorSpace from .PDFColorSpace import PREDEFINED_COLORSPACE @@ -26,6 +28,7 @@ from .PDFContentParser import PDFContentParser from ..utils import settings, mult_matrix, MATRIX_IDENTITY from .constants import LITERAL_FORM, LITERAL_IMAGE +from .types import CurvePoint, CurvePath log = logging.getLogger(__name__) @@ -39,6 +42,7 @@ class PDFPageInterpreter(object): def __init__(self, rsrcmgr, device): self.rsrcmgr = rsrcmgr self.device = device + self.curpath: List[CurvePath] = [] return def dup(self): @@ -180,47 +184,60 @@ class PDFPageInterpreter(object): return # moveto - def do_m(self, x, y): - self.curpath.append(('m', x, y)) + def do_m(self, x: float, y: float): + self.curpath.append(CurvePath(CurvePath.METHOD.MOVE_TO, CurvePoint(x, y))) return # lineto - def do_l(self, x, y): - self.curpath.append(('l', x, y)) + def do_l(self, x: float, y: float): + self.curpath.append(CurvePath(CurvePath.METHOD.LINE_TO, CurvePoint(x, y))) return # curveto - def do_c(self, x1, y1, x2, y2, x3, y3): - self.curpath.append(('c', x1, y1, x2, y2, x3, y3)) + def do_c(self, x1: float, y1: float, x2: float, y2: float, x3: float, y3: float): + self.curpath.append(CurvePath( + CurvePath.METHOD.CURVE_BOTH_TO, + CurvePoint(x1, y1), + CurvePoint(x2, y2), + CurvePoint(x3, y3), + )) return # urveto - def do_v(self, x2, y2, x3, y3): - self.curpath.append(('v', x2, y2, x3, y3)) + def do_v(self, x2: float, y2: float, x3: float, y3: float): + self.curpath.append(CurvePath( + CurvePath.METHOD.CURVE_NEXT_TO, + CurvePoint(x2, y2), + CurvePoint(x3, y3), + )) return # rveto - def do_y(self, x1, y1, x3, y3): - self.curpath.append(('y', x1, y1, x3, y3)) + def do_y(self, x1: float, y1: float, x3: float, y3: float): + self.curpath.append(CurvePath( + CurvePath.METHOD.CURVE_FIRST_TO, + CurvePoint(x1, y1), + CurvePoint(x3, y3) + )) return # closepath def do_h(self): - self.curpath.append(('h',)) + self.curpath.append(CurvePath(CurvePath.METHOD.CLOSE_PATH)) return # rectangle def do_re(self, x, y, w, h): - self.curpath.append(('m', x, y)) - self.curpath.append(('l', x+w, y)) - self.curpath.append(('l', x+w, y+h)) - self.curpath.append(('l', x, y+h)) - self.curpath.append(('h',)) + self.curpath.append(CurvePath(CurvePath.METHOD.MOVE_TO, CurvePoint(x, y) )) + self.curpath.append(CurvePath(CurvePath.METHOD.LINE_TO, CurvePoint(x+w, y) )) + self.curpath.append(CurvePath(CurvePath.METHOD.LINE_TO, CurvePoint(x+w, y+h) )) + self.curpath.append(CurvePath(CurvePath.METHOD.LINE_TO, CurvePoint(x, y+h) )) + self.curpath.append(CurvePath(CurvePath.METHOD.CLOSE_PATH)) return # stroke def do_S(self): - self.device.paint_path(self.graphicstate, False, self.curpath) + self.device.paint_path(self.graphicstate.copy(), False, self.curpath) self.curpath = [] return @@ -232,7 +249,7 @@ class PDFPageInterpreter(object): # fill def do_f(self): - self.device.paint_path(self.graphicstate, False, self.curpath) + self.device.paint_path(self.graphicstate.copy(), False, self.curpath) self.curpath = [] return # fill (obsolete) @@ -240,19 +257,19 @@ class PDFPageInterpreter(object): # fill-even-odd def do_f_a(self): - self.device.paint_path(self.graphicstate, True, self.curpath) + self.device.paint_path(self.graphicstate.copy(), True, self.curpath) self.curpath = [] return # fill-and-stroke def do_B(self): - self.device.paint_path(self.graphicstate, False, self.curpath) + self.device.paint_path(self.graphicstate.copy(), False, self.curpath) self.curpath = [] return # fill-and-stroke-even-odd def do_B_a(self): - self.device.paint_path(self.graphicstate, True, self.curpath) + self.device.paint_path(self.graphicstate.copy(), True, self.curpath) self.curpath = [] return @@ -343,7 +360,7 @@ class PDFPageInterpreter(object): if settings.STRICT: raise PDFInterpreterError('No colorspace specified!') n = 1 - self.graphicstate.scolor = self.pop(n) + self.pop(n) return def do_scn(self): @@ -353,7 +370,7 @@ class PDFPageInterpreter(object): if settings.STRICT: raise PDFInterpreterError('No colorspace specified!') n = 1 - self.graphicstate.ncolor = self.pop(n) + self.pop(n) return def do_SC(self): @@ -595,7 +612,6 @@ class PDFPageInterpreter(object): nargs = func.__code__.co_argcount-1 if nargs: args = self.pop(nargs) - log.debug('exec: %s %r', name, args) if len(args) == nargs: func(*args) else: diff --git a/pdfmajor/interpreter/PDFParser.py b/pdfmajor/interpreter/PDFParser.py index 65bed41..cdcf219 100644 --- a/pdfmajor/interpreter/PDFParser.py +++ b/pdfmajor/interpreter/PDFParser.py @@ -1,6 +1,6 @@ import logging -from io import BytesIO +from io import BytesIO, TextIOWrapper from ..utils import settings from .PSStackParser import PSStackParser @@ -42,7 +42,7 @@ class PDFParser(PSStackParser): """ - def __init__(self, fp): + def __init__(self, fp: TextIOWrapper): PSStackParser.__init__(self, fp) self.doc = None self.fallback = False diff --git a/pdfmajor/interpreter/PDFResourceManager.py b/pdfmajor/interpreter/PDFResourceManager.py index c4a0ae5..4a74d4b 100644 --- a/pdfmajor/interpreter/PDFResourceManager.py +++ b/pdfmajor/interpreter/PDFResourceManager.py @@ -58,7 +58,7 @@ class PDFResourceManager(object): raise return CMap() - def get_font(self, objid, spec): + def get_font(self, objid: int, spec: dict): if objid and objid in self._cached_fonts: font = self._cached_fonts[objid] else: diff --git a/pdfmajor/interpreter/PDFTextState.py b/pdfmajor/interpreter/PDFTextState.py index 9830273..6dcbc37 100644 --- a/pdfmajor/interpreter/PDFTextState.py +++ b/pdfmajor/interpreter/PDFTextState.py @@ -1,18 +1,20 @@ +from .PDFFont import PDFFont from ..utils import MATRIX_IDENTITY + ## PDFTextState ## class PDFTextState(object): def __init__(self): - self.font = None - self.fontsize = 0 - self.charspace = 0 - self.wordspace = 0 - self.scaling = 100 - self.leading = 0 - self.render = 0 - self.rise = 0 + self.font: PDFFont = None + self.fontsize: int = 0 + self.charspace: int = 0 + self.wordspace: int = 0 + self.scaling: int = 100 + self.leading: int = 0 + self.render: int = 0 + self.rise: int = 0 self.reset() # self.matrix is set # self.linematrix is set diff --git a/pdfmajor/interpreter/PDFdevice.py b/pdfmajor/interpreter/PDFdevice.py index d2111b9..0e137fd 100644 --- a/pdfmajor/interpreter/PDFdevice.py +++ b/pdfmajor/interpreter/PDFdevice.py @@ -7,6 +7,8 @@ from ..utils import Bbox, mult_matrix, translate_matrix from .PDFResourceManager import PDFResourceManager from .PDFGraphicState import PDFGraphicState +from .PDFTextState import PDFTextState +from .PDFColorSpace import PDFColorSpace ## PDFDevice ## @@ -68,7 +70,7 @@ class PDFDevice(object): ## class PDFTextDevice(PDFDevice): - def render_string(self, textstate, seq, ncs, graphicstate: PDFGraphicState): + def render_string(self, textstate: PDFTextState, seq: bytearray, ncs: PDFColorSpace, graphicstate: PDFGraphicState): matrix = mult_matrix(textstate.matrix, self.ctm) font = textstate.font fontsize = textstate.fontsize @@ -76,60 +78,40 @@ class PDFTextDevice(PDFDevice): charspace = textstate.charspace * scaling wordspace = textstate.wordspace * scaling rise = textstate.rise + if font.is_multibyte(): wordspace = 0 dxscale = .001 * fontsize * scaling - if font.is_vertical(): - textstate.linematrix = self.render_string_vertical( + + if textstate.font.is_vertical(): + textstate.linematrix = self.__render_string_along(1, seq, matrix, textstate.linematrix, font, fontsize, scaling, charspace, wordspace, rise, dxscale, ncs, graphicstate) else: - textstate.linematrix = self.render_string_horizontal( + textstate.linematrix = self.__render_string_along(0, seq, matrix, textstate.linematrix, font, fontsize, scaling, charspace, wordspace, rise, dxscale, ncs, graphicstate) - return - def render_string_horizontal(self, seq, matrix, pos, + def __render_string_along(self, idx: int, seq: bytearray, matrix: list, pos: tuple, font, fontsize, scaling, charspace, wordspace, rise, dxscale, ncs, graphicstate: PDFGraphicState): - (x, y) = pos + pos_copy = [*pos] needcharspace = False for obj in seq: if isnumber(obj): - x -= obj*dxscale + pos_copy[idx] -= obj*dxscale needcharspace = True else: for cid in font.decode(obj): if needcharspace: - x += charspace - x += self.render_char(translate_matrix(matrix, (x, y)), + pos_copy[idx] += charspace + pos_copy[idx] += self.render_char(translate_matrix(matrix, pos_copy), font, fontsize, scaling, rise, cid, ncs, graphicstate) if cid == 32 and wordspace: - x += wordspace + pos_copy[idx] += wordspace needcharspace = True - return (x, y) - - def render_string_vertical(self, seq, matrix, pos, - font, fontsize, scaling, charspace, wordspace, - rise, dxscale, ncs, graphicstate: PDFGraphicState): - (x, y) = pos - needcharspace = False - for obj in seq: - if isnumber(obj): - y -= obj*dxscale - needcharspace = True - else: - for cid in font.decode(obj): - if needcharspace: - y += charspace - y += self.render_char(translate_matrix(matrix, (x, y)), - font, fontsize, scaling, rise, cid, - ncs, graphicstate) - if cid == 32 and wordspace: - y += wordspace - needcharspace = True - return (x, y) + return pos_copy def render_char(self, matrix, font, fontsize, scaling, rise, cid, ncs, graphicstate: PDFGraphicState): - return 0 + return NotImplementedError diff --git a/pdfmajor/interpreter/PSStackParser/PSBaseParser.py b/pdfmajor/interpreter/PSStackParser/PSBaseParser.py index a206b42..2ce6d92 100644 --- a/pdfmajor/interpreter/PSStackParser/PSBaseParser.py +++ b/pdfmajor/interpreter/PSStackParser/PSBaseParser.py @@ -1,6 +1,9 @@ import logging + log = logging.getLogger(__name__) +from io import TextIOWrapper +from typing import List, Tuple, Union from ...utils import int2byte from .exceptions import PSEOF @@ -8,6 +11,7 @@ from .constants import EOL, NONSPC, KWD, END_LITERAL, LIT, HEX from .constants import SPC, HEX_PAIR from .constants import END_NUMBER, END_STRING, END_KEYWORD, END_HEX_STRING from .constants import OCT_STRING, ESC_STRING, KEYWORD_DICT_BEGIN, KEYWORD_DICT_END +from .types import PSLiteral class PSBaseParser(object): @@ -15,7 +19,7 @@ class PSBaseParser(object): """ BUFSIZ = 4096 - def __init__(self, fp): + def __init__(self, fp: TextIOWrapper): self.fp = fp self.seek(0) return @@ -42,20 +46,20 @@ class PSBaseParser(object): self.fp.seek(pos0) return - def seek(self, pos): + def seek(self, pos: int): """Seeks the parser to the given position. """ log.debug('seek: %r', pos) self.fp.seek(pos) # reset the status for nextline() - self.bufpos = pos - self.buf = b'' - self.charpos = 0 + self.bufpos: int = pos + self.buf: bytes = b'' + self.charpos: int = 0 # reset the status for nexttoken() - self._parse1 = self._parse_main - self._curtoken = b'' - self._curtokenpos = 0 - self._tokens = [] + self._current_parse_func = self._parse_main + self._curtoken: bytes = b'' + self._curtokenpos: int = 0 + self._tokens: List[Tuple[int, Union[int, float, bool, str, bytes, PSLiteral]]] = [] return def fillbuf(self): @@ -133,36 +137,36 @@ class PSBaseParser(object): self._curtokenpos = self.bufpos+j if c == b'%': self._curtoken = b'%' - self._parse1 = self._parse_comment + self._current_parse_func = self._parse_comment return j+1 elif c == b'/': self._curtoken = b'' - self._parse1 = self._parse_literal + self._current_parse_func = self._parse_literal return j+1 elif c in b'-+' or c.isdigit(): self._curtoken = c - self._parse1 = self._parse_number + self._current_parse_func = self._parse_number return j+1 elif c == b'.': self._curtoken = c - self._parse1 = self._parse_float + self._current_parse_func = self._parse_float return j+1 elif c.isalpha(): self._curtoken = c - self._parse1 = self._parse_keyword + self._current_parse_func = self._parse_keyword return j+1 elif c == b'(': self._curtoken = b'' self.paren = 1 - self._parse1 = self._parse_string + self._current_parse_func = self._parse_string return j+1 elif c == b'<': self._curtoken = b'' - self._parse1 = self._parse_wopen + self._current_parse_func = self._parse_wopen return j+1 elif c == b'>': self._curtoken = b'' - self._parse1 = self._parse_wclose + self._current_parse_func = self._parse_wclose return j+1 else: self._add_token(KWD(c)) @@ -179,7 +183,7 @@ class PSBaseParser(object): return len(s) j = m.start(0) self._curtoken += s[i:j] - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main # We ignore comments. #self._tokens.append(self._curtoken) return j @@ -194,14 +198,14 @@ class PSBaseParser(object): c = s[j:j+1] if c == b'#': self.hex = b'' - self._parse1 = self._parse_literal_hex + self._current_parse_func = self._parse_literal_hex return j+1 try: self._curtoken=str(self._curtoken,'utf-8') except: pass self._add_token(LIT(self._curtoken)) - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main return j def _parse_literal_hex(self, s, i): @@ -211,7 +215,7 @@ class PSBaseParser(object): return i+1 if self.hex: self._curtoken += int2byte(int(self.hex, 16)) - self._parse1 = self._parse_literal + self._current_parse_func = self._parse_literal return i def _parse_number(self, s, i): @@ -224,13 +228,13 @@ class PSBaseParser(object): c = s[j:j+1] if c == b'.': self._curtoken += c - self._parse1 = self._parse_float + self._current_parse_func = self._parse_float return j+1 try: self._add_token(int(self._curtoken)) except ValueError: pass - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main return j def _parse_float(self, s, i): @@ -244,7 +248,7 @@ class PSBaseParser(object): self._add_token(float(self._curtoken)) except ValueError: pass - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main return j def _parse_keyword(self, s, i): @@ -261,7 +265,7 @@ class PSBaseParser(object): else: token = KWD(self._curtoken) self._add_token(token) - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main return j def _parse_string(self, s, i): @@ -274,7 +278,7 @@ class PSBaseParser(object): c = s[j:j+1] if c == b'\\': self.oct = b'' - self._parse1 = self._parse_string_1 + self._current_parse_func = self._parse_string_1 return j+1 if c == b'(': self.paren += 1 @@ -286,7 +290,7 @@ class PSBaseParser(object): self._curtoken += c return j+1 self._add_token(self._curtoken) - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main return j+1 def _parse_string_1(self, s, i): @@ -296,21 +300,21 @@ class PSBaseParser(object): return i+1 if self.oct: self._curtoken += int2byte(int(self.oct, 8)) - self._parse1 = self._parse_string + self._current_parse_func = self._parse_string return i if c in ESC_STRING: self._curtoken += int2byte(ESC_STRING[c]) - self._parse1 = self._parse_string + self._current_parse_func = self._parse_string return i+1 def _parse_wopen(self, s, i): c = s[i:i+1] if c == b'<': self._add_token(KEYWORD_DICT_BEGIN) - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main i += 1 else: - self._parse1 = self._parse_hexstring + self._current_parse_func = self._parse_hexstring return i def _parse_wclose(self, s, i): @@ -318,7 +322,7 @@ class PSBaseParser(object): if c == b'>': self._add_token(KEYWORD_DICT_END) i += 1 - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main return i def _parse_hexstring(self, s, i): @@ -330,13 +334,13 @@ class PSBaseParser(object): self._curtoken += s[i:j] token = HEX_PAIR.sub(lambda m: int2byte(int(m.group(0), 16)),SPC.sub(b'', self._curtoken)) self._add_token(token) - self._parse1 = self._parse_main + self._current_parse_func = self._parse_main return j def nexttoken(self): while not self._tokens: self.fillbuf() - self.charpos = self._parse1(self.buf, self.charpos) + self.charpos = self._current_parse_func(self.buf, self.charpos) token = self._tokens.pop(0) log.debug('nexttoken: %r', token) return token diff --git a/pdfmajor/interpreter/PSStackParser/__init__.py b/pdfmajor/interpreter/PSStackParser/__init__.py index b91d5f7..e78a18d 100644 --- a/pdfmajor/interpreter/PSStackParser/__init__.py +++ b/pdfmajor/interpreter/PSStackParser/__init__.py @@ -1,4 +1,5 @@ import logging +from io import TextIOWrapper from ...utils import choplist, settings @@ -38,7 +39,7 @@ def keyword_name(x): class PSStackParser(PSBaseParser): - def __init__(self, fp): + def __init__(self, fp: TextIOWrapper): PSBaseParser.__init__(self, fp) self.reset() return diff --git a/pdfmajor/interpreter/PSStackParser/types.py b/pdfmajor/interpreter/PSStackParser/types.py index 7fd274b..38fae37 100644 --- a/pdfmajor/interpreter/PSStackParser/types.py +++ b/pdfmajor/interpreter/PSStackParser/types.py @@ -1,5 +1,6 @@ ## Basic PostScript Types ## +from typing import Union ## PSObject ## diff --git a/pdfmajor/interpreter/types.py b/pdfmajor/interpreter/types.py new file mode 100644 index 0000000..ba9f9d5 --- /dev/null +++ b/pdfmajor/interpreter/types.py @@ -0,0 +1,27 @@ +from enum import Enum +from typing import List + +class CurvePoint: + def __init__(self, x: float, y: float): + self.x = x + self.y = y + + def __repr__(self) -> str: + return f'' + +class CurveMethod(Enum): + MOVE_TO='m' + LINE_TO='l' + CURVE_BOTH_TO='c' + CURVE_NEXT_TO='v' + CURVE_FIRST_TO='y' + CLOSE_PATH='h' + +class CurvePath: + METHOD = CurveMethod + def __init__(self, method: CurveMethod, *points: List[CurvePoint]): + self.method = method + self.points = points + + def __repr__(self) -> str: + return f'' \ No newline at end of file diff --git a/pdfmajor/layouts/LTCurves.py b/pdfmajor/layouts/LTCurves.py index 444c106..6139a78 100644 --- a/pdfmajor/layouts/LTCurves.py +++ b/pdfmajor/layouts/LTCurves.py @@ -3,43 +3,43 @@ from typing import List, Tuple from ..utils import Bbox from ..interpreter.PDFGraphicState import PDFGraphicStateColor -from ._base import LTComponent +from ..interpreter.types import CurvePath + +from ._base import LTComponent, Bbox class LTCurve(LTComponent): def __init__(self, linewidth: float, - pts: List[Tuple[float]], + paths: List[CurvePath], + bbox: Bbox, stroke: PDFGraphicStateColor, fill: PDFGraphicStateColor, evenodd: bool, ): - LTComponent.__init__(self, Bbox.from_points(pts)) - self.pts = pts + LTComponent.__init__(self, bbox) + self.paths = paths self.linewidth = linewidth self.evenodd = evenodd self.stroke = stroke self.fill = fill - def get_pts(self): - return ','.join('%.3f,%.3f' % p for p in self.pts) - ## LTLine ## class LTLine(LTCurve): + pass - def __init__(self, linewidth: float, p0:Tuple[float], p1:Tuple[float], stroke = PDFGraphicStateColor(), fill = PDFGraphicStateColor(), evenodd = False): - LTCurve.__init__(self, - linewidth=linewidth, - pts=[p0, p1], - stroke=stroke, - fill=fill, - evenodd=evenodd - ) +## LTHorizontalLine +## +class LTHorizontalLine(LTLine): + pass + +## LTHorizontalLine +## +class LTVerticalLine(LTLine): + pass ## LTRect ## class LTRect(LTCurve): - - def __init__(self, linewidth: float, pts: List[Tuple[float]], stroke = PDFGraphicStateColor(), fill = PDFGraphicStateColor(), evenodd = False): - LTCurve.__init__(self, linewidth, pts, stroke, fill, evenodd) + pass diff --git a/pdfmajor/layouts/__init__.py b/pdfmajor/layouts/__init__.py index 3e69cf5..faa4641 100644 --- a/pdfmajor/layouts/__init__.py +++ b/pdfmajor/layouts/__init__.py @@ -7,12 +7,12 @@ from typing import Tuple, List from ._base import LTItem from .LTPage import LTPage -from .LTCurves import LTCurve, LTLine, LTRect +from .LTCurves import LTCurve, LTLine, LTRect, LTHorizontalLine, LTVerticalLine from .LTFigure import LTFigure from .LTImage import LTImage from .LTChar import LTChar -from ..utils import Point, Bbox +from ..utils import Point, Bbox, INF from ..utils import apply_matrix_pt, mult_matrix from ..interpreter.PDFFont import PDFUnicodeNotDefined @@ -21,6 +21,7 @@ from ..interpreter.PDFGraphicState import PDFGraphicState, PDFGraphicStateColor from ..interpreter.PDFdevice import PDFTextDevice from ..interpreter.PDFPage import PDFPage from ..interpreter.PDFStream import PDFStream +from ..interpreter.types import CurvePath log = logging.getLogger(__name__) @@ -85,59 +86,94 @@ class PDFLayoutAnalyzer(PDFTextDevice): self.cur_item.add(item) return - def paint_path(self, gstate: PDFGraphicState, evenodd: bool, path: list): - shape = ''.join(x[0] for x in path) + def paint_path(self, gstate: PDFGraphicState, evenodd: bool, paths: List[CurvePath]): + shape = ''.join(x.method.value for x in paths) if shape == 'ml': # horizontal/vertical line - (_, x0, y0) = path[0] - (_, x1, y1) = path[1] - (x0, y0) = apply_matrix_pt(self.ctm, (x0, y0)) - (x1, y1) = apply_matrix_pt(self.ctm, (x1, y1)) - if x0 == x1 or y0 == y1: - self.cur_item.add(LTLine( - gstate.linewidth, - (x0, y0), (x1, y1), + pt0 = paths[0].points[0] + pt1 = paths[1].points[0] + (x0, y0) = apply_matrix_pt(self.ctm, (pt0.x, pt0.y)) + (x1, y1) = apply_matrix_pt(self.ctm, (pt1.x, pt1.y)) + if x0 == x1: + self.cur_item.add(LTVerticalLine( + linewidth=gstate.linewidth, + paths=paths, + bbox=Bbox( x0, y0, x1, y1 ), stroke=gstate.scolor, fill=gstate.ncolor, evenodd=evenodd, )) - return - if shape == 'mlllh': + elif y0 == y1: + self.cur_item.add(LTHorizontalLine( + linewidth=gstate.linewidth, + paths=paths, + bbox=Bbox( x0, y0, x1, y1 ), + stroke=gstate.scolor, + fill=gstate.ncolor, + evenodd=evenodd, + )) + else: + self.cur_item.add(LTLine( + linewidth=gstate.linewidth, + paths=paths, + bbox=Bbox( x0, y0, x1, y1 ), + stroke=gstate.scolor, + fill=gstate.ncolor, + evenodd=evenodd, + )) + elif shape == 'mlllh': # rectangle - (_, x0, y0) = path[0] - (_, x1, y1) = path[1] - (_, x2, y2) = path[2] - (_, x3, y3) = path[3] - (x0, y0) = apply_matrix_pt(self.ctm, (x0, y0)) - (x1, y1) = apply_matrix_pt(self.ctm, (x1, y1)) - (x2, y2) = apply_matrix_pt(self.ctm, (x2, y2)) - (x3, y3) = apply_matrix_pt(self.ctm, (x3, y3)) + pt0 = paths[0].points[0] + pt1 = paths[1].points[0] + pt2 = paths[2].points[0] + pt3 = paths[3].points[0] + (x0, y0) = apply_matrix_pt(self.ctm, (pt0.x, pt0.y)) + (x1, y1) = apply_matrix_pt(self.ctm, (pt1.x, pt1.y)) + (x2, y2) = apply_matrix_pt(self.ctm, (pt2.x, pt2.y)) + (x3, y3) = apply_matrix_pt(self.ctm, (pt3.x, pt3.y)) if ((x0 == x1 and y1 == y2 and x2 == x3 and y3 == y0) or (y0 == y1 and x1 == x2 and y2 == y3 and x3 == x0)): self.cur_item.add(LTRect( linewidth=gstate.linewidth, - pts=[ - (x0, y0), (x0, y2), - (x2, y0), (x2, y2) - ], + paths=paths, + bbox=Bbox( + x0=min(x0,x1,x2,x3), + x1=max(x0,x1,x2,x3), + y0=min(y0,y1,y2,y3), + y1=max(y0,y1,y2,y3), + ), evenodd=evenodd, stroke=gstate.scolor, fill=gstate.ncolor, )) - return - # other shapes - pts = [] - for p in path: - for i in range(1, len(p), 2): - pts.append(apply_matrix_pt(self.ctm, (p[i], p[i+1]))) - self.cur_item.add(LTCurve( - linewidth=gstate.linewidth, - pts=pts, - evenodd=evenodd, - stroke=gstate.scolor, - fill=gstate.ncolor - )) - return + else: + (x0, y0, x1, y1) = (INF, INF, -INF, -INF) + for path in paths: + if path.method in [CurvePath.METHOD.MOVE_TO, CurvePath.METHOD.LINE_TO]: + x0 = min(x0, path.points[0].x) + y0 = min(y0, path.points[0].y) + x1 = max(x1, path.points[0].x) + y1 = max(y1, path.points[0].y) + elif path.method in [CurvePath.METHOD.CURVE_BOTH_TO]: + x0 = min(x0, path.points[2].x) + y0 = min(y0, path.points[2].y) + x1 = max(x1, path.points[2].x) + y1 = max(y1, path.points[2].y) + elif path.method in [CurvePath.METHOD.CURVE_NEXT_TO, CurvePath.METHOD.CURVE_FIRST_TO]: + x0 = min(x0, path.points[1].x) + y0 = min(y0, path.points[1].y) + x1 = max(x1, path.points[1].x) + y1 = max(y1, path.points[1].y) + # for p in path: + # paths.append(apply_matrix_pt(self.ctm, (p.x, p.y))) + self.cur_item.add(LTCurve( + linewidth=gstate.linewidth, + paths=paths, + bbox=Bbox(x0,y0,x1,y1), + evenodd=evenodd, + stroke=gstate.scolor, + fill=gstate.ncolor + )) def render_char(self, matrix: List[Point], font, fontsize, scaling, rise, cid, ncs, graphicstate): try: diff --git a/samples/convert_samples.py b/samples/convert_samples.py index be1e9ea..9234d15 100644 --- a/samples/convert_samples.py +++ b/samples/convert_samples.py @@ -1,12 +1,13 @@ import re import os + from typing import List from pdfmajor.converters import convert_file def rel_path(*arg: List[str]) -> str: return os.path.join(os.path.dirname(__file__), *arg) -EXT = 'html' +EXT = 'xml' INPUT_FOLDER = rel_path("./pdf") OUTPUT_FOLDER = rel_path(f"./output/{EXT}") @@ -14,6 +15,8 @@ if not os.path.exists(OUTPUT_FOLDER): os.makedirs(OUTPUT_FOLDER) files = os.listdir(INPUT_FOLDER) +# files = ['colors.pdf'] +# files = ['bar-charts.pdf'] TOTAL = len(files) for idx, file_name in enumerate(files): diff --git a/samples/output/html/bar-charts.html b/samples/output/html/bar-charts.html index 98d6c97..62124a7 100644 --- a/samples/output/html/bar-charts.html +++ b/samples/output/html/bar-charts.html @@ -16,262 +16,265 @@ -
-
-
-
-
-
- + + + + + + + + + + + + +
+ 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + C - + a - + t - + e - + g - + o - + r - + y - + - + 1 - + C - + a - + t - + e - + g - + o - + r - + y - + - + 2 - + C - + a - + t - + e - + g - + o - + r - + y - + - + 3 - + C - + a - + t - + e - + g - + o - + r - + y - + - + 4 - + C - + h - + a - + r - + t - + - + T - + i - + t - + l - + e -
- + S - + e - + r - + i - + e - + s - + - + 1 -
- + S - + e - + r - + i - + e - + s - + - + 2 -
- + S - + e - + r - + i - + e - + s - + - + 3 -
@@ -283,325 +286,328 @@ -
-
-
-
-
-
- + + + + + + + + + + + + +
+ 4 - + . - + 3 - + 2 - + . - + 5 - + 3 - + . - + 5 - + 4 - + . - + 5 - + 2 - + . - + 4 - + 4 - + . - + 4 - + 1 - + . - + 8 - + 2 - + . - + 8 - + 2 - + 2 - + 3 - + 5 - + C - + A - + T - + E - + G - + O - + R - + Y - + - + 1 - + C - + A - + T - + E - + G - + O - + R - + Y - + - + 2 - + C - + A - + T - + E - + G - + O - + R - + Y - + - + 3 - + C - + A - + T - + E - + G - + O - + R - + Y - + - + 4 - + C - + H - + A - + R - + T - + - + T - + I - + T - + L - + E -
- + S - + e - + r - + i - + e - + s - + - + 1 -
- + S - + e - + r - + i - + e - + s - + - + 2 -
- + S - + e - + r - + i - + e - + s - + - + 3 -
@@ -613,4 +619,1216 @@ -
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+
+ + 0 + + + 1 + + + 2 + + + 3 + + + 4 + + + 5 + + + 6 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 1 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 2 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 3 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 4 + + + C + + + H + + + A + + + R + + + T + + + + + + T + + + I + + + T + + + L + + + E + +
+ +
+ + S + + + e + + + r + + + i + + + e + + + s + + + + + + 1 + +
+ +
+ + S + + + e + + + r + + + i + + + e + + + s + + + + + + 2 + +
+ +
+ + S + + + e + + + r + + + i + + + e + + + s + + + + + + 3 + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + 4 + + + . + + + 3 + + + 2 + + + . + + + 5 + + + 3 + + + . + + + 5 + + + 4 + + + . + + + 5 + + + 2 + + + . + + + 4 + + + 4 + + + . + + + 4 + + + 1 + + + . + + + 8 + + + 2 + + + . + + + 8 + + + 2 + + + 2 + + + 3 + + + 5 + + + C + + + A + + + T + + + E + + + G + + + O + + + R + + + Y + + + + + + 1 + + + C + + + A + + + T + + + E + + + G + + + O + + + R + + + Y + + + + + + 2 + + + C + + + A + + + T + + + E + + + G + + + O + + + R + + + Y + + + + + + 3 + + + C + + + A + + + T + + + E + + + G + + + O + + + R + + + Y + + + + + + 4 + + + C + + + h + + + a + + + r + + + t + + + + + + T + + + i + + + t + + + l + + + e + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 1 + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 2 + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 3 + +
+
+ + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + 0 + + + 1 + + + 2 + + + 3 + + + 4 + + + 5 + + + 6 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 1 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 2 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 3 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 4 + +
+ +
+ + C + + + h + + + a + + + r + + + t + + + + + + T + + + i + + + t + + + l + + + e + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 1 + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 2 + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 3 + +
+
+ + + + + + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + 0 + + + 1 + + + 2 + + + 3 + + + 4 + + + 5 + + + 6 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 1 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 2 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 3 + + + C + + + a + + + t + + + e + + + g + + + o + + + r + + + y + + + + + + 4 + +
+ +
+ + C + + + h + + + a + + + r + + + t + + + + + + T + + + i + + + t + + + l + + + e + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 1 + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 2 + + + S + + + e + + + r + + + i + + + e + + + s + + + + + + 3 + +
+ + diff --git a/samples/output/html/colors.html b/samples/output/html/colors.html index 5449b8b..dae97d5 100644 --- a/samples/output/html/colors.html +++ b/samples/output/html/colors.html @@ -7,68 +7,68 @@
-
- +
+ Y - + e - + l - + l - + o - + w -
- +
+ R - + e - + d -
- +
+ G - + r - + e - + e - + n -
- +
+ R - + a - + n - + d - + o - + m
diff --git a/samples/output/html/line-charts.html b/samples/output/html/line-charts.html deleted file mode 100644 index e69de29..0000000 diff --git a/samples/output/html/tables.html b/samples/output/html/tables.html index ffb9451..512b05c 100644 --- a/samples/output/html/tables.html +++ b/samples/output/html/tables.html @@ -142,25 +142,25 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -284,23 +284,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -412,23 +412,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -543,23 +543,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -671,36 +671,36 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -844,27 +844,27 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -898,8 +898,8 @@ -
-
+
+
1 @@ -924,8 +924,8 @@ -
-
+
+
$ @@ -965,8 +965,8 @@ -
-
+
+
M @@ -982,8 +982,8 @@ -
-
+
+
P @@ -996,23 +996,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -1124,25 +1124,25 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -1176,8 +1176,8 @@ -
-
+
+
5 @@ -1196,8 +1196,8 @@ -
-
+
+
$ @@ -1237,8 +1237,8 @@ -
-
+
+
S @@ -1251,8 +1251,8 @@ -
-
+
+
P @@ -1265,23 +1265,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -1393,36 +1393,36 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1569,15 +1569,15 @@ -
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
2 @@ -1701,15 +1701,15 @@ -
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
2 @@ -1821,15 +1821,15 @@ -
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
2 @@ -1944,15 +1944,15 @@ -
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
2 @@ -2064,24 +2064,24 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -2228,8 +2228,8 @@ -
-
+
+
2 @@ -2263,8 +2263,8 @@ -
-
+
+
1 @@ -2289,8 +2289,8 @@ -
-
+
+
$ @@ -2330,8 +2330,8 @@ -
-
+
+
M @@ -2347,8 +2347,8 @@ -
-
+
+
P @@ -2361,17 +2361,17 @@ -
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
2 @@ -2483,9 +2483,9 @@ -
-
-
+
+
+
2 @@ -2519,8 +2519,8 @@ -
-
+
+
5 @@ -2539,8 +2539,8 @@ -
-
+
+
$ @@ -2580,8 +2580,8 @@ -
-
+
+
S @@ -2594,8 +2594,8 @@ -
-
+
+
P @@ -2608,7 +2608,7 @@ -
+
2 @@ -2720,7 +2720,7 @@ -
+
@@ -2867,25 +2867,25 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -3009,27 +3009,27 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -3141,23 +3141,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -3272,23 +3272,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -3400,36 +3400,36 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -3441,8 +3441,8 @@
-
-
+
+
D @@ -3458,8 +3458,8 @@ -
-
+
+
C @@ -3490,8 +3490,8 @@ -
-
+
+
C @@ -3522,8 +3522,8 @@ -
-
+
+
C @@ -3554,8 +3554,8 @@ -
-
+
+
C @@ -3586,8 +3586,8 @@ -
-
+
+
2 @@ -3621,8 +3621,8 @@ -
-
+
+
1 @@ -3647,8 +3647,8 @@ -
-
+
+
$ @@ -3688,8 +3688,8 @@ -
-
+
+
M @@ -3705,8 +3705,8 @@ -
-
+
+
P @@ -3719,27 +3719,27 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -3851,23 +3851,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -3901,8 +3901,8 @@ -
-
+
+
5 @@ -3921,8 +3921,8 @@ -
-
+
+
$ @@ -3962,8 +3962,8 @@ -
-
+
+
S @@ -3976,8 +3976,8 @@ -
-
+
+
P @@ -3990,23 +3990,23 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2 @@ -4118,32 +4118,32 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+