本文整理汇总了Python中reportlab.lib.styles.ParagraphStyle.leading方法的典型用法代码示例。如果您正苦于以下问题:Python ParagraphStyle.leading方法的具体用法?Python ParagraphStyle.leading怎么用?Python ParagraphStyle.leading使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.lib.styles.ParagraphStyle
的用法示例。
在下文中一共展示了ParagraphStyle.leading方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawText
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def drawText(self,txt,x,y,w,h,style={}):
margin = 0
self.canvas.saveState()
path = self.canvas.beginPath()
path.rect(x,y,w,h)
self.canvas.clipPath(path,stroke=1)
_s = styles['BodyText']
_s = ParagraphStyle({})
_s.fontSize = style['fontSize']*1.0
# _s.fontSize = style['fontSize']
_s.leading = style['fontSize']
print _s
print 'writing text',txt,x,y
while _s.fontSize > 1.0:
p = Paragraph(txt.strip(),_s)
aw,ah = p.wrapOn(self.canvas,w-margin*2,h-margin*2)
print aw,w-margin*2,ah,h-margin*2,_s.fontSize
break
if (aw > w-margin*2) or (ah > h-margin*2):
_s.fontSize = _s.fontSize - 1
_s.leading = _s.fontSize*1.9
else:
break
p.drawOn(self.canvas,x+margin,y+margin)
self.canvas.restoreState()
示例2: _prepare_styles
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def _prepare_styles():
styles = {}
stylesheet = getSampleStyleSheet()
style = ParagraphStyle("Normal", stylesheet['Normal'])
style.alignment = TA_LEFT
style.fontSize = 6
style.fontName = 'FreeSans'
style.leading = 8
styles['Normal'] = style
style = ParagraphStyle("ItemTitle", stylesheet['Heading1'])
style.alignment = TA_LEFT
style.fontSize = 8
style.fontName = 'FreeSansBold'
style.fontSize = 10
styles['ItemTitle'] = style
style = ParagraphStyle("Heading", stylesheet['Heading2'])
style.alignment = TA_CENTER
style.fontSize = 6
style.fontName = 'FreeSansBold'
styles['Heading'] = style
style = ParagraphStyle("FieldHead", stylesheet['Heading2'])
style.alignment = TA_LEFT
style.fontSize = 6
style.fontName = 'FreeSansBold'
style.leading = 8
styles['FieldHead'] = style
return styles
示例3: render_card_pdf
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def render_card_pdf(card, filename):
# set up styles
regular = ParagraphStyle('default')
regular.fontName = 'Helvetica'
regular.fontSize = 9
regular.leading = 11
small = ParagraphStyle('default')
small.fontName = 'Helvetica'
small.fontSize = 7
small.leading = 9
large = ParagraphStyle('default')
large.fontName = 'Helvetica'
large.fontSize = 11
large.leading = 13
text = []
# generate content
address_template = Template(address_format)
# return address
text.extend([Paragraph(address_template.render(Context({
'name': card.sender_name,
'address1': card.sender_address1,
'address2': card.sender_address2,
'city': card.sender_city,
'state': card.sender_state,
'zip': card.sender_zip,
})), small), Spacer(10, 10)])
text.append(Paragraph(strip_tags(card.message).replace('\n', '<br />'), regular))
text.extend([Spacer(10, 10), HR(0.5), Spacer(10, 10)])
text.append(Paragraph('The Sunlight Foundation is a non-partisan non-profit that uses cutting-edge technology and ideas to make government transparent and accountable. Visit SunlightFoundation.com to learn more.', small))
canv = Canvas(filename)
canv.setPageSize((6.25 * inch, 4.5 * inch))
f = Frame(0.375 * inch, 0.75 * inch, 3.125 * inch, 3.375 * inch, showBoundary=0)
f.addFromList(text, canv)
address = Frame(3.75 * inch, 1 * inch, 2 * inch, 1.5 * inch, showBoundary=0)
address.addFromList([Paragraph(address_template.render(Context({
'name': card.recipient_name,
'address1': card.recipient_address1,
'address2': card.recipient_address2,
'city': card.recipient_city,
'state': card.recipient_state,
'zip': card.recipient_zip,
})), large)], canv)
canv.save()
示例4: toParagraphStyle
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def toParagraphStyle(self, first, full=False):
style = ParagraphStyle('default%d' % self.UID(), keepWithNext=first.keepWithNext)
style.fontName = first.fontName
style.fontSize = first.fontSize
style.leading = max(first.leading, first.fontSize * 1.25)
style.backColor = first.backColor
style.spaceBefore = first.spaceBefore
style.spaceAfter = first.spaceAfter
style.leftIndent = first.leftIndent
style.rightIndent = first.rightIndent
style.firstLineIndent = first.firstLineIndent
style.textColor = first.textColor
style.alignment = first.alignment
style.bulletFontName = first.bulletFontName or first.fontName
style.bulletFontSize = first.fontSize
style.bulletIndent = first.bulletIndent
# Border handling for Paragraph
style.borderWidth = 0
if getBorderStyle(first.borderTopStyle):
style.borderWidth = max(first.borderLeftWidth, first.borderRightWidth, first.borderTopWidth, first.borderBottomWidth)
style.borderPadding = first.borderPadding # + first.borderWidth
style.borderColor = first.borderTopColor
# If no border color is given, the text color is used (XXX Tables!)
if (style.borderColor is None) and style.borderWidth:
style.borderColor = first.textColor
if full:
style.fontName = tt2ps(first.fontName, first.bold, first.italic)
return style
示例5: test3
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def test3(self):
'''compare CJK splitting in some edge cases'''
from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus.paragraph import Paragraph
from reportlab.lib.styles import ParagraphStyle
from reportlab.pdfbase import pdfmetrics
from reportlab.lib.enums import TA_LEFT
sty = ParagraphStyle('A')
sty.fontSize = 15
sty.leading = sty.fontSize*1.2
sty.fontName = 'Courier'
sty.alignment = TA_LEFT
sty.wordWrap = 'CJK'
p0=Paragraph('ABCDEFGHIJKL]N',sty)
p1=Paragraph('AB<font color="red">C</font>DEFGHIJKL]N',sty)
canv = Canvas('test_platypus_paragraph_cjk3.pdf')
ix = len(canv._code)
aW = pdfmetrics.stringWidth('ABCD','Courier',15)
w,h=p0.wrap(aW,1000000)
y = canv._pagesize[1]-72-h
p0.drawOn(canv,72,y)
w,h=p1.wrap(aW,1000000)
y -= h+10
p1.drawOn(canv,72,y)
w,h=p0.wrap(aW*0.25-2,1000000)
y -= h+10
p0.drawOn(canv,72,y)
w,h=p1.wrap(aW/4.-2,1000000)
y -= h+10
p1.drawOn(canv,72,y)
assert canv._code[ix:]==['q', '1 0 0 1 72 697.8898 cm', 'q', '0 0 0 rg', 'BT 1 0 0 1 0 57 Tm /F2 15 Tf 18 TL (ABCD) Tj T* (EFGH) Tj T* (IJKL]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 615.8898 cm', 'q', 'BT 1 0 0 1 0 57 Tm 18 TL /F2 15 Tf 0 0 0 rg (AB) Tj 1 0 0 rg (C) Tj 0 0 0 rg (D) Tj T* (EFGH) Tj T* (IJKL]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 353.8898 cm', 'q', '0 0 0 rg', 'BT 1 0 0 1 0 237 Tm /F2 15 Tf 18 TL (A) Tj T* (B) Tj T* (C) Tj T* (D) Tj T* (E) Tj T* (F) Tj T* (G) Tj T* (H) Tj T* (I) Tj T* (J) Tj T* (K) Tj T* (L) Tj T* (]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 91.88976 cm', 'q', 'BT 1 0 0 1 0 237 Tm 18 TL /F2 15 Tf 0 0 0 rg (A) Tj T* (B) Tj T* 1 0 0 rg (C) Tj T* 0 0 0 rg (D) Tj T* (E) Tj T* (F) Tj T* (G) Tj T* (H) Tj T* (I) Tj T* (J) Tj T* (K) Tj T* (L) Tj T* (]) Tj T* (N) Tj T* ET', 'Q', 'Q']
canv.showPage()
canv.save()
示例6: addStyle
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def addStyle(self, data):
def addFont(fontfile):
if not fontfile:
return None
elif fontfile.endswith(".ttf") or fontfile.endswith(".otf"):
fontname = os.path.splitext(fontfile)[0]
pdfmetrics.registerFont(TTFont(fontname, fontfile))
print "Registered", fontfile
return fontname
else:
return fontfile
name = data.get('name', "")
s = ParagraphStyle(name)
normal = addFont(data.get('font', "Helvetica"))
bold = addFont(data.get('bold', None))
italic = addFont(data.get('italic', None))
bolditalic = addFont(data.get('bolditalic', None))
pdfmetrics.registerFontFamily(normal, normal=normal, bold=bold or normal, italic=italic or normal, boldItalic=bolditalic or normal)
s.fontName = normal
s.fontSize = data.get('size', 10)
s.alignment = dict(center=TA_CENTER, left=TA_LEFT, right=TA_RIGHT)[data.get('align', 'left')]
s.leading = data.get('leading', s.leading)
s.valign = data.get('valign', "top")
s.textColor = data.get('color', "#ff000000")
self.styles[name] = s
示例7: addPara
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def addPara(self, force=False):
# Cleanup the trail
for frag in reversed(self.fragList):
frag.text = frag.text.rstrip()
if frag.text:
break
if force or (self.text.strip() and self.fragList):
# Strip trailing whitespaces
# for f in self.fragList:
# f.text = f.text.lstrip()
# if f.text:
# break
# self.fragList[-1].lineBreak = self.fragList[-1].text.rstrip()
# Update paragraph style by style of first fragment
first = self.fragBlock
style = ParagraphStyle("default%d" % self.UID(), keepWithNext=first.keepWithNext)
style.fontName = first.fontName
style.fontSize = first.fontSize
style.leading = max(first.leading, first.fontSize * 1.25)
style.backColor = first.backColor
style.spaceBefore = first.spaceBefore
style.spaceAfter = first.spaceAfter
style.leftIndent = first.leftIndent
style.rightIndent = first.rightIndent
style.firstLineIndent = first.firstLineIndent
style.alignment = first.alignment
style.bulletFontName = first.fontName
style.bulletFontSize = first.fontSize
style.bulletIndent = first.bulletIndent
style.borderWidth = max(
first.borderLeftWidth, first.borderRightWidth, first.borderTopWidth, first.borderBottomWidth
)
style.borderPadding = first.borderPadding # + first.borderWidth
style.borderColor = first.borderTopColor
# borderRadius: None,
# print repr(self.text.strip()), style.leading, "".join([repr(x.text) for x in self.fragList])
# print first.leftIndent, first.listStyleType,repr(self.text)
# Add paragraph to story
para = PmlParagraph(
self.text, style, frags=self.fragAnchor + self.fragList, bulletText=copy.copy(first.bulletText)
)
para.outline = frag.outline
para.outlineLevel = frag.outlineLevel
para.outlineOpen = frag.outlineOpen
self.addStory(para)
self.fragAnchor = []
first.bulletText = None
self.clearFrag()
示例8: toParagraphStyle
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def toParagraphStyle(self, first):
style = ParagraphStyle('default%d' % self.UID(), keepWithNext=first.keepWithNext)
style.fontName = first.fontName
style.fontSize = first.fontSize
style.letterSpacing = first.letterSpacing
style.leading = max(first.leading + first.leadingSpace, first.fontSize * 1.25)
style.backColor = first.backColor
style.spaceBefore = first.spaceBefore
style.spaceAfter = first.spaceAfter
style.leftIndent = first.leftIndent
style.rightIndent = first.rightIndent
style.firstLineIndent = first.firstLineIndent
style.textColor = first.textColor
style.alignment = first.alignment
style.bulletFontName = first.bulletFontName or first.fontName
style.bulletFontSize = first.fontSize
style.bulletIndent = first.bulletIndent
style.wordWrap = first.wordWrap
# Border handling for Paragraph
# Transfer the styles for each side of the border, *not* the whole
# border values that reportlab supports. We'll draw them ourselves in
# PmlParagraph.
style.borderTopStyle = first.borderTopStyle
style.borderTopWidth = first.borderTopWidth
style.borderTopColor = first.borderTopColor
style.borderBottomStyle = first.borderBottomStyle
style.borderBottomWidth = first.borderBottomWidth
style.borderBottomColor = first.borderBottomColor
style.borderLeftStyle = first.borderLeftStyle
style.borderLeftWidth = first.borderLeftWidth
style.borderLeftColor = first.borderLeftColor
style.borderRightStyle = first.borderRightStyle
style.borderRightWidth = first.borderRightWidth
style.borderRightColor = first.borderRightColor
# If no border color is given, the text color is used (XXX Tables!)
if (style.borderTopColor is None) and style.borderTopWidth:
style.borderTopColor = first.textColor
if (style.borderBottomColor is None) and style.borderBottomWidth:
style.borderBottomColor = first.textColor
if (style.borderLeftColor is None) and style.borderLeftWidth:
style.borderLeftColor = first.textColor
if (style.borderRightColor is None) and style.borderRightWidth:
style.borderRightColor = first.textColor
style.borderPadding = first.borderPadding
style.paddingTop = first.paddingTop
style.paddingBottom = first.paddingBottom
style.paddingLeft = first.paddingLeft
style.paddingRight = first.paddingRight
style.fontName = tt2ps(first.fontName, first.bold, first.italic)
return style
示例9: runBuild
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def runBuild(self, str):
p = ParagraphStyle('test')
p.textColor = self.FONTCOLOR
p.borderWidth = 0
p.fontSize = self.FONTSIZE
p.fontName = self.FONTNAME
p.leading = 12 * self.FONTSIZE / 10
for line in str:
para = Paragraph("%s" % line, p)
self.story.append(para)
self.doc.build(self.story, onFirstPage=self.pageCanvas,
onLaterPages=self.pageCanvas)
示例10: _processTOCPage
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def _processTOCPage(self):
style1 = ParagraphStyle({})
style1.fontName = "Times-Bold"
style1.fontSize = modifiedFontSize(18, self._fontsize)
style1.leading = modifiedFontSize(22, self._fontsize)
style1.alignment = TA_CENTER
p = Paragraph( _("Table of contents"), style1)
self._story.append(Spacer(inch, 1*cm))
self._story.append(p)
self._story.append(Spacer(inch, 2*cm))
self._story.append(self._toc)
self._story.append(PageBreak())
示例11: drawMetadata
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def drawMetadata(self):
data = [('Artist', self.artist), ('Made', self.place), ('Date', self.date)]
data = self.artist + ", " + self.date + ", " + self.place
# self.canvas.setFont('TheSans', 12)
# self.canvas.drawString(PAGE_HEIGHT*0.635, PAGE_WIDTH*0.86, data)
parastyle = ParagraphStyle('pad')
parastyle.textColor = 'black'
parastyle.fontSize = 10
parastyle.leading = 20
parastyle.font = 'TheSans-Bold'
paragraph = Paragraph(data, parastyle)
paragraph.wrapOn(self.canvas, PAGE_HEIGHT*0.25, PAGE_WIDTH*0.1)
paragraph.drawOn(self.canvas, PAGE_HEIGHT*0.635, PAGE_WIDTH*0.84)
示例12: test2
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def test2(self):
sty = ParagraphStyle(name = 'normal')
sty.fontName = 'Times-Roman'
sty.fontSize = 10
sty.leading = 12
p = Paragraph('one two three',sty)
p.wrap(20,36)
self.assertEqual(len(p.split(20,24)),2) #widows allowed
self.assertEqual(len(p.split(20,16)),0) #orphans disallowed
p.allowWidows = 0
self.assertEqual(len(p.split(20,24)),0) #widows disallowed
p.allowOrphans = 1
self.assertEqual(len(p.split(20,16)),2) #orphans allowed
示例13: addStyle
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def addStyle(self, data):
name = data.get('name', "")
s = ParagraphStyle(name)
fontfile = data.get('font', "Helvetica")
if fontfile.endswith(".ttf") or fontfile.endswith(".otf"):
fontname = os.path.splitext(fontfile)[0]
pdfmetrics.registerFont(TTFont(fontname, fontfile))
s.fontName = fontname
else:
s.fontName = fontfile
s.fontSize = data.get('size', 10)
s.alignment = dict(center=TA_CENTER, left=TA_LEFT, right=TA_RIGHT)[data.get('align', 'left')]
s.leading = data.get('leading', s.leading)
s.valign = data.get('valign', "top")
s.textColor = data.get('color', "#ff000000")
self.styles[name] = s
示例14: drawParagraph
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def drawParagraph(text, position):
style = ParagraphStyle('test')
style.font = 'Helvetica-Bold'
font_size = 16
while font_size > 0:
style.fontSize = font_size
style.leading = font_size
para = Paragraph(text, style)
(para_width, para_height) = para.wrap(CARD_INNER_WIDTH - COLUMN_WIDTH - CARD_IMAGE_WIDTH, CARD_INNER_HEIGHT)
if para_height <= 48:
para.drawOn(p, inner_left + COLUMN_WIDTH, inner_bottom + CARD_INNER_HEIGHT * position + 8 - para_height / 2)
return
font_size -= 1
示例15: _prepareTOC
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import leading [as 别名]
def _prepareTOC(self):
headerStyle = ParagraphStyle({})
headerStyle.fontName = "LinuxLibertine-Bold"
headerStyle.fontSize = modifiedFontSize(18, 18)
headerStyle.leading = modifiedFontSize(22, 22)
headerStyle.alignment = TA_CENTER
entryStyle = ParagraphStyle({})
entryStyle.fontName = "LinuxLibertine"
entryStyle.spaceBefore = 8
self._tocStory.append(PageBreak())
if self.include_toc:
self._tocStory.append(Spacer(inch, 1*cm))
self._tocStory.append(Paragraph(_("Table of contents"), headerStyle))
self._tocStory.append(Spacer(inch, 2*cm))
for entry in self._toc:
indent = ((entry[0] - 1) * 50)
toc_entry = TableOfContentsEntry('<para leftIndent={}>{}</para>'.format(indent, entry[1]),
str(entry[2]), entryStyle)
self._tocStory.append(toc_entry)