diff options
author | Jonas Karlsson <jonas.karlsson@qt.io> | 2020-08-06 17:05:45 +0200 |
---|---|---|
committer | Jonas Karlsson <jonas.karlsson@qt.io> | 2020-08-28 15:46:58 +0200 |
commit | 6b0ea2b0413be93b17ad1e328027531af9ff1cb5 (patch) | |
tree | 5149e7480b12fa976ec6429998bfe5f0ef87d25f /src/svg/qsvgstyle.cpp | |
parent | e3a5c2a5686845f0159f8091697961cd634cbc8e (diff) | |
download | qtsvg-6b0ea2b0413be93b17ad1e328027531af9ff1cb5.tar.gz |
Use OpenType font weights
Task-number: QTBUG-42248
Change-Id: If3984fa22b89a65fd126d42b3a2320d5ab16c94b
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/svg/qsvgstyle.cpp')
-rw-r--r-- | src/svg/qsvgstyle.cpp | 42 |
1 files changed, 11 insertions, 31 deletions
diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp index f36dda8..d425923 100644 --- a/src/svg/qsvgstyle.cpp +++ b/src/svg/qsvgstyle.cpp @@ -54,14 +54,14 @@ QT_BEGIN_NAMESPACE QSvgExtraStates::QSvgExtraStates() - : fillOpacity(1.0) - , strokeOpacity(1.0) - , svgFont(0) - , textAnchor(Qt::AlignLeft) - , fontWeight(400) - , fillRule(Qt::WindingFill) - , strokeDashOffset(0) - , vectorEffect(false) + : fillOpacity(1.0), + strokeOpacity(1.0), + svgFont(0), + textAnchor(Qt::AlignLeft), + fontWeight(QFont::Normal), + fillRule(Qt::WindingFill), + strokeDashOffset(0), + vectorEffect(false) { } @@ -199,26 +199,6 @@ QSvgFontStyle::QSvgFontStyle() { } -int QSvgFontStyle::SVGToQtWeight(int weight) { - switch (weight) { - case 100: - case 200: - return QFont::Light; - case 300: - case 400: - return QFont::Normal; - case 500: - case 600: - return QFont::DemiBold; - case 700: - case 800: - return QFont::Bold; - case 900: - return QFont::Black; - } - return QFont::Normal; -} - void QSvgFontStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &states) { m_oldQFont = p->font(); @@ -246,13 +226,13 @@ void QSvgFontStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &states if (m_weightSet) { if (m_weight == BOLDER) { - states.fontWeight = qMin(states.fontWeight + 100, 900); + states.fontWeight = qMin(states.fontWeight + 100, static_cast<int>(QFont::Black)); } else if (m_weight == LIGHTER) { - states.fontWeight = qMax(states.fontWeight - 100, 100); + states.fontWeight = qMax(states.fontWeight - 100, static_cast<int>(QFont::Thin)); } else { states.fontWeight = m_weight; } - font.setWeight(SVGToQtWeight(states.fontWeight)); + font.setWeight(QFont::Weight(states.fontWeight)); } p->setFont(font); |