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