summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontmetrics.cpp
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@nokia.com>2010-05-25 18:19:14 (GMT)
committerJocelyn Turcotte <jocelyn.turcotte@nokia.com>2010-05-31 16:23:05 (GMT)
commit032fb3d54eaaa1fa36ec45b37f5f7356b1137830 (patch)
tree127dc0c3555003432aaa8add2b73385b24c74c4d /src/gui/text/qfontmetrics.cpp
parent33fddc2adf95b56d8309ef9bc11408252140a085 (diff)
downloadQt-032fb3d54eaaa1fa36ec45b37f5f7356b1137830.zip
Qt-032fb3d54eaaa1fa36ec45b37f5f7356b1137830.tar.gz
Qt-032fb3d54eaaa1fa36ec45b37f5f7356b1137830.tar.bz2
Add the Qt::TextBypassShaping flag.
This allows quick layouting especially with Windows fonts which contain heavy OpenType logic. On regular latin text the visual compromize is the loss of kerning, justification, capitalization, word spacing and letter spacing support. Reviewed-by: Simon Hausmann Reviewed-by: Eskil
Diffstat (limited to 'src/gui/text/qfontmetrics.cpp')
-rw-r--r--src/gui/text/qfontmetrics.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp
index 5163c94..d02e841 100644
--- a/src/gui/text/qfontmetrics.cpp
+++ b/src/gui/text/qfontmetrics.cpp
@@ -526,6 +526,14 @@ int QFontMetrics::rightBearing(QChar ch) const
*/
int QFontMetrics::width(const QString &text, int len) const
{
+ return width(text, len, 0);
+}
+
+/*!
+ \internal
+*/
+int QFontMetrics::width(const QString &text, int len, int flags) const
+{
int pos = text.indexOf(QLatin1Char('\x9c'));
if (pos != -1) {
len = (len < 0) ? pos : qMin(pos, len);
@@ -535,6 +543,23 @@ int QFontMetrics::width(const QString &text, int len) const
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));