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