src/reportlab/platypus/paraparser.py
changeset 3552 20ecbcc53c15
parent 3440 739ddbe7feab
child 3617 ae5744e97c42
equal deleted inserted replaced
3551:dc4aedd55fea 3552:20ecbcc53c15
   154                 'name': ('fontName', None),
   154                 'name': ('fontName', None),
   155                 'fg':   ('textColor', toColor),
   155                 'fg':   ('textColor', toColor),
   156                 'color':('textColor', toColor),
   156                 'color':('textColor', toColor),
   157                 'backcolor':('backColor',toColor),
   157                 'backcolor':('backColor',toColor),
   158                 'bgcolor':('backColor',toColor),
   158                 'bgcolor':('backColor',toColor),
       
   159                 }
       
   160 #things which are valid span attributes
       
   161 _spanAttrMap = {'size': ('fontSize', _num),
       
   162                 'face': ('fontName', None),
       
   163                 'name': ('fontName', None),
       
   164                 'fg':   ('textColor', toColor),
       
   165                 'color':('textColor', toColor),
       
   166                 'backcolor':('backColor',toColor),
       
   167                 'bgcolor':('backColor',toColor),
       
   168                 'style': ('style',None),
   159                 }
   169                 }
   160 #things which are valid font attributes
   170 #things which are valid font attributes
   161 _linkAttrMap = {'size': ('fontSize', _num),
   171 _linkAttrMap = {'size': ('fontSize', _num),
   162                 'face': ('fontName', None),
   172                 'face': ('fontName', None),
   163                 'name': ('fontName', None),
   173                 'name': ('fontName', None),
   200         n = string.lower(n)
   210         n = string.lower(n)
   201         if n not in m: m[n] = m[k]
   211         if n not in m: m[n] = m[k]
   202 
   212 
   203 _addAttributeNames(_paraAttrMap)
   213 _addAttributeNames(_paraAttrMap)
   204 _addAttributeNames(_fontAttrMap)
   214 _addAttributeNames(_fontAttrMap)
       
   215 _addAttributeNames(_spanAttrMap)
   205 _addAttributeNames(_bulletAttrMap)
   216 _addAttributeNames(_bulletAttrMap)
   206 _addAttributeNames(_anchorAttrMap)
   217 _addAttributeNames(_anchorAttrMap)
   207 _addAttributeNames(_linkAttrMap)
   218 _addAttributeNames(_linkAttrMap)
   208 
   219 
   209 def _applyAttributes(obj, attr):
   220 def _applyAttributes(obj, attr):
   513 #       < strike > < /strike > - strike through
   524 #       < strike > < /strike > - strike through
   514 #       < super > < /super > - superscript
   525 #       < super > < /super > - superscript
   515 #       < sup > < /sup > - superscript
   526 #       < sup > < /sup > - superscript
   516 #       < sub > < /sub > - subscript
   527 #       < sub > < /sub > - subscript
   517 #       <font name=fontfamily/fontname color=colorname size=float>
   528 #       <font name=fontfamily/fontname color=colorname size=float>
       
   529 #        <span name=fontfamily/fontname color=colorname backcolor=colorname size=float style=stylename>
   518 #       < bullet > </bullet> - bullet text (at head of para only)
   530 #       < bullet > </bullet> - bullet text (at head of para only)
   519 #       <onDraw name=callable label="a label"/>
   531 #       <onDraw name=callable label="a label"/>
   520 #       <index [name="callablecanvasattribute"] label="a label"/>
   532 #       <index [name="callablecanvasattribute"] label="a label"/>
   521 #       <link>link text</link>
   533 #       <link>link text</link>
   522 #           attributes of links 
   534 #           attributes of links 
   753         self._push(**self.getAttributes(attr,_fontAttrMap))
   765         self._push(**self.getAttributes(attr,_fontAttrMap))
   754 
   766 
   755     def end_font(self):
   767     def end_font(self):
   756         self._pop()
   768         self._pop()
   757 
   769 
       
   770     def start_span(self,attr):
       
   771         A = self.getAttributes(attr,_spanAttrMap)
       
   772         if 'style' in A:
       
   773             style = self.findSpanStyle(A.pop('style'))
       
   774             D = {}
       
   775             for k in 'fontName fontSize textColor backColor'.split():
       
   776                 v = getattr(style,k,self)
       
   777                 if v is self: continue
       
   778                 D[k] = v
       
   779             D.update(A)
       
   780             A = D
       
   781         self._push(**A)
       
   782 
       
   783     end_span = end_font
       
   784 
   758     def start_br(self, attr):
   785     def start_br(self, attr):
   759         #just do the trick to make sure there is no content
   786         #just do the trick to make sure there is no content
   760         self._push(_selfClosingTag='br',lineBreak=True,text='')
   787         self._push(_selfClosingTag='br',lineBreak=True,text='')
   761 
   788 
   762     def end_br(self):
   789     def end_br(self):
  1098         '''parse from tupletree form'''
  1125         '''parse from tupletree form'''
  1099         self._setup_for_parse(style)
  1126         self._setup_for_parse(style)
  1100         self._tt_handlers = self.handle_data,self._tt_parse
  1127         self._tt_handlers = self.handle_data,self._tt_parse
  1101         self._tt_parse(tt)
  1128         self._tt_parse(tt)
  1102         return self._complete_parse()
  1129         return self._complete_parse()
       
  1130 
       
  1131     def findSpanStyle(self,style):
       
  1132         raise ValueError('findSpanStyle not implemented in this parser')
  1103 
  1133 
  1104 if __name__=='__main__':
  1134 if __name__=='__main__':
  1105     from reportlab.platypus import cleanBlockQuotedText
  1135     from reportlab.platypus import cleanBlockQuotedText
  1106     from reportlab.lib.styles import _baseFontName
  1136     from reportlab.lib.styles import _baseFontName
  1107     _parser=ParaParser()
  1137     _parser=ParaParser()