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