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 <lars.knoll@digia.com>
This commit is contained in:
Konstantin Ritt 2014-03-03 06:37:29 +02:00 committed by The Qt Project
parent af74201edb
commit 2b15c9c256
12 changed files with 19 additions and 113 deletions

View File

@ -385,6 +385,17 @@ bool QFontEngine::supportsScript(QChar::Script script) const
return hbFace->supported_scripts[script_to_hbscript(script)]; 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 QFontEngine::boundingBox(glyph_t glyph, const QTransform &matrix)
{ {
glyph_metrics_t metrics = boundingBox(glyph); glyph_metrics_t metrics = boundingBox(glyph);
@ -1533,7 +1544,7 @@ const char *QFontEngineBox::name() const
return "null"; return "null";
} }
bool QFontEngineBox::canRender(const QChar *, int) bool QFontEngineBox::canRender(const QChar *, int) const
{ {
return true; return true;
} }
@ -1951,7 +1962,7 @@ qreal QFontEngineMulti::minRightBearing() const
return engine(0)->minRightBearing(); 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)) if (engine(0)->canRender(string, len))
return true; return true;

View File

@ -1468,19 +1468,6 @@ static inline unsigned int getChar(const QChar *str, int &i, const int len)
return ucs4; 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) void QFontEngineFT::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
{ {
if (!glyphs.numGlyphs) if (!glyphs.numGlyphs)

View File

@ -237,8 +237,6 @@ private:
virtual bool supportsTransformation(const QTransform &transform) const; 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, virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs,
QPainterPath *path, QTextItem::RenderFlags flags); QPainterPath *path, QTextItem::RenderFlags flags);
virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs,

View File

@ -227,19 +227,8 @@ public:
virtual const char *name() const = 0; virtual const char *name() const = 0;
virtual bool canRender(const QChar *string, int len) = 0; inline bool canRender(uint ucs4) const { return glyphIndex(ucs4) != 0; }
inline bool canRender(uint ucs4) { virtual bool canRender(const QChar *str, int len) const;
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);
}
virtual bool supportsTransformation(const QTransform &transform) const; virtual bool supportsTransformation(const QTransform &transform) const;
@ -374,7 +363,7 @@ public:
virtual const char *name() const; 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; virtual Type type() const;
inline int size() const { return _size; } inline int size() const { return _size; }
@ -421,7 +410,7 @@ public:
virtual inline Type type() const virtual inline Type type() const
{ return QFontEngine::Multi; } { 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 inline virtual const char *name() const
{ return "Multi"; } { return "Multi"; }

View File

@ -515,29 +515,6 @@ QFontEngine::Type QFontEngineQPA::type() const
return QFontEngine::QPF2; 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 bool QFontEngineQPA::isValid() const
{ {
return fontData && dataSize && (cmapOffset || externalCMap) return fontData && dataSize && (cmapOffset || externalCMap)

View File

@ -184,7 +184,6 @@ public:
Type type() const; Type type() const;
bool canRender(const QChar *string, int len);
inline const char *name() const { return "QPF2"; } inline const char *name() const { return "QPF2"; }
virtual int glyphCount() const { return glyphMapEntries; } virtual int glyphCount() const { return glyphMapEntries; }

View File

@ -673,7 +673,7 @@ QFontEngine::FaceId QCoreTextFontEngine::faceId() const
return QFontEngine::FaceId(); return QFontEngine::FaceId();
} }
bool QCoreTextFontEngine::canRender(const QChar *string, int len) bool QCoreTextFontEngine::canRender(const QChar *string, int len) const
{ {
QVarLengthArray<CGGlyph> cgGlyphs(len); QVarLengthArray<CGGlyph> cgGlyphs(len);
return CTFontGetGlyphsForCharacters(ctfont, (const UniChar *) string, cgGlyphs.data(), len); return CTFontGetGlyphsForCharacters(ctfont, (const UniChar *) string, cgGlyphs.data(), len);

View File

@ -81,7 +81,7 @@ public:
virtual const char *name() const { return "QCoreTextFontEngine"; } 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 int synthesized() const { return synthesisFlags; }
virtual bool supportsSubPixelPositions() const { return true; } virtual bool supportsSubPixelPositions() const { return true; }

View File

@ -777,35 +777,6 @@ const char *QWindowsFontEngine::name() const
return 0; 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 QFontEngine::Type QWindowsFontEngine::type() const
{ {
return QFontEngine::Win; return QFontEngine::Win;

View File

@ -112,8 +112,6 @@ public:
virtual const char *name() const; virtual const char *name() const;
bool canRender(const QChar *string, int len);
Type type() const; Type type() const;
virtual QImage alphaMapForGlyph(glyph_t t) { return alphaMapForGlyph(t, QTransform()); } virtual QImage alphaMapForGlyph(glyph_t t) { return alphaMapForGlyph(t, QTransform()); }

View File

@ -647,29 +647,6 @@ const char *QWindowsFontEngineDirectWrite::name() const
return 0; return 0;
} }
bool QWindowsFontEngineDirectWrite::canRender(const QChar *string, int len)
{
QVarLengthArray<UINT32> codePoints(len);
int actualLength = 0;
for (int i=0; i<len; ++i, actualLength++)
codePoints[actualLength] = getChar(string, i, len);
QVarLengthArray<UINT16> 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 QFontEngine::Type QWindowsFontEngineDirectWrite::type() const
{ {
return QFontEngine::DirectWrite; return QFontEngine::DirectWrite;

View File

@ -99,7 +99,6 @@ public:
QFontEngine *cloneWithSize(qreal pixelSize) const; QFontEngine *cloneWithSize(qreal pixelSize) const;
bool canRender(const QChar *string, int len);
Type type() const; Type type() const;
const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; } const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; }