本文整理汇总了Python中xhtml2pdf.reportlab_paragraph.Paragraph.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Paragraph.draw方法的具体用法?Python Paragraph.draw怎么用?Python Paragraph.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xhtml2pdf.reportlab_paragraph.Paragraph
的用法示例。
在下文中一共展示了Paragraph.draw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from xhtml2pdf.reportlab_paragraph import Paragraph [as 别名]
# 或者: from xhtml2pdf.reportlab_paragraph.Paragraph import draw [as 别名]
def draw(self):
# Insert page number
'''
if 0: #for line in self.blPara.lines:
try:
for frag in line.words:
#print 111,frag.pageNumber, frag.text
if frag.pageNumber:
frag.text = str(self.canv.getPageNumber())
except Exception, e:
log.debug("PmlParagraph", exc_info=1)
'''
# Create outline
if getattr(self, "outline", False):
# Check level and add all levels
last = getattr(self.canv, "outlineLast", - 1) + 1
while last < self.outlineLevel:
# print "(OUTLINE", last, self.text
key = getUID()
self.canv.bookmarkPage(key)
self.canv.addOutlineEntry(
self.text,
key,
last,
not self.outlineOpen)
last += 1
self.canv.outlineLast = self.outlineLevel
key = getUID()
# print " OUTLINE", self.outlineLevel, self.text
self.canv.bookmarkPage(key)
self.canv.addOutlineEntry(
self.text,
key,
self.outlineLevel,
not self.outlineOpen)
last += 1
#else:
# print repr(self.text)[:80]
# Draw the background and borders here before passing control on to
# ReportLab. This is because ReportLab can't handle the individual
# components of the border independently. This will also let us
# support more border styles eventually.
canvas = self.canv
style = self.style
bg = style.backColor
leftIndent = style.leftIndent
bp = 0 # style.borderPadding
x = leftIndent - bp
y = - bp
w = self.width - (leftIndent + style.rightIndent) + 2 * bp
h = self.height + 2 * bp
if bg:
# draw a filled rectangle (with no stroke) using bg color
canvas.saveState()
canvas.setFillColor(bg)
canvas.rect(x, y, w, h, fill=1, stroke=0)
canvas.restoreState()
# we need to hide the bg color (if any) so Paragraph won't try to draw it again
style.backColor = None
# offset the origin to compensate for the padding
canvas.saveState()
canvas.translate(
(style.paddingLeft + style.borderLeftWidth),
-1 * (style.paddingTop + style.borderTopWidth)) # + (style.leading / 4)))
# Call the base class draw method to finish up
Paragraph.draw(self)
canvas.restoreState()
# Reset color because we need it again if we run 2-PASS like we
# do when using TOC
style.backColor = bg
canvas.saveState()
def _drawBorderLine(bstyle, width, color, x1, y1, x2, y2):
# We need width and border style to be able to draw a border
if width and getBorderStyle(bstyle):
# If no color for border is given, the text color is used (like defined by W3C)
if color is None:
color = style.textColor
# print "Border", bstyle, width, color
if color is not None:
canvas.setStrokeColor(color)
canvas.setLineWidth(width)
canvas.line(x1, y1, x2, y2)
_drawBorderLine(style.borderLeftStyle,
style.borderLeftWidth,
style.borderLeftColor,
#.........这里部分代码省略.........