src/gui/text/qfont_win.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    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 "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 {
       
    65     QString family = QString::fromWCharArray(lf.lfFaceName);
       
    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:
       
   151             return QString::fromLatin1("Courier New");
       
   152         case QFont::Decorative:
       
   153             return QString::fromLatin1("Bookman Old Style");
       
   154         case QFont::Helvetica:
       
   155             return QString::fromLatin1("Arial");
       
   156         case QFont::System:
       
   157         default:
       
   158             return QString::fromLatin1("MS Sans Serif");
       
   159     }
       
   160 }
       
   161 
       
   162 QString QFont::lastResortFamily() const
       
   163 {
       
   164     return QString::fromLatin1("helvetica");
       
   165 }
       
   166 
       
   167 QString QFont::lastResortFont() const
       
   168 {
       
   169     return QString::fromLatin1("arial");
       
   170 }
       
   171 
       
   172 QT_END_NAMESPACE