Skip to content

Commit

Permalink
paraparser.py add support for <span style=stylename>
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.reportlab.com/svn/public/reportlab/trunk@3892 636e621b-80dc-0310-9e7d-ef5f34d1b73f
  • Loading branch information
rgbecker committed Nov 22, 2011
1 parent 902e232 commit a259e6f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/reportlab/platypus/paragraph.py
Expand Up @@ -834,6 +834,7 @@ class Paragraph(Flowable):
<super> ... </super> - superscript
<sub> ... </sub> - subscript
<font name=fontfamily/fontname color=colorname size=float>
<span name=fontfamily/fontname color=colorname backcolor=colorname size=float style=stylename>
<onDraw name=callable label="a label"/>
<index [name="callablecanvasattribute"] label="a label"/>
<link>link text</link>
Expand Down
30 changes: 30 additions & 0 deletions src/reportlab/platypus/paraparser.py
Expand Up @@ -157,6 +157,16 @@ def _align(s):
'backcolor':('backColor',toColor),
'bgcolor':('backColor',toColor),
}
#things which are valid span attributes
_spanAttrMap = {'size': ('fontSize', _num),
'face': ('fontName', None),
'name': ('fontName', None),
'fg': ('textColor', toColor),
'color':('textColor', toColor),
'backcolor':('backColor',toColor),
'bgcolor':('backColor',toColor),
'style': ('style',None),
}
#things which are valid font attributes
_linkAttrMap = {'size': ('fontSize', _num),
'face': ('fontName', None),
Expand Down Expand Up @@ -202,6 +212,7 @@ def _addAttributeNames(m):

_addAttributeNames(_paraAttrMap)
_addAttributeNames(_fontAttrMap)
_addAttributeNames(_spanAttrMap)
_addAttributeNames(_bulletAttrMap)
_addAttributeNames(_anchorAttrMap)
_addAttributeNames(_linkAttrMap)
Expand Down Expand Up @@ -515,6 +526,7 @@ def _greekConvert(data):
# < sup > < /sup > - superscript
# < sub > < /sub > - subscript
# <font name=fontfamily/fontname color=colorname size=float>
# <span name=fontfamily/fontname color=colorname backcolor=colorname size=float style=stylename>
# < bullet > </bullet> - bullet text (at head of para only)
# <onDraw name=callable label="a label"/>
# <index [name="callablecanvasattribute"] label="a label"/>
Expand Down Expand Up @@ -755,6 +767,21 @@ def start_font(self,attr):
def end_font(self):
self._pop()

def start_span(self,attr):
A = self.getAttributes(attr,_spanAttrMap)
if 'style' in A:
style = self.findSpanStyle(A.pop('style'))
D = {}
for k in 'fontName fontSize textColor backColor'.split():
v = getattr(style,k,self)
if v is self: continue
D[k] = v
D.update(A)
A = D
self._push(**A)

end_span = end_font

def start_br(self, attr):
#just do the trick to make sure there is no content
self._push(_selfClosingTag='br',lineBreak=True,text='')
Expand Down Expand Up @@ -1101,6 +1128,9 @@ def tt_parse(self,tt,style):
self._tt_parse(tt)
return self._complete_parse()

def findSpanStyle(self,style):
raise ValueError('findSpanStyle not implemented in this parser')

if __name__=='__main__':
from reportlab.platypus import cleanBlockQuotedText
from reportlab.lib.styles import _baseFontName
Expand Down

0 comments on commit a259e6f

Please sign in to comment.