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 from lxml import etree
46 _regex = re.compile('\[\[(.+?)\]\]')
49 return s.replace('&', '&').replace('<', '<').replace('>', '>')
52 return s.replace('&','&').replace('<','<').replace('>','>')
54 def _child_get(node, self=None, tagname=None):
56 if self and self.localcontext and n.get('rml_loop', False):
57 oldctx = self.localcontext
59 for ctx in eval(n.get('rml_loop'),{}, self.localcontext):
60 self.localcontext.update(ctx)
61 if (tagname is None) or (n.tag==tagname):
62 if n.get('rml_except', False):
64 eval(n.get('rml_except'), {}, self.localcontext)
69 (tag,attr) = eval(n.get('rml_tag'),{}, self.localcontext)
72 n2.attrib.update(attr)
78 self.localcontext = oldctx
80 if self and self.localcontext and n.get('rml_except', False):
82 eval(n.get('rml_except'), {}, self.localcontext)
85 if self and self.localcontext and n.get('rml_tag', False):
87 (tag,attr) = eval(n.get('rml_tag'),{}, self.localcontext)
90 n2.attrib.update(attr or {})
95 if (tagname is None) or (n.tag==tagname):
98 def _process_text(self, txt):
99 if not self.localcontext:
104 sps = _regex.split(txt)
106 # This is a simple text to translate
107 result += self.localcontext.get('translate', lambda x:x)(sps.pop(0))
110 txt = eval(sps.pop(0),self.localcontext)
113 if type(txt)==type('') or type(txt)==type(u''):
115 result += tools.ustr(txt2)
116 elif (txt is not None) and (txt is not False):
122 for node in node.getchildren():
123 rc = rc + tools.ustr(node.text)
127 (re.compile('^(-?[0-9\.]+)\s*in$'), reportlab.lib.units.inch),
128 (re.compile('^(-?[0-9\.]+)\s*cm$'), reportlab.lib.units.cm),
129 (re.compile('^(-?[0-9\.]+)\s*mm$'), reportlab.lib.units.mm),
130 (re.compile('^(-?[0-9\.]+)\s*$'), 1)
137 res = unit[0].search(size, 0)
139 return unit[1]*float(res.group(1))
142 def tuple_int_get(node, attr_name, default=None):
143 if not node.get(attr_name):
145 res = [int(x) for x in node.get(attr_name).split(',')]
149 return (str(value)=="1") or (value.lower()=='yes')
151 def attr_get(node, attrs, dict={}):
155 res[name] = unit_get(node.get(name))
159 res[key] = str(node.get(key))
160 elif dict[key]=='bool':
161 res[key] = bool_get(node.get(key))
162 elif dict[key]=='int':
163 res[key] = int(node.get(key))
164 elif dict[key]=='unit':
165 res[key] = unit_get(node.get(key))
166 elif dict[key] == 'float' :
167 res[key] = float(node.get(key))
170 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: