Fix uses of qRound on non-floating-point types.
[profile/ivi/qtbase.git] / src / gui / text / qfont_mac.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
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
60 QT_BEGIN_NAMESPACE
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
83 QString QFont::rawName() const
84 {
85     return family();
86 }
87
88 void QFont::setRawName(const QString &name)
89 {
90     setFamily(name);
91 }
92
93 void QFont::cleanup()
94 {
95     QFontCache::cleanup();
96 }
97
98 /*!
99   Returns an ATSUFontID
100 */
101 quint32 QFont::macFontID() const  // ### need 64-bit version
102 {
103 #ifdef QT_MAC_USE_COCOA
104     return 0;
105 #elif 1
106     QFontEngine *fe = d->engineForScript(QUnicodeTables::Common);
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
121 Qt::HANDLE QFont::handle() const
122 {
123 #ifdef QT_MAC_USE_COCOA
124     QFontEngine *fe = d->engineForScript(QUnicodeTables::Common);
125     if (fe && fe->type() == QFontEngine::Multi)
126         return (Qt::HANDLE)static_cast<QCoreTextFontEngineMulti*>(fe)->macFontID();
127 #endif
128     return 0;
129 }
130
131 void QFont::initialize()
132 { }
133
134 QString QFont::defaultFamily() const
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
156 QString QFont::lastResortFamily() const
157 {
158     return QString::fromLatin1("Helvetica");
159 }
160
161 QString QFont::lastResortFont() const
162 {
163     return QString::fromLatin1("Geneva");
164 }
165
166 QT_END_NAMESPACE