本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.setLineCap方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.setLineCap方法的具体用法?Python Canvas.setLineCap怎么用?Python Canvas.setLineCap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.pdfgen.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.setLineCap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import setLineCap [as 别名]
def render(grid, options):
draw_with_curves = options['draw_with_curves']
filename = options['filename']
use_A4 = options['use_A4']
width = options['width']
height = options['height']
def s_shape_00(p):
p.moveTo(a, 0)
if draw_with_curves:
p.arcTo(-a, -a, a, a, 0, 90)
else:
p.lineTo(a, a)
p.lineTo(0, a)
def s_shape_01(p):
p.moveTo(0, b)
if draw_with_curves:
p.arcTo(-a, b, a, s + a, 270, 90)
else:
p.lineTo(a, b)
p.lineTo(a, s)
def s_shape_10(p):
p.moveTo(s, a)
if draw_with_curves:
p.arcTo(b, -a, s + a, a, 90, 90)
else:
p.lineTo(b, a)
p.lineTo(b, 0)
def s_shape_11(p):
p.moveTo(s, b)
if draw_with_curves:
p.arcTo(b, b, s + a, s + a, 270, -90)
else:
p.lineTo(b, b)
p.lineTo(b, s)
buffer = StringIO()
if filename:
c = Canvas(filename)
else:
c = Canvas(buffer)
c.setTitle('Maze')
c.setSubject("")
c.setAuthor("Dale O'Brien")
if use_A4:
page_width = 8.3 * 72
page_height = 11.7 * 72
else:
page_width = 8.5 * 72
page_height = 11.0 * 72
c.setPageSize((page_width, page_height))
# 0=butt,1=draw_with_curves,2=square
c.setLineCap(1)
left_margin = 15
top_margin = 15
# cells must be square, it's the math!, I'm not doing it again.
# so scale the width if the height will go over the page
org_width = width
ratio = (page_height - 2 * top_margin) / (page_width - 2 * left_margin)
if (float(height) / width > ratio):
width = ceil(height / ratio)
s = (page_width - 2 * left_margin) / width
# center the maze, looks better for mazes that don't fit the page nicely
left_margin -= (org_width - width) * s / 2.0
top_margin -= (s * height - (page_height - 2.0 * top_margin)) / 2.0
g = s * 0.2
stroke = s / 7.0
c.setLineWidth(stroke)
k = 0.5
n = -(g / k) + 0.5 * (s - sqrt((g *
(4.0 * g - 3.0 * g * k + 2 * k * s)) / k))
r = g / k
q = n + r
v = (g * (-1 + k)) / k
theta = asin((2.0 * g - 2.0 * g * k + k * s) /
(2.0 * g - g * k + k * s)) * 180 / pi
delta = theta - 90
for j, row in enumerate(grid):
# upper/lower rows
#.........这里部分代码省略.........
示例2: min
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import setLineCap [as 别名]
cropposns = image.get(crops, cropdefault)
for cpos in cropposns:
if not cpos.abs:
cpos = cpos.normalise(image[pix], image[dim])
pmin = min(cpos.val, pmin)
pmax = max(cpos.val, pmax)
image[pos] = ((lo+hi) - (pmax+pmin)) / 2.0
image[minval] = image[pos] + pmin
image[maxval] = image[pos] + pmax
# Draw crop marks.
if image.get('crops',False):
pdf.setLineWidth(inch/720.0)
pdf.setLineCap(0)
for xcrop in image.get("xcrops", cropdefault):
if not xcrop.abs:
xcrop = xcrop.normalise(image["pw"], image["w"])
pdf.line(xcrop.val + image["x"], image["y0"] - cropdist.val,
xcrop.val + image["x"], image["y0"] - cropdist.val - croplen.val)
pdf.line(xcrop.val + image["x"], image["y1"] + cropdist.val,
xcrop.val + image["x"], image["y1"] + cropdist.val + croplen.val)
for ycrop in image.get("ycrops", cropdefault):
if not ycrop.abs:
ycrop = ycrop.normalise(image["ph"], image["h"])
pdf.line(image["x0"] - cropdist.val, ycrop.val + image["y"],
image["x0"] - cropdist.val - croplen.val, ycrop.val + image["y"])
pdf.line(image["x1"] + cropdist.val, ycrop.val + image["y"],
image["x1"] + cropdist.val + croplen.val, ycrop.val + image["y"])
示例3: PDFGenerator
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import setLineCap [as 别名]
#.........这里部分代码省略.........
r, g, b = color[1]
return Color(r, g, b, alpha)
elif color[0] == uc2const.COLOR_GRAY:
k = 1.0 - color[1][0]
c = m = y = 0.0
pdfcolor = CMYKColor(c, m, y, k, alpha=alpha)
else:
c, m, y, k = self.cms.get_cmyk_color(color)[1]
pdfcolor = CMYKColor(c, m, y, k, alpha=alpha)
self.set_rgb_values(color, pdfcolor)
return pdfcolor
def stroke_pdfpath(self, pdfpath, stroke_style, stroke_trafo=[]):
width = stroke_style[1]
if not stroke_style[8]:
width = stroke_style[1]
else:
if not stroke_trafo:
stroke_trafo = [] + sk2_const.NORMAL_TRAFO
points = [[0.0, 0.0], [1.0, 0.0]]
points = libgeom.apply_trafo_to_points(points, stroke_trafo)
coef = libgeom.distance(*points)
width = stroke_style[1] * coef
self.canvas.setStrokeColor(self.get_pdfcolor(stroke_style[2]))
dash = stroke_style[3]
caps = stroke_style[4]
joint = stroke_style[5]
miter = stroke_style[6]
self.canvas.setLineWidth(width)
self.canvas.setLineCap(caps - 1)
self.canvas.setLineJoin(joint)
dashes = []
if dash:
dashes = list(dash)
w = width
if w < 1.0: w = 1.0
for i in range(len(dashes)):
dashes[i] = w * dashes[i]
self.canvas.setDash(dashes)
self.canvas.setMiterLimit(miter)
self.canvas.drawPath(pdfpath, 1, 0)
self.canvas.setStrokeAlpha(1.0)
def fill_pdfpath(self, obj, pdfpath, fill_style, fill_trafo=None):
self.set_fill_rule(fill_style[0])
if fill_style[1] == sk2_const.FILL_SOLID:
self.canvas.setFillColor(self.get_pdfcolor(fill_style[2]))
self.canvas.drawPath(pdfpath, 0, 1)
elif fill_style[1] == sk2_const.FILL_GRADIENT:
gradient = fill_style[2]
stops = gradient[2]
transparency = False
for stop in stops:
if stop[1][2] < 1.0:
transparency = True
break
if transparency:
self.fill_tr_gradient(obj, pdfpath, fill_trafo, gradient)
else:
self.fill_gradient(pdfpath, fill_trafo, gradient)