qrawfont.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qrawfont.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qglobal.h"-
41-
42#if !defined(QT_NO_RAWFONT)-
43-
44#include "qrawfont.h"-
45#include "qrawfont_p.h"-
46#include "qplatformfontdatabase.h"-
47-
48#include <private/qguiapplication_p.h>-
49#include <qpa/qplatformintegration.h>-
50#include <qpa/qplatformfontdatabase.h>-
51-
52#include <QtCore/qendian.h>-
53#include <QtCore/qfile.h>-
54-
55QT_BEGIN_NAMESPACE-
56-
57/*!-
58 \class QRawFont-
59 \brief The QRawFont class provides access to a single physical instance of a font.-
60 \since 4.8-
61 \inmodule QtGui-
62-
63 \ingroup text-
64 \ingroup shared-
65-
66 \note QRawFont is a low level class. For most purposes QFont is a more appropriate class.-
67-
68 Most commonly, when presenting text in a user interface, the exact fonts used-
69 to render the characters is to some extent unknown. This can be the case for several-
70 reasons: For instance, the actual, physical fonts present on the target system could be-
71 unexpected to the developers, or the text could contain user selected styles, sizes or-
72 writing systems that are not supported by font chosen in the code.-
73-
74 Therefore, Qt's QFont class really represents a query for fonts. When text is interpreted,-
75 Qt will do its best to match the text to the query, but depending on the support, different-
76 fonts can be used behind the scenes.-
77-
78 For most use cases, this is both expected and necessary, as it minimizes the possibility of-
79 text in the user interface being undisplayable. In some cases, however, more direct control-
80 over the process might be useful. It is for these use cases the QRawFont class exists.-
81-
82 A QRawFont object represents a single, physical instance of a given font in a given pixel size.-
83 I.e. in the typical case it represents a set of TrueType or OpenType font tables and uses a-
84 user specified pixel size to convert metrics into logical pixel units. It can be used in-
85 combination with the QGlyphRun class to draw specific glyph indexes at specific positions, and-
86 also have accessors to some relevant data in the physical font.-
87-
88 QRawFont only provides support for the main font technologies: GDI and DirectWrite on Windows-
89 platforms, FreeType on Linux platforms and CoreText on \macos. For other-
90 font back-ends, the APIs will be disabled.-
91-
92 QRawFont can be constructed in a number of ways:-
93 \list-
94 \li It can be constructed by calling QTextLayout::glyphs() or QTextFragment::glyphs(). The-
95 returned QGlyphs objects will contain QRawFont objects which represent the actual fonts-
96 used to render each portion of the text.-
97 \li It can be constructed by passing a QFont object to QRawFont::fromFont(). The function-
98 will return a QRawFont object representing the font that will be selected as response to-
99 the QFont query and the selected writing system.-
100 \li It can be constructed by passing a file name or QByteArray directly to the QRawFont-
101 constructor, or by calling loadFromFile() or loadFromData(). In this case, the-
102 font will not be registered in QFontDatabase, and it will not be available as part of-
103 regular font selection.-
104 \endlist-
105-
106 QRawFont is considered local to the thread in which it is constructed (either using a-
107 constructor, or by calling loadFromData() or loadFromFile()). The QRawFont cannot be moved to a-
108 different thread, but will have to be recreated in the thread in question.-
109-
110 \note For the requirement of caching glyph indexes and font selections for static text to avoid-
111 reshaping and relayouting in the inner loop of an application, a better choice is the QStaticText-
112 class, since it optimizes the memory cost of the cache and also provides the possibility of paint-
113 engine specific caches for an additional speed-up.-
114*/-
115-
116/*!-
117 \enum QRawFont::AntialiasingType-
118-
119 This enum represents the different ways a glyph can be rasterized in the function-
120 alphaMapForGlyph().-
121-
122 \value PixelAntialiasing Will rasterize by measuring the coverage of the shape on whole pixels.-
123 The returned image contains the alpha values of each pixel based on the coverage of-
124 the glyph shape.-
125 \value SubPixelAntialiasing Will rasterize by measuring the coverage of each subpixel,-
126 returning a separate alpha value for each of the red, green and blue components of-
127 each pixel.-
128*/-
129-
130/*!-
131 \enum QRawFont::LayoutFlag-
132 \since 5.1-
133-
134 This enum tells the function advancesForGlyphIndexes() how to calculate the advances.-
135-
136 \value SeparateAdvances Will calculate the advance for each glyph separately.-
137 \value KernedAdvances Will apply kerning between adjacent glyphs. Note that OpenType GPOS based-
138 kerning is currently not supported.-
139 \value UseDesignMetrics Use design metrics instead of hinted metrics adjusted to the resolution-
140 of the paint device.-
141 Can be OR-ed with any of the options above.-
142*/-
143-
144/*!-
145 Constructs an invalid QRawFont.-
146*/-
147QRawFont::QRawFont()-
148 : d(new QRawFontPrivate)-
149{-
150}
never executed: end of block
0
151-
152/*!-
153 Constructs a QRawFont representing the font contained in the file referenced-
154 by \a fileName for the size (in pixels) given by \a pixelSize, and using the-
155 hinting preference specified by \a hintingPreference.-
156-
157 \note The referenced file must contain a TrueType or OpenType font.-
158*/-
159QRawFont::QRawFont(const QString &fileName,-
160 qreal pixelSize,-
161 QFont::HintingPreference hintingPreference)-
162 : d(new QRawFontPrivate)-
163{-
164 loadFromFile(fileName, pixelSize, hintingPreference);-
165}
never executed: end of block
0
166-
167/*!-
168 Constructs a QRawFont representing the font contained in the supplied-
169 \a fontData for the size (in pixels) given by \a pixelSize, and using the-
170 hinting preference specified by \a hintingPreference.-
171-
172 \note The data must contain a TrueType or OpenType font.-
173*/-
174QRawFont::QRawFont(const QByteArray &fontData,-
175 qreal pixelSize,-
176 QFont::HintingPreference hintingPreference)-
177 : d(new QRawFontPrivate)-
178{-
179 loadFromData(fontData, pixelSize, hintingPreference);-
180}
never executed: end of block
0
181-
182/*!-
183 Creates a QRawFont which is a copy of \a other.-
184*/-
185QRawFont::QRawFont(const QRawFont &other)-
186{-
187 d = other.d;-
188}
never executed: end of block
0
189-
190/*!-
191 Destroys the QRawFont-
192*/-
193QRawFont::~QRawFont()-
194{-
195}-
196-
197/*!-
198 Assigns \a other to this QRawFont.-
199*/-
200QRawFont &QRawFont::operator=(const QRawFont &other)-
201{-
202 d = other.d;-
203 return *this;
never executed: return *this;
0
204}-
205-
206/*!-
207 \fn void QRawFont::swap(QRawFont &other)-
208 \since 5.0-
209-
210 Swaps this raw font with \a other. This function is very fast and-
211 never fails.-
212*/-
213-
214/*!-
215 Returns \c true if the QRawFont is valid and false otherwise.-
216*/-
217bool QRawFont::isValid() const-
218{-
219 return d->isValid();
never executed: return d->isValid();
0
220}-
221-
222/*!-
223 Replaces the current QRawFont with the contents of the file referenced-
224 by \a fileName for the size (in pixels) given by \a pixelSize, and using the-
225 hinting preference specified by \a hintingPreference.-
226-
227 The file must reference a TrueType or OpenType font.-
228-
229 \sa loadFromData()-
230*/-
231void QRawFont::loadFromFile(const QString &fileName,-
232 qreal pixelSize,-
233 QFont::HintingPreference hintingPreference)-
234{-
235 QFile file(fileName);-
236 if (file.open(QIODevice::ReadOnly))
file.open(QIODevice::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
0
237 loadFromData(file.readAll(), pixelSize, hintingPreference);
never executed: loadFromData(file.readAll(), pixelSize, hintingPreference);
0
238}
never executed: end of block
0
239-
240/*!-
241 Replaces the current QRawFont with the font contained in the supplied-
242 \a fontData for the size (in pixels) given by \a pixelSize, and using the-
243 hinting preference specified by \a hintingPreference.-
244-
245 The \a fontData must contain a TrueType or OpenType font.-
246-
247 \sa loadFromFile()-
248*/-
249void QRawFont::loadFromData(const QByteArray &fontData,-
250 qreal pixelSize,-
251 QFont::HintingPreference hintingPreference)-
252{-
253 d.detach();-
254 d->cleanUp();-
255 d->hintingPreference = hintingPreference;-
256 d->loadFromData(fontData, pixelSize, hintingPreference);-
257}
never executed: end of block
0
258-
259/*!-
260 This function returns a rasterized image of the glyph at the given-
261 \a glyphIndex in the underlying font, using the \a transform specified.-
262 If the QRawFont is not valid, this function will return an invalid QImage.-
263-
264 If \a antialiasingType is set to QRawFont::SubPixelAntialiasing, then the resulting image will be-
265 in QImage::Format_RGB32 and the RGB values of each pixel will represent the subpixel opacities of-
266 the pixel in the rasterization of the glyph. Otherwise, the image will be in the format of-
267 QImage::Format_Indexed8 and each pixel will contain the opacity of the pixel in the-
268 rasterization.-
269-
270 \sa pathForGlyph(), QPainter::drawGlyphRun()-
271*/-
272QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType,-
273 const QTransform &transform) const-
274{-
275 if (!d->isValid())
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
276 return QImage();
never executed: return QImage();
0
277-
278 if (antialiasingType == SubPixelAntialiasing)
antialiasingTy...elAntialiasingDescription
TRUEnever evaluated
FALSEnever evaluated
0
279 return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), transform);
never executed: return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), transform);
0
280-
281 return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
never executed: return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
0
282}-
283-
284/*!-
285 This function returns the shape of the glyph at a given \a glyphIndex in the underlying font-
286 if the QRawFont is valid. Otherwise, it returns an empty QPainterPath.-
287-
288 The returned glyph will always be unhinted.-
289-
290 \sa alphaMapForGlyph(), QPainterPath::addText()-
291*/-
292QPainterPath QRawFont::pathForGlyph(quint32 glyphIndex) const-
293{-
294 if (!d->isValid())
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
295 return QPainterPath();
never executed: return QPainterPath();
0
296-
297 QFixedPoint position;-
298 QPainterPath path;-
299 d->fontEngine->addGlyphsToPath(&glyphIndex, &position, 1, &path, 0);-
300 return path;
never executed: return path;
0
301}-
302-
303/*!-
304 Returns \c true if this QRawFont is equal to \a other. Otherwise, returns \c false.-
305*/-
306bool QRawFont::operator==(const QRawFont &other) const-
307{-
308 return d->fontEngine == other.d->fontEngine;
never executed: return d->fontEngine == other.d->fontEngine;
0
309}-
310-
311/*!-
312 \fn bool QRawFont::operator!=(const QRawFont &other) const-
313-
314 Returns \c true if this QRawFont is not equal to \a other. Otherwise, returns \c false.-
315*/-
316-
317/*!-
318 Returns the ascent of this QRawFont in pixel units.-
319-
320 The ascent of a font is the distance from the baseline to the-
321 highest position characters extend to. In practice, some font-
322 designers break this rule, e.g. when they put more than one accent-
323 on top of a character, or to accommodate an unusual character in-
324 an exotic language, so it is possible (though rare) that this-
325 value will be too small.-
326-
327 \sa QFontMetricsF::ascent()-
328*/-
329qreal QRawFont::ascent() const-
330{-
331 return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0;
0
332}-
333-
334/*!-
335 Returns the descent of this QRawFont in pixel units.-
336-
337 The descent is the distance from the base line to the lowest point-
338 characters extend to. In practice, some font designers break this rule,-
339 e.g. to accommodate an unusual character in an exotic language, so-
340 it is possible (though rare) that this value will be too small.-
341-
342 \sa QFontMetricsF::descent()-
343*/-
344qreal QRawFont::descent() const-
345{-
346 return d->isValid() ? d->fontEngine->descent().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->descent().toReal() : 0.0;
0
347}-
348-
349/*!-
350 Returns the xHeight of this QRawFont in pixel units.-
351-
352 This is often but not always the same as the height of the character 'x'.-
353-
354 \sa QFontMetricsF::xHeight()-
355*/-
356qreal QRawFont::xHeight() const-
357{-
358 return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0;
0
359}-
360-
361/*!-
362 Returns the leading of this QRawFont in pixel units.-
363-
364 This is the natural inter-line spacing.-
365-
366 \sa QFontMetricsF::leading()-
367*/-
368qreal QRawFont::leading() const-
369{-
370 return d->isValid() ? d->fontEngine->leading().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->leading().toReal() : 0.0;
0
371}-
372-
373/*!-
374 Returns the average character width of this QRawFont in pixel units.-
375-
376 \sa QFontMetricsF::averageCharWidth()-
377*/-
378qreal QRawFont::averageCharWidth() const-
379{-
380 return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0;
0
381}-
382-
383/*!-
384 Returns the width of the widest character in the font.-
385-
386 \sa QFontMetricsF::maxWidth()-
387*/-
388qreal QRawFont::maxCharWidth() const-
389{-
390 return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0;
never executed: return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0;
0
391}-
392-
393/*!-
394 Returns the pixel size set for this QRawFont. The pixel size affects how glyphs are-
395 rasterized, the size of glyphs returned by pathForGlyph(), and is used to convert-
396 internal metrics from design units to logical pixel units.-
397-
398 \sa setPixelSize()-
399*/-
400qreal QRawFont::pixelSize() const-
401{-
402 return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0;
never executed: return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0;
0
403}-
404-
405/*!-
406 Returns the number of design units define the width and height of the em square-
407 for this QRawFont. This value is used together with the pixel size when converting design metrics-
408 to pixel units, as the internal metrics are specified in design units and the pixel size gives-
409 the size of 1 em in pixels.-
410-
411 \sa pixelSize(), setPixelSize()-
412*/-
413qreal QRawFont::unitsPerEm() const-
414{-
415 return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0;
0
416}-
417-
418/*!-
419 Returns the thickness for drawing lines (underline, overline, etc.)-
420 along with text drawn in this font.-
421 */-
422qreal QRawFont::lineThickness() const-
423{-
424 return d->isValid() ? d->fontEngine->lineThickness().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->lineThickness().toReal() : 0.0;
0
425}-
426-
427/*!-
428 Returns the position from baseline for drawing underlines below the text-
429 rendered with this font.-
430 */-
431qreal QRawFont::underlinePosition() const-
432{-
433 return d->isValid() ? d->fontEngine->underlinePosition().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->underlinePosition().toReal() : 0.0;
0
434}-
435-
436/*!-
437 Returns the family name of this QRawFont.-
438*/-
439QString QRawFont::familyName() const-
440{-
441 return d->isValid() ? d->fontEngine->fontDef.family : QString();
never executed: return d->isValid() ? d->fontEngine->fontDef.family : QString();
0
442}-
443-
444/*!-
445 Returns the style name of this QRawFont.-
446-
447 \sa QFont::styleName()-
448*/-
449QString QRawFont::styleName() const-
450{-
451 return d->isValid() ? d->fontEngine->fontDef.styleName : QString();
never executed: return d->isValid() ? d->fontEngine->fontDef.styleName : QString();
0
452}-
453-
454/*!-
455 Returns the style of this QRawFont.-
456-
457 \sa QFont::style()-
458*/-
459QFont::Style QRawFont::style() const-
460{-
461 return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal;
never executed: return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal;
0
462}-
463-
464/*!-
465 Returns the weight of this QRawFont.-
466-
467 \sa QFont::weight()-
468*/-
469int QRawFont::weight() const-
470{-
471 return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1;
never executed: return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1;
0
472}-
473-
474/*!-
475 Converts the string of unicode points given by \a text to glyph indexes-
476 using the CMAP table in the underlying font, and returns a vector containing-
477 the result.-
478-
479 Note that, in cases where there are other tables in the font that affect the-
480 shaping of the text, the returned glyph indexes will not correctly represent-
481 the rendering of the text. To get the correctly shaped text, you can use-
482 QTextLayout to lay out and shape the text, then call QTextLayout::glyphs()-
483 to get the set of glyph index list and QRawFont pairs.-
484-
485 \sa advancesForGlyphIndexes(), glyphIndexesForChars(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns()-
486*/-
487QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const-
488{-
489 QVector<quint32> glyphIndexes;-
490 if (!d->isValid() || text.isEmpty())
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
491 return glyphIndexes;
never executed: return glyphIndexes;
0
492-
493 int numGlyphs = text.size();-
494 glyphIndexes.resize(numGlyphs);-
495-
496 QGlyphLayout glyphs;-
497 glyphs.numGlyphs = numGlyphs;-
498 glyphs.glyphs = glyphIndexes.data();-
499 if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly))
!d->fontEngine...phIndicesOnly)Description
TRUEnever evaluated
FALSEnever evaluated
0
500 Q_UNREACHABLE();
never executed: end of block
0
501-
502 glyphIndexes.resize(numGlyphs);-
503 return glyphIndexes;
never executed: return glyphIndexes;
0
504}-
505-
506/*!-
507 Converts a string of unicode points to glyph indexes using the CMAP table in the-
508 underlying font. The function works like glyphIndexesForString() except it take-
509 an array (\a chars), the results will be returned though \a glyphIndexes array-
510 and number of glyphs will be set in \a numGlyphs. The size of \a glyphIndexes array-
511 must be at least \a numChars, if that's still not enough, this function will return-
512 false, then you can resize \a glyphIndexes from the size returned in \a numGlyphs.-
513-
514 \sa glyphIndexesForString(), advancesForGlyphIndexes(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns()-
515*/-
516bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const-
517{-
518 Q_ASSERT(numGlyphs);-
519 if (!d->isValid() || numChars <= 0) {
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
numChars <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
520 *numGlyphs = 0;-
521 return false;
never executed: return false;
0
522 }-
523-
524 if (*numGlyphs <= 0 || !glyphIndexes) {
*numGlyphs <= 0Description
TRUEnever evaluated
FALSEnever evaluated
!glyphIndexesDescription
TRUEnever evaluated
FALSEnever evaluated
0
525 *numGlyphs = numChars;-
526 return false;
never executed: return false;
0
527 }-
528-
529 QGlyphLayout glyphs;-
530 glyphs.numGlyphs = *numGlyphs;-
531 glyphs.glyphs = glyphIndexes;-
532 return d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QFontEngine::GlyphIndicesOnly);
never executed: return d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QFontEngine::GlyphIndicesOnly);
0
533}-
534-
535/*!-
536 \fn QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes, LayoutFlags layoutFlags) const-
537 \since 5.1-
538-
539 Returns the QRawFont's advances for each of the \a glyphIndexes in pixel units. The advances-
540 give the distance from the position of a given glyph to where the next glyph should be drawn-
541 to make it appear as if the two glyphs are unspaced. How the advances are calculated is-
542 controlled by \a layoutFlags.-
543-
544 \sa QTextLine::horizontalAdvance(), QFontMetricsF::width()-
545*/-
546-
547/*!-
548 \fn QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes) const-
549-
550 \overload-
551-
552 Returns the QRawFont's advances for each of the \a glyphIndexes in pixel units. The advances-
553 give the distance from the position of a given glyph to where the next glyph should be drawn-
554 to make it appear as if the two glyphs are unspaced. The advance of each glyph is calculated-
555 separately.-
556-
557 \sa QTextLine::horizontalAdvance(), QFontMetricsF::width()-
558*/-
559-
560/*!-
561 \since 5.1-
562-
563 Returns the QRawFont's advances for each of the \a glyphIndexes in pixel units. The advances-
564 give the distance from the position of a given glyph to where the next glyph should be drawn-
565 to make it appear as if the two glyphs are unspaced. The glyph indexes are given with the-
566 array \a glyphIndexes while the results are returned through \a advances, both of them must-
567 have \a numGlyphs elements. How the advances are calculated is controlled by \a layoutFlags.-
568-
569 \sa QTextLine::horizontalAdvance(), QFontMetricsF::width()-
570*/-
571bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs, LayoutFlags layoutFlags) const-
572{-
573 Q_ASSERT(glyphIndexes && advances);-
574 if (!d->isValid() || numGlyphs <= 0)
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
numGlyphs <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
575 return false;
never executed: return false;
0
576-
577 QVarLengthArray<QFixed> tmpAdvances(numGlyphs);-
578-
579 QGlyphLayout glyphs;-
580 glyphs.glyphs = const_cast<glyph_t *>(glyphIndexes);-
581 glyphs.numGlyphs = numGlyphs;-
582 glyphs.advances = tmpAdvances.data();-
583-
584 bool design = layoutFlags & UseDesignMetrics;-
585-
586 d->fontEngine->recalcAdvances(&glyphs, design ? QFontEngine::DesignMetrics : QFontEngine::ShaperFlag(0));-
587 if (layoutFlags & KernedAdvances)
layoutFlags & KernedAdvancesDescription
TRUEnever evaluated
FALSEnever evaluated
0
588 d->fontEngine->doKerning(&glyphs, design ? QFontEngine::DesignMetrics : QFontEngine::ShaperFlag(0));
never executed: d->fontEngine->doKerning(&glyphs, design ? QFontEngine::DesignMetrics : QFontEngine::ShaperFlag(0));
0
589-
590 for (int i=0; i<numGlyphs; ++i)
i<numGlyphsDescription
TRUEnever evaluated
FALSEnever evaluated
0
591 advances[i] = QPointF(tmpAdvances[i].toReal(), 0.0);
never executed: advances[i] = QPointF(tmpAdvances[i].toReal(), 0.0);
0
592-
593 return true;
never executed: return true;
0
594}-
595-
596/*!-
597 \overload-
598-
599 Returns the QRawFont's advances for each of the \a glyphIndexes in pixel units. The advances-
600 give the distance from the position of a given glyph to where the next glyph should be drawn-
601 to make it appear as if the two glyphs are unspaced. The glyph indexes are given with the-
602 array \a glyphIndexes while the results are returned through \a advances, both of them must-
603 have \a numGlyphs elements. The advance of each glyph is calculated separately-
604-
605 \sa QTextLine::horizontalAdvance(), QFontMetricsF::width()-
606*/-
607bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const-
608{-
609 return QRawFont::advancesForGlyphIndexes(glyphIndexes, advances, numGlyphs, SeparateAdvances);
never executed: return QRawFont::advancesForGlyphIndexes(glyphIndexes, advances, numGlyphs, SeparateAdvances);
0
610}-
611-
612/*!-
613 Returns the hinting preference used to construct this QRawFont.-
614-
615 \sa QFont::hintingPreference()-
616*/-
617QFont::HintingPreference QRawFont::hintingPreference() const-
618{-
619 return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting;
never executed: return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting;
0
620}-
621-
622/*!-
623 Retrieves the sfnt table named \a tagName from the underlying physical font, or an empty-
624 byte array if no such table was found. The returned font table's byte order is Big Endian, like-
625 the sfnt format specifies. The \a tagName must be four characters long and should be formatted-
626 in the default endianness of the current platform.-
627*/-
628QByteArray QRawFont::fontTable(const char *tagName) const-
629{-
630 if (!d->isValid())
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
631 return QByteArray();
never executed: return QByteArray();
0
632-
633 return d->fontEngine->getSfntTable(MAKE_TAG(tagName[0], tagName[1], tagName[2], tagName[3]));
never executed: return d->fontEngine->getSfntTable(( (((quint32)(tagName[0])) << 24) | (((quint32)(tagName[1])) << 16) | (((quint32)(tagName[2])) << 8) | ((quint32)(tagName[3])) ));
0
634}-
635-
636/*!-
637 Returns a list of writing systems supported by the font according to designer supplied-
638 information in the font file. Please note that this does not guarantee support for a-
639 specific unicode point in the font. You can use the supportsCharacter() to check support-
640 for a single, specific character.-
641-
642 \note The list is determined based on the unicode ranges and codepage ranges set in the font's-
643 OS/2 table and requires such a table to be present in the underlying font file.-
644-
645 \sa supportsCharacter()-
646*/-
647QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const-
648{-
649 QList<QFontDatabase::WritingSystem> writingSystems;-
650 if (d->isValid()) {
d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
651 QByteArray os2Table = fontTable("OS/2");-
652 if (os2Table.size() > 86) {
os2Table.size() > 86Description
TRUEnever evaluated
FALSEnever evaluated
0
653 const uchar * const data = reinterpret_cast<const uchar *>(os2Table.constData());-
654 const uchar * const bigEndianUnicodeRanges = data + 42;-
655 const uchar * const bigEndianCodepageRanges = data + 78;-
656-
657 quint32 unicodeRanges[4];-
658 quint32 codepageRanges[2];-
659-
660 for (size_t i = 0; i < sizeof unicodeRanges / sizeof *unicodeRanges; ++i)
i < sizeof uni...*unicodeRangesDescription
TRUEnever evaluated
FALSEnever evaluated
0
661 unicodeRanges[i] = qFromBigEndian<quint32>(bigEndianUnicodeRanges + i * sizeof(quint32));
never executed: unicodeRanges[i] = qFromBigEndian<quint32>(bigEndianUnicodeRanges + i * sizeof(quint32));
0
662-
663 for (size_t i = 0; i < sizeof codepageRanges / sizeof *codepageRanges; ++i)
i < sizeof cod...codepageRangesDescription
TRUEnever evaluated
FALSEnever evaluated
0
664 codepageRanges[i] = qFromBigEndian<quint32>(bigEndianCodepageRanges + i * sizeof(quint32));
never executed: codepageRanges[i] = qFromBigEndian<quint32>(bigEndianCodepageRanges + i * sizeof(quint32));
0
665-
666 QSupportedWritingSystems ws = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRanges, codepageRanges);-
667 for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
i < QFontDatab...ngSystemsCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
668 if (ws.supported(QFontDatabase::WritingSystem(i)))
ws.supported(Q...tingSystem(i))Description
TRUEnever evaluated
FALSEnever evaluated
0
669 writingSystems.append(QFontDatabase::WritingSystem(i));
never executed: writingSystems.append(QFontDatabase::WritingSystem(i));
0
670 }
never executed: end of block
0
671 }
never executed: end of block
0
672 }
never executed: end of block
0
673-
674 return writingSystems;
never executed: return writingSystems;
0
675}-
676-
677/*!-
678 Returns \c true if the font has a glyph that corresponds to the given \a character.-
679-
680 \sa supportedWritingSystems()-
681*/-
682bool QRawFont::supportsCharacter(QChar character) const-
683{-
684 return supportsCharacter(character.unicode());
never executed: return supportsCharacter(character.unicode());
0
685}-
686-
687/*!-
688 \overload-
689-
690 Returns \c true if the font has a glyph that corresponds to the UCS-4 encoded character \a ucs4.-
691-
692 \sa supportedWritingSystems()-
693*/-
694bool QRawFont::supportsCharacter(uint ucs4) const-
695{-
696 return d->isValid() && d->fontEngine->canRender(ucs4);
never executed: return d->isValid() && d->fontEngine->canRender(ucs4);
0
697}-
698-
699// qfontdatabase.cpp-
700extern int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem);-
701-
702/*!-
703 Fetches the physical representation based on a \a font query. The physical font returned is-
704 the font that will be preferred by Qt in order to display text in the selected \a writingSystem.-
705-
706 \warning This function is potentially expensive and should not be called in performance-
707 sensitive code.-
708*/-
709QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writingSystem)-
710{-
711 QRawFont rawFont;-
712 const QFontPrivate *font_d = QFontPrivate::get(font);-
713 int script = qt_script_for_writing_system(writingSystem);-
714 QFontEngine *fe = font_d->engineForScript(script);-
715-
716 if (fe != 0 && fe->type() == QFontEngine::Multi) {
fe != 0Description
TRUEnever evaluated
FALSEnever evaluated
fe->type() == ...tEngine::MultiDescription
TRUEnever evaluated
FALSEnever evaluated
0
717 QFontEngineMulti *multiEngine = static_cast<QFontEngineMulti *>(fe);-
718 fe = multiEngine->engine(0);-
719-
720 if (script > QChar::Script_Latin) {
script > QChar::Script_LatinDescription
TRUEnever evaluated
FALSEnever evaluated
0
721 // keep in sync with QFontEngineMulti::loadEngine()-
722 QFontDef request(multiEngine->fontDef);-
723 request.styleStrategy |= QFont::NoFontMerging;-
724-
725 if (QFontEngine *engine = QFontDatabase::findFont(request, script)) {
QFontEngine *e...quest, script)Description
TRUEnever evaluated
FALSEnever evaluated
0
726 if (request.weight > QFont::Normal)
request.weight > QFont::NormalDescription
TRUEnever evaluated
FALSEnever evaluated
0
727 engine->fontDef.weight = request.weight;
never executed: engine->fontDef.weight = request.weight;
0
728 if (request.style > QFont::StyleNormal)
request.style ...t::StyleNormalDescription
TRUEnever evaluated
FALSEnever evaluated
0
729 engine->fontDef.style = request.style;
never executed: engine->fontDef.style = request.style;
0
730 fe = engine;-
731 }
never executed: end of block
0
732 }
never executed: end of block
0
733 Q_ASSERT(fe);-
734 }
never executed: end of block
0
735-
736 if (fe != 0) {
fe != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
737 rawFont.d.data()->setFontEngine(fe);-
738 rawFont.d.data()->hintingPreference = font.hintingPreference();-
739 }
never executed: end of block
0
740 return rawFont;
never executed: return rawFont;
0
741}-
742-
743/*!-
744 Sets the pixel size with which this font should be rendered to \a pixelSize.-
745*/-
746void QRawFont::setPixelSize(qreal pixelSize)-
747{-
748 if (!d->isValid() || qFuzzyCompare(d->fontEngine->fontDef.pixelSize, pixelSize))
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
qFuzzyCompare(...ze, pixelSize)Description
TRUEnever evaluated
FALSEnever evaluated
0
749 return;
never executed: return;
0
750-
751 d.detach();-
752 d->setFontEngine(d->fontEngine->cloneWithSize(pixelSize));-
753}
never executed: end of block
0
754-
755/*!-
756 \internal-
757*/-
758void QRawFontPrivate::loadFromData(const QByteArray &fontData, qreal pixelSize,-
759 QFont::HintingPreference hintingPreference)-
760{-
761 Q_ASSERT(fontEngine == 0);-
762-
763 QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase();-
764 setFontEngine(pfdb->fontEngine(fontData, pixelSize, hintingPreference));-
765}
never executed: end of block
0
766-
767/*!-
768 Returns the smallest rectangle containing the glyph with the given \a glyphIndex.-
769-
770 \since 5.0-
771*/-
772QRectF QRawFont::boundingRect(quint32 glyphIndex) const-
773{-
774 if (!d->isValid())
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
775 return QRectF();
never executed: return QRectF();
0
776-
777 glyph_metrics_t gm = d->fontEngine->boundingBox(glyphIndex);-
778 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
779}-
780-
781#endif // QT_NO_RAWFONT-
782-
783QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9