Ejemplo n.º 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 >> stderr, "Processing xobj: %r" % xobj
     subtype = xobj.dic.get("Subtype")
     try:
         if subtype == LITERAL_FORM and "BBox" in xobj.dic:
             interpreter = PDFPageInterpreter(self.rsrc, self.device)
             (x0, y0, x1, y1) = xobj.dic["BBox"]
             ctm = mult_matrix(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(xobj.dic.get("Resources"), [xobj], ctm=ctm)
             self.device.end_figure(xobjid)
         elif subtype == 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)
     except TypeError:
         pass
     else:
         # unsupported xobject type.
         pass
     return
Ejemplo n.º 2
0
 def fillfp(self):
     if not self.fp:
         if self.istream < len(self.streams):
             strm = stream_value(self.streams[self.istream])
             self.istream += 1
         else:
             raise PSEOF
         self.fp = StringIO(strm.get_data())
     return
Ejemplo n.º 3
0
 def get_colorspace(spec):
     if isinstance(spec, list):
         name = literal_name(spec[0])
     else:
         name = literal_name(spec)
     if name == "ICCBased" and isinstance(spec, list) and 2 <= len(spec):
         return ColorSpace(name, stream_value(spec[1]).dic["N"])
     elif name == "DeviceN" and isinstance(spec, list) and 2 <= len(spec):
         return ColorSpace(name, len(list_value(spec[1])))
     else:
         return PREDEFINED_COLORSPACE[name]
Ejemplo n.º 4
0
 def __init__(self, descriptor, widths, spec):
     # Font encoding is specified either by a name of
     # built-in encoding or a dictionary that describes
     # the differences.
     if "Encoding" in spec:
         encoding = resolve1(spec["Encoding"])
     else:
         encoding = LITERAL_STANDARD_ENCODING
     if isinstance(encoding, dict):
         name = literal_name(encoding.get("BaseEncoding", LITERAL_STANDARD_ENCODING))
         diff = list_value(encoding.get("Differences", None))
         self.encoding = EncodingDB.get_encoding(name, diff)
     else:
         self.encoding = EncodingDB.get_encoding(literal_name(encoding))
     self.ucs2_cmap = None
     if "ToUnicode" in spec:
         strm = stream_value(spec["ToUnicode"])
         self.ucs2_cmap = CMap()
         CMapParser(self.ucs2_cmap, StringIO(strm.get_data())).run()
     PDFFont.__init__(self, descriptor, widths)
     return