1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qfont.h"
|
---|
43 | #include "qfont_p.h"
|
---|
44 | #include "qfontengine_p.h"
|
---|
45 | #include "qfontinfo.h"
|
---|
46 | #include "qfontmetrics.h"
|
---|
47 | #include "qpaintdevice.h"
|
---|
48 | #include "qstring.h"
|
---|
49 | #include <private/qt_mac_p.h>
|
---|
50 | #include <private/qtextengine_p.h>
|
---|
51 | #include <private/qunicodetables_p.h>
|
---|
52 | #include <qapplication.h>
|
---|
53 | #include "qfontdatabase.h"
|
---|
54 | #include <qpainter.h>
|
---|
55 | #include "qtextengine_p.h"
|
---|
56 | #include <stdlib.h>
|
---|
57 |
|
---|
58 | QT_BEGIN_NAMESPACE
|
---|
59 |
|
---|
60 | extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp
|
---|
61 |
|
---|
62 | int qt_mac_pixelsize(const QFontDef &def, int dpi)
|
---|
63 | {
|
---|
64 | float ret;
|
---|
65 | if(def.pixelSize == -1)
|
---|
66 | ret = def.pointSize * dpi / qt_mac_defaultDpi_x();
|
---|
67 | else
|
---|
68 | ret = def.pixelSize;
|
---|
69 | return qRound(ret);
|
---|
70 | }
|
---|
71 | int qt_mac_pointsize(const QFontDef &def, int dpi)
|
---|
72 | {
|
---|
73 | float ret;
|
---|
74 | if(def.pointSize < 0)
|
---|
75 | ret = def.pixelSize * qt_mac_defaultDpi_x() / float(dpi);
|
---|
76 | else
|
---|
77 | ret = def.pointSize;
|
---|
78 | return qRound(ret);
|
---|
79 | }
|
---|
80 |
|
---|
81 | QString QFont::rawName() const
|
---|
82 | {
|
---|
83 | return family();
|
---|
84 | }
|
---|
85 |
|
---|
86 | void QFont::setRawName(const QString &name)
|
---|
87 | {
|
---|
88 | setFamily(name);
|
---|
89 | }
|
---|
90 |
|
---|
91 | void QFont::cleanup()
|
---|
92 | {
|
---|
93 | QFontCache::cleanup();
|
---|
94 | }
|
---|
95 |
|
---|
96 | /*!
|
---|
97 | Returns an ATSUFontID
|
---|
98 | */
|
---|
99 | quint32 QFont::macFontID() const // ### need 64-bit version
|
---|
100 | {
|
---|
101 | #ifdef QT_MAC_USE_COCOA
|
---|
102 | return 0;
|
---|
103 | #elif 1
|
---|
104 | QFontEngine *fe = d->engineForScript(QUnicodeTables::Common);
|
---|
105 | if (fe && fe->type() == QFontEngine::Multi)
|
---|
106 | return static_cast<QFontEngineMacMulti*>(fe)->macFontID();
|
---|
107 | #else
|
---|
108 | Str255 name;
|
---|
109 | if(FMGetFontFamilyName((FMFontFamily)((UInt32)handle()), name) == noErr) {
|
---|
110 | short fnum;
|
---|
111 | GetFNum(name, &fnum);
|
---|
112 | return fnum;
|
---|
113 | }
|
---|
114 | #endif
|
---|
115 | return 0;
|
---|
116 | }
|
---|
117 |
|
---|
118 | // Returns an ATSUFonFamilyRef
|
---|
119 | Qt::HANDLE QFont::handle() const
|
---|
120 | {
|
---|
121 | #if 0
|
---|
122 | QFontEngine *fe = d->engineForScript(QUnicodeTables::Common);
|
---|
123 | if (fe && fe->type() == QFontEngine::Mac)
|
---|
124 | return (Qt::HANDLE)static_cast<QFontEngineMacMulti*>(fe)->fontFamilyRef();
|
---|
125 | #endif
|
---|
126 | return 0;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void QFont::initialize()
|
---|
130 | { }
|
---|
131 |
|
---|
132 | QString QFont::defaultFamily() const
|
---|
133 | {
|
---|
134 | switch(d->request.styleHint) {
|
---|
135 | case QFont::Times:
|
---|
136 | return QString::fromLatin1("Times New Roman");
|
---|
137 | case QFont::Courier:
|
---|
138 | return QString::fromLatin1("Courier New");
|
---|
139 | case QFont::Decorative:
|
---|
140 | return QString::fromLatin1("Bookman Old Style");
|
---|
141 | case QFont::Helvetica:
|
---|
142 | case QFont::System:
|
---|
143 | default:
|
---|
144 | return QString::fromLatin1("Helvetica");
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | QString QFont::lastResortFamily() const
|
---|
149 | {
|
---|
150 | return QString::fromLatin1("Helvetica");
|
---|
151 | }
|
---|
152 |
|
---|
153 | QString QFont::lastResortFont() const
|
---|
154 | {
|
---|
155 | return QString::fromLatin1("Geneva");
|
---|
156 | }
|
---|
157 |
|
---|
158 | QT_END_NAMESPACE
|
---|