[Libreoffice-commits] core.git: 2 commits - desktop/qa desktop/source include/LibreOfficeKit
Mihai Varga
mihai.varga at collabora.com
Thu Sep 10 01:46:04 PDT 2015
desktop/qa/desktop_lib/test_desktop_lib.cxx | 29 ++++++++++-
desktop/source/lib/init.cxx | 70 ++++++++++++++++++++++++++--
include/LibreOfficeKit/LibreOfficeKit.h | 2
include/LibreOfficeKit/LibreOfficeKit.hxx | 9 ++-
4 files changed, 100 insertions(+), 10 deletions(-)
New commits:
commit 1806882317af1162edce5c2389c9c5eeb18455ac
Author: Mihai Varga <mihai.varga at collabora.com>
Date: Thu Sep 10 11:31:48 2015 +0300
LOK: getFonts method
Returns a json mapping of the available fonts to their possible font
sizes
Change-Id: I80c0bdd79e3ef2d814f64b8d38143d6c2b9ca720
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 842d209..a089614 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -49,6 +49,7 @@ public:
void runAllTests();
void testGetStyles();
+ void testGetFonts();
CPPUNIT_TEST_SUITE(DesktopLOKTest);
CPPUNIT_TEST(runAllTests);
@@ -81,6 +82,7 @@ void DesktopLOKTest::closeDoc()
void DesktopLOKTest::runAllTests()
{
testGetStyles();
+ testGetFonts();
}
void DesktopLOKTest::testGetStyles()
@@ -112,6 +114,26 @@ void DesktopLOKTest::testGetStyles()
closeDoc();
}
+void DesktopLOKTest::testGetFonts()
+{
+ LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
+ boost::property_tree::ptree aTree;
+ char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:CharFontName");
+ std::stringstream aStream(pJSON);
+ boost::property_tree::read_json(aStream, aTree);
+ CPPUNIT_ASSERT( aTree.size() > 0 );
+ CPPUNIT_ASSERT( aTree.get_child("commandName").get_value<std::string>() == ".uno:CharFontName" );
+
+ boost::property_tree::ptree aValues = aTree.get_child("commandValues");
+ CPPUNIT_ASSERT( aValues.size() > 0 );
+ for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aValues)
+ {
+ // check that we have font sizes available for each font
+ CPPUNIT_ASSERT( rPair.second.size() > 0);
+ }
+ closeDoc();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 7a020d1..be1a018 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -45,10 +45,15 @@
#include <com/sun/star/ucb/XContentProvider.hpp>
#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
+#include <editeng/fontitem.hxx>
+#include <editeng/flstitem.hxx>
+#include <sfx2/objsh.hxx>
+#include <svx/svxids.hrc>
#include <vcl/svapp.hxx>
#include <vcl/svpforlokit.hxx>
#include <tools/resmgr.hxx>
#include <tools/fract.hxx>
+#include <svtools/ctrltool.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/virdev.hxx>
@@ -864,6 +869,43 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
pDoc->resetSelection();
}
+static char* getFonts (const char* pCommand)
+{
+ SfxObjectShell* pDocSh = SfxObjectShell::Current();
+ const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>(
+ pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
+ const FontList* pList = pFonts ? pFonts->GetFontList() : 0;
+
+ 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 aChildren;
+ const vcl::FontInfo& rInfo = pList->GetFontName(i);
+ const sal_IntPtr* pAry = pList->GetSizeAry(rInfo);
+ sal_uInt16 nSizeCount = 0;
+ while (pAry[nSizeCount])
+ {
+ boost::property_tree::ptree aChild;
+ aChild.put("", (float)pAry[nSizeCount] / 10);
+ aChildren.push_back(std::make_pair("", aChild));
+ nSizeCount++;
+ }
+ aValues.add_child(rInfo.GetName().toUtf8().getStr(), aChildren);
+ }
+ }
+ aTree.add_child("commandValues", aValues);
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
+ strcpy(pJson, aStream.str().c_str());
+ pJson[aStream.str().size()] = '\0';
+ return pJson;
+}
static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
{
@@ -901,7 +943,11 @@ static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand)
{
- if (!strcmp(pCommand, ".uno:StyleApply"))
+ if (!strcmp(pCommand, ".uno:CharFontName"))
+ {
+ return getFonts(pCommand);
+ }
+ else if (!strcmp(pCommand, ".uno:StyleApply"))
{
return getStyles(pThis, pCommand);
}
commit 39975c477a38be613e9e162acb6de241999f0ae1
Author: Mihai Varga <mihai.varga at collabora.com>
Date: Thu Sep 10 09:21:45 2015 +0300
LOK: added a general getCommandValues method
This method returns a JSON mapping of the posible values for the given
command (e.g. .uno:StyleApply, etc).
returns:
{commandName: "cmdName", commandValues: {json_of_cmd_values}}
I've fixed the unit test this time
Change-Id: I30b0fba8ba1db33dd79f4b46026d293b9ea72402
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index c88a53f..842d209 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -87,12 +87,15 @@ void DesktopLOKTest::testGetStyles()
{
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
boost::property_tree::ptree aTree;
- char* pJSON = pDocument->m_pDocumentClass->getStyles(pDocument);
+ char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:StyleApply");
std::stringstream aStream(pJSON);
boost::property_tree::read_json(aStream, aTree);
CPPUNIT_ASSERT( aTree.size() > 0 );
+ CPPUNIT_ASSERT( aTree.get_child("commandName").get_value<std::string>() == ".uno:StyleApply" );
- for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree)
+ boost::property_tree::ptree aValues = aTree.get_child("commandValues");
+ CPPUNIT_ASSERT( aValues.size() > 0 );
+ for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aValues)
{
CPPUNIT_ASSERT( rPair.second.size() > 0);
if (rPair.first != "CharacterStyles" &&
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index a20decd..7a020d1 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -235,7 +235,7 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
int nX,
int nY);
static void doc_resetSelection (LibreOfficeKitDocument* pThis);
-static char* doc_getStyles(LibreOfficeKitDocument* pThis);
+static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
@@ -266,7 +266,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->getTextSelection = doc_getTextSelection;
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection;
- m_pDocumentClass->getStyles = doc_getStyles;
+ m_pDocumentClass->getCommandValues = doc_getCommandValues;
gDocumentClass = m_pDocumentClass;
}
@@ -865,15 +865,17 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
pDoc->resetSelection();
}
-static char* doc_getStyles(LibreOfficeKitDocument* pThis)
+static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
{
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
boost::property_tree::ptree aTree;
+ aTree.put("commandName", pCommand);
uno::Reference<css::style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(pDocument->mxComponent, uno::UNO_QUERY);
uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
uno::Sequence<OUString> aStyleFamilies = xStyleFamilies->getElementNames();
+ boost::property_tree::ptree aValues;
for (sal_Int32 nStyleFam = 0; nStyleFam < aStyleFamilies.getLength(); ++nStyleFam)
{
boost::property_tree::ptree aChildren;
@@ -886,8 +888,9 @@ static char* doc_getStyles(LibreOfficeKitDocument* pThis)
aChild.put("", aStyles[nInd]);
aChildren.push_back(std::make_pair("", aChild));
}
- aTree.add_child(sStyleFam.toUtf8().getStr(), aChildren);
+ aValues.add_child(sStyleFam.toUtf8().getStr(), aChildren);
}
+ aTree.add_child("commandValues", aValues);
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
@@ -895,6 +898,19 @@ static char* doc_getStyles(LibreOfficeKitDocument* pThis)
pJson[aStream.str().size()] = '\0';
return pJson;
}
+
+static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand)
+{
+ if (!strcmp(pCommand, ".uno:StyleApply"))
+ {
+ return getStyles(pThis, pCommand);
+ }
+ else {
+ gImpl->maLastExceptionMsg = "Unknown command, no values returned";
+ return NULL;
+ }
+}
+
static char* lo_getError (LibreOfficeKit *pThis)
{
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index af7155c..8060f0e 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -161,7 +161,7 @@ struct _LibreOfficeKitDocumentClass
void (*resetSelection) (LibreOfficeKitDocument* pThis);
/// @see lok::Document:getStyles
- char* (*getStyles) (LibreOfficeKitDocument* pThis);
+ char* (*getCommandValues) (LibreOfficeKitDocument* pThis, const char* pCommand);
#endif // LOK_USE_UNSTABLE_API
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index c526bda..4459994 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -248,11 +248,14 @@ public:
}
/**
- * Returns a json map, {"familyName1" : ["list of style names in the family1"], etc.}
+ * Returns a json mapping of the possible values for the given command
+ * e.g. {commandName: ".uno:StyleApply", commandValues: {"familyName1" : ["list of style names in the family1"], etc.}}
+ * @param pCommand a uno command for which the possible values are requested
+ * @return {commandName: unoCmd, commandValues: {possible_values}}
*/
- inline char* getStyles()
+ inline char* getCommandValues(const char* pCommand)
{
- return mpDoc->pClass->getStyles(mpDoc);
+ return mpDoc->pClass->getCommandValues(mpDoc, pCommand);
}
#endif // LOK_USE_UNSTABLE_API
};
More information about the Libreoffice-commits
mailing list