QWindowsFontDatabaseFT: Code deduplication
Re-use a private helper API from QWindowsFontDatabase. This also helped in consolidating the behavior between these two. Change-Id: I93ba0a486a2c11fdefd328af090497dde5b0fbdb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
d437457bec
commit
e4588b70dd
@ -1544,7 +1544,7 @@ LOGFONT QWindowsFontDatabase::fontDefToLOGFONT(const QFontDef &request)
|
||||
return lf;
|
||||
}
|
||||
|
||||
static QStringList extraTryFontsForFamily(const QString& family)
|
||||
QStringList QWindowsFontDatabase::extraTryFontsForFamily(const QString &family)
|
||||
{
|
||||
QStringList result;
|
||||
QFontDatabase db;
|
||||
@ -1615,7 +1615,7 @@ QStringList QWindowsFontDatabase::fallbacksForFamily(const QString &family, QFon
|
||||
}
|
||||
|
||||
if (script == QChar::Script_Common || script == QChar::Script_Han)
|
||||
result.append(extraTryFontsForFamily(family));
|
||||
result.append(QWindowsFontDatabase::extraTryFontsForFamily(family));
|
||||
|
||||
qCDebug(lcQpaFonts) << __FUNCTION__ << family << style << styleHint
|
||||
<< script << result << m_families.size();
|
||||
@ -1779,7 +1779,7 @@ QFontEngine *QWindowsFontDatabase::createEngine(int script, const QFontDef &requ
|
||||
|
||||
if ((script == QChar::Script_Common || script == QChar::Script_Han)
|
||||
&& !(request.styleStrategy & QFont::NoFontMerging)) {
|
||||
QStringList extraFonts = extraTryFontsForFamily(request.family);
|
||||
const QStringList extraFonts = QWindowsFontDatabase::extraTryFontsForFamily(request.family);
|
||||
if (extraFonts.size()) {
|
||||
QStringList list = family_list;
|
||||
list.append(extraFonts);
|
||||
@ -1818,9 +1818,9 @@ QFont QWindowsFontDatabase::LOGFONT_to_QFont(const LOGFONT& logFont, int vertica
|
||||
qFont.setWeight(weightFromInteger(logFont.lfWeight));
|
||||
const qreal logFontHeight = qAbs(logFont.lfHeight);
|
||||
qFont.setPointSizeF(logFontHeight * 72.0 / qreal(verticalDPI_In));
|
||||
qFont.setUnderline(false);
|
||||
qFont.setUnderline(logFont.lfUnderline);
|
||||
qFont.setOverline(false);
|
||||
qFont.setStrikeOut(false);
|
||||
qFont.setStrikeOut(logFont.lfStrikeOut);
|
||||
return qFont;
|
||||
}
|
||||
|
||||
|
@ -103,6 +103,8 @@ public:
|
||||
static qreal fontSmoothingGamma();
|
||||
static LOGFONT fontDefToLOGFONT(const QFontDef &fontDef);
|
||||
|
||||
static QStringList extraTryFontsForFamily(const QString &family);
|
||||
|
||||
private:
|
||||
void populate(const QString &family = QString());
|
||||
void removeApplicationFonts();
|
||||
|
@ -436,95 +436,8 @@ QFontEngine *QWindowsFontDatabaseFT::fontEngine(const QByteArray &fontData, qrea
|
||||
return fe;
|
||||
}
|
||||
|
||||
static const char *other_tryFonts[] = {
|
||||
"Arial",
|
||||
"MS UI Gothic",
|
||||
"Gulim",
|
||||
"SimSun",
|
||||
"PMingLiU",
|
||||
"Arial Unicode MS",
|
||||
0
|
||||
};
|
||||
|
||||
static const char *jp_tryFonts [] = {
|
||||
"MS UI Gothic",
|
||||
"Arial",
|
||||
"Gulim",
|
||||
"SimSun",
|
||||
"PMingLiU",
|
||||
"Arial Unicode MS",
|
||||
0
|
||||
};
|
||||
|
||||
static const char *ch_CN_tryFonts [] = {
|
||||
"SimSun",
|
||||
"Arial",
|
||||
"PMingLiU",
|
||||
"Gulim",
|
||||
"MS UI Gothic",
|
||||
"Arial Unicode MS",
|
||||
0
|
||||
};
|
||||
|
||||
static const char *ch_TW_tryFonts [] = {
|
||||
"PMingLiU",
|
||||
"Arial",
|
||||
"SimSun",
|
||||
"Gulim",
|
||||
"MS UI Gothic",
|
||||
"Arial Unicode MS",
|
||||
0
|
||||
};
|
||||
|
||||
static const char *kr_tryFonts[] = {
|
||||
"Gulim",
|
||||
"Arial",
|
||||
"PMingLiU",
|
||||
"SimSun",
|
||||
"MS UI Gothic",
|
||||
"Arial Unicode MS",
|
||||
0
|
||||
};
|
||||
|
||||
static const char **tryFonts = 0;
|
||||
|
||||
QStringList QWindowsFontDatabaseFT::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const
|
||||
{
|
||||
if (script == QChar::Script_Common || script == QChar::Script_Han) {
|
||||
// && !(request.styleStrategy & QFont::NoFontMerging)) {
|
||||
QFontDatabase db;
|
||||
if (!db.writingSystems(family).contains(QFontDatabase::Symbol)) {
|
||||
if(!tryFonts) {
|
||||
LANGID lid = GetUserDefaultLangID();
|
||||
switch( lid&0xff ) {
|
||||
case LANG_CHINESE: // Chinese (Taiwan)
|
||||
if ( lid == 0x0804 ) // Taiwan
|
||||
tryFonts = ch_TW_tryFonts;
|
||||
else
|
||||
tryFonts = ch_CN_tryFonts;
|
||||
break;
|
||||
case LANG_JAPANESE:
|
||||
tryFonts = jp_tryFonts;
|
||||
break;
|
||||
case LANG_KOREAN:
|
||||
tryFonts = kr_tryFonts;
|
||||
break;
|
||||
default:
|
||||
tryFonts = other_tryFonts;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QStringList list;
|
||||
const char **tf = tryFonts;
|
||||
while(tf && *tf) {
|
||||
if(m_families.contains(QLatin1String(*tf)))
|
||||
list << QLatin1String(*tf);
|
||||
++tf;
|
||||
}
|
||||
if (!list.isEmpty())
|
||||
return list;
|
||||
}
|
||||
}
|
||||
QStringList result = QPlatformFontDatabase::fallbacksForFamily(family, style, styleHint, script);
|
||||
if (!result.isEmpty())
|
||||
return result;
|
||||
@ -564,8 +477,12 @@ QStringList QWindowsFontDatabaseFT::fallbacksForFamily(const QString &family, QF
|
||||
}
|
||||
#endif
|
||||
|
||||
if (script == QChar::Script_Common || script == QChar::Script_Han)
|
||||
result.append(QWindowsFontDatabase::extraTryFontsForFamily(family));
|
||||
|
||||
qCDebug(lcQpaFonts) << __FUNCTION__ << family << style << styleHint
|
||||
<< script << result << m_families;
|
||||
|
||||
return result;
|
||||
}
|
||||
QString QWindowsFontDatabaseFT::fontDir() const
|
||||
@ -575,38 +492,9 @@ QString QWindowsFontDatabaseFT::fontDir() const
|
||||
return result;
|
||||
}
|
||||
|
||||
HFONT QWindowsFontDatabaseFT::systemFont()
|
||||
{
|
||||
static const HFONT stock_sysfont = (HFONT)GetStockObject(SYSTEM_FONT);
|
||||
return stock_sysfont;
|
||||
}
|
||||
|
||||
// Creation functions
|
||||
|
||||
static inline int verticalDPI()
|
||||
{
|
||||
return GetDeviceCaps(QWindowsContext::instance()->displayContext(), LOGPIXELSY);
|
||||
}
|
||||
|
||||
QFont QWindowsFontDatabaseFT::defaultFont() const
|
||||
{
|
||||
return QWindowsFontDatabase::systemDefaultFont();
|
||||
}
|
||||
|
||||
QFont QWindowsFontDatabaseFT::LOGFONT_to_QFont(const LOGFONT& logFont, int verticalDPI_In)
|
||||
{
|
||||
if (verticalDPI_In <= 0)
|
||||
verticalDPI_In = verticalDPI();
|
||||
QFont qFont(QString::fromWCharArray(logFont.lfFaceName));
|
||||
qFont.setItalic(logFont.lfItalic);
|
||||
if (logFont.lfWeight != FW_DONTCARE)
|
||||
qFont.setWeight(weightFromInteger(logFont.lfWeight));
|
||||
const qreal logFontHeight = qAbs(logFont.lfHeight);
|
||||
qFont.setPointSizeF(logFontHeight * 72.0 / qreal(verticalDPI_In));
|
||||
qFont.setUnderline(logFont.lfUnderline);
|
||||
qFont.setOverline(false);
|
||||
qFont.setStrikeOut(logFont.lfStrikeOut);
|
||||
return qFont;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -60,9 +60,6 @@ public:
|
||||
virtual QString fontDir() const;
|
||||
virtual QFont defaultFont() const;
|
||||
|
||||
static HFONT systemFont();
|
||||
static QFont LOGFONT_to_QFont(const LOGFONT& lf, int verticalDPI = 0);
|
||||
|
||||
private:
|
||||
void populate(const QString &family = QString());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user