[MERGE] forward port of branch 7.0 up to 3a0af6a
[odoo/odoo.git] / openerp / report / render / rml2pdf / trml2pdf.py
index 3b36c3e..dab7ee5 100644 (file)
@@ -56,8 +56,11 @@ def select_fontname(fontname, default_fontname):
         try:
             pdfmetrics.getFont(fontname)
         except Exception:
-            _logger.warning('Could not locate font %s, substituting default: %s',
-                fontname, default_fontname)
+            addition = ""
+            if " " in fontname:
+                addition = ". Your font contains spaces which is not valid in RML."
+            _logger.warning('Could not locate font %s, substituting default: %s%s',
+                fontname, default_fontname, addition)
             fontname = default_fontname
     return fontname
 
@@ -281,6 +284,9 @@ class _rml_doc(object):
         from reportlab.pdfbase import pdfmetrics
         from reportlab.pdfbase.ttfonts import TTFont
 
+        if mode:
+            mode = mode.lower()
+
         if fontname not in pdfmetrics._fonts:
             pdfmetrics.registerFont(TTFont(fontname, filename))
         if mode == 'all':
@@ -288,14 +294,14 @@ class _rml_doc(object):
             addMapping(face, 0, 1, fontname)    #italic
             addMapping(face, 1, 0, fontname)    #bold
             addMapping(face, 1, 1, fontname)    #italic and bold
-        elif (mode== 'normal') or (mode == 'regular'):
-            addMapping(face, 0, 0, fontname)    #normal
-        elif mode == 'italic':
+        elif mode in ['italic', 'oblique']:
             addMapping(face, 0, 1, fontname)    #italic
         elif mode == 'bold':
             addMapping(face, 1, 0, fontname)    #bold
-        elif mode == 'bolditalic':
+        elif mode in ('bolditalic', 'bold italic','boldoblique', 'bold oblique'):
             addMapping(face, 1, 1, fontname)    #italic and bold
+        else:
+            addMapping(face, 0, 0, fontname)    #normal
 
     def _textual_image(self, node):
         rc = ''
@@ -376,9 +382,9 @@ class _rml_canvas(object):
         text = utils.xml2str(text)
         try:
             self.canvas.drawString(text=text, **v)
-        except TypeError as e:
+        except TypeError:
             _logger.error("Bad RML: <drawString> tag requires attributes 'x' and 'y'!")
-            raise e
+            raise
 
     def _drawCenteredString(self, node):
         v = utils.attr_get(node, ['x','y'])