Qtopia library API Documentation

fontmanager.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 "fontmanager.h"
00022 #include <qfile.h>
00023 #include <stdlib.h>
00024 #include <qgfx_qws.h>
00025 
00026 
00027 
00028 /*
00029     QFontInfo doesn't work in QWS at the moment,
00030     otherwise we would just have used that to check
00031     the real values
00032     
00033      For now, there are only two Unicode fonts in
00034      the known universe...
00035     
00036 */
00037 
00038 bool FontManager::hasUnicodeFont()
00039 {
00040     QString fontDir = getenv("QTDIR") + QString("/lib/fonts/");
00041 
00042     QString suffix;
00043     if ( qt_screen->isTransformed() ) {
00044     suffix += "_t";
00045     QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2));
00046     QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2));
00047     suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) );
00048     }
00049     suffix += ".qpf";
00050 
00051     return QFile::exists( fontDir+"cyberbit_120_50"+suffix )
00052     || QFile::exists( fontDir+"unifont_160_50"+suffix ) ||
00053     QFile::exists( fontDir+"arial_140_50" + suffix );
00054 }
00055 
00056 QFont FontManager::unicodeFont( Spacing sp )
00057 {
00058     QString key;
00059     QString fontName;
00060     QString fontDir = getenv("QTDIR") + QString("/lib/fonts/");
00061 
00062     int size;
00063     if ( sp == Proportional ) {
00064     fontName = "Arial";
00065     size=14;
00066     key = "arial_140_50";
00067     } else {
00068     fontName = "Unifont";
00069     size=16;
00070     key = "unifont_160_50";
00071     }
00072     
00073     QString suffix;
00074     if ( qt_screen->isTransformed() ) {
00075     suffix += "_t";
00076     QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2));
00077     QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2));
00078     suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) );
00079     }
00080     suffix += ".qpf";
00081 
00082     // if we cannot find it, try the other one
00083     
00084     if ( !QFile::exists(fontDir+key+suffix) ) {
00085     key = (sp == Fixed ) ? "arial_140_50" : "unifont_160_50";
00086     if ( QFile::exists(fontDir+key+suffix) ) {
00087         fontName = (sp == Fixed) ? "Arial" : "Unifont";
00088         size = (sp == Fixed) ? 14 : 16;
00089     } else {
00090         key = "cyberbit_120_50";
00091         if ( QFile::exists(fontDir+key+suffix) ) {
00092         fontName = "Cyberbit";
00093         size = 12;
00094         } else {
00095         fontName = "Helvetica";
00096         size = 14;
00097         }
00098     }
00099     }
00100     return QFont(fontName,size);
00101 }
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