qrawfont.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qrawfont.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8QRawFont::QRawFont()-
9 : d(new QRawFontPrivate)-
10{-
11}
never executed: end of block
0
12QRawFont::QRawFont(const QString &fileName,-
13 qreal pixelSize,-
14 QFont::HintingPreference hintingPreference)-
15 : d(new QRawFontPrivate)-
16{-
17 loadFromFile(fileName, pixelSize, hintingPreference);-
18}
never executed: end of block
0
19QRawFont::QRawFont(const QByteArray &fontData,-
20 qreal pixelSize,-
21 QFont::HintingPreference hintingPreference)-
22 : d(new QRawFontPrivate)-
23{-
24 loadFromData(fontData, pixelSize, hintingPreference);-
25}
never executed: end of block
0
26-
27-
28-
29-
30QRawFont::QRawFont(const QRawFont &other)-
31{-
32 d = other.d;-
33}
never executed: end of block
0
34-
35-
36-
37-
38QRawFont::~QRawFont()-
39{-
40}-
41-
42-
43-
44-
45QRawFont &QRawFont::operator=(const QRawFont &other)-
46{-
47 d = other.d;-
48 return
never executed: return *this;
*this;
never executed: return *this;
0
49}-
50bool QRawFont::isValid() const-
51{-
52 return
never executed: return d->isValid();
d->isValid();
never executed: return d->isValid();
0
53}-
54void QRawFont::loadFromFile(const QString &fileName,-
55 qreal pixelSize,-
56 QFont::HintingPreference hintingPreference)-
57{-
58 QFile file(fileName);-
59 if (file.open(QIODevice::ReadOnly)
file.open(QIODevice::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
60 loadFromData(file.readAll(), pixelSize, hintingPreference);
never executed: loadFromData(file.readAll(), pixelSize, hintingPreference);
0
61}
never executed: end of block
0
62void QRawFont::loadFromData(const QByteArray &fontData,-
63 qreal pixelSize,-
64 QFont::HintingPreference hintingPreference)-
65{-
66 d.detach();-
67 d->cleanUp();-
68 d->hintingPreference = hintingPreference;-
69 d->loadFromData(fontData, pixelSize, hintingPreference);-
70}
never executed: end of block
0
71QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType,-
72 const QTransform &transform) const-
73{-
74 if (!d->isValid()
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
75 return
never executed: return QImage();
QImage();
never executed: return QImage();
0
76-
77 if (antialiasingType == SubPixelAntialiasing
antialiasingTy...elAntialiasingDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
78 return
never executed: return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), transform);
d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), transform);
never executed: return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), transform);
0
79-
80 return
never executed: return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
never executed: return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
0
81}-
82QPainterPath QRawFont::pathForGlyph(quint32 glyphIndex) const-
83{-
84 if (!d->isValid()
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
85 return
never executed: return QPainterPath();
QPainterPath();
never executed: return QPainterPath();
0
86-
87 QFixedPoint position;-
88 QPainterPath path;-
89 d->fontEngine->addGlyphsToPath(&glyphIndex, &position, 1, &path, 0);-
90 return
never executed: return path;
path;
never executed: return path;
0
91}-
92-
93-
94-
95-
96bool QRawFont::operator==(const QRawFont &other) const-
97{-
98 return
never executed: return d->fontEngine == other.d->fontEngine;
d->fontEngine == other.d->fontEngine;
never executed: return d->fontEngine == other.d->fontEngine;
0
99}-
100qreal QRawFont::ascent() const-
101{-
102 return
never executed: return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0;
d->isValid() ? d->fontEngine->ascent().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0;
0
103}-
104qreal QRawFont::descent() const-
105{-
106 return
never executed: return d->isValid() ? d->fontEngine->descent().toReal() : 0.0;
d->isValid() ? d->fontEngine->descent().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->descent().toReal() : 0.0;
0
107}-
108qreal QRawFont::xHeight() const-
109{-
110 return
never executed: return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0;
d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0;
0
111}-
112qreal QRawFont::leading() const-
113{-
114 return
never executed: return d->isValid() ? d->fontEngine->leading().toReal() : 0.0;
d->isValid() ? d->fontEngine->leading().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->leading().toReal() : 0.0;
0
115}-
116-
117-
118-
119-
120-
121-
122qreal QRawFont::averageCharWidth() const-
123{-
124 return
never executed: return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0;
d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0;
0
125}-
126-
127-
128-
129-
130-
131-
132qreal QRawFont::maxCharWidth() const-
133{-
134 return
never executed: return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0;
d->isValid() ? d->fontEngine->maxCharWidth() : 0.0;
never executed: return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0;
0
135}-
136qreal QRawFont::pixelSize() const-
137{-
138 return
never executed: return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0;
d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0;
never executed: return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0;
0
139}-
140qreal QRawFont::unitsPerEm() const-
141{-
142 return
never executed: return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0;
d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0;
0
143}-
144-
145-
146-
147-
148-
149qreal QRawFont::lineThickness() const-
150{-
151 return
never executed: return d->isValid() ? d->fontEngine->lineThickness().toReal() : 0.0;
d->isValid() ? d->fontEngine->lineThickness().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->lineThickness().toReal() : 0.0;
0
152}-
153-
154-
155-
156-
157-
158qreal QRawFont::underlinePosition() const-
159{-
160 return
never executed: return d->isValid() ? d->fontEngine->underlinePosition().toReal() : 0.0;
d->isValid() ? d->fontEngine->underlinePosition().toReal() : 0.0;
never executed: return d->isValid() ? d->fontEngine->underlinePosition().toReal() : 0.0;
0
161}-
162-
163-
164-
165-
166QString QRawFont::familyName() const-
167{-
168 return
never executed: return d->isValid() ? d->fontEngine->fontDef.family : QString();
d->isValid() ? d->fontEngine->fontDef.family : QString();
never executed: return d->isValid() ? d->fontEngine->fontDef.family : QString();
0
169}-
170-
171-
172-
173-
174-
175-
176QString QRawFont::styleName() const-
177{-
178 return
never executed: return d->isValid() ? d->fontEngine->fontDef.styleName : QString();
d->isValid() ? d->fontEngine->fontDef.styleName : QString();
never executed: return d->isValid() ? d->fontEngine->fontDef.styleName : QString();
0
179}-
180-
181-
182-
183-
184-
185-
186QFont::Style QRawFont::style() const-
187{-
188 return
never executed: return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal;
d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal;
never executed: return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal;
0
189}-
190-
191-
192-
193-
194-
195-
196int QRawFont::weight() const-
197{-
198 return
never executed: return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1;
d->isValid() ? int(d->fontEngine->fontDef.weight) : -1;
never executed: return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1;
0
199}-
200QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const-
201{-
202 QVector<quint32> glyphIndexes;-
203 if (!d->isValid()
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
|| text.isEmpty()
text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
204 return
never executed: return glyphIndexes;
glyphIndexes;
never executed: return glyphIndexes;
0
205-
206 int numGlyphs = text.size();-
207 glyphIndexes.resize(numGlyphs);-
208-
209 QGlyphLayout glyphs;-
210 glyphs.numGlyphs = numGlyphs;-
211 glyphs.glyphs = glyphIndexes.data();-
212 if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly)
!d->fontEngine...phIndicesOnly)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
213 do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,500) : qt_noop()); __builtin_unreachable(); }
never executed: end of block
while (0);
0
214-
215 glyphIndexes.resize(numGlyphs);-
216 return
never executed: return glyphIndexes;
glyphIndexes;
never executed: return glyphIndexes;
0
217}-
218bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const-
219{-
220 ((!(numGlyphs)) ? qt_assert("numGlyphs",__FILE__,518) : qt_noop());-
221 if (!d->isValid()
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
|| numChars <= 0
numChars <= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
222 *numGlyphs = 0;-
223 return
never executed: return false;
false;
never executed: return false;
0
224 }-
225-
226 if (*
*numGlyphs <= 0Description
TRUEnever evaluated
FALSEnever evaluated
numGlyphs <= 0
*numGlyphs <= 0Description
TRUEnever evaluated
FALSEnever evaluated
|| !glyphIndexes
!glyphIndexesDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
227 *numGlyphs = numChars;-
228 return
never executed: return false;
false;
never executed: return false;
0
229 }-
230-
231 QGlyphLayout glyphs;-
232 glyphs.numGlyphs = *numGlyphs;-
233 glyphs.glyphs = glyphIndexes;-
234 return
never executed: return d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QFontEngine::GlyphIndicesOnly);
d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QFontEngine::GlyphIndicesOnly);
never executed: return d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QFontEngine::GlyphIndicesOnly);
0
235}-
236bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs, LayoutFlags layoutFlags) const-
237{-
238 ((!(glyphIndexes && advances)) ? qt_assert("glyphIndexes && advances",__FILE__,573) : qt_noop());-
239 if (!d->isValid()
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
|| numGlyphs <= 0
numGlyphs <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
240 return
never executed: return false;
false;
never executed: return false;
0
241-
242 QVarLengthArray<QFixed> tmpAdvances(numGlyphs);-
243-
244 QGlyphLayout glyphs;-
245 glyphs.glyphs = const_cast<glyph_t *>(glyphIndexes);-
246 glyphs.numGlyphs = numGlyphs;-
247 glyphs.advances = tmpAdvances.data();-
248-
249 bool design = layoutFlags & UseDesignMetrics;-
250-
251 d->fontEngine->recalcAdvances(&glyphs, design ? QFontEngine::DesignMetrics : QFontEngine::ShaperFlag(0));-
252 if (layoutFlags & KernedAdvances
layoutFlags & KernedAdvancesDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
253 d->fontEngine->doKerning(&glyphs, design ? QFontEngine::DesignMetrics : QFontEngine::ShaperFlag(0));
never executed: d->fontEngine->doKerning(&glyphs, design ? QFontEngine::DesignMetrics : QFontEngine::ShaperFlag(0));
0
254-
255 for (int i=0; i<numGlyphs
i<numGlyphsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
256 advances[i] = QPointF(tmpAdvances[i].toReal(), 0.0);
never executed: advances[i] = QPointF(tmpAdvances[i].toReal(), 0.0);
0
257-
258 return
never executed: return true;
true;
never executed: return true;
0
259}-
260bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const-
261{-
262 return
never executed: return QRawFont::advancesForGlyphIndexes(glyphIndexes, advances, numGlyphs, SeparateAdvances);
QRawFont::advancesForGlyphIndexes(glyphIndexes, advances, numGlyphs, SeparateAdvances);
never executed: return QRawFont::advancesForGlyphIndexes(glyphIndexes, advances, numGlyphs, SeparateAdvances);
0
263}-
264-
265-
266-
267-
268-
269-
270QFont::HintingPreference QRawFont::hintingPreference() const-
271{-
272 return
never executed: return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting;
d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting;
never executed: return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting;
0
273}-
274-
275-
276-
277-
278-
279-
280-
281QByteArray QRawFont::fontTable(const char *tagName) const-
282{-
283 if (!d->isValid()
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
284 return
never executed: return QByteArray();
QByteArray();
never executed: return QByteArray();
0
285-
286 return
never executed: return d->fontEngine->getSfntTable(( (((quint32)(tagName[0])) << 24) | (((quint32)(tagName[1])) << 16) | (((quint32)(tagName[2])) << 8) | ((quint32)(tagName[3])) ));
d->fontEngine->getSfntTable(( (((quint32)(tagName[0])) << 24) | (((quint32)(tagName[1])) << 16) | (((quint32)(tagName[2])) << 8) | ((quint32)(tagName[3])) ));
never executed: return d->fontEngine->getSfntTable(( (((quint32)(tagName[0])) << 24) | (((quint32)(tagName[1])) << 16) | (((quint32)(tagName[2])) << 8) | ((quint32)(tagName[3])) ));
0
287}-
288QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const-
289{-
290 QList<QFontDatabase::WritingSystem> writingSystems;-
291 if (d->isValid()
d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
292 QByteArray os2Table = fontTable("OS/2");-
293 if (os2Table.size() > 86
os2Table.size() > 86Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
294 const uchar * const data = reinterpret_cast<const uchar *>(os2Table.constData());-
295 const uchar * const bigEndianUnicodeRanges = data + 42;-
296 const uchar * const bigEndianCodepageRanges = data + 78;-
297-
298 quint32 unicodeRanges[4];-
299 quint32 codepageRanges[2];-
300-
301 for (size_t i = 0; i < sizeof unicodeRanges / sizeof *unicodeRanges
i < sizeof uni...*unicodeRangesDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
302 unicodeRanges[i] = qFromBigEndian<quint32>(bigEndianUnicodeRanges + i * sizeof(quint32));
never executed: unicodeRanges[i] = qFromBigEndian<quint32>(bigEndianUnicodeRanges + i * sizeof(quint32));
0
303-
304 for (size_t i = 0; i < sizeof codepageRanges / sizeof *codepageRanges
i < sizeof cod...codepageRangesDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
305 codepageRanges[i] = qFromBigEndian<quint32>(bigEndianCodepageRanges + i * sizeof(quint32));
never executed: codepageRanges[i] = qFromBigEndian<quint32>(bigEndianCodepageRanges + i * sizeof(quint32));
0
306-
307 QSupportedWritingSystems ws = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRanges, codepageRanges);-
308 for (int i = 0; i < QFontDatabase::WritingSystemsCount
i < QFontDatab...ngSystemsCountDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
309 if (ws.supported(QFontDatabase::WritingSystem(i))
ws.supported(Q...tingSystem(i))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
310 writingSystems.append(QFontDatabase::WritingSystem(i));
never executed: writingSystems.append(QFontDatabase::WritingSystem(i));
0
311 }
never executed: end of block
0
312 }
never executed: end of block
0
313 }
never executed: end of block
0
314-
315 return
never executed: return writingSystems;
writingSystems;
never executed: return writingSystems;
0
316}-
317-
318-
319-
320-
321-
322-
323bool QRawFont::supportsCharacter(QChar character) const-
324{-
325 return
never executed: return supportsCharacter(character.unicode());
supportsCharacter(character.unicode());
never executed: return supportsCharacter(character.unicode());
0
326}-
327bool QRawFont::supportsCharacter(uint ucs4) const-
328{-
329 return
never executed: return d->isValid() && d->fontEngine->canRender(ucs4);
d->isValid() && d->fontEngine->canRender(ucs4);
never executed: return d->isValid() && d->fontEngine->canRender(ucs4);
0
330}-
331-
332-
333extern int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem);-
334QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writingSystem)-
335{-
336 QRawFont rawFont;-
337 const QFontPrivate *font_d = QFontPrivate::get(font);-
338 int script = qt_script_for_writing_system(writingSystem);-
339 QFontEngine *fe = font_d->engineForScript(script);-
340-
341 if (fe != 0
fe != 0Description
TRUEnever evaluated
FALSEnever evaluated
&& fe->type() == QFontEngine::Multi
fe->type() == ...tEngine::MultiDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
342 QFontEngineMulti *multiEngine = static_cast<QFontEngineMulti *>(fe);-
343 fe = multiEngine->engine(0);-
344-
345 if (script > QChar::Script_Latin
script > QChar::Script_LatinDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
346-
347 QFontDef request(multiEngine->fontDef);-
348 request.styleStrategy |= QFont::NoFontMerging;-
349-
350 if (QFontEngine *engine = QFontDatabase::findFont(request, script)
QFontEngine *e...quest, script)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
351 if (request.weight > QFont::Normal
request.weight > QFont::NormalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
352 engine->fontDef.weight = request.weight;
never executed: engine->fontDef.weight = request.weight;
0
353 if (request.style > QFont::StyleNormal
request.style ...t::StyleNormalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
354 engine->fontDef.style = request.style;
never executed: engine->fontDef.style = request.style;
0
355 fe = engine;-
356 }
never executed: end of block
0
357 }
never executed: end of block
0
358 ((!(fe)) ? qt_assert("fe",__FILE__,733) : qt_noop());-
359 }
never executed: end of block
0
360-
361 if (fe != 0
fe != 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
362 rawFont.d.data()->setFontEngine(fe);-
363 rawFont.d.data()->hintingPreference = font.hintingPreference();-
364 }
never executed: end of block
0
365 return
never executed: return rawFont;
rawFont;
never executed: return rawFont;
0
366}-
367-
368-
369-
370-
371void QRawFont::setPixelSize(qreal pixelSize)-
372{-
373 if (!d->isValid()
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
|| qFuzzyCompare(d->fontEngine->fontDef.pixelSize, pixelSize)
qFuzzyCompare(...ze, pixelSize)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
374 return;
never executed: return;
0
375-
376 d.detach();-
377 d->setFontEngine(d->fontEngine->cloneWithSize(pixelSize));-
378}
never executed: end of block
0
379-
380-
381-
382-
383void QRawFontPrivate::loadFromData(const QByteArray &fontData, qreal pixelSize,-
384 QFont::HintingPreference hintingPreference)-
385{-
386 ((!(fontEngine == 0)) ? qt_assert("fontEngine == 0",__FILE__,761) : qt_noop());-
387-
388 QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase();-
389 setFontEngine(pfdb->fontEngine(fontData, pixelSize, hintingPreference));-
390}
never executed: end of block
0
391-
392-
393-
394-
395-
396-
397QRectF QRawFont::boundingRect(quint32 glyphIndex) const-
398{-
399 if (!d->isValid()
!d->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
400 return
never executed: return QRectF();
QRectF();
never executed: return QRectF();
0
401-
402 glyph_metrics_t gm = d->fontEngine->boundingBox(glyphIndex);-
403 return
never executed: return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());
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
404}-
405-
406-
407-
408-
Switch to Source codePreprocessed file

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