From a54787669b9283efdfdd18b0cbafc3184cdde58f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 22 Jan 2018 15:18:45 +0100 Subject: EPUB export, fixed layout: add chapter names to the navigation document Extend vcl::PDFExtOutDevData so that it's possible to use it outside the PDF export; this way the EPUB export can know which chapters start on which page. This means fixed and reflowable layout has the same table of contents, instead of just Page in the fixed layout case. Change-Id: I935fb23c66ec747431b91e83b0e677d4e5f704b9 Reviewed-on: https://gerrit.libreoffice.org/48332 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- writerperfect/source/writer/EPUBExportFilter.cxx | 12 ++++++--- writerperfect/source/writer/EPUBExportFilter.hxx | 4 +-- writerperfect/source/writer/exp/xmlimp.cxx | 32 +++++++++++++++++------- writerperfect/source/writer/exp/xmlimp.hxx | 17 +++++++++---- 4 files changed, 45 insertions(+), 20 deletions(-) (limited to 'writerperfect/source') diff --git a/writerperfect/source/writer/EPUBExportFilter.cxx b/writerperfect/source/writer/EPUBExportFilter.cxx index b25118350193..2e4286e1f80b 100644 --- a/writerperfect/source/writer/EPUBExportFilter.cxx +++ b/writerperfect/source/writer/EPUBExportFilter.cxx @@ -94,7 +94,7 @@ sal_Bool EPUBExportFilter::filter(const uno::Sequence &rDe if (xSourceModel.is()) aSourceURL = xSourceModel->getURL(); - std::vector, Size>> aPageMetafiles; + std::vector aPageMetafiles; if (nLayoutMethod == libepubgen::EPUB_LAYOUT_METHOD_FIXED) CreateMetafiles(aPageMetafiles); @@ -119,7 +119,7 @@ sal_Bool EPUBExportFilter::filter(const uno::Sequence &rDe return xFilter->filter(rDescriptor); } -void EPUBExportFilter::CreateMetafiles(std::vector, Size>> &rPageMetafiles) +void EPUBExportFilter::CreateMetafiles(std::vector &rPageMetafiles) { DocumentToGraphicRenderer aRenderer(mxSourceDocument, /*bSelectionOnly=*/false); uno::Reference xModel(mxSourceDocument, uno::UNO_QUERY); @@ -142,7 +142,7 @@ void EPUBExportFilter::CreateMetafiles(std::vector pixel using 96 DPI, independent from system DPI). Size aCss(static_cast(aLogic.getWidth()) / 26.4583, static_cast(aLogic.getHeight()) / 26.4583); - Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aCss, COL_WHITE); + Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aCss, COL_WHITE, /*bExtOutDevData=*/true); auto &rGDIMetaFile = const_cast(aGraphic.GetGDIMetaFile()); // Set preferred map unit and size on the metafile, so the SVG size @@ -156,7 +156,11 @@ void EPUBExportFilter::CreateMetafiles(std::vector aSequence(static_cast(aMemoryStream.GetData()), aMemoryStream.Tell()); - rPageMetafiles.emplace_back(aSequence, aCss); + exp::FixedLayoutPage aPage; + aPage.aMetafile = aSequence; + aPage.aCssPixels = aCss; + aPage.aChapterNames = aRenderer.getChapterNames(); + rPageMetafiles.push_back(aPage); } } diff --git a/writerperfect/source/writer/EPUBExportFilter.hxx b/writerperfect/source/writer/EPUBExportFilter.hxx index 188139a32843..ee676d3e1701 100644 --- a/writerperfect/source/writer/EPUBExportFilter.hxx +++ b/writerperfect/source/writer/EPUBExportFilter.hxx @@ -19,7 +19,7 @@ #include #include -class Size; +#include "exp/xmlimp.hxx" namespace writerperfect { @@ -59,7 +59,7 @@ public: private: /// Create page metafiles in case of fixed layout. - void CreateMetafiles(std::vector, Size>> &rPageMetafiles); + void CreateMetafiles(std::vector &rPageMetafiles); }; } // namespace writerperfect diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx index ef681119d4cf..3ef02f69f008 100644 --- a/writerperfect/source/writer/exp/xmlimp.cxx +++ b/writerperfect/source/writer/exp/xmlimp.cxx @@ -238,7 +238,7 @@ public: rtl::Reference CreateChildContext(const OUString &rName, const uno::Reference &/*xAttribs*/) override; // Handles metafile for a single page. - void HandleFixedLayoutPage(const uno::Sequence &rPage, const Size &rSize, bool bFirst); + void HandleFixedLayoutPage(const FixedLayoutPage &rPage, bool bFirst); }; XMLOfficeDocContext::XMLOfficeDocContext(XMLImport &rImport) @@ -266,7 +266,7 @@ rtl::Reference XMLOfficeDocContext::CreateChildContext(const O bool bFirst = true; for (const auto &rPage : mrImport.GetPageMetafiles()) { - HandleFixedLayoutPage(rPage.first, rPage.second, bFirst); + HandleFixedLayoutPage(rPage, bFirst); if (bFirst) bFirst = false; } @@ -274,7 +274,7 @@ rtl::Reference XMLOfficeDocContext::CreateChildContext(const O return nullptr; } -void XMLOfficeDocContext::HandleFixedLayoutPage(const uno::Sequence &rPage, const Size &rSize, bool bFirst) +void XMLOfficeDocContext::HandleFixedLayoutPage(const FixedLayoutPage &rPage, bool bFirst) { uno::Reference xCtx = mrImport.GetComponentContext(); uno::Reference xSaxWriter = xml::sax::Writer::create(xCtx); @@ -292,17 +292,31 @@ void XMLOfficeDocContext::HandleFixedLayoutPage(const uno::Sequence &r SvMemoryStream aMemoryStream; xSaxWriter->setOutputStream(new utl::OStreamWrapper(aMemoryStream)); - xSVGWriter->write(xSaxWriter, rPage); + xSVGWriter->write(xSaxWriter, rPage.aMetafile); - // Have all the info, invoke libepubgen. + // Have all the info, invoke the generator. librevenge::RVNGPropertyList aPageProperties; // Pixel -> inch. - double fWidth = rSize.getWidth(); + double fWidth = rPage.aCssPixels.getWidth(); fWidth /= 96; aPageProperties.insert("fo:page-width", fWidth); - double fHeight = rSize.getHeight(); + double fHeight = rPage.aCssPixels.getHeight(); fHeight /= 96; aPageProperties.insert("fo:page-height", fHeight); + + if (!rPage.aChapterNames.empty()) + { + // Name of chapters starting on this page. + librevenge::RVNGPropertyListVector aChapterNames; + for (const auto &rName : rPage.aChapterNames) + { + librevenge::RVNGPropertyList aChapter; + aChapter.insert("librevenge:name", rName.toUtf8().getStr()); + aChapterNames.append(aChapter); + } + aPageProperties.insert("librevenge:chapter-names", aChapterNames); + } + mrImport.GetGenerator().openPageSpan(aPageProperties); librevenge::RVNGPropertyList aParagraphProperties; if (!bFirst) @@ -320,7 +334,7 @@ void XMLOfficeDocContext::HandleFixedLayoutPage(const uno::Sequence &r mrImport.GetGenerator().closePageSpan(); } -XMLImport::XMLImport(const uno::Reference &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const uno::Sequence &rDescriptor, const std::vector, Size>> &rPageMetafiles) +XMLImport::XMLImport(const uno::Reference &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const uno::Sequence &rDescriptor, const std::vector &rPageMetafiles) : mrGenerator(rGenerator), mxContext(xContext), mrPageMetafiles(rPageMetafiles) @@ -421,7 +435,7 @@ PopupState XMLImport::FillPopupData(const OUString &rURL, librevenge::RVNGProper return PopupState::Consumed; } -const std::vector, Size>> &XMLImport::GetPageMetafiles() const +const std::vector &XMLImport::GetPageMetafiles() const { return mrPageMetafiles; } diff --git a/writerperfect/source/writer/exp/xmlimp.hxx b/writerperfect/source/writer/exp/xmlimp.hxx index 246eb45dbd16..1953c7196772 100644 --- a/writerperfect/source/writer/exp/xmlimp.hxx +++ b/writerperfect/source/writer/exp/xmlimp.hxx @@ -23,8 +23,7 @@ #include #include - -class Size; +#include namespace writerperfect { @@ -33,6 +32,14 @@ namespace exp class XMLImportContext; +/// Contains info about a fixed-layout page. +struct FixedLayoutPage +{ + css::uno::Sequence aMetafile; + Size aCssPixels; + std::vector aChapterNames; +}; + /// States describing the result of a link -> popup conversion. enum class PopupState { @@ -74,10 +81,10 @@ class XMLImport : public cppu::WeakImplHelper const css::uno::Reference &mxContext; css::uno::Reference mxUriReferenceFactory; OUString maMediaDir; - const std::vector, Size>> &mrPageMetafiles; + const std::vector &mrPageMetafiles; public: - XMLImport(const css::uno::Reference &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const css::uno::Sequence &rDescriptor, const std::vector, Size>> &rPageMetafiles); + XMLImport(const css::uno::Reference &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const css::uno::Sequence &rDescriptor, const std::vector &rPageMetafiles); rtl::Reference CreateContext(const OUString &rName, const css::uno::Reference &xAttribs); @@ -99,7 +106,7 @@ public: const librevenge::RVNGPropertyListVector &GetCoverImages(); const librevenge::RVNGPropertyList &GetMetaData(); PopupState FillPopupData(const OUString &rURL, librevenge::RVNGPropertyList &rPropList); - const std::vector, Size>> &GetPageMetafiles() const; + const std::vector &GetPageMetafiles() const; const css::uno::Reference &GetComponentContext() const; // XDocumentHandler -- cgit