Update of /cvsroot/pythonreports/PythonReports/PythonReports
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv8666/PythonReports
Modified Files:
fonts.py
Log Message:
try to load windows fonts once when a font is missing
Index: fonts.py
===================================================================
RCS file: /cvsroot/pythonreports/PythonReports/PythonReports/fonts.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** fonts.py 26 Jan 2011 07:43:39 -0000 1.4
--- fonts.py 26 Jan 2011 13:53:59 -0000 1.5
***************
*** 1,4 ****
--- 1,5 ----
"""Fonts registry"""
"""History (most recent first):
+ 26-jan-2011 [luch] try to load windows fonts once when a font is missing
26-jan-2011 [als] more well-known font file names;
add Mac OS X font paths
***************
*** 16,19 ****
--- 17,22 ----
import os, sys
+ import windows_fonts
+
# well-known font files
FONTS = {
***************
*** 77,80 ****
--- 80,85 ----
}
+ WINDOWS_FONTS_ADDED = False
+
# paths to look for TrueType fonts
SYSFONTPATHS = []
***************
*** 89,95 ****
"/usr/share/fonts/truetype/msttcorefonts", # Ubuntu (Feisty)
])
! if sys.platform == "darwin":
! SYSFONTPATHS.extend(map(itemgetter(0), os.walk("/Library/Fonts")))
! FONTS[None] = "Courier New.ttf"
def fontfile(typeface, bold=False, italic=False):
--- 94,100 ----
"/usr/share/fonts/truetype/msttcorefonts", # Ubuntu (Feisty)
])
! if sys.platform == "darwin":
! SYSFONTPATHS.extend(map(itemgetter(0), os.walk("/Library/Fonts")))
! FONTS[None] = "Courier New.ttf"
def fontfile(typeface, bold=False, italic=False):
***************
*** 102,109 ****
"""
try:
! _file = FONTS[(typeface, bool(bold), bool(italic))]
except KeyError:
! _file = FONTS[None]
if os.path.dirname(_file) == "":
# file name does not contain directory path.
--- 107,119 ----
"""
+ _font_key = (typeface, bool(bold), bool(italic))
try:
! _file = FONTS[_font_key]
except KeyError:
! add_windows_fonts()
! try:
! _file = FONTS[_font_key]
! except:
! _file = FONTS[None]
if os.path.dirname(_file) == "":
# file name does not contain directory path.
***************
*** 117,121 ****
# WARNING: this will populate the registry
# with default font for each unknown typeface
! FONTS[(typeface, bool(bold), bool(italic))] = _file
break
else:
--- 127,131 ----
# WARNING: this will populate the registry
# with default font for each unknown typeface
! FONTS[_font_key] = _file
break
else:
***************
*** 124,127 ****
--- 134,144 ----
return _file
+ def add_windows_fonts():
+ """Register installed windows fonts"""
+ global WINDOWS_FONTS_ADDED
+ if not WINDOWS_FONTS_ADDED:
+ FONTS.update(windows_fonts.ls_ttf())
+ WINDOWS_FONTS_ADDED = True
+
def register(filename, typeface, bold=False, italic=False):
"""Register non-standard TTF file
|