Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/text/qfontmetrics.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    7676    \brief The QFontMetrics class provides font metrics information.
    7777
    78     \ingroup multimedia
     78    \ingroup painting
    7979    \ingroup shared
    80     \ingroup text
    8180
    8281    QFontMetrics functions calculate the size of characters and
     
    165164*/
    166165QFontMetrics::QFontMetrics(const QFont &font)
    167     : d(font.d)
    168 {
    169     d->ref.ref();
     166    : d(font.d.data())
     167{
    170168}
    171169
     
    197195        d->screen = screen;
    198196    } else {
    199         d = font.d;
    200         d->ref.ref();
     197        d = font.d.data();
    201198    }
    202199
     
    207204*/
    208205QFontMetrics::QFontMetrics(const QFontMetrics &fm)
    209     : d(fm.d)
    210 { d->ref.ref(); }
     206    : d(fm.d.data())
     207{
     208}
    211209
    212210/*!
     
    216214QFontMetrics::~QFontMetrics()
    217215{
    218     if (!d->ref.deref())
    219         delete d;
    220216}
    221217
     
    225221QFontMetrics &QFontMetrics::operator=(const QFontMetrics &fm)
    226222{
    227     qAtomicAssign(d, fm.d);
     223    d = fm.d.data();
    228224    return *this;
    229225}
     
    529525int QFontMetrics::width(const QString &text, int len) const
    530526{
    531     if (len < 0)
     527    int pos = text.indexOf(QLatin1Char('\x9c'));
     528    if (pos != -1) {
     529        len = (len < 0) ? pos : qMin(pos, len);
     530    } else if (len < 0) {
    532531        len = text.length();
     532    }
    533533    if (len == 0)
    534534        return 0;
    535535
    536     QTextEngine layout(text, d);
     536    QTextEngine layout(text, d.data());
    537537    layout.ignoreBidi = true;
    538538    return qRound(layout.width(0, len));
     
    558558    characters or non-spacing marks in the middle of a string, as the
    559559    glyph shaping and positioning of marks that happens when
    560     processing strings cannot be taken into account. Use charWidth()
    561     instead if you aren't looking for the width of isolated
    562     characters.
    563 
    564     \sa boundingRect(), charWidth()
     560    processing strings cannot be taken into account. When implementing
     561    an interactive text control, use QTextLayout instead.
     562
     563    \sa boundingRect()
    565564*/
    566565int QFontMetrics::width(QChar ch) const
     
    611610        int to = qMin(text.length(), pos + 8);
    612611        QString cstr = QString::fromRawData(text.unicode() + from, to - from);
    613         QTextEngine layout(cstr, d);
     612        QTextEngine layout(cstr, d.data());
    614613        layout.ignoreBidi = true;
    615614        layout.itemize();
     
    660659        return QRect();
    661660
    662     QTextEngine layout(text, d);
     661    QTextEngine layout(text, d.data());
    663662    layout.ignoreBidi = true;
    664663    layout.itemize();
     
    671670    were to be drawn at the origin of the coordinate system.
    672671
    673     Note that the bounding rectangle may extend to the left of (0, 0),
    674     e.g. for italicized fonts, and that the text output may cover \e
     672    Note that the bounding rectangle may extend to the left of (0, 0)
     673    (e.g., for italicized fonts), and that the text output may cover \e
    675674    all pixels in the bounding rectangle. For a space character the rectangle
    676675    will usually be empty.
     
    725724    \o Qt::TextSingleLine ignores newline characters in the text.
    726725    \o Qt::TextExpandTabs expands tabs (see below)
    727     \o Qt::TextShowMnemonic interprets "&amp;x" as \underline{x}, i.e. underlined.
     726    \o Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined.
    728727    \o Qt::TextWordWrap breaks the text to fit the rectangle.
    729728    \endlist
     
    769768    QRectF rb;
    770769    QRectF rr(rect);
    771     qt_format_text(QFont(d), rr, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
     770    qt_format_text(QFont(d.data()), rr, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
    772771                   tabArrayLen, 0);
    773772
     
    782781    \o Qt::TextSingleLine ignores newline characters.
    783782    \o Qt::TextExpandTabs expands tabs (see below)
    784     \o Qt::TextShowMnemonic interprets "&amp;x" as \underline{x}, i.e. underlined.
     783    \o Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined.
    785784    \o Qt::TextWordBreak breaks the text to fit the rectangle.
    786785    \endlist
     
    800799QSize QFontMetrics::size(int flags, const QString &text, int tabStops, int *tabArray) const
    801800{
    802     return boundingRect(QRect(0,0,0,0), flags, text, tabStops, tabArray).size();
     801    return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
    803802}
    804803
     
    830829        return QRect();
    831830
    832     QTextEngine layout(text, d);
     831    QTextEngine layout(text, d.data());
    833832    layout.ignoreBidi = true;
    834833    layout.itemize();
     
    859858    layouts. Note that this behavior is independent of the text
    860859    language.
    861 
    862860*/
    863861QString QFontMetrics::elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags) const
    864862{
    865     QStackTextEngine engine(text, QFont(d));
     863    QString _text = text;
     864    if (!(flags & Qt::TextLongestVariant)) {
     865        int posA = 0;
     866        int posB = _text.indexOf(QLatin1Char('\x9c'));
     867        while (posB >= 0) {
     868            QString portion = _text.mid(posA, posB - posA);
     869            if (size(flags, portion).width() <= width)
     870                return portion;
     871            posA = posB + 1;
     872            posB = _text.indexOf(QLatin1Char('\x9c'), posA);
     873        }
     874        _text = _text.mid(posA);
     875    }
     876    QStackTextEngine engine(_text, QFont(d.data()));
    866877    return engine.elidedText(mode, width, flags);
    867878}
     
    929940    \brief The QFontMetricsF class provides font metrics information.
    930941
    931     \ingroup multimedia
     942    \ingroup painting
    932943    \ingroup shared
    933     \ingroup text
    934944
    935945    QFontMetricsF functions calculate the size of characters and
     
    977987*/
    978988QFontMetricsF::QFontMetricsF(const QFontMetrics &fontMetrics)
    979     : d(fontMetrics.d)
    980 {
    981     d->ref.ref();
     989    : d(fontMetrics.d.data())
     990{
    982991}
    983992
     
    989998QFontMetricsF &QFontMetricsF::operator=(const QFontMetrics &other)
    990999{
    991     qAtomicAssign(d, other.d);
     1000    d = other.d.data();
    9921001    return *this;
    9931002}
     
    10071016*/
    10081017QFontMetricsF::QFontMetricsF(const QFont &font)
    1009     : d(font.d)
    1010 {
    1011     d->ref.ref();
     1018    : d(font.d.data())
     1019{
    10121020}
    10131021
     
    10391047        d->screen = screen;
    10401048    } else {
    1041         d = font.d;
    1042         d->ref.ref();
     1049        d = font.d.data();
    10431050    }
    10441051
     
    10491056*/
    10501057QFontMetricsF::QFontMetricsF(const QFontMetricsF &fm)
    1051     : d(fm.d)
    1052 { d->ref.ref(); }
     1058    : d(fm.d.data())
     1059{
     1060}
    10531061
    10541062/*!
     
    10581066QFontMetricsF::~QFontMetricsF()
    10591067{
    1060     if (!d->ref.deref())
    1061         delete d;
    10621068}
    10631069
     
    10671073QFontMetricsF &QFontMetricsF::operator=(const QFontMetricsF &fm)
    10681074{
    1069     qAtomicAssign(d, fm.d);
     1075    d = fm.d.data();
    10701076    return *this;
    10711077}
     
    13621368qreal QFontMetricsF::width(const QString &text) const
    13631369{
    1364     QTextEngine layout(text, d);
     1370    int pos = text.indexOf(QLatin1Char('\x9c'));
     1371    int len = (pos != -1) ? pos : text.length();
     1372
     1373    QTextEngine layout(text, d.data());
    13651374    layout.ignoreBidi = true;
    13661375    layout.itemize();
    1367     return layout.width(0, text.length()).toReal();
     1376    return layout.width(0, len).toReal();
    13681377}
    13691378
     
    13871396    characters or non-spacing marks in the middle of a string, as the
    13881397    glyph shaping and positioning of marks that happens when
    1389     processing strings cannot be taken into account. Use charWidth()
    1390     instead if you aren't looking for the width of isolated
    1391     characters.
     1398    processing strings cannot be taken into account. When implementing
     1399    an interactive text control, use QTextLayout instead.
    13921400
    13931401    \sa boundingRect()
     
    14401448        return QRectF();
    14411449
    1442     QTextEngine layout(text, d);
     1450    QTextEngine layout(text, d.data());
    14431451    layout.ignoreBidi = true;
    14441452    layout.itemize();
     
    15011509    \o Qt::TextSingleLine ignores newline characters in the text.
    15021510    \o Qt::TextExpandTabs expands tabs (see below)
    1503     \o Qt::TextShowMnemonic interprets "&amp;x" as \underline{x}, i.e. underlined.
     1511    \o Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined.
    15041512    \o Qt::TextWordWrap breaks the text to fit the rectangle.
    15051513    \endlist
     
    15481556
    15491557    QRectF rb;
    1550     qt_format_text(QFont(d), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
     1558    qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
    15511559                   tabArrayLen, 0);
    15521560    return rb;
     
    15601568    \o Qt::TextSingleLine ignores newline characters.
    15611569    \o Qt::TextExpandTabs expands tabs (see below)
    1562     \o Qt::TextShowMnemonic interprets "&amp;x" as \underline{x}, i.e. underlined.
     1570    \o Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined.
    15631571    \o Qt::TextWordBreak breaks the text to fit the rectangle.
    15641572    \endlist
     
    15831591QSizeF QFontMetricsF::size(int flags, const QString &text, int tabStops, int *tabArray) const
    15841592{
    1585     return boundingRect(QRectF(), flags, text, tabStops, tabArray).size();
     1593    return boundingRect(QRectF(), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
    15861594}
    15871595
     
    16131621        return QRect();
    16141622
    1615     QTextEngine layout(text, d);
     1623    QTextEngine layout(text, d.data());
    16161624    layout.ignoreBidi = true;
    16171625    layout.itemize();
     
    16381646QString QFontMetricsF::elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags) const
    16391647{
    1640     QStackTextEngine engine(text, QFont(d));
     1648    QString _text = text;
     1649    if (!(flags & Qt::TextLongestVariant)) {
     1650        int posA = 0;
     1651        int posB = _text.indexOf(QLatin1Char('\x9c'));
     1652        while (posB >= 0) {
     1653            QString portion = _text.mid(posA, posB - posA);
     1654            if (size(flags, portion).width() <= width)
     1655                return portion;
     1656            posA = posB + 1;
     1657            posB = _text.indexOf(QLatin1Char('\x9c'), posA);
     1658        }
     1659        _text = _text.mid(posA);
     1660    }
     1661    QStackTextEngine engine(_text, QFont(d.data()));
    16411662    return engine.elidedText(mode, QFixed::fromReal(width), flags);
    16421663}
Note: See TracChangeset for help on using the changeset viewer.