summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2024-05-17 21:25:29 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-05-18 22:06:18 +0200
commit628f56a1802ad76cbe84a9a5590b04ed81a57a9e (patch)
tree2269fac5e120665d4ec9c0d322b27089fa54d145
parent457f24c004590a28d200fdda79bf468d363fff69 (diff)
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--desktop/source/lib/init.cxx78
1 files changed, 52 insertions, 26 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 9608c5374da7..cb487d641ac8 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -267,11 +267,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;
@@ -6080,7 +6081,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)
@@ -6089,36 +6090,59 @@ 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);
+ {
+ 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()] = '\0';
+ 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()] = '\0';
- return pJson;
}
static char* getFontSubset (std::string_view aFontName)
@@ -6415,7 +6439,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")
{
@@ -7934,6 +7958,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")