本文整理汇总了Python中unit.topt函数的典型用法代码示例。如果您正苦于以下问题:Python topt函数的具体用法?Python topt怎么用?Python topt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了topt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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")
示例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))
示例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))
示例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)
示例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)
示例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
示例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)
示例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
示例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)
示例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)
示例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))