def begin_page(self, page, ctm): (x0,y0,x1,y1) = page.mediabox (x0,y0) = apply_matrix_pt(ctm, (x0,y0)) (x1,y1) = apply_matrix_pt(ctm, (x1,y1)) mediabox = (0, 0, abs(x0-x1), abs(y0-y1)) self.cur_item = LTPage(self.pageno, mediabox) return
def begin_page(self, page, ctm): (x0, y0, x1, y1) = page.mediabox (x0, y0) = apply_matrix_pt(ctm, (x0, y0)) (x1, y1) = apply_matrix_pt(ctm, (x1, y1)) mediabox = (0, 0, abs(x0 - x1), abs(y0 - y1)) self.cur_item = LTPage(self.pageno, mediabox) return
def __init__(self, name, bbox, matrix): self.name = name self.matrix = matrix (x, y, w, h) = bbox bbox = get_bound(apply_matrix_pt(matrix, (p, q)) for (p, q) in ((x, y), (x + w, y), (x, y + h), (x + w, y + h))) LTLayoutContainer.__init__(self, bbox) return
def __init__(self, id, bbox, matrix): (x,y,w,h) = bbox bbox = get_bounds( apply_matrix_pt(matrix, (p,q)) for (p,q) in ((x,y), (x+w,y), (x,y+h), (x+w,y+h)) ) self.matrix = matrix LayoutContainer.__init__(self, id, bbox) return
def __init__(self, name, bbox, matrix): (x,y,w,h) = bbox bbox = get_bounds( apply_matrix_pt(matrix, (p,q)) for (p,q) in ((x,y), (x+w,y), (x,y+h), (x+w,y+h)) ) LTAnalyzer.__init__(self, bbox) self.name = name self.matrix = matrix return
def __init__(self, name, bbox, matrix): self.name = name self.matrix = matrix (x, y, w, h) = bbox bbox = get_bound(apply_matrix_pt(matrix, (p, q)) for (p, q) in ((x, y), (x+w, y), (x, y+h), (x+w, y+h))) LTLayoutContainer.__init__(self, bbox) return
def __init__(self, matrix, font, fontsize, scaling, rise, text, textwidth, textdisp): LTText.__init__(self) self._text = text self.matrix = matrix self.fontname = font.fontname self.adv = textwidth * fontsize * scaling m0 = abs(matrix[0]) m1 = abs(matrix[1]) self.direction = 0 if ( m0 > .001 and m1 < .001) else \ 1 if (m0 < .001 and m1 > .001) else 2 # compute the boundary rectangle. if font.is_vertical(): # vertical width = font.get_width() * fontsize (vx, vy) = textdisp if vx is None: vx = width//2 else: vx = vx * fontsize * .001 vy = (1000 - vy) * fontsize * .001 tx = -vx ty = vy + rise bll = (tx, ty+self.adv) bur = (tx+width, ty) else: # horizontal height = font.get_height() * fontsize descent = font.get_descent() * fontsize ty = descent + rise bll = (0, ty) bur = (self.adv, ty+height) (a, b, c, d, e, f) = self.matrix self.upright = (0 < a*d*scaling and b*c <= 0) (x0, y0) = apply_matrix_pt(self.matrix, bll) (x1, y1) = apply_matrix_pt(self.matrix, bur) if x1 < x0: (x0, x1) = (x1, x0) if y1 < y0: (y0, y1) = (y1, y0) LTComponent.__init__(self, (x0, y0, x1, y1)) if font.is_vertical(): self.size = self.width else: self.size = self.height return
def paint_path(self, gstate, stroke, fill, evenodd, path): shape = ''.join(x[0] for x in path) 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))) return if 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)) 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(gstate.linewidth, (x0, y0, x2, y2))) return # other shapes pts = [] for p in path: for i in xrange(1, len(p), 2): pts.append(apply_matrix_pt(self.ctm, (p[i], p[i + 1]))) self.cur_item.add(LTCurve(gstate.linewidth, pts)) return
def paint_path(self, gstate, stroke, fill, evenodd, path): shape = ''.join(x[0] for x in path) 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))) return if 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)) 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(gstate.linewidth, (x0,y0,x2,y2))) return # other shapes pts = [] for p in path: for i in xrange(1, len(p), 2): pts.append(apply_matrix_pt(self.ctm, (p[i], p[i+1]))) self.cur_item.add(LTCurve(gstate.linewidth, pts)) return
def __init__(self, name, bbox, matrix): (x, y, w, h) = bbox bbox = get_bounds( apply_matrix_pt(matrix, (p, q)) for (p, q) in ((x, y), (x + w, y), (x, y + h), (x + w, y + h))) LTAnalyzer.__init__(self, bbox) self.name = name self.matrix = matrix return
def __init__(self, matrix, font, fontsize, scaling, rise, text, textwidth, textdisp): LTText.__init__(self) self._text = text self.matrix = matrix self.fontsize = fontsize self.fontname = font.fontname self.adv = textwidth * fontsize * scaling # compute the boundary rectangle. if font.is_vertical(): # vertical width = font.get_width() * fontsize (vx, vy) = textdisp if vx is None: vx = width // 2 else: vx = vx * fontsize * .001 vy = (1000 - vy) * fontsize * .001 tx = -vx ty = vy + rise bll = (tx, ty + self.adv) bur = (tx + width, ty) else: # horizontal height = font.get_height() * fontsize descent = font.get_descent() * fontsize ty = descent + rise bll = (0, ty) bur = (self.adv, ty + height) (a, b, c, d, e, f) = self.matrix self.upright = (0 < a * d * scaling and b * c <= 0) (x0, y0) = apply_matrix_pt(self.matrix, bll) (x1, y1) = apply_matrix_pt(self.matrix, bur) if x1 < x0: (x0, x1) = (x1, x0) if y1 < y0: (y0, y1) = (y1, y0) LTComponent.__init__(self, (x0, y0, x1, y1)) if font.is_vertical(): self.size = self.width else: self.size = self.height return
def __init__(self, matrix, font, fontsize, scaling, rise, cid): self.matrix = matrix self.font = font self.fontsize = fontsize self.adv = font.char_width(cid) * fontsize * scaling try: text = font.to_unichr(cid) assert isinstance(text, unicode), text except PDFUnicodeNotDefined: text = '?' LTText.__init__(self, text) # compute the boundary rectangle. if self.font.is_vertical(): # vertical width = font.get_width() * fontsize (vx,vy) = font.char_disp(cid) if vx is None: vx = width/2 else: vx = vx * fontsize * .001 vy = (1000 - vy) * fontsize * .001 tx = -vx ty = vy + rise bll = (tx, ty+self.adv) bur = (tx+width, ty) else: # horizontal height = font.get_height() * fontsize descent = font.get_descent() * fontsize ty = descent + rise bll = (0, ty) bur = (self.adv, ty+height) (a,b,c,d,e,f) = self.matrix self.upright = (0 < a*d*scaling and b*c <= 0) bbox = (apply_matrix_pt(self.matrix, bll) + apply_matrix_pt(self.matrix, bur)) LTItem.__init__(self, bbox) return