From d355207b45755cfe1eef0147bc25ead931741684 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 29 Sep 2015 10:47:31 +0200 Subject: lok: add Document::getPartPageRectangles() Change-Id: I20acd44f7a81471982ba96ad3894a9124e035c5f --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 25 +++++++++++++++++++++++++ desktop/source/lib/init.cxx | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'desktop') diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index d7b93472c1b5..a7696d824bee 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -52,12 +52,14 @@ public: void testGetFonts(); void testCreateView(); void testGetFilterTypes(); + void testGetPartPageRectangles(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(testGetStyles); CPPUNIT_TEST(testGetFonts); CPPUNIT_TEST(testCreateView); CPPUNIT_TEST(testGetFilterTypes); + CPPUNIT_TEST(testGetPartPageRectangles); CPPUNIT_TEST_SUITE_END(); uno::Reference mxComponent; @@ -152,6 +154,29 @@ void DesktopLOKTest::testCreateView() closeDoc(); } +void DesktopLOKTest::testGetPartPageRectangles() +{ + // Test that we get as many page rectangles as expected: blank document is + // one page. + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + char* pRectangles = pDocument->pClass->getPartPageRectangles(pDocument); + OUString sRectangles = OUString::fromUtf8(pRectangles); + + std::vector aRectangles; + sal_Int32 nIndex = 0; + do + { + OUString aRectangle = sRectangles.getToken(0, ';', nIndex); + if (!aRectangle.isEmpty()) + aRectangles.push_back(aRectangle); + } + while (nIndex >= 0); + CPPUNIT_ASSERT_EQUAL(static_cast(1), aRectangles.size()); + + free(pRectangles); + closeDoc(); +} + void DesktopLOKTest::testGetFilterTypes() { LibLibreOffice_Impl aOffice; diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index b581bca5d011..509983c1c8ac 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -204,6 +204,7 @@ static void doc_destroy(LibreOfficeKitDocument* pThis); static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* pUrl, const char* pFormat, const char* pFilterOptions); static int doc_getDocumentType(LibreOfficeKitDocument* pThis); static int doc_getParts(LibreOfficeKitDocument* pThis); +static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis); static int doc_getPart(LibreOfficeKitDocument* pThis); static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart); static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart); @@ -266,6 +267,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference saveAs = doc_saveAs; m_pDocumentClass->getDocumentType = doc_getDocumentType; m_pDocumentClass->getParts = doc_getParts; + m_pDocumentClass->getPartPageRectangles = doc_getPartPageRectangles; m_pDocumentClass->getPart = doc_getPart; m_pDocumentClass->setPart = doc_setPart; m_pDocumentClass->getPartName = doc_getPartName; @@ -659,6 +661,23 @@ static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart) pDoc->setPart( nPart ); } +static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis) +{ + ITiledRenderable* pDoc = getTiledRenderable(pThis); + if (!pDoc) + { + gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering"; + return 0; + } + + OUString sRectangles = pDoc->getPartPageRectangles(); + OString aString = OUStringToOString(sRectangles, RTL_TEXTENCODING_UTF8); + char* pMemory = static_cast(malloc(aString.getLength() + 1)); + strcpy(pMemory, aString.getStr()); + return pMemory; + +} + static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart) { ITiledRenderable* pDoc = getTiledRenderable(pThis); -- cgit