Do not use charset loaded by fontconfig

The only use for storing charset loaded by fontconfig in font engines
is for determine if a font supports certain codepoint, however FreeType
already does that. The charset loaded is sometimes not complete, for
instance in fontconfig 2.9.0 it removed Apple Roman platform support
for cmap loading, thus results a regression in common symbol fonts
(Wingdings, Webdings) rendering. Because those symbol fonts produced
by Monotype only contain two cmap tables: Apple Roman and Microsoft
Symbol, since the Microsoft Symbol table has a weird 0xF000 offset,
we always fallback to the Apple Roman cmap table.

Removing freetype charset cache also make each font engine consuming
less memory.

Change-Id: I88f3f44981f3a1c517b84809a3f5b834ffff7681
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
This commit is contained in:
Jiang Jiang 2012-05-09 16:38:54 +02:00 committed by Qt by Nokia
parent 954c2f4cf1
commit 2b39093d2f
4 changed files with 17 additions and 68 deletions

View File

@ -270,9 +270,6 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id,
newFreetype->matrix.yx = 0;
newFreetype->unicode_map = 0;
newFreetype->symbol_map = 0;
#ifndef QT_NO_FONTCONFIG
newFreetype->charset = 0;
#endif
memset(newFreetype->cmapCache, 0, sizeof(newFreetype->cmapCache));
@ -299,21 +296,6 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id,
if (!FT_IS_SCALABLE(newFreetype->face) && newFreetype->face->num_fixed_sizes == 1)
FT_Set_Char_Size (face, X_SIZE(newFreetype->face, 0), Y_SIZE(newFreetype->face, 0), 0, 0);
# if 0
FcChar8 *name;
FcPatternGetString(pattern, FC_FAMILY, 0, &name);
qDebug("%s: using maps: default: %x unicode: %x, symbol: %x", name,
newFreetype->face->charmap ? newFreetype->face->charmap->encoding : 0,
newFreetype->unicode_map ? newFreetype->unicode_map->encoding : 0,
newFreetype->symbol_map ? newFreetype->symbol_map->encoding : 0);
for (int i = 0; i < 256; i += 8)
qDebug(" %x: %d %d %d %d %d %d %d %d", i,
FcCharSetHasChar(newFreetype->charset, i), FcCharSetHasChar(newFreetype->charset, i),
FcCharSetHasChar(newFreetype->charset, i), FcCharSetHasChar(newFreetype->charset, i),
FcCharSetHasChar(newFreetype->charset, i), FcCharSetHasChar(newFreetype->charset, i),
FcCharSetHasChar(newFreetype->charset, i), FcCharSetHasChar(newFreetype->charset, i));
#endif
FT_Set_Charmap(newFreetype->face, newFreetype->unicode_map);
QT_TRY {
@ -334,10 +316,6 @@ void QFreetypeFace::release(const QFontEngine::FaceId &face_id)
if (!ref.deref()) {
qHBFreeFace(hbFace);
FT_Done_Face(face);
#ifndef QT_NO_FONTCONFIG
if (charset)
FcCharSetDestroy(charset);
#endif
if(freetypeData->faces.contains(face_id))
freetypeData->faces.take(face_id);
delete this;
@ -1430,19 +1408,6 @@ static inline unsigned int getChar(const QChar *str, int &i, const int len)
bool QFontEngineFT::canRender(const QChar *string, int len)
{
FT_Face face = freetype->face;
#if 0
if (_cmap != -1) {
lockFace();
for ( int i = 0; i < len; i++ ) {
unsigned int uc = getChar(string, i, len);
if (!FcCharSetHasChar (_font->charset, uc) && getAdobeCharIndex(face, _cmap, uc) == 0) {
allExist = false;
break;
}
}
unlockFace();
} else
#endif
{
for ( int i = 0; i < len; i++ ) {
unsigned int uc = getChar(string, i, len);
@ -1513,19 +1478,20 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
unsigned int uc = getChar(str, i, len);
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
if ( !glyphs->glyphs[glyph_pos] ) {
glyph_t glyph;
#if !defined(QT_NO_FONTCONFIG)
if (freetype->charset != 0 && FcCharSetHasChar(freetype->charset, uc)) {
#else
if (false) {
#endif
redo0:
// Symbol fonts can have more than one CMAPs, FreeType should take the
// correct one for us by default, so we always try FT_Get_Char_Index
// first. If it didn't work (returns 0), we will explicitly set the
// CMAP to symbol font one and try again. symbol_map is not always the
// correct one because in certain fonts like Wingdings symbol_map only
// contains PUA codepoints instead of the common ones.
glyph_t glyph = FT_Get_Char_Index(face, uc);
// Certain symbol fonts don't have no-break space (0xa0) and tab (0x9),
// while we usually want to render them as space
if (!glyph && (uc == 0xa0 || uc == 0x9)) {
uc = 0x20;
glyph = FT_Get_Char_Index(face, uc);
if (!glyph && (uc == 0xa0 || uc == 0x9)) {
uc = 0x20;
goto redo0;
}
} else {
}
if (!glyph) {
FT_Set_Charmap(face, freetype->symbol_map);
glyph = FT_Get_Char_Index(face, uc);
FT_Set_Charmap(face, freetype->unicode_map);
@ -1544,9 +1510,6 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
uc = QChar::mirroredChar(uc);
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
if (!glyphs->glyphs[glyph_pos]) {
#if !defined(QT_NO_FONTCONFIG)
if (freetype->charset == 0 || FcCharSetHasChar(freetype->charset, uc))
#endif
{
redo:
glyph_t glyph = FT_Get_Char_Index(face, uc);

View File

@ -102,9 +102,6 @@ struct QFreetypeFace
FT_Face face;
HB_Face hbFace;
#ifndef QT_NO_FONTCONFIG
FcCharSet *charset;
#endif
int xsize; // 26.6
int ysize; // 26.6
FT_Matrix matrix;

View File

@ -517,7 +517,6 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QFontDef &f, QUnicodeTables::
FcResult result;
FcPattern *match = FcFontMatch(0, pattern, &result);
FcCharSet *charset;
if (match) {
QFontEngineFT::HintStyle default_hint_style;
if (f.hintingPreference != QFont::PreferDefaultHinting) {
@ -577,7 +576,6 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QFontDef &f, QUnicodeTables::
} else
format = QFontEngineFT::Format_Mono;
FcPatternGetCharSet(match, FC_CHARSET, 0, &charset);
FcPatternDestroy(match);
} else
format = antialias ? QFontEngineFT::Format_A8 : QFontEngineFT::Format_Mono;
@ -600,9 +598,6 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QFontDef &f, QUnicodeTables::
}
}
if (engine && engine->freetype && !engine->freetype->charset)
engine->freetype->charset = FcCharSetCopy(charset);
return engine;
}

View File

@ -61,18 +61,12 @@ QFontEngineMultiFontConfig::~QFontEngineMultiFontConfig()
bool QFontEngineMultiFontConfig::shouldLoadFontEngineForCharacter(int at, uint ucs4) const
{
QFontEngineFT *fontEngine = static_cast<QFontEngineFT *>(engines.at(at));
bool charSetHasChar = true;
if (fontEngine != 0) {
FcCharSet *charSet = fontEngine->freetype->charset;
FcPattern *matchPattern = getMatchPatternForFallback(at - 1);
if (matchPattern != 0) {
FcCharSet *charSet;
FcPatternGetCharSet(matchPattern, FC_CHARSET, 0, &charSet);
charSetHasChar = FcCharSetHasChar(charSet, ucs4);
} else {
FcPattern *matchPattern = getMatchPatternForFallback(at - 1);
if (matchPattern != 0) {
FcCharSet *charSet;
FcPatternGetCharSet(matchPattern, FC_CHARSET, 0, &charSet);
charSetHasChar = FcCharSetHasChar(charSet, ucs4);
}
}
return charSetHasChar;