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@fbihome.de>
diff --git a/vcl/inc/qt5/Qt5FontFace.hxx b/vcl/inc/qt5/Qt5FontFace.hxx
index 4f8f968..350abd5 100644
--- a/vcl/inc/qt5/Qt5FontFace.hxx
+++ b/vcl/inc/qt5/Qt5FontFace.hxx
@@ -35,6 +35,7 @@
{
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 e7b6a6eb..ec30460 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 @@
        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 @@
            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 @@
    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 693f67fe..510aa50 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -124,11 +124,7 @@

    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() {}