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 "qglobal.h" | - |
43 | | - |
44 | #if !defined(QT_NO_RAWFONT) | - |
45 | | - |
46 | #include "qrawfont.h" | - |
47 | #include "qrawfont_p.h" | - |
48 | | - |
49 | #include <QtCore/qendian.h> | - |
50 | | - |
51 | QT_BEGIN_NAMESPACE | - |
52 | | - |
53 | /*! | - |
54 | \class QRawFont | - |
55 | \brief The QRawFont class provides access to a single physical instance of a font. | - |
56 | \since 4.8 | - |
57 | \inmodule QtGui | - |
58 | | - |
59 | \ingroup text | - |
60 | \ingroup shared | - |
61 | \mainclass | - |
62 | | - |
63 | \note QRawFont is a low level class. For most purposes QFont is a more appropriate class. | - |
64 | | - |
65 | Most commonly, when presenting text in a user interface, the exact fonts used | - |
66 | to render the characters is to some extent unknown. This can be the case for several | - |
67 | reasons: For instance, the actual, physical fonts present on the target system could be | - |
68 | unexpected to the developers, or the text could contain user selected styles, sizes or | - |
69 | writing systems that are not supported by font chosen in the code. | - |
70 | | - |
71 | Therefore, Qt's QFont class really represents a query for fonts. When text is interpreted, | - |
72 | Qt will do its best to match the text to the query, but depending on the support, different | - |
73 | fonts can be used behind the scenes. | - |
74 | | - |
75 | For most use cases, this is both expected and necessary, as it minimizes the possibility of | - |
76 | text in the user interface being undisplayable. In some cases, however, more direct control | - |
77 | over the process might be useful. It is for these use cases the QRawFont class exists. | - |
78 | | - |
79 | A QRawFont object represents a single, physical instance of a given font in a given pixel size. | - |
80 | I.e. in the typical case it represents a set of TrueType or OpenType font tables and uses a | - |
81 | user specified pixel size to convert metrics into logical pixel units. It can be used in | - |
82 | combination with the QGlyphRun class to draw specific glyph indexes at specific positions, and | - |
83 | also have accessors to some relevant data in the physical font. | - |
84 | | - |
85 | QRawFont only provides support for the main font technologies: GDI and DirectWrite on Windows | - |
86 | platforms, FreeType on Linux platforms and CoreText on Mac OS X. For other | - |
87 | font back-ends, the APIs will be disabled. | - |
88 | | - |
89 | QRawFont can be constructed in a number of ways: | - |
90 | \list | - |
91 | \li It can be constructed by calling QTextLayout::glyphs() or QTextFragment::glyphs(). The | - |
92 | returned QGlyphs objects will contain QRawFont objects which represent the actual fonts | - |
93 | used to render each portion of the text. | - |
94 | \li It can be constructed by passing a QFont object to QRawFont::fromFont(). The function | - |
95 | will return a QRawFont object representing the font that will be selected as response to | - |
96 | the QFont query and the selected writing system. | - |
97 | \li It can be constructed by passing a file name or QByteArray directly to the QRawFont | - |
98 | constructor, or by calling loadFromFile() or loadFromData(). In this case, the | - |
99 | font will not be registered in QFontDatabase, and it will not be available as part of | - |
100 | regular font selection. | - |
101 | \endlist | - |
102 | | - |
103 | QRawFont is considered local to the thread in which it is constructed (either using a | - |
104 | constructor, or by calling loadFromData() or loadFromFile()). The QRawFont cannot be moved to a | - |
105 | different thread, but will have to be recreated in the thread in question. | - |
106 | | - |
107 | \note For the requirement of caching glyph indexes and font selections for static text to avoid | - |
108 | reshaping and relayouting in the inner loop of an application, a better choice is the QStaticText | - |
109 | class, since it optimizes the memory cost of the cache and also provides the possibility of paint | - |
110 | engine specific caches for an additional speed-up. | - |
111 | */ | - |
112 | | - |
113 | /*! | - |
114 | \enum QRawFont::AntialiasingType | - |
115 | | - |
116 | This enum represents the different ways a glyph can be rasterized in the function | - |
117 | alphaMapForGlyph(). | - |
118 | | - |
119 | \value PixelAntialiasing Will rasterize by measuring the coverage of the shape on whole pixels. | - |
120 | The returned image contains the alpha values of each pixel based on the coverage of | - |
121 | the glyph shape. | - |
122 | \value SubPixelAntialiasing Will rasterize by measuring the coverage of each subpixel, | - |
123 | returning a separate alpha value for each of the red, green and blue components of | - |
124 | each pixel. | - |
125 | */ | - |
126 | | - |
127 | /*! | - |
128 | Constructs an invalid QRawFont. | - |
129 | */ | - |
130 | QRawFont::QRawFont() | - |
131 | : d(new QRawFontPrivate) | - |
132 | { | - |
133 | } executed: } Execution Count:203591 | 203591 |
134 | | - |
135 | /*! | - |
136 | Constructs a QRawFont representing the font contained in the file referenced | - |
137 | by \a fileName for the size (in pixels) given by \a pixelSize, and using the | - |
138 | hinting preference specified by \a hintingPreference. | - |
139 | | - |
140 | \note The referenced file must contain a TrueType or OpenType font. | - |
141 | */ | - |
142 | QRawFont::QRawFont(const QString &fileName, | - |
143 | qreal pixelSize, | - |
144 | QFont::HintingPreference hintingPreference) | - |
145 | : d(new QRawFontPrivate) | - |
146 | { | - |
147 | loadFromFile(fileName, pixelSize, hintingPreference); executed (the execution status of this line is deduced): loadFromFile(fileName, pixelSize, hintingPreference); | - |
148 | } executed: } Execution Count:1233 | 1233 |
149 | | - |
150 | /*! | - |
151 | Constructs a QRawFont representing the font contained in the supplied | - |
152 | \a fontData for the size (in pixels) given by \a pixelSize, and using the | - |
153 | hinting preference specified by \a hintingPreference. | - |
154 | | - |
155 | \note The data must contain a TrueType or OpenType font. | - |
156 | */ | - |
157 | QRawFont::QRawFont(const QByteArray &fontData, | - |
158 | qreal pixelSize, | - |
159 | QFont::HintingPreference hintingPreference) | - |
160 | : d(new QRawFontPrivate) | - |
161 | { | - |
162 | loadFromData(fontData, pixelSize, hintingPreference); never executed (the execution status of this line is deduced): loadFromData(fontData, pixelSize, hintingPreference); | - |
163 | } | 0 |
164 | | - |
165 | /*! | - |
166 | Creates a QRawFont which is a copy of \a other. | - |
167 | */ | - |
168 | QRawFont::QRawFont(const QRawFont &other) | - |
169 | { | - |
170 | d = other.d; executed (the execution status of this line is deduced): d = other.d; | - |
171 | } executed: } Execution Count:70 | 70 |
172 | | - |
173 | /*! | - |
174 | Destroys the QRawFont | - |
175 | */ | - |
176 | QRawFont::~QRawFont() | - |
177 | { | - |
178 | } | - |
179 | | - |
180 | /*! | - |
181 | Assigns \a other to this QRawFont. | - |
182 | */ | - |
183 | QRawFont &QRawFont::operator=(const QRawFont &other) | - |
184 | { | - |
185 | d = other.d; executed (the execution status of this line is deduced): d = other.d; | - |
186 | return *this; executed: return *this; Execution Count:50 | 50 |
187 | } | - |
188 | | - |
189 | /*! | - |
190 | \fn void QRawFont::swap(QRawFont &other) | - |
191 | \since 5.0 | - |
192 | | - |
193 | Swaps this raw font with \a other. This function is very fast and | - |
194 | never fails. | - |
195 | */ | - |
196 | | - |
197 | /*! | - |
198 | Returns true if the QRawFont is valid and false otherwise. | - |
199 | */ | - |
200 | bool QRawFont::isValid() const | - |
201 | { | - |
202 | return d->isValid(); executed: return d->isValid(); Execution Count:1292 | 1292 |
203 | } | - |
204 | | - |
205 | /*! | - |
206 | Replaces the current QRawFont with the contents of the file referenced | - |
207 | by \a fileName for the size (in pixels) given by \a pixelSize, and using the | - |
208 | hinting preference specified by \a hintingPreference. | - |
209 | | - |
210 | The file must reference a TrueType or OpenType font. | - |
211 | | - |
212 | \sa loadFromData() | - |
213 | */ | - |
214 | void QRawFont::loadFromFile(const QString &fileName, | - |
215 | qreal pixelSize, | - |
216 | QFont::HintingPreference hintingPreference) | - |
217 | { | - |
218 | QFile file(fileName); executed (the execution status of this line is deduced): QFile file(fileName); | - |
219 | if (file.open(QIODevice::ReadOnly)) partially evaluated: file.open(QIODevice::ReadOnly) yes Evaluation Count:1245 | no Evaluation Count:0 |
| 0-1245 |
220 | loadFromData(file.readAll(), pixelSize, hintingPreference); executed: loadFromData(file.readAll(), pixelSize, hintingPreference); Execution Count:1245 | 1245 |
221 | } executed: } Execution Count:1245 | 1245 |
222 | | - |
223 | /*! | - |
224 | Replaces the current QRawFont with the font contained in the supplied | - |
225 | \a fontData for the size (in pixels) given by \a pixelSize, and using the | - |
226 | hinting preference specified by \a hintingPreference. | - |
227 | | - |
228 | The \a fontData must contain a TrueType or OpenType font. | - |
229 | | - |
230 | \sa loadFromFile() | - |
231 | */ | - |
232 | void QRawFont::loadFromData(const QByteArray &fontData, | - |
233 | qreal pixelSize, | - |
234 | QFont::HintingPreference hintingPreference) | - |
235 | { | - |
236 | d.detach(); executed (the execution status of this line is deduced): d.detach(); | - |
237 | d->cleanUp(); executed (the execution status of this line is deduced): d->cleanUp(); | - |
238 | d->hintingPreference = hintingPreference; executed (the execution status of this line is deduced): d->hintingPreference = hintingPreference; | - |
239 | d->thread = QThread::currentThread(); executed (the execution status of this line is deduced): d->thread = QThread::currentThread(); | - |
240 | d->platformLoadFromData(fontData, pixelSize, hintingPreference); executed (the execution status of this line is deduced): d->platformLoadFromData(fontData, pixelSize, hintingPreference); | - |
241 | } executed: } Execution Count:1247 | 1247 |
242 | | - |
243 | /*! | - |
244 | This function returns a rasterized image of the glyph at the given | - |
245 | \a glyphIndex in the underlying font, using the \a transform specified. | - |
246 | If the QRawFont is not valid, this function will return an invalid QImage. | - |
247 | | - |
248 | If \a antialiasingType is set to QRawFont::SubPixelAntialiasing, then the resulting image will be | - |
249 | in QImage::Format_RGB32 and the RGB values of each pixel will represent the subpixel opacities of | - |
250 | the pixel in the rasterization of the glyph. Otherwise, the image will be in the format of | - |
251 | QImage::Format_Indexed8 and each pixel will contain the opacity of the pixel in the | - |
252 | rasterization. | - |
253 | | - |
254 | \sa pathForGlyph(), QPainter::drawGlyphRun() | - |
255 | */ | - |
256 | QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType, | - |
257 | const QTransform &transform) const | - |
258 | { | - |
259 | if (!d->isValid()) never evaluated: !d->isValid() | 0 |
260 | return QImage(); never executed: return QImage(); | 0 |
261 | | - |
262 | if (antialiasingType == SubPixelAntialiasing) never evaluated: antialiasingType == SubPixelAntialiasing | 0 |
263 | return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), transform); never executed: return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), transform); | 0 |
264 | | - |
265 | return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform); never executed: return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform); | 0 |
266 | } | - |
267 | | - |
268 | /*! | - |
269 | This function returns the shape of the glyph at a given \a glyphIndex in the underlying font | - |
270 | if the QRawFont is valid. Otherwise, it returns an empty QPainterPath. | - |
271 | | - |
272 | The returned glyph will always be unhinted. | - |
273 | | - |
274 | \sa alphaMapForGlyph(), QPainterPath::addText() | - |
275 | */ | - |
276 | QPainterPath QRawFont::pathForGlyph(quint32 glyphIndex) const | - |
277 | { | - |
278 | if (!d->isValid()) never evaluated: !d->isValid() | 0 |
279 | return QPainterPath(); never executed: return QPainterPath(); | 0 |
280 | | - |
281 | QFixedPoint position; never executed (the execution status of this line is deduced): QFixedPoint position; | - |
282 | QPainterPath path; never executed (the execution status of this line is deduced): QPainterPath path; | - |
283 | d->fontEngine->addGlyphsToPath(&glyphIndex, &position, 1, &path, 0); never executed (the execution status of this line is deduced): d->fontEngine->addGlyphsToPath(&glyphIndex, &position, 1, &path, 0); | - |
284 | return path; never executed: return path; | 0 |
285 | } | - |
286 | | - |
287 | /*! | - |
288 | Returns true if this QRawFont is equal to \a other. Otherwise, returns false. | - |
289 | */ | - |
290 | bool QRawFont::operator==(const QRawFont &other) const | - |
291 | { | - |
292 | return d->fontEngine == other.d->fontEngine; executed: return d->fontEngine == other.d->fontEngine; Execution Count:7 | 7 |
293 | } | - |
294 | | - |
295 | /*! | - |
296 | \fn bool QRawFont::operator!=(const QRawFont &other) const | - |
297 | | - |
298 | Returns true if this QRawFont is not equal to \a other. Otherwise, returns false. | - |
299 | */ | - |
300 | | - |
301 | /*! | - |
302 | Returns the ascent of this QRawFont in pixel units. | - |
303 | | - |
304 | \sa QFontMetricsF::ascent() | - |
305 | */ | - |
306 | qreal QRawFont::ascent() const | - |
307 | { | - |
308 | return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0; executed: return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0; Execution Count:79 | 79 |
309 | } | - |
310 | | - |
311 | /*! | - |
312 | Returns the descent of this QRawFont in pixel units. | - |
313 | | - |
314 | \sa QFontMetricsF::descent() | - |
315 | */ | - |
316 | qreal QRawFont::descent() const | - |
317 | { | - |
318 | return d->isValid() ? d->fontEngine->descent().toReal() : 0.0; executed: return d->isValid() ? d->fontEngine->descent().toReal() : 0.0; Execution Count:56 | 56 |
319 | } | - |
320 | | - |
321 | /*! | - |
322 | Returns the xHeight of this QRawFont in pixel units. | - |
323 | | - |
324 | \sa QFontMetricsF::xHeight() | - |
325 | */ | - |
326 | qreal QRawFont::xHeight() const | - |
327 | { | - |
328 | return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0; never executed: return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0; | 0 |
329 | } | - |
330 | | - |
331 | /*! | - |
332 | Returns the leading of this QRawFont in pixel units. | - |
333 | | - |
334 | \sa QFontMetricsF::leading() | - |
335 | */ | - |
336 | qreal QRawFont::leading() const | - |
337 | { | - |
338 | return d->isValid() ? d->fontEngine->leading().toReal() : 0.0; never executed: return d->isValid() ? d->fontEngine->leading().toReal() : 0.0; | 0 |
339 | } | - |
340 | | - |
341 | /*! | - |
342 | Returns the average character width of this QRawFont in pixel units. | - |
343 | | - |
344 | \sa QFontMetricsF::averageCharWidth() | - |
345 | */ | - |
346 | qreal QRawFont::averageCharWidth() const | - |
347 | { | - |
348 | return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0; never executed: return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0; | 0 |
349 | } | - |
350 | | - |
351 | /*! | - |
352 | Returns the width of the widest character in the font. | - |
353 | | - |
354 | \sa QFontMetricsF::maxWidth() | - |
355 | */ | - |
356 | qreal QRawFont::maxCharWidth() const | - |
357 | { | - |
358 | return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0; never executed: return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0; | 0 |
359 | } | - |
360 | | - |
361 | /*! | - |
362 | Returns the pixel size set for this QRawFont. The pixel size affects how glyphs are | - |
363 | rasterized, the size of glyphs returned by pathForGlyph(), and is used to convert | - |
364 | internal metrics from design units to logical pixel units. | - |
365 | | - |
366 | \sa setPixelSize() | - |
367 | */ | - |
368 | qreal QRawFont::pixelSize() const | - |
369 | { | - |
370 | return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0; executed: return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0; Execution Count:79 | 79 |
371 | } | - |
372 | | - |
373 | /*! | - |
374 | Returns the number of design units define the width and height of the em square | - |
375 | for this QRawFont. This value is used together with the pixel size when converting design metrics | - |
376 | to pixel units, as the internal metrics are specified in design units and the pixel size gives | - |
377 | the size of 1 em in pixels. | - |
378 | | - |
379 | \sa pixelSize(), setPixelSize() | - |
380 | */ | - |
381 | qreal QRawFont::unitsPerEm() const | - |
382 | { | - |
383 | return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0; executed: return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0; Execution Count:8 | 8 |
384 | } | - |
385 | | - |
386 | /*! | - |
387 | Returns the thickness for drawing lines (underline, overline, etc.) | - |
388 | along with text drawn in this font. | - |
389 | */ | - |
390 | qreal QRawFont::lineThickness() const | - |
391 | { | - |
392 | return d->isValid() ? d->fontEngine->lineThickness().toReal() : 0.0; never executed: return d->isValid() ? d->fontEngine->lineThickness().toReal() : 0.0; | 0 |
393 | } | - |
394 | | - |
395 | /*! | - |
396 | Returns the position from baseline for drawing underlines below the text | - |
397 | rendered with this font. | - |
398 | */ | - |
399 | qreal QRawFont::underlinePosition() const | - |
400 | { | - |
401 | return d->isValid() ? d->fontEngine->underlinePosition().toReal() : 0.0; never executed: return d->isValid() ? d->fontEngine->underlinePosition().toReal() : 0.0; | 0 |
402 | } | - |
403 | | - |
404 | /*! | - |
405 | Returns the family name of this QRawFont. | - |
406 | */ | - |
407 | QString QRawFont::familyName() const | - |
408 | { | - |
409 | return d->isValid() ? d->fontEngine->fontDef.family : QString(); executed: return d->isValid() ? d->fontEngine->fontDef.family : QString(); Execution Count:84 | 84 |
410 | } | - |
411 | | - |
412 | /*! | - |
413 | Returns the style name of this QRawFont. | - |
414 | | - |
415 | \sa QFont::styleName() | - |
416 | */ | - |
417 | QString QRawFont::styleName() const | - |
418 | { | - |
419 | return d->isValid() ? d->fontEngine->fontDef.styleName : QString(); never executed: return d->isValid() ? d->fontEngine->fontDef.styleName : QString(); | 0 |
420 | } | - |
421 | | - |
422 | /*! | - |
423 | Returns the style of this QRawFont. | - |
424 | | - |
425 | \sa QFont::style() | - |
426 | */ | - |
427 | QFont::Style QRawFont::style() const | - |
428 | { | - |
429 | return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal; executed: return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal; Execution Count:11 | 11 |
430 | } | - |
431 | | - |
432 | /*! | - |
433 | Returns the weight of this QRawFont. | - |
434 | | - |
435 | \sa QFont::weight() | - |
436 | */ | - |
437 | int QRawFont::weight() const | - |
438 | { | - |
439 | return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1; executed: return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1; Execution Count:9 | 9 |
440 | } | - |
441 | | - |
442 | /*! | - |
443 | Converts the string of unicode points given by \a text to glyph indexes | - |
444 | using the CMAP table in the underlying font, and returns a vector containing | - |
445 | the result. | - |
446 | | - |
447 | Note that, in cases where there are other tables in the font that affect the | - |
448 | shaping of the text, the returned glyph indexes will not correctly represent | - |
449 | the rendering of the text. To get the correctly shaped text, you can use | - |
450 | QTextLayout to lay out and shape the text, then call QTextLayout::glyphs() | - |
451 | to get the set of glyph index list and QRawFont pairs. | - |
452 | | - |
453 | \sa advancesForGlyphIndexes(), glyphIndexesForChars(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns() | - |
454 | */ | - |
455 | QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const | - |
456 | { | - |
457 | QVector<quint32> glyphIndexes; executed (the execution status of this line is deduced): QVector<quint32> glyphIndexes; | - |
458 | if (!d->isValid() || text.isEmpty()) evaluated: !d->isValid() yes Evaluation Count:1 | yes Evaluation Count:3 |
evaluated: text.isEmpty() yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-3 |
459 | return glyphIndexes; executed: return glyphIndexes; Execution Count:2 | 2 |
460 | | - |
461 | int numGlyphs = text.size(); executed (the execution status of this line is deduced): int numGlyphs = text.size(); | - |
462 | glyphIndexes.resize(numGlyphs); executed (the execution status of this line is deduced): glyphIndexes.resize(numGlyphs); | - |
463 | | - |
464 | QGlyphLayout glyphs; executed (the execution status of this line is deduced): QGlyphLayout glyphs; | - |
465 | glyphs.numGlyphs = numGlyphs; executed (the execution status of this line is deduced): glyphs.numGlyphs = numGlyphs; | - |
466 | glyphs.glyphs = glyphIndexes.data(); executed (the execution status of this line is deduced): glyphs.glyphs = glyphIndexes.data(); | - |
467 | if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly)) { partially evaluated: !d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly) no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
468 | glyphIndexes.resize(numGlyphs); never executed (the execution status of this line is deduced): glyphIndexes.resize(numGlyphs); | - |
469 | | - |
470 | glyphs.numGlyphs = numGlyphs; never executed (the execution status of this line is deduced): glyphs.numGlyphs = numGlyphs; | - |
471 | glyphs.glyphs = glyphIndexes.data(); never executed (the execution status of this line is deduced): glyphs.glyphs = glyphIndexes.data(); | - |
472 | if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly)) { never evaluated: !d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly) | 0 |
473 | Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice"); never executed (the execution status of this line is deduced): qt_noop(); | - |
474 | return QVector<quint32>(); never executed: return QVector<quint32>(); | 0 |
475 | } | - |
476 | } | 0 |
477 | | - |
478 | glyphIndexes.resize(numGlyphs); executed (the execution status of this line is deduced): glyphIndexes.resize(numGlyphs); | - |
479 | return glyphIndexes; executed: return glyphIndexes; Execution Count:2 | 2 |
480 | } | - |
481 | | - |
482 | /*! | - |
483 | Converts a string of unicode points to glyph indexes using the CMAP table in the | - |
484 | underlying font. The function works like glyphIndexesForString() except it take | - |
485 | an array (\a chars), the results will be returned though \a glyphIndexes array | - |
486 | and number of glyphs will be set in \a numGlyphs. The size of \a glyphIndexes array | - |
487 | must be at least \a numChars, if that's still not enough, this function will return | - |
488 | false, then you can resize \a glyphIndexes from the size returned in \a numGlyphs. | - |
489 | | - |
490 | \sa glyphIndexesForString(), advancesForGlyphIndexes(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns() | - |
491 | */ | - |
492 | bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const | - |
493 | { | - |
494 | Q_ASSERT(numGlyphs); executed (the execution status of this line is deduced): qt_noop(); | - |
495 | if (!d->isValid() || numChars <= 0) { partially evaluated: !d->isValid() no Evaluation Count:0 | yes Evaluation Count:3 |
evaluated: numChars <= 0 yes Evaluation Count:1 | yes Evaluation Count:2 |
| 0-3 |
496 | *numGlyphs = 0; executed (the execution status of this line is deduced): *numGlyphs = 0; | - |
497 | return false; executed: return false; Execution Count:1 | 1 |
498 | } | - |
499 | | - |
500 | if (*numGlyphs <= 0 || !glyphIndexes) { evaluated: *numGlyphs <= 0 yes Evaluation Count:1 | yes Evaluation Count:1 |
partially evaluated: !glyphIndexes no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
501 | *numGlyphs = numChars; executed (the execution status of this line is deduced): *numGlyphs = numChars; | - |
502 | return false; executed: return false; Execution Count:1 | 1 |
503 | } | - |
504 | | - |
505 | QGlyphLayout glyphs; executed (the execution status of this line is deduced): QGlyphLayout glyphs; | - |
506 | glyphs.numGlyphs = *numGlyphs; executed (the execution status of this line is deduced): glyphs.numGlyphs = *numGlyphs; | - |
507 | glyphs.glyphs = glyphIndexes; executed (the execution status of this line is deduced): glyphs.glyphs = glyphIndexes; | - |
508 | return d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QFontEngine::GlyphIndicesOnly); executed: return d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QFontEngine::GlyphIndicesOnly); Execution Count:1 | 1 |
509 | } | - |
510 | | - |
511 | /*! | - |
512 | \fn QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes) const | - |
513 | | - |
514 | Returns the QRawFont's advances for each of the \a glyphIndexes in pixel units. The advances | - |
515 | give the distance from the position of a given glyph to where the next glyph should be drawn | - |
516 | to make it appear as if the two glyphs are unspaced. | - |
517 | | - |
518 | \sa QTextLine::horizontalAdvance(), QFontMetricsF::width() | - |
519 | */ | - |
520 | | - |
521 | /*! | - |
522 | Returns the QRawFont's advances for each of the \a glyphIndexes in pixel units. The advances | - |
523 | give the distance from the position of a given glyph to where the next glyph should be drawn | - |
524 | to make it appear as if the two glyphs are unspaced. The glyph indexes are given with the | - |
525 | array \a glyphIndexes while the results are returned through \a advances, both of them must | - |
526 | have \a numGlyphs elements. | - |
527 | | - |
528 | \sa QTextLine::horizontalAdvance(), QFontMetricsF::width() | - |
529 | */ | - |
530 | bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const | - |
531 | { | - |
532 | Q_ASSERT(glyphIndexes && advances); executed (the execution status of this line is deduced): qt_noop(); | - |
533 | if (!d->isValid() || numGlyphs <= 0) partially evaluated: !d->isValid() no Evaluation Count:0 | yes Evaluation Count:17 |
evaluated: numGlyphs <= 0 yes Evaluation Count:8 | yes Evaluation Count:9 |
| 0-17 |
534 | return false; executed: return false; Execution Count:8 | 8 |
535 | | - |
536 | QGlyphLayout glyphs; executed (the execution status of this line is deduced): QGlyphLayout glyphs; | - |
537 | glyphs.glyphs = const_cast<HB_Glyph *>(glyphIndexes); executed (the execution status of this line is deduced): glyphs.glyphs = const_cast<HB_Glyph *>(glyphIndexes); | - |
538 | glyphs.numGlyphs = numGlyphs; executed (the execution status of this line is deduced): glyphs.numGlyphs = numGlyphs; | - |
539 | QVarLengthArray<QFixed> advances_x(numGlyphs); executed (the execution status of this line is deduced): QVarLengthArray<QFixed> advances_x(numGlyphs); | - |
540 | QVarLengthArray<QFixed> advances_y(numGlyphs); executed (the execution status of this line is deduced): QVarLengthArray<QFixed> advances_y(numGlyphs); | - |
541 | glyphs.advances_x = advances_x.data(); executed (the execution status of this line is deduced): glyphs.advances_x = advances_x.data(); | - |
542 | glyphs.advances_y = advances_y.data(); executed (the execution status of this line is deduced): glyphs.advances_y = advances_y.data(); | - |
543 | | - |
544 | d->fontEngine->recalcAdvances(&glyphs, 0); executed (the execution status of this line is deduced): d->fontEngine->recalcAdvances(&glyphs, 0); | - |
545 | | - |
546 | for (int i=0; i<numGlyphs; ++i) evaluated: i<numGlyphs yes Evaluation Count:53 | yes Evaluation Count:9 |
| 9-53 |
547 | advances[i] = QPointF(glyphs.advances_x[i].toReal(), glyphs.advances_y[i].toReal()); executed: advances[i] = QPointF(glyphs.advances_x[i].toReal(), glyphs.advances_y[i].toReal()); Execution Count:53 | 53 |
548 | | - |
549 | return true; executed: return true; Execution Count:9 | 9 |
550 | } | - |
551 | | - |
552 | /*! | - |
553 | Returns the hinting preference used to construct this QRawFont. | - |
554 | | - |
555 | \sa QFont::hintingPreference() | - |
556 | */ | - |
557 | QFont::HintingPreference QRawFont::hintingPreference() const | - |
558 | { | - |
559 | return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting; executed: return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting; Execution Count:32 | 32 |
560 | } | - |
561 | | - |
562 | /*! | - |
563 | Retrieves the sfnt table named \a tagName from the underlying physical font, or an empty | - |
564 | byte array if no such table was found. The returned font table's byte order is Big Endian, like | - |
565 | the sfnt format specifies. The \a tagName must be four characters long and should be formatted | - |
566 | in the default endianness of the current platform. | - |
567 | */ | - |
568 | QByteArray QRawFont::fontTable(const char *tagName) const | - |
569 | { | - |
570 | if (!d->isValid()) partially evaluated: !d->isValid() no Evaluation Count:0 | yes Evaluation Count:44 |
| 0-44 |
571 | return QByteArray(); never executed: return QByteArray(); | 0 |
572 | | - |
573 | const quint32 *tagId = reinterpret_cast<const quint32 *>(tagName); executed (the execution status of this line is deduced): const quint32 *tagId = reinterpret_cast<const quint32 *>(tagName); | - |
574 | return d->fontEngine->getSfntTable(qToBigEndian(*tagId)); executed: return d->fontEngine->getSfntTable(qToBigEndian(*tagId)); Execution Count:44 | 44 |
575 | } | - |
576 | | - |
577 | // From qfontdatabase.cpp | - |
578 | extern QList<QFontDatabase::WritingSystem> qt_determine_writing_systems_from_truetype_bits(quint32 unicodeRange[4], quint32 codePageRange[2]); | - |
579 | | - |
580 | /*! | - |
581 | Returns a list of writing systems supported by the font according to designer supplied | - |
582 | information in the font file. Please note that this does not guarantee support for a | - |
583 | specific unicode point in the font. You can use the supportsCharacter() to check support | - |
584 | for a single, specific character. | - |
585 | | - |
586 | \note The list is determined based on the unicode ranges and codepage ranges set in the font's | - |
587 | OS/2 table and requires such a table to be present in the underlying font file. | - |
588 | | - |
589 | \sa supportsCharacter() | - |
590 | */ | - |
591 | QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const | - |
592 | { | - |
593 | if (d->isValid()) { partially evaluated: d->isValid() yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-8 |
594 | QByteArray os2Table = fontTable("OS/2"); executed (the execution status of this line is deduced): QByteArray os2Table = fontTable("OS/2"); | - |
595 | if (os2Table.size() > 86) { partially evaluated: os2Table.size() > 86 yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-8 |
596 | char *data = os2Table.data(); executed (the execution status of this line is deduced): char *data = os2Table.data(); | - |
597 | quint32 *bigEndianUnicodeRanges = reinterpret_cast<quint32 *>(data + 42); executed (the execution status of this line is deduced): quint32 *bigEndianUnicodeRanges = reinterpret_cast<quint32 *>(data + 42); | - |
598 | quint32 *bigEndianCodepageRanges = reinterpret_cast<quint32 *>(data + 78); executed (the execution status of this line is deduced): quint32 *bigEndianCodepageRanges = reinterpret_cast<quint32 *>(data + 78); | - |
599 | | - |
600 | quint32 unicodeRanges[4]; executed (the execution status of this line is deduced): quint32 unicodeRanges[4]; | - |
601 | quint32 codepageRanges[2]; executed (the execution status of this line is deduced): quint32 codepageRanges[2]; | - |
602 | | - |
603 | for (int i=0; i<4; ++i) { evaluated: i<4 yes Evaluation Count:32 | yes Evaluation Count:8 |
| 8-32 |
604 | if (i < 2) evaluated: i < 2 yes Evaluation Count:16 | yes Evaluation Count:16 |
| 16 |
605 | codepageRanges[i] = qFromBigEndian(bigEndianCodepageRanges[i]); executed: codepageRanges[i] = qFromBigEndian(bigEndianCodepageRanges[i]); Execution Count:16 | 16 |
606 | unicodeRanges[i] = qFromBigEndian(bigEndianUnicodeRanges[i]); executed (the execution status of this line is deduced): unicodeRanges[i] = qFromBigEndian(bigEndianUnicodeRanges[i]); | - |
607 | } executed: } Execution Count:32 | 32 |
608 | | - |
609 | return qt_determine_writing_systems_from_truetype_bits(unicodeRanges, codepageRanges); executed: return qt_determine_writing_systems_from_truetype_bits(unicodeRanges, codepageRanges); Execution Count:8 | 8 |
610 | } | - |
611 | } | 0 |
612 | | - |
613 | return QList<QFontDatabase::WritingSystem>(); never executed: return QList<QFontDatabase::WritingSystem>(); | 0 |
614 | } | - |
615 | | - |
616 | /*! | - |
617 | Returns true if the font has a glyph that corresponds to the given \a character. | - |
618 | | - |
619 | \sa supportedWritingSystems() | - |
620 | */ | - |
621 | bool QRawFont::supportsCharacter(QChar character) const | - |
622 | { | - |
623 | return d->isValid() && d->fontEngine->canRender(&character, 1); executed: return d->isValid() && d->fontEngine->canRender(&character, 1); Execution Count:976 | 976 |
624 | } | - |
625 | | - |
626 | /*! | - |
627 | \overload | - |
628 | | - |
629 | Returns true if the font has a glyph that corresponds to the UCS-4 encoded character \a ucs4. | - |
630 | | - |
631 | \sa supportedWritingSystems() | - |
632 | */ | - |
633 | bool QRawFont::supportsCharacter(uint ucs4) const | - |
634 | { | - |
635 | return d->isValid() && d->fontEngine->canRender(ucs4); executed: return d->isValid() && d->fontEngine->canRender(ucs4); Execution Count:216 | 216 |
636 | } | - |
637 | | - |
638 | // qfontdatabase.cpp | - |
639 | extern int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem); | - |
640 | | - |
641 | /*! | - |
642 | Fetches the physical representation based on a \a font query. The physical font returned is | - |
643 | the font that will be preferred by Qt in order to display text in the selected \a writingSystem. | - |
644 | | - |
645 | \warning This function is potentially expensive and should not be called in performance | - |
646 | sensitive code. | - |
647 | */ | - |
648 | QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writingSystem) | - |
649 | { | - |
650 | QRawFont rawFont; executed (the execution status of this line is deduced): QRawFont rawFont; | - |
651 | QFontPrivate *font_d = QFontPrivate::get(font); executed (the execution status of this line is deduced): QFontPrivate *font_d = QFontPrivate::get(font); | - |
652 | int script = qt_script_for_writing_system(writingSystem); executed (the execution status of this line is deduced): int script = qt_script_for_writing_system(writingSystem); | - |
653 | QFontEngine *fe = font_d->engineForScript(script); executed (the execution status of this line is deduced): QFontEngine *fe = font_d->engineForScript(script); | - |
654 | | - |
655 | if (fe != 0 && fe->type() == QFontEngine::Multi) { partially evaluated: fe != 0 yes Evaluation Count:32 | no Evaluation Count:0 |
partially evaluated: fe->type() == QFontEngine::Multi yes Evaluation Count:32 | no Evaluation Count:0 |
| 0-32 |
656 | QFontEngineMulti *multiEngine = static_cast<QFontEngineMulti *>(fe); executed (the execution status of this line is deduced): QFontEngineMulti *multiEngine = static_cast<QFontEngineMulti *>(fe); | - |
657 | fe = multiEngine->engine(0); executed (the execution status of this line is deduced): fe = multiEngine->engine(0); | - |
658 | if (fe == 0) { partially evaluated: fe == 0 no Evaluation Count:0 | yes Evaluation Count:32 |
| 0-32 |
659 | multiEngine->loadEngine(0); never executed (the execution status of this line is deduced): multiEngine->loadEngine(0); | - |
660 | fe = multiEngine->engine(0); never executed (the execution status of this line is deduced): fe = multiEngine->engine(0); | - |
661 | } | 0 |
662 | } executed: } Execution Count:32 | 32 |
663 | | - |
664 | if (fe != 0) { partially evaluated: fe != 0 yes Evaluation Count:32 | no Evaluation Count:0 |
| 0-32 |
665 | rawFont.d.data()->fontEngine = fe; executed (the execution status of this line is deduced): rawFont.d.data()->fontEngine = fe; | - |
666 | rawFont.d.data()->fontEngine->ref.ref(); executed (the execution status of this line is deduced): rawFont.d.data()->fontEngine->ref.ref(); | - |
667 | rawFont.d.data()->hintingPreference = font.hintingPreference(); executed (the execution status of this line is deduced): rawFont.d.data()->hintingPreference = font.hintingPreference(); | - |
668 | } executed: } Execution Count:32 | 32 |
669 | return rawFont; executed: return rawFont; Execution Count:32 | 32 |
670 | } | - |
671 | | - |
672 | /*! | - |
673 | Sets the pixel size with which this font should be rendered to \a pixelSize. | - |
674 | */ | - |
675 | void QRawFont::setPixelSize(qreal pixelSize) | - |
676 | { | - |
677 | if (d->fontEngine == 0 || qFuzzyCompare(d->fontEngine->fontDef.pixelSize, pixelSize)) partially evaluated: d->fontEngine == 0 no Evaluation Count:0 | yes Evaluation Count:4 |
partially evaluated: qFuzzyCompare(d->fontEngine->fontDef.pixelSize, pixelSize) no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
678 | return; | 0 |
679 | | - |
680 | d.detach(); executed (the execution status of this line is deduced): d.detach(); | - |
681 | QFontEngine *oldFontEngine = d->fontEngine; executed (the execution status of this line is deduced): QFontEngine *oldFontEngine = d->fontEngine; | - |
682 | | - |
683 | d->fontEngine = d->fontEngine->cloneWithSize(pixelSize); executed (the execution status of this line is deduced): d->fontEngine = d->fontEngine->cloneWithSize(pixelSize); | - |
684 | if (d->fontEngine != 0) partially evaluated: d->fontEngine != 0 yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
685 | d->fontEngine->ref.ref(); executed: d->fontEngine->ref.ref(); Execution Count:4 | 4 |
686 | | - |
687 | oldFontEngine->ref.deref(); executed (the execution status of this line is deduced): oldFontEngine->ref.deref(); | - |
688 | if (oldFontEngine->cache_count == 0 && oldFontEngine->ref.load() == 0) partially evaluated: oldFontEngine->cache_count == 0 no Evaluation Count:0 | yes Evaluation Count:4 |
never evaluated: oldFontEngine->ref.load() == 0 | 0-4 |
689 | delete oldFontEngine; never executed: delete oldFontEngine; | 0 |
690 | } executed: } Execution Count:4 | 4 |
691 | | - |
692 | /*! | - |
693 | \internal | - |
694 | */ | - |
695 | void QRawFontPrivate::cleanUp() | - |
696 | { | - |
697 | platformCleanUp(); executed (the execution status of this line is deduced): platformCleanUp(); | - |
698 | if (fontEngine != 0) { evaluated: fontEngine != 0 yes Evaluation Count:1318 | yes Evaluation Count:204750 |
| 1318-204750 |
699 | fontEngine->ref.deref(); executed (the execution status of this line is deduced): fontEngine->ref.deref(); | - |
700 | if (fontEngine->cache_count == 0 && fontEngine->ref.load() == 0) evaluated: fontEngine->cache_count == 0 yes Evaluation Count:1263 | yes Evaluation Count:55 |
evaluated: fontEngine->ref.load() == 0 yes Evaluation Count:1251 | yes Evaluation Count:12 |
| 12-1263 |
701 | delete fontEngine; executed: delete fontEngine; Execution Count:1251 | 1251 |
702 | fontEngine = 0; executed (the execution status of this line is deduced): fontEngine = 0; | - |
703 | } executed: } Execution Count:1318 | 1318 |
704 | hintingPreference = QFont::PreferDefaultHinting; executed (the execution status of this line is deduced): hintingPreference = QFont::PreferDefaultHinting; | - |
705 | } executed: } Execution Count:206068 | 206068 |
706 | | - |
707 | /*! | - |
708 | Returns the smallest rectangle containing the glyph with the given \a glyphIndex. | - |
709 | | - |
710 | \since 5.0 | - |
711 | */ | - |
712 | QRectF QRawFont::boundingRect(quint32 glyphIndex) const | - |
713 | { | - |
714 | if (!isValid()) partially evaluated: !isValid() no Evaluation Count:0 | yes Evaluation Count:10 |
| 0-10 |
715 | return QRectF(); never executed: return QRectF(); | 0 |
716 | | - |
717 | glyph_metrics_t gm = d->fontEngine->boundingBox(glyphIndex); executed (the execution status of this line is deduced): glyph_metrics_t gm = d->fontEngine->boundingBox(glyphIndex); | - |
718 | return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal()); executed: return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal()); Execution Count:10 | 10 |
719 | } | - |
720 | | - |
721 | #endif // QT_NO_RAWFONT | - |
722 | | - |
723 | QT_END_NAMESPACE | - |
724 | | - |
| | |