本文整理汇总了Python中xhtml2pdf.reportlab_paragraph.Paragraph类的典型用法代码示例。如果您正苦于以下问题:Python Paragraph类的具体用法?Python Paragraph怎么用?Python Paragraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Paragraph类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrap
def wrap(self, availWidth, availHeight):
availHeight = self.setMaxHeight(availHeight)
style = self.style
self.deltaWidth = style.paddingLeft + style.paddingRight + style.borderLeftWidth + style.borderRightWidth
self.deltaHeight = style.paddingTop + style.paddingBottom + style.borderTopWidth + style.borderBottomWidth
# reduce the available width & height by the padding so the wrapping
# will use the correct size
availWidth -= self.deltaWidth
availHeight -= self.deltaHeight
# Modify maxium image sizes
self._calcImageMaxSizes(availWidth, self.getMaxHeight() - self.deltaHeight)
# call the base class to do wrapping and calculate the size
Paragraph.wrap(self, availWidth, availHeight)
#self.height = max(1, self.height)
#self.width = max(1, self.width)
# increase the calculated size by the padding
self.width = self.width + self.deltaWidth
self.height = self.height + self.deltaHeight
return (self.width, self.height)
示例2: split
def split(self, availWidth, availHeight):
if len(self.frags) <= 0:
return []
#the split information is all inside self.blPara
if not hasattr(self, 'deltaWidth'):
self.wrap(availWidth, availHeight)
availWidth -= self.deltaWidth
availHeight -= self.deltaHeight
return Paragraph.split(self, availWidth, availHeight)
示例3: draw
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,
#.........这里部分代码省略.........