Don't crash when no usable font is available
authorJiang Jiang <jiang.jiang@nokia.com>
Mon, 10 Oct 2011 15:43:59 +0000 (17:43 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 11 Oct 2011 14:01:12 +0000 (16:01 +0200)
We will fallback to box engine when no usable font is available,
and QRawFont (which scenegraph depends on) won't allocate glyph
index array on certain occasions. In those cases, QFontEngineBox
needs to support GlyphIndicesOnly flag.

Change-Id: I408ddd1b2f1a5f7ac2b6681cb7bf531bbbfc68e6
Reviewed-on: http://codereview.qt-project.org/6360
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
src/gui/text/qfontengine.cpp

index fabd8c3..1960b1e 100644 (file)
@@ -1197,7 +1197,7 @@ QFontEngineBox::~QFontEngineBox()
 {
 }
 
-bool QFontEngineBox::stringToCMap(const QChar *, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags) const
+bool QFontEngineBox::stringToCMap(const QChar *, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
 {
     if (*nglyphs < len) {
         *nglyphs = len;
@@ -1206,8 +1206,10 @@ bool QFontEngineBox::stringToCMap(const QChar *, int len, QGlyphLayout *glyphs,
 
     for (int i = 0; i < len; i++) {
         glyphs->glyphs[i] = 0;
-        glyphs->advances_x[i] = _size;
-        glyphs->advances_y[i] = 0;
+        if (!(flags & QTextEngine::GlyphIndicesOnly)) {
+            glyphs->advances_x[i] = _size;
+            glyphs->advances_y[i] = 0;
+        }
     }
 
     *nglyphs = len;