예제 #1
0
파일: deco.py 프로젝트: dcf21/pyxplot7
def _arrowhead(anormpath, arclenfrombegin, direction, size, angle, constrictionlen):

    """helper routine, which returns an arrowhead from a given anormpath

    - arclenfrombegin: position of arrow in arc length from the start of the path
    - direction: +1 for an arrow pointing along the direction of anormpath or
                 -1 for an arrow pointing opposite to the direction of normpath
    - size: size of the arrow as arc length
    - angle. opening angle
    - constrictionlen: None (no constriction) or arc length of constriction.
    """

    # arc length and coordinates of tip
    tx, ty = anormpath.at(arclenfrombegin)

    # construct the template for the arrow by cutting the path at the
    # corresponding length
    arrowtemplate = anormpath.split([arclenfrombegin, arclenfrombegin - direction * size])[1]

    # from this template, we construct the two outer curves of the arrow
    arrowl = arrowtemplate.transformed(trafo.rotate(-angle/2.0, tx, ty))
    arrowr = arrowtemplate.transformed(trafo.rotate( angle/2.0, tx, ty))

    # now come the joining backward parts
    if constrictionlen is not None:
        # constriction point (cx, cy) lies on path
        cx, cy = anormpath.at(arclenfrombegin - direction * constrictionlen)
        arrowcr= path.line(*(arrowr.atend() + (cx,cy)))
        arrow = arrowl.reversed() << arrowr << arrowcr
    else:
        arrow = arrowl.reversed() << arrowr

    arrow[-1].close()

    return arrow
예제 #2
0
    def _process(self, processMethod, contentfile, writer, context, registry, bbox):
        # usually, it is the bbox of the canvas enlarged by self.bboxenlarge, but
        # it might be a different bbox as specified in the page constructor
        assert not bbox
        if self.pagebbox:
            bbox.set(self.pagebbox)
        else:
            bbox.set(self.canvas.bbox()) # this bbox is not accurate
            bbox.enlarge(self.bboxenlarge)

        # check whether we expect a page trafo and use a temporary canvas to insert the
        # page canvas
        if self.paperformat and (self.rotated or self.centered or self.fittosize) and bbox:
            # calculate the pagetrafo
            paperwidth, paperheight = self.paperformat.width, self.paperformat.height

            # center (optionally rotated) output on page
            if self.rotated:
                pagetrafo = trafo.rotate(90).translated(paperwidth, 0)
                if self.centered or self.fittosize:
                    if not self.fittosize and (bbox.height() > paperwidth or bbox.width() > paperheight):
                        warnings.warn("content exceeds the papersize")
                    pagetrafo = pagetrafo.translated(-0.5*(paperwidth - bbox.height()) + bbox.bottom(),
                                                      0.5*(paperheight - bbox.width()) - bbox.left())
            else:
                if not self.fittosize and (bbox.width() > paperwidth or bbox.height() > paperheight):
                    warnings.warn("content exceeds the papersize")
                pagetrafo = trafo.translate(0.5*(paperwidth - bbox.width())  - bbox.left(),
                                            0.5*(paperheight - bbox.height()) - bbox.bottom())

            if self.fittosize:

                if 2*self.margin > paperwidth or 2*self.margin > paperheight:
                    raise ValueError("Margins too broad for selected paperformat. Aborting.")

                paperwidth -= 2 * self.margin
                paperheight -= 2 * self.margin

                # scale output to pagesize - margins
                if self.rotated:
                    sfactor = min(unit.topt(paperheight)/bbox.width_pt(), unit.topt(paperwidth)/bbox.height_pt())
                else:
                    sfactor = min(unit.topt(paperwidth)/bbox.width_pt(), unit.topt(paperheight)/bbox.height_pt())

                pagetrafo = pagetrafo.scaled(sfactor, sfactor, self.margin + 0.5*paperwidth, self.margin + 0.5*paperheight)

            bbox.transform(pagetrafo)
            cc = canvasmodule.canvas()
            cc.insert(self.canvas, [pagetrafo])
        else:
            cc = self.canvas

        getattr(style.linewidth.normal, processMethod)(contentfile, writer, context, registry, bbox)
        if self.pagebbox:
            bbox = bbox.copy() # don't alter the bbox provided to the constructor -> use a copy
        getattr(cc, processMethod)(contentfile, writer, context, registry, bbox)
예제 #3
0
    def _process(self, processMethod, contentfile, writer, context, registry, bbox):
        # usually, it is the bbox of the canvas enlarged by self.bboxenlarge, but
        # it might be a different bbox as specified in the page constructor
        assert not bbox
        if self.pagebbox:
            bbox.set(self.pagebbox)
        else:
            bbox.set(self.canvas.bbox()) # this bbox is not accurate
            bbox.enlarge(self.bboxenlarge)

        # check whether we expect a page trafo and use a temporary canvas to insert the
        # page canvas
        if self.paperformat and (self.rotated or self.centered or self.fittosize) and bbox:
            # calculate the pagetrafo
            paperwidth, paperheight = self.paperformat.width, self.paperformat.height

            # center (optionally rotated) output on page
            if self.rotated:
                pagetrafo = trafo.rotate(90).translated(paperwidth, 0)
                if self.centered or self.fittosize:
                    if not self.fittosize and (bbox.height() > paperwidth or bbox.width() > paperheight):
                        warnings.warn("content exceeds the papersize")
                    pagetrafo = pagetrafo.translated(-0.5*(paperwidth - bbox.height()) + bbox.bottom(),
                                                      0.5*(paperheight - bbox.width()) - bbox.left())
            else:
                if not self.fittosize and (bbox.width() > paperwidth or bbox.height() > paperheight):
                    warnings.warn("content exceeds the papersize")
                pagetrafo = trafo.translate(0.5*(paperwidth - bbox.width())  - bbox.left(),
                                            0.5*(paperheight - bbox.height()) - bbox.bottom())

            if self.fittosize:

                if 2*self.margin > paperwidth or 2*self.margin > paperheight:
                    raise ValueError("Margins too broad for selected paperformat. Aborting.")

                paperwidth -= 2 * self.margin
                paperheight -= 2 * self.margin

                # scale output to pagesize - margins
                if self.rotated:
                    sfactor = min(unit.topt(paperheight)/bbox.width_pt(), unit.topt(paperwidth)/bbox.height_pt())
                else:
                    sfactor = min(unit.topt(paperwidth)/bbox.width_pt(), unit.topt(paperheight)/bbox.height_pt())

                pagetrafo = pagetrafo.scaled(sfactor, sfactor, self.margin + 0.5*paperwidth, self.margin + 0.5*paperheight)

            bbox.transform(pagetrafo)
            cc = canvasmodule.canvas()
            cc.insert(self.canvas, [pagetrafo])
        else:
            cc = self.canvas

        getattr(style.linewidth.normal, processMethod)(contentfile, writer, context, registry, bbox)
        if self.pagebbox:
            bbox = bbox.copy() # don't alter the bbox provided to the constructor -> use a copy
        getattr(cc, processMethod)(contentfile, writer, context, registry, bbox)
예제 #4
0
 def __init__(self, dist, angle, strokestyles=[]):
     pattern.__init__(self,
                      painttype=1,
                      tilingtype=1,
                      xstep=dist,
                      ystep=100 * unit.t_pt,
                      bbox=None,
                      trafo=trafo.rotate(angle))
     self.strokestyles = attr.mergeattrs([style.linewidth.THIN] +
                                         strokestyles)
     attr.checkattrs(self.strokestyles, [style.strokestyle])
     self.dist = dist
     self.angle = angle
     self.stroke(path.line_pt(0, -50, 0, 50), self.strokestyles)
예제 #5
0
def _arrowhead(anormpath, arclenfrombegin, direction, size, angle,
               constrictionlen):
    """helper routine, which returns an arrowhead from a given anormpath

    - arclenfrombegin: position of arrow in arc length from the start of the path
    - direction: +1 for an arrow pointing along the direction of anormpath or
                 -1 for an arrow pointing opposite to the direction of normpath
    - size: size of the arrow as arc length
    - angle. opening angle
    - constrictionlen: None (no constriction) or arc length of constriction.
    """

    # arc length and coordinates of tip
    tx, ty = anormpath.at(arclenfrombegin)

    # construct the template for the arrow by cutting the path at the
    # corresponding length
    arrowtemplate = anormpath.split(
        [arclenfrombegin, arclenfrombegin - direction * size])[1]

    # from this template, we construct the two outer curves of the arrow
    arrowl = arrowtemplate.transformed(trafo.rotate(-angle / 2.0, tx, ty))
    arrowr = arrowtemplate.transformed(trafo.rotate(angle / 2.0, tx, ty))

    # now come the joining backward parts
    if constrictionlen is not None:
        # constriction point (cx, cy) lies on path
        cx, cy = anormpath.at(arclenfrombegin - direction * constrictionlen)
        arrowcr = path.line(*(arrowr.atend() + (cx, cy)))
        arrow = arrowl.reversed() << arrowr << arrowcr
    else:
        arrow = arrowl.reversed() << arrowr

    arrow[-1].close()

    return arrow
예제 #6
0
    def _process(self, processMethod, contentfile, writer, context, registry,
                 bbox):
        assert not bbox

        # check whether we expect a page trafo and use a temporary canvasfile to insert the
        # pagetrafo in front after the bbox was calculated
        expectpagetrafo = self.paperformat and (self.rotated or self.centered
                                                or self.fittosize)
        if expectpagetrafo:
            canvasfile = cStringIO.StringIO()
        else:
            canvasfile = contentfile

        getattr(style.linewidth.normal, processMethod)(canvasfile, writer,
                                                       context, registry, bbox)
        getattr(self.canvas, processMethod)(canvasfile, writer, context,
                                            registry, bbox)

        # usually its the bbox of the canvas enlarged by self.bboxenlarge, but
        # it might be a different bbox as specified in the page constructor
        if self.pagebbox:
            bbox.set(self.pagebbox)
        elif bbox:
            bbox.enlarge(self.bboxenlarge)

        if expectpagetrafo:

            if bbox:
                # calculate the pagetrafo
                paperwidth, paperheight = self.paperformat.width, self.paperformat.height

                # center (optionally rotated) output on page
                if self.rotated:
                    pagetrafo = trafo.rotate(90).translated(paperwidth, 0)
                    if self.centered or self.fittosize:
                        if not self.fittosize and (bbox.height() > paperwidth
                                                   or
                                                   bbox.width() > paperheight):
                            warnings.warn("content exceeds the papersize")
                        pagetrafo = pagetrafo.translated(
                            -0.5 * (paperwidth - bbox.height()) +
                            bbox.bottom(),
                            0.5 * (paperheight - bbox.width()) - bbox.left())
                else:
                    if not self.fittosize and (bbox.width() > paperwidth
                                               or bbox.height() > paperheight):
                        warnings.warn("content exceeds the papersize")
                    pagetrafo = trafo.translate(
                        0.5 * (paperwidth - bbox.width()) - bbox.left(),
                        0.5 * (paperheight - bbox.height()) - bbox.bottom())

                if self.fittosize:

                    if 2 * self.margin > paperwidth or 2 * self.margin > paperheight:
                        raise ValueError(
                            "Margins too broad for selected paperformat. Aborting."
                        )

                    paperwidth -= 2 * self.margin
                    paperheight -= 2 * self.margin

                    # scale output to pagesize - margins
                    if self.rotated:
                        sfactor = min(
                            unit.topt(paperheight) / bbox.width_pt(),
                            unit.topt(paperwidth) / bbox.height_pt())
                    else:
                        sfactor = min(
                            unit.topt(paperwidth) / bbox.width_pt(),
                            unit.topt(paperheight) / bbox.height_pt())

                    pagetrafo = pagetrafo.scaled(
                        sfactor, sfactor, self.margin + 0.5 * paperwidth,
                        self.margin + 0.5 * paperheight)

                # apply the pagetrafo and write it to the contentfile
                bbox.transform(pagetrafo)
                pagetrafofile = cStringIO.StringIO()
                # context, bbox, registry are just passed as stubs (the trafo should not touch them)
                getattr(pagetrafo, processMethod)(pagetrafofile, writer,
                                                  context, registry, bbox)
                contentfile.write(pagetrafofile.getvalue())
                pagetrafofile.close()

            contentfile.write(canvasfile.getvalue())
            canvasfile.close()
예제 #7
0
파일: pattern.py 프로젝트: dcf21/pyxplot7
 def __init__(self, dist, angle, strokestyles=[]):
     pattern.__init__(self, painttype=1, tilingtype=1, xstep=dist, ystep=dist, bbox=None, trafo=trafo.rotate(angle))
     self.strokestyles = attr.mergeattrs([style.linewidth.THIN] + strokestyles)
     attr.checkattrs(self.strokestyles, [style.strokestyle])
     self.dist = dist
     self.angle = angle
     self.stroke(path.line_pt(0, 0, 0, unit.topt(dist)), self.strokestyles)
     self.stroke(path.line_pt(0, 0, unit.topt(dist), 0), self.strokestyles)
예제 #8
0
파일: document.py 프로젝트: dcf21/pyxplot7
    def _process(self, processMethod, contentfile, writer, context, registry, bbox):
        assert not bbox

        # check whether we expect a page trafo and use a temporary canvasfile to insert the
        # pagetrafo in front after the bbox was calculated
        expectpagetrafo = self.paperformat and (self.rotated or self.centered or self.fittosize)
        if expectpagetrafo:
            canvasfile = cStringIO.StringIO()
        else:
            canvasfile = contentfile

        getattr(style.linewidth.normal, processMethod)(canvasfile, writer, context, registry, bbox)
        getattr(self.canvas, processMethod)(canvasfile, writer, context, registry, bbox)

        # usually its the bbox of the canvas enlarged by self.bboxenlarge, but
        # it might be a different bbox as specified in the page constructor
        if self.pagebbox:
            bbox.set(self.pagebbox)
        elif bbox:
            bbox.enlarge(self.bboxenlarge)

        if expectpagetrafo:

            if bbox:
                # calculate the pagetrafo
                paperwidth, paperheight = self.paperformat.width, self.paperformat.height

                # center (optionally rotated) output on page
                if self.rotated:
                    pagetrafo = trafo.rotate(90).translated(paperwidth, 0)
                    if self.centered or self.fittosize:
                        if not self.fittosize and (bbox.height() > paperwidth or bbox.width() > paperheight):
                            warnings.warn("content exceeds the papersize")
                        pagetrafo = pagetrafo.translated(-0.5*(paperwidth - bbox.height()) + bbox.bottom(),
                                                          0.5*(paperheight - bbox.width()) - bbox.left())
                else:
                    if not self.fittosize and (bbox.width() > paperwidth or bbox.height() > paperheight):
                        warnings.warn("content exceeds the papersize")
                    pagetrafo = trafo.translate(0.5*(paperwidth - bbox.width())  - bbox.left(),
                                                0.5*(paperheight - bbox.height()) - bbox.bottom())

                if self.fittosize:

                    if 2*self.margin > paperwidth or 2*self.margin > paperheight:
                        raise ValueError("Margins too broad for selected paperformat. Aborting.")

                    paperwidth -= 2 * self.margin
                    paperheight -= 2 * self.margin

                    # scale output to pagesize - margins
                    if self.rotated:
                        sfactor = min(unit.topt(paperheight)/bbox.width_pt(), unit.topt(paperwidth)/bbox.height_pt())
                    else:
                        sfactor = min(unit.topt(paperwidth)/bbox.width_pt(), unit.topt(paperheight)/bbox.height_pt())

                    pagetrafo = pagetrafo.scaled(sfactor, sfactor, self.margin + 0.5*paperwidth, self.margin + 0.5*paperheight)

                # apply the pagetrafo and write it to the contentfile
                bbox.transform(pagetrafo)
                pagetrafofile = cStringIO.StringIO()
                # context, bbox, registry are just passed as stubs (the trafo should not touch them)
                getattr(pagetrafo, processMethod)(pagetrafofile, writer, context, registry, bbox)
                contentfile.write(pagetrafofile.getvalue())
                pagetrafofile.close()

            contentfile.write(canvasfile.getvalue())
            canvasfile.close()