[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 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 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qfont.h"
|
---|
| 43 | #include "qfont_p.h"
|
---|
| 44 | #include "qfontengine_p.h"
|
---|
| 45 | #include "qtextengine_p.h"
|
---|
| 46 | #include "qfontmetrics.h"
|
---|
| 47 | #include "qfontinfo.h"
|
---|
| 48 |
|
---|
| 49 | #include "qwidget.h"
|
---|
| 50 | #include "qpainter.h"
|
---|
| 51 | #include <limits.h>
|
---|
| 52 | #include "qt_windows.h"
|
---|
| 53 | #include <private/qapplication_p.h>
|
---|
| 54 | #include "qapplication.h"
|
---|
| 55 | #include <private/qunicodetables_p.h>
|
---|
| 56 | #include <qfontdatabase.h>
|
---|
| 57 |
|
---|
| 58 | QT_BEGIN_NAMESPACE
|
---|
| 59 |
|
---|
| 60 | extern HDC shared_dc(); // common dc for all fonts
|
---|
| 61 |
|
---|
| 62 | // ### maybe move to qapplication_win
|
---|
| 63 | QFont qt_LOGFONTtoQFont(LOGFONT& lf, bool /*scale*/)
|
---|
| 64 | {
|
---|
[561] | 65 | QString family = QString::fromWCharArray(lf.lfFaceName);
|
---|
[2] | 66 | QFont qf(family);
|
---|
| 67 | qf.setItalic(lf.lfItalic);
|
---|
| 68 | if (lf.lfWeight != FW_DONTCARE) {
|
---|
| 69 | int weight;
|
---|
| 70 | if (lf.lfWeight < 400)
|
---|
| 71 | weight = QFont::Light;
|
---|
| 72 | else if (lf.lfWeight < 600)
|
---|
| 73 | weight = QFont::Normal;
|
---|
| 74 | else if (lf.lfWeight < 700)
|
---|
| 75 | weight = QFont::DemiBold;
|
---|
| 76 | else if (lf.lfWeight < 800)
|
---|
| 77 | weight = QFont::Bold;
|
---|
| 78 | else
|
---|
| 79 | weight = QFont::Black;
|
---|
| 80 | qf.setWeight(weight);
|
---|
| 81 | }
|
---|
| 82 | int lfh = qAbs(lf.lfHeight);
|
---|
| 83 | qf.setPointSizeF(lfh * 72.0 / GetDeviceCaps(shared_dc(),LOGPIXELSY));
|
---|
| 84 | qf.setUnderline(false);
|
---|
| 85 | qf.setOverline(false);
|
---|
| 86 | qf.setStrikeOut(false);
|
---|
| 87 | return qf;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | static inline float pixelSize(const QFontDef &request, int dpi)
|
---|
| 92 | {
|
---|
| 93 | float pSize;
|
---|
| 94 | if (request.pointSize != -1)
|
---|
| 95 | pSize = request.pointSize * dpi/ 72.;
|
---|
| 96 | else
|
---|
| 97 | pSize = request.pixelSize;
|
---|
| 98 | return pSize;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | static inline float pointSize(const QFontDef &fd, int dpi)
|
---|
| 102 | {
|
---|
| 103 | float pSize;
|
---|
| 104 | if (fd.pointSize < 0)
|
---|
| 105 | pSize = fd.pixelSize * 72. / ((float)dpi);
|
---|
| 106 | else
|
---|
| 107 | pSize = fd.pointSize;
|
---|
| 108 | return pSize;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | /*****************************************************************************
|
---|
| 112 | QFont member functions
|
---|
| 113 | *****************************************************************************/
|
---|
| 114 |
|
---|
| 115 | void QFont::initialize()
|
---|
| 116 | {
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | void QFont::cleanup()
|
---|
| 120 | {
|
---|
| 121 | QFontCache::cleanup();
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | HFONT QFont::handle() const
|
---|
| 125 | {
|
---|
| 126 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
---|
| 127 | Q_ASSERT(engine != 0);
|
---|
| 128 | if (engine->type() == QFontEngine::Multi)
|
---|
| 129 | engine = static_cast<QFontEngineMulti *>(engine)->engine(0);
|
---|
| 130 | if (engine->type() == QFontEngine::Win)
|
---|
| 131 | return static_cast<QFontEngineWin *>(engine)->hfont;
|
---|
| 132 | return 0;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | QString QFont::rawName() const
|
---|
| 136 | {
|
---|
| 137 | return family();
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | void QFont::setRawName(const QString &name)
|
---|
| 141 | {
|
---|
| 142 | setFamily(name);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | QString QFont::defaultFamily() const
|
---|
| 146 | {
|
---|
| 147 | switch(d->request.styleHint) {
|
---|
| 148 | case QFont::Times:
|
---|
| 149 | return QString::fromLatin1("Times New Roman");
|
---|
| 150 | case QFont::Courier:
|
---|
[846] | 151 | case QFont::Monospace:
|
---|
[2] | 152 | return QString::fromLatin1("Courier New");
|
---|
| 153 | case QFont::Decorative:
|
---|
| |
---|