1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 # trml2pdf - An RML to PDF converter
24 # Copyright (C) 2003, Fabien Pinckaers, UCL, FSA
26 # This library is free software; you can redistribute it and/or
27 # modify it under the terms of the GNU Lesser General Public
28 # License as published by the Free Software Foundation; either
29 # version 2.1 of the License, or (at your option) any later version.
31 # This library is distributed in the hope that it will be useful,
32 # but WITHOUT ANY WARRANTY; without even the implied warranty of
33 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 # Lesser General Public License for more details.
36 # You should have received a copy of the GNU Lesser General Public
37 # License along with this library; if not, write to the Free Software
38 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 import reportlab.lib.units
43 from lxml import etree
45 _regex = re.compile('\[\[(.+?)\]\]')
47 def _child_get(node, self=None, tagname=None):
49 if self and self.localcontext and n.get('rml_loop', False):
50 oldctx = self.localcontext
51 for ctx in eval(n.get('rml_loop'),{}, self.localcontext):
52 self.localcontext.update(ctx)
53 if (tagname is None) or (n.tag==tagname):
54 if n.get('rml_except', False):
56 eval(n.get('rml_except'), {}, self.localcontext)
61 (tag,attr) = eval(n.get('rml_tag'),{}, self.localcontext)
64 n2.attrib.update(attr)
70 self.localcontext = oldctx
72 if self and self.localcontext and n.get('rml_except', False):
74 eval(n.get('rml_except'), {}, self.localcontext)
77 if (tagname is None) or (n.tag==tagname):
80 def _process_text(self, txt):
81 if not self.localcontext:
86 sps = _regex.split(txt)
88 # This is a simple text to translate
89 result += self.localcontext.get('translate', lambda x:x)(sps.pop(0))
92 txt2 = eval(sps.pop(0),self.localcontext)
95 if type(txt2) == type(0) or type(txt2) == type(0.0):
97 if type(txt2)==type('') or type(txt2)==type(u''):
103 for node in node.getchildren():
108 (re.compile('^(-?[0-9\.]+)\s*in$'), reportlab.lib.units.inch),
109 (re.compile('^(-?[0-9\.]+)\s*cm$'), reportlab.lib.units.cm),
110 (re.compile('^(-?[0-9\.]+)\s*mm$'), reportlab.lib.units.mm),
111 (re.compile('^(-?[0-9\.]+)\s*$'), 1)
118 res = unit[0].search(size, 0)
120 return unit[1]*float(res.group(1))
123 def tuple_int_get(node, attr_name, default=None):
124 if not node.get(attr_name):
126 res = [int(x) for x in node.get(attr_name).split(',')]
130 return (str(value)=="1") or (value.lower()=='yes')
132 def attr_get(node, attrs, dict={}):
136 res[name] = unit_get(node.get(name))
140 res[key] = str(node.get(key))
141 elif dict[key]=='bool':
142 res[key] = bool_get(node.get(key))
143 elif dict[key]=='int':
144 res[key] = int(node.get(key))
145 elif dict[key]=='unit':
146 res[key] = unit_get(node.get(key))
149 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: