[FIX] reporting: change the way that para style are computed

- we now compute generic style (i.e. inside <styles/> tag) only once
    at the begenning of the report.
  - for each <para/> tag we encounter, we first try use generic style, and
    we only make a deepcopy() of the style structre, in the case there is
    some style customization directly on the tag

bzr revid: jvo@tinyerp.com-20100514131355-mdv7jpsapib7edm9
This commit is contained in:
Xavier ALT 2010-05-14 18:43:55 +05:30 committed by Jay (Open ERP)
parent 2f0ff7766a
commit 1bfd4b60d0
1 changed files with 18 additions and 9 deletions

View File

@ -52,13 +52,20 @@ class _rml_styles(object,):
def __init__(self, nodes, localcontext):
self.localcontext = localcontext
self.styles = {}
self.styles_obj = {}
self.names = {}
self.table_styles = {}
self.default_style = reportlab.lib.styles.getSampleStyleSheet()
for node in nodes:
for style in node.findall('blockTableStyle'):
self.table_styles[style.get('id')] = self._table_style_get(style)
for style in node.findall('paraStyle'):
self.styles[style.get('name')] = self._para_style_update(style)
sname = style.get('name')
self.styles[sname] = self._para_style_update(style)
self.styles_obj[sname] = reportlab.lib.styles.ParagraphStyle(sname, self.default_style["Normal"], **self.styles[sname])
for variable in node.findall('initialize'):
for name in variable.findall('name'):
self.names[ name.get('id')] = name.get('value')
@ -126,17 +133,19 @@ class _rml_styles(object,):
def para_style_get(self, node):
style = False
if node.get('style'):
if node.get('style') in self.styles:
styles = reportlab.lib.styles.getSampleStyleSheet()
sname = node.get('style')
style = reportlab.lib.styles.ParagraphStyle(sname, styles["Normal"], **self.styles[sname])
sname = node.get('style')
if sname:
if sname in self.styles_obj:
style = self.styles_obj[sname]
else:
sys.stderr.write('Warning: style not found, %s - setting default!\n' % (node.get('style'),) )
if not style:
styles = reportlab.lib.styles.getSampleStyleSheet()
style = styles['Normal']
style.__dict__.update(self._para_style_update(node))
style = self.default_style['Normal']
para_update = self._para_style_update(node)
if para_update:
# update style only is necessary
style = copy.deepcopy(style)
style.__dict__.update(para_update)
return style
class _rml_doc(object):