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