summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/fontdatabase.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp
index 899d5cf..c7a5211 100644
--- a/library/fontdatabase.cpp
+++ b/library/fontdatabase.cpp
@@ -1,234 +1,249 @@
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
33static QString fontDir() 33static 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
41static QString fontFamily( const QString& key ) 41static 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
55QValueList<FontFactory> *FontDatabase::factoryList = 0;
56 55
56QValueList<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*/
78FontDatabase::FontDatabase() 78FontDatabase::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*/
90QStringList FontDatabase::families() const 90QStringList 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
96#ifndef QWS
97 QStringList list;
98 return list;
99#else
95 QStringList list; 100 QStringList list;
96 QDict<void> familyDict; 101 QDict<void> familyDict;
97 QDiskFont *qdf; 102 QDiskFont *qdf;
98 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; 103 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
99 qdf=qt_fontmanager->diskfonts.next()) { 104 qdf=qt_fontmanager->diskfonts.next()) {
100 QString familyname = qdf->name; 105 QString familyname = qdf->name;
101 if ( !familyDict.find( familyname ) ) { 106 if ( !familyDict.find( familyname ) ) {
102 familyDict.insert( familyname, (void *)1 ); 107 familyDict.insert( familyname, (void *)1 );
103 list.append( familyname ); 108 list.append( familyname );
104 } 109 }
105 } 110 }
106 111
107 QDir dir(fontDir(),"*.qpf"); 112 QDir dir(fontDir(),"*.qpf");
108 for (int i=0; i<(int)dir.count(); i++) { 113 for (int i=0; i<(int)dir.count(); i++) {
109 QString familyname = fontFamily(dir[i]); 114 QString familyname = fontFamily(dir[i]);
110 if ( !familyDict.find( familyname ) ) { 115 if ( !familyDict.find( familyname ) ) {
111 familyDict.insert( familyname, (void *)1 ); 116 familyDict.insert( familyname, (void *)1 );
112 list.append( familyname ); 117 list.append( familyname );
113 } 118 }
114 } 119 }
115 120
116 return list; 121 return list;
117#endif 122#endif
123#endif
118} 124}
119 125
120#ifdef QT_NO_FONTDATABASE 126#ifdef QT_NO_FONTDATABASE
121/*! 127/*!
122 Returns a list of standard fontsizes. 128 Returns a list of standard fontsizes.
123*/ 129*/
124QValueList<int> FontDatabase::standardSizes() 130QValueList<int> FontDatabase::standardSizes()
125{ 131{
126 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,
127 36, 48, 72, 0 }; 133 36, 48, 72, 0 };
128 static bool first = TRUE; 134 static bool first = TRUE;
129 static QValueList<int> sList; 135 static QValueList<int> sList;
130 if ( first ) { 136 if ( first ) {
131 first = FALSE; 137 first = FALSE;
132 int i = 0; 138 int i = 0;
133 while( s[i] ) 139 while( s[i] )
134 sList.append( s[i++] ); 140 sList.append( s[i++] );
135 } 141 }
136 return sList; 142 return sList;
137} 143}
138 144
139#endif 145#endif
140 146
141/*! 147/*!
142 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
143 that the plugins can read available. 149 that the plugins can read available.
144*/ 150*/
145void FontDatabase::loadRenderers() 151void FontDatabase::loadRenderers()
146{ 152{
153#ifndef QWS
154 return;
155#else
156
147#ifndef QT_NO_COMPONENT 157#ifndef QT_NO_COMPONENT
148 if ( !factoryList ) 158 if ( !factoryList )
149 factoryList = new QValueList<FontFactory>; 159 factoryList = new QValueList<FontFactory>;
150 160
151 QValueList<FontFactory>::Iterator mit; 161 QValueList<FontFactory>::Iterator mit;
152 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { 162 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
153 qt_fontmanager->factories.setAutoDelete( false ); 163 qt_fontmanager->factories.setAutoDelete( false );
154 qt_fontmanager->factories.removeRef( (*mit).factory ); 164 qt_fontmanager->factories.removeRef( (*mit).factory );
155 qt_fontmanager->factories.setAutoDelete( true ); 165 qt_fontmanager->factories.setAutoDelete( true );
156 (*mit).interface->release(); 166 (*mit).interface->release();
157 (*mit).library->unload(); 167 (*mit).library->unload();
158 delete (*mit).library; 168 delete (*mit).library;
159 } 169 }
160 factoryList->clear(); 170 factoryList->clear();
161 171
162 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; 172 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories";
163 QDir dir( path, "lib*.so" ); 173 QDir dir( path, "lib*.so" );
164 174
165 if ( !dir.exists()) 175 if ( !dir.exists())
166 return; 176 return;
167 177
168 QStringList list = dir.entryList(); 178 QStringList list = dir.entryList();
169 QStringList::Iterator it; 179 QStringList::Iterator it;
170 for ( it = list.begin(); it != list.end(); ++it ) { 180 for ( it = list.begin(); it != list.end(); ++it ) {
171 FontFactoryInterface *iface = 0; 181 FontFactoryInterface *iface = 0;
172 QLibrary *lib = new QLibrary( path + "/" + *it ); 182 QLibrary *lib = new QLibrary( path + "/" + *it );
173 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { 183 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
174 FontFactory factory; 184 FontFactory factory;
175 factory.library = lib; 185 factory.library = lib;
176 factory.interface = iface; 186 factory.interface = iface;
177 factory.factory = factory.interface->fontFactory(); 187 factory.factory = factory.interface->fontFactory();
178 factoryList->append( factory ); 188 factoryList->append( factory );
179 qt_fontmanager->factories.append( factory.factory ); 189 qt_fontmanager->factories.append( factory.factory );
180 readFonts( factory.factory ); 190 readFonts( factory.factory );
181 } else { 191 } else {
182 delete lib; 192 delete lib;
183 } 193 }
184 } 194 }
185#endif 195#endif
196#endif
186} 197}
187 198
188/*! 199/*!
189 \internal 200 \internal
190*/ 201*/
191void FontDatabase::readFonts( QFontFactory *factory ) 202void FontDatabase::readFonts( QFontFactory *factory )
192{ 203{
204#ifndef QWS
205return;
206#else
193 // Load in font definition file 207 // Load in font definition file
194 QString fn = fontDir() + "fontdir"; 208 QString fn = fontDir() + "fontdir";
195 FILE* fontdef=fopen(fn.local8Bit(),"r"); 209 FILE* fontdef=fopen(fn.local8Bit(),"r");
196 if(!fontdef) { 210 if(!fontdef) {
197 QCString temp=fn.local8Bit(); 211 QCString temp=fn.local8Bit();
198 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", 212 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
199 temp.data()); 213 temp.data());
200 return; 214 return;
201 } 215 }
202 char buf[200]=""; 216 char buf[200]="";
203 char name[200]=""; 217 char name[200]="";
204 char render[200]=""; 218 char render[200]="";
205 char file[200]=""; 219 char file[200]="";
206 char flags[200]=""; 220 char flags[200]="";
207 char isitalic[10]=""; 221 char isitalic[10]="";
208 fgets(buf,200,fontdef); 222 fgets(buf,200,fontdef);
209 while(!feof(fontdef)) { 223 while(!feof(fontdef)) {
210 if ( buf[0] != '#' ) { 224 if ( buf[0] != '#' ) {
211 int weight=50; 225 int weight=50;
212 int size=0; 226 int size=0;
213 flags[0]=0; 227 flags[0]=0;
214 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); 228 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
215 QString filename; 229 QString filename;
216 if ( file[0] != '/' ) 230 if ( file[0] != '/' )
217 filename = fontDir(); 231 filename = fontDir();
218 filename += file; 232 filename += file;
219 if ( QFile::exists(filename) ) { 233 if ( QFile::exists(filename) ) {
220 if( factory->name() == render ) { 234 if( factory->name() == render ) {
221 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', 235 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y',
222 weight,size,flags,filename); 236 weight,size,flags,filename);
223 qt_fontmanager->diskfonts.append(qdf); 237 qt_fontmanager->diskfonts.append(qdf);
224#if QT_VERSION >= 232 238#if QT_VERSION >= 232
225 QFontDatabase::qwsAddDiskFont( qdf ); 239 QFontDatabase::qwsAddDiskFont( qdf );
226#endif 240#endif
227 } 241 }
228 } 242 }
229 } 243 }
230 fgets(buf,200,fontdef); 244 fgets(buf,200,fontdef);
231 } 245 }
232 fclose(fontdef); 246 fclose(fontdef);
247#endif
233} 248}
234 249