vcl/inc/qt5/Qt5FontFace.hxx | 7 ++ vcl/qt5/Qt5Font.cxx | 69 ++++++++++++++++++++++------- vcl/qt5/Qt5FontFace.cxx | 104 ++++++++++++++++++++++++-------------------- vcl/unx/kf5/KF5SalFrame.cxx | 42 +---------------- 4 files changed, 122 insertions(+), 100 deletions(-)
New commits: commit 63ea1e811a3b3806b6b2408d759a449f4e086eb3 Author: Jan-Marek Glogowski <glo...@fbihome.de> AuthorDate: Mon Mar 2 10:04:24 2020 +0100 Commit: Jan-Marek Glogowski <glo...@fbihome.de> CommitDate: Mon Mar 2 13:26:44 2020 +0100 Qt5 unify font attribute conversions Adds conversion functions for VCLs FontWeight, FontWidth and FontItalic to Qt5FontFace and remove the partial "switch" tables from KF5SalFrame. And correctly handle the FontWidth in Qt5Font as the stretch value, so the default font in qt5 gets the correct stretch and doesn't look bold. Change-Id: I698986416dff13e6dfaf9dfa7f95851b89e9137d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89813 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> diff --git a/vcl/inc/qt5/Qt5FontFace.hxx b/vcl/inc/qt5/Qt5FontFace.hxx index 1785e0d4dff9..585f4aaa87bf 100644 --- a/vcl/inc/qt5/Qt5FontFace.hxx +++ b/vcl/inc/qt5/Qt5FontFace.hxx @@ -19,6 +19,7 @@ #pragma once +#include <vclpluginapi.h> #include <PhysicalFontFace.hxx> #include <tools/ref.hxx> @@ -26,10 +27,10 @@ #include <vcl/fontcharmap.hxx> #include <QtCore/QString> +#include <QtGui/QFont> class FontAttributes; class FontSelectPattern; -class QFont; class Qt5FontFace final : public PhysicalFontFace { @@ -38,6 +39,10 @@ public: static Qt5FontFace* fromQFontDatabase(const QString& aFamily, const QString& aStyle); static void fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA); + VCLPLUG_QT5_PUBLIC static FontWeight toFontWeight(const int nWeight); + VCLPLUG_QT5_PUBLIC static FontWidth toFontWidth(const int nStretch); + VCLPLUG_QT5_PUBLIC static FontItalic toFontItalic(const QFont::Style eStyle); + sal_IntPtr GetFontId() const override; int GetFontTable(const char pTagName[5], unsigned char*) const; diff --git a/vcl/qt5/Qt5Font.cxx b/vcl/qt5/Qt5Font.cxx index ee9d339266b2..832508038b4d 100644 --- a/vcl/qt5/Qt5Font.cxx +++ b/vcl/qt5/Qt5Font.cxx @@ -23,7 +23,7 @@ #include <QtGui/QFont> #include <QtGui/QRawFont> -static QFont::Weight GetQFontWeight(FontWeight eWeight) +static QFont::Weight toWeight(FontWeight eWeight) { switch (eWeight) { @@ -57,27 +57,66 @@ static QFont::Weight GetQFontWeight(FontWeight eWeight) return QFont::Normal; } -Qt5Font::Qt5Font(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP) - : LogicalFontInstance(rPFF, rFSP) +static int toStretch(FontWidth eWidthType) { - setFamily(toQString(rPFF.GetFamilyName())); - setWeight(GetQFontWeight(rPFF.GetWeight())); - setPixelSize(rFSP.mnHeight); - switch (rFSP.GetItalic()) + switch (eWidthType) + { + case WIDTH_DONTKNOW: + return QFont::AnyStretch; + case WIDTH_ULTRA_CONDENSED: + return QFont::UltraCondensed; + case WIDTH_EXTRA_CONDENSED: + return QFont::ExtraCondensed; + case WIDTH_CONDENSED: + return QFont::Condensed; + case WIDTH_SEMI_CONDENSED: + return QFont::SemiCondensed; + case WIDTH_NORMAL: + return QFont::Unstretched; + case WIDTH_SEMI_EXPANDED: + return QFont::SemiExpanded; + case WIDTH_EXPANDED: + return QFont::Expanded; + case WIDTH_EXTRA_EXPANDED: + return QFont::ExtraExpanded; + case WIDTH_ULTRA_EXPANDED: + return QFont::UltraExpanded; + case FontWidth_FORCE_EQUAL_SIZE: + assert(false && "FontWidth_FORCE_EQUAL_SIZE not implementable for QFont"); + } + + // so we would get enum not handled warning + return QFont::AnyStretch; +} + +static QFont::Style toStyle(FontItalic eItalic) +{ + switch (eItalic) { case ITALIC_DONTKNOW: - case FontItalic_FORCE_EQUAL_SIZE: - break; + [[fallthrough]]; case ITALIC_NONE: - setStyle(Style::StyleNormal); - break; + return QFont::Style::StyleNormal; case ITALIC_OBLIQUE: - setStyle(Style::StyleOblique); - break; + return QFont::Style::StyleOblique; case ITALIC_NORMAL: - setStyle(Style::StyleItalic); - break; + return QFont::Style::StyleItalic; + case FontItalic_FORCE_EQUAL_SIZE: + assert(false && "FontItalic_FORCE_EQUAL_SIZE not implementable for QFont"); } + + // so we would get enum not handled warning + return QFont::Style::StyleNormal; +} + +Qt5Font::Qt5Font(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP) + : LogicalFontInstance(rPFF, rFSP) +{ + setFamily(toQString(rPFF.GetFamilyName())); + setWeight(toWeight(rPFF.GetWeight())); + setPixelSize(rFSP.mnHeight); + setStretch(toStretch(rPFF.GetWidthType())); + setStyle(toStyle(rFSP.GetItalic())); } static hb_blob_t* getFontTable(hb_face_t*, hb_tag_t nTableTag, void* pUserData) diff --git a/vcl/qt5/Qt5FontFace.cxx b/vcl/qt5/Qt5FontFace.cxx index a7837667f1dd..8ac2f87d1843 100644 --- a/vcl/qt5/Qt5FontFace.cxx +++ b/vcl/qt5/Qt5FontFace.cxx @@ -46,40 +46,63 @@ Qt5FontFace::Qt5FontFace(const Qt5FontFace& rSrc) m_xCharMap = rSrc.m_xCharMap; } -static FontWeight fromQFontWeight(int nWeight) +FontWeight Qt5FontFace::toFontWeight(const int nWeight) { - FontWeight eWeight = WEIGHT_DONTKNOW; - switch (nWeight) + if (nWeight <= QFont::Thin) + return WEIGHT_THIN; + if (nWeight <= QFont::ExtraLight) + return WEIGHT_ULTRALIGHT; + if (nWeight <= QFont::Light) + return WEIGHT_LIGHT; + if (nWeight <= QFont::Normal) + return WEIGHT_NORMAL; + if (nWeight <= QFont::Medium) + return WEIGHT_MEDIUM; + if (nWeight <= QFont::DemiBold) + return WEIGHT_SEMIBOLD; + if (nWeight <= QFont::Bold) + return WEIGHT_BOLD; + if (nWeight <= QFont::ExtraBold) + return WEIGHT_ULTRABOLD; + return WEIGHT_BLACK; +} + +FontWidth Qt5FontFace::toFontWidth(const int nStretch) +{ + if (nStretch == 0) // QFont::AnyStretch since Qt 5.8 + return WIDTH_DONTKNOW; + if (nStretch <= QFont::UltraCondensed) + return WIDTH_ULTRA_CONDENSED; + if (nStretch <= QFont::ExtraCondensed) + return WIDTH_EXTRA_CONDENSED; + if (nStretch <= QFont::Condensed) + return WIDTH_CONDENSED; + if (nStretch <= QFont::SemiCondensed) + return WIDTH_SEMI_CONDENSED; + if (nStretch <= QFont::Unstretched) + return WIDTH_NORMAL; + if (nStretch <= QFont::SemiExpanded) + return WIDTH_SEMI_EXPANDED; + if (nStretch <= QFont::Expanded) + return WIDTH_EXPANDED; + if (nStretch <= QFont::ExtraExpanded) + return WIDTH_EXTRA_EXPANDED; + return WIDTH_ULTRA_EXPANDED; +} + +FontItalic Qt5FontFace::toFontItalic(const QFont::Style eStyle) +{ + switch (eStyle) { - case QFont::Thin: - eWeight = WEIGHT_THIN; - break; - case QFont::ExtraLight: - eWeight = WEIGHT_ULTRALIGHT; - break; - case QFont::Light: - eWeight = WEIGHT_LIGHT; - break; - case QFont::Normal: - eWeight = WEIGHT_NORMAL; - break; - case QFont::Medium: - eWeight = WEIGHT_MEDIUM; - break; - case QFont::DemiBold: - eWeight = WEIGHT_SEMIBOLD; - break; - case QFont::Bold: - eWeight = WEIGHT_BOLD; - break; - case QFont::ExtraBold: - eWeight = WEIGHT_ULTRABOLD; - break; - case QFont::Black: - eWeight = WEIGHT_BLACK; - break; + case QFont::StyleNormal: + return ITALIC_NONE; + case QFont::StyleItalic: + return ITALIC_NORMAL; + case QFont::StyleOblique: + return ITALIC_OBLIQUE; } - return eWeight; + + return ITALIC_NONE; } void Qt5FontFace::fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA) @@ -91,20 +114,9 @@ void Qt5FontFace::fillAttributesFromQFont(const QFont& rFont, FontAttributes& rF rFA.SetSymbolFlag(true); rFA.SetStyleName(toOUString(aFontInfo.styleName())); rFA.SetPitch(aFontInfo.fixedPitch() ? PITCH_FIXED : PITCH_VARIABLE); - rFA.SetWeight(fromQFontWeight(aFontInfo.weight())); - - switch (aFontInfo.style()) - { - case QFont::StyleNormal: - rFA.SetItalic(ITALIC_NONE); - break; - case QFont::StyleItalic: - rFA.SetItalic(ITALIC_NORMAL); - break; - case QFont::StyleOblique: - rFA.SetItalic(ITALIC_OBLIQUE); - break; - } + rFA.SetWeight(Qt5FontFace::toFontWeight(aFontInfo.weight())); + rFA.SetItalic(Qt5FontFace::toFontItalic(aFontInfo.style())); + rFA.SetWidthType(Qt5FontFace::toFontWidth(rFont.stretch())); } Qt5FontFace* Qt5FontFace::fromQFont(const QFont& rFont) @@ -123,7 +135,7 @@ Qt5FontFace* Qt5FontFace::fromQFontDatabase(const QString& aFamily, const QStrin aFA.SetSymbolFlag(true); aFA.SetStyleName(toOUString(aStyle)); aFA.SetPitch(aFDB.isFixedPitch(aFamily, aStyle) ? PITCH_FIXED : PITCH_VARIABLE); - aFA.SetWeight(fromQFontWeight(aFDB.weight(aFamily, aStyle))); + aFA.SetWeight(Qt5FontFace::toFontWeight(aFDB.weight(aFamily, aStyle))); aFA.SetItalic(aFDB.italic(aFamily, aStyle) ? ITALIC_NORMAL : ITALIC_NONE); return new Qt5FontFace(aFA, aFamily + "," + aStyle); } diff --git a/vcl/unx/kf5/KF5SalFrame.cxx b/vcl/unx/kf5/KF5SalFrame.cxx index 27503444a0a1..cc08b9c07748 100644 --- a/vcl/unx/kf5/KF5SalFrame.cxx +++ b/vcl/unx/kf5/KF5SalFrame.cxx @@ -28,6 +28,7 @@ #include <KConfigGroup> #include <KSharedConfig> +#include <Qt5FontFace.hxx> #include "KF5SalFrame.hxx" #include <tools/color.hxx> @@ -62,44 +63,9 @@ static vcl::Font toFont(const QFont& rQFont, const css::lang::Locale& rLocale) strlen(static_cast<const char*>(rQFont.family().toUtf8())), RTL_TEXTENCODING_UTF8); - // set italic - aInfo.m_eItalic = (qFontInfo.italic() ? ITALIC_NORMAL : ITALIC_NONE); - - // set weight - int nWeight = qFontInfo.weight(); - if (nWeight <= QFont::Light) - aInfo.m_eWeight = WEIGHT_LIGHT; - else if (nWeight <= QFont::Normal) - aInfo.m_eWeight = WEIGHT_NORMAL; - else if (nWeight <= QFont::DemiBold) - aInfo.m_eWeight = WEIGHT_SEMIBOLD; - else if (nWeight <= QFont::Bold) - aInfo.m_eWeight = WEIGHT_BOLD; - else - aInfo.m_eWeight = WEIGHT_ULTRABOLD; - - // set width - int nStretch = rQFont.stretch(); - if (nStretch == 0) // QFont::AnyStretch since Qt 5.8 - aInfo.m_eWidth = WIDTH_DONTKNOW; - else if (nStretch <= QFont::UltraCondensed) - aInfo.m_eWidth = WIDTH_ULTRA_CONDENSED; - else if (nStretch <= QFont::ExtraCondensed) - aInfo.m_eWidth = WIDTH_EXTRA_CONDENSED; - else if (nStretch <= QFont::Condensed) - aInfo.m_eWidth = WIDTH_CONDENSED; - else if (nStretch <= QFont::SemiCondensed) - aInfo.m_eWidth = WIDTH_SEMI_CONDENSED; - else if (nStretch <= QFont::Unstretched) - aInfo.m_eWidth = WIDTH_NORMAL; - else if (nStretch <= QFont::SemiExpanded) - aInfo.m_eWidth = WIDTH_SEMI_EXPANDED; - else if (nStretch <= QFont::Expanded) - aInfo.m_eWidth = WIDTH_EXPANDED; - else if (nStretch <= QFont::ExtraExpanded) - aInfo.m_eWidth = WIDTH_EXTRA_EXPANDED; - else - aInfo.m_eWidth = WIDTH_ULTRA_EXPANDED; + aInfo.m_eItalic = Qt5FontFace::toFontItalic(qFontInfo.style()); + aInfo.m_eWeight = Qt5FontFace::toFontWeight(qFontInfo.weight()); + aInfo.m_eWidth = Qt5FontFace::toFontWidth(rQFont.stretch()); SAL_INFO("vcl.kf5", "font name BEFORE system match: \"" << aInfo.m_aFamilyName << "\""); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits