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

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