From 8b8aa6bc010fffbcd47679aa101075d702741f69 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 24 Nov 2017 09:14:05 +0100 Subject: EPUB export: handle total table width This is important when e.g. the col width are 50-50%, then without explicit total table width the table width won't be correct. Change-Id: I5ccd6dfb5b78c564485d54cda62e12f3d1ca36c1 Reviewed-on: https://gerrit.libreoffice.org/45204 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- writerperfect/source/writer/exp/txtstyli.cxx | 41 ++++++++++++++++++++++++++++ writerperfect/source/writer/exp/txtstyli.hxx | 2 ++ writerperfect/source/writer/exp/xmlfmt.cxx | 11 ++++++-- writerperfect/source/writer/exp/xmlfmt.hxx | 5 +++- writerperfect/source/writer/exp/xmlimp.cxx | 16 +++++++++-- writerperfect/source/writer/exp/xmlimp.hxx | 4 +++ writerperfect/source/writer/exp/xmltbli.cxx | 23 ++++++++++++++-- writerperfect/source/writer/exp/xmltbli.hxx | 2 ++ 8 files changed, 96 insertions(+), 8 deletions(-) (limited to 'writerperfect/source/writer/exp') diff --git a/writerperfect/source/writer/exp/txtstyli.cxx b/writerperfect/source/writer/exp/txtstyli.cxx index 48f5f72beff8..c05d53cc87b9 100644 --- a/writerperfect/source/writer/exp/txtstyli.cxx +++ b/writerperfect/source/writer/exp/txtstyli.cxx @@ -75,6 +75,38 @@ void XMLTextPropertiesContext::startElement(const OUString &/*rName*/, const css } } +/// Handler for . +class XMLTablePropertiesContext : public XMLImportContext +{ +public: + XMLTablePropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle); + + void SAL_CALL startElement(const OUString &rName, const css::uno::Reference &xAttribs) override; + +private: + XMLStyleContext &mrStyle; +}; + +XMLTablePropertiesContext::XMLTablePropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle) + : XMLImportContext(rImport) + , mrStyle(rStyle) +{ +} + +void XMLTablePropertiesContext::startElement(const OUString &/*rName*/, const css::uno::Reference &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); + if (sName == "style:rel-width") + // Make sure this is passed through as a string, and not parsed as a double. + mrStyle.GetTablePropertyList().insert(sName.getStr(), librevenge::RVNGPropertyFactory::newStringProp(sValue.getStr())); + else + mrStyle.GetTablePropertyList().insert(sName.getStr(), sValue.getStr()); + } +} + /// Handler for . class XMLTableRowPropertiesContext : public XMLImportContext { @@ -177,6 +209,8 @@ rtl::Reference XMLStyleContext::CreateChildContext(const OUStr return new XMLTableColumnPropertiesContext(mrImport, *this); if (rName == "style:table-row-properties") return new XMLTableRowPropertiesContext(mrImport, *this); + if (rName == "style:table-properties") + return new XMLTablePropertiesContext(mrImport, *this); return nullptr; } @@ -214,6 +248,8 @@ void XMLStyleContext::endElement(const OUString &/*rName*/) m_rStyles.GetCurrentColumnStyles()[m_aName] = m_aColumnPropertyList; if (m_aFamily == "table-row") m_rStyles.GetCurrentRowStyles()[m_aName] = m_aRowPropertyList; + if (m_aFamily == "table") + m_rStyles.GetCurrentTableStyles()[m_aName] = m_aTablePropertyList; } librevenge::RVNGPropertyList &XMLStyleContext::GetTextPropertyList() @@ -241,6 +277,11 @@ librevenge::RVNGPropertyList &XMLStyleContext::GetRowPropertyList() return m_aRowPropertyList; } +librevenge::RVNGPropertyList &XMLStyleContext::GetTablePropertyList() +{ + return m_aTablePropertyList; +} + } // namespace exp } // namespace writerperfect diff --git a/writerperfect/source/writer/exp/txtstyli.hxx b/writerperfect/source/writer/exp/txtstyli.hxx index 6d0e2c1828a8..9855d459e360 100644 --- a/writerperfect/source/writer/exp/txtstyli.hxx +++ b/writerperfect/source/writer/exp/txtstyli.hxx @@ -36,6 +36,7 @@ public: librevenge::RVNGPropertyList &GetCellPropertyList(); librevenge::RVNGPropertyList &GetColumnPropertyList(); librevenge::RVNGPropertyList &GetRowPropertyList(); + librevenge::RVNGPropertyList &GetTablePropertyList(); private: OUString m_aName; @@ -45,6 +46,7 @@ private: librevenge::RVNGPropertyList m_aCellPropertyList; librevenge::RVNGPropertyList m_aColumnPropertyList; librevenge::RVNGPropertyList m_aRowPropertyList; + librevenge::RVNGPropertyList m_aTablePropertyList; XMLStylesContext &m_rStyles; }; diff --git a/writerperfect/source/writer/exp/xmlfmt.cxx b/writerperfect/source/writer/exp/xmlfmt.cxx index 2c73a9a8c968..23550616953b 100644 --- a/writerperfect/source/writer/exp/xmlfmt.cxx +++ b/writerperfect/source/writer/exp/xmlfmt.cxx @@ -23,13 +23,15 @@ XMLStylesContext::XMLStylesContext(XMLImport &rImport, std::map &rTextStyles, std::map &rCellStyles, std::map &rColumnStyles, - std::map &rRowStyles) + std::map &rRowStyles, + std::map &rTableStyles) : XMLImportContext(rImport), m_rParagraphStyles(rParagraphStyles), m_rTextStyles(rTextStyles), m_rCellStyles(rCellStyles), m_rColumnStyles(rColumnStyles), - m_rRowStyles(rRowStyles) + m_rRowStyles(rRowStyles), + m_rTableStyles(rTableStyles) { } @@ -65,6 +67,11 @@ std::map &XMLStylesContext::GetCurrentRo return m_rRowStyles; } +std::map &XMLStylesContext::GetCurrentTableStyles() +{ + return m_rTableStyles; +} + } // namespace exp } // namespace writerperfect diff --git a/writerperfect/source/writer/exp/xmlfmt.hxx b/writerperfect/source/writer/exp/xmlfmt.hxx index 7ab31d1c7e97..74d4b20d84f0 100644 --- a/writerperfect/source/writer/exp/xmlfmt.hxx +++ b/writerperfect/source/writer/exp/xmlfmt.hxx @@ -29,7 +29,8 @@ public: std::map &rTextStyles, std::map &rCellStyles, std::map &rColumnStyles, - std::map &rRowStyles); + std::map &rRowStyles, + std::map &rTableStyles); rtl::Reference CreateChildContext(const OUString &rName, const css::uno::Reference &xAttribs) override; @@ -38,12 +39,14 @@ public: std::map &GetCurrentCellStyles(); std::map &GetCurrentColumnStyles(); std::map &GetCurrentRowStyles(); + std::map &GetCurrentTableStyles(); private: std::map &m_rParagraphStyles; std::map &m_rTextStyles; std::map &m_rCellStyles; std::map &m_rColumnStyles; std::map &m_rRowStyles; + std::map &m_rTableStyles; }; } // namespace exp diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx index 806c3eaa35d0..0f6582ff7403 100644 --- a/writerperfect/source/writer/exp/xmlimp.cxx +++ b/writerperfect/source/writer/exp/xmlimp.cxx @@ -67,13 +67,15 @@ rtl::Reference XMLOfficeDocContext::CreateChildContext(const O mrImport.GetAutomaticTextStyles(), mrImport.GetAutomaticCellStyles(), mrImport.GetAutomaticColumnStyles(), - mrImport.GetAutomaticRowStyles()); + mrImport.GetAutomaticRowStyles(), + mrImport.GetAutomaticTableStyles()); else if (rName == "office:styles") return new XMLStylesContext(mrImport, mrImport.GetParagraphStyles(), mrImport.GetTextStyles(), mrImport.GetCellStyles(), mrImport.GetColumnStyles(), - mrImport.GetRowStyles()); + mrImport.GetRowStyles(), + mrImport.GetTableStyles()); return nullptr; } @@ -119,6 +121,11 @@ std::map &XMLImport::GetAutomaticRowStyl return maAutomaticRowStyles; } +std::map &XMLImport::GetAutomaticTableStyles() +{ + return maAutomaticTableStyles; +} + std::map &XMLImport::GetTextStyles() { return maTextStyles; @@ -144,6 +151,11 @@ std::map &XMLImport::GetRowStyles() return maRowStyles; } +std::map &XMLImport::GetTableStyles() +{ + return maTableStyles; +} + void XMLImport::startDocument() { mrGenerator.startDocument(librevenge::RVNGPropertyList()); diff --git a/writerperfect/source/writer/exp/xmlimp.hxx b/writerperfect/source/writer/exp/xmlimp.hxx index a2efde2e10c7..7f690d86a165 100644 --- a/writerperfect/source/writer/exp/xmlimp.hxx +++ b/writerperfect/source/writer/exp/xmlimp.hxx @@ -45,6 +45,8 @@ class XMLImport : public cppu::WeakImplHelper std::map maColumnStyles; std::map maAutomaticRowStyles; std::map maRowStyles; + std::map maAutomaticTableStyles; + std::map maTableStyles; public: XMLImport(librevenge::RVNGTextInterface &rGenerator); @@ -57,11 +59,13 @@ public: std::map &GetAutomaticCellStyles(); std::map &GetAutomaticColumnStyles(); std::map &GetAutomaticRowStyles(); + std::map &GetAutomaticTableStyles(); std::map &GetTextStyles(); std::map &GetParagraphStyles(); std::map &GetCellStyles(); std::map &GetColumnStyles(); std::map &GetRowStyles(); + std::map &GetTableStyles(); // XDocumentHandler void SAL_CALL startDocument() override; diff --git a/writerperfect/source/writer/exp/xmltbli.cxx b/writerperfect/source/writer/exp/xmltbli.cxx index 19ea15d502a8..bec52dab0f22 100644 --- a/writerperfect/source/writer/exp/xmltbli.cxx +++ b/writerperfect/source/writer/exp/xmltbli.cxx @@ -183,10 +183,9 @@ rtl::Reference XMLTableContext::CreateChildContext(const OUStr if (!m_bTableOpened) { - librevenge::RVNGPropertyList aPropertyList; if (!m_aColumns.empty()) - aPropertyList.insert("librevenge:table-columns", m_aColumns); - mrImport.GetGenerator().openTable(aPropertyList); + m_aPropertyList.insert("librevenge:table-columns", m_aColumns); + mrImport.GetGenerator().openTable(m_aPropertyList); m_bTableOpened = true; } @@ -198,6 +197,24 @@ rtl::Reference XMLTableContext::CreateChildContext(const OUStr return nullptr; } +void XMLTableContext::startElement(const OUString &/*rName*/, const css::uno::Reference &xAttribs) +{ + for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) + { + const OUString &rAttributeName = xAttribs->getNameByIndex(i); + const OUString &rAttributeValue = xAttribs->getValueByIndex(i); + + if (rAttributeName == "table:style-name") + FillStyles(rAttributeValue, mrImport.GetAutomaticTableStyles(), mrImport.GetTableStyles(), m_aPropertyList); + else + { + OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8); + OString sValue = OUStringToOString(rAttributeValue, RTL_TEXTENCODING_UTF8); + m_aPropertyList.insert(sName.getStr(), sValue.getStr()); + } + } +} + void XMLTableContext::endElement(const OUString &/*rName*/) { mrImport.GetGenerator().closeTable(); diff --git a/writerperfect/source/writer/exp/xmltbli.hxx b/writerperfect/source/writer/exp/xmltbli.hxx index c3671b433dab..01228ea9cdfe 100644 --- a/writerperfect/source/writer/exp/xmltbli.hxx +++ b/writerperfect/source/writer/exp/xmltbli.hxx @@ -25,10 +25,12 @@ public: rtl::Reference CreateChildContext(const OUString &rName, const css::uno::Reference &xAttribs) override; + void SAL_CALL startElement(const OUString &rName, const css::uno::Reference &xAttribs) override; void SAL_CALL endElement(const OUString &rName) override; private: bool m_bTableOpened = false; + librevenge::RVNGPropertyList m_aPropertyList; librevenge::RVNGPropertyListVector m_aColumns; }; -- cgit v1.2.3