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