Пример #1
0
    def processPS(self, file, writer, context, registry, bbox):
        if writer.mesh_as_bitmap:
            from pyx import bitmap, canvas
            from PIL import Image
            c = canvas.canvas()
            c.insert(self)
            i = Image.open(c.pipeGS("pngalpha", resolution=writer.mesh_as_bitmap_resolution))
            i.load()
            b = bitmap.bitmap_pt(self.bbox().llx_pt, self.bbox().lly_pt, i)
            # we slightly shift the bitmap to re-center it, as the bitmap might contain some additional border
            # unfortunately we need to construct another bitmap instance for that ...
            b = bitmap.bitmap_pt(self.bbox().llx_pt + 0.5*(self.bbox().width_pt()-b.bbox().width_pt()),
                                 self.bbox().lly_pt + 0.5*(self.bbox().height_pt()-b.bbox().height_pt()), i)
            b.processPS(file, writer, context, registry, bbox)
        else:
            thisbbox = self.bbox()
            bbox += thisbbox
            file.write("""<< /ShadingType 4
/ColorSpace %s
/BitsPerCoordinate 24
/BitsPerComponent 8
/BitsPerFlag 8
/Decode [%f %f %f %f %s]
/DataSource currentfile /ASCIIHexDecode filter /FlateDecode filter
>> shfill\n""" % (self.elements[0].nodes[0].value.colorspacestring(),
                  thisbbox.llx_pt, thisbbox.urx_pt, thisbbox.lly_pt, thisbbox.ury_pt,
                  " ".join(["0 1" for value in self.elements[0].nodes[0].value.to8bitbytes()])))
            file.write_bytes(binascii.b2a_hex(zlib.compress(self.data(thisbbox))))
            file.write(">\n")
Пример #2
0
    def processPDF(self, file, writer, context, registry, bbox):
        if writer.mesh_as_bitmap:
            from pyx import bitmap, canvas
            import Image
            c = canvas.canvas()
            c.insert(self)
            fd, fname = tempfile.mkstemp()
            f = os.fdopen(fd, "wb")
            f.close()
            c.pipeGS(fname,
                     device="pngalpha",
                     resolution=writer.mesh_as_bitmap_resolution)
            i = Image.open(fname)
            os.unlink(fname)
            b = bitmap.bitmap_pt(self.bbox().llx_pt, self.bbox().lly_pt, i)
            # we slightly shift the bitmap to re-center it, as the bitmap might contain some additional border
            # unfortunately we need to construct another bitmap instance for that ...
            b = bitmap.bitmap_pt(
                self.bbox().llx_pt + 0.5 *
                (self.bbox().width_pt() - b.bbox().width_pt()),
                self.bbox().lly_pt + 0.5 *
                (self.bbox().height_pt() - b.bbox().height_pt()), i)
            b.processPDF(file, writer, context, registry, bbox)
        else:
            thisbbox = self.bbox()
            bbox += thisbbox
            d = self.data(thisbbox)
            if writer.compress:
                filter = "/Filter /FlateDecode\n"
                d = zlib.compress(d)
            else:
                filter = ""
            name = "shading-%s" % id(self)
            shading = PDFGenericResource(
                "shading", name, """<<
/ShadingType 4
/ColorSpace %s
/BitsPerCoordinate 24
/BitsPerComponent 8
/BitsPerFlag 8
/Decode [%f %f %f %f %s]
/Length %i
%s>>
stream
%s
endstream\n""" % (self.elements[0].nodes[0].value.colorspacestring(),
                  thisbbox.llx_pt, thisbbox.urx_pt, thisbbox.lly_pt,
                  thisbbox.ury_pt, " ".join([
                      "0 1" for value in
                      self.elements[0].nodes[0].value.to8bitstring()
                  ]), len(d), filter, d))
            registry.add(shading)
            registry.addresource("Shading", name, shading)
            file.write("/%s sh\n" % name)
Пример #3
0
 def processSVG(self, xml, writer, context, registry, bbox):
     from pyx import bitmap, canvas
     from PIL import Image
     c = canvas.canvas()
     c.insert(self)
     i = Image.open(c.pipeGS("pngalpha", resolution=writer.mesh_as_bitmap_resolution))
     i.load()
     b = bitmap.bitmap_pt(self.bbox().llx_pt, self.bbox().lly_pt, i)
     # we slightly shift the bitmap to re-center it, as the bitmap might contain some additional border
     # unfortunately we need to construct another bitmap instance for that ...
     b = bitmap.bitmap_pt(self.bbox().llx_pt + 0.5*(self.bbox().width_pt()-b.bbox().width_pt()),
                          self.bbox().lly_pt + 0.5*(self.bbox().height_pt()-b.bbox().height_pt()), i)
     b.processSVG(xml, writer, context, registry, bbox)
Пример #4
0
 def processPDF(self, file, writer, context, registry, bbox):
     warnings.warn("EPS file is included as a bitmap created using pipeGS")
     from pyx import bitmap, canvas
     import Image
     c = canvas.canvas()
     c.insert(self)
     i = Image.open(c.pipeGS(device="pngalpha", resolution=600, seekable=True))
     i.load()
     b = bitmap.bitmap_pt(self.bbox().llx_pt, self.bbox().lly_pt, i)
     # we slightly shift the bitmap to re-center it, as the bitmap might contain some additional border
     # unfortunately we need to construct another bitmap instance for that ...
     b = bitmap.bitmap_pt(self.bbox().llx_pt + 0.5*(self.bbox().width_pt()-b.bbox().width_pt()),
                          self.bbox().lly_pt + 0.5*(self.bbox().height_pt()-b.bbox().height_pt()), i)
     b.processPDF(file, writer, context, registry, bbox)
Пример #5
0
 def processSVG(self, xml, writer, context, registry, bbox):
     from pyx import bitmap, canvas
     from PIL import Image
     c = canvas.canvas()
     c.insert(self)
     i = Image.open(
         c.pipeGS("pngalpha", resolution=writer.meshasbitmapresolution))
     i.load()
     b = bitmap.bitmap_pt(self.bbox().llx_pt, self.bbox().lly_pt, i)
     # we slightly shift the bitmap to re-center it, as the bitmap might contain some additional border
     # unfortunately we need to construct another bitmap instance for that ...
     b = bitmap.bitmap_pt(
         self.bbox().llx_pt + 0.5 *
         (self.bbox().width_pt() - b.bbox().width_pt()),
         self.bbox().lly_pt + 0.5 *
         (self.bbox().height_pt() - b.bbox().height_pt()), i)
     b.processSVG(xml, writer, context, registry, bbox)
Пример #6
0
    def processPDF(self, file, writer, context, registry, bbox):
        if writer.mesh_as_bitmap:
            from pyx import bitmap, canvas
            import Image
            c = canvas.canvas()
            c.insert(self)
            fd, fname = tempfile.mkstemp()
            f = os.fdopen(fd, "wb")
            f.close()
            c.pipeGS(fname, device="pngalpha", resolution=writer.mesh_as_bitmap_resolution)
            i = Image.open(fname)
            os.unlink(fname)
            b = bitmap.bitmap_pt(self.bbox().llx_pt, self.bbox().lly_pt, i)
            # we slightly shift the bitmap to re-center it, as the bitmap might contain some additional border
            # unfortunately we need to construct another bitmap instance for that ...
            b = bitmap.bitmap_pt(self.bbox().llx_pt + 0.5*(self.bbox().width_pt()-b.bbox().width_pt()),
                                 self.bbox().lly_pt + 0.5*(self.bbox().height_pt()-b.bbox().height_pt()), i)
            b.processPDF(file, writer, context, registry, bbox)
        else:
            thisbbox = self.bbox()
            bbox += thisbbox
            d = self.data(thisbbox)
            if writer.compress:
                filter = "/Filter /FlateDecode\n"
                d = zlib.compress(d)
            else:
                filter = ""
            name = "shading-%s" % id(self)
            shading = PDFGenericResource("shading", name, """<<
/ShadingType 4
/ColorSpace %s
/BitsPerCoordinate 24
/BitsPerComponent 8
/BitsPerFlag 8
/Decode [%f %f %f %f %s]
/Length %i
%s>>
stream
%s
endstream\n""" % (self.elements[0].nodes[0].value.colorspacestring(),
                  thisbbox.llx_pt, thisbbox.urx_pt, thisbbox.lly_pt, thisbbox.ury_pt,
                  " ".join(["0 1" for value in self.elements[0].nodes[0].value.to8bitstring()]),
                  len(d), filter, d))
            registry.add(shading)
            registry.addresource("Shading", name, shading)
            file.write("/%s sh\n" % name)
Пример #7
0
    def processPS(self, file, writer, context, registry, bbox):
        if writer.mesh_as_bitmap:
            from pyx import bitmap, canvas
            import Image
            c = canvas.canvas()
            c.insert(self)
            fd, fname = tempfile.mkstemp()
            f = os.fdopen(fd, "wb")
            f.close()
            c.pipeGS(fname,
                     device="pngalpha",
                     resolution=writer.mesh_as_bitmap_resolution)
            i = Image.open(fname)
            os.unlink(fname)
            b = bitmap.bitmap_pt(self.bbox().llx_pt, self.bbox().lly_pt, i)
            # we slightly shift the bitmap to re-center it, as the bitmap might contain some additional border
            # unfortunately we need to construct another bitmap instance for that ...
            b = bitmap.bitmap_pt(
                self.bbox().llx_pt + 0.5 *
                (self.bbox().width_pt() - b.bbox().width_pt()),
                self.bbox().lly_pt + 0.5 *
                (self.bbox().height_pt() - b.bbox().height_pt()), i)
            b.processPS(file, writer, context, registry, bbox)
        else:
            thisbbox = self.bbox()
            bbox += thisbbox
            file.write("""<< /ShadingType 4
/ColorSpace %s
/BitsPerCoordinate 24
/BitsPerComponent 8
/BitsPerFlag 8
/Decode [%f %f %f %f %s]
/DataSource currentfile /ASCIIHexDecode filter /FlateDecode filter
>> shfill\n""" % (self.elements[0].nodes[0].value.colorspacestring(),
                  thisbbox.llx_pt, thisbbox.urx_pt, thisbbox.lly_pt,
                  thisbbox.ury_pt, " ".join([
                      "0 1" for value in
                      self.elements[0].nodes[0].value.to8bitstring()
                  ])))
            file.write(binascii.b2a_hex(zlib.compress(self.data(thisbbox))))
            file.write("\n")