• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python unit.topt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中unit.topt函数的典型用法代码示例。如果您正苦于以下问题:Python topt函数的具体用法?Python topt怎么用?Python topt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了topt函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

 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)
开发者ID:dcf21,项目名称:pyxplot7,代码行数:8,代码来源:pattern.py


示例2: __init__

    def __init__(self, angle, x=None, y=None, epsilon=_marker):
        vector = 0, 0 
        if x is not None or y is not None:
            if x is None or y is None:
                raise TrafoException("either specify both x and y or none of them")
            vector=_rvector(angle, unit.topt(x), unit.topt(y))

        trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector, epsilon=epsilon)
开发者ID:asuar078,项目名称:python_workspace,代码行数:8,代码来源:trafo.py


示例3: _process

    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)
开发者ID:asuar078,项目名称:python_workspace,代码行数:56,代码来源:document.py


示例4: __init__

    def __init__(self, xpos, ypos, image, width=None, height=None, **kwargs):
        xpos_pt = unit.topt(xpos)
        ypos_pt = unit.topt(ypos)
        if width is not None:
            width_pt = unit.topt(width)
        else:
            width_pt = None
        if height is not None:
            height_pt = unit.topt(height)
        else:
            height_pt = None

        bitmap_pt.__init__(self, xpos_pt, ypos_pt, image, width_pt=width_pt, height_pt=height_pt, **kwargs)
开发者ID:epavlick,项目名称:esl-sent-anal,代码行数:13,代码来源:bitmap.py


示例5: write

 def write(self, file, writer, registry):
     file.write("<<\n"
                "/Type /Page\n"
                "/Parent %i 0 R\n" % registry.getrefno(self.PDFpages))
     paperformat = self.page.paperformat
     if paperformat:
         file.write("/MediaBox [0 0 %f %f]\n" % (unit.topt(paperformat.width), unit.topt(paperformat.height)))
     else:
         file.write("/MediaBox [%f %f %f %f]\n" % self.PDFcontent.bbox.highrestuple_pt())
     if self.PDFcontent.bbox and writer.writebbox:
         file.write("/CropBox [%f %f %f %f]\n" % self.PDFcontent.bbox.highrestuple_pt())
     if self.page.rotated:
         file.write("/Rotate 90\n")
     file.write("/Contents %i 0 R\n" % registry.getrefno(self.PDFcontent))
     self.pageregistry.writeresources(file)
     file.write(">>\n")
开发者ID:dcf21,项目名称:pyxplot7,代码行数:16,代码来源:pdfwriter.py


示例6: _bracepath

    def _bracepath(self, x0_pt, y0_pt, x1_pt, y1_pt): # <<<
        height_pt = unit.topt(self.totalheight)
        totallength_pt = math.hypot(x1_pt - x0_pt, y1_pt - y0_pt)
        leftlength_pt = self.middlerelpos * totallength_pt
        rightlength_pt = totallength_pt - leftlength_pt
        ithick_pt = unit.topt(self.innerstrokesthickness)
        othick_pt = unit.topt(self.outerstrokesthickness)
        bthick_pt = unit.topt(self.barthickness)

        # create the left halfbrace with positive slanting
        # because we will mirror this part
        cos_iangle = math.cos(math.radians(0.5*self.innerstrokesangle - self.slantstrokesangle))
        sin_iangle = math.sin(math.radians(0.5*self.innerstrokesangle - self.slantstrokesangle))
        cos_oangle = math.cos(math.radians(self.outerstrokesangle - self.slantstrokesangle))
        sin_oangle = math.sin(math.radians(self.outerstrokesangle - self.slantstrokesangle))
        cos_slangle = math.cos(math.radians(-self.slantstrokesangle))
        sin_slangle = math.sin(math.radians(-self.slantstrokesangle))
        ilength_pt = self.innerstrokesrelheight * height_pt / cos_iangle
        olength_pt = self.outerstrokesrelheight * height_pt / cos_oangle

        bracepath = self._halfbracepath_pt(leftlength_pt, height_pt,
          ilength_pt, olength_pt, ithick_pt, othick_pt, bthick_pt, cos_iangle,
          sin_iangle, cos_oangle, sin_oangle, cos_slangle,
          sin_slangle).reversed().transformed(trafo.mirror(90))

        # create the right halfbrace with negative slanting
        cos_iangle = math.cos(math.radians(0.5*self.innerstrokesangle + self.slantstrokesangle))
        sin_iangle = math.sin(math.radians(0.5*self.innerstrokesangle + self.slantstrokesangle))
        cos_oangle = math.cos(math.radians(self.outerstrokesangle + self.slantstrokesangle))
        sin_oangle = math.sin(math.radians(self.outerstrokesangle + self.slantstrokesangle))
        cos_slangle = math.cos(math.radians(-self.slantstrokesangle))
        sin_slangle = math.sin(math.radians(-self.slantstrokesangle))
        ilength_pt = self.innerstrokesrelheight * height_pt / cos_iangle
        olength_pt = self.outerstrokesrelheight * height_pt / cos_oangle

        bracepath = bracepath << self._halfbracepath_pt(rightlength_pt, height_pt,
        ilength_pt, olength_pt, ithick_pt, othick_pt, bthick_pt, cos_iangle,
        sin_iangle, cos_oangle, sin_oangle, cos_slangle,
        sin_slangle)

        return bracepath.transformed(
          # two trafos for matching the given endpoints
          trafo.translate_pt(x0_pt, y0_pt) *
          trafo.rotate_pt(math.degrees(math.atan2(y1_pt-y0_pt, x1_pt-x0_pt))) *
          # one trafo to move the brace's left outer stroke to zero
          trafo.translate_pt(leftlength_pt, 0))
开发者ID:asuar078,项目名称:python_workspace,代码行数:46,代码来源:deco.py


示例7: __init__

 def __init__(self, box1, box2, relangle=45,
              absbulge=None, relbulge=None, boxdists=[0,0]):
     if absbulge is not None:
         absbulge = unit.topt(absbulge)
     arc_pt.__init__(self, box1, box2,
                     relangle=relangle,
                     absbulge=absbulge, relbulge=relbulge,
                     boxdists=map(unit.topt, boxdists))
开发者ID:dcf21,项目名称:pyxplot7,代码行数:8,代码来源:connector.py


示例8: enlarged

    def enlarged(self, all=0, bottom=None, left=None, top=None, right=None):
        """return bbox enlarged

        all is used, if bottom, left, top and/or right are not given.

        """
        if self.llx_pt is None:
            return empty()
        bottom_pt = left_pt = top_pt = right_pt = unit.topt(all)
        if bottom is not None:
           bottom_pt = unit.topt(bottom)
        if left is not None:
           left_pt = unit.topt(left)
        if top is not None:
           top_pt = unit.topt(top)
        if right is not None:
           right_pt = unit.topt(right)
        return bbox_pt(self.llx_pt-left_pt, self.lly_pt-bottom_pt, self.urx_pt+right_pt, self.ury_pt+top_pt)
开发者ID:asuar078,项目名称:python_workspace,代码行数:18,代码来源:bbox.py


示例9: processPDF

    def processPDF(self, file, writer, context, registry, bbox):
        # we need to keep track of the resources used by the pattern, hence
        # we create our own registry, which we merge immediately in the main registry
        patternregistry = pdfwriter.PDFregistry()

        patternfile = cStringIO.StringIO()
        realpatternbbox = bboxmodule.empty()
        canvas._canvas.processPDF(self, patternfile, writer, pdfwriter.context(), patternregistry, realpatternbbox)
        patternproc = patternfile.getvalue()
        patternfile.close()

        registry.mergeregistry(patternregistry)

        if self.xstep is None:
           xstep = unit.topt(realpatternbbox.width())
        else:
           xstep = unit.topt(self.xstep)
        if self.ystep is None:
            ystep = unit.topt(realpatternbbox.height())
        else:
           ystep = unit.topt(self.ystep)
        if not xstep:
            raise ValueError("xstep in pattern cannot be zero")
        if not ystep:
            raise ValueError("ystep in pattern cannot be zero")
        patternbbox = self.patternbbox or realpatternbbox.enlarged(5*unit.pt)
        patterntrafo = self.patterntrafo or trafo.trafo()

        registry.add(PDFpattern(self.id, self.patterntype, self.painttype, self.tilingtype,
                                patternbbox, xstep, ystep, patterntrafo, patternproc, writer, registry, patternregistry))

        # activate pattern
        if context.colorspace != "Pattern":
            # we only set the fill color space (see next comment)
            file.write("/Pattern cs\n")
            context.colorspace = "Pattern"
        if context.strokeattr:
            # using patterns as stroke colors doesn't seem to work, so
            # we just don't do this...
            warnings.warn("ignoring stroke color for patterns in PDF")
        if context.fillattr:
            file.write("/%s scn\n"% self.id)
开发者ID:dcf21,项目名称:pyxplot7,代码行数:42,代码来源:pattern.py


示例10: enlarge

    def enlarge(self, all=0, bottom=None, left=None, top=None, right=None):
        """enlarge bbox in place

        all is used, if bottom, left, top and/or right are not given.

        """
        if self.llx_pt is None:
            return
        bottom_pt = left_pt = top_pt = right_pt = unit.topt(all)
        if bottom is not None:
           bottom_pt = unit.topt(bottom)
        if left is not None:
           left_pt = unit.topt(left)
        if top is not None:
           top_pt = unit.topt(top)
        if right is not None:
           right_pt = unit.topt(right)
        self.llx_pt -= left_pt
        self.lly_pt -= bottom_pt
        self.urx_pt += right_pt
        self.ury_pt += top_pt
开发者ID:asuar078,项目名称:python_workspace,代码行数:21,代码来源:bbox.py


示例11: path

 def path(self, centerradius=None, bezierradius=None, beziersoftness=None):
     pathitems = []
     if centerradius is not None and self.center is not None:
         r = unit.topt(centerradius)
         pathitems.append(path.arc_pt(self.center[0], self.center[1], r, 0, 360))
         pathitems.append(path.closepath())
     if bezierradius is not None or beziersoftness is not None:
         raise ValueError("smooth functionality removed; apply smooth deformer on path")
     pathitems.append(path.moveto_pt(self.corners[0][0], self.corners[0][1]))
     for x, y in self.corners[1:]:
         pathitems.append(path.lineto_pt(x, y))
     pathitems.append(path.closepath())
     return path.path(*pathitems)
开发者ID:dcf21,项目名称:pyxplot7,代码行数:13,代码来源:box.py


示例12: _decocanvas

    def _decocanvas(self, angle, dp, texrunner):
        dp.ensurenormpath()
        dist_pt = unit.topt(self.dist)

        c = canvas.canvas([canvas.clip(dp.path)])
        llx_pt, lly_pt, urx_pt, ury_pt = dp.path.bbox().highrestuple_pt()
        center_pt = 0.5*(llx_pt+urx_pt), 0.5*(lly_pt+ury_pt)
        radius_pt = 0.5*math.hypot(urx_pt-llx_pt, ury_pt-lly_pt) + dist_pt
        n = int(2*radius_pt / dist_pt) + 1
        for i in range(n):
            x_pt = center_pt[0] - radius_pt + i*dist_pt
            c.stroke(path.line_pt(x_pt, center_pt[1]-radius_pt, x_pt, center_pt[1]+radius_pt),
                     [trafo.rotate_pt(angle, center_pt[0], center_pt[1])] + self.strokestyles)
        return c
开发者ID:asuar078,项目名称:python_workspace,代码行数:14,代码来源:deco.py


示例13: processPS

    def processPS(self, file, writer, context, registry, bbox):
        # process pattern, letting it register its resources and calculate the bbox of the pattern
        patternfile = cStringIO.StringIO()
        realpatternbbox = bboxmodule.empty()
        canvas._canvas.processPS(self, patternfile, writer, pswriter.context(), registry, realpatternbbox)
        patternproc = patternfile.getvalue()
        patternfile.close()

        if self.xstep is None:
           xstep = unit.topt(realpatternbbox.width())
        else:
           xstep = unit.topt(self.xstep)
        if self.ystep is None:
            ystep = unit.topt(realpatternbbox.height())
        else:
           ystep = unit.topt(self.ystep)
        if not xstep:
            raise ValueError("xstep in pattern cannot be zero")
        if not ystep:
            raise ValueError("ystep in pattern cannot be zero")
        patternbbox = self.patternbbox or realpatternbbox.enlarged(5*unit.pt)

        patternprefix = "\n".join(("<<",
                                   "/PatternType %d" % self.patterntype,
                                   "/PaintType %d" % self.painttype,
                                   "/TilingType %d" % self.tilingtype,
                                   "/BBox[%d %d %d %d]" % patternbbox.lowrestuple_pt(),
                                   "/XStep %g" % xstep,
                                   "/YStep %g" % ystep,
                                   "/PaintProc {\nbegin\n"))
        patterntrafostring = self.patterntrafo is None and "matrix" or str(self.patterntrafo)
        patternsuffix = "end\n} bind\n>>\n%s\nmakepattern" % patterntrafostring

        registry.add(pswriter.PSdefinition(self.id, "".join((patternprefix, patternproc, patternsuffix))))

        # activate pattern
        file.write("%s setpattern\n" % self.id)
开发者ID:dcf21,项目名称:pyxplot7,代码行数:37,代码来源:pattern.py


示例14: decorate

 def decorate(self, dp, texrunner):
     dp.ensurenormpath()
     x0_pt, y0_pt = dp.path.atbegin_pt()
     x1_pt, y1_pt = dp.path.atend_pt()
     if self.reverse:
         x0_pt, y0_pt, x1_pt, y1_pt = x1_pt, y1_pt, x0_pt, y0_pt
     if self.stretch is not None:
         xm, ym = 0.5*(x0_pt+x1_pt), 0.5*(y0_pt+y1_pt)
         x0_pt, y0_pt = xm + self.stretch*(x0_pt-xm), ym + self.stretch*(y0_pt-ym)
         x1_pt, y1_pt = xm + self.stretch*(x1_pt-xm), ym + self.stretch*(y1_pt-ym)
     if self.dist is not None:
         d = unit.topt(self.dist)
         dx, dy = dp.path.rotation_pt(dp.path.begin()).apply_pt(0, 1)
         x0_pt += d*dx; y0_pt += d*dy
         dx, dy = dp.path.rotation_pt(dp.path.end()).apply_pt(0, 1)
         x1_pt += d*dx; y1_pt += d*dy
     dp.ornaments.fill(self._bracepath(x0_pt, y0_pt, x1_pt, y1_pt), self.fillattrs)
开发者ID:asuar078,项目名称:python_workspace,代码行数:17,代码来源:deco.py


示例15: __init__

 def __init__(self, x1, y1, x2, y2, x3, y3):
     curveto_pt.__init__(self,
                         unit.topt(x1), unit.topt(y1),
                         unit.topt(x2), unit.topt(y2),
                         unit.topt(x3), unit.topt(y3))
开发者ID:epavlick,项目名称:esl-sent-anal,代码行数:5,代码来源:path.py


示例16: __init__

 def __init__(self, coords, value):
     node_pt.__init__(self, [unit.topt(coord) for coord in coords], value)
开发者ID:dcf21,项目名称:pyxplot7,代码行数:2,代码来源:mesh.py


示例17: __init__

    def __init__(self,
                 x, y, filename,
                 width=None, height=None, scale=None, align="bl",
                 clip=1, translatebbox=1, bbox=None,
                 kpsearch=0):
        """inserts epsfile

        Object for an EPS file named filename at position (x,y). Width, height,
        scale and aligment can be adjusted by the corresponding parameters. If
        clip is set, the result gets clipped to the bbox of the EPS file. If
        translatebbox is not set, the EPS graphics is not translated to the
        corresponding origin. If bbox is not None, it overrides the bounding
        box in the epsfile itself. If kpsearch is set then filename is searched
        using the kpathsea library.
        """

        self.x_pt = unit.topt(x)
        self.y_pt = unit.topt(y)
        self.filename = filename
        self.kpsearch = kpsearch
        if bbox:
            self.mybbox = bbox
        else:
            epsfile = self.open()
            self.mybbox = _readbbox(epsfile)
            epsfile.close()

        # determine scaling in x and y direction
        self.scalex = self.scaley = scale

        if width is not None or height is not None:
            if scale is not None:
                raise ValueError("cannot set both width and/or height and scale simultaneously")
            if height is not None:
                self.scaley = unit.topt(height)/(self.mybbox.ury_pt-self.mybbox.lly_pt)
            if width is not None:
                self.scalex = unit.topt(width)/(self.mybbox.urx_pt-self.mybbox.llx_pt)

            if self.scalex is None:
                self.scalex = self.scaley
            if self.scaley is None:
                self.scaley = self.scalex

        # set the actual width and height of the eps file (after a
        # possible scaling)
        self.width_pt  = self.mybbox.urx_pt-self.mybbox.llx_pt
        if self.scalex:
            self.width_pt *= self.scalex

        self.height_pt = self.mybbox.ury_pt-self.mybbox.lly_pt
        if self.scaley:
            self.height_pt *= self.scaley

        # take alignment into account
        self.align       = align
        if self.align[0]=="b":
            pass
        elif self.align[0]=="c":
            self.y_pt -= self.height_pt/2.0
        elif self.align[0]=="t":
            self.y_pt -= self.height_pt
        else:
            raise ValueError("vertical alignment can only be b (bottom), c (center), or t (top)")

        if self.align[1]=="l":
            pass
        elif self.align[1]=="c":
            self.x_pt -= self.width_pt/2.0
        elif self.align[1]=="r":
            self.x_pt -= self.width_pt
        else:
            raise ValueError("horizontal alignment can only be l (left), c (center), or r (right)")

        self.clip = clip
        self.translatebbox = translatebbox

        self.trafo = trafo.translate_pt(self.x_pt, self.y_pt)

        if self.scalex is not None:
            self.trafo = self.trafo * trafo.scale_pt(self.scalex, self.scaley)

        if translatebbox:
            self.trafo = self.trafo * trafo.translate_pt(-self.mybbox.llx_pt, -self.mybbox.lly_pt)
开发者ID:asuar078,项目名称:python_workspace,代码行数:83,代码来源:epsfile.py


示例18: apply

 def apply(self, x, y):
     # for the transformation we have to convert to points
     tx, ty = self.apply_pt(unit.topt(x), unit.topt(y))
     return tx * unit.t_pt, ty * unit.t_pt
开发者ID:asuar078,项目名称:python_workspace,代码行数:4,代码来源:trafo.py



注:本文中的unit.topt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unit.Unit类代码示例发布时间:2022-05-27
下一篇:
Python unirest.post函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap