~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/text/qfont_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the text module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef QFONTDATA_P_H
 
30
#define QFONTDATA_P_H
 
31
 
 
32
//
 
33
//  W A R N I N G
 
34
//  -------------
 
35
//
 
36
// This file is not part of the Qt API.  It exists for the convenience
 
37
// of internal files.  This header file may change from version to version
 
38
// without notice, or even be removed.
 
39
//
 
40
// We mean it.
 
41
//
 
42
 
 
43
#include "qfont.h"
 
44
#include "qmap.h"
 
45
#include "qobject.h"
 
46
#include <private/qunicodetables_p.h>
 
47
 
 
48
// forwards
 
49
class QFontEngine;
 
50
 
 
51
struct QFontDef
 
52
{
 
53
    inline QFontDef()
 
54
        : pointSize(-1.0), pixelSize(-1),
 
55
          styleStrategy(QFont::PreferDefault), styleHint(QFont::AnyStyle),
 
56
          weight(50), fixedPitch(false), style(QFont::StyleNormal), stretch(100),
 
57
          ignorePitch(true)
 
58
#ifdef Q_WS_MAC
 
59
          ,fixedPitchComputed(false)
 
60
#endif
 
61
    {
 
62
    }
 
63
 
 
64
    QString family;
 
65
 
 
66
#ifdef Q_WS_X11
 
67
    QString addStyle;
 
68
#endif // Q_WS_X11
 
69
 
 
70
    qreal pointSize;
 
71
    int pixelSize;
 
72
 
 
73
    uint styleStrategy : 16;
 
74
    uint styleHint     : 8;
 
75
 
 
76
    uint weight     :  7; // 0-99
 
77
    uint fixedPitch :  1;
 
78
    uint style      :  2;
 
79
    uint stretch    : 12; // 0-400
 
80
 
 
81
    uint ignorePitch : 1;
 
82
    uint fixedPitchComputed : 1; // for Mac OS X only
 
83
    uint reserved   : 16; // for future extensions
 
84
 
 
85
    bool exactMatch(const QFontDef &other) const;
 
86
    bool operator==(const QFontDef &other) const
 
87
    {
 
88
        return pixelSize == other.pixelSize
 
89
                    && weight == other.weight
 
90
                    && style == other.style
 
91
                    && stretch == other.stretch
 
92
                    && styleHint == other.styleHint
 
93
                    && styleStrategy == other.styleStrategy
 
94
                    && family == other.family
 
95
#ifdef Q_WS_X11
 
96
                    && addStyle == other.addStyle
 
97
#endif
 
98
                          ;
 
99
    }
 
100
    inline bool operator<(const QFontDef &other) const
 
101
    {
 
102
        if (pixelSize != other.pixelSize) return pixelSize < other.pixelSize;
 
103
        if (weight != other.weight) return weight < other.weight;
 
104
        if (style != other.style) return style < other.style;
 
105
        if (stretch != other.stretch) return stretch < other.stretch;
 
106
        if (styleHint != other.styleHint) return styleHint < other.styleHint;
 
107
        if (styleStrategy != other.styleStrategy) return styleStrategy < other.styleStrategy;
 
108
        if (family != other.family) return family < other.family;
 
109
 
 
110
#ifdef Q_WS_X11
 
111
        if (addStyle != other.addStyle) return addStyle < other.addStyle;
 
112
#endif // Q_WS_X11
 
113
 
 
114
        return false;
 
115
    }
 
116
};
 
117
 
 
118
class QFontEngineData
 
119
{
 
120
public:
 
121
    QFontEngineData();
 
122
    ~QFontEngineData();
 
123
 
 
124
    QAtomic ref;
 
125
    uint lineWidth;
 
126
 
 
127
#if defined(Q_WS_X11) || defined(Q_WS_WIN)
 
128
    QFontEngine *engines[QUnicodeTables::ScriptCount];
 
129
#else
 
130
    QFontEngine *engine;
 
131
#endif // Q_WS_X11 || Q_WS_WIN
 
132
#ifndef Q_WS_MAC
 
133
    enum { widthCacheSize = 0x500 };
 
134
    uchar widthCache[widthCacheSize];
 
135
#endif
 
136
};
 
137
 
 
138
 
 
139
class Q_GUI_EXPORT QFontPrivate
 
140
{
 
141
public:
 
142
#ifdef Q_WS_X11
 
143
    static int defaultEncodingID;
 
144
#endif // Q_WS_X11
 
145
 
 
146
    QFontPrivate();
 
147
    QFontPrivate(const QFontPrivate &other);
 
148
    ~QFontPrivate();
 
149
 
 
150
    void load(int script);
 
151
#if defined(Q_WS_X11) || defined(Q_WS_WIN)
 
152
    inline QFontEngine *engineForScript(int script) const
 
153
    {
 
154
        if (script >= QUnicodeTables::Inherited)
 
155
            script = QUnicodeTables::Common;
 
156
        if (!engineData || !engineData->engines[script])
 
157
            const_cast<QFontPrivate *>(this)->load(script);
 
158
        return engineData->engines[script];
 
159
    }
 
160
#else
 
161
    inline QFontEngine *engineForScript(int script) const
 
162
    {
 
163
        if (script >= QUnicodeTables::Inherited)
 
164
            script = QUnicodeTables::Common;
 
165
        if (!engineData || !engineData->engine)
 
166
            const_cast<QFontPrivate *>(this)->load(script);
 
167
        return engineData->engine;
 
168
    }
 
169
#endif // Q_WS_X11 || Q_WS_WIN
 
170
 
 
171
    QAtomic ref;
 
172
    QFontDef request;
 
173
    QFontEngineData *engineData;
 
174
    int dpi;
 
175
    int screen;
 
176
 
 
177
    uint rawMode    :  1;
 
178
    uint underline  :  1;
 
179
    uint overline   :  1;
 
180
    uint strikeOut  :  1;
 
181
    uint kerning    :  1;
 
182
 
 
183
    enum {
 
184
        Family        = 0x0001,
 
185
        Size          = 0x0002,
 
186
        StyleHint     = 0x0004,
 
187
        StyleStrategy = 0x0008,
 
188
        Weight        = 0x0010,
 
189
        Style         = 0x0020,
 
190
        Underline     = 0x0040,
 
191
        Overline      = 0x0080,
 
192
        StrikeOut     = 0x0100,
 
193
        FixedPitch    = 0x0200,
 
194
        Stretch       = 0x0400,
 
195
        Kerning       = 0x0800,
 
196
        Complete      = 0x0fff
 
197
    };
 
198
 
 
199
    void resolve(uint mask, const QFontPrivate *other);
 
200
};
 
201
 
 
202
 
 
203
class QFontCache : public QObject
 
204
{
 
205
    Q_OBJECT
 
206
public:
 
207
    static QFontCache *instance;
 
208
 
 
209
    QFontCache();
 
210
    ~QFontCache();
 
211
 
 
212
#ifdef Q_WS_QWS
 
213
    void clear();
 
214
#endif
 
215
    // universal key structure.  QFontEngineDatas and QFontEngines are cached using
 
216
    // the same keys
 
217
    struct Key {
 
218
        Key() : script(0), screen(0) { }
 
219
        Key(const QFontDef &d, int c, int s = 0)
 
220
            : def(d), script(c), screen(s) { }
 
221
 
 
222
        QFontDef def;
 
223
        int script;
 
224
        int screen;
 
225
 
 
226
        inline bool operator<(const Key &other) const
 
227
        {
 
228
            if (script != other.script) return script < other.script;
 
229
            if (screen != other.screen) return screen < other.screen;
 
230
            return def < other.def;
 
231
        }
 
232
        inline bool operator==(const Key &other) const
 
233
        { return def == other.def && script == other.script && screen == other.screen; }
 
234
    };
 
235
 
 
236
    // QFontEngineData cache
 
237
    typedef QMap<Key,QFontEngineData*> EngineDataCache;
 
238
    EngineDataCache engineDataCache;
 
239
 
 
240
    QFontEngineData *findEngineData(const Key &key) const;
 
241
    void insertEngineData(const Key &key, QFontEngineData *engineData);
 
242
 
 
243
    // QFontEngine cache
 
244
    struct Engine {
 
245
        Engine() : data(0), timestamp(0), hits(0) { }
 
246
        Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
 
247
 
 
248
        QFontEngine *data;
 
249
        uint timestamp;
 
250
        uint hits;
 
251
    };
 
252
 
 
253
    typedef QMap<Key,Engine> EngineCache;
 
254
    EngineCache engineCache;
 
255
 
 
256
    QFontEngine *findEngine(const Key &key);
 
257
    void insertEngine(const Key &key, QFontEngine *engine);
 
258
 
 
259
#if defined(Q_WS_WIN) || defined(Q_WS_QWS)
 
260
    void cleanupPrinterFonts();
 
261
#endif
 
262
 
 
263
    private:
 
264
    void increaseCost(uint cost);
 
265
    void decreaseCost(uint cost);
 
266
    void timerEvent(QTimerEvent *event);
 
267
 
 
268
    static const uint min_cost;
 
269
    uint total_cost, max_cost;
 
270
    uint current_timestamp;
 
271
    bool fast;
 
272
    int timer_id;
 
273
};
 
274
 
 
275
#endif // QFONTDATA_P_H