sd/CppunitTest_sd_html_export_tests.mk | 118 +++++++++++++++ sd/Module_sd.mk | 1 sd/qa/unit/HtmlExportTest.cxx | 110 ++++++++++++++ sd/qa/unit/data/HtmlExportTestDocument.odp |binary sd/qa/unit/sdmodeltestbase.hxx | 76 +++++++-- sd/source/filter/html/htmlex.cxx | 221 ++++++++++------------------- sd/source/filter/html/htmlex.hxx | 4 sd/source/filter/html/pubdlg.cxx | 27 ++- sd/source/filter/html/pubdlg.src | 20 +- sd/source/ui/inc/pubdlg.hrc | 33 ++-- sd/source/ui/inc/pubdlg.hxx | 1 11 files changed, 422 insertions(+), 189 deletions(-)
New commits: commit f7ea60218ae96cda55dc39073fac807df64f18de Author: Tomaž Vajngerl <[email protected]> Date: Sun Apr 13 23:12:03 2014 +0200 fdo#74079 - sd html export: fix false width values Change-Id: I498310525cf912706d64adb773c951b197b6fc72 diff --git a/sd/source/filter/html/pubdlg.cxx b/sd/source/filter/html/pubdlg.cxx index c79bb43..27189d7 100644 --- a/sd/source/filter/html/pubdlg.cxx +++ b/sd/source/filter/html/pubdlg.cxx @@ -807,11 +807,11 @@ void SdPublishingDlg::GetParameterSequence( Sequence< PropertyValue >& rParams ) // Page 3 aValue.Name = "Width"; - sal_Int32 nTmpWidth = 512; + sal_Int32 nTmpWidth = 640; if( pPage3_Resolution_2->IsChecked() ) - nTmpWidth = 640; - else if( pPage3_Resolution_3->IsChecked() ) nTmpWidth = 800; + else if( pPage3_Resolution_3->IsChecked() ) + nTmpWidth = 1024; aValue.Value <<= nTmpWidth; aProps.push_back( aValue ); commit 24ae12911a38343b29a68eb75ccbb2589dd383cc Author: Tomaž Vajngerl <[email protected]> Date: Sun Apr 13 23:03:00 2014 +0200 sd html export: q&d add single document publish mode Change-Id: Ifa96814eb2664bea082e51bfaa739250718abd1e diff --git a/sd/source/filter/html/pubdlg.cxx b/sd/source/filter/html/pubdlg.cxx index 439844a..c79bb43 100644 --- a/sd/source/filter/html/pubdlg.cxx +++ b/sd/source/filter/html/pubdlg.cxx @@ -400,6 +400,7 @@ SdPublishingDlg::SdPublishingDlg(Window* pWindow, DocumentType eDocType) pPage2_Standard_FB->SetBorderStyle(WINDOW_BORDER_MONO); pPage2_Frames->SetClickHdl(LINK(this,SdPublishingDlg,BaseHdl)); pPage2_Frames_FB->SetBorderStyle(WINDOW_BORDER_MONO); + pPage2_SingleDocument->SetClickHdl(LINK(this,SdPublishingDlg,BaseHdl)); pPage2_Kiosk->SetClickHdl(LINK(this,SdPublishingDlg,BaseHdl)); pPage2_Kiosk_FB->SetBorderStyle(WINDOW_BORDER_MONO); pPage2_WebCast->SetClickHdl(LINK(this,SdPublishingDlg,BaseHdl)); @@ -491,6 +492,8 @@ void SdPublishingDlg::CreatePages() aAssistentFunc.InsertControl(2, pPage2_Frames = new RadioButton(this,SdResId(PAGE2_FRAMES))); aAssistentFunc.InsertControl(2, + pPage2_SingleDocument = new RadioButton(this,SdResId(PAGE2_SINGLE_DOCUMENT))); + aAssistentFunc.InsertControl(2, pPage2_Kiosk = new RadioButton(this,SdResId(PAGE2_KIOSK))); aAssistentFunc.InsertControl(2, pPage2_WebCast = new RadioButton(this,SdResId(PAGE2_WEBCAST))); @@ -646,6 +649,7 @@ void SdPublishingDlg::RemovePages() delete pPage2_Titel; delete pPage2_Standard; delete pPage2_Frames; + delete pPage2_SingleDocument; delete pPage2_Kiosk; delete pPage2_WebCast; delete pPage2_Standard_FB; @@ -740,9 +744,20 @@ void SdPublishingDlg::GetParameterSequence( Sequence< PropertyValue >& rParams ) // Page 2 aValue.Name = "PublishMode"; - aValue.Value <<= (sal_Int32)(pPage2_Standard->IsChecked()?PUBLISH_HTML: - pPage2_Frames->IsChecked()?PUBLISH_FRAMES: - pPage2_Kiosk->IsChecked()?PUBLISH_KIOSK:PUBLISH_WEBCAST); + + HtmlPublishMode ePublishMode; + if (pPage2_Frames->IsChecked()) + ePublishMode = PUBLISH_FRAMES; + if (pPage2_SingleDocument->IsChecked()) + ePublishMode = PUBLISH_SINGLE_DOCUMENT; + else if (pPage2_Kiosk->IsChecked()) + ePublishMode = PUBLISH_KIOSK; + else if (pPage2_WebCast->IsChecked()) + ePublishMode = PUBLISH_WEBCAST; + else + ePublishMode = PUBLISH_HTML; + + aValue.Value <<= (sal_Int32) ePublishMode; aProps.push_back( aValue ); aValue.Name = "IsExportContentsPage"; diff --git a/sd/source/filter/html/pubdlg.src b/sd/source/filter/html/pubdlg.src index fe85a23..ddc01e7 100644 --- a/sd/source/filter/html/pubdlg.src +++ b/sd/source/filter/html/pubdlg.src @@ -105,10 +105,18 @@ ModalDialog DLG_PUBLISHING Text [ en-US ] = "Standard HTML with ~frames"; }; + RadioButton PAGE2_SINGLE_DOCUMENT + { + HelpID = "sd:RadioButton:DLG_PUBLISHING:PAGE2_SINGLE_DOCUMENT"; + Pos = MAP_APPFONT( 12, 47 ); + Size = MAP_APPFONT( 116, 10 ); + Text [ en-US ] = "~Single document html"; + }; + RadioButton PAGE2_KIOSK { HelpID = "sd:RadioButton:DLG_PUBLISHING:PAGE2_KIOSK"; - Pos = MAP_APPFONT( 12, 47 ); + Pos = MAP_APPFONT( 12, 60 ); Size = MAP_APPFONT( 116, 10 ); Text [ en-US ] = "~Automatic"; }; @@ -116,14 +124,14 @@ ModalDialog DLG_PUBLISHING RadioButton PAGE2_WEBCAST { HelpID = "sd:RadioButton:DLG_PUBLISHING:PAGE2_WEBCAST"; - Pos = MAP_APPFONT( 12, 60 ); + Pos = MAP_APPFONT( 12, 73 ); Size = MAP_APPFONT( 116, 10 ); Text [ en-US ] = "~WebCast"; }; FixedBitmap PAGE2_NOFRAMES_FB { - Pos = MAP_APPFONT( 21, 73 ); + Pos = MAP_APPFONT( 61, 60 ); Scale = TRUE; Size = MAP_APPFONT( 60, 50 ); Fixed = Bitmap { File = "pubdes.bmp"; }; @@ -133,7 +141,7 @@ ModalDialog DLG_PUBLISHING FixedBitmap PAGE2_FRAMES_FB { - Pos = MAP_APPFONT( 21, 73 ); + Pos = MAP_APPFONT( 61, 60 ); Scale = TRUE; Size = MAP_APPFONT( 60, 50 ); Fixed = Bitmap { File = "pubdes2.bmp"; }; @@ -143,7 +151,7 @@ ModalDialog DLG_PUBLISHING FixedBitmap PAGE2_KIOSK_FB { - Pos = MAP_APPFONT( 21, 73 ); + Pos = MAP_APPFONT( 61, 60 ); Scale = TRUE; Size = MAP_APPFONT( 60, 50 ); Fixed = Bitmap { File = "pubdes3.bmp"; }; @@ -153,7 +161,7 @@ ModalDialog DLG_PUBLISHING FixedBitmap PAGE2_WEBCAST_FB { - Pos = MAP_APPFONT( 21, 73 ); + Pos = MAP_APPFONT( 61, 60 ); Scale = TRUE; Size = MAP_APPFONT( 60, 50 ); Fixed = Bitmap { File = "pubdes4.bmp"; }; diff --git a/sd/source/ui/inc/pubdlg.hrc b/sd/source/ui/inc/pubdlg.hrc index 1648902..83f3933 100644 --- a/sd/source/ui/inc/pubdlg.hrc +++ b/sd/source/ui/inc/pubdlg.hrc @@ -32,22 +32,23 @@ #define PAGE2_FRAMES 23 #define PAGE2_KIOSK 24 #define PAGE2_WEBCAST 25 - -#define PAGE2_NOFRAMES_FB 26 -#define PAGE2_FRAMES_FB 27 -#define PAGE2_KIOSK_FB 28 -#define PAGE2_WEBCAST_FB 29 - -#define PAGE2_TITEL_HTML 30 -#define PAGE2_CONTENT 31 -#define PAGE2_NOTES 32 - -#define PAGE2_TITEL_KIOSK 33 -#define PAGE2_CHG_DEFAULT 34 -#define PAGE2_CHG_AUTO 35 -#define PAGE2_DURATION_TXT 36 -#define PAGE2_DURATION_TMF 37 -#define PAGE2_ENDLESS 38 +#define PAGE2_SINGLE_DOCUMENT 26 + +#define PAGE2_NOFRAMES_FB 27 +#define PAGE2_FRAMES_FB 28 +#define PAGE2_KIOSK_FB 29 +#define PAGE2_WEBCAST_FB 30 + +#define PAGE2_TITEL_HTML 31 +#define PAGE2_CONTENT 32 +#define PAGE2_NOTES 33 + +#define PAGE2_TITEL_KIOSK 34 +#define PAGE2_CHG_DEFAULT 35 +#define PAGE2_CHG_AUTO 36 +#define PAGE2_DURATION_TXT 37 +#define PAGE2_DURATION_TMF 38 +#define PAGE2_ENDLESS 39 #define PAGE2_TITEL_WEBCAST 40 #define PAGE2_ASP 41 diff --git a/sd/source/ui/inc/pubdlg.hxx b/sd/source/ui/inc/pubdlg.hxx index 574a6ff..36bc3ed 100644 --- a/sd/source/ui/inc/pubdlg.hxx +++ b/sd/source/ui/inc/pubdlg.hxx @@ -63,6 +63,7 @@ private: FixedLine* pPage2_Titel; RadioButton* pPage2_Standard; RadioButton* pPage2_Frames; + RadioButton* pPage2_SingleDocument; RadioButton* pPage2_Kiosk; RadioButton* pPage2_WebCast; FixedBitmap* pPage2_Standard_FB; commit ccbe5105ca782f4d6efc4de5fb4e0a4714d59ab1 Author: Tomaž Vajngerl <[email protected]> Date: Sun Apr 13 23:01:34 2014 +0200 sd html export: reset progress bar in single document mode Change-Id: I455588c927cc35660023f74885f63108625cd123 diff --git a/sd/source/filter/html/htmlex.cxx b/sd/source/filter/html/htmlex.cxx index f3ff94e..a592324 100644 --- a/sd/source/filter/html/htmlex.cxx +++ b/sd/source/filter/html/htmlex.cxx @@ -705,6 +705,7 @@ void HtmlExport::ExportSingleDocument() WriteHtml(maDocFileName, false, aStr.makeStringAndClear()); pOutliner->Clear(); + ResetProgress(); } // exports the (in the c'tor specified impress document) to html commit e679c101ac6c995aa26c9e1490ddb8233e668438 Author: Tomaž Vajngerl <[email protected]> Date: Sun Apr 13 22:13:56 2014 +0200 sd html: impress html export test Change-Id: I710868b4cb19cec2820c3cf699dd5d855e3da7e2 diff --git a/sd/CppunitTest_sd_html_export_tests.mk b/sd/CppunitTest_sd_html_export_tests.mk new file mode 100644 index 0000000..4fcc680 --- /dev/null +++ b/sd/CppunitTest_sd_html_export_tests.mk @@ -0,0 +1,118 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sd_html_export_tests)) + +$(eval $(call gb_CppunitTest_use_externals,sd_html_export_tests,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sd_html_export_tests, \ + sd/qa/unit/HtmlExportTest \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sd_html_export_tests, \ + avmedia \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + editeng \ + for \ + forui \ + i18nlangtag \ + msfilter \ + oox \ + sal \ + salhelper \ + sax \ + sd \ + sfx \ + sot \ + svl \ + svt \ + svx \ + svxcore \ + test \ + tl \ + tk \ + ucbhelper \ + unotest \ + utl \ + vcl \ + xo \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_set_include,sd_html_export_tests,\ + -I$(SRCDIR)/sd/source/ui/inc \ + -I$(SRCDIR)/sd/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sd_html_export_tests,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sd_html_export_tests)) + +$(eval $(call gb_CppunitTest_use_components,sd_html_export_tests,\ + animations/source/animcore/animcore \ + basic/util/sb \ + chart2/source/chartcore \ + chart2/source/controller/chartcontroller \ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + dbaccess/util/dba \ + desktop/source/deployment/deployment \ + embeddedobj/util/embobj \ + filter/source/config/cache/filterconfig1 \ + filter/source/svg/svgfilter \ + forms/util/frm \ + framework/util/fwk \ + i18npool/util/i18npool \ + linguistic/source/lng \ + oox/util/oox \ + package/source/xstor/xstor \ + package/util/package2 \ + sax/source/expatwrap/expwrap \ + sd/util/sd \ + sd/util/sdfilt \ + sd/util/sdd \ + sfx2/util/sfx \ + sot/util/sot \ + svl/source/fsstor/fsstorage \ + svtools/util/svt \ + svx/util/svxcore \ + toolkit/util/tk \ + ucb/source/core/ucb1 \ + ucb/source/ucp/expand/ucpexpand1 \ + ucb/source/ucp/file/ucpfile1 \ + ucb/source/ucp/package/ucppkg1 \ + ucb/source/ucp/tdoc/ucptdoc1 \ + unotools/util/utl \ + unoxml/source/rdf/unordf \ + unoxml/source/service/unoxml \ + xmloff/util/xo \ + xmlsecurity/util/xsec_fw \ + xmlsecurity/util/xmlsecurity \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sd_html_export_tests)) + +$(eval $(call gb_CppunitTest_use_unittest_configuration,sd_html_export_tests)) + +$(call gb_CppunitTest_get_target,sd_html_export_tests) : $(call gb_AllLangResTarget_get_target,sd) + +# vim: set noet sw=4 ts=4: diff --git a/sd/Module_sd.mk b/sd/Module_sd.mk index 63a345e..7850ba4 100644 --- a/sd/Module_sd.mk +++ b/sd/Module_sd.mk @@ -30,6 +30,7 @@ $(eval $(call gb_Module_add_check_targets,sd,\ CppunitTest_sd_uimpress \ CppunitTest_sd_import_tests \ CppunitTest_sd_filters_test \ + CppunitTest_sd_html_export_tests \ )) endif diff --git a/sd/qa/unit/HtmlExportTest.cxx b/sd/qa/unit/HtmlExportTest.cxx new file mode 100644 index 0000000..8779f9f --- /dev/null +++ b/sd/qa/unit/HtmlExportTest.cxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "sdmodeltestbase.hxx" + +#include <libxml/xmlwriter.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> +#include <libxml/parserInternals.h> +#include <libxml/HTMLparser.h> +#include <libxml/HTMLtree.h> + +#include <rtl/byteseq.hxx> +#include <boost/scoped_array.hpp> + +using namespace css; +using namespace rtl; + +class SdHTMLFilterTest : public SdModelTestBase +{ + htmlDocPtr parseHtml(utl::TempFile& aTempFile) + { + SvFileStream aFileStream(aTempFile.GetURL(), STREAM_READ); + sal_Size nSize = aFileStream.remainingSize(); + + boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nSize + 1]); + + aFileStream.Read(pBuffer.get(), nSize); + + pBuffer[nSize] = 0; + printf("Content: %s\n", reinterpret_cast<char*>(pBuffer.get())); + return htmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get()), NULL); + } + + xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath) + { + xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc); + xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx); + return pXmlXpathObj->nodesetval; + } + + OUString getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute) + { + xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath); + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(), + 1, xmlXPathNodeSetGetLength(pXmlNodes)); + if (rAttribute.isEmpty()) + return OUString(); + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + return OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr()))); + } + + void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute = OString(), const OUString& rExpectedValue = OUString()) + { + OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute); + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("Attribute '" + rAttribute + "' of '" + rXPath + "' incorrect value.").getStr(), + rExpectedValue, aValue); + } + + void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes) + { + xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath); + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(), + nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes)); + } + + htmlDocPtr exportAndparseHtml(sd::DrawDocShellRef& xDocShRef) + { + FileFormat* pFormat = getFormat(HTML); + OUString aExt = OUString( "." ) + OUString::createFromAscii(pFormat->pName); + utl::TempFile aTempFile(OUString(), &aExt); + aTempFile.EnableKillingFile(); + exportTo(xDocShRef, pFormat, aTempFile); + return parseHtml(aTempFile); + } + +public: + + void testHTMLExport() + { + sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/HtmlExportTestDocument.odp")); + htmlDocPtr htmlDoc = exportAndparseHtml(xDocShRef); + + assertXPath(htmlDoc, "/html", 1); + assertXPath(htmlDoc, "/html/body", 1); + assertXPath(htmlDoc, "/html/body/h1", 4); + assertXPath(htmlDoc, "/html/body/table", 1); + assertXPath(htmlDoc, "/html/body/table/tr", 5); + assertXPath(htmlDoc, "/html/body/ul", 1); + assertXPath(htmlDoc, "/html/body/ul/li", 2); + } + + CPPUNIT_TEST_SUITE(SdHTMLFilterTest); + CPPUNIT_TEST(testHTMLExport); + CPPUNIT_TEST_SUITE_END(); +}; + + + +CPPUNIT_TEST_SUITE_REGISTRATION(SdHTMLFilterTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/qa/unit/data/HtmlExportTestDocument.odp b/sd/qa/unit/data/HtmlExportTestDocument.odp new file mode 100644 index 0000000..3c16614 Binary files /dev/null and b/sd/qa/unit/data/HtmlExportTestDocument.odp differ diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx index eec3231..bc63fa1 100644 --- a/sd/qa/unit/sdmodeltestbase.hxx +++ b/sd/qa/unit/sdmodeltestbase.hxx @@ -37,6 +37,7 @@ struct FileFormat { #define ODP_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_TEMPLATE | SFX_FILTER_OWN | SFX_FILTER_DEFAULT | SFX_FILTER_ENCRYPTION | SFX_FILTER_PREFERED ) #define PPT_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN ) #define PPTX_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_STARONEFILTER | SFX_FILTER_PREFERED ) +#define HTML_FORMAT_TYPE ( SFX_FILTER_EXPORT | SFX_FILTER_ALIEN ) /** List of file formats we support in Impress unit tests. @@ -50,12 +51,14 @@ FileFormat aFileFormats[] = { { "odp", "impress8", "impress8", "", ODP_FORMAT_TYPE }, { "ppt", "MS PowerPoint 97", "Microsoft PowerPoint 97/2000/XP/2003", "sdfilt", PPT_FORMAT_TYPE }, { "pptx", "Impress MS PowerPoint 2007 XML", "MS PowerPoint 2007 XML", "", PPTX_FORMAT_TYPE }, + { "html", "graphic_HTML", "graphic_HTML", "", HTML_FORMAT_TYPE }, { 0, 0, 0, 0, 0 } }; -#define ODP 0 -#define PPT 1 +#define ODP 0 +#define PPT 1 #define PPTX 2 +#define HTML 3 /// Base class for filter tests loading or roundtriping a document, and asserting the document model. class SdModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest @@ -83,7 +86,7 @@ public: protected: /// Load the document. - ::sd::DrawDocShellRef loadURL( const OUString &rURL ) + sd::DrawDocShellRef loadURL( const OUString &rURL ) { FileFormat *pFmt(0); @@ -121,31 +124,60 @@ protected: return xDocShRef; } - ::sd::DrawDocShellRef saveAndReload( ::sd::DrawDocShell *pShell, sal_Int32 nExportType ) + FileFormat* getFormat(sal_Int32 nExportType) { - FileFormat *pFmt = &aFileFormats[0]; - if( ( (sal_uInt32) nExportType ) < SAL_N_ELEMENTS( aFileFormats ) ) - pFmt = &aFileFormats[ nExportType ]; - OUString aExt = OUString( "." ) + OUString::createFromAscii( pFmt->pName ); - utl::TempFile aTempFile( OUString(), &aExt ); - aTempFile.EnableKillingFile(); - SfxMedium aStoreMedium( aTempFile.GetURL(), STREAM_STD_WRITE ); + FileFormat* pFormat = &aFileFormats[0]; + if (((sal_uInt32) nExportType) < SAL_N_ELEMENTS(aFileFormats)) + pFormat = &aFileFormats[nExportType]; + return pFormat; + } + + void exportTo(sd::DrawDocShell* pShell, FileFormat* pFormat, utl::TempFile& rTempFile) + { + SfxMedium aStoreMedium(rTempFile.GetURL(), STREAM_STD_WRITE); + sal_uInt32 nExportFormat = 0; + if (pFormat->nFormatType == ODP_FORMAT_TYPE) + nExportFormat = SFX_FILTER_EXPORT | SFX_FILTER_USESOPTIONS; + SfxFilter* pExportFilter = new SfxFilter( + OUString::createFromAscii(pFormat->pFilterName), + OUString(), pFormat->nFormatType, nExportFormat, + OUString::createFromAscii(pFormat->pTypeName), + 0, OUString(), + OUString::createFromAscii(pFormat->pUserData), + OUString("private:factory/simpress*") ); + pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); + aStoreMedium.SetFilter(pExportFilter); + pShell->ConvertTo(aStoreMedium); + pShell->DoClose(); + } + + void save(sd::DrawDocShell* pShell, FileFormat* pFormat, utl::TempFile& rTempFile) + { + SfxMedium aStoreMedium(rTempFile.GetURL(), STREAM_STD_WRITE); sal_uInt32 nExportFormat = 0; - if( pFmt->nFormatType == ODP_FORMAT_TYPE ) + if (pFormat->nFormatType == ODP_FORMAT_TYPE) nExportFormat = SFX_FILTER_EXPORT | SFX_FILTER_USESOPTIONS; SfxFilter* pExportFilter = new SfxFilter( - OUString::createFromAscii( pFmt->pFilterName ), - OUString(), pFmt->nFormatType, nExportFormat, - OUString::createFromAscii( pFmt->pTypeName ), - 0, OUString(), - OUString::createFromAscii( pFmt->pUserData ), - OUString("private:factory/simpress*") ); - pExportFilter->SetVersion( SOFFICE_FILEFORMAT_CURRENT ); - aStoreMedium.SetFilter( pExportFilter ); - pShell->DoSaveAs( aStoreMedium ); + OUString::createFromAscii(pFormat->pFilterName), + OUString(), pFormat->nFormatType, nExportFormat, + OUString::createFromAscii(pFormat->pTypeName), + 0, OUString(), + OUString::createFromAscii(pFormat->pUserData), + OUString("private:factory/simpress*") ); + pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); + aStoreMedium.SetFilter(pExportFilter); + pShell->DoSaveAs(aStoreMedium); pShell->DoClose(); + } - return loadURL( aTempFile.GetURL() ); + sd::DrawDocShellRef saveAndReload(sd::DrawDocShell *pShell, sal_Int32 nExportType) + { + FileFormat* pFormat = getFormat(nExportType); + OUString aExt = OUString( "." ) + OUString::createFromAscii(pFormat->pName); + utl::TempFile aTempFile(OUString(), &aExt); + aTempFile.EnableKillingFile(); + save(pShell, pFormat, aTempFile); + return loadURL(aTempFile.GetURL()); } /** Dump shapes in xDocShRef, and compare the dump against content of pShapesDumpFileNameBase<number>.xml. commit 87c3fdeed8a1e9129966323c1100e1cd1aa31a9f Author: Tomaž Vajngerl <[email protected]> Date: Sun Apr 13 22:11:53 2014 +0200 sd html: export outline, code simplification Change-Id: Ic201f4bd7716806edd031a2935d1e859a6b51958 diff --git a/sd/source/filter/html/htmlex.cxx b/sd/source/filter/html/htmlex.cxx index b06f5b8..f3ff94e 100644 --- a/sd/source/filter/html/htmlex.cxx +++ b/sd/source/filter/html/htmlex.cxx @@ -1205,9 +1205,8 @@ OUString HtmlExport::CreateTextForTitle( SdrOutliner* pOutliner, SdPage* pPage, // creates a outliner text for a page -OUString HtmlExport::CreateTextForPage( SdrOutliner* pOutliner, - SdPage* pPage, - bool bHeadLine, const Color& rBackgroundColor ) +OUString HtmlExport::CreateTextForPage(SdrOutliner* pOutliner, SdPage* pPage, + bool bHeadLine, const Color& rBackgroundColor) { OUStringBuffer aStr; @@ -1216,171 +1215,114 @@ OUString HtmlExport::CreateTextForPage( SdrOutliner* pOutliner, SdrObject* pObject = pPage->GetObj(i); PresObjKind eKind = pPage->GetPresObjKind(pObject); - if (eKind == PRESOBJ_TABLE) + switch (eKind) { - SdrTableObj* pTableObject = (SdrTableObj*) pObject; - - CellPos aStart, aEnd; - - aStart = pTableObject->getFirstCell(); - aEnd = pTableObject->getLastCell(); - - sal_Int32 nColCount = pTableObject->getColumnCount(); - aStr.append("<table>\r\n"); - for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++) + case PRESOBJ_TABLE: { - aStr.append(" <tr>\r\n"); - for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++) - { - aStr.append(" <td>\r\n"); - sal_Int32 nCellIndex = nRow * nColCount + nCol; - SdrText* pText = pTableObject->getText(nCellIndex); - if (!pText || !pText->GetOutlinerParaObject()) - continue; - - pOutliner->SetText(*(pText->GetOutlinerParaObject())); + SdrTableObj* pTableObject = (SdrTableObj*) pObject; - sal_Int32 nCount = pOutliner->GetParagraphCount(); + CellPos aStart, aEnd; - Paragraph* pPara = NULL; + aStart = pTableObject->getFirstCell(); + aEnd = pTableObject->getLastCell(); - sal_Int16 nCurrentDepth = -1; - - for (sal_Int32 nPara = 0; nPara < nCount; nPara++) + sal_Int32 nColCount = pTableObject->getColumnCount(); + aStr.append("<table>\r\n"); + for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++) + { + aStr.append(" <tr>\r\n"); + for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++) { - pPara = pOutliner->GetParagraph(nPara); - if(pPara == 0) - continue; + aStr.append(" <td>\r\n"); + sal_Int32 nCellIndex = nRow * nColCount + nCol; + SdrText* pText = pTableObject->getText(nCellIndex); - const sal_Int16 nDepth = (sal_uInt16) pOutliner->GetDepth(nPara); - OUString aParaText = ParagraphToHTMLString(pOutliner, nPara, rBackgroundColor); - - if (aParaText.isEmpty()) + if (pText == NULL) continue; - - if (nDepth < 0) - { - lclAppendStyle(aStr, "p", getParagraphStyle(pOutliner, nPara)); - aStr.append(aParaText); - aStr.append("</p>\r\n"); - } - else - { - while(nCurrentDepth < nDepth) - { - aStr.append("<ul>\r\n"); - nCurrentDepth++; - } - while(nCurrentDepth > nDepth) - { - aStr.append("</ul>\r\n"); - nCurrentDepth--; - } - lclAppendStyle(aStr, "li", getParagraphStyle(pOutliner, nPara)); - aStr.append(aParaText); - aStr.append("</li>\r\n"); - } + WriteOutlinerParagraph(aStr, pOutliner, pText->GetOutlinerParaObject(), rBackgroundColor, false); + aStr.append(" </td>\r\n"); } - while(nCurrentDepth >= 0) - { - aStr.append("</ul>\r\n"); - nCurrentDepth--; - } - pOutliner->Clear(); - aStr.append(" </td>\r\n"); + aStr.append(" </tr>\r\n"); } - aStr.append(" </tr>\r\n"); + aStr.append("</table>\r\n"); + } + break; + case PRESOBJ_TEXT: + case PRESOBJ_OUTLINE: + { + SdrTextObj* pTextObject = (SdrTextObj*) pObject; + if (pTextObject->IsEmptyPresObj()) + continue; + WriteOutlinerParagraph(aStr, pOutliner, pTextObject->GetOutlinerParaObject(), rBackgroundColor, bHeadLine); } - aStr.append("</table>\r\n"); + break; + default: + break; } } + return aStr.makeStringAndClear(); +} - SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TEXT); - if(!pTO) - pTO = GetLayoutTextObject(pPage); +void HtmlExport::WriteOutlinerParagraph(OUStringBuffer& aStr, SdrOutliner* pOutliner, + OutlinerParaObject* pOutlinerParagraphObject, + const Color& rBackgroundColor, bool bHeadLine) +{ + if (pOutlinerParagraphObject == NULL) + return; - if (pTO && !pTO->IsEmptyPresObj()) - { - OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject(); - if (pOPO) - { - pOutliner->Clear(); - pOutliner->SetText( *pOPO ); + pOutliner->SetText(*pOutlinerParagraphObject); - sal_Int32 nCount = pOutliner->GetParagraphCount(); + sal_Int32 nCount = pOutliner->GetParagraphCount(); - Paragraph* pPara = NULL; - sal_Int16 nActDepth = -1; + Paragraph* pParagraph = NULL; - OUString aParaText; - for (sal_Int32 nPara = 0; nPara < nCount; nPara++) - { - pPara = pOutliner->GetParagraph(nPara); - if(pPara == 0) - continue; + sal_Int16 nCurrentDepth = -1; - const sal_Int16 nDepth = (sal_uInt16) pOutliner->GetDepth( nPara ); - aParaText = ParagraphToHTMLString(pOutliner,nPara,rBackgroundColor); + for (sal_Int32 nIndex = 0; nIndex < nCount; nIndex++) + { + pParagraph = pOutliner->GetParagraph(nIndex); + if(pParagraph == NULL) + continue; - if (aParaText.isEmpty()) - continue; + const sal_Int16 nDepth = (sal_uInt16) pOutliner->GetDepth(nIndex); + OUString aParaText = ParagraphToHTMLString(pOutliner, nIndex, rBackgroundColor); - if(nDepth < nActDepth ) - { - do - { - aStr.append("</ul>"); - nActDepth--; - } - while(nDepth < nActDepth); - } - else if(nDepth > nActDepth ) - { - do - { - aStr.append("<ul>"); - nActDepth++; - } - while( nDepth > nActDepth ); - } + if (aParaText.isEmpty()) + continue; - OUString sStyle(getParagraphStyle(pOutliner, nPara)); - if(nActDepth >= 0 ) - { - lclAppendStyle(aStr, "li", sStyle); - } + if (nDepth < 0) + { + OUString aTag = bHeadLine ? OUString("h2") : OUString("p"); + lclAppendStyle(aStr, aTag, getParagraphStyle(pOutliner, nIndex)); - if(nActDepth <= 0 && bHeadLine) - { - if( nActDepth == 0 ) - { - aStr.append("<h2>"); - } - else - { - lclAppendStyle(aStr, "h2", sStyle); - } - } - aStr.append(aParaText); - if(nActDepth == 0 && bHeadLine) - aStr.append("</h2>"); - if(nActDepth >= 0 ) - aStr.append("</li>"); - aStr.append("\r\n"); + aStr.append(aParaText); + aStr.append("</" + aTag + ">\r\n"); + } + else + { + while(nCurrentDepth < nDepth) + { + aStr.append("<ul>\r\n"); + nCurrentDepth++; } - - while( nActDepth >= 0 ) + while(nCurrentDepth > nDepth) { - aStr.append("</ul>"); - nActDepth--; - }; + aStr.append("</ul>\r\n"); + nCurrentDepth--; + } + lclAppendStyle(aStr, "li", getParagraphStyle(pOutliner, nIndex)); + aStr.append(aParaText); + aStr.append("</li>\r\n"); } } - - return aStr.makeStringAndClear(); + while(nCurrentDepth >= 0) + { + aStr.append("</ul>\r\n"); + nCurrentDepth--; + } + pOutliner->Clear(); } - // creates a outliner text for a note page OUString HtmlExport::CreateTextForNotesPage( SdrOutliner* pOutliner, SdPage* pPage, diff --git a/sd/source/filter/html/htmlex.hxx b/sd/source/filter/html/htmlex.hxx index 53b1292..58e0086 100644 --- a/sd/source/filter/html/htmlex.hxx +++ b/sd/source/filter/html/htmlex.hxx @@ -211,6 +211,10 @@ class HtmlExport bool WriteHtml( const OUString& rFileName, bool bAddExtension, const OUString& rHtmlData ); OUString GetButtonName( int nButton ) const; + void WriteOutlinerParagraph(OUStringBuffer& aStr, SdrOutliner* pOutliner, + OutlinerParaObject* pOutlinerParagraphObject, + const Color& rBackgroundColor, bool bHeadLine); + public: HtmlExport(const OUString& aPath, const css::uno::Sequence<css::beans::PropertyValue>& rParams,
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
