135360
From 1c485d2af28ed27f8cdb174d82f4a6199a23e72e Mon Sep 17 00:00:00 2001
135360
From: Mihai Varga <mihai.varga@collabora.com>
135360
Date: Thu, 10 Sep 2015 11:31:48 +0300
135360
Subject: [PATCH 106/398] LOK: getFonts method
135360
135360
Returns a json mapping of the available fonts to their possible font
135360
sizes
135360
135360
Change-Id: I80c0bdd79e3ef2d814f64b8d38143d6c2b9ca720
135360
(cherry picked from commit 1806882317af1162edce5c2389c9c5eeb18455ac)
135360
---
135360
 desktop/qa/desktop_lib/test_desktop_lib.cxx | 22 +++++++++++++
135360
 desktop/source/lib/init.cxx                 | 48 ++++++++++++++++++++++++++++-
135360
 2 files changed, 69 insertions(+), 1 deletion(-)
135360
135360
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
index 842d209f8fb3..a08961403aac 100644
135360
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
@@ -49,6 +49,7 @@ public:
135360
 
135360
     void runAllTests();
135360
     void testGetStyles();
135360
+    void testGetFonts();
135360
 
135360
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
135360
     CPPUNIT_TEST(runAllTests);
135360
@@ -81,6 +82,7 @@ void DesktopLOKTest::closeDoc()
135360
 void DesktopLOKTest::runAllTests()
135360
 {
135360
     testGetStyles();
135360
+    testGetFonts();
135360
 }
135360
 
135360
 void DesktopLOKTest::testGetStyles()
135360
@@ -112,6 +114,26 @@ void DesktopLOKTest::testGetStyles()
135360
     closeDoc();
135360
 }
135360
 
135360
+void DesktopLOKTest::testGetFonts()
135360
+{
135360
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
135360
+    boost::property_tree::ptree aTree;
135360
+    char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:CharFontName");
135360
+    std::stringstream aStream(pJSON);
135360
+    boost::property_tree::read_json(aStream, aTree);
135360
+    CPPUNIT_ASSERT( aTree.size() > 0 );
135360
+    CPPUNIT_ASSERT( aTree.get_child("commandName").get_value<std::string>() == ".uno:CharFontName" );
135360
+
135360
+    boost::property_tree::ptree aValues = aTree.get_child("commandValues");
135360
+    CPPUNIT_ASSERT( aValues.size() > 0 );
135360
+    for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aValues)
135360
+    {
135360
+        // check that we have font sizes available for each font
135360
+        CPPUNIT_ASSERT( rPair.second.size() > 0);
135360
+    }
135360
+    closeDoc();
135360
+}
135360
+
135360
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
135360
 
135360
 CPPUNIT_PLUGIN_IMPLEMENT();
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index 7a020d142ddc..be1a01867cf5 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -45,10 +45,15 @@
135360
 #include <com/sun/star/ucb/XContentProvider.hpp>
135360
 #include <com/sun/star/ucb/XUniversalContentBroker.hpp>
135360
 
135360
+#include <editeng/fontitem.hxx>
135360
+#include <editeng/flstitem.hxx>
135360
+#include <sfx2/objsh.hxx>
135360
+#include <svx/svxids.hrc>
135360
 #include <vcl/svapp.hxx>
135360
 #include <vcl/svpforlokit.hxx>
135360
 #include <tools/resmgr.hxx>
135360
 #include <tools/fract.hxx>
135360
+#include <svtools/ctrltool.hxx>
135360
 #include <vcl/graphicfilter.hxx>
135360
 #include <vcl/sysdata.hxx>
135360
 #include <vcl/virdev.hxx>
135360
@@ -864,6 +869,43 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
135360
 
135360
     pDoc->resetSelection();
135360
 }
135360
+static char* getFonts (const char* pCommand)
135360
+{
135360
+    SfxObjectShell* pDocSh = SfxObjectShell::Current();
135360
+    const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>(
135360
+        pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
135360
+    const FontList* pList = pFonts ? pFonts->GetFontList() : 0;
135360
+
135360
+    boost::property_tree::ptree aTree;
135360
+    aTree.put("commandName", pCommand);
135360
+    boost::property_tree::ptree aValues;
135360
+    if ( pList )
135360
+    {
135360
+        sal_uInt16 nFontCount = pList->GetFontNameCount();
135360
+        for (sal_uInt16 i = 0; i < nFontCount; ++i)
135360
+        {
135360
+            boost::property_tree::ptree aChildren;
135360
+            const vcl::FontInfo& rInfo = pList->GetFontName(i);
135360
+            const sal_IntPtr* pAry = pList->GetSizeAry(rInfo);
135360
+            sal_uInt16 nSizeCount = 0;
135360
+            while (pAry[nSizeCount])
135360
+            {
135360
+                boost::property_tree::ptree aChild;
135360
+                aChild.put("", (float)pAry[nSizeCount] / 10);
135360
+                aChildren.push_back(std::make_pair("", aChild));
135360
+                nSizeCount++;
135360
+            }
135360
+            aValues.add_child(rInfo.GetName().toUtf8().getStr(), aChildren);
135360
+        }
135360
+    }
135360
+    aTree.add_child("commandValues", aValues);
135360
+    std::stringstream aStream;
135360
+    boost::property_tree::write_json(aStream, aTree);
135360
+    char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
135360
+    strcpy(pJson, aStream.str().c_str());
135360
+    pJson[aStream.str().size()] = '\0';
135360
+    return pJson;
135360
+}
135360
 
135360
 static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
135360
 {
135360
@@ -901,7 +943,11 @@ static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
135360
 
135360
 static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand)
135360
 {
135360
-    if (!strcmp(pCommand, ".uno:StyleApply"))
135360
+    if (!strcmp(pCommand, ".uno:CharFontName"))
135360
+    {
135360
+        return getFonts(pCommand);
135360
+    }
135360
+    else if (!strcmp(pCommand, ".uno:StyleApply"))
135360
     {
135360
         return getStyles(pThis, pCommand);
135360
     }
135360
-- 
135360
2.12.0
135360