desktop/source/lib/init.cxx |   79 +++++++++++++++++++++++++++++---------------
 1 file changed, 53 insertions(+), 26 deletions(-)

New commits:
commit aaf4613a0aeb9cf7c27c731f2391de14bdcff880
Author:     Michael Meeks <michael.me...@collabora.com>
AuthorDate: Fri May 17 21:25:29 2024 +0100
Commit:     Michael Meeks <michael.me...@collabora.com>
CommitDate: Thu May 23 12:31:46 2024 +0200

    lok: stop amazing waste of repeated font sizes in each font element.
    
    These days all sensible fonts are scalable, so anything else is madness.
    
    With the compact_fonts option we go from:
    
        INCOMING: commandvalues: 
{"commandName":".uno:CharFontName","commandValues":
        {"Albany 
AMT":["6","7","8","9","10","10.5","11","12","13","14","15","16",
        "18","20","21","22","24","26","28","32","36","40","42","44","48","54",
        "60","66","72","80","88","96"],"Amiri":["6","7"
    
                <truncated 58,418 chars>
    
        INCOMING: commandvalues: { "commandName": ".uno:CharFontName", 
"FontNames":
        [ "Albany AMT", "Amiri", "Amiri Quran", "Amiri Quran Colored", "Andale 
Mono",
        "Andale Sans", "Andy MT", "AR PL UMing CN", "AR PL UMing HK", "AR PL 
UMing TW",
        "AR PL UMing TW MBE", "Arial",
    
               <truncated 6,948 chars>
    
    An 8x size win.
    
    Change-Id: I3dc9f5de876def6e4afc09a43105b1740f7c621f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167799
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    (cherry picked from commit 628f56a1802ad76cbe84a9a5590b04ed81a57a9e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167962
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 7730614d6a49..4e484cf71a34 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -252,11 +252,12 @@ extern "C" {
 
 #endif
 
-
 using LanguageToolCfg = 
officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
 
+
 static LibLibreOffice_Impl *gImpl = nullptr;
 static bool lok_preinit_2_called = false;
+static bool gUseCompactFonts = false;
 static std::weak_ptr< LibreOfficeKitClass > gOfficeClass;
 static std::weak_ptr< LibreOfficeKitDocumentClass > gDocumentClass;
 
@@ -6036,7 +6037,7 @@ static char* getLanguages(const char* pCommand)
     return pJson;
 }
 
-static char* getFonts (const char* pCommand)
+static char* getFonts (const char* pCommand, const bool 
bBloatWithRepeatedSizes)
 {
     SfxObjectShell* pDocSh = SfxObjectShell::Current();
     if (!pDocSh)
@@ -6045,36 +6046,60 @@ static char* getFonts (const char* pCommand)
         pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
     const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr;
 
-    boost::property_tree::ptree aTree;
-    aTree.put("commandName", pCommand);
-    boost::property_tree::ptree aValues;
-    if ( pList )
+    if (!bBloatWithRepeatedSizes)
     {
-        sal_uInt16 nFontCount = pList->GetFontNameCount();
-        for (sal_uInt16 i = 0; i < nFontCount; ++i)
+        tools::JsonWriter aJson;
+        aJson.put("commandName", pCommand);
+        if (pList)
+        {
+            auto aFontNames = aJson.startArray("FontNames");
+
+            sal_uInt16 nFontCount = pList->GetFontNameCount();
+            for (sal_uInt16 i = 0; i < nFontCount; ++i)
+                aJson.putSimpleValue(pList->GetFontName(i).GetFamilyName());
+        }
         {
-            boost::property_tree::ptree aChildren;
-            const FontMetric& rFontMetric = pList->GetFontName(i);
+            auto aFontSizes = aJson.startArray("FontSizes");
             const int* pAry = FontList::GetStdSizeAry();
-            sal_uInt16 nSizeCount = 0;
-            while (pAry[nSizeCount])
+            for (sal_uInt16 i = 0; pAry[i]; ++i)
+                
aJson.putSimpleValue(OUString::number(static_cast<float>(pAry[i]) / 10));
+        }
+
+        return convertOString(aJson.finishAndGetAsOString());
+    }
+    else // FIXME: remove nonsensical legacy version
+    {
+        boost::property_tree::ptree aTree;
+        aTree.put("commandName", pCommand);
+        boost::property_tree::ptree aValues;
+        if ( pList )
+        {
+            sal_uInt16 nFontCount = pList->GetFontNameCount();
+            for (sal_uInt16 i = 0; i < nFontCount; ++i)
             {
-                boost::property_tree::ptree aChild;
-                aChild.put("", static_cast<float>(pAry[nSizeCount]) / 10);
-                aChildren.push_back(std::make_pair("", aChild));
-                nSizeCount++;
+                boost::property_tree::ptree aChildren;
+                const FontMetric& rFontMetric = pList->GetFontName(i);
+                const int* pAry = FontList::GetStdSizeAry();
+                sal_uInt16 nSizeCount = 0;
+                while (pAry[nSizeCount])
+                {
+                    boost::property_tree::ptree aChild;
+                    aChild.put("", static_cast<float>(pAry[nSizeCount]) / 10);
+                    aChildren.push_back(std::make_pair("", aChild));
+                    nSizeCount++;
+                }
+                
aValues.add_child(rFontMetric.GetFamilyName().toUtf8().getStr(), aChildren);
             }
-            aValues.add_child(rFontMetric.GetFamilyName().toUtf8().getStr(), 
aChildren);
         }
+        aTree.add_child("commandValues", aValues);
+        std::stringstream aStream;
+        boost::property_tree::write_json(aStream, aTree, false /* pretty */);
+        char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
+        assert(pJson); // Don't handle OOM conditions
+        strcpy(pJson, aStream.str().c_str());
+        pJson[aStream.str().size()] = '
+        return pJson;
     }
-    aTree.add_child("commandValues", aValues);
-    std::stringstream aStream;
-    boost::property_tree::write_json(aStream, aTree, false /* pretty */);
-    char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
-    assert(pJson); // Don't handle OOM conditions
-    strcpy(pJson, aStream.str().c_str());
-    pJson[aStream.str().size()] = '
-    return pJson;
 }
 
 static char* getFontSubset (std::string_view aFontName)
@@ -6371,7 +6396,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* 
pThis, const char* pCo
     }
     else if (aCommand == ".uno:CharFontName")
     {
-        return getFonts(pCommand);
+        return getFonts(pCommand, !gUseCompactFonts);
     }
     else if (aCommand == ".uno:StyleApply")
     {
@@ -7886,6 +7911,8 @@ static int lo_initialize(LibreOfficeKit* pThis, const 
char* pAppPath, const char
         {
             if (it == "unipoll")
                 bUnipoll = true;
+            if (it == "compact_fonts")
+                gUseCompactFonts = true;
             else if (it == "profile_events")
                 bProfileZones = true;
             else if (it == "sc_no_grid_bg")

Reply via email to