Eneboo - Documentación para desarrolladores
src/qt/include/private/qfontdata_p.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qfontdata_p.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of internal QFontData struct
00005 **
00006 ** Created : 941229
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QFONTDATA_P_H
00039 #define QFONTDATA_P_H
00040 
00041 //
00042 //  W A R N I N G
00043 //  -------------
00044 //
00045 // This file is not part of the Qt API.  It exists for the convenience
00046 // of internal files.  This header file may change from version to version
00047 // without notice, or even be removed.
00048 //
00049 // We mean it.
00050 //
00051 //
00052 
00053 #include "qobject.h"
00054 #include "qfont.h"
00055 #include "qpaintdevicemetrics.h"
00056 
00057 // forwards
00058 class QFontEngine;
00059 class QPaintDevice;
00060 
00061 
00062 struct QFontDef
00063 {
00064     inline QFontDef()
00065         : pointSize( -1 ), pixelSize( -1 ),
00066           styleHint( QFont::AnyStyle ), styleStrategy( QFont::PreferDefault ),
00067           weight( 50 ), italic( FALSE ), fixedPitch( FALSE ), stretch( 100 ),
00068           ignorePitch(TRUE)
00069 #ifdef Q_WS_MAC
00070           ,fixedPitchComputed(FALSE)
00071 #endif
00072     {
00073     }
00074 
00075     QString family;
00076 
00077 #ifdef Q_WS_X11
00078     QString addStyle;
00079 #endif // Q_WS_X11
00080 
00081     int pointSize;
00082     int pixelSize;
00083 
00084     uint styleHint     : 8;
00085     uint styleStrategy : 16;
00086 
00087     uint weight     :  7; // 0-99
00088     uint italic     :  1;
00089     uint fixedPitch :  1;
00090     uint stretch    : 12; // 0-400
00091 
00092     uint ignorePitch : 1;
00093     uint fixedPitchComputed : 1; // for Mac OS X only
00094     uint reserved   : 14; // for future extensions
00095 
00096     bool operator==( const QFontDef &other ) const;
00097     inline bool operator<( const QFontDef &other ) const
00098     {
00099         if ( pixelSize != other.pixelSize ) return pixelSize < other.pixelSize;
00100         if ( weight != other.weight ) return weight < other.weight;
00101         if ( italic != other.italic ) return italic < other.italic;
00102         if ( stretch != other.stretch ) return stretch < other.stretch;
00103         if ( styleHint != other.styleHint ) return styleHint < other.styleHint;
00104         if ( styleStrategy != other.styleStrategy ) return styleStrategy < other.styleStrategy;
00105         if ( family != other.family ) return family < other.family;
00106 
00107 #ifdef Q_WS_X11
00108         if ( addStyle != other.addStyle ) return addStyle < other.addStyle;
00109 #endif // Q_WS_X11
00110 
00111         return FALSE;
00112     }
00113 };
00114 
00115 class QFontEngineData : public QShared
00116 {
00117 public:
00118     QFontEngineData();
00119     ~QFontEngineData();
00120 
00121     uint lineWidth;
00122 
00123 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
00124     QFontEngine *engines[QFont::LastPrivateScript];
00125 #else
00126     QFontEngine *engine;
00127 #endif // Q_WS_X11 || Q_WS_WIN
00128 #ifndef Q_WS_MAC
00129     enum { widthCacheSize = 0x500 };
00130     uchar widthCache[widthCacheSize];
00131 #endif
00132 };
00133 
00134 
00135 class Q_EXPORT QFontPrivate : public QShared
00136 {
00137 public:
00138     static QFont::Script defaultScript;
00139 #ifdef Q_WS_X11
00140     static int defaultEncodingID;
00141 #endif // Q_WS_X11
00142 
00143     QFontPrivate();
00144     QFontPrivate( const QFontPrivate &other );
00145     ~QFontPrivate();
00146 
00147     void load( QFont::Script script );
00148     QFontEngine *engineForScript( QFont::Script script ) const {
00149         if ( script == QFont::NoScript )
00150             script = QFontPrivate::defaultScript;
00151 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
00152         if ( ! engineData || ! engineData->engines[script] )
00153             ((QFontPrivate *) this)->load( script );
00154         return engineData->engines[script];
00155 #else
00156         if ( ! engineData || ! engineData->engine )
00157             ((QFontPrivate *) this)->load( script );
00158         return engineData->engine;
00159 #endif // Q_WS_X11 || Q_WS_WIN
00160     }
00161 
00162     QFontDef request;
00163     QFontEngineData *engineData;
00164     QPaintDevice *paintdevice;
00165     int screen;
00166 
00167     uint rawMode    :  1;
00168     uint underline  :  1;
00169     uint overline   :  1;
00170     uint strikeOut  :  1;
00171 
00172     enum {
00173         Family        = 0x0001,
00174         Size          = 0x0002,
00175         StyleHint     = 0x0004,
00176         StyleStrategy = 0x0008,
00177         Weight        = 0x0010,
00178         Italic        = 0x0020,
00179         Underline     = 0x0040,
00180         Overline      = 0x0080,
00181         StrikeOut     = 0x0100,
00182         FixedPitch    = 0x0200,
00183         Stretch       = 0x0400,
00184         Complete      = 0x07ff
00185     };
00186 
00187     uint mask;
00188 
00189     void resolve( const QFontPrivate *other );
00190 };
00191 
00192 
00193 class QFontCache : public QObject
00194 {
00195 public:
00196     static QFontCache *instance;
00197 
00198     QFontCache();
00199     ~QFontCache();
00200 
00201 #ifdef Q_WS_QWS
00202     void clear();
00203 #endif
00204     // universal key structure.  QFontEngineDatas and QFontEngines are cached using
00205     // the same keys
00206     struct Key {
00207         Key() : script(0), screen( 0 ), dpi(0) { }
00208         Key( const QFontDef &d, QFont::Script c, int s, QPaintDevice *pdev )
00209             : script(c), screen(s) {
00210             def = d;
00211 #ifdef Q_WS_X11
00212             dpi = pdev ? QPaintDeviceMetrics(pdev).logicalDpiY() : 0;
00213 #else
00214             Q_UNUSED(pdev);
00215             dpi = 0;
00216 #endif
00217         }
00218 
00219         QFontDef def;
00220         int script;
00221         int screen;
00222         int dpi;
00223 
00224         inline bool operator<( const Key &other ) const
00225         {
00226             if ( script != other.script ) return script < other.script;
00227             if ( screen != other.screen ) return screen < other.screen;
00228             if ( dpi != other.dpi ) return dpi < other.dpi;
00229             return def < other.def;
00230         }
00231         inline bool operator==( const Key &other ) const
00232         { return def == other.def && script == other.script &&
00233                 screen == other.screen && dpi == other.dpi; }
00234     };
00235 
00236     // QFontEngineData cache
00237     typedef QMap<Key,QFontEngineData*> EngineDataCache;
00238     EngineDataCache engineDataCache;
00239 
00240     QFontEngineData *findEngineData( const Key &key ) const;
00241     void insertEngineData( const Key &key, QFontEngineData *engineData );
00242 
00243     // QFontEngine cache
00244     struct Engine {
00245         Engine() : data( 0 ), timestamp( 0 ), hits( 0 ) { }
00246         Engine( QFontEngine *d ) : data( d ), timestamp( 0 ), hits( 0 ) { }
00247 
00248         QFontEngine *data;
00249         uint timestamp;
00250         uint hits;
00251     };
00252 
00253     typedef QMap<Key,Engine> EngineCache;
00254     EngineCache engineCache;
00255 
00256     QFontEngine *findEngine( const Key &key );
00257     void insertEngine( const Key &key, QFontEngine *engine );
00258 
00259 #if defined(Q_WS_WIN) || defined(Q_WS_QWS)
00260     void cleanupPrinterFonts();
00261 #endif
00262 
00263     private:
00264     void increaseCost( uint cost );
00265     void decreaseCost( uint cost );
00266     void timerEvent( QTimerEvent *event );
00267 
00268     static const uint min_cost;
00269     uint total_cost, max_cost;
00270     uint current_timestamp;
00271     bool fast;
00272     int timer_id;
00273 };
00274 
00275 #endif // QFONTDATA_P_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'