-rw-r--r-- | library/fontdatabase.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp index c7a5211..2ad8e95 100644 --- a/library/fontdatabase.cpp +++ b/library/fontdatabase.cpp | |||
@@ -1,249 +1,253 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
22 | #include "fontfactoryinterface.h" | 22 | #include "fontfactoryinterface.h" |
23 | #include "fontdatabase.h" | 23 | #include "fontdatabase.h" |
24 | 24 | ||
25 | #include <qpe/qlibrary.h> | 25 | #include <qpe/qlibrary.h> |
26 | 26 | ||
27 | #include <qfontmanager_qws.h> | 27 | #include <qfontmanager_qws.h> |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | #include <stdio.h> | 30 | #include <stdio.h> |
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | 32 | ||
33 | static QString fontDir() | 33 | static QString fontDir() |
34 | { | 34 | { |
35 | QString qtdir = getenv("QTDIR"); | 35 | QString qtdir = getenv("QTDIR"); |
36 | if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded"; | 36 | if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded"; |
37 | return qtdir+"/lib/fonts/"; | 37 | return qtdir+"/lib/fonts/"; |
38 | } | 38 | } |
39 | 39 | ||
40 | #ifdef QT_NO_FONTDATABASE | 40 | #ifdef QT_NO_FONTDATABASE |
41 | static QString fontFamily( const QString& key ) | 41 | static QString fontFamily( const QString& key ) |
42 | { | 42 | { |
43 | int u0 = key.find('_'); | 43 | int u0 = key.find('_'); |
44 | int u1 = key.find('_',u0+1); | 44 | int u1 = key.find('_',u0+1); |
45 | int u2 = key.find('_',u1+1); | 45 | int u2 = key.find('_',u1+1); |
46 | QString family = key.left(u0); | 46 | QString family = key.left(u0); |
47 | //int pointSize = key.mid(u0+1,u1-u0-1).toInt(); | 47 | //int pointSize = key.mid(u0+1,u1-u0-1).toInt(); |
48 | //int weight = key.mid(u1+1,u2-u1-1).toInt(); | 48 | //int weight = key.mid(u1+1,u2-u1-1).toInt(); |
49 | //bool italic = key.mid(u2-1,1) == "i"; | 49 | //bool italic = key.mid(u2-1,1) == "i"; |
50 | // #### ignores _t and _I fields | 50 | // #### ignores _t and _I fields |
51 | return family; | 51 | return family; |
52 | } | 52 | } |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | 55 | ||
56 | QValueList<FontFactory> *FontDatabase::factoryList = 0; | 56 | QValueList<FontFactory> *FontDatabase::factoryList = 0; |
57 | /*! | 57 | /*! |
58 | \class FontDatabase fontdatabase.h | 58 | \class FontDatabase fontdatabase.h |
59 | \brief The FontDatabase class provides information about available fonts. | 59 | \brief The FontDatabase class provides information about available fonts. |
60 | 60 | ||
61 | Most often you will simply want to query the database for the | 61 | Most often you will simply want to query the database for the |
62 | available font families(). | 62 | available font families(). |
63 | 63 | ||
64 | Use FontDatabase rather than QFontDatabase when you may need access | 64 | Use FontDatabase rather than QFontDatabase when you may need access |
65 | to fonts that are not normally available. For example, if the | 65 | to fonts that are not normally available. For example, if the |
66 | freetype library and the Qtopia freetype plugin are installed, | 66 | freetype library and the Qtopia freetype plugin are installed, |
67 | TrueType fonts will be available to your application. Font renderer | 67 | TrueType fonts will be available to your application. Font renderer |
68 | plugins have greater resource requirements than system fonts so they | 68 | plugins have greater resource requirements than system fonts so they |
69 | should be used only when necessary. You can force the loading of | 69 | should be used only when necessary. You can force the loading of |
70 | font renderer plugins with loadRenderers(). | 70 | font renderer plugins with loadRenderers(). |
71 | 71 | ||
72 | \ingroup qtopiaemb | 72 | \ingroup qtopiaemb |
73 | */ | 73 | */ |
74 | 74 | ||
75 | /*! | 75 | /*! |
76 | Constructs a FontDatabase object. | 76 | Constructs a FontDatabase object. |
77 | */ | 77 | */ |
78 | FontDatabase::FontDatabase() | 78 | FontDatabase::FontDatabase() |
79 | #ifndef QT_NO_FONTDATABASE | 79 | #ifndef QT_NO_FONTDATABASE |
80 | : QFontDatabase() | 80 | : QFontDatabase() |
81 | #endif | 81 | #endif |
82 | { | 82 | { |
83 | if ( !factoryList ) | 83 | if ( !factoryList ) |
84 | loadRenderers(); | 84 | loadRenderers(); |
85 | } | 85 | } |
86 | 86 | ||
87 | /*! | 87 | /*! |
88 | Returns a list of names of all the available font families. | 88 | Returns a list of names of all the available font families. |
89 | */ | 89 | */ |
90 | QStringList FontDatabase::families() const | 90 | QStringList FontDatabase::families() const |
91 | { | 91 | { |
92 | #ifndef QT_NO_FONTDATABASE | 92 | #ifndef QT_NO_FONTDATABASE |
93 | return QFontDatabase::families(); | 93 | return QFontDatabase::families(); |
94 | #else | 94 | #else |
95 | 95 | ||
96 | #ifndef QWS | 96 | #ifndef QWS |
97 | QStringList list; | 97 | QStringList list; |
98 | return list; | 98 | return list; |
99 | #else | 99 | #else |
100 | QStringList list; | 100 | QStringList list; |
101 | QDict<void> familyDict; | 101 | QDict<void> familyDict; |
102 | QDiskFont *qdf; | 102 | QDiskFont *qdf; |
103 | for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; | 103 | for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; |
104 | qdf=qt_fontmanager->diskfonts.next()) { | 104 | qdf=qt_fontmanager->diskfonts.next()) { |
105 | QString familyname = qdf->name; | 105 | QString familyname = qdf->name; |
106 | if ( !familyDict.find( familyname ) ) { | 106 | if ( !familyDict.find( familyname ) ) { |
107 | familyDict.insert( familyname, (void *)1 ); | 107 | familyDict.insert( familyname, (void *)1 ); |
108 | list.append( familyname ); | 108 | list.append( familyname ); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
112 | QDir dir(fontDir(),"*.qpf"); | 112 | QDir dir(fontDir(),"*.qpf"); |
113 | for (int i=0; i<(int)dir.count(); i++) { | 113 | for (int i=0; i<(int)dir.count(); i++) { |
114 | QString familyname = fontFamily(dir[i]); | 114 | QString familyname = fontFamily(dir[i]); |
115 | if ( !familyDict.find( familyname ) ) { | 115 | if ( !familyDict.find( familyname ) ) { |
116 | familyDict.insert( familyname, (void *)1 ); | 116 | familyDict.insert( familyname, (void *)1 ); |
117 | list.append( familyname ); | 117 | list.append( familyname ); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | return list; | 121 | return list; |
122 | #endif | 122 | #endif |
123 | #endif | 123 | #endif |
124 | } | 124 | } |
125 | 125 | ||
126 | #ifdef QT_NO_FONTDATABASE | 126 | #ifdef QT_NO_FONTDATABASE |
127 | /*! | 127 | /*! |
128 | Returns a list of standard fontsizes. | 128 | Returns a list of standard fontsizes. |
129 | */ | 129 | */ |
130 | QValueList<int> FontDatabase::standardSizes() | 130 | QValueList<int> FontDatabase::standardSizes() |
131 | { | 131 | { |
132 | static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, | 132 | static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, |
133 | 36, 48, 72, 0 }; | 133 | 36, 48, 72, 0 }; |
134 | static bool first = TRUE; | 134 | static bool first = TRUE; |
135 | static QValueList<int> sList; | 135 | static QValueList<int> sList; |
136 | if ( first ) { | 136 | if ( first ) { |
137 | first = FALSE; | 137 | first = FALSE; |
138 | int i = 0; | 138 | int i = 0; |
139 | while( s[i] ) | 139 | while( s[i] ) |
140 | sList.append( s[i++] ); | 140 | sList.append( s[i++] ); |
141 | } | 141 | } |
142 | return sList; | 142 | return sList; |
143 | } | 143 | } |
144 | 144 | ||
145 | #endif | 145 | #endif |
146 | 146 | ||
147 | /*! | 147 | /*! |
148 | Load any font renderer plugins that are available and make the fonts | 148 | Load any font renderer plugins that are available and make the fonts |
149 | that the plugins can read available. | 149 | that the plugins can read available. |
150 | */ | 150 | */ |
151 | void FontDatabase::loadRenderers() | 151 | void FontDatabase::loadRenderers() |
152 | { | 152 | { |
153 | #ifndef QWS | 153 | #ifndef QWS |
154 | return; | 154 | return; |
155 | #else | 155 | #else |
156 | 156 | ||
157 | #ifndef QT_NO_COMPONENT | 157 | #ifndef QT_NO_COMPONENT |
158 | if ( !factoryList ) | 158 | if ( !factoryList ) |
159 | factoryList = new QValueList<FontFactory>; | 159 | factoryList = new QValueList<FontFactory>; |
160 | 160 | ||
161 | QValueList<FontFactory>::Iterator mit; | 161 | QValueList<FontFactory>::Iterator mit; |
162 | for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { | 162 | for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { |
163 | qt_fontmanager->factories.setAutoDelete( false ); | 163 | qt_fontmanager->factories.setAutoDelete( false ); |
164 | qt_fontmanager->factories.removeRef( (*mit).factory ); | 164 | qt_fontmanager->factories.removeRef( (*mit).factory ); |
165 | qt_fontmanager->factories.setAutoDelete( true ); | 165 | qt_fontmanager->factories.setAutoDelete( true ); |
166 | (*mit).interface->release(); | 166 | (*mit).interface->release(); |
167 | (*mit).library->unload(); | 167 | (*mit).library->unload(); |
168 | delete (*mit).library; | 168 | delete (*mit).library; |
169 | } | 169 | } |
170 | factoryList->clear(); | 170 | factoryList->clear(); |
171 | 171 | ||
172 | QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; | 172 | QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; |
173 | #ifdef Q_OS_MACX | ||
174 | QDir dir( path, "lib*.dylib" ); | ||
175 | #else | ||
173 | QDir dir( path, "lib*.so" ); | 176 | QDir dir( path, "lib*.so" ); |
177 | #endif | ||
174 | 178 | ||
175 | if ( !dir.exists()) | 179 | if ( !dir.exists()) |
176 | return; | 180 | return; |
177 | 181 | ||
178 | QStringList list = dir.entryList(); | 182 | QStringList list = dir.entryList(); |
179 | QStringList::Iterator it; | 183 | QStringList::Iterator it; |
180 | for ( it = list.begin(); it != list.end(); ++it ) { | 184 | for ( it = list.begin(); it != list.end(); ++it ) { |
181 | FontFactoryInterface *iface = 0; | 185 | FontFactoryInterface *iface = 0; |
182 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 186 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
183 | if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { | 187 | if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { |
184 | FontFactory factory; | 188 | FontFactory factory; |
185 | factory.library = lib; | 189 | factory.library = lib; |
186 | factory.interface = iface; | 190 | factory.interface = iface; |
187 | factory.factory = factory.interface->fontFactory(); | 191 | factory.factory = factory.interface->fontFactory(); |
188 | factoryList->append( factory ); | 192 | factoryList->append( factory ); |
189 | qt_fontmanager->factories.append( factory.factory ); | 193 | qt_fontmanager->factories.append( factory.factory ); |
190 | readFonts( factory.factory ); | 194 | readFonts( factory.factory ); |
191 | } else { | 195 | } else { |
192 | delete lib; | 196 | delete lib; |
193 | } | 197 | } |
194 | } | 198 | } |
195 | #endif | 199 | #endif |
196 | #endif | 200 | #endif |
197 | } | 201 | } |
198 | 202 | ||
199 | /*! | 203 | /*! |
200 | \internal | 204 | \internal |
201 | */ | 205 | */ |
202 | void FontDatabase::readFonts( QFontFactory *factory ) | 206 | void FontDatabase::readFonts( QFontFactory *factory ) |
203 | { | 207 | { |
204 | #ifndef QWS | 208 | #ifndef QWS |
205 | return; | 209 | return; |
206 | #else | 210 | #else |
207 | // Load in font definition file | 211 | // Load in font definition file |
208 | QString fn = fontDir() + "fontdir"; | 212 | QString fn = fontDir() + "fontdir"; |
209 | FILE* fontdef=fopen(fn.local8Bit(),"r"); | 213 | FILE* fontdef=fopen(fn.local8Bit(),"r"); |
210 | if(!fontdef) { | 214 | if(!fontdef) { |
211 | QCString temp=fn.local8Bit(); | 215 | QCString temp=fn.local8Bit(); |
212 | qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", | 216 | qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", |
213 | temp.data()); | 217 | temp.data()); |
214 | return; | 218 | return; |
215 | } | 219 | } |
216 | char buf[200]=""; | 220 | char buf[200]=""; |
217 | char name[200]=""; | 221 | char name[200]=""; |
218 | char render[200]=""; | 222 | char render[200]=""; |
219 | char file[200]=""; | 223 | char file[200]=""; |
220 | char flags[200]=""; | 224 | char flags[200]=""; |
221 | char isitalic[10]=""; | 225 | char isitalic[10]=""; |
222 | fgets(buf,200,fontdef); | 226 | fgets(buf,200,fontdef); |
223 | while(!feof(fontdef)) { | 227 | while(!feof(fontdef)) { |
224 | if ( buf[0] != '#' ) { | 228 | if ( buf[0] != '#' ) { |
225 | int weight=50; | 229 | int weight=50; |
226 | int size=0; | 230 | int size=0; |
227 | flags[0]=0; | 231 | flags[0]=0; |
228 | sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); | 232 | sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); |
229 | QString filename; | 233 | QString filename; |
230 | if ( file[0] != '/' ) | 234 | if ( file[0] != '/' ) |
231 | filename = fontDir(); | 235 | filename = fontDir(); |
232 | filename += file; | 236 | filename += file; |
233 | if ( QFile::exists(filename) ) { | 237 | if ( QFile::exists(filename) ) { |
234 | if( factory->name() == render ) { | 238 | if( factory->name() == render ) { |
235 | QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', | 239 | QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', |
236 | weight,size,flags,filename); | 240 | weight,size,flags,filename); |
237 | qt_fontmanager->diskfonts.append(qdf); | 241 | qt_fontmanager->diskfonts.append(qdf); |
238 | #if QT_VERSION >= 232 | 242 | #if QT_VERSION >= 232 |
239 | QFontDatabase::qwsAddDiskFont( qdf ); | 243 | QFontDatabase::qwsAddDiskFont( qdf ); |
240 | #endif | 244 | #endif |
241 | } | 245 | } |
242 | } | 246 | } |
243 | } | 247 | } |
244 | fgets(buf,200,fontdef); | 248 | fgets(buf,200,fontdef); |
245 | } | 249 | } |
246 | fclose(fontdef); | 250 | fclose(fontdef); |
247 | #endif | 251 | #endif |
248 | } | 252 | } |
249 | 253 | ||