author | kergoth <kergoth> | 2002-11-01 00:10:42 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-11-01 00:10:42 (UTC) |
commit | 5042e3cf0d3514552769e441f5aad590c8eaf967 (patch) (unidiff) | |
tree | 4a5ea45f3519d981a172ab5275bf38c6fa778dec /qmake/include/private/qfontdata_p.h | |
parent | 108c1c753e74e989cc13923086996791428c9af4 (diff) | |
download | opie-5042e3cf0d3514552769e441f5aad590c8eaf967.zip opie-5042e3cf0d3514552769e441f5aad590c8eaf967.tar.gz opie-5042e3cf0d3514552769e441f5aad590c8eaf967.tar.bz2 |
Adding qmake in preperation for new build system
Diffstat (limited to 'qmake/include/private/qfontdata_p.h') (more/less context) (show whitespace changes)
-rw-r--r-- | qmake/include/private/qfontdata_p.h | 479 |
1 files changed, 479 insertions, 0 deletions
diff --git a/qmake/include/private/qfontdata_p.h b/qmake/include/private/qfontdata_p.h new file mode 100644 index 0000000..917d14f --- a/dev/null +++ b/qmake/include/private/qfontdata_p.h | |||
@@ -0,0 +1,479 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Definition of internal QFontData struct | ||
5 | ** | ||
6 | ** Created : 941229 | ||
7 | ** | ||
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. | ||
9 | ** | ||
10 | ** This file is part of the kernel module of the Qt GUI Toolkit. | ||
11 | ** | ||
12 | ** This file may be distributed under the terms of the Q Public License | ||
13 | ** as defined by Trolltech AS of Norway and appearing in the file | ||
14 | ** LICENSE.QPL included in the packaging of this file. | ||
15 | ** | ||
16 | ** This file may be distributed and/or modified under the terms of the | ||
17 | ** GNU General Public License version 2 as published by the Free Software | ||
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
19 | ** packaging of this file. | ||
20 | ** | ||
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
22 | ** licenses may use this file in accordance with the Qt Commercial License | ||
23 | ** Agreement provided with the Software. | ||
24 | ** | ||
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
27 | ** | ||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
29 | ** information about Qt Commercial License Agreements. | ||
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
32 | ** | ||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
34 | ** not clear to you. | ||
35 | ** | ||
36 | **********************************************************************/ | ||
37 | |||
38 | #ifndef QFONTDATA_P_H | ||
39 | #define QFONTDATA_P_H | ||
40 | |||
41 | #ifndef QT_H | ||
42 | #include <qcache.h> | ||
43 | #include <qobject.h> | ||
44 | #include <qpaintdevice.h> | ||
45 | #endif // QT_H | ||
46 | #include <limits.h> | ||
47 | |||
48 | // | ||
49 | // W A R N I N G | ||
50 | // ------------- | ||
51 | // | ||
52 | // This file is not part of the Qt API. It exists for the convenience | ||
53 | // of internal files. This header file may change from version to version | ||
54 | // without notice, or even be removed. | ||
55 | // | ||
56 | // We mean it. | ||
57 | // | ||
58 | // | ||
59 | |||
60 | class QPaintDevice; | ||
61 | |||
62 | #ifdef Q_WS_WIN | ||
63 | #include <qt_windows.h> | ||
64 | #endif | ||
65 | |||
66 | #ifdef Q_WS_X11 | ||
67 | #include <qt_x11.h> | ||
68 | |||
69 | class QCharStruct; | ||
70 | #endif | ||
71 | |||
72 | // font description | ||
73 | struct QFontDef { | ||
74 | QFontDef() | ||
75 | : pixelSize(0), pointSize(0), lbearing(SHRT_MIN), rbearing(SHRT_MIN), | ||
76 | styleStrategy(QFont::PreferDefault), styleHint(QFont::AnyStyle), | ||
77 | weight(0), italic(FALSE), underline(FALSE), strikeOut(FALSE), | ||
78 | fixedPitch(FALSE), hintSetByUser(FALSE), rawMode(FALSE), dirty(TRUE) | ||
79 | { ; } | ||
80 | |||
81 | QString family; | ||
82 | QString addStyle; | ||
83 | |||
84 | int pixelSize; | ||
85 | int pointSize; | ||
86 | short lbearing; | ||
87 | short rbearing; | ||
88 | |||
89 | ushort styleStrategy; | ||
90 | uchar styleHint; | ||
91 | uchar weight; | ||
92 | |||
93 | bool italic; | ||
94 | bool underline; | ||
95 | bool strikeOut; | ||
96 | bool fixedPitch; | ||
97 | bool hintSetByUser; | ||
98 | bool rawMode; | ||
99 | |||
100 | bool dirty; | ||
101 | }; | ||
102 | |||
103 | |||
104 | class QTextCodec; | ||
105 | |||
106 | #ifdef Q_WS_X11 | ||
107 | |||
108 | // this is a shared wrapper for XFontStruct (to prevent a font being freed by | ||
109 | // the cache while it's being used) | ||
110 | class QFontStruct : public QShared | ||
111 | { | ||
112 | public: | ||
113 | QFontStruct(Qt::HANDLE h, Qt::HANDLE xfth, Qt::HANDLE xftp, | ||
114 | QCString n, QTextCodec *c, int a) : | ||
115 | QShared(), handle(h), xfthandle(xfth), xftpattern(xftp), | ||
116 | name(n), codec(c), cache_cost(a), scale( 1. ) | ||
117 | { ; } | ||
118 | |||
119 | ~QFontStruct(); | ||
120 | |||
121 | Qt::HANDLE handle, xfthandle, xftpattern; | ||
122 | QCString name; | ||
123 | QTextCodec *codec; | ||
124 | int cache_cost; | ||
125 | float scale; // needed for printing, to correctly scale font metrics for bitmap fonts | ||
126 | }; | ||
127 | |||
128 | enum { widthCacheSize = 0x500 }; | ||
129 | |||
130 | class QFontX11Data // used as a QFontPrivate member | ||
131 | { | ||
132 | public: | ||
133 | // X fontstruct handles for each character set | ||
134 | QFontStruct *fontstruct[QFont::LastPrivateScript]; | ||
135 | |||
136 | uchar widthCache[widthCacheSize]; | ||
137 | |||
138 | QFontX11Data(); | ||
139 | ~QFontX11Data(); | ||
140 | }; | ||
141 | |||
142 | #endif // Q_WS_X11 | ||
143 | |||
144 | |||
145 | #ifdef Q_WS_WIN | ||
146 | |||
147 | class QFontStruct : public QShared | ||
148 | { | ||
149 | public: | ||
150 | QFontStruct( const QString &key ); | ||
151 | ~QFontStruct() { reset(); } | ||
152 | bool dirty() const { return hfont == 0; } | ||
153 | HDC dc() const; | ||
154 | HFONT font() const { return hfont; } | ||
155 | const TEXTMETRICA *textMetricA() const { return &tm.a; } | ||
156 | const TEXTMETRICW *textMetricW() const { return &tm.w; } | ||
157 | QString key() const { return k; } | ||
158 | void reset(); | ||
159 | |||
160 | QStringk; | ||
161 | HDC hdc; | ||
162 | HFONThfont; | ||
163 | uintstockFont:1; | ||
164 | uintpaintDevice:1; | ||
165 | union { | ||
166 | TEXTMETRICWw; | ||
167 | TEXTMETRICAa; | ||
168 | } tm; | ||
169 | int lw; | ||
170 | int cache_cost; | ||
171 | // friend void QFont::initFontInfo() const; | ||
172 | }; | ||
173 | |||
174 | #endif // Q_WS_WIN | ||
175 | |||
176 | #if defined( Q_WS_MAC ) | ||
177 | |||
178 | #if defined( Q_WS_MACX ) | ||
179 | # define QMAC_FONT_ATSUI | ||
180 | #endif | ||
181 | #include "qt_mac.h" | ||
182 | class QMacFontInfo; | ||
183 | |||
184 | class QFontStruct : public QShared | ||
185 | { | ||
186 | public: | ||
187 | inline QFontStruct() : QShared(), info(NULL), fnum(-1), cache_cost(0), internal_fi(NULL) { } | ||
188 | #if defined( QMAC_FONT_ATSUI ) && 0 | ||
189 | ATSFontMetrics *info; | ||
190 | int maxWidth() const { return (int)info->maxAdvanceWidth; } | ||
191 | #else | ||
192 | FontInfo *info; | ||
193 | int maxWidth() const { return info->widMax; } | ||
194 | #endif | ||
195 | int ascent() const { return (int)info->ascent; } | ||
196 | int descent() const { return (int)info->descent; } | ||
197 | int leading() const { return (int)info->leading; } | ||
198 | int minLeftBearing() const { return 0; } | ||
199 | int minRightBearing() const { return 0; } | ||
200 | |||
201 | short fnum; | ||
202 | int psize, cache_cost; | ||
203 | QMacFontInfo *internal_fi; | ||
204 | }; | ||
205 | |||
206 | #endif | ||
207 | |||
208 | #ifdef Q_WS_QWS | ||
209 | class QFontStruct; | ||
210 | class QGfx; | ||
211 | #endif | ||
212 | |||
213 | typedef QCacheIterator<QFontStruct> QFontCacheIterator; | ||
214 | class QFontCache : public QObject, public QCache<QFontStruct> | ||
215 | { | ||
216 | public: | ||
217 | QFontCache(); | ||
218 | ~QFontCache(); | ||
219 | |||
220 | bool insert(const QString &, const QFontStruct *, int c); | ||
221 | #ifndef Q_WS_MAC | ||
222 | void deleteItem(Item d); | ||
223 | #endif | ||
224 | void timerEvent(QTimerEvent *); | ||
225 | |||
226 | |||
227 | protected: | ||
228 | |||
229 | |||
230 | private: | ||
231 | int timer_id; | ||
232 | bool fast; | ||
233 | }; | ||
234 | |||
235 | |||
236 | // QFontPrivate - holds all data on which a font operates | ||
237 | class QFontPrivate : public QShared | ||
238 | { | ||
239 | public: | ||
240 | static QFontCache *fontCache; | ||
241 | |||
242 | |||
243 | public: | ||
244 | |||
245 | QFontPrivate(); | ||
246 | QFontPrivate(const QFontPrivate &fp); | ||
247 | QFontPrivate( const QFontPrivate &fp, QPaintDevice *pd ); | ||
248 | ~QFontPrivate(); | ||
249 | |||
250 | // requested font | ||
251 | QFontDef request; | ||
252 | // actual font | ||
253 | QFontDef actual; | ||
254 | |||
255 | bool exactMatch; | ||
256 | int lineWidth; | ||
257 | |||
258 | // common functions | ||
259 | QString defaultFamily() const; | ||
260 | QString lastResortFamily() const; | ||
261 | QString lastResortFont() const; | ||
262 | QString key() const; | ||
263 | |||
264 | static int getFontWeight(const QCString &, bool = FALSE); | ||
265 | QRect boundingRect( const QChar &ch ); | ||
266 | |||
267 | struct TextRun { | ||
268 | TextRun() | ||
269 | { | ||
270 | xoff = 0; | ||
271 | yoff = 0; | ||
272 | x2off = 0; | ||
273 | script = QFont::NoScript; | ||
274 | string = 0; | ||
275 | length = 0; | ||
276 | next = 0; | ||
277 | } | ||
278 | |||
279 | ~TextRun() | ||
280 | { | ||
281 | if ( next ) | ||
282 | delete next; | ||
283 | } | ||
284 | |||
285 | void setParams( int x, int y, int x2, const QChar *s, int len, | ||
286 | QFont::Script sc = QFont::NoScript ) { | ||
287 | xoff = x; | ||
288 | yoff = y; | ||
289 | x2off = x2; | ||
290 | string = s; | ||
291 | length = len; | ||
292 | script = sc; | ||
293 | } | ||
294 | int xoff; | ||
295 | int yoff; | ||
296 | int x2off; | ||
297 | QFont::Script script; | ||
298 | const QChar *string; | ||
299 | int length; | ||
300 | TextRun *next; | ||
301 | #ifdef Q_WS_X11 | ||
302 | QByteArray mapped; | ||
303 | #endif | ||
304 | }; | ||
305 | |||
306 | // some replacement functions for native calls. This is needed, because shaping and | ||
307 | // non spacing marks can change the extents of a string to draw. At the same time | ||
308 | // drawing needs to take care to correctly position non spacing marks. | ||
309 | int textWidth( const QString &str, int pos, int len ); | ||
310 | |||
311 | // returns the script a certain character is in. Needed to separate the string | ||
312 | // into runs of different scripts as required for X11 and opentype. | ||
313 | QFont::Script scriptForChar(const QChar &c); | ||
314 | |||
315 | #ifdef Q_WS_X11 | ||
316 | QFont::Script hanHack( const QChar & c ); | ||
317 | static char **getXFontNames(const char *, int *); | ||
318 | static bool fontExists(const QString &); | ||
319 | static bool parseXFontName(char *, char **); | ||
320 | static QCString fixXLFD( const QCString & ); | ||
321 | static bool fillFontDef(XFontStruct *, QFontDef *, int); | ||
322 | static bool fillFontDef(const QCString &, QFontDef *, int); | ||
323 | |||
324 | static inline bool isZero(char *x) | ||
325 | { | ||
326 | return (x[0] == '0' && x[1] == 0); | ||
327 | } | ||
328 | |||
329 | static inline bool isScalable( char **tokens ) | ||
330 | { | ||
331 | return (isZero(tokens[PixelSize]) && | ||
332 | isZero(tokens[PointSize]) && | ||
333 | isZero(tokens[AverageWidth])); | ||
334 | } | ||
335 | |||
336 | static inline bool isSmoothlyScalable( char **tokens ) | ||
337 | { | ||
338 | return (isZero(tokens[ResolutionX]) && isZero(tokens[ResolutionY])); | ||
339 | } | ||
340 | |||
341 | static inline bool isFixedPitch( char **tokens ) | ||
342 | { | ||
343 | return (tokens[Spacing][0] == 'm' || | ||
344 | tokens[Spacing][0] == 'c' || | ||
345 | tokens[Spacing][0] == 'M' || | ||
346 | tokens[Spacing][0] == 'C'); | ||
347 | } | ||
348 | |||
349 | // XLFD fields | ||
350 | enum FontFieldNames { | ||
351 | Foundry, | ||
352 | Family, | ||
353 | Weight, | ||
354 | Slant, | ||
355 | Width, | ||
356 | AddStyle, | ||
357 | PixelSize, | ||
358 | PointSize, | ||
359 | ResolutionX, | ||
360 | ResolutionY, | ||
361 | Spacing, | ||
362 | AverageWidth, | ||
363 | CharsetRegistry, | ||
364 | CharsetEncoding, | ||
365 | NFontFields | ||
366 | }; | ||
367 | |||
368 | #ifndef QT_NO_XFTFREETYPE | ||
369 | XftPattern *findXftFont(const QChar &, bool *, double *scale) const; | ||
370 | XftPattern *bestXftPattern(const QString &, const QString &, const QChar &, double *scale) const; | ||
371 | #endif // QT_NO_XFTFREETYPE | ||
372 | QCString findFont(QFont::Script, bool *, double *) const; | ||
373 | QCString bestFamilyMember(QFont::Script, const QString &, const QString &, | ||
374 | const QString &, int *, double *) const; | ||
375 | QCString bestMatch(const char *, int *, QFont::Script, double *) const; | ||
376 | int fontMatchScore(const char *, QCString &, float *, int *, bool *, | ||
377 | bool *, QFont::Script, double *) const; | ||
378 | void initFontInfo(QFont::Script, double scale); | ||
379 | void load(QFont::Script = QFont::NoScript, bool = TRUE); | ||
380 | bool loadUnicode(QFont::Script, const QChar &); | ||
381 | void computeLineWidth(); | ||
382 | |||
383 | int textWidth( const QString &str, int pos, int len, TextRun *cache ); | ||
384 | void textExtents( const QString &str, int pos, int len, QCharStruct *overall ); | ||
385 | void drawText( Display *dpy, int screen, Qt::HANDLE hd, Qt::HANDLE rendhd, | ||
386 | GC gc, const QColor &pen, Qt::BGMode, const QColor &bgcolor, | ||
387 | int x, int y, const TextRun *cache, int pdWidth ); | ||
388 | bool inFont( const QChar &ch ); | ||
389 | |||
390 | QFontX11Data x11data; | ||
391 | static QFont::Script defaultScript; | ||
392 | int x11Screen; | ||
393 | #endif // Q_WS_X11 | ||
394 | |||
395 | QPaintDevice *paintdevice; | ||
396 | |||
397 | #ifdef Q_WS_WIN | ||
398 | void load(); | ||
399 | void initFontInfo(); | ||
400 | HFONT create( bool *stockFont, HDC hdc = 0, bool compatMode = FALSE ); | ||
401 | QFontStruct *fin; | ||
402 | |||
403 | void buildCache( HDC hdc, const QString &str, int pos, int len, TextRun *cache ); | ||
404 | void drawText( HDC hdc, int x, int y, TextRun *cache ); | ||
405 | #endif // Q_WS_WIN | ||
406 | |||
407 | #ifdef Q_WS_QWS | ||
408 | void load(); | ||
409 | QFontStruct *fin; | ||
410 | int textWidth( const QString &str, int pos, int len, TextRun *cache ); | ||
411 | void drawText( QGfx *gfx, int x, int y, const TextRun *cache ); | ||
412 | #endif | ||
413 | |||
414 | #if defined( Q_WS_MAC ) | ||
415 | void macSetFont(QPaintDevice *); | ||
416 | void drawText(int x, int y, QString s, int len, QPaintDevice *dev, const QRegion *rgn); | ||
417 | void computeLineWidth(); | ||
418 | void load(); | ||
419 | QFontStruct *fin; | ||
420 | #endif | ||
421 | |||
422 | }; | ||
423 | |||
424 | inline QFontPrivate::QFontPrivate() | ||
425 | : QShared(), exactMatch(FALSE), lineWidth(1) | ||
426 | { | ||
427 | |||
428 | #if defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_MAC) | ||
429 | fin = 0; | ||
430 | #endif // Q_WS_WIN || Q_WS_QWS | ||
431 | #if defined(Q_WS_X11) | ||
432 | x11Screen = QPaintDevice::x11AppScreen(); | ||
433 | #endif // Q_WS_X11 | ||
434 | paintdevice = 0; | ||
435 | } | ||
436 | |||
437 | inline QFontPrivate::QFontPrivate(const QFontPrivate &fp) | ||
438 | : QShared(), request(fp.request), actual(fp.actual), | ||
439 | exactMatch(fp.exactMatch), lineWidth(1) | ||
440 | { | ||
441 | Q_ASSERT(!fp.paintdevice); | ||
442 | #if defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_MAC) | ||
443 | fin = 0; | ||
444 | #endif // Q_WS_WIN || Q_WS_QWS | ||
445 | #if defined(Q_WS_X11) | ||
446 | x11Screen = fp.x11Screen; | ||
447 | #endif // Q_WS_X11 | ||
448 | paintdevice = 0; | ||
449 | } | ||
450 | |||
451 | inline QFontPrivate::QFontPrivate( const QFontPrivate &fp, QPaintDevice *pd ) | ||
452 | : QShared(), request(fp.request), actual(fp.actual), | ||
453 | exactMatch(fp.exactMatch), lineWidth(1) | ||
454 | { | ||
455 | |||
456 | #if defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_MAC) | ||
457 | fin = 0; | ||
458 | #endif // Q_WS_WIN || Q_WS_QWS | ||
459 | #if defined(Q_WS_X11) | ||
460 | x11Screen = pd->x11Screen(); | ||
461 | #endif // Q_WS_X11 | ||
462 | paintdevice = pd; | ||
463 | } | ||
464 | |||
465 | #ifndef Q_WS_QWS | ||
466 | inline QFontPrivate::~QFontPrivate() | ||
467 | { | ||
468 | #if defined(Q_WS_WIN) | ||
469 | if( fin ) | ||
470 | fin->deref(); | ||
471 | #endif | ||
472 | #if defined(Q_WS_MAC) | ||
473 | if( fin && fin->deref() ) | ||
474 | delete fin; | ||
475 | #endif | ||
476 | } | ||
477 | #endif | ||
478 | |||
479 | #endif // QFONTDATA_P_H | ||