[Libreoffice-commits] core.git: vcl/inc vcl/qt5

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Sat Mar 23 12:57:20 UTC 2019


 vcl/inc/qt5/Qt5FontFace.hxx  |    1 +
 vcl/qt5/Qt5FontFace.cxx      |   41 ++++++++++++++++++++++++++++++-----------
 vcl/qt5/Qt5Graphics_Text.cxx |    6 +-----
 3 files changed, 32 insertions(+), 16 deletions(-)

New commits:
commit 3519325b7d1fa80220f52b74bce3dd75eb220038
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sat Mar 23 05:30:33 2019 +0000
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Sat Mar 23 13:56:48 2019 +0100

    tdf#123072 Qt5 just use data from QFontDatabase
    
    This way we can skip the intermediate QFont creation, which takes
    a much longer. The database information is actually sufficient.
    
    Change-Id: Ie5ab163edf6a1712d45b0738bb2e4822f2e3298c
    Reviewed-on: https://gerrit.libreoffice.org/69579
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/qt5/Qt5FontFace.hxx b/vcl/inc/qt5/Qt5FontFace.hxx
index 4f8f968700f9..350abd593d6a 100644
--- a/vcl/inc/qt5/Qt5FontFace.hxx
+++ b/vcl/inc/qt5/Qt5FontFace.hxx
@@ -35,6 +35,7 @@ class Qt5FontFace : public PhysicalFontFace
 {
 public:
     static Qt5FontFace* fromQFont(const QFont& rFont);
+    static Qt5FontFace* fromQFontDatabase(const QString& aFamily, const QString& aStyle);
     static void fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA);
 
     sal_IntPtr GetFontId() const override;
diff --git a/vcl/qt5/Qt5FontFace.cxx b/vcl/qt5/Qt5FontFace.cxx
index e7b6a6ebf9b7..ec304603b2f1 100644
--- a/vcl/qt5/Qt5FontFace.cxx
+++ b/vcl/qt5/Qt5FontFace.cxx
@@ -32,6 +32,7 @@
 #include <PhysicalFontCollection.hxx>
 
 #include <QtGui/QFont>
+#include <QtGui/QFontDatabase>
 #include <QtGui/QFontInfo>
 #include <QtGui/QRawFont>
 
@@ -45,18 +46,10 @@ Qt5FontFace::Qt5FontFace(const Qt5FontFace& rSrc)
         m_xCharMap = rSrc.m_xCharMap;
 }
 
-void Qt5FontFace::fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA)
+static FontWeight fromQFontWeight(int nWeight)
 {
-    QFontInfo aFontInfo(rFont);
-
-    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())
+    switch (nWeight)
     {
         case QFont::Thin:
             eWeight = WEIGHT_THIN;
@@ -86,7 +79,19 @@ void Qt5FontFace::fillAttributesFromQFont(const QFont& rFont, FontAttributes& rF
             eWeight = WEIGHT_BLACK;
             break;
     }
-    rFA.SetWeight(eWeight);
+    return eWeight;
+}
+
+void Qt5FontFace::fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA)
+{
+    QFontInfo aFontInfo(rFont);
+
+    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);
+    rFA.SetWeight(fromQFontWeight(aFontInfo.weight()));
 
     switch (aFontInfo.style())
     {
@@ -109,6 +114,20 @@ Qt5FontFace* Qt5FontFace::fromQFont(const QFont& rFont)
     return new Qt5FontFace(aFA, rFont.toString());
 }
 
+Qt5FontFace* Qt5FontFace::fromQFontDatabase(const QString& aFamily, const QString& aStyle)
+{
+    QFontDatabase aFDB;
+    FontAttributes aFA;
+    aFA.SetFamilyName(toOUString(aFamily));
+    if (IsStarSymbol(aFA.GetFamilyName()))
+        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.SetItalic(aFDB.italic(aFamily, aStyle) ? ITALIC_NORMAL : ITALIC_NONE);
+    return new Qt5FontFace(aFA, aFamily + "," + aStyle);
+}
+
 Qt5FontFace::Qt5FontFace(const FontAttributes& rFA, const QString& rFontID)
     : PhysicalFontFace(rFA)
     , m_aFontId(rFontID)
diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx
index 693f67fe2df0..510aa5053237 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -124,11 +124,7 @@ void Qt5Graphics::GetDevFontList(PhysicalFontCollection* pPFC)
 
     for (auto& family : aFDB.families())
         for (auto& style : aFDB.styles(family))
-        {
-            // Just get any size - we don't care
-            QList<int> sizes = aFDB.smoothSizes(family, style);
-            pPFC->Add(Qt5FontFace::fromQFont(aFDB.font(family, style, *sizes.begin())));
-        }
+            pPFC->Add(Qt5FontFace::fromQFontDatabase(family, style));
 }
 
 void Qt5Graphics::ClearDevFontCache() {}


More information about the Libreoffice-commits mailing list