From 9beac9838510e94338377fcd1cfc68b371f32a86 Mon Sep 17 00:00:00 2001 From: Raymund Apfelboeck Date: Thu, 2 Aug 2018 08:41:08 +0200 Subject: makeqpf: fix crash Also fix generation of special characters like space [ChangeLog][makeqpf] Fix assert when rendering font using debug build of Qt Fixes: QTBUG-46544 Change-Id: Ic17ee44973d3f85b5d2ae4423a059223abd52ea5 Reviewed-by: Paul Olav Tvete --- src/makeqpf/qpf2.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/makeqpf/qpf2.cpp b/src/makeqpf/qpf2.cpp index 508afaa33..c56ec391a 100644 --- a/src/makeqpf/qpf2.cpp +++ b/src/makeqpf/qpf2.cpp @@ -402,10 +402,10 @@ static QByteArray generateTrueTypeCMap(QFontEngine *fe) quint32 previousGlyphIndex = 0xfffffffe; bool inSegment = false; - QGlyphLayoutArray<10> layout; + QGlyphLayoutArray<1> layout; for (uint uc = 0; uc < 0x10000; ++uc) { QChar ch(uc); - int nglyphs = 10; + int nglyphs = 1; bool validGlyph = fe->stringToCMap(&ch, 1, &layout, &nglyphs, /*flags*/ 0) && nglyphs == 1 && layout.glyphs[0]; @@ -503,14 +503,14 @@ void QPF::addGlyphs(QFontEngine *fe, const QList &ranges) * (sizeof(QFontEngineQPF2::Glyph) + qRound(fe->maxCharWidth() * (fe->ascent() + fe->descent()).toReal()))); - QGlyphLayoutArray<10> layout; + QGlyphLayoutArray<1> layout; for (CharacterRange range : ranges) { if (debugVerbosity > 2) qDebug() << "rendering range from" << range.start << "to" << range.end; for (uint uc = range.start; uc < range.end; ++uc) { QChar ch(uc); - int nglyphs = 10; + int nglyphs = 1; if (!fe->stringToCMap(&ch, 1, &layout, &nglyphs, /*flags*/ 0)) continue; @@ -524,8 +524,12 @@ void QPF::addGlyphs(QFontEngine *fe, const QList &ranges) Q_ASSERT(glyphIndex < glyphCount); - QImage img = fe->alphaMapForGlyph(glyphIndex).convertToFormat(QImage::Format_Indexed8); glyph_metrics_t metrics = fe->boundingBox(glyphIndex); + const bool valid = metrics.width.value() != 0 && metrics.height.value() != 0; + + QImage img = valid + ? fe->alphaMapForGlyph(glyphIndex).convertToFormat(QImage::Format_Indexed8) + : QPixmap(0,0).toImage(); const quint32 oldSize = glyphs.size(); glyphs.resize(glyphs.size() + sizeof(QFontEngineQPF2::Glyph) + img.byteCount()); -- cgit v1.2.1