Qtopia library API Documentation

fontdatabase.cpp

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 "fontfactoryinterface.h"
00023 #include "fontdatabase.h"
00024 
00025 #include <qpe/qlibrary.h>
00026 
00027 #include <qfontmanager_qws.h>
00028 #include <qdir.h>
00029 #include <qdict.h>
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 
00033 static QString fontDir()
00034 {
00035     QString qtdir = getenv("QTDIR");
00036     if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded";
00037     return qtdir+"/lib/fonts/";
00038 }
00039 
00040 #ifdef QT_NO_FONTDATABASE
00041 static QString fontFamily( const QString& key )
00042 {
00043     int u0 = key.find('_');
00044     int u1 = key.find('_',u0+1);
00045     int u2 = key.find('_',u1+1);
00046     QString family = key.left(u0);
00047     //int pointSize = key.mid(u0+1,u1-u0-1).toInt();
00048     //int weight = key.mid(u1+1,u2-u1-1).toInt();
00049     //bool italic = key.mid(u2-1,1) == "i";
00050     // #### ignores _t and _I fields
00051     return family;
00052 }
00053 #endif
00054 
00055 
00056 QValueList<FontFactory> *FontDatabase::factoryList = 0;
00078 FontDatabase::FontDatabase()
00079 #ifndef QT_NO_FONTDATABASE
00080     : QFontDatabase()
00081 #endif
00082 {
00083     if ( !factoryList )
00084     loadRenderers();
00085 }
00086 
00090 QStringList FontDatabase::families() const
00091 {
00092 #ifndef QT_NO_FONTDATABASE
00093     return QFontDatabase::families();
00094 #else
00095 
00096 #ifndef QWS
00097    QStringList list;
00098    return list;
00099 #else
00100     QStringList list;
00101     QDict<void> familyDict;
00102     QDiskFont *qdf;
00103     for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
00104             qdf=qt_fontmanager->diskfonts.next()) {
00105     QString familyname = qdf->name;
00106     if ( !familyDict.find( familyname ) ) {
00107         familyDict.insert( familyname, (void *)1 );
00108         list.append( familyname );
00109     }
00110     }
00111 
00112     QDir dir(fontDir(),"*.qpf");
00113     for (int i=0; i<(int)dir.count(); i++) {
00114     QString familyname = fontFamily(dir[i]);
00115     if ( !familyDict.find( familyname ) ) {
00116         familyDict.insert( familyname, (void *)1 );
00117         list.append( familyname );
00118     }
00119     }
00120 
00121     return list;
00122 #endif
00123 #endif
00124 }
00125 
00126 #ifdef QT_NO_FONTDATABASE
00127 
00130 QValueList<int> FontDatabase::standardSizes()
00131 {
00132     static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
00133              36, 48, 72, 0 };
00134     static bool first = TRUE;
00135     static QValueList<int> sList;
00136     if ( first ) {
00137     first = FALSE;
00138     int i = 0;
00139     while( s[i] )
00140         sList.append( s[i++] );
00141     }
00142     return sList;
00143 }
00144 
00145 #endif
00146 
00151 void FontDatabase::loadRenderers()
00152 {
00153 #ifndef QWS
00154     return;
00155 #else
00156 
00157 #ifndef QT_NO_COMPONENT
00158     if ( !factoryList )
00159     factoryList = new QValueList<FontFactory>;
00160 
00161     QValueList<FontFactory>::Iterator mit;
00162     for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
00163     qt_fontmanager->factories.setAutoDelete( false );
00164     qt_fontmanager->factories.removeRef( (*mit).factory );
00165     qt_fontmanager->factories.setAutoDelete( true );
00166     (*mit).interface->release();
00167     (*mit).library->unload();
00168     delete (*mit).library;
00169     }
00170     factoryList->clear();
00171 
00172     QString path = QPEApplication::qpeDir() + "/plugins/fontfactories";
00173 #ifdef Q_OS_MACX
00174     QDir dir( path, "lib*.dylib" );
00175 #else
00176     QDir dir( path, "lib*.so" );
00177 #endif
00178     
00179     if ( !dir.exists())
00180         return;
00181     
00182     QStringList list = dir.entryList();
00183     QStringList::Iterator it;
00184     for ( it = list.begin(); it != list.end(); ++it ) {
00185     FontFactoryInterface *iface = 0;
00186     QLibrary *lib = new QLibrary( path + "/" + *it );
00187     if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
00188         FontFactory factory;
00189         factory.library = lib;
00190         factory.interface = iface;
00191         factory.factory = factory.interface->fontFactory();
00192         factoryList->append( factory );
00193         qt_fontmanager->factories.append( factory.factory );
00194         readFonts( factory.factory );
00195     } else {
00196         delete lib;
00197     }
00198     }
00199 #endif
00200 #endif
00201 }
00202 
00206 void FontDatabase::readFonts( QFontFactory *factory )
00207 {
00208 #ifndef QWS
00209 return;
00210 #else
00211     // Load in font definition file
00212     QString fn = fontDir() + "fontdir";
00213     FILE* fontdef=fopen(fn.local8Bit(),"r");
00214     if(!fontdef) {
00215     QCString temp=fn.local8Bit();
00216     qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
00217            temp.data());
00218     return;
00219     }
00220     char buf[200]="";
00221     char name[200]="";
00222     char render[200]="";
00223     char file[200]="";
00224     char flags[200]="";
00225     char isitalic[10]="";
00226     fgets(buf,200,fontdef);
00227     while(!feof(fontdef)) {
00228     if ( buf[0] != '#' ) {
00229         int weight=50;
00230         int size=0;
00231         flags[0]=0;
00232         sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
00233         QString filename;
00234         if ( file[0] != '/' )
00235         filename = fontDir();
00236         filename += file;
00237         if ( QFile::exists(filename) ) {
00238         if( factory->name() == render ) {
00239             QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y',
00240                           weight,size,flags,filename);
00241             qt_fontmanager->diskfonts.append(qdf);
00242 #if QT_VERSION >= 232
00243             QFontDatabase::qwsAddDiskFont( qdf );
00244 #endif
00245         }
00246         }
00247     }
00248     fgets(buf,200,fontdef);
00249     }
00250     fclose(fontdef);
00251 #endif
00252 }
00253 
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:05 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001