src/gui/text/qfontmetrics.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
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 #ifndef QFONTMETRICS_H
       
    43 #define QFONTMETRICS_H
       
    44 
       
    45 #include <QtGui/qfont.h>
       
    46 #ifndef QT_INCLUDE_COMPAT
       
    47 #include <QtCore/qrect.h>
       
    48 #endif
       
    49 
       
    50 QT_BEGIN_HEADER
       
    51 
       
    52 QT_BEGIN_NAMESPACE
       
    53 
       
    54 QT_MODULE(Gui)
       
    55 
       
    56 #ifdef Q_WS_QWS
       
    57 class QFontEngine;
       
    58 #endif
       
    59 
       
    60 class QTextCodec;
       
    61 class QRect;
       
    62 
       
    63 
       
    64 class Q_GUI_EXPORT QFontMetrics
       
    65 {
       
    66 public:
       
    67     QFontMetrics(const QFont &);
       
    68     QFontMetrics(const QFont &, QPaintDevice *pd);
       
    69     QFontMetrics(const QFontMetrics &);
       
    70     ~QFontMetrics();
       
    71 
       
    72     QFontMetrics &operator=(const QFontMetrics &);
       
    73 
       
    74     int ascent() const;
       
    75     int descent() const;
       
    76     int height() const;
       
    77     int leading() const;
       
    78     int lineSpacing() const;
       
    79     int minLeftBearing() const;
       
    80     int minRightBearing() const;
       
    81     int maxWidth() const;
       
    82 
       
    83     int xHeight() const;
       
    84     int averageCharWidth() const;
       
    85 
       
    86     bool inFont(QChar) const;
       
    87 
       
    88     int leftBearing(QChar) const;
       
    89     int rightBearing(QChar) const;
       
    90     int width(const QString &, int len = -1) const;
       
    91 
       
    92     int width(QChar) const;
       
    93     int charWidth(const QString &str, int pos) const;
       
    94 
       
    95     QRect boundingRect(QChar) const;
       
    96 
       
    97     QRect boundingRect(const QString &text) const;
       
    98     QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops=0, int *tabarray=0) const;
       
    99     inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text,
       
   100                               int tabstops=0, int *tabarray=0) const
       
   101         { return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); }
       
   102     QSize size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
       
   103 
       
   104     QRect tightBoundingRect(const QString &text) const;
       
   105 
       
   106     QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const;
       
   107 
       
   108     int underlinePos() const;
       
   109     int overlinePos() const;
       
   110     int strikeOutPos() const;
       
   111     int lineWidth() const;
       
   112 
       
   113     bool operator==(const QFontMetrics &other); // 5.0 - remove me
       
   114     bool operator==(const QFontMetrics &other) const;
       
   115     inline bool operator !=(const QFontMetrics &other) { return !operator==(other); } // 5.0 - remove me
       
   116     inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); }
       
   117 
       
   118 #ifdef QT3_SUPPORT
       
   119     inline QRect boundingRect(const QString &text, int len) const
       
   120         { return boundingRect(text.left(len)); }
       
   121     inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString& str, int len,
       
   122                               int tabstops=0, int *tabarray=0) const
       
   123         { return boundingRect(QRect(x, y, w, h), flags, str.left(len), tabstops, tabarray); }
       
   124     inline QSize size(int flags, const QString& str, int len, int tabstops=0, int *tabarray=0) const
       
   125         { return size(flags, str.left(len), tabstops, tabarray); }
       
   126 #endif
       
   127 private:
       
   128 #if defined(Q_WS_MAC)
       
   129     friend class QFontPrivate;
       
   130 #endif
       
   131     friend class QFontMetricsF;
       
   132     friend class QStackTextEngine;
       
   133 
       
   134     QFontPrivate *d;
       
   135 };
       
   136 
       
   137 
       
   138 class Q_GUI_EXPORT QFontMetricsF
       
   139 {
       
   140 public:
       
   141     QFontMetricsF(const QFont &);
       
   142     QFontMetricsF(const QFont &, QPaintDevice *pd);
       
   143     QFontMetricsF(const QFontMetrics &);
       
   144     QFontMetricsF(const QFontMetricsF &);
       
   145     ~QFontMetricsF();
       
   146 
       
   147     QFontMetricsF &operator=(const QFontMetricsF &);
       
   148     QFontMetricsF &operator=(const QFontMetrics &);
       
   149 
       
   150     qreal ascent() const;
       
   151     qreal descent() const;
       
   152     qreal height() const;
       
   153     qreal leading() const;
       
   154     qreal lineSpacing() const;
       
   155     qreal minLeftBearing() const;
       
   156     qreal minRightBearing() const;
       
   157     qreal maxWidth() const;
       
   158 
       
   159     qreal xHeight() const;
       
   160     qreal averageCharWidth() const;
       
   161 
       
   162     bool inFont(QChar) const;
       
   163 
       
   164     qreal leftBearing(QChar) const;
       
   165     qreal rightBearing(QChar) const;
       
   166     qreal width(const QString &string) const;
       
   167 
       
   168     qreal width(QChar) const;
       
   169 
       
   170     QRectF boundingRect(const QString &string) const;
       
   171     QRectF boundingRect(QChar) const;
       
   172     QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops=0, int *tabarray=0) const;
       
   173     QSizeF size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
       
   174 
       
   175     QRectF tightBoundingRect(const QString &text) const;
       
   176 
       
   177     QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;
       
   178 
       
   179     qreal underlinePos() const;
       
   180     qreal overlinePos() const;
       
   181     qreal strikeOutPos() const;
       
   182     qreal lineWidth() const;
       
   183 
       
   184     bool operator==(const QFontMetricsF &other); // 5.0 - remove me
       
   185     bool operator==(const QFontMetricsF &other) const;
       
   186     inline bool operator !=(const QFontMetricsF &other) { return !operator==(other); } // 5.0 - remove me
       
   187     inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); }
       
   188 
       
   189 private:
       
   190     QFontPrivate *d;
       
   191 };
       
   192 
       
   193 QT_END_NAMESPACE
       
   194 
       
   195 QT_END_HEADER
       
   196 
       
   197 #endif // QFONTMETRICS_H