Kaydet (Commit) d4c59bf4 authored tarafından Mihai Varga's avatar Mihai Varga Kaydeden (comit) Jan Holesovsky

lok::Document getStyles method

This method returns a JSON mapping of style families to a list of styles
from the corresponding family.
Will be used to know and apply styles in tiledrendering.

Change-Id: I0aa395c40b9573920ade44255f97c077475ae5f1
üst 47c56f96
......@@ -35,11 +35,13 @@
#include <comphelper/processfactory.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/ucb/XContentProvider.hpp>
#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
......@@ -233,6 +235,7 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
int nX,
int nY);
static void doc_resetSelection (LibreOfficeKitDocument* pThis);
static char* doc_getStyles(LibreOfficeKitDocument* pThis);
struct LibLODocument_Impl : public _LibreOfficeKitDocument
{
......@@ -267,6 +270,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
m_pDocumentClass->getTextSelection = doc_getTextSelection;
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection;
m_pDocumentClass->getStyles = doc_getStyles;
gDocumentClass = m_pDocumentClass;
}
......@@ -864,6 +868,36 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
pDoc->resetSelection();
}
static char* doc_getStyles(LibreOfficeKitDocument* pThis)
{
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
boost::property_tree::ptree aTree;
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();
for (sal_Int32 nStyleFam = 0; nStyleFam < aStyleFamilies.getLength(); ++nStyleFam)
{
boost::property_tree::ptree aChildren;
OUString sStyleFam = aStyleFamilies[nStyleFam];
uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(sStyleFam), uno::UNO_QUERY);
uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
for (sal_Int32 nInd = 0; nInd < aStyles.getLength(); ++nInd)
{
boost::property_tree::ptree aChild;
aChild.put("", aStyles[nInd]);
aChildren.push_back(std::make_pair("", aChild));
}
aTree.add_child(sStyleFam.toUtf8().getStr(), aChildren);
}
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* lo_getError (LibreOfficeKit *pThis)
{
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
......
......@@ -159,6 +159,9 @@ struct _LibreOfficeKitDocumentClass
/// @see lok::Document::resetSelection
void (*resetSelection) (LibreOfficeKitDocument* pThis);
/// @see lok::Document:getStyles
char* (*getStyles) (LibreOfficeKitDocument* pThis);
#endif // LOK_USE_UNSTABLE_API
};
......
......@@ -246,6 +246,14 @@ public:
{
mpDoc->pClass->resetSelection(mpDoc);
}
/**
* Returns a json map, {"familyName1" : ["list of style names in the family1"], etc.}
*/
inline char* getStyles()
{
return mpDoc->pClass->getStyles(mpDoc);
}
#endif // LOK_USE_UNSTABLE_API
};
......
......@@ -9,6 +9,7 @@
#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <cppunit/TestFixture.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <cppunit/extensions/HelperMacros.h>
......@@ -67,6 +68,7 @@ public:
void testDocumentTypes( Office* pOffice );
void testImpressSlideNames( Office* pOffice );
void testCalcSheetNames( Office* pOffice );
void testGetStyles( Office* pOffice );
#if 0
void testOverlay( Office* pOffice );
#endif
......@@ -93,6 +95,7 @@ void TiledRenderingTest::runAllTests()
testDocumentTypes( pOffice.get() );
testImpressSlideNames( pOffice.get() );
testCalcSheetNames( pOffice.get() );
testGetStyles( pOffice.get() );
#if 0
testOverlay( pOffice.get() );
#endif
......@@ -181,6 +184,38 @@ void TiledRenderingTest::testCalcSheetNames( Office* pOffice )
CPPUNIT_ASSERT( strcmp( pDocument->getPartName( 2 ), "Sheet3" ) == 0 );
}
void TiledRenderingTest::testGetStyles( Office* pOffice )
{
const string sDocPath = m_sSrcRoot + "/libreofficekit/qa/data/blank_text.odt";
const string sLockFile = m_sSrcRoot +"/libreofficekit/qa/data/.~lock.blank_text.odt#";
// FIXME: LOK will fail when trying to open a locked file
remove( sLockFile.c_str() );
scoped_ptr< Document> pDocument( pOffice->documentLoad( sDocPath.c_str() ) );
boost::property_tree::ptree aTree;
char* pJSON = pDocument->getStyles();
std::stringstream aStream(pJSON);
boost::property_tree::read_json(aStream, aTree);
CPPUNIT_ASSERT( aTree.size() > 0 );
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree)
{
CPPUNIT_ASSERT( rPair.second.size() > 0);
if (rPair.first != "CharacterStyles" &&
rPair.first != "ParagraphStyles" &&
rPair.first != "FrameStyles" &&
rPair.first != "PageStyles" &&
rPair.first != "NumberingStyles" &&
rPair.first != "CellStyles" &&
rPair.first != "ShapeStyles")
{
CPPUNIT_FAIL("Unknown style family: " + rPair.first);
}
}
}
#if 0
static void dumpRGBABitmap( const OUString& rPath, const unsigned char* pBuffer,
const int nWidth, const int nHeight )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment