From 2b15c9c256e5be597cfc3e8165d9b1a9047cfa7c Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 3 Mar 2014 06:37:29 +0200 Subject: Introduce a generic QFontEngine::canRender() implementation ...which uses the recently introduced glyphIndex() method; get rid of re-implementations that did almost the same. Change-Id: I6d32d2cee6a31f57de6aee05ed8d120d4a1f4e9c Reviewed-by: Lars Knoll --- src/gui/text/qfontengine.cpp | 15 +++++++++-- src/gui/text/qfontengine_ft.cpp | 13 ---------- src/gui/text/qfontengine_ft_p.h | 2 -- src/gui/text/qfontengine_p.h | 19 +++----------- src/gui/text/qfontengine_qpa.cpp | 23 ----------------- src/gui/text/qfontengine_qpa_p.h | 1 - .../fontdatabases/mac/qfontengine_coretext.mm | 2 +- .../fontdatabases/mac/qfontengine_coretext_p.h | 2 +- .../platforms/windows/qwindowsfontengine.cpp | 29 ---------------------- src/plugins/platforms/windows/qwindowsfontengine.h | 2 -- .../windows/qwindowsfontenginedirectwrite.cpp | 23 ----------------- .../windows/qwindowsfontenginedirectwrite.h | 1 - 12 files changed, 19 insertions(+), 113 deletions(-) (limited to 'src') diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 61816c83fb..ed758f6f0f 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -385,6 +385,17 @@ bool QFontEngine::supportsScript(QChar::Script script) const return hbFace->supported_scripts[script_to_hbscript(script)]; } +bool QFontEngine::canRender(const QChar *str, int len) const +{ + QStringIterator it(str, str + len); + while (it.hasNext()) { + if (glyphIndex(it.next()) == 0) + return false; + } + + return true; +} + glyph_metrics_t QFontEngine::boundingBox(glyph_t glyph, const QTransform &matrix) { glyph_metrics_t metrics = boundingBox(glyph); @@ -1533,7 +1544,7 @@ const char *QFontEngineBox::name() const return "null"; } -bool QFontEngineBox::canRender(const QChar *, int) +bool QFontEngineBox::canRender(const QChar *, int) const { return true; } @@ -1951,7 +1962,7 @@ qreal QFontEngineMulti::minRightBearing() const return engine(0)->minRightBearing(); } -bool QFontEngineMulti::canRender(const QChar *string, int len) +bool QFontEngineMulti::canRender(const QChar *string, int len) const { if (engine(0)->canRender(string, len)) return true; diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index b50c8fd95a..04cf6bfdcb 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -1468,19 +1468,6 @@ static inline unsigned int getChar(const QChar *str, int &i, const int len) return ucs4; } -bool QFontEngineFT::canRender(const QChar *string, int len) -{ - FT_Face face = freetype->face; - { - for ( int i = 0; i < len; i++ ) { - unsigned int uc = getChar(string, i, len); - if (!FT_Get_Char_Index(face, uc)) - return false; - } - } - return true; -} - void QFontEngineFT::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) { if (!glyphs.numGlyphs) diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h index 7fc73c816d..fa6ef6f422 100644 --- a/src/gui/text/qfontengine_ft_p.h +++ b/src/gui/text/qfontengine_ft_p.h @@ -237,8 +237,6 @@ private: virtual bool supportsTransformation(const QTransform &transform) const; - virtual bool canRender(const QChar *string, int len); - virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags); virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index f497085ce2..f5e4ae98fa 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -227,19 +227,8 @@ public: virtual const char *name() const = 0; - virtual bool canRender(const QChar *string, int len) = 0; - inline bool canRender(uint ucs4) { - QChar utf16[2]; - int utf16len = 1; - if (QChar::requiresSurrogates(ucs4)) { - utf16[0] = QChar::highSurrogate(ucs4); - utf16[1] = QChar::lowSurrogate(ucs4); - ++utf16len; - } else { - utf16[0] = QChar(ucs4); - } - return canRender(utf16, utf16len); - } + inline bool canRender(uint ucs4) const { return glyphIndex(ucs4) != 0; } + virtual bool canRender(const QChar *str, int len) const; virtual bool supportsTransformation(const QTransform &transform) const; @@ -374,7 +363,7 @@ public: virtual const char *name() const; - virtual bool canRender(const QChar *string, int len); + virtual bool canRender(const QChar *string, int len) const; virtual Type type() const; inline int size() const { return _size; } @@ -421,7 +410,7 @@ public: virtual inline Type type() const { return QFontEngine::Multi; } - virtual bool canRender(const QChar *string, int len); + virtual bool canRender(const QChar *string, int len) const; inline virtual const char *name() const { return "Multi"; } diff --git a/src/gui/text/qfontengine_qpa.cpp b/src/gui/text/qfontengine_qpa.cpp index f48b44374e..b0bfd02448 100644 --- a/src/gui/text/qfontengine_qpa.cpp +++ b/src/gui/text/qfontengine_qpa.cpp @@ -515,29 +515,6 @@ QFontEngine::Type QFontEngineQPA::type() const return QFontEngine::QPF2; } -bool QFontEngineQPA::canRender(const QChar *string, int len) -{ - const uchar *cmap = externalCMap ? externalCMap : (fontData + cmapOffset); - - if (symbol) { - for (int i = 0; i < len; ++i) { - unsigned int uc = getChar(string, i, len); - glyph_t g = getTrueTypeGlyphIndex(cmap, uc); - if(!g && uc < 0x100) - g = getTrueTypeGlyphIndex(cmap, uc + 0xf000); - if (!g) - return false; - } - } else { - for (int i = 0; i < len; ++i) { - unsigned int uc = getChar(string, i, len); - if (!getTrueTypeGlyphIndex(cmap, uc)) - return false; - } - } - return true; -} - bool QFontEngineQPA::isValid() const { return fontData && dataSize && (cmapOffset || externalCMap) diff --git a/src/gui/text/qfontengine_qpa_p.h b/src/gui/text/qfontengine_qpa_p.h index bcd48ca690..9d9140b842 100644 --- a/src/gui/text/qfontengine_qpa_p.h +++ b/src/gui/text/qfontengine_qpa_p.h @@ -184,7 +184,6 @@ public: Type type() const; - bool canRender(const QChar *string, int len); inline const char *name() const { return "QPF2"; } virtual int glyphCount() const { return glyphMapEntries; } diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 2ea7e6f00d..53c4c01a73 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -673,7 +673,7 @@ QFontEngine::FaceId QCoreTextFontEngine::faceId() const return QFontEngine::FaceId(); } -bool QCoreTextFontEngine::canRender(const QChar *string, int len) +bool QCoreTextFontEngine::canRender(const QChar *string, int len) const { QVarLengthArray cgGlyphs(len); return CTFontGetGlyphsForCharacters(ctfont, (const UniChar *) string, cgGlyphs.data(), len); diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 0070aede24..aefe495c37 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -81,7 +81,7 @@ public: virtual const char *name() const { return "QCoreTextFontEngine"; } - virtual bool canRender(const QChar *string, int len); + virtual bool canRender(const QChar *string, int len) const; virtual int synthesized() const { return synthesisFlags; } virtual bool supportsSubPixelPositions() const { return true; } diff --git a/src/plugins/platforms/windows/qwindowsfontengine.cpp b/src/plugins/platforms/windows/qwindowsfontengine.cpp index a2f65c766d..264c22f47e 100644 --- a/src/plugins/platforms/windows/qwindowsfontengine.cpp +++ b/src/plugins/platforms/windows/qwindowsfontengine.cpp @@ -777,35 +777,6 @@ const char *QWindowsFontEngine::name() const return 0; } -bool QWindowsFontEngine::canRender(const QChar *string, int len) -{ - if (symbol) { - for (int i = 0; i < len; ++i) { - unsigned int uc = getChar(string, i, len); - if (getTrueTypeGlyphIndex(cmap, uc) == 0) { - if (uc < 0x100) { - if (getTrueTypeGlyphIndex(cmap, uc + 0xf000) == 0) - return false; - } else { - return false; - } - } - } - } else if (ttf) { - for (int i = 0; i < len; ++i) { - unsigned int uc = getChar(string, i, len); - if (getTrueTypeGlyphIndex(cmap, uc) == 0) - return false; - } - } else { - while(len--) { - if (tm.tmFirstChar > string->unicode() || tm.tmLastChar < string->unicode()) - return false; - } - } - return true; -} - QFontEngine::Type QWindowsFontEngine::type() const { return QFontEngine::Win; diff --git a/src/plugins/platforms/windows/qwindowsfontengine.h b/src/plugins/platforms/windows/qwindowsfontengine.h index 390de1d16e..89ad08f689 100644 --- a/src/plugins/platforms/windows/qwindowsfontengine.h +++ b/src/plugins/platforms/windows/qwindowsfontengine.h @@ -112,8 +112,6 @@ public: virtual const char *name() const; - bool canRender(const QChar *string, int len); - Type type() const; virtual QImage alphaMapForGlyph(glyph_t t) { return alphaMapForGlyph(t, QTransform()); } diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp index cd5defdfea..744058279e 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp @@ -647,29 +647,6 @@ const char *QWindowsFontEngineDirectWrite::name() const return 0; } -bool QWindowsFontEngineDirectWrite::canRender(const QChar *string, int len) -{ - QVarLengthArray codePoints(len); - int actualLength = 0; - for (int i=0; i glyphIndices(actualLength); - HRESULT hr = m_directWriteFontFace->GetGlyphIndices(codePoints.data(), actualLength, - glyphIndices.data()); - if (FAILED(hr)) { - qErrnoWarning("%s: GetGlyphIndices failed", __FUNCTION__); - return false; - } - - for (int i = 0; i < actualLength; ++i) { - if (glyphIndices.at(i) == 0) - return false; - } - - return true; -} - QFontEngine::Type QWindowsFontEngineDirectWrite::type() const { return QFontEngine::DirectWrite; diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h index aacdcd5a89..070adfcbde 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h @@ -99,7 +99,6 @@ public: QFontEngine *cloneWithSize(qreal pixelSize) const; - bool canRender(const QChar *string, int len); Type type() const; const QSharedPointer &fontEngineData() const { return m_fontEngineData; } -- cgit v1.2.3