Skip to content

Commit

Permalink
Use more flexible solution for font hinting in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkanovikov committed Apr 20, 2023
1 parent 4ed6298 commit fd38201
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/corelib/business_layer/templates/text_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void TextBlockStyle::setFont(const QFont& _font)
}

m_font = _font;
// m_font.setHintingPreference(QFont::HintingPreference::PreferNoHinting);
TextHelper::updateFontHinting(m_font);
m_charFormat.setFont(m_font);
updateLineHeight();
}
Expand Down Expand Up @@ -560,7 +560,7 @@ TextBlockStyle::TextBlockStyle(const QXmlStreamAttributes& _blockAttributes)
"Apple Color Emoji",
"Noto Color Emoji",
});
// m_font.setHintingPreference(QFont::HintingPreference::PreferNoHinting);
TextHelper::updateFontHinting(m_font);
m_font.setPixelSize(MeasurementHelper::ptToPx(_blockAttributes.value("font_size").toDouble()));
//
// ... начертание
Expand Down
15 changes: 15 additions & 0 deletions src/corelib/utils/helpers/text_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static void initFontMetrics()
addFontDelta("Arial", 2355.0);
addFontDelta("Times New Roman", 2355.0);
}

} // namespace

qreal TextHelper::fineTextWidthF(const QString& _text, const QFont& _font)
Expand Down Expand Up @@ -155,6 +156,20 @@ qreal TextHelper::fineLineSpacing(const QFont& _font)
return metrics.lineSpacing() + sFontToLineSpacing.value(_font.family(), platformDelta);
}

void TextHelper::updateFontHinting(QFont& _font)
{
#ifdef Q_OS_WINDOWS
//
// Arial в Windows при масштабировании рисуется коряво, поэтому убираем ему хинтинг
//
if (_font.family() == "Arial") {
_font.setHintingPreference(QFont::PreferNoHinting);
}
#else
Q_UNUSED(_font)
#endif
}

qreal TextHelper::heightForWidth(const QString& _text, const QFont& _font, qreal _width)
{
const qreal lineHeight = fineLineSpacing(_font);
Expand Down
5 changes: 5 additions & 0 deletions src/corelib/utils/helpers/text_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class CORE_LIBRARY_EXPORT TextHelper
*/
static qreal fineLineSpacing(const QFont& _font);

/**
* @brief Обновить хинтинг шрифта в зависимости от гарнитуры
*/
static void updateFontHinting(QFont& _font);

/**
* Возвращает высоту текста
* @param text Текст
Expand Down

0 comments on commit fd38201

Please sign in to comment.