| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qfont.h" | - |
| 43 | #include "qpaintdevice.h" | - |
| 44 | #include "qfontmetrics.h" | - |
| 45 | | - |
| 46 | #include "qfont_p.h" | - |
| 47 | #include "qfontengine_p.h" | - |
| 48 | #include <private/qunicodetables_p.h> | - |
| 49 | | - |
| 50 | #include <math.h> | - |
| 51 | | - |
| 52 | | - |
| 53 | QT_BEGIN_NAMESPACE | - |
| 54 | | - |
| 55 | | - |
| 56 | extern void qt_format_text(const QFont& font, const QRectF &_r, | - |
| 57 | int tf, const QString &text, QRectF *brect, | - |
| 58 | int tabStops, int *tabArray, int tabArrayLen, | - |
| 59 | QPainter *painter); | - |
| 60 | | - |
| 61 | /***************************************************************************** | - |
| 62 | QFontMetrics member functions | - |
| 63 | *****************************************************************************/ | - |
| 64 | | - |
| 65 | /*! | - |
| 66 | \class QFontMetrics | - |
| 67 | \reentrant | - |
| 68 | \inmodule QtGui | - |
| 69 | | - |
| 70 | \brief The QFontMetrics class provides font metrics information. | - |
| 71 | | - |
| 72 | \ingroup painting | - |
| 73 | \ingroup shared | - |
| 74 | | - |
| 75 | QFontMetrics functions calculate the size of characters and | - |
| 76 | strings for a given font. There are three ways you can create a | - |
| 77 | QFontMetrics object: | - |
| 78 | | - |
| 79 | \list 1 | - |
| 80 | \li Calling the QFontMetrics constructor with a QFont creates a | - |
| 81 | font metrics object for a screen-compatible font, i.e. the font | - |
| 82 | cannot be a printer font. If the font is changed | - |
| 83 | later, the font metrics object is \e not updated. | - |
| 84 | | - |
| 85 | (Note: If you use a printer font the values returned may be | - |
| 86 | inaccurate. Printer fonts are not always accessible so the nearest | - |
| 87 | screen font is used if a printer font is supplied.) | - |
| 88 | | - |
| 89 | \li QWidget::fontMetrics() returns the font metrics for a widget's | - |
| 90 | font. This is equivalent to QFontMetrics(widget->font()). If the | - |
| 91 | widget's font is changed later, the font metrics object is \e not | - |
| 92 | updated. | - |
| 93 | | - |
| 94 | \li QPainter::fontMetrics() returns the font metrics for a | - |
| 95 | painter's current font. If the painter's font is changed later, the | - |
| 96 | font metrics object is \e not updated. | - |
| 97 | \endlist | - |
| 98 | | - |
| 99 | Once created, the object provides functions to access the | - |
| 100 | individual metrics of the font, its characters, and for strings | - |
| 101 | rendered in the font. | - |
| 102 | | - |
| 103 | There are several functions that operate on the font: ascent(), | - |
| 104 | descent(), height(), leading() and lineSpacing() return the basic | - |
| 105 | size properties of the font. The underlinePos(), overlinePos(), | - |
| 106 | strikeOutPos() and lineWidth() functions, return the properties of | - |
| 107 | the line that underlines, overlines or strikes out the | - |
| 108 | characters. These functions are all fast. | - |
| 109 | | - |
| 110 | There are also some functions that operate on the set of glyphs in | - |
| 111 | the font: minLeftBearing(), minRightBearing() and maxWidth(). | - |
| 112 | These are by necessity slow, and we recommend avoiding them if | - |
| 113 | possible. | - |
| 114 | | - |
| 115 | For each character, you can get its width(), leftBearing() and | - |
| 116 | rightBearing() and find out whether it is in the font using | - |
| 117 | inFont(). You can also treat the character as a string, and use | - |
| 118 | the string functions on it. | - |
| 119 | | - |
| 120 | The string functions include width(), to return the width of a | - |
| 121 | string in pixels (or points, for a printer), boundingRect(), to | - |
| 122 | return a rectangle large enough to contain the rendered string, | - |
| 123 | and size(), to return the size of that rectangle. | - |
| 124 | | - |
| 125 | Example: | - |
| 126 | \snippet code/src_gui_text_qfontmetrics.cpp 0 | - |
| 127 | | - |
| 128 | \sa QFont, QFontInfo, QFontDatabase, {Character Map Example} | - |
| 129 | */ | - |
| 130 | | - |
| 131 | /*! | - |
| 132 | \fn QRect QFontMetrics::boundingRect(int x, int y, int width, int height, | - |
| 133 | int flags, const QString &text, int tabStops, int *tabArray) const | - |
| 134 | \overload | - |
| 135 | | - |
| 136 | Returns the bounding rectangle for the given \a text within the | - |
| 137 | rectangle specified by the \a x and \a y coordinates, \a width, and | - |
| 138 | \a height. | - |
| 139 | | - |
| 140 | If Qt::TextExpandTabs is set in \a flags and \a tabArray is | - |
| 141 | non-null, it specifies a 0-terminated sequence of pixel-positions | - |
| 142 | for tabs; otherwise, if \a tabStops is non-zero, it is used as the | - |
| 143 | tab spacing (in pixels). | - |
| 144 | */ | - |
| 145 | | - |
| 146 | /*! | - |
| 147 | Constructs a font metrics object for \a font. | - |
| 148 | | - |
| 149 | The font metrics will be compatible with the paintdevice used to | - |
| 150 | create \a font. | - |
| 151 | | - |
| 152 | The font metrics object holds the information for the font that is | - |
| 153 | passed in the constructor at the time it is created, and is not | - |
| 154 | updated if the font's attributes are changed later. | - |
| 155 | | - |
| 156 | Use QFontMetrics(const QFont &, QPaintDevice *) to get the font | - |
| 157 | metrics that are compatible with a certain paint device. | - |
| 158 | */ | - |
| 159 | QFontMetrics::QFontMetrics(const QFont &font) | - |
| 160 | : d(font.d.data()) | - |
| 161 | { | - |
| 162 | } executed: }Execution Count:930718 | 930718 |
| 163 | | - |
| 164 | /*! | - |
| 165 | Constructs a font metrics object for \a font and \a paintdevice. | - |
| 166 | | - |
| 167 | The font metrics will be compatible with the paintdevice passed. | - |
| 168 | If the \a paintdevice is 0, the metrics will be screen-compatible, | - |
| 169 | ie. the metrics you get if you use the font for drawing text on a | - |
| 170 | \l{QWidget}{widgets} or \l{QPixmap}{pixmaps}, | - |
| 171 | not on a QPicture or QPrinter. | - |
| 172 | | - |
| 173 | The font metrics object holds the information for the font that is | - |
| 174 | passed in the constructor at the time it is created, and is not | - |
| 175 | updated if the font's attributes are changed later. | - |
| 176 | */ | - |
| 177 | QFontMetrics::QFontMetrics(const QFont &font, QPaintDevice *paintdevice) | - |
| 178 | { | - |
| 179 | int dpi = paintdevice ? paintdevice->logicalDpiY() : qt_defaultDpi(); partially evaluated: paintdevice| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 180 | const int screen = 0; executed (the execution status of this line is deduced): const int screen = 0; | - |
| 181 | if (font.d->dpi != dpi || font.d->screen != screen ) { partially evaluated: font.d->dpi != dpi| yes Evaluation Count:1 | no Evaluation Count:0 |
never evaluated: font.d->screen != screen | 0-1 |
| 182 | d = new QFontPrivate(*font.d); executed (the execution status of this line is deduced): d = new QFontPrivate(*font.d); | - |
| 183 | d->dpi = dpi; executed (the execution status of this line is deduced): d->dpi = dpi; | - |
| 184 | d->screen = screen; executed (the execution status of this line is deduced): d->screen = screen; | - |
| 185 | } else { executed: }Execution Count:1 | 1 |
| 186 | d = font.d.data(); never executed (the execution status of this line is deduced): d = font.d.data(); | - |
| 187 | } | 0 |
| 188 | | - |
| 189 | } | - |
| 190 | | - |
| 191 | /*! | - |
| 192 | Constructs a copy of \a fm. | - |
| 193 | */ | - |
| 194 | QFontMetrics::QFontMetrics(const QFontMetrics &fm) | - |
| 195 | : d(fm.d.data()) | - |
| 196 | { | - |
| 197 | } executed: }Execution Count:11900 | 11900 |
| 198 | | - |
| 199 | /*! | - |
| 200 | Destroys the font metrics object and frees all allocated | - |
| 201 | resources. | - |
| 202 | */ | - |
| 203 | QFontMetrics::~QFontMetrics() | - |
| 204 | { | - |
| 205 | } | - |
| 206 | | - |
| 207 | /*! | - |
| 208 | Assigns the font metrics \a fm. | - |
| 209 | */ | - |
| 210 | QFontMetrics &QFontMetrics::operator=(const QFontMetrics &fm) | - |
| 211 | { | - |
| 212 | d = fm.d.data(); executed (the execution status of this line is deduced): d = fm.d.data(); | - |
| 213 | return *this; executed: return *this;Execution Count:214207 | 214207 |
| 214 | } | - |
| 215 | | - |
| 216 | /*! | - |
| 217 | \fn void QFontMetrics::swap(QFontMetrics &other) | - |
| 218 | \since 5.0 | - |
| 219 | | - |
| 220 | Swaps this font metrics instance with \a other. This function is | - |
| 221 | very fast and never fails. | - |
| 222 | */ | - |
| 223 | | - |
| 224 | /*! | - |
| 225 | Returns true if \a other is equal to this object; otherwise | - |
| 226 | returns false. | - |
| 227 | | - |
| 228 | Two font metrics are considered equal if they were constructed | - |
| 229 | from the same QFont and the paint devices they were constructed | - |
| 230 | for are considered compatible. | - |
| 231 | | - |
| 232 | \sa operator!=() | - |
| 233 | */ | - |
| 234 | bool QFontMetrics::operator ==(const QFontMetrics &other) const | - |
| 235 | { | - |
| 236 | return d == other.d; never executed: return d == other.d; | 0 |
| 237 | } | - |
| 238 | | - |
| 239 | /*! | - |
| 240 | \fn bool QFontMetrics::operator !=(const QFontMetrics &other) const | - |
| 241 | | - |
| 242 | Returns true if \a other is not equal to this object; otherwise returns false. | - |
| 243 | | - |
| 244 | Two font metrics are considered equal if they were constructed | - |
| 245 | from the same QFont and the paint devices they were constructed | - |
| 246 | for are considered compatible. | - |
| 247 | | - |
| 248 | \sa operator==() | - |
| 249 | */ | - |
| 250 | | - |
| 251 | /*! | - |
| 252 | Returns the ascent of the font. | - |
| 253 | | - |
| 254 | The ascent of a font is the distance from the baseline to the | - |
| 255 | highest position characters extend to. In practice, some font | - |
| 256 | designers break this rule, e.g. when they put more than one accent | - |
| 257 | on top of a character, or to accommodate an unusual character in | - |
| 258 | an exotic language, so it is possible (though rare) that this | - |
| 259 | value will be too small. | - |
| 260 | | - |
| 261 | \sa descent() | - |
| 262 | */ | - |
| 263 | int QFontMetrics::ascent() const | - |
| 264 | { | - |
| 265 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 266 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 267 | return qRound(engine->ascent()); executed: return qRound(engine->ascent());Execution Count:996 | 996 |
| 268 | } | - |
| 269 | | - |
| 270 | | - |
| 271 | /*! | - |
| 272 | Returns the descent of the font. | - |
| 273 | | - |
| 274 | The descent is the distance from the base line to the lowest point | - |
| 275 | characters extend to. In practice, some font designers break this rule, | - |
| 276 | e.g. to accommodate an unusual character in an exotic language, so | - |
| 277 | it is possible (though rare) that this value will be too small. | - |
| 278 | | - |
| 279 | \sa ascent() | - |
| 280 | */ | - |
| 281 | int QFontMetrics::descent() const | - |
| 282 | { | - |
| 283 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 284 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 285 | return qRound(engine->descent()); executed: return qRound(engine->descent());Execution Count:242 | 242 |
| 286 | } | - |
| 287 | | - |
| 288 | /*! | - |
| 289 | Returns the height of the font. | - |
| 290 | | - |
| 291 | This is always equal to ascent()+descent()+1 (the 1 is for the | - |
| 292 | base line). | - |
| 293 | | - |
| 294 | \sa leading(), lineSpacing() | - |
| 295 | */ | - |
| 296 | int QFontMetrics::height() const | - |
| 297 | { | - |
| 298 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 299 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 300 | return qRound(engine->ascent()) + qRound(engine->descent()); executed: return qRound(engine->ascent()) + qRound(engine->descent());Execution Count:70025 | 70025 |
| 301 | } | - |
| 302 | | - |
| 303 | /*! | - |
| 304 | Returns the leading of the font. | - |
| 305 | | - |
| 306 | This is the natural inter-line spacing. | - |
| 307 | | - |
| 308 | \sa height(), lineSpacing() | - |
| 309 | */ | - |
| 310 | int QFontMetrics::leading() const | - |
| 311 | { | - |
| 312 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 313 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 314 | return qRound(engine->leading()); executed: return qRound(engine->leading());Execution Count:593 | 593 |
| 315 | } | - |
| 316 | | - |
| 317 | /*! | - |
| 318 | Returns the distance from one base line to the next. | - |
| 319 | | - |
| 320 | This value is always equal to leading()+height(). | - |
| 321 | | - |
| 322 | \sa height(), leading() | - |
| 323 | */ | - |
| 324 | int QFontMetrics::lineSpacing() const | - |
| 325 | { | - |
| 326 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 327 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 328 | return qRound(engine->leading()) + qRound(engine->ascent()) + qRound(engine->descent()); executed: return qRound(engine->leading()) + qRound(engine->ascent()) + qRound(engine->descent());Execution Count:713 | 713 |
| 329 | } | - |
| 330 | | - |
| 331 | /*! | - |
| 332 | Returns the minimum left bearing of the font. | - |
| 333 | | - |
| 334 | This is the smallest leftBearing(char) of all characters in the | - |
| 335 | font. | - |
| 336 | | - |
| 337 | Note that this function can be very slow if the font is large. | - |
| 338 | | - |
| 339 | \sa minRightBearing(), leftBearing() | - |
| 340 | */ | - |
| 341 | int QFontMetrics::minLeftBearing() const | - |
| 342 | { | - |
| 343 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 344 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 345 | return qRound(engine->minLeftBearing()); executed: return qRound(engine->minLeftBearing());Execution Count:762 | 762 |
| 346 | } | - |
| 347 | | - |
| 348 | /*! | - |
| 349 | Returns the minimum right bearing of the font. | - |
| 350 | | - |
| 351 | This is the smallest rightBearing(char) of all characters in the | - |
| 352 | font. | - |
| 353 | | - |
| 354 | Note that this function can be very slow if the font is large. | - |
| 355 | | - |
| 356 | \sa minLeftBearing(), rightBearing() | - |
| 357 | */ | - |
| 358 | int QFontMetrics::minRightBearing() const | - |
| 359 | { | - |
| 360 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 361 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 362 | return qRound(engine->minRightBearing()); executed: return qRound(engine->minRightBearing());Execution Count:762 | 762 |
| 363 | } | - |
| 364 | | - |
| 365 | /*! | - |
| 366 | Returns the width of the widest character in the font. | - |
| 367 | */ | - |
| 368 | int QFontMetrics::maxWidth() const | - |
| 369 | { | - |
| 370 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 371 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 372 | return qRound(engine->maxCharWidth()); executed: return qRound(engine->maxCharWidth());Execution Count:2625 | 2625 |
| 373 | } | - |
| 374 | | - |
| 375 | /*! | - |
| 376 | Returns the 'x' height of the font. This is often but not always | - |
| 377 | the same as the height of the character 'x'. | - |
| 378 | */ | - |
| 379 | int QFontMetrics::xHeight() const | - |
| 380 | { | - |
| 381 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 382 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 383 | if (d->capital == QFont::SmallCaps) never evaluated: d->capital == QFont::SmallCaps | 0 |
| 384 | return qRound(d->smallCapsFontPrivate()->engineForScript(QUnicodeTables::Common)->ascent()); never executed: return qRound(d->smallCapsFontPrivate()->engineForScript(QUnicodeTables::Common)->ascent()); | 0 |
| 385 | return qRound(engine->xHeight()); never executed: return qRound(engine->xHeight()); | 0 |
| 386 | } | - |
| 387 | | - |
| 388 | /*! | - |
| 389 | \since 4.2 | - |
| 390 | | - |
| 391 | Returns the average width of glyphs in the font. | - |
| 392 | */ | - |
| 393 | int QFontMetrics::averageCharWidth() const | - |
| 394 | { | - |
| 395 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 396 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 397 | return qRound(engine->averageCharWidth()); executed: return qRound(engine->averageCharWidth());Execution Count:210 | 210 |
| 398 | } | - |
| 399 | | - |
| 400 | /*! | - |
| 401 | Returns true if character \a ch is a valid character in the font; | - |
| 402 | otherwise returns false. | - |
| 403 | */ | - |
| 404 | bool QFontMetrics::inFont(QChar ch) const | - |
| 405 | { | - |
| 406 | const int script = QUnicodeTables::script(ch); executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 407 | QFontEngine *engine = d->engineForScript(script); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(script); | - |
| 408 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 409 | if (engine->type() == QFontEngine::Box) partially evaluated: engine->type() == QFontEngine::Box| no Evaluation Count:0 | yes Evaluation Count:6 |
| 0-6 |
| 410 | return false; never executed: return false; | 0 |
| 411 | return engine->canRender(&ch, 1); executed: return engine->canRender(&ch, 1);Execution Count:6 | 6 |
| 412 | } | - |
| 413 | | - |
| 414 | /*! | - |
| 415 | Returns true if the character \a ucs4 encoded in UCS-4/UTF-32 is a valid | - |
| 416 | character in the font; otherwise returns false. | - |
| 417 | */ | - |
| 418 | bool QFontMetrics::inFontUcs4(uint ucs4) const | - |
| 419 | { | - |
| 420 | const int script = QUnicodeTables::script(ucs4); executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ucs4); | - |
| 421 | QFontEngine *engine = d->engineForScript(script); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(script); | - |
| 422 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 423 | if (engine->type() == QFontEngine::Box) partially evaluated: engine->type() == QFontEngine::Box| no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
| 424 | return false; never executed: return false; | 0 |
| 425 | return engine->canRender(ucs4); executed: return engine->canRender(ucs4);Execution Count:1 | 1 |
| 426 | } | - |
| 427 | | - |
| 428 | /*! | - |
| 429 | Returns the left bearing of character \a ch in the font. | - |
| 430 | | - |
| 431 | The left bearing is the right-ward distance of the left-most pixel | - |
| 432 | of the character from the logical origin of the character. This | - |
| 433 | value is negative if the pixels of the character extend to the | - |
| 434 | left of the logical origin. | - |
| 435 | | - |
| 436 | See width(QChar) for a graphical description of this metric. | - |
| 437 | | - |
| 438 | \sa rightBearing(), minLeftBearing(), width() | - |
| 439 | */ | - |
| 440 | int QFontMetrics::leftBearing(QChar ch) const | - |
| 441 | { | - |
| 442 | const int script = QUnicodeTables::script(ch); never executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 443 | QFontEngine *engine; never executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 444 | if (d->capital == QFont::SmallCaps && ch.isLower()) never evaluated: d->capital == QFont::SmallCaps never evaluated: ch.isLower() | 0 |
| 445 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 446 | else | - |
| 447 | engine = d->engineForScript(script); never executed: engine = d->engineForScript(script); | 0 |
| 448 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 449 | if (engine->type() == QFontEngine::Box) never evaluated: engine->type() == QFontEngine::Box | 0 |
| 450 | return 0; never executed: return 0; | 0 |
| 451 | | - |
| 452 | d->alterCharForCapitalization(ch); never executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 453 | | - |
| 454 | QGlyphLayoutArray<10> glyphs; never executed (the execution status of this line is deduced): QGlyphLayoutArray<10> glyphs; | - |
| 455 | int nglyphs = 9; never executed (the execution status of this line is deduced): int nglyphs = 9; | - |
| 456 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); never executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); | - |
| 457 | // ### can nglyphs != 1 happen at all? Not currently I think | - |
| 458 | qreal lb; never executed (the execution status of this line is deduced): qreal lb; | - |
| 459 | engine->getGlyphBearings(glyphs.glyphs[0], &lb); never executed (the execution status of this line is deduced): engine->getGlyphBearings(glyphs.glyphs[0], &lb); | - |
| 460 | return qRound(lb); never executed: return qRound(lb); | 0 |
| 461 | } | - |
| 462 | | - |
| 463 | /*! | - |
| 464 | Returns the right bearing of character \a ch in the font. | - |
| 465 | | - |
| 466 | The right bearing is the left-ward distance of the right-most | - |
| 467 | pixel of the character from the logical origin of a subsequent | - |
| 468 | character. This value is negative if the pixels of the character | - |
| 469 | extend to the right of the width() of the character. | - |
| 470 | | - |
| 471 | See width() for a graphical description of this metric. | - |
| 472 | | - |
| 473 | \sa leftBearing(), minRightBearing(), width() | - |
| 474 | */ | - |
| 475 | int QFontMetrics::rightBearing(QChar ch) const | - |
| 476 | { | - |
| 477 | const int script = QUnicodeTables::script(ch); never executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 478 | QFontEngine *engine; never executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 479 | if (d->capital == QFont::SmallCaps && ch.isLower()) never evaluated: d->capital == QFont::SmallCaps never evaluated: ch.isLower() | 0 |
| 480 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 481 | else | - |
| 482 | engine = d->engineForScript(script); never executed: engine = d->engineForScript(script); | 0 |
| 483 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 484 | if (engine->type() == QFontEngine::Box) never evaluated: engine->type() == QFontEngine::Box | 0 |
| 485 | return 0; never executed: return 0; | 0 |
| 486 | | - |
| 487 | d->alterCharForCapitalization(ch); never executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 488 | | - |
| 489 | QGlyphLayoutArray<10> glyphs; never executed (the execution status of this line is deduced): QGlyphLayoutArray<10> glyphs; | - |
| 490 | int nglyphs = 9; never executed (the execution status of this line is deduced): int nglyphs = 9; | - |
| 491 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); never executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); | - |
| 492 | // ### can nglyphs != 1 happen at all? Not currently I think | - |
| 493 | qreal rb; never executed (the execution status of this line is deduced): qreal rb; | - |
| 494 | engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb); never executed (the execution status of this line is deduced): engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb); | - |
| 495 | return qRound(rb); never executed: return qRound(rb); | 0 |
| 496 | } | - |
| 497 | | - |
| 498 | /*! | - |
| 499 | Returns the width in pixels of the first \a len characters of \a | - |
| 500 | text. If \a len is negative (the default), the entire string is | - |
| 501 | used. | - |
| 502 | | - |
| 503 | Note that this value is \e not equal to boundingRect().width(); | - |
| 504 | boundingRect() returns a rectangle describing the pixels this | - |
| 505 | string will cover whereas width() returns the distance to where | - |
| 506 | the next string should be drawn. | - |
| 507 | | - |
| 508 | \sa boundingRect() | - |
| 509 | */ | - |
| 510 | int QFontMetrics::width(const QString &text, int len) const | - |
| 511 | { | - |
| 512 | return width(text, len, 0); executed: return width(text, len, 0);Execution Count:7747 | 7747 |
| 513 | } | - |
| 514 | | - |
| 515 | /*! | - |
| 516 | \internal | - |
| 517 | */ | - |
| 518 | int QFontMetrics::width(const QString &text, int len, int flags) const | - |
| 519 | { | - |
| 520 | int pos = text.indexOf(QLatin1Char('\x9c')); executed (the execution status of this line is deduced): int pos = text.indexOf(QLatin1Char('\x9c')); | - |
| 521 | if (pos != -1) { partially evaluated: pos != -1| no Evaluation Count:0 | yes Evaluation Count:7748 |
| 0-7748 |
| 522 | len = (len < 0) ? pos : qMin(pos, len); never evaluated: (len < 0) | 0 |
| 523 | } else if (len < 0) { never executed: } evaluated: len < 0| yes Evaluation Count:7746 | yes Evaluation Count:2 |
| 0-7746 |
| 524 | len = text.length(); executed (the execution status of this line is deduced): len = text.length(); | - |
| 525 | } executed: }Execution Count:7746 | 7746 |
| 526 | if (len == 0) evaluated: len == 0| yes Evaluation Count:164 | yes Evaluation Count:7584 |
| 164-7584 |
| 527 | return 0; executed: return 0;Execution Count:164 | 164 |
| 528 | | - |
| 529 | if (flags & Qt::TextBypassShaping) { evaluated: flags & Qt::TextBypassShaping| yes Evaluation Count:1 | yes Evaluation Count:7583 |
| 1-7583 |
| 530 | // Skip harfbuzz complex shaping, only use advances | - |
| 531 | int numGlyphs = len; executed (the execution status of this line is deduced): int numGlyphs = len; | - |
| 532 | QVarLengthGlyphLayoutArray glyphs(numGlyphs); executed (the execution status of this line is deduced): QVarLengthGlyphLayoutArray glyphs(numGlyphs); | - |
| 533 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 534 | if (!engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0)) { partially evaluated: !engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0)| no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
| 535 | glyphs.resize(numGlyphs); never executed (the execution status of this line is deduced): glyphs.resize(numGlyphs); | - |
| 536 | if (!engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0)) never evaluated: !engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0) | 0 |
| 537 | Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice"); never executed: qt_noop(); | 0 |
| 538 | } | 0 |
| 539 | | - |
| 540 | QFixed width; executed (the execution status of this line is deduced): QFixed width; | - |
| 541 | for (int i = 0; i < numGlyphs; ++i) evaluated: i < numGlyphs| yes Evaluation Count:155 | yes Evaluation Count:1 |
| 1-155 |
| 542 | width += glyphs.advances_x[i]; executed: width += glyphs.advances_x[i];Execution Count:155 | 155 |
| 543 | return qRound(width); executed: return qRound(width);Execution Count:1 | 1 |
| 544 | } | - |
| 545 | | - |
| 546 | QStackTextEngine layout(text, QFont(d.data())); executed (the execution status of this line is deduced): QStackTextEngine layout(text, QFont(d.data())); | - |
| 547 | layout.ignoreBidi = true; executed (the execution status of this line is deduced): layout.ignoreBidi = true; | - |
| 548 | return qRound(layout.width(0, len)); executed: return qRound(layout.width(0, len));Execution Count:7583 | 7583 |
| 549 | } | - |
| 550 | | - |
| 551 | /*! | - |
| 552 | \overload | - |
| 553 | | - |
| 554 | \image bearings.png Bearings | - |
| 555 | | - |
| 556 | Returns the logical width of character \a ch in pixels. This is a | - |
| 557 | distance appropriate for drawing a subsequent character after \a | - |
| 558 | ch. | - |
| 559 | | - |
| 560 | Some of the metrics are described in the image to the right. The | - |
| 561 | central dark rectangles cover the logical width() of each | - |
| 562 | character. The outer pale rectangles cover the leftBearing() and | - |
| 563 | rightBearing() of each character. Notice that the bearings of "f" | - |
| 564 | in this particular font are both negative, while the bearings of | - |
| 565 | "o" are both positive. | - |
| 566 | | - |
| 567 | \warning This function will produce incorrect results for Arabic | - |
| 568 | characters or non-spacing marks in the middle of a string, as the | - |
| 569 | glyph shaping and positioning of marks that happens when | - |
| 570 | processing strings cannot be taken into account. When implementing | - |
| 571 | an interactive text control, use QTextLayout instead. | - |
| 572 | | - |
| 573 | \sa boundingRect() | - |
| 574 | */ | - |
| 575 | int QFontMetrics::width(QChar ch) const | - |
| 576 | { | - |
| 577 | if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing) partially evaluated: QChar::category(ch.unicode()) == QChar::Mark_NonSpacing| no Evaluation Count:0 | yes Evaluation Count:1946 |
| 0-1946 |
| 578 | return 0; never executed: return 0; | 0 |
| 579 | | - |
| 580 | const int script = QUnicodeTables::script(ch); executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 581 | QFontEngine *engine; executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 582 | if (d->capital == QFont::SmallCaps && ch.isLower()) partially evaluated: d->capital == QFont::SmallCaps| no Evaluation Count:0 | yes Evaluation Count:1946 |
never evaluated: ch.isLower() | 0-1946 |
| 583 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 584 | else | - |
| 585 | engine = d->engineForScript(script); executed: engine = d->engineForScript(script);Execution Count:1946 | 1946 |
| 586 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 587 | | - |
| 588 | d->alterCharForCapitalization(ch); executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 589 | | - |
| 590 | QGlyphLayoutArray<8> glyphs; executed (the execution status of this line is deduced): QGlyphLayoutArray<8> glyphs; | - |
| 591 | int nglyphs = 7; executed (the execution status of this line is deduced): int nglyphs = 7; | - |
| 592 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); | - |
| 593 | return qRound(glyphs.advances_x[0]); executed: return qRound(glyphs.advances_x[0]);Execution Count:1946 | 1946 |
| 594 | } | - |
| 595 | | - |
| 596 | /*! \obsolete | - |
| 597 | | - |
| 598 | Returns the width of the character at position \a pos in the | - |
| 599 | string \a text. | - |
| 600 | | - |
| 601 | The whole string is needed, as the glyph drawn may change | - |
| 602 | depending on the context (the letter before and after the current | - |
| 603 | one) for some languages (e.g. Arabic). | - |
| 604 | | - |
| 605 | This function also takes non spacing marks and ligatures into | - |
| 606 | account. | - |
| 607 | */ | - |
| 608 | int QFontMetrics::charWidth(const QString &text, int pos) const | - |
| 609 | { | - |
| 610 | if (pos < 0 || pos > (int)text.length()) partially evaluated: pos < 0| no Evaluation Count:0 | yes Evaluation Count:2 |
partially evaluated: pos > (int)text.length()| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 611 | return 0; never executed: return 0; | 0 |
| 612 | | - |
| 613 | QChar ch = text.unicode()[pos]; executed (the execution status of this line is deduced): QChar ch = text.unicode()[pos]; | - |
| 614 | const int script = QUnicodeTables::script(ch); executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 615 | int width; executed (the execution status of this line is deduced): int width; | - |
| 616 | | - |
| 617 | if (script != QUnicodeTables::Common) { partially evaluated: script != QUnicodeTables::Common| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 618 | // complex script shaping. Have to do some hard work | - |
| 619 | int from = qMax(0, pos - 8); never executed (the execution status of this line is deduced): int from = qMax(0, pos - 8); | - |
| 620 | int to = qMin(text.length(), pos + 8); never executed (the execution status of this line is deduced): int to = qMin(text.length(), pos + 8); | - |
| 621 | QString cstr = QString::fromRawData(text.unicode() + from, to - from); never executed (the execution status of this line is deduced): QString cstr = QString::fromRawData(text.unicode() + from, to - from); | - |
| 622 | QStackTextEngine layout(cstr, QFont(d.data())); never executed (the execution status of this line is deduced): QStackTextEngine layout(cstr, QFont(d.data())); | - |
| 623 | layout.ignoreBidi = true; never executed (the execution status of this line is deduced): layout.ignoreBidi = true; | - |
| 624 | layout.itemize(); never executed (the execution status of this line is deduced): layout.itemize(); | - |
| 625 | width = qRound(layout.width(pos-from, 1)); never executed (the execution status of this line is deduced): width = qRound(layout.width(pos-from, 1)); | - |
| 626 | } else if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing) { never executed: } partially evaluated: QChar::category(ch.unicode()) == QChar::Mark_NonSpacing| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 627 | width = 0; never executed (the execution status of this line is deduced): width = 0; | - |
| 628 | } else { | 0 |
| 629 | QFontEngine *engine; executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 630 | if (d->capital == QFont::SmallCaps && ch.isLower()) partially evaluated: d->capital == QFont::SmallCaps| no Evaluation Count:0 | yes Evaluation Count:2 |
never evaluated: ch.isLower() | 0-2 |
| 631 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 632 | else | - |
| 633 | engine = d->engineForScript(script); executed: engine = d->engineForScript(script);Execution Count:2 | 2 |
| 634 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 635 | | - |
| 636 | d->alterCharForCapitalization(ch); executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 637 | | - |
| 638 | QGlyphLayoutArray<8> glyphs; executed (the execution status of this line is deduced): QGlyphLayoutArray<8> glyphs; | - |
| 639 | int nglyphs = 7; executed (the execution status of this line is deduced): int nglyphs = 7; | - |
| 640 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); | - |
| 641 | width = qRound(glyphs.advances_x[0]); executed (the execution status of this line is deduced): width = qRound(glyphs.advances_x[0]); | - |
| 642 | } executed: }Execution Count:2 | 2 |
| 643 | return width; executed: return width;Execution Count:2 | 2 |
| 644 | } | - |
| 645 | | - |
| 646 | /*! | - |
| 647 | Returns the bounding rectangle of the characters in the string | - |
| 648 | specified by \a text. The bounding rectangle always covers at least | - |
| 649 | the set of pixels the text would cover if drawn at (0, 0). | - |
| 650 | | - |
| 651 | Note that the bounding rectangle may extend to the left of (0, 0), | - |
| 652 | e.g. for italicized fonts, and that the width of the returned | - |
| 653 | rectangle might be different than what the width() method returns. | - |
| 654 | | - |
| 655 | If you want to know the advance width of the string (to layout | - |
| 656 | a set of strings next to each other), use width() instead. | - |
| 657 | | - |
| 658 | Newline characters are processed as normal characters, \e not as | - |
| 659 | linebreaks. | - |
| 660 | | - |
| 661 | The height of the bounding rectangle is at least as large as the | - |
| 662 | value returned by height(). | - |
| 663 | | - |
| 664 | \sa width(), height(), QPainter::boundingRect(), tightBoundingRect() | - |
| 665 | */ | - |
| 666 | QRect QFontMetrics::boundingRect(const QString &text) const | - |
| 667 | { | - |
| 668 | if (text.length() == 0) evaluated: text.length() == 0| yes Evaluation Count:8 | yes Evaluation Count:880 |
| 8-880 |
| 669 | return QRect(); executed: return QRect();Execution Count:8 | 8 |
| 670 | | - |
| 671 | QStackTextEngine layout(text, QFont(d.data())); executed (the execution status of this line is deduced): QStackTextEngine layout(text, QFont(d.data())); | - |
| 672 | layout.ignoreBidi = true; executed (the execution status of this line is deduced): layout.ignoreBidi = true; | - |
| 673 | layout.itemize(); executed (the execution status of this line is deduced): layout.itemize(); | - |
| 674 | glyph_metrics_t gm = layout.boundingBox(0, text.length()); executed (the execution status of this line is deduced): glyph_metrics_t gm = layout.boundingBox(0, text.length()); | - |
| 675 | return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height)); executed: return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));Execution Count:880 | 880 |
| 676 | } | - |
| 677 | | - |
| 678 | /*! | - |
| 679 | Returns the rectangle that is covered by ink if character \a ch | - |
| 680 | were to be drawn at the origin of the coordinate system. | - |
| 681 | | - |
| 682 | Note that the bounding rectangle may extend to the left of (0, 0) | - |
| 683 | (e.g., for italicized fonts), and that the text output may cover \e | - |
| 684 | all pixels in the bounding rectangle. For a space character the rectangle | - |
| 685 | will usually be empty. | - |
| 686 | | - |
| 687 | Note that the rectangle usually extends both above and below the | - |
| 688 | base line. | - |
| 689 | | - |
| 690 | \warning The width of the returned rectangle is not the advance width | - |
| 691 | of the character. Use boundingRect(const QString &) or width() instead. | - |
| 692 | | - |
| 693 | \sa width() | - |
| 694 | */ | - |
| 695 | QRect QFontMetrics::boundingRect(QChar ch) const | - |
| 696 | { | - |
| 697 | const int script = QUnicodeTables::script(ch); executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 698 | QFontEngine *engine; executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 699 | if (d->capital == QFont::SmallCaps && ch.isLower()) partially evaluated: d->capital == QFont::SmallCaps| no Evaluation Count:0 | yes Evaluation Count:26 |
never evaluated: ch.isLower() | 0-26 |
| 700 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 701 | else | - |
| 702 | engine = d->engineForScript(script); executed: engine = d->engineForScript(script);Execution Count:26 | 26 |
| 703 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 704 | | - |
| 705 | d->alterCharForCapitalization(ch); executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 706 | | - |
| 707 | QGlyphLayoutArray<10> glyphs; executed (the execution status of this line is deduced): QGlyphLayoutArray<10> glyphs; | - |
| 708 | int nglyphs = 9; executed (the execution status of this line is deduced): int nglyphs = 9; | - |
| 709 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); | - |
| 710 | glyph_metrics_t gm = engine->boundingBox(glyphs.glyphs[0]); executed (the execution status of this line is deduced): glyph_metrics_t gm = engine->boundingBox(glyphs.glyphs[0]); | - |
| 711 | return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height)); executed: return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));Execution Count:26 | 26 |
| 712 | } | - |
| 713 | | - |
| 714 | /*! | - |
| 715 | \overload | - |
| 716 | | - |
| 717 | Returns the bounding rectangle of the characters in the string | - |
| 718 | specified by \a text, which is the set of pixels the text would | - |
| 719 | cover if drawn at (0, 0). The drawing, and hence the bounding | - |
| 720 | rectangle, is constrained to the rectangle \a rect. | - |
| 721 | | - |
| 722 | The \a flags argument is the bitwise OR of the following flags: | - |
| 723 | \list | - |
| 724 | \li Qt::AlignLeft aligns to the left border, except for | - |
| 725 | Arabic and Hebrew where it aligns to the right. | - |
| 726 | \li Qt::AlignRight aligns to the right border, except for | - |
| 727 | Arabic and Hebrew where it aligns to the left. | - |
| 728 | \li Qt::AlignJustify produces justified text. | - |
| 729 | \li Qt::AlignHCenter aligns horizontally centered. | - |
| 730 | \li Qt::AlignTop aligns to the top border. | - |
| 731 | \li Qt::AlignBottom aligns to the bottom border. | - |
| 732 | \li Qt::AlignVCenter aligns vertically centered | - |
| 733 | \li Qt::AlignCenter (== \c{Qt::AlignHCenter | Qt::AlignVCenter}) | - |
| 734 | \li Qt::TextSingleLine ignores newline characters in the text. | - |
| 735 | \li Qt::TextExpandTabs expands tabs (see below) | - |
| 736 | \li Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined. | - |
| 737 | \li Qt::TextWordWrap breaks the text to fit the rectangle. | - |
| 738 | \endlist | - |
| 739 | | - |
| 740 | Qt::Horizontal alignment defaults to Qt::AlignLeft and vertical | - |
| 741 | alignment defaults to Qt::AlignTop. | - |
| 742 | | - |
| 743 | If several of the horizontal or several of the vertical alignment | - |
| 744 | flags are set, the resulting alignment is undefined. | - |
| 745 | | - |
| 746 | If Qt::TextExpandTabs is set in \a flags, then: if \a tabArray is | - |
| 747 | non-null, it specifies a 0-terminated sequence of pixel-positions | - |
| 748 | for tabs; otherwise if \a tabStops is non-zero, it is used as the | - |
| 749 | tab spacing (in pixels). | - |
| 750 | | - |
| 751 | Note that the bounding rectangle may extend to the left of (0, 0), | - |
| 752 | e.g. for italicized fonts, and that the text output may cover \e | - |
| 753 | all pixels in the bounding rectangle. | - |
| 754 | | - |
| 755 | Newline characters are processed as linebreaks. | - |
| 756 | | - |
| 757 | Despite the different actual character heights, the heights of the | - |
| 758 | bounding rectangles of "Yes" and "yes" are the same. | - |
| 759 | | - |
| 760 | The bounding rectangle returned by this function is somewhat larger | - |
| 761 | than that calculated by the simpler boundingRect() function. This | - |
| 762 | function uses the \l{minLeftBearing()}{maximum left} and | - |
| 763 | \l{minRightBearing()}{right} font bearings as is | - |
| 764 | necessary for multi-line text to align correctly. Also, | - |
| 765 | fontHeight() and lineSpacing() are used to calculate the height, | - |
| 766 | rather than individual character heights. | - |
| 767 | | - |
| 768 | \sa width(), QPainter::boundingRect(), Qt::Alignment | - |
| 769 | */ | - |
| 770 | QRect QFontMetrics::boundingRect(const QRect &rect, int flags, const QString &text, int tabStops, | - |
| 771 | int *tabArray) const | - |
| 772 | { | - |
| 773 | int tabArrayLen = 0; executed (the execution status of this line is deduced): int tabArrayLen = 0; | - |
| 774 | if (tabArray) partially evaluated: tabArray| no Evaluation Count:0 | yes Evaluation Count:31876 |
| 0-31876 |
| 775 | while (tabArray[tabArrayLen]) never evaluated: tabArray[tabArrayLen] | 0 |
| 776 | tabArrayLen++; never executed: tabArrayLen++; | 0 |
| 777 | | - |
| 778 | QRectF rb; executed (the execution status of this line is deduced): QRectF rb; | - |
| 779 | QRectF rr(rect); executed (the execution status of this line is deduced): QRectF rr(rect); | - |
| 780 | qt_format_text(QFont(d.data()), rr, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray, executed (the execution status of this line is deduced): qt_format_text(QFont(d.data()), rr, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray, | - |
| 781 | tabArrayLen, 0); executed (the execution status of this line is deduced): tabArrayLen, 0); | - |
| 782 | | - |
| 783 | return rb.toAlignedRect(); executed: return rb.toAlignedRect();Execution Count:31876 | 31876 |
| 784 | } | - |
| 785 | | - |
| 786 | /*! | - |
| 787 | Returns the size in pixels of \a text. | - |
| 788 | | - |
| 789 | The \a flags argument is the bitwise OR of the following flags: | - |
| 790 | \list | - |
| 791 | \li Qt::TextSingleLine ignores newline characters. | - |
| 792 | \li Qt::TextExpandTabs expands tabs (see below) | - |
| 793 | \li Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined. | - |
| 794 | \li Qt::TextWordBreak breaks the text to fit the rectangle. | - |
| 795 | \endlist | - |
| 796 | | - |
| 797 | If Qt::TextExpandTabs is set in \a flags, then: if \a tabArray is | - |
| 798 | non-null, it specifies a 0-terminated sequence of pixel-positions | - |
| 799 | for tabs; otherwise if \a tabStops is non-zero, it is used as the | - |
| 800 | tab spacing (in pixels). | - |
| 801 | | - |
| 802 | Newline characters are processed as linebreaks. | - |
| 803 | | - |
| 804 | Despite the different actual character heights, the heights of the | - |
| 805 | bounding rectangles of "Yes" and "yes" are the same. | - |
| 806 | | - |
| 807 | \sa boundingRect() | - |
| 808 | */ | - |
| 809 | QSize QFontMetrics::size(int flags, const QString &text, int tabStops, int *tabArray) const | - |
| 810 | { | - |
| 811 | return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size(); executed: return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();Execution Count:27081 | 27081 |
| 812 | } | - |
| 813 | | - |
| 814 | /*! | - |
| 815 | \since 4.3 | - |
| 816 | | - |
| 817 | Returns a tight bounding rectangle around the characters in the | - |
| 818 | string specified by \a text. The bounding rectangle always covers | - |
| 819 | at least the set of pixels the text would cover if drawn at (0, | - |
| 820 | 0). | - |
| 821 | | - |
| 822 | Note that the bounding rectangle may extend to the left of (0, 0), | - |
| 823 | e.g. for italicized fonts, and that the width of the returned | - |
| 824 | rectangle might be different than what the width() method returns. | - |
| 825 | | - |
| 826 | If you want to know the advance width of the string (to layout | - |
| 827 | a set of strings next to each other), use width() instead. | - |
| 828 | | - |
| 829 | Newline characters are processed as normal characters, \e not as | - |
| 830 | linebreaks. | - |
| 831 | | - |
| 832 | \warning Calling this method is very slow on Windows. | - |
| 833 | | - |
| 834 | \sa width(), height(), boundingRect() | - |
| 835 | */ | - |
| 836 | QRect QFontMetrics::tightBoundingRect(const QString &text) const | - |
| 837 | { | - |
| 838 | if (text.length() == 0) never evaluated: text.length() == 0 | 0 |
| 839 | return QRect(); never executed: return QRect(); | 0 |
| 840 | | - |
| 841 | QStackTextEngine layout(text, QFont(d.data())); never executed (the execution status of this line is deduced): QStackTextEngine layout(text, QFont(d.data())); | - |
| 842 | layout.ignoreBidi = true; never executed (the execution status of this line is deduced): layout.ignoreBidi = true; | - |
| 843 | layout.itemize(); never executed (the execution status of this line is deduced): layout.itemize(); | - |
| 844 | glyph_metrics_t gm = layout.tightBoundingBox(0, text.length()); never executed (the execution status of this line is deduced): glyph_metrics_t gm = layout.tightBoundingBox(0, text.length()); | - |
| 845 | return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height)); never executed: return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height)); | 0 |
| 846 | } | - |
| 847 | | - |
| 848 | | - |
| 849 | /*! | - |
| 850 | \since 4.2 | - |
| 851 | | - |
| 852 | If the string \a text is wider than \a width, returns an elided | - |
| 853 | version of the string (i.e., a string with "..." in it). | - |
| 854 | Otherwise, returns the original string. | - |
| 855 | | - |
| 856 | The \a mode parameter specifies whether the text is elided on the | - |
| 857 | left (e.g., "...tech"), in the middle (e.g., "Tr...ch"), or on | - |
| 858 | the right (e.g., "Trol..."). | - |
| 859 | | - |
| 860 | The \a width is specified in pixels, not characters. | - |
| 861 | | - |
| 862 | The \a flags argument is optional and currently only supports | - |
| 863 | Qt::TextShowMnemonic as value. | - |
| 864 | | - |
| 865 | The elide mark will follow the \l{Qt::LayoutDirection}{layout | - |
| 866 | direction}; it will be on the right side of the text for | - |
| 867 | right-to-left layouts, and on the left side for right-to-left | - |
| 868 | layouts. Note that this behavior is independent of the text | - |
| 869 | language. | - |
| 870 | */ | - |
| 871 | QString QFontMetrics::elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags) const | - |
| 872 | { | - |
| 873 | QString _text = text; executed (the execution status of this line is deduced): QString _text = text; | - |
| 874 | if (!(flags & Qt::TextLongestVariant)) { partially evaluated: !(flags & Qt::TextLongestVariant)| yes Evaluation Count:3425 | no Evaluation Count:0 |
| 0-3425 |
| 875 | int posA = 0; executed (the execution status of this line is deduced): int posA = 0; | - |
| 876 | int posB = _text.indexOf(QLatin1Char('\x9c')); executed (the execution status of this line is deduced): int posB = _text.indexOf(QLatin1Char('\x9c')); | - |
| 877 | while (posB >= 0) { evaluated: posB >= 0| yes Evaluation Count:10 | yes Evaluation Count:3421 |
| 10-3421 |
| 878 | QString portion = _text.mid(posA, posB - posA); executed (the execution status of this line is deduced): QString portion = _text.mid(posA, posB - posA); | - |
| 879 | if (size(flags, portion).width() <= width) evaluated: size(flags, portion).width() <= width| yes Evaluation Count:4 | yes Evaluation Count:6 |
| 4-6 |
| 880 | return portion; executed: return portion;Execution Count:4 | 4 |
| 881 | posA = posB + 1; executed (the execution status of this line is deduced): posA = posB + 1; | - |
| 882 | posB = _text.indexOf(QLatin1Char('\x9c'), posA); executed (the execution status of this line is deduced): posB = _text.indexOf(QLatin1Char('\x9c'), posA); | - |
| 883 | } executed: }Execution Count:6 | 6 |
| 884 | _text = _text.mid(posA); executed (the execution status of this line is deduced): _text = _text.mid(posA); | - |
| 885 | } executed: }Execution Count:3421 | 3421 |
| 886 | QStackTextEngine engine(_text, QFont(d.data())); executed (the execution status of this line is deduced): QStackTextEngine engine(_text, QFont(d.data())); | - |
| 887 | return engine.elidedText(mode, width, flags); executed: return engine.elidedText(mode, width, flags);Execution Count:3421 | 3421 |
| 888 | } | - |
| 889 | | - |
| 890 | /*! | - |
| 891 | Returns the distance from the base line to where an underscore | - |
| 892 | should be drawn. | - |
| 893 | | - |
| 894 | \sa overlinePos(), strikeOutPos(), lineWidth() | - |
| 895 | */ | - |
| 896 | int QFontMetrics::underlinePos() const | - |
| 897 | { | - |
| 898 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 899 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 900 | return qRound(engine->underlinePosition()); never executed: return qRound(engine->underlinePosition()); | 0 |
| 901 | } | - |
| 902 | | - |
| 903 | /*! | - |
| 904 | Returns the distance from the base line to where an overline | - |
| 905 | should be drawn. | - |
| 906 | | - |
| 907 | \sa underlinePos(), strikeOutPos(), lineWidth() | - |
| 908 | */ | - |
| 909 | int QFontMetrics::overlinePos() const | - |
| 910 | { | - |
| 911 | return ascent() + 1; never executed: return ascent() + 1; | 0 |
| 912 | } | - |
| 913 | | - |
| 914 | /*! | - |
| 915 | Returns the distance from the base line to where the strikeout | - |
| 916 | line should be drawn. | - |
| 917 | | - |
| 918 | \sa underlinePos(), overlinePos(), lineWidth() | - |
| 919 | */ | - |
| 920 | int QFontMetrics::strikeOutPos() const | - |
| 921 | { | - |
| 922 | int pos = ascent() / 3; never executed (the execution status of this line is deduced): int pos = ascent() / 3; | - |
| 923 | return pos > 0 ? pos : 1; never executed: return pos > 0 ? pos : 1; | 0 |
| 924 | } | - |
| 925 | | - |
| 926 | /*! | - |
| 927 | Returns the width of the underline and strikeout lines, adjusted | - |
| 928 | for the point size of the font. | - |
| 929 | | - |
| 930 | \sa underlinePos(), overlinePos(), strikeOutPos() | - |
| 931 | */ | - |
| 932 | int QFontMetrics::lineWidth() const | - |
| 933 | { | - |
| 934 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 935 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 936 | return qRound(engine->lineThickness()); executed: return qRound(engine->lineThickness());Execution Count:3 | 3 |
| 937 | } | - |
| 938 | | - |
| 939 | | - |
| 940 | | - |
| 941 | | - |
| 942 | /***************************************************************************** | - |
| 943 | QFontMetricsF member functions | - |
| 944 | *****************************************************************************/ | - |
| 945 | | - |
| 946 | /*! | - |
| 947 | \class QFontMetricsF | - |
| 948 | \reentrant | - |
| 949 | \inmodule QtGui | - |
| 950 | | - |
| 951 | \brief The QFontMetricsF class provides font metrics information. | - |
| 952 | | - |
| 953 | \ingroup painting | - |
| 954 | \ingroup shared | - |
| 955 | | - |
| 956 | QFontMetricsF functions calculate the size of characters and | - |
| 957 | strings for a given font. You can construct a QFontMetricsF object | - |
| 958 | with an existing QFont to obtain metrics for that font. If the | - |
| 959 | font is changed later, the font metrics object is \e not updated. | - |
| 960 | | - |
| 961 | Once created, the object provides functions to access the | - |
| 962 | individual metrics of the font, its characters, and for strings | - |
| 963 | rendered in the font. | - |
| 964 | | - |
| 965 | There are several functions that operate on the font: ascent(), | - |
| 966 | descent(), height(), leading() and lineSpacing() return the basic | - |
| 967 | size properties of the font. The underlinePos(), overlinePos(), | - |
| 968 | strikeOutPos() and lineWidth() functions, return the properties of | - |
| 969 | the line that underlines, overlines or strikes out the | - |
| 970 | characters. These functions are all fast. | - |
| 971 | | - |
| 972 | There are also some functions that operate on the set of glyphs in | - |
| 973 | the font: minLeftBearing(), minRightBearing() and maxWidth(). | - |
| 974 | These are by necessity slow, and we recommend avoiding them if | - |
| 975 | possible. | - |
| 976 | | - |
| 977 | For each character, you can get its width(), leftBearing() and | - |
| 978 | rightBearing() and find out whether it is in the font using | - |
| 979 | inFont(). You can also treat the character as a string, and use | - |
| 980 | the string functions on it. | - |
| 981 | | - |
| 982 | The string functions include width(), to return the width of a | - |
| 983 | string in pixels (or points, for a printer), boundingRect(), to | - |
| 984 | return a rectangle large enough to contain the rendered string, | - |
| 985 | and size(), to return the size of that rectangle. | - |
| 986 | | - |
| 987 | Example: | - |
| 988 | \snippet code/src_gui_text_qfontmetrics.cpp 1 | - |
| 989 | | - |
| 990 | \sa QFont, QFontInfo, QFontDatabase | - |
| 991 | */ | - |
| 992 | | - |
| 993 | /*! | - |
| 994 | \since 4.2 | - |
| 995 | | - |
| 996 | Constructs a font metrics object with floating point precision | - |
| 997 | from the given \a fontMetrics object. | - |
| 998 | */ | - |
| 999 | QFontMetricsF::QFontMetricsF(const QFontMetrics &fontMetrics) | - |
| 1000 | : d(fontMetrics.d.data()) | - |
| 1001 | { | - |
| 1002 | } executed: }Execution Count:995 | 995 |
| 1003 | | - |
| 1004 | /*! | - |
| 1005 | \since 4.2 | - |
| 1006 | | - |
| 1007 | Assigns \a other to this object. | - |
| 1008 | */ | - |
| 1009 | QFontMetricsF &QFontMetricsF::operator=(const QFontMetrics &other) | - |
| 1010 | { | - |
| 1011 | d = other.d.data(); never executed (the execution status of this line is deduced): d = other.d.data(); | - |
| 1012 | return *this; never executed: return *this; | 0 |
| 1013 | } | - |
| 1014 | | - |
| 1015 | /*! | - |
| 1016 | \fn void QFontMetricsF::swap(QFontMetricsF &other) | - |
| 1017 | \since 5.0 | - |
| 1018 | | - |
| 1019 | Swaps this font metrics instance with \a other. This function is | - |
| 1020 | very fast and never fails. | - |
| 1021 | */ | - |
| 1022 | | - |
| 1023 | | - |
| 1024 | | - |
| 1025 | /*! | - |
| 1026 | Constructs a font metrics object for \a font. | - |
| 1027 | | - |
| 1028 | The font metrics will be compatible with the paintdevice used to | - |
| 1029 | create \a font. | - |
| 1030 | | - |
| 1031 | The font metrics object holds the information for the font that is | - |
| 1032 | passed in the constructor at the time it is created, and is not | - |
| 1033 | updated if the font's attributes are changed later. | - |
| 1034 | | - |
| 1035 | Use QFontMetricsF(const QFont &, QPaintDevice *) to get the font | - |
| 1036 | metrics that are compatible with a certain paint device. | - |
| 1037 | */ | - |
| 1038 | QFontMetricsF::QFontMetricsF(const QFont &font) | - |
| 1039 | : d(font.d.data()) | - |
| 1040 | { | - |
| 1041 | } executed: }Execution Count:35634 | 35634 |
| 1042 | | - |
| 1043 | /*! | - |
| 1044 | Constructs a font metrics object for \a font and \a paintdevice. | - |
| 1045 | | - |
| 1046 | The font metrics will be compatible with the paintdevice passed. | - |
| 1047 | If the \a paintdevice is 0, the metrics will be screen-compatible, | - |
| 1048 | ie. the metrics you get if you use the font for drawing text on a | - |
| 1049 | \l{QWidget}{widgets} or \l{QPixmap}{pixmaps}, | - |
| 1050 | not on a QPicture or QPrinter. | - |
| 1051 | | - |
| 1052 | The font metrics object holds the information for the font that is | - |
| 1053 | passed in the constructor at the time it is created, and is not | - |
| 1054 | updated if the font's attributes are changed later. | - |
| 1055 | */ | - |
| 1056 | QFontMetricsF::QFontMetricsF(const QFont &font, QPaintDevice *paintdevice) | - |
| 1057 | { | - |
| 1058 | int dpi = paintdevice ? paintdevice->logicalDpiY() : qt_defaultDpi(); partially evaluated: paintdevice| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 1059 | const int screen = 0; executed (the execution status of this line is deduced): const int screen = 0; | - |
| 1060 | if (font.d->dpi != dpi || font.d->screen != screen ) { partially evaluated: font.d->dpi != dpi| yes Evaluation Count:1 | no Evaluation Count:0 |
never evaluated: font.d->screen != screen | 0-1 |
| 1061 | d = new QFontPrivate(*font.d); executed (the execution status of this line is deduced): d = new QFontPrivate(*font.d); | - |
| 1062 | d->dpi = dpi; executed (the execution status of this line is deduced): d->dpi = dpi; | - |
| 1063 | d->screen = screen; executed (the execution status of this line is deduced): d->screen = screen; | - |
| 1064 | } else { executed: }Execution Count:1 | 1 |
| 1065 | d = font.d.data(); never executed (the execution status of this line is deduced): d = font.d.data(); | - |
| 1066 | } | 0 |
| 1067 | | - |
| 1068 | } | - |
| 1069 | | - |
| 1070 | /*! | - |
| 1071 | Constructs a copy of \a fm. | - |
| 1072 | */ | - |
| 1073 | QFontMetricsF::QFontMetricsF(const QFontMetricsF &fm) | - |
| 1074 | : d(fm.d.data()) | - |
| 1075 | { | - |
| 1076 | } | 0 |
| 1077 | | - |
| 1078 | /*! | - |
| 1079 | Destroys the font metrics object and frees all allocated | - |
| 1080 | resources. | - |
| 1081 | */ | - |
| 1082 | QFontMetricsF::~QFontMetricsF() | - |
| 1083 | { | - |
| 1084 | } | - |
| 1085 | | - |
| 1086 | /*! | - |
| 1087 | Assigns the font metrics \a fm to this font metrics object. | - |
| 1088 | */ | - |
| 1089 | QFontMetricsF &QFontMetricsF::operator=(const QFontMetricsF &fm) | - |
| 1090 | { | - |
| 1091 | d = fm.d.data(); never executed (the execution status of this line is deduced): d = fm.d.data(); | - |
| 1092 | return *this; never executed: return *this; | 0 |
| 1093 | } | - |
| 1094 | | - |
| 1095 | /*! | - |
| 1096 | Returns true if the font metrics are equal to the \a other font | - |
| 1097 | metrics; otherwise returns false. | - |
| 1098 | | - |
| 1099 | Two font metrics are considered equal if they were constructed from the | - |
| 1100 | same QFont and the paint devices they were constructed for are | - |
| 1101 | considered to be compatible. | - |
| 1102 | */ | - |
| 1103 | bool QFontMetricsF::operator ==(const QFontMetricsF &other) const | - |
| 1104 | { | - |
| 1105 | return d == other.d; never executed: return d == other.d; | 0 |
| 1106 | } | - |
| 1107 | | - |
| 1108 | /*! | - |
| 1109 | \fn bool QFontMetricsF::operator !=(const QFontMetricsF &other) const | - |
| 1110 | \overload | - |
| 1111 | | - |
| 1112 | Returns true if the font metrics are not equal to the \a other font | - |
| 1113 | metrics; otherwise returns false. | - |
| 1114 | | - |
| 1115 | \sa operator==() | - |
| 1116 | */ | - |
| 1117 | | - |
| 1118 | /*! | - |
| 1119 | Returns the ascent of the font. | - |
| 1120 | | - |
| 1121 | The ascent of a font is the distance from the baseline to the | - |
| 1122 | highest position characters extend to. In practice, some font | - |
| 1123 | designers break this rule, e.g. when they put more than one accent | - |
| 1124 | on top of a character, or to accommodate an unusual character in | - |
| 1125 | an exotic language, so it is possible (though rare) that this | - |
| 1126 | value will be too small. | - |
| 1127 | | - |
| 1128 | \sa descent() | - |
| 1129 | */ | - |
| 1130 | qreal QFontMetricsF::ascent() const | - |
| 1131 | { | - |
| 1132 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1133 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1134 | return engine->ascent().toReal(); never executed: return engine->ascent().toReal(); | 0 |
| 1135 | } | - |
| 1136 | | - |
| 1137 | | - |
| 1138 | /*! | - |
| 1139 | Returns the descent of the font. | - |
| 1140 | | - |
| 1141 | The descent is the distance from the base line to the lowest point | - |
| 1142 | characters extend to. (Note that this is different from X, which | - |
| 1143 | adds 1 pixel.) In practice, some font designers break this rule, | - |
| 1144 | e.g. to accommodate an unusual character in an exotic language, so | - |
| 1145 | it is possible (though rare) that this value will be too small. | - |
| 1146 | | - |
| 1147 | \sa ascent() | - |
| 1148 | */ | - |
| 1149 | qreal QFontMetricsF::descent() const | - |
| 1150 | { | - |
| 1151 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1152 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1153 | return engine->descent().toReal(); never executed: return engine->descent().toReal(); | 0 |
| 1154 | } | - |
| 1155 | | - |
| 1156 | /*! | - |
| 1157 | Returns the height of the font. | - |
| 1158 | | - |
| 1159 | This is always equal to ascent()+descent()+1 (the 1 is for the | - |
| 1160 | base line). | - |
| 1161 | | - |
| 1162 | \sa leading(), lineSpacing() | - |
| 1163 | */ | - |
| 1164 | qreal QFontMetricsF::height() const | - |
| 1165 | { | - |
| 1166 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1167 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 1168 | | - |
| 1169 | return (engine->ascent() + engine->descent()).toReal(); executed: return (engine->ascent() + engine->descent()).toReal();Execution Count:1237 | 1237 |
| 1170 | } | - |
| 1171 | | - |
| 1172 | /*! | - |
| 1173 | Returns the leading of the font. | - |
| 1174 | | - |
| 1175 | This is the natural inter-line spacing. | - |
| 1176 | | - |
| 1177 | \sa height(), lineSpacing() | - |
| 1178 | */ | - |
| 1179 | qreal QFontMetricsF::leading() const | - |
| 1180 | { | - |
| 1181 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1182 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 1183 | return engine->leading().toReal(); executed: return engine->leading().toReal();Execution Count:35389 | 35389 |
| 1184 | } | - |
| 1185 | | - |
| 1186 | /*! | - |
| 1187 | Returns the distance from one base line to the next. | - |
| 1188 | | - |
| 1189 | This value is always equal to leading()+height(). | - |
| 1190 | | - |
| 1191 | \sa height(), leading() | - |
| 1192 | */ | - |
| 1193 | qreal QFontMetricsF::lineSpacing() const | - |
| 1194 | { | - |
| 1195 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1196 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1197 | return (engine->leading() + engine->ascent() + engine->descent()).toReal(); never executed: return (engine->leading() + engine->ascent() + engine->descent()).toReal(); | 0 |
| 1198 | } | - |
| 1199 | | - |
| 1200 | /*! | - |
| 1201 | Returns the minimum left bearing of the font. | - |
| 1202 | | - |
| 1203 | This is the smallest leftBearing(char) of all characters in the | - |
| 1204 | font. | - |
| 1205 | | - |
| 1206 | Note that this function can be very slow if the font is large. | - |
| 1207 | | - |
| 1208 | \sa minRightBearing(), leftBearing() | - |
| 1209 | */ | - |
| 1210 | qreal QFontMetricsF::minLeftBearing() const | - |
| 1211 | { | - |
| 1212 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1213 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1214 | return engine->minLeftBearing(); never executed: return engine->minLeftBearing(); | 0 |
| 1215 | } | - |
| 1216 | | - |
| 1217 | /*! | - |
| 1218 | Returns the minimum right bearing of the font. | - |
| 1219 | | - |
| 1220 | This is the smallest rightBearing(char) of all characters in the | - |
| 1221 | font. | - |
| 1222 | | - |
| 1223 | Note that this function can be very slow if the font is large. | - |
| 1224 | | - |
| 1225 | \sa minLeftBearing(), rightBearing() | - |
| 1226 | */ | - |
| 1227 | qreal QFontMetricsF::minRightBearing() const | - |
| 1228 | { | - |
| 1229 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1230 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1231 | return engine->minRightBearing(); never executed: return engine->minRightBearing(); | 0 |
| 1232 | } | - |
| 1233 | | - |
| 1234 | /*! | - |
| 1235 | Returns the width of the widest character in the font. | - |
| 1236 | */ | - |
| 1237 | qreal QFontMetricsF::maxWidth() const | - |
| 1238 | { | - |
| 1239 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1240 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1241 | return engine->maxCharWidth(); never executed: return engine->maxCharWidth(); | 0 |
| 1242 | } | - |
| 1243 | | - |
| 1244 | /*! | - |
| 1245 | Returns the 'x' height of the font. This is often but not always | - |
| 1246 | the same as the height of the character 'x'. | - |
| 1247 | */ | - |
| 1248 | qreal QFontMetricsF::xHeight() const | - |
| 1249 | { | - |
| 1250 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1251 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1252 | if (d->capital == QFont::SmallCaps) never evaluated: d->capital == QFont::SmallCaps | 0 |
| 1253 | return d->smallCapsFontPrivate()->engineForScript(QUnicodeTables::Common)->ascent().toReal(); never executed: return d->smallCapsFontPrivate()->engineForScript(QUnicodeTables::Common)->ascent().toReal(); | 0 |
| 1254 | return engine->xHeight().toReal(); never executed: return engine->xHeight().toReal(); | 0 |
| 1255 | } | - |
| 1256 | | - |
| 1257 | /*! | - |
| 1258 | \since 4.2 | - |
| 1259 | | - |
| 1260 | Returns the average width of glyphs in the font. | - |
| 1261 | */ | - |
| 1262 | qreal QFontMetricsF::averageCharWidth() const | - |
| 1263 | { | - |
| 1264 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1265 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 1266 | return engine->averageCharWidth().toReal(); executed: return engine->averageCharWidth().toReal();Execution Count:1 | 1 |
| 1267 | } | - |
| 1268 | | - |
| 1269 | /*! | - |
| 1270 | Returns true if character \a ch is a valid character in the font; | - |
| 1271 | otherwise returns false. | - |
| 1272 | */ | - |
| 1273 | bool QFontMetricsF::inFont(QChar ch) const | - |
| 1274 | { | - |
| 1275 | const int script = QUnicodeTables::script(ch); never executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 1276 | QFontEngine *engine = d->engineForScript(script); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(script); | - |
| 1277 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1278 | if (engine->type() == QFontEngine::Box) never evaluated: engine->type() == QFontEngine::Box | 0 |
| 1279 | return false; never executed: return false; | 0 |
| 1280 | return engine->canRender(&ch, 1); never executed: return engine->canRender(&ch, 1); | 0 |
| 1281 | } | - |
| 1282 | | - |
| 1283 | /*! | - |
| 1284 | \fn bool QFontMetricsF::inFontUcs4(uint ch) const | - |
| 1285 | | - |
| 1286 | Returns true if the character given by \a ch, encoded in UCS-4/UTF-32, | - |
| 1287 | is a valid character in the font; otherwise returns false. | - |
| 1288 | */ | - |
| 1289 | bool QFontMetricsF::inFontUcs4(uint ucs4) const | - |
| 1290 | { | - |
| 1291 | const int script = QUnicodeTables::script(ucs4); executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ucs4); | - |
| 1292 | QFontEngine *engine = d->engineForScript(script); executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(script); | - |
| 1293 | Q_ASSERT(engine != 0); executed (the execution status of this line is deduced): qt_noop(); | - |
| 1294 | if (engine->type() == QFontEngine::Box) partially evaluated: engine->type() == QFontEngine::Box| no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
| 1295 | return false; never executed: return false; | 0 |
| 1296 | return engine->canRender(ucs4); executed: return engine->canRender(ucs4);Execution Count:1 | 1 |
| 1297 | } | - |
| 1298 | | - |
| 1299 | /*! | - |
| 1300 | Returns the left bearing of character \a ch in the font. | - |
| 1301 | | - |
| 1302 | The left bearing is the right-ward distance of the left-most pixel | - |
| 1303 | of the character from the logical origin of the character. This | - |
| 1304 | value is negative if the pixels of the character extend to the | - |
| 1305 | left of the logical origin. | - |
| 1306 | | - |
| 1307 | See width(QChar) for a graphical description of this metric. | - |
| 1308 | | - |
| 1309 | \sa rightBearing(), minLeftBearing(), width() | - |
| 1310 | */ | - |
| 1311 | qreal QFontMetricsF::leftBearing(QChar ch) const | - |
| 1312 | { | - |
| 1313 | const int script = QUnicodeTables::script(ch); never executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 1314 | QFontEngine *engine; never executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 1315 | if (d->capital == QFont::SmallCaps && ch.isLower()) never evaluated: d->capital == QFont::SmallCaps never evaluated: ch.isLower() | 0 |
| 1316 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 1317 | else | - |
| 1318 | engine = d->engineForScript(script); never executed: engine = d->engineForScript(script); | 0 |
| 1319 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1320 | if (engine->type() == QFontEngine::Box) never evaluated: engine->type() == QFontEngine::Box | 0 |
| 1321 | return 0; never executed: return 0; | 0 |
| 1322 | | - |
| 1323 | d->alterCharForCapitalization(ch); never executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 1324 | | - |
| 1325 | QGlyphLayoutArray<10> glyphs; never executed (the execution status of this line is deduced): QGlyphLayoutArray<10> glyphs; | - |
| 1326 | int nglyphs = 9; never executed (the execution status of this line is deduced): int nglyphs = 9; | - |
| 1327 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); never executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); | - |
| 1328 | // ### can nglyphs != 1 happen at all? Not currently I think | - |
| 1329 | qreal lb; never executed (the execution status of this line is deduced): qreal lb; | - |
| 1330 | engine->getGlyphBearings(glyphs.glyphs[0], &lb); never executed (the execution status of this line is deduced): engine->getGlyphBearings(glyphs.glyphs[0], &lb); | - |
| 1331 | return lb; never executed: return lb; | 0 |
| 1332 | } | - |
| 1333 | | - |
| 1334 | /*! | - |
| 1335 | Returns the right bearing of character \a ch in the font. | - |
| 1336 | | - |
| 1337 | The right bearing is the left-ward distance of the right-most | - |
| 1338 | pixel of the character from the logical origin of a subsequent | - |
| 1339 | character. This value is negative if the pixels of the character | - |
| 1340 | extend to the right of the width() of the character. | - |
| 1341 | | - |
| 1342 | See width() for a graphical description of this metric. | - |
| 1343 | | - |
| 1344 | \sa leftBearing(), minRightBearing(), width() | - |
| 1345 | */ | - |
| 1346 | qreal QFontMetricsF::rightBearing(QChar ch) const | - |
| 1347 | { | - |
| 1348 | const int script = QUnicodeTables::script(ch); never executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 1349 | QFontEngine *engine; never executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 1350 | if (d->capital == QFont::SmallCaps && ch.isLower()) never evaluated: d->capital == QFont::SmallCaps never evaluated: ch.isLower() | 0 |
| 1351 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 1352 | else | - |
| 1353 | engine = d->engineForScript(script); never executed: engine = d->engineForScript(script); | 0 |
| 1354 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1355 | if (engine->type() == QFontEngine::Box) never evaluated: engine->type() == QFontEngine::Box | 0 |
| 1356 | return 0; never executed: return 0; | 0 |
| 1357 | | - |
| 1358 | d->alterCharForCapitalization(ch); never executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 1359 | | - |
| 1360 | QGlyphLayoutArray<10> glyphs; never executed (the execution status of this line is deduced): QGlyphLayoutArray<10> glyphs; | - |
| 1361 | int nglyphs = 9; never executed (the execution status of this line is deduced): int nglyphs = 9; | - |
| 1362 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); never executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); | - |
| 1363 | // ### can nglyphs != 1 happen at all? Not currently I think | - |
| 1364 | qreal rb; never executed (the execution status of this line is deduced): qreal rb; | - |
| 1365 | engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb); never executed (the execution status of this line is deduced): engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb); | - |
| 1366 | return rb; never executed: return rb; | 0 |
| 1367 | | - |
| 1368 | } | - |
| 1369 | | - |
| 1370 | /*! | - |
| 1371 | Returns the width in pixels of the characters in the given \a text. | - |
| 1372 | | - |
| 1373 | Note that this value is \e not equal to the width returned by | - |
| 1374 | boundingRect().width() because boundingRect() returns a rectangle | - |
| 1375 | describing the pixels this string will cover whereas width() | - |
| 1376 | returns the distance to where the next string should be drawn. | - |
| 1377 | | - |
| 1378 | \sa boundingRect() | - |
| 1379 | */ | - |
| 1380 | qreal QFontMetricsF::width(const QString &text) const | - |
| 1381 | { | - |
| 1382 | int pos = text.indexOf(QLatin1Char('\x9c')); executed (the execution status of this line is deduced): int pos = text.indexOf(QLatin1Char('\x9c')); | - |
| 1383 | int len = (pos != -1) ? pos : text.length(); partially evaluated: (pos != -1)| no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
| 1384 | | - |
| 1385 | QStackTextEngine layout(text, QFont(d.data())); executed (the execution status of this line is deduced): QStackTextEngine layout(text, QFont(d.data())); | - |
| 1386 | layout.ignoreBidi = true; executed (the execution status of this line is deduced): layout.ignoreBidi = true; | - |
| 1387 | layout.itemize(); executed (the execution status of this line is deduced): layout.itemize(); | - |
| 1388 | return layout.width(0, len).toReal(); executed: return layout.width(0, len).toReal();Execution Count:1 | 1 |
| 1389 | } | - |
| 1390 | | - |
| 1391 | /*! | - |
| 1392 | \overload | - |
| 1393 | | - |
| 1394 | \image bearings.png Bearings | - |
| 1395 | | - |
| 1396 | Returns the logical width of character \a ch in pixels. This is a | - |
| 1397 | distance appropriate for drawing a subsequent character after \a | - |
| 1398 | ch. | - |
| 1399 | | - |
| 1400 | Some of the metrics are described in the image to the right. The | - |
| 1401 | central dark rectangles cover the logical width() of each | - |
| 1402 | character. The outer pale rectangles cover the leftBearing() and | - |
| 1403 | rightBearing() of each character. Notice that the bearings of "f" | - |
| 1404 | in this particular font are both negative, while the bearings of | - |
| 1405 | "o" are both positive. | - |
| 1406 | | - |
| 1407 | \warning This function will produce incorrect results for Arabic | - |
| 1408 | characters or non-spacing marks in the middle of a string, as the | - |
| 1409 | glyph shaping and positioning of marks that happens when | - |
| 1410 | processing strings cannot be taken into account. When implementing | - |
| 1411 | an interactive text control, use QTextLayout instead. | - |
| 1412 | | - |
| 1413 | \sa boundingRect() | - |
| 1414 | */ | - |
| 1415 | qreal QFontMetricsF::width(QChar ch) const | - |
| 1416 | { | - |
| 1417 | if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing) never evaluated: QChar::category(ch.unicode()) == QChar::Mark_NonSpacing | 0 |
| 1418 | return 0.; never executed: return 0.; | 0 |
| 1419 | | - |
| 1420 | const int script = QUnicodeTables::script(ch); never executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 1421 | QFontEngine *engine; never executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 1422 | if (d->capital == QFont::SmallCaps && ch.isLower()) never evaluated: d->capital == QFont::SmallCaps never evaluated: ch.isLower() | 0 |
| 1423 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 1424 | else | - |
| 1425 | engine = d->engineForScript(script); never executed: engine = d->engineForScript(script); | 0 |
| 1426 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1427 | | - |
| 1428 | d->alterCharForCapitalization(ch); never executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 1429 | | - |
| 1430 | QGlyphLayoutArray<8> glyphs; never executed (the execution status of this line is deduced): QGlyphLayoutArray<8> glyphs; | - |
| 1431 | int nglyphs = 7; never executed (the execution status of this line is deduced): int nglyphs = 7; | - |
| 1432 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); never executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0); | - |
| 1433 | return glyphs.advances_x[0].toReal(); never executed: return glyphs.advances_x[0].toReal(); | 0 |
| 1434 | } | - |
| 1435 | | - |
| 1436 | /*! | - |
| 1437 | Returns the bounding rectangle of the characters in the string | - |
| 1438 | specified by \a text. The bounding rectangle always covers at least | - |
| 1439 | the set of pixels the text would cover if drawn at (0, 0). | - |
| 1440 | | - |
| 1441 | Note that the bounding rectangle may extend to the left of (0, 0), | - |
| 1442 | e.g. for italicized fonts, and that the width of the returned | - |
| 1443 | rectangle might be different than what the width() method returns. | - |
| 1444 | | - |
| 1445 | If you want to know the advance width of the string (to layout | - |
| 1446 | a set of strings next to each other), use width() instead. | - |
| 1447 | | - |
| 1448 | Newline characters are processed as normal characters, \e not as | - |
| 1449 | linebreaks. | - |
| 1450 | | - |
| 1451 | The height of the bounding rectangle is at least as large as the | - |
| 1452 | value returned height(). | - |
| 1453 | | - |
| 1454 | \sa width(), height(), QPainter::boundingRect() | - |
| 1455 | */ | - |
| 1456 | QRectF QFontMetricsF::boundingRect(const QString &text) const | - |
| 1457 | { | - |
| 1458 | int len = text.length(); never executed (the execution status of this line is deduced): int len = text.length(); | - |
| 1459 | if (len == 0) never evaluated: len == 0 | 0 |
| 1460 | return QRectF(); never executed: return QRectF(); | 0 |
| 1461 | | - |
| 1462 | QStackTextEngine layout(text, QFont(d.data())); never executed (the execution status of this line is deduced): QStackTextEngine layout(text, QFont(d.data())); | - |
| 1463 | layout.ignoreBidi = true; never executed (the execution status of this line is deduced): layout.ignoreBidi = true; | - |
| 1464 | layout.itemize(); never executed (the execution status of this line is deduced): layout.itemize(); | - |
| 1465 | glyph_metrics_t gm = layout.boundingBox(0, len); never executed (the execution status of this line is deduced): glyph_metrics_t gm = layout.boundingBox(0, len); | - |
| 1466 | return QRectF(gm.x.toReal(), gm.y.toReal(), never executed: return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal()); | 0 |
| 1467 | gm.width.toReal(), gm.height.toReal()); never executed: return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal()); | 0 |
| 1468 | } | - |
| 1469 | | - |
| 1470 | /*! | - |
| 1471 | Returns the bounding rectangle of the character \a ch relative to | - |
| 1472 | the left-most point on the base line. | - |
| 1473 | | - |
| 1474 | Note that the bounding rectangle may extend to the left of (0, 0), | - |
| 1475 | e.g. for italicized fonts, and that the text output may cover \e | - |
| 1476 | all pixels in the bounding rectangle. | - |
| 1477 | | - |
| 1478 | Note that the rectangle usually extends both above and below the | - |
| 1479 | base line. | - |
| 1480 | | - |
| 1481 | \sa width() | - |
| 1482 | */ | - |
| 1483 | QRectF QFontMetricsF::boundingRect(QChar ch) const | - |
| 1484 | { | - |
| 1485 | const int script = QUnicodeTables::script(ch); never executed (the execution status of this line is deduced): const int script = QUnicodeTables::script(ch); | - |
| 1486 | QFontEngine *engine; never executed (the execution status of this line is deduced): QFontEngine *engine; | - |
| 1487 | if (d->capital == QFont::SmallCaps && ch.isLower()) never evaluated: d->capital == QFont::SmallCaps never evaluated: ch.isLower() | 0 |
| 1488 | engine = d->smallCapsFontPrivate()->engineForScript(script); never executed: engine = d->smallCapsFontPrivate()->engineForScript(script); | 0 |
| 1489 | else | - |
| 1490 | engine = d->engineForScript(script); never executed: engine = d->engineForScript(script); | 0 |
| 1491 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1492 | | - |
| 1493 | d->alterCharForCapitalization(ch); never executed (the execution status of this line is deduced): d->alterCharForCapitalization(ch); | - |
| 1494 | | - |
| 1495 | QGlyphLayoutArray<10> glyphs; never executed (the execution status of this line is deduced): QGlyphLayoutArray<10> glyphs; | - |
| 1496 | int nglyphs = 9; never executed (the execution status of this line is deduced): int nglyphs = 9; | - |
| 1497 | engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); never executed (the execution status of this line is deduced): engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QFontEngine::GlyphIndicesOnly); | - |
| 1498 | glyph_metrics_t gm = engine->boundingBox(glyphs.glyphs[0]); never executed (the execution status of this line is deduced): glyph_metrics_t gm = engine->boundingBox(glyphs.glyphs[0]); | - |
| 1499 | return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal()); never executed: return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal()); | 0 |
| 1500 | } | - |
| 1501 | | - |
| 1502 | /*! | - |
| 1503 | \overload | - |
| 1504 | | - |
| 1505 | Returns the bounding rectangle of the characters in the given \a text. | - |
| 1506 | This is the set of pixels the text would cover if drawn when constrained | - |
| 1507 | to the bounding rectangle specified by \a rect. | - |
| 1508 | | - |
| 1509 | The \a flags argument is the bitwise OR of the following flags: | - |
| 1510 | \list | - |
| 1511 | \li Qt::AlignLeft aligns to the left border, except for | - |
| 1512 | Arabic and Hebrew where it aligns to the right. | - |
| 1513 | \li Qt::AlignRight aligns to the right border, except for | - |
| 1514 | Arabic and Hebrew where it aligns to the left. | - |
| 1515 | \li Qt::AlignJustify produces justified text. | - |
| 1516 | \li Qt::AlignHCenter aligns horizontally centered. | - |
| 1517 | \li Qt::AlignTop aligns to the top border. | - |
| 1518 | \li Qt::AlignBottom aligns to the bottom border. | - |
| 1519 | \li Qt::AlignVCenter aligns vertically centered | - |
| 1520 | \li Qt::AlignCenter (== \c{Qt::AlignHCenter | Qt::AlignVCenter}) | - |
| 1521 | \li Qt::TextSingleLine ignores newline characters in the text. | - |
| 1522 | \li Qt::TextExpandTabs expands tabs (see below) | - |
| 1523 | \li Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined. | - |
| 1524 | \li Qt::TextWordWrap breaks the text to fit the rectangle. | - |
| 1525 | \endlist | - |
| 1526 | | - |
| 1527 | Qt::Horizontal alignment defaults to Qt::AlignLeft and vertical | - |
| 1528 | alignment defaults to Qt::AlignTop. | - |
| 1529 | | - |
| 1530 | If several of the horizontal or several of the vertical alignment | - |
| 1531 | flags are set, the resulting alignment is undefined. | - |
| 1532 | | - |
| 1533 | These flags are defined in \l{Qt::AlignmentFlag}. | - |
| 1534 | | - |
| 1535 | If Qt::TextExpandTabs is set in \a flags, the following behavior is | - |
| 1536 | used to interpret tab characters in the text: | - |
| 1537 | \list | - |
| 1538 | \li If \a tabArray is non-null, it specifies a 0-terminated sequence of | - |
| 1539 | pixel-positions for tabs in the text. | - |
| 1540 | \li If \a tabStops is non-zero, it is used as the tab spacing (in pixels). | - |
| 1541 | \endlist | - |
| 1542 | | - |
| 1543 | Note that the bounding rectangle may extend to the left of (0, 0), | - |
| 1544 | e.g. for italicized fonts. | - |
| 1545 | | - |
| 1546 | Newline characters are processed as line breaks. | - |
| 1547 | | - |
| 1548 | Despite the different actual character heights, the heights of the | - |
| 1549 | bounding rectangles of "Yes" and "yes" are the same. | - |
| 1550 | | - |
| 1551 | The bounding rectangle returned by this function is somewhat larger | - |
| 1552 | than that calculated by the simpler boundingRect() function. This | - |
| 1553 | function uses the \l{minLeftBearing()}{maximum left} and | - |
| 1554 | \l{minRightBearing()}{right} font bearings as is | - |
| 1555 | necessary for multi-line text to align correctly. Also, | - |
| 1556 | fontHeight() and lineSpacing() are used to calculate the height, | - |
| 1557 | rather than individual character heights. | - |
| 1558 | | - |
| 1559 | \sa width(), QPainter::boundingRect(), Qt::Alignment | - |
| 1560 | */ | - |
| 1561 | QRectF QFontMetricsF::boundingRect(const QRectF &rect, int flags, const QString& text, | - |
| 1562 | int tabStops, int *tabArray) const | - |
| 1563 | { | - |
| 1564 | int tabArrayLen = 0; executed (the execution status of this line is deduced): int tabArrayLen = 0; | - |
| 1565 | if (tabArray) partially evaluated: tabArray| no Evaluation Count:0 | yes Evaluation Count:14 |
| 0-14 |
| 1566 | while (tabArray[tabArrayLen]) never evaluated: tabArray[tabArrayLen] | 0 |
| 1567 | tabArrayLen++; never executed: tabArrayLen++; | 0 |
| 1568 | | - |
| 1569 | QRectF rb; executed (the execution status of this line is deduced): QRectF rb; | - |
| 1570 | qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray, executed (the execution status of this line is deduced): qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray, | - |
| 1571 | tabArrayLen, 0); executed (the execution status of this line is deduced): tabArrayLen, 0); | - |
| 1572 | return rb; executed: return rb;Execution Count:14 | 14 |
| 1573 | } | - |
| 1574 | | - |
| 1575 | /*! | - |
| 1576 | Returns the size in pixels of the characters in the given \a text. | - |
| 1577 | | - |
| 1578 | The \a flags argument is the bitwise OR of the following flags: | - |
| 1579 | \list | - |
| 1580 | \li Qt::TextSingleLine ignores newline characters. | - |
| 1581 | \li Qt::TextExpandTabs expands tabs (see below) | - |
| 1582 | \li Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined. | - |
| 1583 | \li Qt::TextWordBreak breaks the text to fit the rectangle. | - |
| 1584 | \endlist | - |
| 1585 | | - |
| 1586 | These flags are defined in \l{Qt::TextFlags}. | - |
| 1587 | | - |
| 1588 | If Qt::TextExpandTabs is set in \a flags, the following behavior is | - |
| 1589 | used to interpret tab characters in the text: | - |
| 1590 | \list | - |
| 1591 | \li If \a tabArray is non-null, it specifies a 0-terminated sequence of | - |
| 1592 | pixel-positions for tabs in the text. | - |
| 1593 | \li If \a tabStops is non-zero, it is used as the tab spacing (in pixels). | - |
| 1594 | \endlist | - |
| 1595 | | - |
| 1596 | Newline characters are processed as line breaks. | - |
| 1597 | | - |
| 1598 | Note: Despite the different actual character heights, the heights of the | - |
| 1599 | bounding rectangles of "Yes" and "yes" are the same. | - |
| 1600 | | - |
| 1601 | \sa boundingRect() | - |
| 1602 | */ | - |
| 1603 | QSizeF QFontMetricsF::size(int flags, const QString &text, int tabStops, int *tabArray) const | - |
| 1604 | { | - |
| 1605 | return boundingRect(QRectF(), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size(); executed: return boundingRect(QRectF(), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();Execution Count:14 | 14 |
| 1606 | } | - |
| 1607 | | - |
| 1608 | /*! | - |
| 1609 | \since 4.3 | - |
| 1610 | | - |
| 1611 | Returns a tight bounding rectangle around the characters in the | - |
| 1612 | string specified by \a text. The bounding rectangle always covers | - |
| 1613 | at least the set of pixels the text would cover if drawn at (0, | - |
| 1614 | 0). | - |
| 1615 | | - |
| 1616 | Note that the bounding rectangle may extend to the left of (0, 0), | - |
| 1617 | e.g. for italicized fonts, and that the width of the returned | - |
| 1618 | rectangle might be different than what the width() method returns. | - |
| 1619 | | - |
| 1620 | If you want to know the advance width of the string (to layout | - |
| 1621 | a set of strings next to each other), use width() instead. | - |
| 1622 | | - |
| 1623 | Newline characters are processed as normal characters, \e not as | - |
| 1624 | linebreaks. | - |
| 1625 | | - |
| 1626 | \warning Calling this method is very slow on Windows. | - |
| 1627 | | - |
| 1628 | \sa width(), height(), boundingRect() | - |
| 1629 | */ | - |
| 1630 | QRectF QFontMetricsF::tightBoundingRect(const QString &text) const | - |
| 1631 | { | - |
| 1632 | if (text.length() == 0) never evaluated: text.length() == 0 | 0 |
| 1633 | return QRect(); never executed: return QRect(); | 0 |
| 1634 | | - |
| 1635 | QStackTextEngine layout(text, QFont(d.data())); never executed (the execution status of this line is deduced): QStackTextEngine layout(text, QFont(d.data())); | - |
| 1636 | layout.ignoreBidi = true; never executed (the execution status of this line is deduced): layout.ignoreBidi = true; | - |
| 1637 | layout.itemize(); never executed (the execution status of this line is deduced): layout.itemize(); | - |
| 1638 | glyph_metrics_t gm = layout.tightBoundingBox(0, text.length()); never executed (the execution status of this line is deduced): glyph_metrics_t gm = layout.tightBoundingBox(0, text.length()); | - |
| 1639 | return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal()); never executed: return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal()); | 0 |
| 1640 | } | - |
| 1641 | | - |
| 1642 | /*! | - |
| 1643 | \since 4.2 | - |
| 1644 | | - |
| 1645 | If the string \a text is wider than \a width, returns an elided | - |
| 1646 | version of the string (i.e., a string with "..." in it). | - |
| 1647 | Otherwise, returns the original string. | - |
| 1648 | | - |
| 1649 | The \a mode parameter specifies whether the text is elided on the | - |
| 1650 | left (e.g., "...tech"), in the middle (e.g., "Tr...ch"), or on | - |
| 1651 | the right (e.g., "Trol..."). | - |
| 1652 | | - |
| 1653 | The \a width is specified in pixels, not characters. | - |
| 1654 | | - |
| 1655 | The \a flags argument is optional and currently only supports | - |
| 1656 | Qt::TextShowMnemonic as value. | - |
| 1657 | */ | - |
| 1658 | QString QFontMetricsF::elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags) const | - |
| 1659 | { | - |
| 1660 | QString _text = text; executed (the execution status of this line is deduced): QString _text = text; | - |
| 1661 | if (!(flags & Qt::TextLongestVariant)) { partially evaluated: !(flags & Qt::TextLongestVariant)| yes Evaluation Count:6 | no Evaluation Count:0 |
| 0-6 |
| 1662 | int posA = 0; executed (the execution status of this line is deduced): int posA = 0; | - |
| 1663 | int posB = _text.indexOf(QLatin1Char('\x9c')); executed (the execution status of this line is deduced): int posB = _text.indexOf(QLatin1Char('\x9c')); | - |
| 1664 | while (posB >= 0) { evaluated: posB >= 0| yes Evaluation Count:10 | yes Evaluation Count:2 |
| 2-10 |
| 1665 | QString portion = _text.mid(posA, posB - posA); executed (the execution status of this line is deduced): QString portion = _text.mid(posA, posB - posA); | - |
| 1666 | if (size(flags, portion).width() <= width) evaluated: size(flags, portion).width() <= width| yes Evaluation Count:4 | yes Evaluation Count:6 |
| 4-6 |
| 1667 | return portion; executed: return portion;Execution Count:4 | 4 |
| 1668 | posA = posB + 1; executed (the execution status of this line is deduced): posA = posB + 1; | - |
| 1669 | posB = _text.indexOf(QLatin1Char('\x9c'), posA); executed (the execution status of this line is deduced): posB = _text.indexOf(QLatin1Char('\x9c'), posA); | - |
| 1670 | } executed: }Execution Count:6 | 6 |
| 1671 | _text = _text.mid(posA); executed (the execution status of this line is deduced): _text = _text.mid(posA); | - |
| 1672 | } executed: }Execution Count:2 | 2 |
| 1673 | QStackTextEngine engine(_text, QFont(d.data())); executed (the execution status of this line is deduced): QStackTextEngine engine(_text, QFont(d.data())); | - |
| 1674 | return engine.elidedText(mode, QFixed::fromReal(width), flags); executed: return engine.elidedText(mode, QFixed::fromReal(width), flags);Execution Count:2 | 2 |
| 1675 | } | - |
| 1676 | | - |
| 1677 | /*! | - |
| 1678 | Returns the distance from the base line to where an underscore | - |
| 1679 | should be drawn. | - |
| 1680 | | - |
| 1681 | \sa overlinePos(), strikeOutPos(), lineWidth() | - |
| 1682 | */ | - |
| 1683 | qreal QFontMetricsF::underlinePos() const | - |
| 1684 | { | - |
| 1685 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1686 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1687 | return engine->underlinePosition().toReal(); never executed: return engine->underlinePosition().toReal(); | 0 |
| 1688 | } | - |
| 1689 | | - |
| 1690 | /*! | - |
| 1691 | Returns the distance from the base line to where an overline | - |
| 1692 | should be drawn. | - |
| 1693 | | - |
| 1694 | \sa underlinePos(), strikeOutPos(), lineWidth() | - |
| 1695 | */ | - |
| 1696 | qreal QFontMetricsF::overlinePos() const | - |
| 1697 | { | - |
| 1698 | return ascent() + 1; never executed: return ascent() + 1; | 0 |
| 1699 | } | - |
| 1700 | | - |
| 1701 | /*! | - |
| 1702 | Returns the distance from the base line to where the strikeout | - |
| 1703 | line should be drawn. | - |
| 1704 | | - |
| 1705 | \sa underlinePos(), overlinePos(), lineWidth() | - |
| 1706 | */ | - |
| 1707 | qreal QFontMetricsF::strikeOutPos() const | - |
| 1708 | { | - |
| 1709 | return ascent() / 3.; never executed: return ascent() / 3.; | 0 |
| 1710 | } | - |
| 1711 | | - |
| 1712 | /*! | - |
| 1713 | Returns the width of the underline and strikeout lines, adjusted | - |
| 1714 | for the point size of the font. | - |
| 1715 | | - |
| 1716 | \sa underlinePos(), overlinePos(), strikeOutPos() | - |
| 1717 | */ | - |
| 1718 | qreal QFontMetricsF::lineWidth() const | - |
| 1719 | { | - |
| 1720 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); never executed (the execution status of this line is deduced): QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
| 1721 | Q_ASSERT(engine != 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 1722 | return engine->lineThickness().toReal(); never executed: return engine->lineThickness().toReal(); | 0 |
| 1723 | } | - |
| 1724 | | - |
| 1725 | QT_END_NAMESPACE | - |
| 1726 | | - |
| | |