Commits

Lenard Lindstrom committed d84cb49

have sysfont.py search the Windows font directory default fonts before checking the registry

Comments (0)

Files changed (1)

 
 
 #read the fonts on windows
+# Info taken from:
+# http://www.microsoft.com/typography/fonts/winxp.htm
+# with extra files added from:
+# <fill this in>
+# File name, family, (Bold, Italic)
+XP_default_font_files = [
+    ('ahronbd.ttf', 'Aharoni', (True, False)),
+    ('andlso.ttf', 'Andalus', (False, False)),
+    ('angsa.ttf', 'Angsana New', (False, False)),
+    ('angsab.ttf', 'Angsana New', (True, False)),
+    ('angsai.ttf', 'Angsana New', (False, True)),
+    ('angsaz.ttf', 'Angsana New', (True, True)),
+    ('angsau.ttf', 'AngsanaUPC', (False, False)),
+    ('angsaub.ttf', 'AngsanaUPC', (True, False)),
+    ('angsaui.ttf', 'AngsanaUPC', (False, True)),
+    ('angsauz.ttf', 'AngsanaUPC', (True, True)),
+    ('artro.ttf', 'Arabic Transparent', (False, False)),
+    ('artrbdo.ttf', 'Arabic Transparent', (True, False)),
+    ('agatha.ttf', 'Agatha', (False, False)),
+    ('arial.ttf', 'Arial', (False, False)),
+    ('arialbd.ttf', 'Arial', (True, False)),
+    ('ariali.ttf', 'Arial', (False, True)),
+    ('arialbi.ttf', 'Arial', (True, True)),
+    ('ariblk.ttf', 'Arial Black', (False, False)),
+    ('browa.ttf', 'Browallia New', (False, False)),
+    ('browab.ttf', 'Browallia New', (True, False)),
+    ('browai.ttf', 'Browallia New', (False, True)),
+    ('browaz.ttf', 'Browallia New', (True, True)),
+    ('browau.ttf', 'BrowalliaUPC', (False, False)),
+    ('browaub.ttf', 'BrowalliaUPC', (True, False)),
+    ('browaui.ttf', 'BrowalliaUPC', (False, True)),
+    ('browauz.ttf', 'BrowalliaUPC', (True, True)),
+    ('comic.ttf', 'Comic Sans MS', (False, False)),
+    ('comicbd.ttf', 'Comic Sans MS', (True, False)),
+    ('cordia.ttf', 'Cordia New', (False, False)),
+    ('cordiab.ttf', 'Cordia New', (True, False)),
+    ('cordiai.ttf', 'Cordia New', (False, True)),
+    ('cordiaz.ttf', 'Cordia New', (True, True)),
+    ('cordiau.ttf', 'CordiaUPC', (False, False)),
+    ('cordiaub.ttf', 'CordiaUPC', (True, False)),
+    ('cordiaui.ttf', 'CordiaUPC', (False, True)),
+    ('cordiauz.ttf', 'CordiaUPC', (True, True)),
+    ('cour.ttf', 'Courier New', (False, False)),
+    ('courbd.ttf', 'Courier New', (True, False)),
+    ('couri.ttf', 'Courier New', (False, True)),
+    ('courbi.ttf', 'Courier New', (True, True)),
+    ('david.ttf', 'David', (False, False)),
+    ('davidbd.ttf', 'David', (True, False)),
+    ('davidtr.ttf', 'David Transparent', (False, False)),
+    ('upcdl.ttf', 'DilleniaUPC', (False, False)),
+    ('upcdb.ttf', 'DilleniaUPC', (True, False)),
+    ('upcdi.ttf', 'DilleniaUPC', (False, True)),
+    ('upcdbi.ttf', 'DilleniaUPC', (True, True)),
+    ('estre.ttf', 'Estrangelo Edessa', (False, False)),
+    ('upcel.ttf', 'EucrosialUPC', (False, False)),
+    ('upceb.ttf', 'EucrosialUPC', (True, False)),
+    ('upcei.ttf', 'EucrosialUPC', (False, True)),
+    ('upcebi.ttf', 'EucrosialUPC', (True, True)),
+    ('mriamfx.ttf', 'Fixed Miriam Transparent', (False, False)),
+    ('framd.ttf', 'Franklin Gothic Medium', (False, False)),
+    ('framdit.ttf', 'Franklin Gothic Medium', (False, True)),
+    ('frank.ttf', 'FrankRuehl', (False, False)),
+    ('upcfl.ttf', 'FreesialUPC', (False, False)),
+    ('upcfb.ttf', 'FreesialUPC', (True, False)),
+    ('upcfi.ttf', 'FreesialUPC', (False, True)),
+    ('upcfbi.ttf', 'FreesialUPC', (True, True)),
+    ('gautami.ttf', 'Gautami', (False, False)),
+    ('georgia.ttf', 'Georgia', (False, False)),
+    ('georgiab.ttf', 'Georgia', (True, False)),
+    ('georgiai.ttf', 'Georgia', (False, True)),
+    ('georgiaz.ttf', 'Georgia', (True, True)),
+    ('impact.ttf', 'Impact', (False, False)),
+    ('upcil.ttf', 'IrisUPC', (False, False)),
+    ('upcib.ttf', 'IrisUPC', (True, False)),
+    ('upcii.ttf', 'IrisUPC', (False, True)),
+    ('upcibi.ttf', 'IrisUPC', (True, True)),
+    ('upcjl.ttf', 'JasmineUPC', (False, False)),
+    ('upcjb.ttf', 'JasmineUPC', (True, False)),
+    ('upcji.ttf', 'JasmineUPC', (False, True)),
+    ('upcjbi.ttf', 'JasmineUPC', (True, True)),
+    ('upckl.ttf', 'KodchiangUPC', (False, False)),
+    ('upckb.ttf', 'KodchiangUPC', (True, False)),
+    ('upcki.ttf', 'KodchiangUPC', (False, True)),
+    ('upckbi.ttf', 'KodchiangUPC', (True, True)),
+    ('latha.ttf', 'Latha', (False, False)),
+    ('lvnm.ttf', 'Levenim MT', (False, False)),
+    ('lvnmbd.ttf', 'Levenim MT', (True, False)),
+    ('upcll.ttf', 'LilyUPC', (False, False)),
+    ('upclb.ttf', 'LilyUPC', (True, False)),
+    ('upcli.ttf', 'LilyUPC', (False, True)),
+    ('upclbi.ttf', 'LilyUPC', (True, True)),
+    ('lucon.ttf', 'Lucida Console', (False, False)),
+    ('l_10646.ttf', 'Lucida Sans Unicode', (False, False)),
+    ('mangal.ttf', 'Mangal', (False, False)),
+    ('marlett.ttf', 'Marlett', (False, False)),
+    ('micross.ttf', 'Microsoft Sans Serif', (False, False)),
+    ('mriam.ttf', 'Miriam', (False, False)),
+    ('mriamc.ttf', 'Miriam Fixed', (False, False)),
+    ('mriamtr.ttf', 'Miriam Transparent', (False, False)),
+    ('mvboli.ttf', 'MV Boli', (False, False)),
+    ('nrkis.ttf', 'Narkisim', (False, False)),
+    ('pala.ttf', 'Falatino Linotype', (False, False)),
+    ('palab.ttf', 'Falatino Linotype', (True, False)),
+    ('palai.ttf', 'Falatino Linotype', (False, True)),
+    ('palabi.ttf', 'Falatino Linotype', (True, True)),
+    ('raavi.ttf', 'Raavi', (False, False)),
+    ('rod.ttf', 'Rod', (False, False)),
+    ('rodtr.ttf', 'Rod Transparent', (False, False)),
+    ('shruti.ttf', 'Shruti', (False, False)),
+    ('simpo.ttf', 'Simplified Arabic', (False, False)),
+    ('simpbdo.ttf', 'Simplified Arabic', (True, False)),
+    ('simpfxo.ttf', 'Simplified Arabic Fixed', (False, False)),
+    ('sylfaen.ttf', 'Sylfaen', (False, False)),
+    ('symbol.ttf', 'Symbol', (False, False)),
+    ('tahoma.ttf', 'Tahoma', (False, False)),
+    ('tahomabd.ttf', 'Tahoma', (True, False)),
+    ('times.ttf', 'Times New Roman', (False, False)),
+    ('timesbd.ttf', 'Times New Roman', (True, False)),
+    ('timesi.ttf', 'Times New Roman', (False, True)),
+    ('timesbi.ttf', 'Times New Roman', (True, True)),
+    ('trado.ttf', 'Traditional Arabic', (False, False)),
+    ('tradbdo.ttf', 'Traditional Arabic', (True, False)),
+    ('Trebuc.ttf', 'Trebuchet MS', (False, False)),
+    ('Trebucbd.ttf', 'Trebuchet MS', (True, False)),
+    ('Trebucit.ttf', 'Trebuchet MS', (False, True)),
+    ('Trebucbi.ttf', 'Trebuchet MS', (True, True)),
+    ('tunga.ttf', 'Tunga', (False, False)),
+    ('verdana.ttf', 'Verdana', (False, False)),
+    ('verdanab.ttf', 'Verdana', (True, False)),
+    ('verdanai.ttf', 'Verdana', (False, True)),
+    ('verdanaz.ttf', 'Verdana', (True, True)),
+    ('webdings.ttf', 'Webdings', (False, False)),
+    ('wingding.ttf', 'Wingdings', (False, False)),
+    ('simhei.ttf', 'SimHei', (False, False)),
+    ('simfang.ttf', 'FangSong_GB2312', (False, False)),
+    ('kaiu.ttf', 'DFKai-SB', (False, False)),
+    ('simkai.ttf', 'KaiTi_GB2312', (False, False)),
+    ('msgothic.ttc', 'MS Gothic', (False, False)),
+    ('msmincho.ttc', 'MS Mincho', (False, False)),
+    ('gulim.ttc', 'Gulim', (False, False)),
+    ('mingliu.ttc', 'Mingliu', (False, False)),
+    ('simsun.ttc', 'Simsun', (False, False)),
+    ('batang.ttc', 'Batang', (False, False)),
+    ]
+
 def initsysfonts_win32():
     try:
         import _winreg
     #about fonts installed on the system.
     keys = []
 
+    #add recognized fonts from the fonts directory because the default
+    #fonts may not be entered in the registry.
+    win_font_files_mapping = dict(
+        [(font.lower(), (_simplename(name), face))
+         for font, name, face in XP_default_font_files])
+
+    font_dir_path = os.path.join(os.environ['windir'], 'fonts')
+    try:
+        font_file_paths = glob.glob(os.path.join(font_dir_path, '*.tt?'))
+    except Exception:
+        pass
+    else:
+        for font in font_file_paths:
+            file_name = os.path.basename(font)
+            try:
+                name, face = win_font_file_mapping[file_name]
+            except KeyError:
+                pass
+            else:
+                try:
+                    faces = fonts[name]
+                except KeyError:
+                    _addfont(name, face[0], face[1], font, fonts)
+                else:
+                    if face not in faces:
+                        _addfont(name, face[0], face[1], font, fonts)
+
+    #add additional fonts entered in the registry.
+
     #find valid registry keys containing font information.
     possible_keys = [
         r"SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts",
             name=_simplename(name)
 
             _addfont(name, bold, italic, font, fonts)
+
     return fonts