Qt 4.8
qfont_mac.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qfont.h"
43 #include "qfont_p.h"
44 #include "qfontengine_p.h"
45 #include "qfontengine_mac_p.h"
46 #include "qfontengine_coretext_p.h"
47 #include "qfontinfo.h"
48 #include "qfontmetrics.h"
49 #include "qpaintdevice.h"
50 #include "qstring.h"
51 #include <private/qt_mac_p.h>
52 #include <private/qtextengine_p.h>
53 #include <private/qunicodetables_p.h>
54 #include <qapplication.h>
55 #include "qfontdatabase.h"
56 #include <qpainter.h>
57 #include "qtextengine_p.h"
58 #include <stdlib.h>
59 
61 
62 extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp
63 
64 int qt_mac_pixelsize(const QFontDef &def, int dpi)
65 {
66  float ret;
67  if(def.pixelSize == -1)
68  ret = def.pointSize * dpi / qt_mac_defaultDpi_x();
69  else
70  ret = def.pixelSize;
71  return qRound(ret);
72 }
73 int qt_mac_pointsize(const QFontDef &def, int dpi)
74 {
75  float ret;
76  if(def.pointSize < 0)
77  ret = def.pixelSize * qt_mac_defaultDpi_x() / float(dpi);
78  else
79  ret = def.pointSize;
80  return qRound(ret);
81 }
82 
84 {
85  return family();
86 }
87 
89 {
90  setFamily(name);
91 }
92 
94 {
96 }
97 
101 quint32 QFont::macFontID() const // ### need 64-bit version
102 {
103 #ifdef QT_MAC_USE_COCOA
104  return 0;
105 #elif 1
107  if (fe && fe->type() == QFontEngine::Multi)
108  return static_cast<QFontEngineMacMulti*>(fe)->macFontID();
109 #else
110  Str255 name;
111  if(FMGetFontFamilyName((FMFontFamily)((UInt32)handle()), name) == noErr) {
112  short fnum;
113  GetFNum(name, &fnum);
114  return fnum;
115  }
116 #endif
117  return 0;
118 }
119 
120 // Returns an ATSUFonFamilyRef
122 {
123 #ifdef QT_MAC_USE_COCOA
125  if (fe && fe->type() == QFontEngine::Multi)
126  return (Qt::HANDLE)static_cast<QCoreTextFontEngineMulti*>(fe)->macFontID();
127 #endif
128  return 0;
129 }
130 
132 { }
133 
135 {
136  switch(d->request.styleHint) {
137  case QFont::Times:
138  return QString::fromLatin1("Times New Roman");
139  case QFont::Courier:
140  return QString::fromLatin1("Courier New");
141  case QFont::Monospace:
142  return QString::fromLatin1("Courier");
143  case QFont::Decorative:
144  return QString::fromLatin1("Bookman Old Style");
145  case QFont::Cursive:
146  return QString::fromLatin1("Apple Chancery");
147  case QFont::Fantasy:
148  return QString::fromLatin1("Papyrus");
149  case QFont::Helvetica:
150  case QFont::System:
151  default:
152  return QString::fromLatin1("Helvetica");
153  }
154 }
155 
157 {
158  return QString::fromLatin1("Helvetica");
159 }
160 
162 {
163  return QString::fromLatin1("Geneva");
164 }
165 
int qt_mac_pointsize(const QFontDef &def, int dpi)
Definition: qfont_mac.cpp:73
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
qreal pointSize
Definition: qfont_p.h:89
float qt_mac_defaultDpi_x()
QString lastResortFamily() const
Returns the "last resort" font family name.
Definition: qfont_mac.cpp:156
static void cleanup()
Internal function that cleans up the font system.
Definition: qfont_mac.cpp:93
The QString class provides a Unicode character string.
Definition: qstring.h:83
HFONT handle() const
Returns the window system handle to the font, for low-level access.
Definition: qfont_mac.cpp:121
virtual Type type() const =0
void setFamily(const QString &)
Sets the family name of the font.
Definition: qfont.cpp:924
QString rawName() const
Returns the name of the font within the underlying window system.
Definition: qfont_mac.cpp:83
int qt_mac_pixelsize(const QFontDef &def, int dpi)
Definition: qfont_mac.cpp:64
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static void initialize()
Internal function that initializes the font system.
Definition: qfont_mac.cpp:131
QFontDef request
Definition: qfont_p.h:178
const char * name
void * HANDLE
Definition: qnamespace.h:1671
qreal pixelSize
Definition: qfont_p.h:90
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QString lastResortFont() const
Returns a "last resort" font name for the font matching algorithm.
Definition: qfont_mac.cpp:161
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QString family() const
Returns the requested font family name, i.e.
Definition: qfont.cpp:906
static void cleanup()
Definition: qfont.cpp:2927
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfont.h:343
unsigned int quint32
Definition: qglobal.h:938
QString defaultFamily() const
Returns the family name that corresponds to the current style hint.
Definition: qfont_mac.cpp:134
void setRawName(const QString &)
Sets a font by its system specific name.
Definition: qfont_mac.cpp:88
uint styleHint
Definition: qfont_p.h:93
quint32 macFontID() const
Returns an ATSUFontID.
Definition: qfont_mac.cpp:101
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203