[FIX]l10n_ch: remove font's hack, register the font into the main engine.
authorP. Christeas <p_christ@hol.gr>
Wed, 29 Sep 2010 13:46:11 +0000 (19:16 +0530)
committerHarry (OpenERP) <hmo@tinyerp.com>
Wed, 29 Sep 2010 13:46:11 +0000 (19:16 +0530)
For some reason, reportlab still fails to embed the font into the PDF.
Please fix that.

bzr revid: hmo@tinyerp.com-20100929134611-rx5b9wwp5w3aq7eh

addons/l10n_ch/__openerp__.py
addons/l10n_ch/report/bvr_invoice_report.rml
addons/l10n_ch/report/bvr_report.py
addons/l10n_ch/report/bvr_report.rml

index a9315ab..bca3c7e 100644 (file)
@@ -66,7 +66,7 @@ TODO :
 
 
 """,
-    "version" : "5.0",
+    "version" : "5.1",
     "author" : "Camptocamp SA",
     "category" : "Localisation/Europe",
     "website": "http://www.camptocamp.com",
index e00c061..46798ae 100755 (executable)
@@ -1,8 +1,6 @@
 <?xml version="1.0"?>
 <document filename="test.pdf">
   <docinit>
-     <registerFont fontFile="/tmp/ocrbb.ttf"  expr="{'fontFile':str(police_absolute_path('addons/l10n_ch/report/ocrbb.ttf'))}"  fontName="ocrb"   />
-
   </docinit>
 
   <template pageSize="(210.0mm,297.0mm)" title="Invoices BVR" author="OpenERP S.A. (sales@openerp.com)" allowSplitting="20">
index e0c7ca6..d90d4db 100644 (file)
@@ -39,12 +39,28 @@ from datetime import datetime
 
 from report import report_sxw
 from tools import mod10r
+import logging
+log = logging.getLogger('init')
+
+try:
+    this_module = 'l10n_ch'
+    from report.render.rml2pdf import customfonts
+    from addons import get_module_resource
+    ocrb_fname = get_module_resource(this_module, 'report', 'ocrbb.ttf')
+    if not ocrb_fname:
+        raise OSError("Cannot find ocrbb.ttf in %s resources", this_module)
+    customfonts.CustomTTFonts.append( ('ocrb', 'ocrb', ocrb_fname , None ) )
+    log.debug("module: %s registered custom OCR-B font at %s", this_module, ocrb_fname)
+except ImportError:
+    log.debug("Import error", exc_info=True)
+    pass
+except Exception, e:
+    log.exception("Cannot register custom font")
 
 class account_invoice_bvr(report_sxw.rml_parse):
     """Report class that Allows to print BVR payement vector"""
     def __init__(self, cr, uid, name, context):
         super(account_invoice_bvr, self).__init__(cr, uid, name, context)
-        self.copyocrbfile('addons/l10n_ch/report/ocrbb.ttf')
         self.localcontext.update({
             'time': time,
             'user':self.pool.get("res.users").browse(cr,uid,uid),
@@ -53,8 +69,6 @@ class account_invoice_bvr(report_sxw.rml_parse):
             '_get_ref': self._get_ref,
             'comma_me': self.comma_me,
             'format_date': self._get_and_change_date_format_for_swiss,
-            'police_absolute_path' : self.police_absolute_path,
-            'copyocrbfile': self.copyocrbfile
         })
     def _get_and_change_date_format_for_swiss (self,date_to_format):
         date_formatted=''
@@ -63,23 +77,6 @@ class account_invoice_bvr(report_sxw.rml_parse):
             date_formatted = strptime(date_to_format,'%Y-%m-%d').strftime('%d.%m.%Y')
         return date_formatted
 
-    def police_absolute_path(self, inner_path) :
-        path = os.path.join(os.path.dirname(sys.argv[0]), inner_path)
-        return  path
-
-    def copyocrbfile(self,file):
-        src = self.police_absolute_path(file)
-        file = os.path.basename(src)
-        dest = os.path.join('/tmp/',file)
-        if not os.path.isfile(dest):
-            try:
-                shutil.copyfile(src,dest)
-            except:
-                """print ocrbfile was not copy in /tmp/ please
-                copy it manually from l10_ch/report"""
-
-
-
     def comma_me(self,amount):
         if  type(amount) is float :
             amount = str('%.2f'%amount)
index 838f295..c20e337 100755 (executable)
@@ -1,7 +1,6 @@
 <?xml version="1.0"?>
 <document filename="test.pdf">
   <docinit>
-    <registerFont fontFile="/tmp/ocrbb.ttf"  expr="{'fontFile':str(police_absolute_path('addons/l10n_ch/report/ocrbb.ttf'))}"  fontName="ocrb"   />
   </docinit>
   <template pageSize="(210.0mm,297.0mm)" title="BVR" author="OpenERP S.A. (sales@openerp.com)" allowSplitting="20">
     <pageTemplate id="first">