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