summaryrefslogtreecommitdiff
path: root/writerperfect/source/writer
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-12-01 10:56:03 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-12-01 16:30:53 +0100
commit89e7a00080aadeba08ee649877b2507dc312f9f8 (patch)
tree81e4273ba67073f9b2327480ab8f1bd7b051204d /writerperfect/source/writer
parent913fbc822c0f0e285cd0dc3f919a2fb43a94c7ad (diff)
EPUB export: handle page size in fixed layout
Requires parsing master pages and page layouts. Change-Id: Ia8b9e59a9355396d3776af06e8e67ec88033754b Reviewed-on: https://gerrit.libreoffice.org/45645 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerperfect/source/writer')
-rw-r--r--writerperfect/source/writer/exp/txtparai.cxx7
-rw-r--r--writerperfect/source/writer/exp/txtstyli.cxx96
-rw-r--r--writerperfect/source/writer/exp/txtstyli.hxx29
-rw-r--r--writerperfect/source/writer/exp/xmlfmt.cxx27
-rw-r--r--writerperfect/source/writer/exp/xmlfmt.hxx13
-rw-r--r--writerperfect/source/writer/exp/xmlimp.cxx31
-rw-r--r--writerperfect/source/writer/exp/xmlimp.hxx7
7 files changed, 198 insertions, 12 deletions
diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx
index 309f80ce607a..95f85d86f454 100644
--- a/writerperfect/source/writer/exp/txtparai.cxx
+++ b/writerperfect/source/writer/exp/txtparai.cxx
@@ -397,6 +397,13 @@ void XMLParaContext::startElement(const OUString &/*rName*/, const css::uno::Ref
}
}
+ if (!mrImport.IsPageSpanOpened())
+ {
+ auto it = mrImport.GetMasterPages().find("Standard");
+ if (it != mrImport.GetMasterPages().end())
+ mrImport.GetGenerator().openPageSpan(it->second);
+ mrImport.SetPageSpanOpened(true);
+ }
mrImport.GetGenerator().openParagraph(aPropertyList);
}
diff --git a/writerperfect/source/writer/exp/txtstyli.cxx b/writerperfect/source/writer/exp/txtstyli.cxx
index e8fe1a43bea0..38b32768ddf0 100644
--- a/writerperfect/source/writer/exp/txtstyli.cxx
+++ b/writerperfect/source/writer/exp/txtstyli.cxx
@@ -320,6 +320,102 @@ librevenge::RVNGPropertyList &XMLStyleContext::GetGraphicPropertyList()
return m_aGraphicPropertyList;
}
+XMLMasterPageContext::XMLMasterPageContext(XMLImport &rImport, XMLStylesContext &rStyles)
+ : XMLImportContext(rImport),
+ m_rStyles(rStyles)
+{
+ // I'll remove this in a follow-up commit.
+ (void)m_rStyles;
+}
+
+void XMLMasterPageContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs)
+{
+ OUString aName;
+ OUString aPageLayoutName;
+ for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
+ {
+ const OUString &rAttributeName = xAttribs->getNameByIndex(i);
+ const OUString &rAttributeValue = xAttribs->getValueByIndex(i);
+ if (rAttributeName == "style:name")
+ aName = rAttributeValue;
+ else if (rAttributeName == "style:page-layout-name")
+ aPageLayoutName = rAttributeValue;
+ }
+ auto it = mrImport.GetPageLayouts().find(aPageLayoutName);
+ if (it == mrImport.GetPageLayouts().end())
+ return;
+
+ librevenge::RVNGPropertyList::Iter itProp(it->second);
+ librevenge::RVNGPropertyList aPropertyList;
+ for (itProp.rewind(); itProp.next();)
+ aPropertyList.insert(itProp.key(), itProp()->clone());
+ mrImport.GetMasterPages()[aName] = aPropertyList;
+}
+
+/// Handler for <style:page-layout-properties>.
+class XMLPageLayoutPropertiesContext : public XMLImportContext
+{
+public:
+ XMLPageLayoutPropertiesContext(XMLImport &rImport, XMLPageLayoutContext &rStyle);
+
+ void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+
+private:
+ XMLPageLayoutContext &m_rStyle;
+};
+
+XMLPageLayoutPropertiesContext::XMLPageLayoutPropertiesContext(XMLImport &rImport, XMLPageLayoutContext &rStyle)
+ : XMLImportContext(rImport)
+ , m_rStyle(rStyle)
+{
+}
+
+void XMLPageLayoutPropertiesContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs)
+{
+ for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
+ {
+ OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
+ OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
+ m_rStyle.GetPropertyList().insert(sName.getStr(), sValue.getStr());
+ }
+}
+
+XMLPageLayoutContext::XMLPageLayoutContext(XMLImport &rImport, XMLStylesContext &rStyles)
+ : XMLImportContext(rImport),
+ m_rStyles(rStyles)
+{
+}
+
+void XMLPageLayoutContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs)
+{
+ for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
+ {
+ const OUString &rAttributeName = xAttribs->getNameByIndex(i);
+ const OUString &rAttributeValue = xAttribs->getValueByIndex(i);
+ if (rAttributeName == "style:name")
+ m_aName = rAttributeValue;
+ }
+}
+
+rtl::Reference<XMLImportContext> XMLPageLayoutContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
+{
+ if (rName == "style:page-layout-properties")
+ return new XMLPageLayoutPropertiesContext(mrImport, *this);
+ return nullptr;
+}
+
+void XMLPageLayoutContext::endElement(const OUString &/*rName*/)
+{
+ if (m_aName.isEmpty())
+ return;
+
+ m_rStyles.GetCurrentPageLayouts()[m_aName] = m_aPropertyList;
+}
+
+librevenge::RVNGPropertyList &XMLPageLayoutContext::GetPropertyList()
+{
+ return m_aPropertyList;
+}
} // namespace exp
} // namespace writerperfect
diff --git a/writerperfect/source/writer/exp/txtstyli.hxx b/writerperfect/source/writer/exp/txtstyli.hxx
index f3b3b6da38c9..06ae15e503f8 100644
--- a/writerperfect/source/writer/exp/txtstyli.hxx
+++ b/writerperfect/source/writer/exp/txtstyli.hxx
@@ -52,6 +52,35 @@ private:
XMLStylesContext &m_rStyles;
};
+/// Handler for <style:master-page>.
+class XMLMasterPageContext : public XMLImportContext
+{
+public:
+ XMLMasterPageContext(XMLImport &rImport, XMLStylesContext &rStyles);
+
+ void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+
+private:
+ XMLStylesContext &m_rStyles;
+};
+
+/// Handler for <style:page-layout>.
+class XMLPageLayoutContext : public XMLImportContext
+{
+public:
+ XMLPageLayoutContext(XMLImport &rImport, XMLStylesContext &rStyles);
+
+ rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+ void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+ void SAL_CALL endElement(const OUString &rName) override;
+
+ librevenge::RVNGPropertyList &GetPropertyList();
+private:
+ OUString m_aName;
+ librevenge::RVNGPropertyList m_aPropertyList;
+ XMLStylesContext &m_rStyles;
+};
+
} // namespace exp
} // namespace writerperfect
diff --git a/writerperfect/source/writer/exp/xmlfmt.cxx b/writerperfect/source/writer/exp/xmlfmt.cxx
index abd6bb9a6a72..a4b0781c73f9 100644
--- a/writerperfect/source/writer/exp/xmlfmt.cxx
+++ b/writerperfect/source/writer/exp/xmlfmt.cxx
@@ -20,15 +20,17 @@ namespace writerperfect
namespace exp
{
-XMLStylesContext::XMLStylesContext(XMLImport &rImport, bool bAutomatic)
+XMLStylesContext::XMLStylesContext(XMLImport &rImport, StyleType eType)
: XMLImportContext(rImport),
- m_rParagraphStyles(bAutomatic ? mrImport.GetAutomaticParagraphStyles() : mrImport.GetParagraphStyles()),
- m_rTextStyles(bAutomatic ? mrImport.GetAutomaticTextStyles() : mrImport.GetTextStyles()),
- m_rCellStyles(bAutomatic ? mrImport.GetAutomaticCellStyles() : mrImport.GetCellStyles()),
- m_rColumnStyles(bAutomatic ? mrImport.GetAutomaticColumnStyles() : mrImport.GetColumnStyles()),
- m_rRowStyles(bAutomatic ? mrImport.GetAutomaticRowStyles() : mrImport.GetRowStyles()),
- m_rTableStyles(bAutomatic ? mrImport.GetAutomaticTableStyles() : mrImport.GetTableStyles()),
- m_rGraphicStyles(bAutomatic ? mrImport.GetAutomaticGraphicStyles() : mrImport.GetGraphicStyles())
+ m_rParagraphStyles(eType == StyleType_AUTOMATIC ? mrImport.GetAutomaticParagraphStyles() : mrImport.GetParagraphStyles()),
+ m_rTextStyles(eType == StyleType_AUTOMATIC ? mrImport.GetAutomaticTextStyles() : mrImport.GetTextStyles()),
+ m_rCellStyles(eType == StyleType_AUTOMATIC ? mrImport.GetAutomaticCellStyles() : mrImport.GetCellStyles()),
+ m_rColumnStyles(eType == StyleType_AUTOMATIC ? mrImport.GetAutomaticColumnStyles() : mrImport.GetColumnStyles()),
+ m_rRowStyles(eType == StyleType_AUTOMATIC ? mrImport.GetAutomaticRowStyles() : mrImport.GetRowStyles()),
+ m_rTableStyles(eType == StyleType_AUTOMATIC ? mrImport.GetAutomaticTableStyles() : mrImport.GetTableStyles()),
+ m_rGraphicStyles(eType == StyleType_AUTOMATIC ? mrImport.GetAutomaticGraphicStyles() : mrImport.GetGraphicStyles()),
+ m_rPageLayouts(mrImport.GetPageLayouts()),
+ m_eType(eType)
{
}
@@ -36,6 +38,10 @@ rtl::Reference<XMLImportContext> XMLStylesContext::CreateChildContext(const OUSt
{
if (rName == "style:style")
return new XMLStyleContext(mrImport, *this);
+ if (m_eType == StyleType_MASTER && rName == "style:master-page")
+ return new XMLMasterPageContext(mrImport, *this);
+ if (m_eType == StyleType_AUTOMATIC && rName == "style:page-layout")
+ return new XMLPageLayoutContext(mrImport, *this);
return nullptr;
}
@@ -74,6 +80,11 @@ std::map<OUString, librevenge::RVNGPropertyList> &XMLStylesContext::GetCurrentGr
return m_rGraphicStyles;
}
+std::map<OUString, librevenge::RVNGPropertyList> &XMLStylesContext::GetCurrentPageLayouts()
+{
+ return m_rPageLayouts;
+}
+
/// Handler for <style:font-face>.
class XMLFontFaceContext : public XMLImportContext
{
diff --git a/writerperfect/source/writer/exp/xmlfmt.hxx b/writerperfect/source/writer/exp/xmlfmt.hxx
index 3f609e98b000..24ee493cd660 100644
--- a/writerperfect/source/writer/exp/xmlfmt.hxx
+++ b/writerperfect/source/writer/exp/xmlfmt.hxx
@@ -21,11 +21,17 @@ namespace writerperfect
namespace exp
{
-/// Handler for <office:automatic-styles>/<office:styles>.
+/// Handler for <office:automatic-styles>/<office:master-styles>/<office:styles>.
class XMLStylesContext : public XMLImportContext
{
public:
- XMLStylesContext(XMLImport &rImport, bool bAutomatic);
+ enum StyleType
+ {
+ StyleType_NONE,
+ StyleType_AUTOMATIC,
+ StyleType_MASTER
+ };
+ XMLStylesContext(XMLImport &rImport, StyleType eType);
rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
@@ -36,6 +42,7 @@ public:
std::map<OUString, librevenge::RVNGPropertyList> &GetCurrentRowStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetCurrentTableStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetCurrentGraphicStyles();
+ std::map<OUString, librevenge::RVNGPropertyList> &GetCurrentPageLayouts();
private:
std::map<OUString, librevenge::RVNGPropertyList> &m_rParagraphStyles;
std::map<OUString, librevenge::RVNGPropertyList> &m_rTextStyles;
@@ -44,6 +51,8 @@ private:
std::map<OUString, librevenge::RVNGPropertyList> &m_rRowStyles;
std::map<OUString, librevenge::RVNGPropertyList> &m_rTableStyles;
std::map<OUString, librevenge::RVNGPropertyList> &m_rGraphicStyles;
+ std::map<OUString, librevenge::RVNGPropertyList> &m_rPageLayouts;
+ StyleType m_eType;
};
/// Handler for <office:font-face-decls>.
diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx
index 7b6cc2791459..1d245401aea6 100644
--- a/writerperfect/source/writer/exp/xmlimp.cxx
+++ b/writerperfect/source/writer/exp/xmlimp.cxx
@@ -246,11 +246,13 @@ rtl::Reference<XMLImportContext> XMLOfficeDocContext::CreateChildContext(const O
else if (rName == "office:meta")
return new XMLMetaDocumentContext(mrImport);
else if (rName == "office:automatic-styles")
- return new XMLStylesContext(mrImport, /*bAutomatic=*/true);
+ return new XMLStylesContext(mrImport, XMLStylesContext::StyleType_AUTOMATIC);
else if (rName == "office:styles")
- return new XMLStylesContext(mrImport, /*bAutomatic=*/false);
+ return new XMLStylesContext(mrImport, XMLStylesContext::StyleType_NONE);
else if (rName == "office:font-face-decls")
return new XMLFontFaceDeclsContext(mrImport);
+ else if (rName == "office:master-styles")
+ return new XMLStylesContext(mrImport, XMLStylesContext::StyleType_MASTER);
return nullptr;
}
@@ -339,6 +341,16 @@ bool XMLImport::FillPopupData(const OUString &rURL, librevenge::RVNGPropertyList
return false;
}
+void XMLImport::SetPageSpanOpened(bool bPageSpanOpened)
+{
+ mbPageSpanOpened = bPageSpanOpened;
+}
+
+bool XMLImport::IsPageSpanOpened() const
+{
+ return mbPageSpanOpened;
+}
+
rtl::Reference<XMLImportContext> XMLImport::CreateContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
{
if (rName == "office:document")
@@ -421,6 +433,16 @@ std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetGraphicStyles()
return maGraphicStyles;
}
+std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetPageLayouts()
+{
+ return maPageLayouts;
+}
+
+std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetMasterPages()
+{
+ return maMasterPages;
+}
+
void XMLImport::startDocument()
{
mrGenerator.startDocument(librevenge::RVNGPropertyList());
@@ -428,6 +450,11 @@ void XMLImport::startDocument()
void XMLImport::endDocument()
{
+ if (mbPageSpanOpened)
+ {
+ mrGenerator.closePageSpan();
+ mbPageSpanOpened = false;
+ }
mrGenerator.endDocument();
}
diff --git a/writerperfect/source/writer/exp/xmlimp.hxx b/writerperfect/source/writer/exp/xmlimp.hxx
index de9fa58d7e1f..aeec06bde727 100644
--- a/writerperfect/source/writer/exp/xmlimp.hxx
+++ b/writerperfect/source/writer/exp/xmlimp.hxx
@@ -52,12 +52,15 @@ class XMLImport : public cppu::WeakImplHelper
std::map<OUString, librevenge::RVNGPropertyList> maTableStyles;
std::map<OUString, librevenge::RVNGPropertyList> maAutomaticGraphicStyles;
std::map<OUString, librevenge::RVNGPropertyList> maGraphicStyles;
+ std::map<OUString, librevenge::RVNGPropertyList> maPageLayouts;
+ std::map<OUString, librevenge::RVNGPropertyList> maMasterPages;
librevenge::RVNGPropertyListVector maCoverImages;
/// Author, date, etc -- overwrites what would be from the document out of the box.
librevenge::RVNGPropertyList maMetaData;
const css::uno::Reference<css::uno::XComponentContext> &mxContext;
css::uno::Reference<css::uri::XUriReferenceFactory> mxUriReferenceFactory;
OUString maMediaDir;
+ bool mbPageSpanOpened = false;
public:
XMLImport(const css::uno::Reference<css::uno::XComponentContext> &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const css::uno::Sequence<css::beans::PropertyValue> &rDescriptor);
@@ -79,9 +82,13 @@ public:
std::map<OUString, librevenge::RVNGPropertyList> &GetRowStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetTableStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetGraphicStyles();
+ std::map<OUString, librevenge::RVNGPropertyList> &GetPageLayouts();
+ std::map<OUString, librevenge::RVNGPropertyList> &GetMasterPages();
const librevenge::RVNGPropertyListVector &GetCoverImages();
const librevenge::RVNGPropertyList &GetMetaData();
bool FillPopupData(const OUString &rURL, librevenge::RVNGPropertyList &rPropList);
+ void SetPageSpanOpened(bool bPageSpanOpened);
+ bool IsPageSpanOpened() const;
// XDocumentHandler
void SAL_CALL startDocument() override;