TextJustificationForced = 0x10000,
TextForceLeftToRight = 0x20000,
TextForceRightToLeft = 0x40000,
- TextLongestVariant = 0x80000,
- TextBypassShaping = 0x100000
+ TextLongestVariant = 0x80000
};
enum TextElideMode {
\omitvalue TextLongestVariant Ensures that the longest variant is always used
when computing the size of a multi-variant string. (Internal)
- \omitvalue TextBypassShaping
\omitvalue TextForceLeftToRight
\omitvalue TextForceRightToLeft
if (!d->engine || str.isEmpty() || pen().style() == Qt::NoPen)
return;
- if (tf & Qt::TextBypassShaping) {
- // Skip harfbuzz complex shaping, shape using glyph advances only
- int len = str.length();
- int numGlyphs = len;
- QVarLengthGlyphLayoutArray glyphs(len);
- QFontEngine *fontEngine = d->state->font.d->engineForScript(QUnicodeTables::Common);
- if (!fontEngine->stringToCMap(str.data(), len, &glyphs, &numGlyphs, 0)) {
- glyphs.resize(numGlyphs);
- if (!fontEngine->stringToCMap(str.data(), len, &glyphs, &numGlyphs, 0))
- Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice");
- }
-
- QTextItemInt gf(glyphs, &d->state->font, str.data(), len, fontEngine);
- drawTextItem(p, gf);
- return;
- }
-
QStackTextEngine engine(str, d->state->font);
engine.option.setTextDirection(d->state->layoutDirection);
if (tf & (Qt::TextForceLeftToRight|Qt::TextForceRightToLeft)) {
if (len == 0)
return 0;
- if (flags & Qt::TextBypassShaping) {
- // Skip harfbuzz complex shaping, only use advances
- int numGlyphs = len;
- QVarLengthGlyphLayoutArray glyphs(numGlyphs);
- QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
- if (!engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0)) {
- glyphs.resize(numGlyphs);
- if (!engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0))
- Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice");
- }
-
- QFixed width;
- for (int i = 0; i < numGlyphs; ++i)
- width += glyphs.advances_x[i];
- return qRound(width);
- }
-
QStackTextEngine layout(text, d.data());
layout.ignoreBidi = true;
return qRound(layout.width(0, len));
void elidedText();
void veryNarrowElidedText();
void averageCharWidth();
- void bypassShaping();
void elidedMultiLength();
void elidedMultiLengthF();
void inFontUcs4();
QVERIFY(fmf.averageCharWidth() != 0);
}
-void tst_QFontMetrics::bypassShaping()
-{
- QFont f;
- f.setStyleStrategy(QFont::ForceIntegerMetrics);
- QFontMetrics fm(f);
- QString text = " A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z";
- int textWidth = fm.width(text, -1, Qt::TextBypassShaping);
- QVERIFY(textWidth != 0);
- int charsWidth = 0;
- for (int i = 0; i < text.size(); ++i)
- charsWidth += fm.width(text[i]);
- // This assertion is needed in QtWebKit's WebCore::Font::offsetForPositionForSimpleText
- QCOMPARE(textWidth, charsWidth);
-}
-
template<class FontMetrics> void elidedMultiLength_helper()
{
QString text1 = QString::fromLatin1("Long Text 1\x9cShorter\x9csmall");