Changeset 561 for trunk/src/gui/text/qfontmetrics.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/text/qfontmetrics.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 76 76 \brief The QFontMetrics class provides font metrics information. 77 77 78 \ingroup multimedia78 \ingroup painting 79 79 \ingroup shared 80 \ingroup text81 80 82 81 QFontMetrics functions calculate the size of characters and … … 165 164 */ 166 165 QFontMetrics::QFontMetrics(const QFont &font) 167 : d(font.d) 168 { 169 d->ref.ref(); 166 : d(font.d.data()) 167 { 170 168 } 171 169 … … 197 195 d->screen = screen; 198 196 } else { 199 d = font.d; 200 d->ref.ref(); 197 d = font.d.data(); 201 198 } 202 199 … … 207 204 */ 208 205 QFontMetrics::QFontMetrics(const QFontMetrics &fm) 209 : d(fm.d) 210 { d->ref.ref(); } 206 : d(fm.d.data()) 207 { 208 } 211 209 212 210 /*! … … 216 214 QFontMetrics::~QFontMetrics() 217 215 { 218 if (!d->ref.deref())219 delete d;220 216 } 221 217 … … 225 221 QFontMetrics &QFontMetrics::operator=(const QFontMetrics &fm) 226 222 { 227 qAtomicAssign(d, fm.d);223 d = fm.d.data(); 228 224 return *this; 229 225 } … … 529 525 int QFontMetrics::width(const QString &text, int len) const 530 526 { 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) { 532 531 len = text.length(); 532 } 533 533 if (len == 0) 534 534 return 0; 535 535 536 QTextEngine layout(text, d );536 QTextEngine layout(text, d.data()); 537 537 layout.ignoreBidi = true; 538 538 return qRound(layout.width(0, len)); … … 558 558 characters or non-spacing marks in the middle of a string, as the 559 559 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() 565 564 */ 566 565 int QFontMetrics::width(QChar ch) const … … 611 610 int to = qMin(text.length(), pos + 8); 612 611 QString cstr = QString::fromRawData(text.unicode() + from, to - from); 613 QTextEngine layout(cstr, d );612 QTextEngine layout(cstr, d.data()); 614 613 layout.ignoreBidi = true; 615 614 layout.itemize(); … … 660 659 return QRect(); 661 660 662 QTextEngine layout(text, d );661 QTextEngine layout(text, d.data()); 663 662 layout.ignoreBidi = true; 664 663 layout.itemize(); … … 671 670 were to be drawn at the origin of the coordinate system. 672 671 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 \e672 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 675 674 all pixels in the bounding rectangle. For a space character the rectangle 676 675 will usually be empty. … … 725 724 \o Qt::TextSingleLine ignores newline characters in the text. 726 725 \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. 728 727 \o Qt::TextWordWrap breaks the text to fit the rectangle. 729 728 \endlist … … 769 768 QRectF rb; 770 769 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, 772 771 tabArrayLen, 0); 773 772 … … 782 781 \o Qt::TextSingleLine ignores newline characters. 783 782 \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. 785 784 \o Qt::TextWordBreak breaks the text to fit the rectangle. 786 785 \endlist … … 800 799 QSize QFontMetrics::size(int flags, const QString &text, int tabStops, int *tabArray) const 801 800 { 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(); 803 802 } 804 803 … … 830 829 return QRect(); 831 830 832 QTextEngine layout(text, d );831 QTextEngine layout(text, d.data()); 833 832 layout.ignoreBidi = true; 834 833 layout.itemize(); … … 859 858 layouts. Note that this behavior is independent of the text 860 859 language. 861 862 860 */ 863 861 QString QFontMetrics::elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags) const 864 862 { 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())); 866 877 return engine.elidedText(mode, width, flags); 867 878 } … … 929 940 \brief The QFontMetricsF class provides font metrics information. 930 941 931 \ingroup multimedia942 \ingroup painting 932 943 \ingroup shared 933 \ingroup text934 944 935 945 QFontMetricsF functions calculate the size of characters and … … 977 987 */ 978 988 QFontMetricsF::QFontMetricsF(const QFontMetrics &fontMetrics) 979 : d(fontMetrics.d) 980 { 981 d->ref.ref(); 989 : d(fontMetrics.d.data()) 990 { 982 991 } 983 992 … … 989 998 QFontMetricsF &QFontMetricsF::operator=(const QFontMetrics &other) 990 999 { 991 qAtomicAssign(d, other.d);1000 d = other.d.data(); 992 1001 return *this; 993 1002 } … … 1007 1016 */ 1008 1017 QFontMetricsF::QFontMetricsF(const QFont &font) 1009 : d(font.d) 1010 { 1011 d->ref.ref(); 1018 : d(font.d.data()) 1019 { 1012 1020 } 1013 1021 … … 1039 1047 d->screen = screen; 1040 1048 } else { 1041 d = font.d; 1042 d->ref.ref(); 1049 d = font.d.data(); 1043 1050 } 1044 1051 … … 1049 1056 */ 1050 1057 QFontMetricsF::QFontMetricsF(const QFontMetricsF &fm) 1051 : d(fm.d) 1052 { d->ref.ref(); } 1058 : d(fm.d.data()) 1059 { 1060 } 1053 1061 1054 1062 /*! … … 1058 1066 QFontMetricsF::~QFontMetricsF() 1059 1067 { 1060 if (!d->ref.deref())1061 delete d;1062 1068 } 1063 1069 … … 1067 1073 QFontMetricsF &QFontMetricsF::operator=(const QFontMetricsF &fm) 1068 1074 { 1069 qAtomicAssign(d, fm.d);1075 d = fm.d.data(); 1070 1076 return *this; 1071 1077 } … … 1362 1368 qreal QFontMetricsF::width(const QString &text) const 1363 1369 { 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()); 1365 1374 layout.ignoreBidi = true; 1366 1375 layout.itemize(); 1367 return layout.width(0, text.length()).toReal();1376 return layout.width(0, len).toReal(); 1368 1377 } 1369 1378 … … 1387 1396 characters or non-spacing marks in the middle of a string, as the 1388 1397 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. 1392 1400 1393 1401 \sa boundingRect() … … 1440 1448 return QRectF(); 1441 1449 1442 QTextEngine layout(text, d );1450 QTextEngine layout(text, d.data()); 1443 1451 layout.ignoreBidi = true; 1444 1452 layout.itemize(); … … 1501 1509 \o Qt::TextSingleLine ignores newline characters in the text. 1502 1510 \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. 1504 1512 \o Qt::TextWordWrap breaks the text to fit the rectangle. 1505 1513 \endlist … … 1548 1556 1549 1557 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, 1551 1559 tabArrayLen, 0); 1552 1560 return rb; … … 1560 1568 \o Qt::TextSingleLine ignores newline characters. 1561 1569 \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. 1563 1571 \o Qt::TextWordBreak breaks the text to fit the rectangle. 1564 1572 \endlist … … 1583 1591 QSizeF QFontMetricsF::size(int flags, const QString &text, int tabStops, int *tabArray) const 1584 1592 { 1585 return boundingRect(QRectF(), flags , text, tabStops, tabArray).size();1593 return boundingRect(QRectF(), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size(); 1586 1594 } 1587 1595 … … 1613 1621 return QRect(); 1614 1622 1615 QTextEngine layout(text, d );1623 QTextEngine layout(text, d.data()); 1616 1624 layout.ignoreBidi = true; 1617 1625 layout.itemize(); … … 1638 1646 QString QFontMetricsF::elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags) const 1639 1647 { 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())); 1641 1662 return engine.elidedText(mode, QFixed::fromReal(width), flags); 1642 1663 }
Note:
See TracChangeset
for help on using the changeset viewer.