[Libreoffice-commits] core.git: Branch 'private/jmux/qt5_fixes' - 2 commits - vcl/qt5

Jan-Marek Glogowski glogow at fbihome.de
Mon Apr 16 13:51:39 UTC 2018


 vcl/qt5/Qt5Font.cxx          |   15 +++++++++++++++
 vcl/qt5/Qt5FontFace.cxx      |   32 +++++++++++++++++++++++---------
 vcl/qt5/Qt5FontFace.hxx      |    1 +
 vcl/qt5/Qt5Graphics_Text.cxx |   31 ++++++++++++++++++++++++++++---
 vcl/qt5/Qt5Instance.cxx      |    2 +-
 vcl/qt5/Qt5Tools.hxx         |    2 +-
 6 files changed, 69 insertions(+), 14 deletions(-)

New commits:
commit 6370749eb2e9b476d672542a08a25c95b829d365
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Mon Apr 16 13:37:07 2018 +0000

    Use fontconfig for font substitution
    
    This just shoves all known fonts from the PrintFontManager into
    the QFontDatabase. Can be disabled using SAL_VCL_QT5_NO_FONTCONFIG.
    It already feels slow - don't know.
    
    Running "./bin/run vcldemo --show text" you can see it has some
    pro and cons, regarding the output. Qts' diacrits look definitly
    nicer then the "substitutions". This brings the font support kind
    of on par with the other backends.
    
    And since sensible font substitition is not at all implemented in
    Qt, we have to rely on some platform ssolution anyway. And this
    needs a sensible, platform agnostic interface, so we can reuse the
    code easier.
    
    Change-Id: I4e9d8ee98fc479a7c4bbe4c968116e0a102ebb7a

diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx
index f690889f777f..3c551c52855e 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -23,6 +23,8 @@
 #include "Qt5Painter.hxx"
 
 #include <vcl/fontcharmap.hxx>
+#include <unx/geninst.h>
+#include <unx/fontmanager.hxx>
 
 #include <CommonSalLayout.hxx>
 #include <PhysicalFontCollection.hxx>
@@ -97,11 +99,33 @@ bool Qt5Graphics::GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities)
 
 void Qt5Graphics::GetDevFontList(PhysicalFontCollection* pPFC)
 {
+    static const bool bUseFontconfig = (nullptr == getenv("SAL_VCL_QT5_NO_FONTCONFIG"));
+
     m_pFontCollection = pPFC;
     if (pPFC->Count())
         return;
 
     QFontDatabase aFDB;
+
+    if (bUseFontconfig)
+    {
+        ::std::vector< psp::fontID > aList;
+        psp::FastPrintFontInfo aInfo;
+
+        psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
+        rMgr.getFontList( aList );
+        for (auto const& elem : aList)
+        {
+            if (!rMgr.getFontFastInfo(elem, aInfo))
+                continue;
+            QString aFilename = toQString(OStringToOUString(
+                rMgr.getFontFileSysPath(aInfo.m_nID), RTL_TEXTENCODING_UTF8));
+            aFDB.addApplicationFont(aFilename);
+        }
+
+        SalGenericInstance::RegisterFontSubstitutors(pPFC);
+    }
+
     for (auto& family : aFDB.families())
         for (auto& style : aFDB.styles(family))
         {
diff --git a/vcl/qt5/Qt5Instance.cxx b/vcl/qt5/Qt5Instance.cxx
index dc09bc017307..59d1b5d0836f 100644
--- a/vcl/qt5/Qt5Instance.cxx
+++ b/vcl/qt5/Qt5Instance.cxx
@@ -264,7 +264,7 @@ VCLPLUG_QT5_PUBLIC SalInstance* create_SalInstance()
 
     QApplication::setQuitOnLastWindowClosed(false);
 
-    const bool bUseCairo = (nullptr != getenv("SAL_VCL_QT5_USE_CAIRO"));
+    static const bool bUseCairo = (nullptr != getenv("SAL_VCL_QT5_USE_CAIRO"));
     Qt5Instance* pInstance = new Qt5Instance(new SalYieldMutex(), bUseCairo);
 
     // initialize SalData
commit 2926914466dc46957b2515491e378700aea7b983
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Mon Apr 16 12:38:42 2018 +0000

    More fixes
    
    Change-Id: Iebf3bcaecd0a5ee0185cd8c90e02bfc5a259f2fb

diff --git a/vcl/qt5/Qt5Font.cxx b/vcl/qt5/Qt5Font.cxx
index 6430c2e55066..0482a8374c5e 100644
--- a/vcl/qt5/Qt5Font.cxx
+++ b/vcl/qt5/Qt5Font.cxx
@@ -52,6 +52,21 @@ Qt5Font::Qt5Font(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP)
     setFamily( toQString(rPFF.GetFamilyName()) );
     setWeight( GetQFontWeight(rPFF.GetWeight()) );
     setPixelSize( rFSP.mnHeight );
+    switch( rFSP.GetItalic() )
+    {
+    case ITALIC_DONTKNOW:
+    case FontItalic_FORCE_EQUAL_SIZE:
+        break;
+    case ITALIC_NONE:
+        setStyle(Style::StyleNormal);
+        break;
+    case ITALIC_OBLIQUE:
+        setStyle(Style::StyleOblique);
+        break;
+    case ITALIC_NORMAL:
+        setStyle(Style::StyleItalic);
+        break;
+    }
 }
 
 Qt5Font::~Qt5Font() {}
diff --git a/vcl/qt5/Qt5FontFace.cxx b/vcl/qt5/Qt5FontFace.cxx
index 9ffa51cb4aac..8a91ce8fc6e6 100644
--- a/vcl/qt5/Qt5FontFace.cxx
+++ b/vcl/qt5/Qt5FontFace.cxx
@@ -41,16 +41,17 @@ Qt5FontFace::Qt5FontFace(const Qt5FontFace& rSrc)
         m_xCharMap = rSrc.m_xCharMap;
 }
 
-Qt5FontFace* Qt5FontFace::fromQFont(const QFont& rFont)
+void Qt5FontFace::fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA)
 {
-    FontAttributes aFA;
     QFontInfo aFontInfo(rFont);
-    aFA.SetFamilyName(toOUString(aFontInfo.family()));
-    aFA.SetStyleName(toOUString(aFontInfo.styleName()));
-    aFA.SetItalic(aFontInfo.italic() ? ITALIC_NORMAL : ITALIC_NONE);
-    aFA.SetPitch(aFontInfo.fixedPitch() ? PITCH_FIXED : PITCH_VARIABLE);
 
-    FontWeight eWeight;
+    rFA.SetFamilyName(toOUString(aFontInfo.family()));
+    if (IsStarSymbol(toOUString(aFontInfo.family())))
+        rFA.SetSymbolFlag(true);
+    rFA.SetStyleName(toOUString(aFontInfo.styleName()));
+    rFA.SetPitch(aFontInfo.fixedPitch() ? PITCH_FIXED : PITCH_VARIABLE);
+
+    FontWeight eWeight = WEIGHT_DONTKNOW;
     switch( aFontInfo.weight() )
     {
     case QFont::Thin: eWeight = WEIGHT_THIN; break;
@@ -63,10 +64,23 @@ Qt5FontFace* Qt5FontFace::fromQFont(const QFont& rFont)
     case QFont::ExtraBold: eWeight = WEIGHT_ULTRABOLD; break;
     case QFont::Black: eWeight = WEIGHT_BLACK; break;
     }
-    aFA.SetWeight(eWeight);
+    rFA.SetWeight(eWeight);
+
+    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;
+    }
 
-    SAL_INFO("vcl.qt5.font", toOUString(aFontInfo.family()) << " " << aFontInfo.weight() << " => " << (int) eWeight );
+    SAL_INFO("vcl.qt5.font", toOUString(aFontInfo.family()) << " "
+        << aFontInfo.weight() << " => " << (int) eWeight );
+}
 
+Qt5FontFace* Qt5FontFace::fromQFont(const QFont& rFont)
+{
+    FontAttributes aFA;
+    fillAttributesFromQFont(rFont, aFA);
     return new Qt5FontFace(aFA, rFont.toString());
 }
 
diff --git a/vcl/qt5/Qt5FontFace.hxx b/vcl/qt5/Qt5FontFace.hxx
index 9468cf15b4e3..453bebbe5e68 100644
--- a/vcl/qt5/Qt5FontFace.hxx
+++ b/vcl/qt5/Qt5FontFace.hxx
@@ -37,6 +37,7 @@ public:
     virtual ~Qt5FontFace() override;
 
     static Qt5FontFace* fromQFont(const QFont& rFont);
+    static void fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA);
 
     PhysicalFontFace* Clone() const override;
     sal_IntPtr GetFontId() const override;
diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx
index d66e85553fff..f690889f777f 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -58,6 +58,10 @@ void Qt5Graphics::SetFont(const FontSelectPattern* pReqFont, int nFallbackLevel)
 void Qt5Graphics::GetFontMetric(ImplFontMetricDataRef& rFMD, int nFallbackLevel)
 {
     QRawFont aRawFont(QRawFont::fromFont(*m_pTextStyle[nFallbackLevel]));
+    Qt5FontFace::fillAttributesFromQFont(*m_pTextStyle[nFallbackLevel], *rFMD);
+
+    rFMD->SetSlant(0);
+    rFMD->SetWidth(aRawFont.averageCharWidth());
 
     QByteArray aHheaTable = aRawFont.fontTable("hhea");
     std::vector<uint8_t> rHhea(aHheaTable.data(), aHheaTable.data() + aHheaTable.size());
@@ -67,9 +71,6 @@ void Qt5Graphics::GetFontMetric(ImplFontMetricDataRef& rFMD, int nFallbackLevel)
 
     rFMD->ImplCalcLineSpacing(rHhea, rOS2, aRawFont.unitsPerEm());
 
-    rFMD->SetSlant( 0 );
-    rFMD->SetWidth(aRawFont.averageCharWidth());
-
     const QChar nKashidaCh = 0x0640;
     int nNumGlyphs = 1;
     quint32 nKashidaGid;
diff --git a/vcl/qt5/Qt5Tools.hxx b/vcl/qt5/Qt5Tools.hxx
index c7b47014beb0..6aa910f575d6 100644
--- a/vcl/qt5/Qt5Tools.hxx
+++ b/vcl/qt5/Qt5Tools.hxx
@@ -48,7 +48,7 @@ inline QRect toQRect(const tools::Rectangle& rRect)
 
 inline tools::Rectangle toRectangle(const QRect& rRect)
 {
-    return tools::Rectangle(rRect.left(), rRect.top(), rRect.width(), rRect.height());
+    return tools::Rectangle(rRect.left(), rRect.top(), rRect.right(), rRect.bottom());
 }
 
 inline QSize toQSize(const Size& rSize) { return QSize(rSize.Width(), rSize.Height()); }


More information about the Libreoffice-commits mailing list