src/reportlab/platypus/para.py
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3781 df8b57380768
equal deleted inserted replaced
3722:29c11b905751 3723:99aa837b6703
   986     backColor=None
   986     backColor=None
   987 
   987 
   988     def __init__(self, name, parent=None, **kw):
   988     def __init__(self, name, parent=None, **kw):
   989         mydict = self.__dict__
   989         mydict = self.__dict__
   990         if parent:
   990         if parent:
   991             for (a,b) in list(parent.__dict__.items()):
   991             for a,b in parent.__dict__.items():
   992                 mydict[a]=b
   992                 mydict[a]=b
   993         for (a,b) in list(kw.items()):
   993         for a,b in kw.items():
   994             mydict[a] =  b
   994             mydict[a] =  b
   995 
   995 
   996     def addAttributes(self, dictionary):
   996     def addAttributes(self, dictionary):
   997         for key in list(dictionary.keys()):
   997         for key in dictionary.keys():
   998             value = dictionary[key]
   998             value = dictionary[key]
   999             if value is not None:
   999             if value is not None:
  1000                 if hasattr(StyleAttributeConverters, key):
  1000                 if hasattr(StyleAttributeConverters, key):
  1001                     converter = getattr(StyleAttributeConverters, key)[0]
  1001                     converter = getattr(StyleAttributeConverters, key)[0]
  1002                     value = converter(value)
  1002                     value = converter(value)
  1184 
  1184 
  1185 def defaultContext():
  1185 def defaultContext():
  1186     result = {}
  1186     result = {}
  1187     from reportlab.lib.styles import getSampleStyleSheet
  1187     from reportlab.lib.styles import getSampleStyleSheet
  1188     styles = getSampleStyleSheet()
  1188     styles = getSampleStyleSheet()
  1189     for (stylenamekey, stylenamevalue) in list(DEFAULT_ALIASES.items()):
  1189     for stylenamekey, stylenamevalue in DEFAULT_ALIASES.items():
  1190         result[stylenamekey] = styles[stylenamevalue]
  1190         result[stylenamekey] = styles[stylenamevalue]
  1191     return result
  1191     return result
  1192 
  1192 
  1193 def buildContext(stylesheet=None):
  1193 def buildContext(stylesheet=None):
  1194     result = {}
  1194     result = {}
  1195     from reportlab.lib.styles import getSampleStyleSheet
  1195     from reportlab.lib.styles import getSampleStyleSheet
  1196     if stylesheet is not None:
  1196     if stylesheet is not None:
  1197         # Copy styles with the same name as aliases
  1197         # Copy styles with the same name as aliases
  1198         for (stylenamekey, stylenamevalue) in list(DEFAULT_ALIASES.items()):
  1198         for stylenamekey, stylenamevalue in DEFAULT_ALIASES.items():
  1199             if stylenamekey in stylesheet:
  1199             if stylenamekey in stylesheet:
  1200                 result[stylenamekey] = stylesheet[stylenamekey]
  1200                 result[stylenamekey] = stylesheet[stylenamekey]
  1201         # Then make aliases
  1201         # Then make aliases
  1202         for (stylenamekey, stylenamevalue) in list(DEFAULT_ALIASES.items()):
  1202         for stylenamekey, stylenamevalue in DEFAULT_ALIASES.items():
  1203             if stylenamevalue in stylesheet:
  1203             if stylenamevalue in stylesheet:
  1204                 result[stylenamekey] = stylesheet[stylenamevalue]
  1204                 result[stylenamekey] = stylesheet[stylenamevalue]
  1205 
  1205 
  1206     styles = getSampleStyleSheet()
  1206     styles = getSampleStyleSheet()
  1207     # Then, fill in defaults if they were not filled yet.
  1207     # Then, fill in defaults if they were not filled yet.
  1208     for (stylenamekey, stylenamevalue) in list(DEFAULT_ALIASES.items()):
  1208     for stylenamekey, stylenamevalue in DEFAULT_ALIASES.items():
  1209         if stylenamekey not in result and stylenamevalue in styles:
  1209         if stylenamekey not in result and stylenamevalue in styles:
  1210             result[stylenamekey] = styles[stylenamevalue]
  1210             result[stylenamekey] = styles[stylenamevalue]
  1211     return result
  1211     return result
  1212 
  1212 
  1213 class Para(Flowable):
  1213 class Para(Flowable):
  1488                 # just pass the tag through
  1488                 # just pass the tag through
  1489                 if debug:
  1489                 if debug:
  1490                     L = [ "<" + tagname ]
  1490                     L = [ "<" + tagname ]
  1491                     a = L.append
  1491                     a = L.append
  1492                     if not attdict: attdict = {}
  1492                     if not attdict: attdict = {}
  1493                     for (k, v) in list(attdict.items()):
  1493                     for k, v in attdict.items():
  1494                         a(" %s=%s" % (k,v))
  1494                         a(" %s=%s" % (k,v))
  1495                     if content:
  1495                     if content:
  1496                         a(">")
  1496                         a(">")
  1497                         a(str(content))
  1497                         a(str(content))
  1498                         a("</%s>" % tagname)
  1498                         a("</%s>" % tagname)
  1913 
  1913 
  1914 class SeqResetObject(NameObject):
  1914 class SeqResetObject(NameObject):
  1915 
  1915 
  1916     def getOp(self, tuple, engine):
  1916     def getOp(self, tuple, engine):
  1917         from reportlab.lib.sequencer import getSequencer
  1917         from reportlab.lib.sequencer import getSequencer
  1918         import math
       
  1919         globalsequencer = getSequencer()
  1918         globalsequencer = getSequencer()
  1920         attr = self.attdict
  1919         attr = self.attdict
  1921         try:
  1920         try:
  1922             id = attr['id']
  1921             id = attr['id']
  1923         except KeyError:
  1922         except KeyError:
  1924             id = None
  1923             id = None
  1925         try:
  1924         try:
  1926             base = math.atoi(attr['base'])
  1925             base = int(attr['base'])
  1927         except:
  1926         except:
  1928             base=0
  1927             base=0
  1929         globalsequencer.reset(id, base)
  1928         globalsequencer.reset(id, base)
  1930         self.op = ""
  1929         self.op = ""
  1931         return ""
  1930         return ""
  1992     Controller["h3"] = theParaMapper
  1991     Controller["h3"] = theParaMapper
  1993     Controller["title"] = theParaMapper
  1992     Controller["title"] = theParaMapper
  1994 
  1993 
  1995 def handleSpecialCharacters(engine, text, program=None):
  1994 def handleSpecialCharacters(engine, text, program=None):
  1996     from .paraparser import greeks
  1995     from .paraparser import greeks
  1997     from string import whitespace, atoi, atoi_error
  1996     from string import whitespace
  1998     standard={'lt':'<', 'gt':'>', 'amp':'&'}
  1997     standard={'lt':'<', 'gt':'>', 'amp':'&'}
  1999     # add space prefix if space here
  1998     # add space prefix if space here
  2000     if text[0:1] in whitespace:
  1999     if text[0:1] in whitespace:
  2001         program.append(" ")
  2000         program.append(" ")
  2002     #print "handling", repr(text)
  2001     #print "handling", repr(text)
  2023             if semi>0:
  2022             if semi>0:
  2024                 name = fragment[:semi]
  2023                 name = fragment[:semi]
  2025                 if name[0]=='#':
  2024                 if name[0]=='#':
  2026                     try:
  2025                     try:
  2027                         if name[1] == 'x':
  2026                         if name[1] == 'x':
  2028                             n = atoi(name[2:], 16)
  2027                             n = int(name[2:], 16)
  2029                         else:
  2028                         else:
  2030                             n = atoi(name[1:])
  2029                             n = int(name[1:])
  2031                     except atoi_error:
  2030                     except ValueError:
  2032                         n = -1
  2031                         n = -1
  2033                     if n>=0:
  2032                     if n>=0:
  2034                         fragment = chr(n).encode('utf8')+fragment[semi+1:]
  2033                         fragment = chr(n).encode('utf8')+fragment[semi+1:]
  2035                     else:
  2034                     else:
  2036                         fragment = "&"+fragment
  2035                         fragment = "&"+fragment