def __init__(self, matrix, font, fontsize, scaling, cid): self.matrix = matrix self.font = font self.fontsize = fontsize self.vertical = font.is_vertical() self.adv = font.char_width(cid) * fontsize * scaling try: text = font.to_unichr(cid) except PDFUnicodeNotDefined: text = '?' LTText.__init__(self, text) # compute the boundary rectangle. if self.vertical: # vertical size = font.get_size() * fontsize displacement = (1000 - font.char_disp(cid)) * fontsize * .001 (_,displacement) = apply_matrix_norm(self.matrix, (0, displacement)) (dx,dy) = apply_matrix_norm(self.matrix, (size, self.adv)) (_,_,_,_,tx,ty) = self.matrix tx -= dx/2 ty += displacement bbox = (tx, ty+dy, tx+dx, ty) else: # horizontal size = font.get_size() * fontsize descent = font.get_descent() * fontsize (_,descent) = apply_matrix_norm(self.matrix, (0, descent)) (dx,dy) = apply_matrix_norm(self.matrix, (self.adv, size)) (_,_,_,_,tx,ty) = self.matrix ty += descent bbox = (tx, ty, tx+dx, ty+dy) LTItem.__init__(self, bbox) return
def __init__(self, matrix, font, fontsize, charspace, scaling, chars): assert chars self.matrix = matrix self.font = font self.vertical = font.is_vertical() self.text = ''.join( char for (char,_) in chars ) adv = sum( font.char_width(cid) for (_,cid) in chars ) adv = (adv * fontsize + (len(chars)-1)*charspace) * scaling #size = (font.get_ascent() - font.get_descent()) * fontsize size = font.get_size() * fontsize (_,_,_,_,tx,ty) = self.matrix if not self.vertical: # horizontal text self.adv = (adv, 0) (dx,dy) = apply_matrix_norm(self.matrix, (adv,size)) (_,descent) = apply_matrix_norm(self.matrix, (0,font.get_descent() * fontsize)) ty += descent bbox = (tx, ty, tx+dx, ty+dy) else: # vertical text self.adv = (0, adv) (_,cid) = chars[0] (_,disp) = apply_matrix_norm(self.matrix, (0, (1000-font.char_disp(cid))*fontsize*.001)) (dx,dy) = apply_matrix_norm(self.matrix, (size,adv)) tx -= dx/2 ty += disp bbox = (tx, ty+dy, tx+dx, ty) self.fontsize = max(apply_matrix_norm(self.matrix, (size,size))) LayoutItem.__init__(self, bbox) return
def __init__(self, matrix, font, fontsize, scaling, cid): self.matrix = matrix self.font = font self.fontsize = fontsize self.vertical = font.is_vertical() self.adv = font.char_width(cid) * fontsize * scaling try: text = font.to_unichr(cid) except PDFUnicodeNotDefined: text = '?' LTText.__init__(self, text) # compute the boundary rectangle. if self.vertical: # vertical size = font.get_size() * fontsize displacement = (1000 - font.char_disp(cid)) * fontsize * .001 (_, displacement) = apply_matrix_norm(self.matrix, (0, displacement)) (dx, dy) = apply_matrix_norm(self.matrix, (size, self.adv)) (_, _, _, _, tx, ty) = self.matrix tx -= dx / 2 ty += displacement bbox = (tx, ty + dy, tx + dx, ty) else: # horizontal size = font.get_size() * fontsize descent = font.get_descent() * fontsize (_, descent) = apply_matrix_norm(self.matrix, (0, descent)) (dx, dy) = apply_matrix_norm(self.matrix, (self.adv, size)) (_, _, _, _, tx, ty) = self.matrix ty += descent bbox = (tx, ty, tx + dx, ty + dy) LTItem.__init__(self, bbox) return
def __init__(self, matrix, font, fontsize, charspace, scaling, text): self.matrix = matrix self.font = font (_,_,_,_,tx,ty) = self.matrix self.origin = (tx,ty) self.direction = 0 self.text = '' scaling *= .01 size = (font.get_ascent() - font.get_descent()) * fontsize if not self.font.is_vertical(): # horizontal text spwidth = font.char_width(32) * self.SPACE_WIDTH # space width self.direction = 1 w = 0 dx = 0 prev = ' ' for (char,cid,t) in text: if char: if prev != ' ' and spwidth < dx: self.text += ' ' prev = char self.text += char dx = 0 w += (font.char_width(cid) * fontsize + charspace) * scaling else: t *= .001 dx -= t w -= t * fontsize * scaling (_,descent) = apply_matrix_norm(self.matrix, (0,font.get_descent() * fontsize)) ty += descent (w,h) = apply_matrix_norm(self.matrix, (w,size)) self.adv = (w, 0) self.bbox = (tx, ty, tx+w, ty+h) else: # vertical text self.direction = 2 disp = 0 h = 0 for (char,cid,disp) in text: if not char: continue (_,disp) = apply_matrix_norm(self.matrix, (0, (1000-disp)*fontsize*.001)) self.text += font.to_unicode(cid) h += (font.char_width(cid) * fontsize + charspace) * scaling break for (char,cid,_) in text: if not char: continue self.text += font.to_unicode(cid) h += (font.char_width(cid) * fontsize + charspace) * scaling (w,h) = apply_matrix_norm(self.matrix, (size,h)) tx -= w/2 ty += disp self.adv = (0, h) self.bbox = (tx, ty+h, tx+w, ty) self.fontsize = max(apply_matrix_norm(self.matrix, (size,size))) return
def __init__(self, rsrcmgr, spec): firstchar = int_value(spec.get('FirstChar', 0)) lastchar = int_value(spec.get('LastChar', 0)) widths = list_value(spec.get('Widths', [0] * 256)) widths = dict((i + firstchar, w) for (i, w) in enumerate(widths)) if 'FontDescriptor' in spec: descriptor = dict_value(spec['FontDescriptor']) else: descriptor = {'Ascent': 0, 'Descent': 0, 'FontBBox': spec['FontBBox']} PDFSimpleFont.__init__(self, descriptor, widths, spec) self.matrix = tuple(list_value(spec.get('FontMatrix'))) (_, self.descent, _, self.ascent) = self.bbox (self.hscale, self.vscale) = apply_matrix_norm(self.matrix, (1, 1))
def __init__(self, rsrcmgr, spec): firstchar = int_value(spec.get("FirstChar", 0)) lastchar = int_value(spec.get("LastChar", 0)) widths = list_value(spec.get("Widths", [0] * 256)) widths = dict((i + firstchar, w) for (i, w) in enumerate(widths)) if "FontDescriptor" in spec: descriptor = dict_value(spec["FontDescriptor"]) else: descriptor = {"Ascent": 0, "Descent": 0, "FontBBox": spec["FontBBox"]} PDFSimpleFont.__init__(self, descriptor, widths, spec) self.matrix = tuple(list_value(spec.get("FontMatrix"))) (_, self.descent, _, self.ascent) = self.bbox (self.hscale, self.vscale) = apply_matrix_norm(self.matrix, (1, 1)) return
def __init__(self, rsrcmgr, spec): firstchar = int_value(spec.get('FirstChar', 0)) lastchar = int_value(spec.get('LastChar', 0)) widths = list_value(spec.get('Widths', [0]*256)) widths = dict( (i+firstchar,w) for (i,w) in enumerate(widths)) if 'FontDescriptor' in spec: descriptor = dict_value(spec['FontDescriptor']) else: descriptor = {'Ascent':0, 'Descent':0, 'FontBBox':spec['FontBBox']} PDFSimpleFont.__init__(self, descriptor, widths, spec) self.matrix = tuple(list_value(spec.get('FontMatrix'))) (_,self.descent,_,self.ascent) = self.bbox (self.hscale,self.vscale) = apply_matrix_norm(self.matrix, (1,1)) return
def __init__(self, matrix, font, fontsize, charspace, scaling, text): self.matrix = matrix self.font = font (_, _, _, _, tx, ty) = self.matrix self.origin = (tx, ty) self.direction = 0 self.text = '' scaling *= .01 size = (font.get_ascent() - font.get_descent()) * fontsize if not self.font.is_vertical(): # horizontal text spwidth = font.char_width(32) * self.SPACE_WIDTH # space width self.direction = 1 w = 0 dx = 0 prev = ' ' for (char, cid, t) in text: if char: if prev != ' ' and spwidth < dx: self.text += ' ' prev = char self.text += char dx = 0 w += (font.char_width(cid) * fontsize + charspace) * scaling else: t *= .001 dx -= t w -= t * fontsize * scaling (_, descent) = apply_matrix_norm(self.matrix, (0, font.get_descent() * fontsize)) ty += descent (w, h) = apply_matrix_norm(self.matrix, (w, size)) self.adv = (w, 0) self.bbox = (tx, ty, tx + w, ty + h) else: # vertical text self.direction = 2 disp = 0 h = 0 for (char, cid, disp) in text: if not char: continue (_, disp) = apply_matrix_norm(self.matrix, (0, (1000 - disp) * fontsize * .001)) self.text += font.to_unicode(cid) h += (font.char_width(cid) * fontsize + charspace) * scaling break for (char, cid, _) in text: if not char: continue self.text += font.to_unicode(cid) h += (font.char_width(cid) * fontsize + charspace) * scaling (w, h) = apply_matrix_norm(self.matrix, (size, h)) tx -= w / 2 ty += disp self.adv = (0, h) self.bbox = (tx, ty + h, tx + w, ty) self.fontsize = max(apply_matrix_norm(self.matrix, (size, size))) return