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:
parent
af74201edb
commit
2b15c9c256
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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"; }
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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; }
|
||||
|
@ -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<CGGlyph> cgGlyphs(len);
|
||||
return CTFontGetGlyphsForCharacters(ctfont, (const UniChar *) string, cgGlyphs.data(), len);
|
||||
|
@ -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; }
|
||||
|
@ -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;
|
||||
|
@ -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()); }
|
||||
|
@ -647,29 +647,6 @@ const char *QWindowsFontEngineDirectWrite::name() const
|
||||
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
|
||||
{
|
||||
return QFontEngine::DirectWrite;
|
||||
|
@ -99,7 +99,6 @@ public:
|
||||
|
||||
QFontEngine *cloneWithSize(qreal pixelSize) const;
|
||||
|
||||
bool canRender(const QChar *string, int len);
|
||||
Type type() const;
|
||||
|
||||
const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user