本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.clipPath方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.clipPath方法的具体用法?Python Canvas.clipPath怎么用?Python Canvas.clipPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.pdfgen.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.clipPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_new_canvas
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import clipPath [as 别名]
def _create_new_canvas(self):
pagesize = PAGE_SIZE_MAP[self.pagesize]
units = UNITS_MAP[self.dest_box_units]
gc = Canvas(filename=self.filename, pagesize=pagesize)
width = pagesize[0] * units * inch / 72.0
height = pagesize[1] * units * inch / 72.0
x = self.dest_box[0] * units
y = self.dest_box[1] * units
w = self.dest_box[2] * units
h = self.dest_box[3] * units
if w < 0:
w += width
if h < 0:
h += height
if w < 0 or h < 0:
warnings.warn("Margins exceed page dimensions.")
self.gc = None
return
gc.translate(x,y)
path = gc.beginPath()
path.rect(0, 0, w, h)
gc.clipPath(path, stroke=0, fill=0)
return gc
示例2: __init__
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import clipPath [as 别名]
def __init__(self,
IDmodele=None,
taillePage=(210, 297),
listeValeurs=[],
margeHaut=10,
margeGauche=10,
margeBas = 10,
margeDroite=10,
espaceVertical=5,
espaceHorizontal=5,
nbre_copies=1,
AfficherContourEtiquette=True,
AfficherReperesDecoupe=True,
):
# ----------------------------------------------------------------------------------------------------------------------------------------
def AfficheReperesDecoupe():
if AfficherReperesDecoupe == True :
canvas.setStrokeColor( (0.9, 0.9, 0.9) )
canvas.setLineWidth(0.25)
# Repères de colonnes
for y1, y2 in [(hauteurPage*mm-4*mm, hauteurPage*mm-margeHaut*mm+2*mm), (4*mm, margeBas-2*mm)] :
x = margeGauche*mm
for numColonne in range(0, nbreColonnes):
canvas.line(x, y1, x, y2)
x += largeurEtiquette*mm
canvas.line(x, y1, x, y2)
x += espaceHorizontal*mm
# Repères de lignes
for x1, x2 in [(4*mm, margeGauche*mm-2*mm), (largeurPage*mm-4*mm, largeurPage*mm-margeDroite*mm+2*mm)] :
y = hauteurPage*mm - margeHaut*mm
for numLigne in range(0, nbreLignes):
canvas.line(x1, y, x2, y)
y -= hauteurEtiquette*mm
canvas.line(x1, y, x2, y)
y -= espaceVertical*mm
# -----------------------------------------------------------------------------------------------------------------------------------------
largeurPage = taillePage[0]
hauteurPage = taillePage[1]
# Initialisation du modèle de document
modeleDoc = DLG_Noedoc.ModeleDoc(IDmodele=IDmodele)
largeurEtiquette = modeleDoc.dictInfosModele["largeur"]
hauteurEtiquette = modeleDoc.dictInfosModele["hauteur"]
# Calcul du nbre de colonnes et de lignes
nbreColonnes = (largeurPage - margeGauche - margeDroite + espaceHorizontal) / (largeurEtiquette + espaceHorizontal)
nbreLignes = (hauteurPage - margeHaut - margeBas + espaceVertical) / (hauteurEtiquette + espaceVertical)
# Initialisation du PDF
nomDoc = FonctionsPerso.GenerationNomDoc("ETIQUETTES", "pdf")
canvas = Canvas(nomDoc, pagesize=(largeurPage*mm, hauteurPage*mm))
# Création des étiquettes
numColonne = 0
numLigne = 0
for dictValeurs in listeValeurs :
for num_copie in range(0, nbre_copies) :
x = margeGauche + ((largeurEtiquette + espaceHorizontal) * numColonne)
y = hauteurPage - margeHaut - hauteurEtiquette - ((hauteurEtiquette + espaceVertical) * numLigne)
# Positionnement sur la feuille
canvas.saveState()
canvas.translate(x*mm, y*mm)
# Création du clipping
p = canvas.beginPath()
canvas.setStrokeColor( (1, 1, 1) )
canvas.setLineWidth(0.25)
p.rect(0, 0, largeurEtiquette*mm, hauteurEtiquette*mm)
canvas.clipPath(p)
# Dessin de l'étiquette
modeleDoc.DessineFond(canvas, dictChamps=dictValeurs)
etat = modeleDoc.DessineTousObjets(canvas, dictChamps=dictValeurs)
if etat == False :
return
# Dessin du contour de l'étiquette
if AfficherContourEtiquette == True :
canvas.setStrokeColor( (0, 0, 0) )
canvas.setLineWidth(0.25)
canvas.rect(0, 0, largeurEtiquette*mm, hauteurEtiquette*mm)
canvas.restoreState()
# Saut de colonne
numColonne += 1
# Saut de ligne
if numColonne > nbreColonnes - 1 :
numLigne += 1
numColonne = 0
# Saut de page
if numLigne > nbreLignes - 1 :
AfficheReperesDecoupe()
canvas.showPage()
numLigne = 0
#.........这里部分代码省略.........
示例3: PDFGenerator
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import clipPath [as 别名]
#.........这里部分代码省略.........
obj_count += 1
shift = 0.0
page_size = 1.0
if self.num_pages:
shift = float(self.page_count) / float(self.num_pages)
page_size = 1.0 / float(self.num_pages)
position = shift + obj_count / len(objs) * page_size
events.emit(events.FILTER_INFO, self.prgs_msg, position)
def draw_curve(self, curve_obj):
paths = libgeom.apply_trafo_to_paths(curve_obj.paths, curve_obj.trafo)
pdfpath, closed = self.make_pdfpath(paths)
fill_style = curve_obj.style[0]
stroke_style = curve_obj.style[1]
if stroke_style and stroke_style[7]:
self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo)
if fill_style and fill_style[0] & sk2_const.FILL_CLOSED_ONLY and closed:
self.fill_pdfpath(curve_obj, pdfpath, fill_style, curve_obj.fill_trafo)
elif fill_style and not fill_style[0] & sk2_const.FILL_CLOSED_ONLY:
self.fill_pdfpath(curve_obj, pdfpath, fill_style, curve_obj.fill_trafo)
if stroke_style and not stroke_style[7]:
self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo)
def draw_container(self, obj):
container = obj.childs[0].to_curve()
paths = libgeom.apply_trafo_to_paths(container.paths, container.trafo)
pdfpath, closed = self.make_pdfpath(paths)
fill_style = container.style[0]
stroke_style = container.style[1]
if stroke_style and stroke_style[7]:
self.stroke_pdfpath(pdfpath, stroke_style, container.stroke_trafo)
self.canvas.saveState()
self.canvas.clipPath(pdfpath, 0, 0)
if fill_style and fill_style[0] & sk2_const.FILL_CLOSED_ONLY and closed:
self.fill_pdfpath(container, pdfpath, fill_style, container.fill_trafo)
elif fill_style and not fill_style[0] & sk2_const.FILL_CLOSED_ONLY:
self.fill_pdfpath(container, pdfpath, fill_style, container.fill_trafo)
self.render(obj.childs[1:])
self.canvas.restoreState()
if stroke_style and not stroke_style[7]:
self.stroke_pdfpath(pdfpath, stroke_style, container.stroke_trafo)
def make_pdfpath(self, paths):
closed = False
pdfpath = self.canvas.beginPath()
for path in paths:
pdfpath.moveTo(*path[0])
for point in path[1]:
if len(point) > 2:
pdfpath.curveTo(point[0][0], point[0][1],
point[1][0], point[1][1],
point[2][0], point[2][1])
else:
pdfpath.lineTo(*point)
if path[2]:
pdfpath.close()
closed = True
return pdfpath, closed
def set_fill_rule(self, fillrule):
if fillrule in (sk2_const.FILL_EVENODD,