void SimpleFontData::platformCharWidthInit() { if (!m_platformData.size()) return; QRawFont rawFont(m_platformData.rawFont()); m_avgCharWidth = rawFont.averageCharWidth(); m_maxCharWidth = rawFont.maxCharWidth(); }
void tst_QRawFont::copyConstructor() { QFETCH(QFont::HintingPreference, hintingPreference); { QString rawFontFamilyName; qreal rawFontPixelSize; qreal rawFontAscent; qreal rawFontDescent; int rawFontTableSize; QRawFont outerRawFont; { QRawFont rawFont(QString::fromLatin1(SRCDIR "testfont.ttf"), 11, hintingPreference); QVERIFY(rawFont.isValid()); rawFontFamilyName = rawFont.familyName(); rawFontPixelSize = rawFont.pixelSize(); rawFontAscent = rawFont.ascent(); rawFontDescent = rawFont.descent(); rawFontTableSize = rawFont.fontTable("glyf").size(); QVERIFY(rawFontTableSize > 0); { QRawFont otherRawFont(rawFont); QVERIFY(otherRawFont.isValid()); QCOMPARE(otherRawFont.pixelSize(), rawFontPixelSize); QCOMPARE(otherRawFont.familyName(), rawFontFamilyName); QCOMPARE(otherRawFont.hintingPreference(), hintingPreference); QCOMPARE(otherRawFont.ascent(), rawFontAscent); QCOMPARE(otherRawFont.descent(), rawFontDescent); QCOMPARE(otherRawFont.fontTable("glyf").size(), rawFontTableSize); } { QRawFont otherRawFont = rawFont; QVERIFY(otherRawFont.isValid()); QCOMPARE(otherRawFont.pixelSize(), rawFontPixelSize); QCOMPARE(otherRawFont.familyName(), rawFontFamilyName); QCOMPARE(otherRawFont.hintingPreference(), hintingPreference); QCOMPARE(otherRawFont.ascent(), rawFontAscent); QCOMPARE(otherRawFont.descent(), rawFontDescent); QCOMPARE(otherRawFont.fontTable("glyf").size(), rawFontTableSize); } outerRawFont = rawFont; } QVERIFY(outerRawFont.isValid()); QCOMPARE(outerRawFont.pixelSize(), rawFontPixelSize); QCOMPARE(outerRawFont.familyName(), rawFontFamilyName); QCOMPARE(outerRawFont.hintingPreference(), hintingPreference); QCOMPARE(outerRawFont.ascent(), rawFontAscent); QCOMPARE(outerRawFont.descent(), rawFontDescent); QCOMPARE(outerRawFont.fontTable("glyf").size(), rawFontTableSize); } }
bool SimpleFontData::containsCharacters(const UChar* characters, int length) const { QRawFont rawFont(m_platformData.rawFont()); for (int i = 0; i < length; ++i) { if (!rawFont.supportsCharacter(static_cast<QChar>(characters[i]))) return false; } return true; }
void SimpleFontData::platformInit() { if (!m_platformData.size()) { m_fontMetrics.reset(); m_avgCharWidth = 0; m_maxCharWidth = 0; return; } #if HAVE(QRAWFONT) QRawFont rawFont(m_platformData.rawFont()); float descent = rawFont.descent(); float ascent = rawFont.ascent(); float xHeight = rawFont.xHeight(); float lineSpacing = ascent + descent + rawFont.leading(); QVector<quint32> indexes = rawFont.glyphIndexesForString(QLatin1String(" ")); QVector<QPointF> advances = rawFont.advancesForGlyphIndexes(indexes); float spaceWidth = advances.at(0).x(); #else QFontMetricsF fm(m_platformData.font()); float descent = fm.descent(); float ascent = fm.ascent(); float xHeight = fm.xHeight(); float lineSpacing = fm.lineSpacing(); float spaceWidth = fm.width(QLatin1Char(' ')); #endif #if !HAVE(QT5) // Qt subtracts 1 from the descent to account for the baseline, // we add it back here to get correct metrics for WebKit. descent += 1; #endif // The line spacing should always be >= (ascent + descent), but this // may be false in some cases due to misbehaving platform libraries. // Workaround from SimpleFontPango.cpp and SimpleFontFreeType.cpp if (lineSpacing < ascent + descent) lineSpacing = ascent + descent; // QFontMetricsF::leading() may return negative values on platforms // such as FreeType. Calculate the line gap manually instead. float lineGap = lineSpacing - ascent - descent; m_fontMetrics.setAscent(ascent); // WebKit expects the descent to be positive. m_fontMetrics.setDescent(qAbs(descent)); m_fontMetrics.setLineSpacing(lineSpacing); m_fontMetrics.setXHeight(xHeight); m_fontMetrics.setLineGap(lineGap); m_spaceWidth = spaceWidth; }
void SimpleFontData::platformCharWidthInit() { if (!m_platformData.size()) return; #if HAVE(QRAWFONT) QRawFont rawFont(m_platformData.rawFont()); m_avgCharWidth = rawFont.averageCharWidth(); m_maxCharWidth = rawFont.maxCharWidth(); #else QFontMetricsF fm(m_platformData.font()); m_avgCharWidth = fm.averageCharWidth(); m_maxCharWidth = fm.maxWidth(); #endif }