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;
|
return lf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList extraTryFontsForFamily(const QString& family)
|
QStringList QWindowsFontDatabase::extraTryFontsForFamily(const QString &family)
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
QFontDatabase db;
|
QFontDatabase db;
|
||||||
@ -1615,7 +1615,7 @@ QStringList QWindowsFontDatabase::fallbacksForFamily(const QString &family, QFon
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (script == QChar::Script_Common || script == QChar::Script_Han)
|
if (script == QChar::Script_Common || script == QChar::Script_Han)
|
||||||
result.append(extraTryFontsForFamily(family));
|
result.append(QWindowsFontDatabase::extraTryFontsForFamily(family));
|
||||||
|
|
||||||
qCDebug(lcQpaFonts) << __FUNCTION__ << family << style << styleHint
|
qCDebug(lcQpaFonts) << __FUNCTION__ << family << style << styleHint
|
||||||
<< script << result << m_families.size();
|
<< 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)
|
if ((script == QChar::Script_Common || script == QChar::Script_Han)
|
||||||
&& !(request.styleStrategy & QFont::NoFontMerging)) {
|
&& !(request.styleStrategy & QFont::NoFontMerging)) {
|
||||||
QStringList extraFonts = extraTryFontsForFamily(request.family);
|
const QStringList extraFonts = QWindowsFontDatabase::extraTryFontsForFamily(request.family);
|
||||||
if (extraFonts.size()) {
|
if (extraFonts.size()) {
|
||||||
QStringList list = family_list;
|
QStringList list = family_list;
|
||||||
list.append(extraFonts);
|
list.append(extraFonts);
|
||||||
@ -1818,9 +1818,9 @@ QFont QWindowsFontDatabase::LOGFONT_to_QFont(const LOGFONT& logFont, int vertica
|
|||||||
qFont.setWeight(weightFromInteger(logFont.lfWeight));
|
qFont.setWeight(weightFromInteger(logFont.lfWeight));
|
||||||
const qreal logFontHeight = qAbs(logFont.lfHeight);
|
const qreal logFontHeight = qAbs(logFont.lfHeight);
|
||||||
qFont.setPointSizeF(logFontHeight * 72.0 / qreal(verticalDPI_In));
|
qFont.setPointSizeF(logFontHeight * 72.0 / qreal(verticalDPI_In));
|
||||||
qFont.setUnderline(false);
|
qFont.setUnderline(logFont.lfUnderline);
|
||||||
qFont.setOverline(false);
|
qFont.setOverline(false);
|
||||||
qFont.setStrikeOut(false);
|
qFont.setStrikeOut(logFont.lfStrikeOut);
|
||||||
return qFont;
|
return qFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +103,8 @@ public:
|
|||||||
static qreal fontSmoothingGamma();
|
static qreal fontSmoothingGamma();
|
||||||
static LOGFONT fontDefToLOGFONT(const QFontDef &fontDef);
|
static LOGFONT fontDefToLOGFONT(const QFontDef &fontDef);
|
||||||
|
|
||||||
|
static QStringList extraTryFontsForFamily(const QString &family);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void populate(const QString &family = QString());
|
void populate(const QString &family = QString());
|
||||||
void removeApplicationFonts();
|
void removeApplicationFonts();
|
||||||
|
@ -436,95 +436,8 @@ QFontEngine *QWindowsFontDatabaseFT::fontEngine(const QByteArray &fontData, qrea
|
|||||||
return fe;
|
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
|
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);
|
QStringList result = QPlatformFontDatabase::fallbacksForFamily(family, style, styleHint, script);
|
||||||
if (!result.isEmpty())
|
if (!result.isEmpty())
|
||||||
return result;
|
return result;
|
||||||
@ -564,8 +477,12 @@ QStringList QWindowsFontDatabaseFT::fallbacksForFamily(const QString &family, QF
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (script == QChar::Script_Common || script == QChar::Script_Han)
|
||||||
|
result.append(QWindowsFontDatabase::extraTryFontsForFamily(family));
|
||||||
|
|
||||||
qCDebug(lcQpaFonts) << __FUNCTION__ << family << style << styleHint
|
qCDebug(lcQpaFonts) << __FUNCTION__ << family << style << styleHint
|
||||||
<< script << result << m_families;
|
<< script << result << m_families;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
QString QWindowsFontDatabaseFT::fontDir() const
|
QString QWindowsFontDatabaseFT::fontDir() const
|
||||||
@ -575,38 +492,9 @@ QString QWindowsFontDatabaseFT::fontDir() const
|
|||||||
return result;
|
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
|
QFont QWindowsFontDatabaseFT::defaultFont() const
|
||||||
{
|
{
|
||||||
return QWindowsFontDatabase::systemDefaultFont();
|
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
|
QT_END_NAMESPACE
|
||||||
|
@ -60,9 +60,6 @@ public:
|
|||||||
virtual QString fontDir() const;
|
virtual QString fontDir() const;
|
||||||
virtual QFont defaultFont() const;
|
virtual QFont defaultFont() const;
|
||||||
|
|
||||||
static HFONT systemFont();
|
|
||||||
static QFont LOGFONT_to_QFont(const LOGFONT& lf, int verticalDPI = 0);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void populate(const QString &family = QString());
|
void populate(const QString &family = QString());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user