Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pisa_tag_will_set_attrs_on_init(self):
dom = minidom.parseString("test")
element = dom.getElementsByTagName("unit")[0]
attrs = AttrContainer({})
instance = tags.pisaTag(element, attrs)
self.assertEqual(instance.node, element)
self.assertEqual(instance.tag, "unit")
self.assertEqual(instance.attr, {})
class pisaTagPDFPAGECOUNT(pisaTag):
"""
"""
def start(self, c):
c.frag.pageCount = True
c.addFrag()
c.frag.pageCount = False
def end(self, c):
c.addPageCount()
class pisaTagPDFTOC(pisaTag):
"""
"""
def end(self, c):
c.multiBuild = True
c.addTOC()
class pisaTagPDFFRAME(pisaTag):
"""
"""
def start(self, c):
deprecation("pdf:frame")
pass
class pisaTagBODY(pisaTag):
"""
We can also asume that there is a BODY tag because html5lib
adds it for us. Here we take the base font size for later calculations
in the FONT tag.
"""
def start(self, c):
c.baseFontSize = c.frag.fontSize
# print("base font size", c.baseFontSize)
class pisaTagTITLE(pisaTag):
def end(self, c):
c.meta["title"] = c.text
c.clearFrag()
class pisaTagSTYLE(pisaTag):
def start(self, c):
c.addPara()
def end(self, c):
c.clearFrag()
class pisaTagMETA(pisaTag):
def start(self, c):
else:
if type(lst) == type(u""):
frag.text = lst
else:
# XXX This should be the recent font, but it throws errors in Reportlab!
frag.text = lst(c)
# XXX This should usually be done in the context!!!
frag.fontName = frag.bulletFontName = tt2ps(frag.fontName, frag.bold, frag.italic)
c.frag.bulletText = [frag]
def end(self, c):
c.fragBlock.spaceBefore += self.offset
class pisaTagBR(pisaTag):
def start(self, c):
c.frag.lineBreak = 1
c.addFrag()
c.fragStrip = True
del c.frag.lineBreak
c.force = True
class pisaTagIMG(pisaTag):
def start(self, c):
attr = self.attr
if attr.src and (not attr.src.notFound()):
try:
align = attr.align or c.frag.vAlign or "baseline"
width = c.frag.width
tdata = c.tableData
row = tdata.row
begin = (0, row)
end = (-1, row)
tdata.add_cell_styles(c, begin, end, "tr")
c.frag.vAlign = self.attr.valign or c.frag.vAlign
tdata.col = 0
tdata.data.append([])
def end(self, c):
c.tableData.row += 1
class pisaTagTD(pisaTag):
def start(self, c):
if self.attr.align is not None:
c.frag.alignment = getAlign(self.attr.align)
c.clearFrag()
self.story = c.swapStory()
attrs = self.attr
tdata = c.tableData
cspan = attrs.colspan
rspan = attrs.rowspan
The default class for a tag definition
"""
def __init__(self, node, attr):
self.node = node
self.tag = node.tagName
self.attr = attr
def start(self, c):
pass
def end(self, c):
pass
class pisaTagBODY(pisaTag):
"""
We can also asume that there is a BODY tag because html5lib
adds it for us. Here we take the base font size for later calculations
in the FONT tag.
"""
def start(self, c):
c.baseFontSize = c.frag.fontSize
# print("base font size", c.baseFontSize)
class pisaTagTITLE(pisaTag):
def end(self, c):
c.meta["title"] = c.text
c.clearFrag()
class pisaTagPDFNEXTPAGE(pisaTag):
"""
"""
def start(self, c):
# deprecation("pdf:nextpage")
c.addPara()
if self.attr.name:
c.addStory(NextPageTemplate(self.attr.name))
c.addStory(PageBreak())
class pisaTagPDFNEXTTEMPLATE(pisaTag):
"""
"""
def start(self, c):
# deprecation("pdf:frame")
c.addStory(NextPageTemplate(self.attr["name"]))
class pisaTagPDFNEXTFRAME(pisaTag):
"""
"""
def start(self, c):
c.addPara()
afrag.bold = 0
afrag.italic = 0
afrag.cbDefn = ABag(
kind="anchor",
name=attr.name,
label="anchor")
c.fragAnchor.append(afrag)
c.anchorName.append(attr.name)
if attr.href and self.rxLink.match(attr.href):
c.frag.link = attr.href
def end(self, c):
pass
class pisaTagFONT(pisaTag):
# Source: http://www.w3.org/TR/CSS21/fonts.html#propdef-font-size
def start(self, c):
if self.attr["color"] is not None:
c.frag.textColor = getColor(self.attr["color"])
if self.attr["face"] is not None:
c.frag.fontName = c.getFontName(self.attr["face"])
if self.attr["size"] is not None:
size = getSize(self.attr["size"], c.frag.fontSize, c.baseFontSize)
c.frag.fontSize = max(size, 1.0)
def end(self, c):
pass
class pisaTagP(pisaTag):
class pisaTagSELECT(pisaTagINPUT):
def start(self, c):
c.select_options = ["One", "Two", "Three"]
def _render(self, c, attr):
c.addStory(xhtml2pdf_reportlab.PmlInput(attr.name,
type="select",
default=c.select_options[0],
options=c.select_options,
width=100,
height=40))
c.select_options = None
class pisaTagOPTION(pisaTag):
pass
class pisaTagPDFNEXTPAGE(pisaTag):
"""
"""
def start(self, c):
# deprecation("pdf:nextpage")
c.addPara()
if self.attr.name:
c.addStory(NextPageTemplate(self.attr.name))
c.addStory(PageBreak())
def start(self, c):
c.addPara()
def end(self, c):
c.clearFrag()
class pisaTagMETA(pisaTag):
def start(self, c):
name = self.attr.name.lower()
if name in ("author", "subject", "keywords"):
c.meta[name] = self.attr.content
class pisaTagSUP(pisaTag):
def start(self, c):
c.frag.super = 1
class pisaTagSUB(pisaTag):
def start(self, c):
c.frag.sub = 1
class pisaTagA(pisaTag):
rxLink = re.compile("^(#|[a-z]+\:).*")
def start(self, c):
attr = self.attr
# XXX Also support attr.id ?