Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

fontdatabase.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include <qpe/qpeapplication.h>
00022 #include "fontdatabase.h"
00023 
00024 #include <qpe/qlibrary.h>
00025 
00026 #include <qfontmanager_qws.h>
00027 #include <qdir.h>
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 
00031 static QString fontDir()
00032 {
00033     QString qtdir = getenv("QTDIR");
00034     if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded";
00035     return qtdir+"/lib/fonts/";
00036 }
00037 
00038 #ifdef QT_NO_FONTDATABASE
00039 static QString fontFamily( const QString& key )
00040 {
00041     int u0 = key.find('_');
00042     int u1 = key.find('_',u0+1);
00043     int u2 = key.find('_',u1+1);
00044     QString family = key.left(u0);
00045     //int pointSize = key.mid(u0+1,u1-u0-1).toInt();
00046     //int weight = key.mid(u1+1,u2-u1-1).toInt();
00047     //bool italic = key.mid(u2-1,1) == "i";
00048     // #### ignores _t and _I fields
00049     return family;
00050 }
00051 #endif
00052 
00053 
00054 QValueList<FontFactory> *FontDatabase::factoryList = 0;
00076 FontDatabase::FontDatabase()
00077 #ifndef QT_NO_FONTDATABASE
00078     : QFontDatabase()
00079 #endif
00080 {
00081     if ( !factoryList )
00082         loadRenderers();
00083 }
00084 
00088 QStringList FontDatabase::families() const
00089 {
00090 #ifndef QT_NO_FONTDATABASE
00091     return QFontDatabase::families();
00092 #else
00093 
00094 #ifndef QWS
00095    QStringList list;
00096    return list;
00097 #else
00098     QStringList list;
00099     QDict<void> familyDict;
00100     QDiskFont *qdf;
00101     for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
00102             qdf=qt_fontmanager->diskfonts.next()) {
00103         QString familyname = qdf->name;
00104         if ( !familyDict.find( familyname ) ) {
00105             familyDict.insert( familyname, (void *)1 );
00106             list.append( familyname );
00107         }
00108     }
00109 
00110     QDir dir(fontDir(),"*.qpf");
00111     for (int i=0; i<(int)dir.count(); i++) {
00112         QString familyname = fontFamily(dir[i]);
00113         if ( !familyDict.find( familyname ) ) {
00114             familyDict.insert( familyname, (void *)1 );
00115             list.append( familyname );
00116         }
00117     }
00118 
00119     return list;
00120 #endif
00121 #endif
00122 }
00123 
00124 #ifdef QT_NO_FONTDATABASE
00125 
00128 QValueList<int> FontDatabase::standardSizes()
00129 {
00130     static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
00131                      36, 48, 72, 0 };
00132     static bool first = TRUE;
00133     static QValueList<int> sList;
00134     if ( first ) {
00135         first = FALSE;
00136         int i = 0;
00137         while( s[i] )
00138             sList.append( s[i++] );
00139     }
00140     return sList;
00141 }
00142 
00143 #endif
00144 
00149 void FontDatabase::loadRenderers()
00150 {
00151 #ifndef QWS
00152     return;
00153 #else
00154 
00155 #ifndef QT_NO_COMPONENT
00156     if ( !factoryList )
00157         factoryList = new QValueList<FontFactory>;
00158 
00159     QValueList<FontFactory>::Iterator mit;
00160     for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
00161         qt_fontmanager->factories.setAutoDelete( false );
00162         qt_fontmanager->factories.removeRef( (*mit).factory );
00163         qt_fontmanager->factories.setAutoDelete( true );
00164         (*mit).interface->release();
00165         (*mit).library->unload();
00166         delete (*mit).library;
00167     }
00168     factoryList->clear();
00169 
00170     QString path = QPEApplication::qpeDir() + "plugins/fontfactories";
00171 #ifdef Q_OS_MACX
00172     QDir dir( path, "lib*.dylib" );
00173 #else
00174     QDir dir( path, "lib*.so" );
00175 #endif
00176     
00177     if ( !dir.exists())
00178         return;
00179     
00180     QStringList list = dir.entryList();
00181     QStringList::Iterator it;
00182     for ( it = list.begin(); it != list.end(); ++it ) {
00183         FontFactoryInterface *iface = 0;
00184         QLibrary *lib = new QLibrary( path + "/" + *it );
00185         if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
00186             FontFactory factory;
00187             factory.library = lib;
00188             factory.interface = iface;
00189             factory.factory = factory.interface->fontFactory();
00190             factoryList->append( factory );
00191             qt_fontmanager->factories.append( factory.factory );
00192             readFonts( factory.factory );
00193         } else {
00194             delete lib;
00195         }
00196     }
00197 #endif
00198 #endif
00199 }
00200 
00204 void FontDatabase::readFonts( QFontFactory *factory )
00205 {
00206 #ifndef QWS
00207 return;
00208 #else
00209     // Load in font definition file
00210     QString fn = fontDir() + "fontdir";
00211     FILE* fontdef=fopen(fn.local8Bit(),"r");
00212     if(!fontdef) {
00213         QCString temp=fn.local8Bit();
00214         qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
00215                temp.data());
00216         return;
00217     }
00218     char buf[200]="";
00219     char name[200]="";
00220     char render[200]="";
00221     char file[200]="";
00222     char flags[200]="";
00223     char isitalic[10]="";
00224     fgets(buf,200,fontdef);
00225     while(!feof(fontdef)) {
00226         if ( buf[0] != '#' ) {
00227             int weight=50;
00228             int size=0;
00229             flags[0]=0;
00230             sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
00231             QString filename;
00232             if ( file[0] != '/' )
00233                 filename = fontDir();
00234             filename += file;
00235             if ( QFile::exists(filename) ) {
00236                 if( factory->name() == render ) {
00237                     QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y',
00238                                                   weight,size,flags,filename);
00239                     qt_fontmanager->diskfonts.append(qdf);
00240 #if QT_VERSION >= 232
00241                     QFontDatabase::qwsAddDiskFont( qdf );
00242 #endif
00243                 }
00244             }
00245         }
00246         fgets(buf,200,fontdef);
00247     }
00248     fclose(fontdef);
00249 #endif
00250 }
00251 

Generated on Sat Nov 5 16:16:36 2005 for OPIE by  doxygen 1.4.2