~openerp-dev/openobject-server/trunk-imp-onchange-behave-darshan

« back to all changes in this revision

Viewing changes to openerp/addons/base/res/res_font.py

  • Committer: Darshan Kalola(OpenERP)
  • Date: 2014-04-09 08:44:52 UTC
  • mfrom: (4936.1.232 openobject-server)
  • Revision ID: dka@tinyerp.com-20140409084452-w1e499j21i3eli9d
[MERGE]sync with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
"""
38
38
_logger = logging.getLogger(__name__)
39
39
 
 
40
# Alternatives for the [broken] builtin PDF fonts. Default order chosen to match
 
41
# the pre-v8 mapping from openerp.report.render.rml2pdf.customfonts.CustomTTFonts.
 
42
# Format: [ (BuiltinFontFamily, mode, [AlternativeFontName, ...]), ...]
 
43
BUILTIN_ALTERNATIVES = [
 
44
    ('Helvetica', "normal", ["DejaVuSans", "LiberationSans"]),
 
45
    ('Helvetica', "bold", ["DejaVuSans-Bold", "LiberationSans-Bold"]),
 
46
    ('Helvetica', 'italic', ["DejaVuSans-Oblique", "LiberationSans-Italic"]),
 
47
    ('Helvetica', 'bolditalic', ["DejaVuSans-BoldOblique", "LiberationSans-BoldItalic"]),
 
48
    ('Times', 'normal', ["LiberationSerif", "DejaVuSerif"]),
 
49
    ('Times', 'bold', ["LiberationSerif-Bold", "DejaVuSerif-Bold"]),
 
50
    ('Times', 'italic', ["LiberationSerif-Italic", "DejaVuSerif-Italic"]),
 
51
    ('Times', 'bolditalic', ["LiberationSerif-BoldItalic", "DejaVuSerif-BoldItalic"]),
 
52
    ('Courier', 'normal', ["FreeMono", "DejaVuSansMono"]),
 
53
    ('Courier', 'bold', ["FreeMonoBold", "DejaVuSansMono-Bold"]),
 
54
    ('Courier', 'italic', ["FreeMonoOblique", "DejaVuSansMono-Oblique"]),
 
55
    ('Courier', 'bolditalic', ["FreeMonoBoldOblique", "DejaVuSansMono-BoldOblique"]),
 
56
]
40
57
 
41
58
class res_font(osv.Model):
42
59
    _name = "res.font"
113
130
    def _sync(self, cr, uid, context=None):
114
131
        """Set the customfonts.CustomTTFonts list to the content of the database"""
115
132
        customfonts.CustomTTFonts = []
 
133
        local_family_modes = set()
 
134
        local_font_paths = {}
116
135
        found_fonts_ids = self.search(cr, uid, [('path', '!=', '/dev/null')], context=context)
117
136
        for font in self.browse(cr, uid, found_fonts_ids, context=None):
 
137
            local_family_modes.add((font.family, font.mode))
 
138
            local_font_paths[font.name] = font.path
118
139
            customfonts.CustomTTFonts.append((font.family, font.name, font.path, font.mode))
 
140
 
 
141
        # Attempt to remap the builtin fonts (Helvetica, Times, Courier) to better alternatives
 
142
        # if available, because they only support a very small subset of unicode
 
143
        # (missing 'č' for example)
 
144
        for builtin_font_family, mode, alts in BUILTIN_ALTERNATIVES:
 
145
            if (builtin_font_family, mode) not in local_family_modes:
 
146
                # No local font exists with that name, try alternatives
 
147
                for altern_font in alts:
 
148
                    if local_font_paths.get(altern_font):
 
149
                        altern_def = (builtin_font_family, altern_font,
 
150
                                      local_font_paths[altern_font], mode)
 
151
                        customfonts.CustomTTFonts.append(altern_def)
 
152
                        _logger.debug("Builtin remapping %r", altern_def)
 
153
                        break
 
154
                else:
 
155
                    _logger.warning("No local alternative found for builtin font `%s` (%s mode)." 
 
156
                                    "Consider installing the DejaVu fonts if you have problems "
 
157
                                    "with unicode characters in RML reports",
 
158
                                    builtin_font_family, mode)
119
159
        return True
120
160
 
121
161
    def clear_caches(self):