Mercurial > pygame
annotate lib/sysfont.py @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 67b60fa1972e |
| children |
| rev | line source |
|---|---|
| 466 | 1 ## pygame - Python Game Library |
| 2 ## Copyright (C) 2000-2003 Pete Shinners | |
| 3 ## | |
| 4 ## This library is free software; you can redistribute it and/or | |
| 5 ## modify it under the terms of the GNU Library General Public | |
| 6 ## License as published by the Free Software Foundation; either | |
| 7 ## version 2 of the License, or (at your option) any later version. | |
| 8 ## | |
| 9 ## This library is distributed in the hope that it will be useful, | |
| 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 ## Library General Public License for more details. | |
| 13 ## | |
| 14 ## You should have received a copy of the GNU Library General Public | |
| 15 ## License along with this library; if not, write to the Free | |
| 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 ## | |
| 18 ## Pete Shinners | |
| 19 ## pete@shinners.org | |
| 20 | |
| 21 "sysfont, used in the font module to find system fonts" | |
| 22 | |
| 23 import os, sys | |
| 24 | |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
25 #Python 3 compatibility |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
26 try: |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
27 bytes |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
28 except NameError: |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
29 def toascii(raw): |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
30 return raw.decode('ascii', 'ignore').encode('ascii') |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
31 else: |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
32 def toascii(raw): |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
33 return raw.decode('ascii', 'ignore') |
| 466 | 34 |
| 35 #create simple version of the font name | |
| 36 def _simplename(name): | |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
37 return ''.join([c.lower() for c in name if c.isalnum()]) |
| 466 | 38 |
| 467 | 39 |
| 466 | 40 #insert a font and style into the font dictionary |
| 41 def _addfont(name, bold, italic, font, fontdict): | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
778
diff
changeset
|
42 if name not in fontdict: |
| 466 | 43 fontdict[name] = {} |
| 44 fontdict[name][bold, italic] = font | |
| 45 | |
| 467 | 46 |
| 466 | 47 #read the fonts on windows |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
48 # Info taken from: |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
49 # http://www.microsoft.com/typography/fonts/winxp.htm |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
50 # with extra files added from: |
|
1803
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
51 # http://www.ampsoft.net/webdesign-l/windows-fonts-by-version.html |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
52 # File name, family, (Bold, Italic) |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
53 _XP_default_font_files = [ |
|
1803
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
54 ('ahronbd.ttf', 'Aharoni', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
55 ('andlso.ttf', 'Andalus', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
56 ('angsa.ttf', 'Angsana New', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
57 ('angsab.ttf', 'Angsana New', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
58 ('angsai.ttf', 'Angsana New', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
59 ('angsaz.ttf', 'Angsana New', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
60 ('angsau.ttf', 'AngsanaUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
61 ('angsaub.ttf', 'AngsanaUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
62 ('angsaui.ttf', 'AngsanaUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
63 ('angsauz.ttf', 'AngsanaUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
64 ('artro.ttf', 'Arabic Transparent', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
65 ('artrbdo.ttf', 'Arabic Transparent', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
66 ('agatha.ttf', 'Agatha', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
67 ('arial.ttf', 'Arial', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
68 ('arialbd.ttf', 'Arial', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
69 ('ariali.ttf', 'Arial', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
70 ('arialbi.ttf', 'Arial', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
71 ('ariblk.ttf', 'Arial Black', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
72 ('browa.ttf', 'Browallia New', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
73 ('browab.ttf', 'Browallia New', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
74 ('browai.ttf', 'Browallia New', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
75 ('browaz.ttf', 'Browallia New', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
76 ('browau.ttf', 'BrowalliaUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
77 ('browaub.ttf', 'BrowalliaUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
78 ('browaui.ttf', 'BrowalliaUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
79 ('browauz.ttf', 'BrowalliaUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
80 ('comic.ttf', 'Comic Sans MS', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
81 ('comicbd.ttf', 'Comic Sans MS', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
82 ('cordia.ttf', 'Cordia New', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
83 ('cordiab.ttf', 'Cordia New', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
84 ('cordiai.ttf', 'Cordia New', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
85 ('cordiaz.ttf', 'Cordia New', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
86 ('cordiau.ttf', 'CordiaUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
87 ('cordiaub.ttf', 'CordiaUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
88 ('cordiaui.ttf', 'CordiaUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
89 ('cordiauz.ttf', 'CordiaUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
90 ('cour.ttf', 'Courier New', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
91 ('courbd.ttf', 'Courier New', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
92 ('couri.ttf', 'Courier New', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
93 ('courbi.ttf', 'Courier New', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
94 ('david.ttf', 'David', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
95 ('davidbd.ttf', 'David', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
96 ('davidtr.ttf', 'David Transparent', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
97 ('upcdl.ttf', 'DilleniaUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
98 ('upcdb.ttf', 'DilleniaUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
99 ('upcdi.ttf', 'DilleniaUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
100 ('upcdbi.ttf', 'DilleniaUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
101 ('estre.ttf', 'Estrangelo Edessa', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
102 ('upcel.ttf', 'EucrosialUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
103 ('upceb.ttf', 'EucrosialUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
104 ('upcei.ttf', 'EucrosialUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
105 ('upcebi.ttf', 'EucrosialUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
106 ('mriamfx.ttf', 'Fixed Miriam Transparent', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
107 ('framd.ttf', 'Franklin Gothic Medium', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
108 ('framdit.ttf', 'Franklin Gothic Medium', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
109 ('frank.ttf', 'FrankRuehl', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
110 ('upcfl.ttf', 'FreesialUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
111 ('upcfb.ttf', 'FreesialUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
112 ('upcfi.ttf', 'FreesialUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
113 ('upcfbi.ttf', 'FreesialUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
114 ('gautami.ttf', 'Gautami', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
115 ('georgia.ttf', 'Georgia', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
116 ('georgiab.ttf', 'Georgia', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
117 ('georgiai.ttf', 'Georgia', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
118 ('georgiaz.ttf', 'Georgia', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
119 ('impact.ttf', 'Impact', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
120 ('upcil.ttf', 'IrisUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
121 ('upcib.ttf', 'IrisUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
122 ('upcii.ttf', 'IrisUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
123 ('upcibi.ttf', 'IrisUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
124 ('upcjl.ttf', 'JasmineUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
125 ('upcjb.ttf', 'JasmineUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
126 ('upcji.ttf', 'JasmineUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
127 ('upcjbi.ttf', 'JasmineUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
128 ('upckl.ttf', 'KodchiangUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
129 ('upckb.ttf', 'KodchiangUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
130 ('upcki.ttf', 'KodchiangUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
131 ('upckbi.ttf', 'KodchiangUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
132 ('latha.ttf', 'Latha', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
133 ('lvnm.ttf', 'Levenim MT', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
134 ('lvnmbd.ttf', 'Levenim MT', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
135 ('upcll.ttf', 'LilyUPC', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
136 ('upclb.ttf', 'LilyUPC', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
137 ('upcli.ttf', 'LilyUPC', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
138 ('upclbi.ttf', 'LilyUPC', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
139 ('lucon.ttf', 'Lucida Console', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
140 ('l_10646.ttf', 'Lucida Sans Unicode', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
141 ('mangal.ttf', 'Mangal', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
142 ('marlett.ttf', 'Marlett', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
143 ('micross.ttf', 'Microsoft Sans Serif', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
144 ('mriam.ttf', 'Miriam', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
145 ('mriamc.ttf', 'Miriam Fixed', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
146 ('mriamtr.ttf', 'Miriam Transparent', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
147 ('mvboli.ttf', 'MV Boli', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
148 ('nrkis.ttf', 'Narkisim', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
149 ('pala.ttf', 'Falatino Linotype', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
150 ('palab.ttf', 'Falatino Linotype', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
151 ('palai.ttf', 'Falatino Linotype', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
152 ('palabi.ttf', 'Falatino Linotype', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
153 ('raavi.ttf', 'Raavi', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
154 ('rod.ttf', 'Rod', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
155 ('rodtr.ttf', 'Rod Transparent', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
156 ('shruti.ttf', 'Shruti', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
157 ('simpo.ttf', 'Simplified Arabic', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
158 ('simpbdo.ttf', 'Simplified Arabic', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
159 ('simpfxo.ttf', 'Simplified Arabic Fixed', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
160 ('sylfaen.ttf', 'Sylfaen', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
161 ('symbol.ttf', 'Symbol', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
162 ('tahoma.ttf', 'Tahoma', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
163 ('tahomabd.ttf', 'Tahoma', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
164 ('times.ttf', 'Times New Roman', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
165 ('timesbd.ttf', 'Times New Roman', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
166 ('timesi.ttf', 'Times New Roman', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
167 ('timesbi.ttf', 'Times New Roman', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
168 ('trado.ttf', 'Traditional Arabic', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
169 ('tradbdo.ttf', 'Traditional Arabic', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
170 ('Trebuc.ttf', 'Trebuchet MS', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
171 ('Trebucbd.ttf', 'Trebuchet MS', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
172 ('Trebucit.ttf', 'Trebuchet MS', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
173 ('Trebucbi.ttf', 'Trebuchet MS', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
174 ('tunga.ttf', 'Tunga', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
175 ('verdana.ttf', 'Verdana', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
176 ('verdanab.ttf', 'Verdana', True, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
177 ('verdanai.ttf', 'Verdana', False, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
178 ('verdanaz.ttf', 'Verdana', True, True), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
179 ('webdings.ttf', 'Webdings', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
180 ('wingding.ttf', 'Wingdings', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
181 ('simhei.ttf', 'SimHei', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
182 ('simfang.ttf', 'FangSong_GB2312', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
183 ('kaiu.ttf', 'DFKai-SB', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
184 ('simkai.ttf', 'KaiTi_GB2312', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
185 ('msgothic.ttc', 'MS Gothic', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
186 ('msmincho.ttc', 'MS Mincho', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
187 ('gulim.ttc', 'Gulim', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
188 ('mingliu.ttc', 'Mingliu', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
189 ('simsun.ttc', 'Simsun', False, False), |
|
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
190 ('batang.ttc', 'Batang', False, False), |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
191 ] |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
192 |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
193 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
194 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
195 |
| 466 | 196 def initsysfonts_win32(): |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
778
diff
changeset
|
197 try: |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
778
diff
changeset
|
198 import _winreg |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
778
diff
changeset
|
199 except ImportError: |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
778
diff
changeset
|
200 import winreg as _winreg |
|
1802
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
201 |
|
1918
97a820e6dcaa
fix pygame.font.get_fonts() bug for Python 3.1 and Windows
Lenard Lindstrom <len-l@telus.net>
parents:
1864
diff
changeset
|
202 if 'WINDIR' in os.environ: |
|
1802
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
203 windir = os.environ['WINDIR'] |
|
1918
97a820e6dcaa
fix pygame.font.get_fonts() bug for Python 3.1 and Windows
Lenard Lindstrom <len-l@telus.net>
parents:
1864
diff
changeset
|
204 elif 'windir' in os.environ: |
|
1802
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
205 windir = os.environ['windir'] |
|
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
206 else: |
|
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
207 windir = "C:\\Windows\\" |
|
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
208 |
|
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
209 |
| 466 | 210 fonts = {} |
| 211 mods = 'demibold', 'narrow', 'light', 'unicode', 'bt', 'mt' | |
|
1802
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
212 fontdir = os.path.join(windir, "Fonts") |
| 466 | 213 |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
214 #this is a list of registry keys containing information |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
215 #about fonts installed on the system. |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
216 keys = [] |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
217 |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
218 #add recognized fonts from the fonts directory because the default |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
219 #fonts may not be entered in the registry. |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
220 win_font_files_mapping = dict( |
|
1803
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
221 [(file_name.lower(), (_simplename(name), bold, italic)) |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
222 for file_name, name, bold, italic in _XP_default_font_files]) |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
223 |
|
1802
a10192feae21
fix possible problem with WINDIR, windir environment variable name.
Rene Dudfield <renesd@gmail.com>
parents:
1801
diff
changeset
|
224 font_dir_path = os.path.join(windir, 'fonts') |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
225 try: |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
226 font_file_paths = glob.glob(os.path.join(font_dir_path, '*.tt?')) |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
227 except Exception: |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
228 pass |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
229 else: |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
230 for font in font_file_paths: |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
231 file_name = os.path.basename(font) |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
232 try: |
|
1803
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
233 name, bold, italic = win_font_file_mapping[file_name] |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
234 except KeyError: |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
235 pass |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
236 else: |
|
1803
3dc727fe8469
simplified sysfont.initsysfonts_win() fonts directory scan
Lenard Lindstrom <len-l@telus.net>
parents:
1802
diff
changeset
|
237 _addfont(name, bold, italic, font, fonts) |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
238 |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
239 #add additional fonts entered in the registry. |
|
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
240 |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
241 #find valid registry keys containing font information. |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
242 possible_keys = [ |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
243 r"SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts", |
|
1801
175a77d13c79
Added another possible registry key where there might be fonts on win.
Rene Dudfield <renesd@gmail.com>
parents:
1800
diff
changeset
|
244 r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", |
|
175a77d13c79
Added another possible registry key where there might be fonts on win.
Rene Dudfield <renesd@gmail.com>
parents:
1800
diff
changeset
|
245 r"SOFTWARE\Microsoft\Windows[NT]\CurrentVersion\Fonts", |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
246 ] |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
247 |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
248 for key_name in possible_keys: |
| 485 | 249 try: |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
250 key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key_name) |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
251 keys.append(key) |
| 485 | 252 except WindowsError: |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
253 pass |
| 485 | 254 |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
255 for key in keys: |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
256 fontdict = {} |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
257 for i in range(_winreg.QueryInfoKey(key)[1]): |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
258 try: name, font, t = _winreg.EnumValue(key,i) |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
259 except EnvironmentError: break |
|
589
2fa9967e4502
attempted fix for unicode font names
Rene Dudfield <renesd@gmail.com>
parents:
561
diff
changeset
|
260 |
|
2fa9967e4502
attempted fix for unicode font names
Rene Dudfield <renesd@gmail.com>
parents:
561
diff
changeset
|
261 # try and handle windows unicode strings for some file names. |
|
592
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
262 |
|
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
263 # here are two documents with some information about it: |
|
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
264 # http://www.python.org/peps/pep-0277.html |
|
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
265 # https://www.microsoft.com/technet/archive/interopmigration/linux/mvc/lintowin.mspx#ECAA |
|
589
2fa9967e4502
attempted fix for unicode font names
Rene Dudfield <renesd@gmail.com>
parents:
561
diff
changeset
|
266 try: |
|
2fa9967e4502
attempted fix for unicode font names
Rene Dudfield <renesd@gmail.com>
parents:
561
diff
changeset
|
267 font = str(font) |
|
2fa9967e4502
attempted fix for unicode font names
Rene Dudfield <renesd@gmail.com>
parents:
561
diff
changeset
|
268 except UnicodeEncodeError: |
|
590
5835be86ae1c
tried encoding to MBCS on failure for fonts. It seems to work with a unicode named font I tried on XP.
Rene Dudfield <renesd@gmail.com>
parents:
589
diff
changeset
|
269 # MBCS is the windows encoding for unicode file names. |
|
592
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
270 try: |
|
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
271 font = font.encode('MBCS') |
|
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
272 except: |
|
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
273 # no goodness with str or MBCS encoding... skip this font. |
|
dcbbb7206b33
skiping a font name if it fails to encode with str or with MBCS encoding.
Rene Dudfield <renesd@gmail.com>
parents:
591
diff
changeset
|
274 continue |
|
590
5835be86ae1c
tried encoding to MBCS on failure for fonts. It seems to work with a unicode named font I tried on XP.
Rene Dudfield <renesd@gmail.com>
parents:
589
diff
changeset
|
275 |
|
2175
4fe70de06bf0
Patch from Ian Katz <ifreecarve@gmail.com>, add OTF sysfont support
Nirav Patel <nrp@eclecti.cc>
parents:
1918
diff
changeset
|
276 if font[-4:].lower() not in [".ttf", ".ttc", ".otf"]: |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
277 continue |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
278 if os.sep not in font: |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
279 font = os.path.join(fontdir, font) |
| 466 | 280 |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
281 if name[-10:] == '(TrueType)': |
|
590
5835be86ae1c
tried encoding to MBCS on failure for fonts. It seems to work with a unicode named font I tried on XP.
Rene Dudfield <renesd@gmail.com>
parents:
589
diff
changeset
|
282 name = name[:-11] |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
283 name = name.lower().split() |
| 466 | 284 |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
285 bold = italic = 0 |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
286 for m in mods: |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
287 if m in name: |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
288 name.remove(m) |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
289 if 'bold' in name: |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
290 name.remove('bold') |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
291 bold = 1 |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
292 if 'italic' in name: |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
293 name.remove('italic') |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
294 italic = 1 |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
295 name = ''.join(name) |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
296 |
|
615
9aa7afa1f3d6
Some patches to make Chinese fonts work better on windows.
Rene Dudfield <renesd@gmail.com>
parents:
592
diff
changeset
|
297 name=_simplename(name) |
|
9aa7afa1f3d6
Some patches to make Chinese fonts work better on windows.
Rene Dudfield <renesd@gmail.com>
parents:
592
diff
changeset
|
298 |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
299 _addfont(name, bold, italic, font, fonts) |
|
1800
d84cb495f32a
have sysfont.py search the Windows font directory default fonts before checking the registry
Lenard Lindstrom <len-l@telus.net>
parents:
1792
diff
changeset
|
300 |
| 466 | 301 return fonts |
| 302 | |
| 303 | |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
304 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
305 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
306 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
307 _OSX_default_font_files = { |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
308 'albayan': {(False, False): '/Library/Fonts/AlBayan.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
309 (True, False): '/Library/Fonts/AlBayanBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
310 'andalemono': {(False, False): '/Library/Fonts/Andale Mono.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
311 'applebraille': {(False, False): '/System/Library/Fonts/Apple Braille Outline 6 Dot.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
312 'applegothic': {(False, False): '/System/Library/Fonts/AppleGothic.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
313 'applesymbols': {(False, False): '/System/Library/Fonts/Apple Symbols.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
314 'arial': {(False, False): '/Library/Fonts/Arial.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
315 (False, True): '/Library/Fonts/Arial Italic.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
316 (True, False): '/Library/Fonts/Arial Bold.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
317 (True, True): '/Library/Fonts/Arial Bold Italic.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
318 'arialblack': {(False, False): '/Library/Fonts/Arial Black.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
319 'arialhebrew': {(False, False): '/Library/Fonts/ArialHB.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
320 (True, False): '/Library/Fonts/ArialHBBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
321 'arialnarrow': {(False, False): '/Library/Fonts/Arial Narrow.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
322 (False, True): '/Library/Fonts/Arial Narrow Italic.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
323 (True, False): '/Library/Fonts/Arial Narrow Bold.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
324 (True, True): '/Library/Fonts/Arial Narrow Bold Italic.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
325 'arialroundedmtbold': {(False, False): '/Library/Fonts/Arial Rounded Bold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
326 'arialunicodems': {(False, False): '/Library/Fonts/Arial Unicode.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
327 'ayuthaya': {(False, False): '/Library/Fonts/Ayuthaya.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
328 'baghdad': {(False, False): '/Library/Fonts/Baghdad.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
329 'brushscriptmt': {(False, True): '/Library/Fonts/Brush Script.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
330 'chalkboard': {(False, False): '/Library/Fonts/Chalkboard.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
331 (True, False): '/Library/Fonts/ChalkboardBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
332 'comicsansms': {(False, False): '/Library/Fonts/Comic Sans MS.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
333 (True, False): '/Library/Fonts/Comic Sans MS Bold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
334 'corsivahebrew': {(False, False): '/Library/Fonts/Corsiva.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
335 (True, False): '/Library/Fonts/CorsivaBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
336 'couriernew': {(False, False): '/Library/Fonts/Courier New.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
337 (False, True): '/Library/Fonts/Courier New Italic.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
338 (True, False): '/Library/Fonts/Courier New Bold.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
339 (True, True): '/Library/Fonts/Courier New Bold Italic.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
340 'decotypenaskh': {(False, False): '/Library/Fonts/DecoTypeNaskh.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
341 'devanagarimt': {(False, False): '/Library/Fonts/DevanagariMT.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
342 (True, False): '/Library/Fonts/DevanagariMTBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
343 'euphemiaucas': {(False, False): '/Library/Fonts/EuphemiaCASRegular.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
344 (False, True): '/Library/Fonts/EuphemiaCASItalic.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
345 (True, False): '/Library/Fonts/EuphemiaCASBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
346 'gb18030bitmap': {(False, False): '/Library/Fonts/NISC18030.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
347 'geezapro': {(False, False): '/System/Library/Fonts/Geeza Pro.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
348 (True, False): '/System/Library/Fonts/Geeza Pro Bold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
349 'georgia': {(False, False): '/Library/Fonts/Georgia.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
350 (False, True): '/Library/Fonts/Georgia Italic.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
351 (True, False): '/Library/Fonts/Georgia Bold.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
352 (True, True): '/Library/Fonts/Georgia Bold Italic.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
353 'gujaratimt': {(False, False): '/Library/Fonts/GujaratiMT.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
354 (True, False): '/Library/Fonts/GujaratiMTBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
355 'gurmukhimt': {(False, False): '/Library/Fonts/Gurmukhi.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
356 'impact': {(False, False): '/Library/Fonts/Impact.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
357 'inaimathi': {(False, False): '/Library/Fonts/InaiMathi.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
358 'kailasa': {(False, False): '/Library/Fonts/Kailasa.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
359 'kokonor': {(False, False): '/Library/Fonts/Kokonor.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
360 'krungthep': {(False, False): '/Library/Fonts/Krungthep.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
361 'kufistandardgk': {(False, False): '/Library/Fonts/KufiStandardGK.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
362 'liheipro': {(False, False): '/System/Library/Fonts/ Pro.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
363 'lisongpro': {(False, False): '/Library/Fonts/ Pro.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
364 'microsoftsansserif': {(False, False): '/Library/Fonts/Microsoft Sans Serif.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
365 'mshtakan': {(False, False): '/Library/Fonts/MshtakanRegular.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
366 (False, True): '/Library/Fonts/MshtakanOblique.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
367 (True, False): '/Library/Fonts/MshtakanBold.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
368 (True, True): '/Library/Fonts/MshtakanBoldOblique.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
369 'nadeem': {(False, False): '/Library/Fonts/Nadeem.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
370 'newpeninimmt': {(False, False): '/Library/Fonts/NewPeninimMT.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
371 (True, False): '/Library/Fonts/NewPeninimMTBoldInclined.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
372 'plantagenetcherokee': {(False, False): '/Library/Fonts/PlantagenetCherokee.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
373 'raanana': {(False, False): '/Library/Fonts/Raanana.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
374 (True, False): '/Library/Fonts/RaananaBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
375 'sathu': {(False, False): '/Library/Fonts/Sathu.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
376 'silom': {(False, False): '/Library/Fonts/Silom.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
377 'stfangsong': {(False, False): '/Library/Fonts/.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
378 'stheiti': {(False, False): '/System/Library/Fonts/.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
379 'stkaiti': {(False, False): '/Library/Fonts/.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
380 'stsong': {(False, False): '/Library/Fonts/.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
381 'tahoma': {(False, False): '/Library/Fonts/Tahoma.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
382 (True, False): '/Library/Fonts/Tahoma Bold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
383 'thonburi': {(False, False): '/System/Library/Fonts/Thonburi.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
384 (True, False): '/System/Library/Fonts/ThonburiBold.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
385 'timesnewroman': {(False, False): '/Library/Fonts/Times New Roman.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
386 (False, True): '/Library/Fonts/Times New Roman Italic.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
387 (True, False): '/Library/Fonts/Times New Roman Bold.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
388 (True, True): '/Library/Fonts/Times New Roman Bold Italic.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
389 'trebuchetms': {(False, False): '/Library/Fonts/Trebuchet MS.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
390 (False, True): '/Library/Fonts/Trebuchet MS Italic.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
391 (True, False): '/Library/Fonts/Trebuchet MS Bold.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
392 (True, True): '/Library/Fonts/Trebuchet MS Bold Italic.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
393 'verdana': {(False, False): '/Library/Fonts/Verdana.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
394 (False, True): '/Library/Fonts/Verdana Italic.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
395 (True, False): '/Library/Fonts/Verdana Bold.ttf', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
396 (True, True): '/Library/Fonts/Verdana Bold Italic.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
397 'webdings': {(False, False): '/Library/Fonts/Webdings.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
398 'wingdings': {(False, False): '/Library/Fonts/Wingdings.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
399 'wingdings2': {(False, False): '/Library/Fonts/Wingdings 2.ttf'}, |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
400 'wingdings3': {(False, False): '/Library/Fonts/Wingdings 3.ttf'}} |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
401 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
402 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
403 def _search_osx_font_paths(fonts): |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
404 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
405 for name, details in _OSX_default_font_files.items(): |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
406 for k, apath in details.items(): |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
407 if os.path.exists(apath): |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
408 bold, italic = k |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
409 _addfont(name, bold, italic, apath, fonts) |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
410 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
411 |
| 466 | 412 def initsysfonts_darwin(): |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
413 """ read the fonts on OSX. |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
414 """ |
|
1791
4f4d57404fde
partial support for OSX sysfont... 10.5.x onwards. just use unix method
Rene Dudfield <renesd@gmail.com>
parents:
1553
diff
changeset
|
415 # if the X11 binary exists... try and use that. |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
416 # Not likely to be there on pre 10.4.x ... |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
417 # so still need to do other OSX specific method below. |
|
1791
4f4d57404fde
partial support for OSX sysfont... 10.5.x onwards. just use unix method
Rene Dudfield <renesd@gmail.com>
parents:
1553
diff
changeset
|
418 if os.path.exists("/usr/X11/bin/fc-list"): |
|
1864
8c66b393bc5d
sysfont on OSX more resiliant. Broke up tests to find broken ones more easily.
Rene Dudfield <renesd@gmail.com>
parents:
1851
diff
changeset
|
419 fonts = initsysfonts_unix() |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
420 |
|
1864
8c66b393bc5d
sysfont on OSX more resiliant. Broke up tests to find broken ones more easily.
Rene Dudfield <renesd@gmail.com>
parents:
1851
diff
changeset
|
421 # we look for the default paths. |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
422 _search_osx_font_paths(fonts) |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
423 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
424 return fonts |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
425 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
426 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
427 |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
428 |
|
1791
4f4d57404fde
partial support for OSX sysfont... 10.5.x onwards. just use unix method
Rene Dudfield <renesd@gmail.com>
parents:
1553
diff
changeset
|
429 |
| 469 | 430 paths = ['/Library/Fonts', |
| 431 '~/Library/Fonts', | |
| 432 '/Local/Library/Fonts', | |
| 433 '/Network/Library/Fonts'] | |
| 434 fonts = {} | |
| 435 for p in paths: | |
| 436 if os.path.isdir(p): | |
| 437 pass | |
| 438 #os.path.walk(p, _fontwalk, fonts) | |
| 439 return fonts | |
| 440 | |
| 466 | 441 |
| 442 | |
| 443 | |
| 444 #read the fonts on unix | |
| 445 def initsysfonts_unix(): | |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
446 import subprocess |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
447 |
| 466 | 448 fonts = {} |
|
650
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
449 |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
450 # we use the fc-list from fontconfig to get a list of fonts. |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
451 |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
452 try: |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
453 # note, we capture stderr so if fc-list isn't there to stop stderr printing. |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
454 flout, flerr = subprocess.Popen('fc-list : file family style', shell=True, |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
455 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
456 close_fds=True).communicate() |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
457 except Exception: |
|
650
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
458 return fonts |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
459 |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
460 entries = toascii(flout) |
|
650
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
461 try: |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
462 for line in entries.split('\n'): |
|
650
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
463 try: |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
464 filename, family, style = line.split(':', 2) |
|
2175
4fe70de06bf0
Patch from Ian Katz <ifreecarve@gmail.com>, add OTF sysfont support
Nirav Patel <nrp@eclecti.cc>
parents:
1918
diff
changeset
|
465 if filename[-4:].lower() in ['.ttf', '.ttc', '.otf']: |
|
650
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
466 bold = style.find('Bold') >= 0 |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
467 italic = style.find('Italic') >= 0 |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
468 oblique = style.find('Oblique') >= 0 |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
469 for name in family.split(','): |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
470 if name: |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
471 break |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
472 else: |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
473 name = os.path.splitext(os.path.basename(filename))[0] |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
474 _addfont(_simplename(name), |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
475 bold, italic or oblique, filename, fonts) |
|
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
476 except Exception: |
|
650
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
477 # try the next one. |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
478 pass |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
479 except Exception: |
|
650
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
480 pass |
|
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
481 |
| 466 | 482 return fonts |
| 483 | |
| 484 | |
|
650
3721f4d5343d
A change to use fc-list for reading fonts on unix.
Rene Dudfield <renesd@gmail.com>
parents:
647
diff
changeset
|
485 |
| 466 | 486 #create alias entries |
| 487 def create_aliases(): | |
| 488 aliases = ( | |
| 467 | 489 ('monospace', 'misc-fixed', 'courier', 'couriernew', 'console', |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
490 'fixed', 'mono', 'freemono', 'bitstreamverasansmono', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
491 'verasansmono', 'monotype', 'lucidaconsole'), |
| 469 | 492 ('sans', 'arial', 'helvetica', 'swiss', 'freesans', |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
493 'bitstreamverasans', 'verasans', 'verdana', 'tahoma'), |
| 467 | 494 ('serif', 'times', 'freeserif', 'bitstreamveraserif', 'roman', |
|
1851
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
495 'timesroman', 'timesnewroman', 'dutch', 'veraserif', |
|
1e2e095a3c56
Added fallback for OSX that doesn't have X11.
Rene Dudfield <renesd@gmail.com>
parents:
1803
diff
changeset
|
496 'georgia'), |
| 466 | 497 ('wingdings', 'wingbats'), |
| 498 ) | |
| 499 for set in aliases: | |
| 500 found = None | |
| 467 | 501 fname = None |
| 466 | 502 for name in set: |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
778
diff
changeset
|
503 if name in Sysfonts: |
| 466 | 504 found = Sysfonts[name] |
| 467 | 505 fname = name |
| 466 | 506 break |
| 507 if not found: | |
| 467 | 508 continue |
| 466 | 509 for name in set: |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
778
diff
changeset
|
510 if name not in Sysfonts: |
| 466 | 511 Sysalias[name] = found |
| 512 | |
| 513 | |
| 514 Sysfonts = {} | |
| 515 Sysalias = {} | |
| 516 | |
| 517 #initialize it all, called once | |
| 518 def initsysfonts(): | |
| 519 if sys.platform == 'win32': | |
| 520 fonts = initsysfonts_win32() | |
| 521 elif sys.platform == 'darwin': | |
| 522 fonts = initsysfonts_darwin() | |
| 523 else: | |
| 524 fonts = initsysfonts_unix() | |
| 525 Sysfonts.update(fonts) | |
| 526 create_aliases() | |
| 527 if not Sysfonts: #dummy so we don't try to reinit | |
| 528 Sysfonts[None] = None | |
| 529 | |
| 530 | |
|
2293
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
531 # pygame.font specific declarations |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
532 def font_constructor(fontpath, size, bold, italic): |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
533 import pygame.font |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
534 |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
535 font = pygame.font.Font(fontpath, size) |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
536 if bold: |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
537 font.set_bold(1) |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
538 if italic: |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
539 font.set_italic(1) |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
540 |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
541 return font |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
542 |
| 466 | 543 |
| 544 #the exported functions | |
| 545 | |
|
2293
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
546 def SysFont(name, size, bold=False, italic=False, constructor=None): |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
547 """pygame.font.SysFont(name, size, bold=False, italic=False, constructor=None) -> Font |
| 466 | 548 create a pygame Font from system font resources |
| 549 | |
| 550 This will search the system fonts for the given font | |
| 551 name. You can also enable bold or italic styles, and | |
| 552 the appropriate system font will be selected if available. | |
| 553 | |
| 554 This will always return a valid Font object, and will | |
| 555 fallback on the builtin pygame font if the given font | |
| 556 is not found. | |
| 557 | |
| 558 Name can also be a comma separated list of names, in | |
| 559 which case set of names will be searched in order. Pygame | |
| 560 uses a small set of common font aliases, if the specific | |
| 561 font you ask for is not available, a reasonable alternative | |
| 562 may be used. | |
|
2293
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
563 |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
564 if optional contructor is provided, it must be a function with |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
565 signature constructor(fontpath, size, bold, italic) which returns |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
566 a Font instance. If None, a pygame.font.Font object is created. |
| 466 | 567 """ |
|
2293
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
568 if constructor is None: |
|
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
569 constructor = font_constructor |
| 466 | 570 |
| 571 if not Sysfonts: | |
| 572 initsysfonts() | |
| 532 | 573 |
| 541 | 574 gotbold = gotitalic = False |
| 466 | 575 fontname = None |
| 483 | 576 if name: |
| 577 allnames = name | |
| 578 for name in allnames.split(','): | |
| 579 name = _simplename(name) | |
| 580 styles = Sysfonts.get(name) | |
| 581 if not styles: | |
| 582 styles = Sysalias.get(name) | |
| 583 if styles: | |
|
3006
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
584 plainname = styles.get((False, False)) |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
585 fontname = styles.get((bold, italic)) |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
586 if not fontname and not plainname: |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
587 # Neither requested style, nor plain font exists, so |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
588 # return a font with the name requested, but an |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
589 # arbitrary style. |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
590 (style, fontname) = list(styles.items())[0] |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
591 # Attempt to style it as requested. This can't |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
592 # unbold or unitalicize anything, but it can |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
593 # fake bold and/or fake italicize. |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
594 if bold and style[0]: |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
595 gotbold = True |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
596 if italic and style[1]: |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
597 gotitalic = True |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
598 elif not fontname: |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
599 fontname = plainname |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
600 elif plainname != fontname: |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
601 gotbold = bold |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
602 gotitalic = italic |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
603 if fontname: |
|
67b60fa1972e
SysFont fix for if there is only italics for a font.
Rene Dudfield <renesd@gmail.com>
parents:
2293
diff
changeset
|
604 break |
| 466 | 605 |
|
2293
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
606 set_bold = set_italic = False |
| 541 | 607 if bold and not gotbold: |
|
2293
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
608 set_bold = True |
| 541 | 609 if italic and not gotitalic: |
|
2293
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
610 set_italic = True |
| 484 | 611 |
|
2293
fb61189ca3f1
sysfont: generalize for other font types
Lenard Lindstrom <len-l@telus.net>
parents:
2175
diff
changeset
|
612 return constructor(fontname, size, set_bold, set_italic) |
| 466 | 613 |
| 614 | |
| 469 | 615 def get_fonts(): |
| 616 """pygame.font.get_fonts() -> list | |
| 466 | 617 get a list of system font names |
| 618 | |
| 619 Returns the list of all found system fonts. Note that | |
| 620 the names of the fonts will be all lowercase with spaces | |
| 621 removed. This is how pygame internally stores the font | |
| 622 names for matching. | |
| 623 """ | |
| 624 if not Sysfonts: | |
| 625 initsysfonts() | |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
626 return list(Sysfonts.keys()) |
| 466 | 627 |
| 628 | |
| 469 | 629 def match_font(name, bold=0, italic=0): |
| 630 """pygame.font.match_font(name, bold=0, italic=0) -> name | |
| 631 find the filename for the named system font | |
| 466 | 632 |
| 633 This performs the same font search as the SysFont() | |
| 634 function, only it returns the path to the TTF file | |
| 635 that would be loaded. The font name can be a comma | |
| 636 separated list of font names to try. | |
| 637 | |
| 638 If no match is found, None is returned. | |
| 639 """ | |
| 640 if not Sysfonts: | |
| 641 initsysfonts() | |
| 642 | |
| 643 fontname = None | |
| 644 allnames = name | |
| 645 for name in allnames.split(','): | |
| 646 name = _simplename(name) | |
| 647 styles = Sysfonts.get(name) | |
| 648 if not styles: | |
| 649 styles = Sysalias.get(name) | |
| 650 if styles: | |
| 651 while not fontname: | |
| 652 fontname = styles.get((bold, italic)) | |
| 653 if italic: | |
| 654 italic = 0 | |
| 655 elif bold: | |
| 656 bold = 0 | |
| 657 elif not fontname: | |
|
1792
dbf60931bdec
additions to font_test.py and sysfont.py
Lenard Lindstrom <len-l@telus.net>
parents:
1791
diff
changeset
|
658 fontname = list(styles.values())[0] |
| 466 | 659 if fontname: break |
| 660 return fontname | |
|
561
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
661 |
|
23d909756029
For windows machines which have two font registry keys. It uses the fonts from both keys instead of just from one. Patch from Atul Varma
Rene Dudfield <renesd@gmail.com>
parents:
546
diff
changeset
|
662 |
