示例#1
0
 def axisatv(self, axis, v):
     if axis.positioner.fixtickdirection[0]:
         # it is a y-axis
         self.axistrafo(axis, trafo.translate_pt(self.xpos_pt + v*self.width_pt - axis.positioner.x1_pt, 0))
     else:
         # it is an x-axis
         self.axistrafo(axis, trafo.translate_pt(0, self.ypos_pt + v*self.height_pt - axis.positioner.y1_pt))
示例#2
0
 def axisatv(self, axis, v):
     if axis.positioner.fixtickdirection[0]:
         # it is a y-axis
         t = trafo.translate_pt(self.xpos_pt + v*self.width_pt - axis.positioner.x1_pt, 0)
     else:
         # it is an x-axis
         t = trafo.translate_pt(0, self.ypos_pt + v*self.height_pt - axis.positioner.y1_pt)
     c = canvas.canvas()
     for layer, subcanvas in axis.canvas.layers.items():
         c.layer(layer).insert(subcanvas, [t])
     assert len(axis.canvas.layers) == len(axis.canvas.items), str(axis.canvas.items)
     axis.canvas = c
示例#3
0
 def axisatv(self, axis, v):
     if axis.positioner.fixtickdirection[0]:
         # it is a y-axis
         self.axistrafo(
             axis,
             trafo.translate_pt(
                 self.xpos_pt + v * self.width_pt - axis.positioner.x1_pt,
                 0))
     else:
         # it is an x-axis
         self.axistrafo(
             axis,
             trafo.translate_pt(
                 0,
                 self.ypos_pt + v * self.height_pt - axis.positioner.y1_pt))
示例#4
0
    def dokey(self):
        if self.did(self.dokey):
            return
        self.dobackground()
        for plotitem in self.plotitems:
            self.dokeyitem(plotitem)
        if self.key is not None:
            c = self.key.paint(self.keyitems)
            bbox = c.bbox()

            def parentchildalign(pmin, pmax, cmin, cmax, pos, dist, inside):
                ppos = pmin + 0.5 * (cmax - cmin) + dist + pos * (
                    pmax - pmin - cmax + cmin - 2 * dist)
                cpos = 0.5 * (cmin + cmax) + (1 - inside) * (1 - 2 * pos) * (
                    cmax - cmin + 2 * dist)
                return ppos - cpos

            if bbox:
                x = parentchildalign(self.xpos_pt, self.xpos_pt + self.size_pt,
                                     bbox.llx_pt, bbox.urx_pt, self.key.hpos,
                                     unit.topt(self.key.hdist),
                                     self.key.hinside)
                y = parentchildalign(self.ypos_pt, self.ypos_pt + self.size_pt,
                                     bbox.lly_pt, bbox.ury_pt, self.key.vpos,
                                     unit.topt(self.key.vdist),
                                     self.key.vinside)
                self.insert(c, [trafo.translate_pt(x, y)])
示例#5
0
文件: t1file.py 项目: mjg/PyX-svn
 def updatepath(self, path, atrafo, context):
     sab = context.t1stack.pop(0)
     adx = context.t1stack.pop(0)
     ady = context.t1stack.pop(0)
     bchar = context.t1stack.pop(0)
     achar = context.t1stack.pop(0)
     aglyph = adobestandardencoding[achar]
     bglyph = adobestandardencoding[bchar]
     context.t1font.updateglyphpath(bglyph, path, atrafo, context)
     atrafo = atrafo * trafo.translate_pt(adx-sab, ady)
     context.t1font.updateglyphpath(aglyph, path, atrafo, context)
示例#6
0
 def updatepath(self, path, atrafo, context):
     sab = context.t1stack.pop(0)
     adx = context.t1stack.pop(0)
     ady = context.t1stack.pop(0)
     bchar = context.t1stack.pop(0)
     achar = context.t1stack.pop(0)
     aglyph = adobestandardencoding[achar]
     bglyph = adobestandardencoding[bchar]
     context.t1font.updateglyphpath(bglyph, path, atrafo, context)
     atrafo = atrafo * trafo.translate_pt(adx - sab, ady)
     context.t1font.updateglyphpath(aglyph, path, atrafo, context)
示例#7
0
文件: key.py 项目: atal2003/test
 def paint(self, plotitems):
     "creates the layout of the key"
     columndist_pt = unit.topt(self.columndist)
     c = canvas.canvas()
     itemspercolumn = (len(plotitems) + self.columns - 1) // self.columns
     x_pt = 0
     while plotitems:
         subc = self.paintcolumn(plotitems[:itemspercolumn])
         c.insert(subc, [trafo.translate_pt(x_pt, 0)])
         x_pt += unit.topt(subc.bbox().width()) + columndist_pt
         del plotitems[:itemspercolumn]
     if self.keyattrs is not None:
         newc = canvas.canvas()
         newc.draw(c.bbox().enlarged(self.border).path(), self.keyattrs)
         newc.insert(c)
         c = newc
     return c
示例#8
0
文件: key.py 项目: mjg/PyX-svn
 def paint(self, plotitems):
     "creates the layout of the key"
     columndist_pt = unit.topt(self.columndist)
     c = canvas.canvas()
     itemspercolumn = (len(plotitems) + self.columns - 1) // self.columns
     x_pt = 0
     while plotitems:
         subc = self.paintcolumn(plotitems[:itemspercolumn])
         c.insert(subc, [trafo.translate_pt(x_pt, 0)])
         x_pt += unit.topt(subc.bbox().width()) + columndist_pt
         del plotitems[:itemspercolumn]
     if self.keyattrs is not None:
         newc = canvas.canvas()
         newc.draw(c.bbox().enlarged(self.border).path(), self.keyattrs)
         newc.insert(c)
         c = newc
     return c
示例#9
0
 def dokey(self):
     if self.did(self.dokey):
         return
     self.dobackground()
     self.dostyles()
     if self.key is not None:
         c = self.key.paint(self.plotitems)
         bbox = c.bbox()
         def parentchildalign(pmin, pmax, cmin, cmax, pos, dist, inside):
             ppos = pmin+0.5*(cmax-cmin)+dist+pos*(pmax-pmin-cmax+cmin-2*dist)
             cpos = 0.5*(cmin+cmax)+(1-inside)*(1-2*pos)*(cmax-cmin+2*dist)
             return ppos-cpos
         if bbox:
             x = parentchildalign(self.xpos_pt, self.xpos_pt+self.size_pt,
                                  bbox.llx_pt, bbox.urx_pt,
                                  self.key.hpos, unit.topt(self.key.hdist), self.key.hinside)
             y = parentchildalign(self.ypos_pt, self.ypos_pt+self.size_pt,
                                  bbox.lly_pt, bbox.ury_pt,
                                  self.key.vpos, unit.topt(self.key.vdist), self.key.vinside)
             self.insert(c, [trafo.translate_pt(x, y)])
示例#10
0
 def autokeygraphtrafo(self, keygraph):
     dependsonaxisnumber = None
     if self.flipped:
         dependsonaxisname = "x"
     else:
         dependsonaxisname = "y"
     for axisname in self.axes:
         if axisname[0] == dependsonaxisname:
             if len(axisname) == 1:
                 axisname += "1"
             axisnumber = int(axisname[1:])
             if not (axisnumber % 2) and not self.flipped or (axisnumber % 2) and self.flipped:
                 if dependsonaxisnumber is None or dependsonaxisnumber < axisnumber:
                     dependsonaxisnumber = axisnumber
     if dependsonaxisnumber is None:
         x_pt = self.xpos_pt + self.width_pt
     else:
         if dependsonaxisnumber > 1:
             dependsonaxisname += str(dependsonaxisnumber)
         self.doaxiscreate(dependsonaxisname)
         x_pt = self.axes[dependsonaxisname].positioner.x1_pt + self.axes[dependsonaxisname].canvas.extent_pt
     x_pt += self.axesdist_pt
     return trafo.translate_pt(x_pt, self.ypos_pt)
示例#11
0
 def autokeygraphtrafo(self, keygraph):
     self.doaxes()
     x_pt = self.layer("axes").bbox().right_pt() + self.axesdist_pt
     y_pt = 0.5*(self.layer("axes").bbox().top_pt() + self.layer("axes").bbox().bottom_pt() - self.size_pt)
     return trafo.translate_pt(x_pt, y_pt)
示例#12
0
    def processPDF(self, file, writer, context, registry, bbox):
        if not self.ignorebbox:
            bbox += self.bbox()

        if writer.text_as_path:
            if self.decode:
                if self.kerning:
                    data = self.font.metric.resolvekernings(self.glyphnames, self.size_pt)
                else:
                    data = self.glyphnames
            else:
                data = self.charcodes
            textpath = path.path()
            x_pt = self.x_pt
            y_pt = self.y_pt
            for i, value in enumerate(data):
                if self.kerning and i % 2:
                    if value is not None:
                        x_pt += value
                else:
                    if i:
                        x_pt += self.spaced_pt
                    glyphpath, wx_pt, wy_pt = self.font.t1file.getglyphpathwxwy_pt(value, self.size_pt, convertcharcode=not self.decode)
                    textpath += glyphpath.transformed(trafo.translate_pt(x_pt, y_pt))
                    x_pt += wx_pt
                    y_pt += wy_pt
            deco.decoratedpath(textpath, fillstyles=[]).processPDF(file, writer, context, registry, bbox)
        else:
            if self.decode:
                encodingname = self.getencodingname(writer.encodings.setdefault(self.font.name, {}))
                encoding = writer.encodings[self.font.name][encodingname]
                charcodes = [encoding[glyphname] for glyphname in self.glyphnames]
            else:
                charcodes = self.charcodes

            # create resources
            fontname = self.font.name
            if self.decode:
                newfontname = "%s-%s" % (fontname, encodingname)
                _encoding = PDFencoding(encoding, newfontname)
                fontname = newfontname
            else:
                _encoding = None
            if self.font.t1file is not None:
                if self.decode:
                    fontfile = PDFfontfile(self.font.t1file, self.glyphnames, [])
                else:
                    fontfile = PDFfontfile(self.font.t1file, [], self.charcodes)
            else:
                fontfile = None
            fontdescriptor = PDFfontdescriptor(self.font.name, fontfile, self.font.metric)
            font = PDFfont(fontname, self.font.name, charcodes, fontdescriptor, _encoding, self.font.metric)

            # register resources
            if fontfile is not None:
                registry.add(fontfile)
            registry.add(fontdescriptor)
            if _encoding is not None:
                registry.add(_encoding)
            registry.add(font)

            registry.addresource("Font", fontname, font, procset="Text")

            if self.slant is None:
                slantvalue = 0
            else:
                slantvalue = self.slant

            # select font if necessary
            sf = selectedfont(fontname, self.size_pt)
            if context.selectedfont is None or sf != context.selectedfont:
                context.selectedfont = sf
                sf.outputPDF(file, writer)

            if self.kerning:
                file.write("1 0 %f 1 %f %f Tm [(" % (slantvalue, self.x_pt, self.y_pt))
            else:
                file.write("1 0 %f 1 %f %f Tm (" % (slantvalue, self.x_pt, self.y_pt))
            if self.decode:
                if self.kerning:
                    data = self.font.metric.resolvekernings(self.glyphnames)
                else:
                    data = self.glyphnames
            else:
                data = self.charcodes
            for i, value in enumerate(data):
                if self.kerning and i % 2:
                    if value is not None:
                        file.write(")%f(" % (-value-self.spaced_pt))
                    elif self.spaced_pt:
                        file.write(")%f(" % (-self.spaced_pt))
                else:
                    if i and not self.kerning and self.spaced_pt:
                        file.write(")%f(" % (-self.spaced_pt))
                    if self.decode:
                        value = encoding[value]
                    if 32 <= value <= 127 and chr(value) not in "()[]<>\\":
                        file.write("%s" % chr(value))
                    else:
                        file.write("\\%03o" % value)
            if self.kerning:
                file.write(")] TJ\n")
            else:
                file.write(") Tj\n")
示例#13
0
    def processPS(self, file, writer, context, registry, bbox):
        if not self.ignorebbox:
            bbox += self.bbox()

        if writer.text_as_path:
            if self.decode:
                if self.kerning:
                    data = self.font.metric.resolvekernings(self.glyphnames, self.size_pt)
                else:
                    data = self.glyphnames
            else:
                data = self.charcodes
            textpath = path.path()
            x_pt = self.x_pt
            y_pt = self.y_pt
            for i, value in enumerate(data):
                if self.kerning and i % 2:
                    if value is not None:
                        x_pt += value
                else:
                    if i:
                        x_pt += self.spaced_pt
                    glyphpath, wx_pt, wy_pt = self.font.t1file.getglyphpathwxwy_pt(value, self.size_pt, convertcharcode=not self.decode)
                    textpath += glyphpath.transformed(trafo.translate_pt(x_pt, y_pt))
                    x_pt += wx_pt
                    y_pt += wy_pt
            deco.decoratedpath(textpath, fillstyles=[]).processPS(file, writer, context, registry, bbox)
        else:
            # register resources
            if self.font.t1file is not None:
                if self.decode:
                    registry.add(PST1file(self.font.t1file, self.glyphnames, []))
                else:
                    registry.add(PST1file(self.font.t1file, [], self.charcodes))

            fontname = self.font.name
            if self.decode:
                encodingname = self.getencodingname(writer.encodings.setdefault(self.font.name, {}))
                encoding = writer.encodings[self.font.name][encodingname]
                newfontname = "%s-%s" % (fontname, encodingname)
                registry.add(_ReEncodeFont)
                registry.add(PSreencodefont(fontname, newfontname, encoding))
                fontname = newfontname

            if self.slant:
                newfontmatrix = trafo.trafo_pt(matrix=((1, self.slant), (0, 1))) * self.font.t1file.fontmatrix
                newfontname = "%s-slant%f" % (fontname, self.slant)
                registry.add(_ChangeFontMatrix)
                registry.add(PSchangefontmatrix(fontname, newfontname, newfontmatrix))
                fontname = newfontname

            # select font if necessary
            sf = selectedfont(fontname, self.size_pt)
            if context.selectedfont is None or sf != context.selectedfont:
                context.selectedfont = sf
                sf.outputPS(file, writer)

            file.write("%f %f moveto (" % (self.x_pt, self.y_pt))
            if self.decode:
                if self.kerning:
                    data = self.font.metric.resolvekernings(self.glyphnames, self.size_pt)
                else:
                    data = self.glyphnames
            else:
                data = self.charcodes
            for i, value in enumerate(data):
                if self.kerning and i % 2:
                    if value is not None:
                        file.write(") show\n%f 0 rmoveto (" % (value+self.spaced_pt))
                    elif self.spaced_pt:
                        file.write(") show\n%f 0 rmoveto (" % self.spaced_pt)
                else:
                    if i and not self.kerning and self.spaced_pt:
                        file.write(") show\n%f 0 rmoveto (" % self.spaced_pt)
                    if self.decode:
                        value = encoding[value]
                    if 32 < value < 127 and chr(value) not in "()[]<>\\":
                        file.write("%s" % chr(value))
                    else:
                        file.write("\\%03o" % value)
            file.write(") show\n")
示例#14
0
    def processPDF(self, file, writer, context, registry, bbox):
        if not self.ignorebbox:
            bbox += self.bbox()

        if writer.text_as_path:
            if self.decode:
                if self.kerning:
                    data = self.font.metric.resolvekernings(
                        self.glyphnames, self.size_pt)
                else:
                    data = self.glyphnames
            else:
                data = self.charcodes
            textpath = path.path()
            x_pt = self.x_pt
            y_pt = self.y_pt
            for i, value in enumerate(data):
                if self.kerning and i % 2:
                    if value is not None:
                        x_pt += value
                else:
                    if i:
                        x_pt += self.spaced_pt
                    glyphpath, wx_pt, wy_pt = self.font.t1file.getglyphpathwxwy_pt(
                        value, self.size_pt, convertcharcode=not self.decode)
                    textpath += glyphpath.transformed(
                        trafo.translate_pt(x_pt, y_pt))
                    x_pt += wx_pt
                    y_pt += wy_pt
            deco.decoratedpath(textpath, fillstyles=[]).processPDF(
                file, writer, context, registry, bbox)
        else:
            if self.decode:
                encodingname = self.getencodingname(
                    writer.encodings.setdefault(self.font.name, {}))
                encoding = writer.encodings[self.font.name][encodingname]
                charcodes = [
                    encoding[glyphname] for glyphname in self.glyphnames
                ]
            else:
                charcodes = self.charcodes

            # create resources
            fontname = self.font.name
            if self.decode:
                newfontname = "%s-%s" % (fontname, encodingname)
                _encoding = PDFencoding(encoding, newfontname)
                fontname = newfontname
            else:
                _encoding = None
            if self.font.t1file is not None:
                if self.decode:
                    fontfile = PDFfontfile(self.font.t1file, self.glyphnames,
                                           [])
                else:
                    fontfile = PDFfontfile(self.font.t1file, [],
                                           self.charcodes)
            else:
                fontfile = None
            fontdescriptor = PDFfontdescriptor(self.font.name, fontfile,
                                               self.font.metric)
            font = PDFfont(fontname, self.font.name, charcodes, fontdescriptor,
                           _encoding, self.font.metric)

            # register resources
            if fontfile is not None:
                registry.add(fontfile)
            registry.add(fontdescriptor)
            if _encoding is not None:
                registry.add(_encoding)
            registry.add(font)

            registry.addresource("Font", fontname, font, procset="Text")

            if self.slant is None:
                slantvalue = 0
            else:
                slantvalue = self.slant

            # select font if necessary
            sf = selectedfont(fontname, self.size_pt)
            if context.selectedfont is None or sf != context.selectedfont:
                context.selectedfont = sf
                sf.outputPDF(file, writer)

            if self.kerning:
                file.write("1 0 %f 1 %f %f Tm [(" %
                           (slantvalue, self.x_pt, self.y_pt))
            else:
                file.write("1 0 %f 1 %f %f Tm (" %
                           (slantvalue, self.x_pt, self.y_pt))
            if self.decode:
                if self.kerning:
                    data = self.font.metric.resolvekernings(self.glyphnames)
                else:
                    data = self.glyphnames
            else:
                data = self.charcodes
            for i, value in enumerate(data):
                if self.kerning and i % 2:
                    if value is not None:
                        file.write(")%f(" % (-value - self.spaced_pt))
                    elif self.spaced_pt:
                        file.write(")%f(" % (-self.spaced_pt))
                else:
                    if i and not self.kerning and self.spaced_pt:
                        file.write(")%f(" % (-self.spaced_pt))
                    if self.decode:
                        value = encoding[value]
                    if 32 <= value <= 127 and chr(value) not in "()[]<>\\":
                        file.write("%s" % chr(value))
                    else:
                        file.write("\\%03o" % value)
            if self.kerning:
                file.write(")] TJ\n")
            else:
                file.write(") Tj\n")
示例#15
0
    def processPS(self, file, writer, context, registry, bbox):
        if not self.ignorebbox:
            bbox += self.bbox()

        if writer.text_as_path:
            if self.decode:
                if self.kerning:
                    data = self.font.metric.resolvekernings(
                        self.glyphnames, self.size_pt)
                else:
                    data = self.glyphnames
            else:
                data = self.charcodes
            textpath = path.path()
            x_pt = self.x_pt
            y_pt = self.y_pt
            for i, value in enumerate(data):
                if self.kerning and i % 2:
                    if value is not None:
                        x_pt += value
                else:
                    if i:
                        x_pt += self.spaced_pt
                    glyphpath, wx_pt, wy_pt = self.font.t1file.getglyphpathwxwy_pt(
                        value, self.size_pt, convertcharcode=not self.decode)
                    textpath += glyphpath.transformed(
                        trafo.translate_pt(x_pt, y_pt))
                    x_pt += wx_pt
                    y_pt += wy_pt
            deco.decoratedpath(textpath, fillstyles=[]).processPS(
                file, writer, context, registry, bbox)
        else:
            # register resources
            if self.font.t1file is not None:
                if self.decode:
                    registry.add(
                        PST1file(self.font.t1file, self.glyphnames, []))
                else:
                    registry.add(PST1file(self.font.t1file, [],
                                          self.charcodes))

            fontname = self.font.name
            if self.decode:
                encodingname = self.getencodingname(
                    writer.encodings.setdefault(self.font.name, {}))
                encoding = writer.encodings[self.font.name][encodingname]
                newfontname = "%s-%s" % (fontname, encodingname)
                registry.add(_ReEncodeFont)
                registry.add(PSreencodefont(fontname, newfontname, encoding))
                fontname = newfontname

            if self.slant:
                newfontmatrix = trafo.trafo_pt(matrix=(
                    (1, self.slant), (0, 1))) * self.font.t1file.fontmatrix
                newfontname = "%s-slant%f" % (fontname, self.slant)
                registry.add(_ChangeFontMatrix)
                registry.add(
                    PSchangefontmatrix(fontname, newfontname, newfontmatrix))
                fontname = newfontname

            # select font if necessary
            sf = selectedfont(fontname, self.size_pt)
            if context.selectedfont is None or sf != context.selectedfont:
                context.selectedfont = sf
                sf.outputPS(file, writer)

            file.write("%f %f moveto (" % (self.x_pt, self.y_pt))
            if self.decode:
                if self.kerning:
                    data = self.font.metric.resolvekernings(
                        self.glyphnames, self.size_pt)
                else:
                    data = self.glyphnames
            else:
                data = self.charcodes
            for i, value in enumerate(data):
                if self.kerning and i % 2:
                    if value is not None:
                        file.write(") show\n%f 0 rmoveto (" %
                                   (value + self.spaced_pt))
                    elif self.spaced_pt:
                        file.write(") show\n%f 0 rmoveto (" % self.spaced_pt)
                else:
                    if i and not self.kerning and self.spaced_pt:
                        file.write(") show\n%f 0 rmoveto (" % self.spaced_pt)
                    if self.decode:
                        value = encoding[value]
                    if 32 < value < 127 and chr(value) not in "()[]<>\\":
                        file.write("%s" % chr(value))
                    else:
                        file.write("\\%03o" % value)
            file.write(") show\n")