~openerp/openobject-server/trunk-speedup-need_action-tde

« back to all changes in this revision

Viewing changes to bin/report/render/rml2pdf/trml2pdf.py

  • Committer: Harry (Open ERP)
  • Author(s): xrg
  • Date: 2009-11-20 14:31:04 UTC
  • mfrom: (1119.1.208)
  • mto: (1898.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1900.
  • Revision ID: hmo@tinyerp.com-20091120143104-tb6136unkdw7yfy9
[merge] merge from lp:~xrg/openobject-server/optimize-5.0 and removed some confilts

Show diffs side-by-side

added added

removed removed

Lines of Context:
163
163
                addMapping(name, 1, 0, name)    #bold
164
164
                addMapping(name, 1, 1, name)    #italic and bold
165
165
 
 
166
    def setTTFontMapping(self,face, fontname,filename, mode='all'):
 
167
        from reportlab.lib.fonts import addMapping
 
168
        from reportlab.pdfbase import pdfmetrics
 
169
        from reportlab.pdfbase.ttfonts import TTFont
 
170
        
 
171
        pdfmetrics.registerFont(TTFont(fontname, filename ))
 
172
        if (mode == 'all'):
 
173
                addMapping(face, 0, 0, fontname)    #normal
 
174
                addMapping(face, 0, 1, fontname)    #italic
 
175
                addMapping(face, 1, 0, fontname)    #bold
 
176
                addMapping(face, 1, 1, fontname)    #italic and bold
 
177
        elif (mode== 'normal') or (mode == 'regular'):
 
178
                addMapping(face, 0, 0, fontname)    #normal
 
179
        elif (mode == 'italic'):
 
180
                addMapping(face, 0, 1, fontname)    #italic
 
181
        elif (mode == 'bold'):
 
182
                addMapping(face, 1, 0, fontname)    #bold
 
183
        elif (mode == 'bolditalic'):
 
184
                addMapping(face, 1, 1, fontname)    #italic and bold
 
185
 
166
186
    def _textual_image(self, node):
167
187
        rc = ''
168
188
        for n in node.getchildren():
775
795
def parseNode(rml, localcontext = {},fout=None, images={}, path='.',title=None):
776
796
    node = etree.XML(rml)
777
797
    r = _rml_doc(node, localcontext, images, path, title=title)
 
798
    #try to override some font mappings
 
799
    try:
 
800
        from customfonts import SetCustomFonts
 
801
        SetCustomFonts(r)
 
802
    except:
 
803
        pass
778
804
    fp = cStringIO.StringIO()
779
805
    r.render(fp)
780
806
    return fp.getvalue()
782
808
def parseString(rml, localcontext = {},fout=None, images={}, path='.',title=None):
783
809
    node = etree.XML(rml)
784
810
    r = _rml_doc(node, localcontext, images, path, title=title)
 
811
 
 
812
    #try to override some font mappings
 
813
    try:
 
814
        from customfonts import SetCustomFonts
 
815
        SetCustomFonts(r)
 
816
    except:
 
817
        pass
 
818
 
785
819
    if fout:
786
820
        fp = file(fout,'wb')
787
821
        r.render(fp)