예제 #1
0
 def do_Do(self, xobjid):
     xobjid = literal_name(xobjid)
     try:
         xobj = stream_value(self.xobjmap[xobjid])
     except KeyError:
         if STRICT:
             raise PDFInterpreterError('Undefined xobject id: %r' % xobjid)
         return
     if 1 <= self.debug:
         print >>sys.stderr, 'Processing xobj: %r' % xobj
     subtype = xobj.get('Subtype')
     if subtype is LITERAL_FORM and 'BBox' in xobj:
         interpreter = self.dup()
         bbox = list_value(xobj['BBox'])
         matrix = list_value(xobj.get('Matrix', MATRIX_IDENTITY))
         # According to PDF reference 1.7 section 4.9.1, XObjects in 
         # earlier PDFs (prior to v1.2) use the page's Resources entry
         # instead of having their own Resources entry.
         resources = dict_value(xobj.get('Resources')) or self.resources.copy()
         self.device.begin_figure(xobjid, bbox, matrix)
         interpreter.render_contents(resources, [xobj], ctm=mult_matrix(matrix, self.ctm))
         self.device.end_figure(xobjid)
     elif subtype is LITERAL_IMAGE and 'Width' in xobj and 'Height' in xobj:
         self.device.begin_figure(xobjid, (0,0,1,1), MATRIX_IDENTITY)
         self.device.render_image(xobjid, xobj)
         self.device.end_figure(xobjid)
     else:
         # unsupported xobject type.
         pass
     return
 def do_Do(self, xobjid):
     xobjid = literal_name(xobjid)
     try:
         xobj = stream_value(self.xobjmap[xobjid])
     except KeyError:
         if STRICT:
             raise PDFInterpreterError('Undefined xobject id: %r' % xobjid)
         return
     if 1 <= self.debug:
         print >>sys.stderr, 'Processing xobj: %r' % xobj
     subtype = xobj.get('Subtype')
     if subtype is LITERAL_FORM and 'BBox' in xobj:
         interpreter = self.dup()
         bbox = list_value(xobj['BBox'])
         matrix = list_value(xobj.get('Matrix', MATRIX_IDENTITY))
         # According to PDF reference 1.7 section 4.9.1, XObjects in 
         # earlier PDFs (prior to v1.2) use the page's Resources entry
         # instead of having their own Resources entry.
         resources = dict_value(xobj.get('Resources')) or self.resources.copy()
         self.device.begin_figure(xobjid, bbox, matrix)
         interpreter.render_contents(resources, [xobj], ctm=mult_matrix(matrix, self.ctm))
         self.device.end_figure(xobjid)
     elif subtype is LITERAL_IMAGE and 'Width' in xobj and 'Height' in xobj:
         self.device.begin_figure(xobjid, (0,0,1,1), MATRIX_IDENTITY)
         self.device.render_image(xobjid, xobj)
         self.device.end_figure(xobjid)
     else:
         # unsupported xobject type.
         pass
     return
예제 #3
0
 def do_Do(self, xobjid):
     xobjid = literal_name(xobjid)
     try:
         xobj = stream_value(self.xobjmap[xobjid])
     except KeyError:
         if STRICT:
             raise PDFInterpreterError('Undefined xobject id: %r' % xobjid)
         return
     if 1 <= self.debug:
         print >> stderr, 'Processing xobj: %r' % xobj
     subtype = xobj.dic.get('Subtype')
     if subtype is LITERAL_FORM and 'BBox' in xobj.dic:
         interpreter = self.dup()
         (x0, y0, x1, y1) = list_value(xobj.dic['BBox'])
         ctm = mult_matrix(
             list_value(xobj.dic.get('Matrix', MATRIX_IDENTITY)), self.ctm)
         (x0, y0) = apply_matrix(ctm, (x0, y0))
         (x1, y1) = apply_matrix(ctm, (x1, y1))
         bbox = (x0, y0, x1, y1)
         self.device.begin_figure(xobjid, bbox)
         interpreter.render_contents(dict_value(xobj.dic.get('Resources')),
                                     [xobj],
                                     ctm=ctm)
         self.device.end_figure(xobjid)
     elif subtype is LITERAL_IMAGE and 'Width' in xobj.dic and 'Height' in xobj.dic:
         (x0, y0) = apply_matrix(self.ctm, (0, 0))
         (x1, y1) = apply_matrix(self.ctm, (1, 1))
         self.device.begin_figure(xobjid, (x0, y0, x1, y1))
         (w, h) = (xobj.dic['Width'], xobj.dic['Height'])
         self.device.render_image(xobj, (w, h), self.ctm)
         self.device.end_figure(xobjid)
     else:
         # unsupported xobject type.
         pass
     return
예제 #4
0
 def do_Do(self, xobjid):
     xobjid = literal_name(xobjid)
     try:
         xobj = stream_value(self.xobjmap[xobjid])
     except KeyError:
         if STRICT:
             raise PDFInterpreterError('Undefined xobject id: %r' % xobjid)
         return
     if 1 <= self.debug:
         print >> stderr, 'Processing xobj: %r' % xobj
     subtype = xobj.get('Subtype')
     if subtype is LITERAL_FORM and 'BBox' in xobj:
         interpreter = self.dup()
         bbox = list_value(xobj['BBox'])
         matrix = list_value(xobj.get('Matrix', MATRIX_IDENTITY))
         self.device.begin_figure(xobjid, bbox, matrix)
         interpreter.render_contents(dict_value(xobj.get('Resources')),
                                     [xobj],
                                     ctm=mult_matrix(matrix, self.ctm))
         self.device.end_figure(xobjid)
     elif subtype is LITERAL_IMAGE and 'Width' in xobj and 'Height' in xobj:
         self.device.begin_figure(xobjid, (0, 0, 1, 1), MATRIX_IDENTITY)
         self.device.render_image(xobjid, xobj)
         self.device.end_figure(xobjid)
     else:
         # unsupported xobject type.
         pass
     return
예제 #5
0
 def render_string(self, textstate, textmatrix, seq):
     font = textstate.font
     text = []
     textmatrix = mult_matrix(textmatrix, self.ctm)
     for x in seq:
         if isinstance(x, int) or isinstance(x, float):
             text.append((None, None, x))
         else:
             chars = font.decode(x)
             for cid in chars:
                 try:
                     char = font.to_unicode(cid)
                 except PDFUnicodeNotDefined, e:
                     (cidcoding, cid) = e.args
                     char = self.handle_undefined_char(cidcoding, cid)
                 text.append((char, cid, font.char_disp(cid)))
                 if cid == 32 and not font.is_multibyte():
                     if text:
                         item = TextItem(textmatrix, font,
                                         textstate.fontsize,
                                         textstate.charspace,
                                         textstate.scaling, text)
                         self.cur_item.add(item)
                         (dx, dy) = item.adv
                         dx += textstate.wordspace * textstate.scaling * .01
                         textmatrix = translate_matrix(textmatrix, (dx, dy))
                         text = []
예제 #6
0
 def do_Do(self, xobjid):
     xobjid = literal_name(xobjid)
     try:
         xobj = stream_value(self.xobjmap[xobjid])
     except KeyError:
         if STRICT:
             raise PDFInterpreterError("Undefined xobject id: %r" % xobjid)
         return
     if 1 <= self.debug:
         print >> stderr, "Processing xobj: %r" % xobj
     subtype = xobj.dic.get("Subtype")
     if subtype is LITERAL_FORM and "BBox" in xobj.dic:
         interpreter = self.dup()
         (x0, y0, x1, y1) = list_value(xobj.dic["BBox"])
         ctm = mult_matrix(list_value(xobj.dic.get("Matrix", MATRIX_IDENTITY)), self.ctm)
         (x0, y0) = apply_matrix(ctm, (x0, y0))
         (x1, y1) = apply_matrix(ctm, (x1, y1))
         bbox = (x0, y0, x1, y1)
         self.device.begin_figure(xobjid, bbox)
         interpreter.render_contents(dict_value(xobj.dic.get("Resources")), [xobj], ctm=ctm)
         self.device.end_figure(xobjid)
     elif subtype is LITERAL_IMAGE and "Width" in xobj.dic and "Height" in xobj.dic:
         (x0, y0) = apply_matrix(self.ctm, (0, 0))
         (x1, y1) = apply_matrix(self.ctm, (1, 1))
         self.device.begin_figure(xobjid, (x0, y0, x1, y1))
         (w, h) = (xobj.dic["Width"], xobj.dic["Height"])
         self.device.render_image(xobj, (w, h), self.ctm)
         self.device.end_figure(xobjid)
     else:
         # unsupported xobject type.
         pass
     return
예제 #7
0
 def render_string(self, textstate, seq):
     matrix = mult_matrix(textstate.matrix, self.ctm)
     font = textstate.font
     fontsize = textstate.fontsize
     scaling = textstate.scaling * .01
     charspace = textstate.charspace * scaling
     wordspace = textstate.wordspace * scaling
     if font.is_multibyte():
         wordspace = 0
     dxscale = .001 * fontsize * scaling
     if font.is_vertical():
         textstate.linematrix = self.render_string_vertical(
             seq, matrix, textstate.linematrix, font, fontsize, scaling, charspace, wordspace, dxscale)
     else:
         textstate.linematrix = self.render_string_horizontal(
             seq, matrix, textstate.linematrix, font, fontsize, scaling, charspace, wordspace, dxscale)
     return
예제 #8
0
파일: pdfdevice.py 프로젝트: Big-Data/pypes
 def render_string(self, textstate, textmatrix, seq):
   font = textstate.font
   text = []
   textmatrix = mult_matrix(textmatrix, self.ctm)
   for x in seq:
     if isinstance(x, int) or isinstance(x, float):
       text.append((None, None, x))
     else:
       chars = font.decode(x)
       for cid in chars:
         try:
           char = font.to_unicode(cid)
         except PDFUnicodeNotDefined, e:
           (cidcoding, cid) = e.args
           char = self.handle_undefined_char(cidcoding, cid)
         text.append((char, cid, font.char_disp(cid)))
         if cid == 32 and not font.is_multibyte():
           if text:
             item = TextItem(textmatrix, font, textstate.fontsize, textstate.charspace, textstate.scaling, text)
             self.cur_item.add(item)
             (dx,dy) = item.adv
             dx += textstate.wordspace * textstate.scaling * .01
             textmatrix = translate_matrix(textmatrix, (dx, dy))
             text = []
예제 #9
0
 def begin_figure(self, name, bbox, matrix):
     self._stack.append(self.cur_item)
     self.cur_item = LTFigure(name, bbox, mult_matrix(matrix, self.ctm))
     return
예제 #10
0
 def begin_figure(self, name, bbox, matrix):
     self._stack.append(self.cur_item)
     self.cur_item = LTFigure(name, bbox, mult_matrix(matrix, self.ctm))
     return
예제 #11
0
 def do_cm(self, a1, b1, c1, d1, e1, f1):
     self.ctm = mult_matrix((a1,b1,c1,d1,e1,f1), self.ctm)
     self.device.set_ctm(self.ctm)
     return
예제 #12
0
 def do_Do(self, xobjid):
     xobjid = literal_name(xobjid)
     try:
         xobj = stream_value(self.xobjmap[xobjid])
     except KeyError:
         if STRICT:
             raise PDFInterpreterError('Undefined xobject id: %r' % xobjid)
         return
     if 1 <= self.debug:
         print >>stderr, 'Processing xobj: %r' % xobj
     subtype = xobj.get('Subtype')
     if subtype is LITERAL_FORM and 'BBox' in xobj:
         interpreter = self.dup()
         bbox = list_value(xobj['BBox'])
         matrix = list_value(xobj.get('Matrix', MATRIX_IDENTITY))
         self.device.begin_figure(xobjid, bbox, matrix)
         interpreter.render_contents(dict_value(xobj.get('Resources')), [xobj], ctm=mult_matrix(matrix, self.ctm))
         self.device.end_figure(xobjid)
     elif subtype is LITERAL_IMAGE and 'Width' in xobj and 'Height' in xobj:
         self.device.begin_figure(xobjid, (0,0,1,1), MATRIX_IDENTITY)
         self.device.render_image(xobjid, xobj)
         self.device.end_figure(xobjid)
     else:
         # unsupported xobject type.
         pass
     return
예제 #13
0
 def do_cm(self, a1, b1, c1, d1, e1, f1):
     self.ctm = mult_matrix((a1,b1,c1,d1,e1,f1), self.ctm)
     self.device.set_ctm(self.ctm)
     return
예제 #14
0
파일: pdfinterp.py 프로젝트: mcs07/pdfminer
 def do_cm(self, a1, b1, c1, d1, e1, f1):
     """concat-matrix"""
     self.ctm = mult_matrix((a1,b1,c1,d1,e1,f1), self.ctm)
     self.device.set_ctm(self.ctm)