Kaydet (Commit) c6d3d064 authored tarafından Mark Hung's avatar Mark Hung Kaydeden (comit) Miklos Vajna

tdf#115623: invoke openPageSpan / closePageSpan

* For paragraphs or tables whose styles specify style:master-page-name,
it indicate starting a new page style and should invoke
openPageSpan / closePageSapn properly.

* closePageSpan at the end of text body is invoked.

Change-Id: Ic85157c9b1a43c94a027b464ad9105e9072afcf7
Reviewed-on: https://gerrit.libreoffice.org/52082Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 8cbf84ed
...@@ -98,6 +98,9 @@ public: ...@@ -98,6 +98,9 @@ public:
void testPopupAPI(); void testPopupAPI();
void testPageSize(); void testPageSize();
void testSVG(); void testSVG();
void testTdf115623SingleWritingMode();
void testTdf115623SplitByChapter();
void testTdf115623ManyPageSpans();
CPPUNIT_TEST_SUITE(EPUBExportTest); CPPUNIT_TEST_SUITE(EPUBExportTest);
CPPUNIT_TEST(testOutlineLevel); CPPUNIT_TEST(testOutlineLevel);
...@@ -144,6 +147,9 @@ public: ...@@ -144,6 +147,9 @@ public:
CPPUNIT_TEST(testPopupAPI); CPPUNIT_TEST(testPopupAPI);
CPPUNIT_TEST(testPageSize); CPPUNIT_TEST(testPageSize);
CPPUNIT_TEST(testSVG); CPPUNIT_TEST(testSVG);
CPPUNIT_TEST(testTdf115623SingleWritingMode);
CPPUNIT_TEST(testTdf115623SplitByChapter);
CPPUNIT_TEST(testTdf115623ManyPageSpans);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -881,6 +887,55 @@ void EPUBExportTest::testSVG() ...@@ -881,6 +887,55 @@ void EPUBExportTest::testSVG()
assertXPathNSDef(mpXmlDoc, "/svg:svg", "xlink", "http://www.w3.org/1999/xlink"); assertXPathNSDef(mpXmlDoc, "/svg:svg", "xlink", "http://www.w3.org/1999/xlink");
} }
void EPUBExportTest::testTdf115623SingleWritingMode()
{
// Simple page that has single writing mode should work.
createDoc("tdf115623-single-writing-mode.odt", {});
std::map< OUString, std::vector<OUString> > aCssDoc = parseCss("OEBPS/styles/stylesheet.css");
mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
OUString aClass = getXPath(mpXmlDoc, "//xhtml:body", "class");
CPPUNIT_ASSERT_EQUAL(OUString("vertical-rl"), EPUBExportTest::getCss(aCssDoc, aClass, "writing-mode"));
}
void EPUBExportTest::testTdf115623SplitByChapter()
{
createDoc("tdf115623-split-by-chapter.odt", {});
std::map< OUString, std::vector<OUString> > aCssDoc = parseCss("OEBPS/styles/stylesheet.css");
{
mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
OUString aClass = getXPath(mpXmlDoc, "//xhtml:body", "class");
CPPUNIT_ASSERT_EQUAL(OUString("vertical-rl"), EPUBExportTest::getCss(aCssDoc, aClass, "writing-mode"));
xmlFreeDoc(mpXmlDoc);
mpXmlDoc = nullptr;
}
// Splitted HTML should keep the same writing-mode.
{
mpXmlDoc = parseExport("OEBPS/sections/section0002.xhtml");
OUString aClass = getXPath(mpXmlDoc, "//xhtml:body", "class");
CPPUNIT_ASSERT_EQUAL(OUString("vertical-rl"), EPUBExportTest::getCss(aCssDoc, aClass, "writing-mode"));
}
}
void EPUBExportTest::testTdf115623ManyPageSpans()
{
createDoc("tdf115623-many-pagespans.odt", {});
std::map< OUString, std::vector<OUString> > aCssDoc = parseCss("OEBPS/styles/stylesheet.css");
// Two pages should have different writing modes.
{
mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
OUString aClass = getXPath(mpXmlDoc, "//xhtml:body", "class");
CPPUNIT_ASSERT_EQUAL(OUString("vertical-rl"), EPUBExportTest::getCss(aCssDoc, aClass, "writing-mode"));
xmlFreeDoc(mpXmlDoc);
mpXmlDoc = nullptr;
}
{
mpXmlDoc = parseExport("OEBPS/sections/section0002.xhtml");
OUString aClass = getXPath(mpXmlDoc, "//xhtml:body", "class");
CPPUNIT_ASSERT_EQUAL(OUString("horizontal-tb"), EPUBExportTest::getCss(aCssDoc, aClass, "writing-mode"));
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest); CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
} }
......
...@@ -402,6 +402,7 @@ void XMLParaContext::startElement(const OUString &/*rName*/, const css::uno::Ref ...@@ -402,6 +402,7 @@ void XMLParaContext::startElement(const OUString &/*rName*/, const css::uno::Ref
m_aStyleName = rAttributeValue; m_aStyleName = rAttributeValue;
FillStyles(m_aStyleName, mrImport.GetAutomaticParagraphStyles(), mrImport.GetParagraphStyles(), aPropertyList); FillStyles(m_aStyleName, mrImport.GetAutomaticParagraphStyles(), mrImport.GetParagraphStyles(), aPropertyList);
FillStyles(m_aStyleName, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), m_aTextPropertyList); FillStyles(m_aStyleName, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), m_aTextPropertyList);
mrImport.HandlePageSpan(aPropertyList);
} }
else else
{ {
......
...@@ -296,6 +296,7 @@ void XMLStyleContext::startElement(const OUString &/*rName*/, const css::uno::Re ...@@ -296,6 +296,7 @@ void XMLStyleContext::startElement(const OUString &/*rName*/, const css::uno::Re
m_aGraphicPropertyList.insert(sName.getStr(), sValue.getStr()); m_aGraphicPropertyList.insert(sName.getStr(), sValue.getStr());
m_aPageLayoutPropertyList.insert(sName.getStr(), sValue.getStr()); m_aPageLayoutPropertyList.insert(sName.getStr(), sValue.getStr());
m_aMasterPagePropertyList.insert(sName.getStr(), sValue.getStr()); m_aMasterPagePropertyList.insert(sName.getStr(), sValue.getStr());
m_aTablePropertyList.insert(sName.getStr(), sValue.getStr());
} }
} }
......
...@@ -339,6 +339,7 @@ void XMLOfficeDocContext::HandleFixedLayoutPage(const FixedLayoutPage &rPage, bo ...@@ -339,6 +339,7 @@ void XMLOfficeDocContext::HandleFixedLayoutPage(const FixedLayoutPage &rPage, bo
XMLImport::XMLImport(const uno::Reference<uno::XComponentContext> &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const uno::Sequence<beans::PropertyValue> &rDescriptor, const std::vector<FixedLayoutPage> &rPageMetafiles) XMLImport::XMLImport(const uno::Reference<uno::XComponentContext> &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const uno::Sequence<beans::PropertyValue> &rDescriptor, const std::vector<FixedLayoutPage> &rPageMetafiles)
: mrGenerator(rGenerator), : mrGenerator(rGenerator),
mxContext(xContext), mxContext(xContext),
mbIsInPageSpan(false),
mrPageMetafiles(rPageMetafiles) mrPageMetafiles(rPageMetafiles)
{ {
uno::Sequence<beans::PropertyValue> aFilterData; uno::Sequence<beans::PropertyValue> aFilterData;
...@@ -595,6 +596,37 @@ void XMLImport::setDocumentLocator(const uno::Reference<xml::sax::XLocator> &/*x ...@@ -595,6 +596,37 @@ void XMLImport::setDocumentLocator(const uno::Reference<xml::sax::XLocator> &/*x
{ {
} }
void XMLImport::HandlePageSpan(const librevenge::RVNGPropertyList &rPropertyList)
{
OUString sMasterPageName;
OUString sLayoutName;
if (rPropertyList["style:master-page-name"])
sMasterPageName = OStringToOUString(rPropertyList["style:master-page-name"]->getStr().cstr(), RTL_TEXTENCODING_UTF8);
else if (!GetIsInPageSpan())
sMasterPageName = "Standard";
if (sMasterPageName.getLength())
{
librevenge::RVNGPropertyList &rMasterPage = GetMasterStyles()[sMasterPageName];
if (rMasterPage["style:page-layout-name"])
{
sLayoutName = OStringToOUString(rMasterPage["style:page-layout-name"]->getStr().cstr(), RTL_TEXTENCODING_UTF8);
}
}
if (sLayoutName.getLength())
{
librevenge::RVNGPropertyList &rPageLayout = GetPageLayouts()[sLayoutName];
if (GetIsInPageSpan())
GetGenerator().closePageSpan();
GetGenerator().openPageSpan(rPageLayout);
SetIsInPageSpan(true);
}
}
} // namespace exp } // namespace exp
} // namespace writerperfect } // namespace writerperfect
......
...@@ -83,6 +83,7 @@ class XMLImport : public cppu::WeakImplHelper ...@@ -83,6 +83,7 @@ class XMLImport : public cppu::WeakImplHelper
const css::uno::Reference<css::uno::XComponentContext> &mxContext; const css::uno::Reference<css::uno::XComponentContext> &mxContext;
css::uno::Reference<css::uri::XUriReferenceFactory> mxUriReferenceFactory; css::uno::Reference<css::uri::XUriReferenceFactory> mxUriReferenceFactory;
OUString maMediaDir; OUString maMediaDir;
bool mbIsInPageSpan;
const std::vector<FixedLayoutPage> &mrPageMetafiles; const std::vector<FixedLayoutPage> &mrPageMetafiles;
public: public:
...@@ -113,6 +114,10 @@ public: ...@@ -113,6 +114,10 @@ public:
const std::vector<FixedLayoutPage> &GetPageMetafiles() const; const std::vector<FixedLayoutPage> &GetPageMetafiles() const;
const css::uno::Reference<css::uno::XComponentContext> &GetComponentContext() const; const css::uno::Reference<css::uno::XComponentContext> &GetComponentContext() const;
bool GetIsInPageSpan() const { return mbIsInPageSpan; }
void SetIsInPageSpan(bool bSet) { mbIsInPageSpan = bSet; }
void HandlePageSpan(const librevenge::RVNGPropertyList &rPropertyList);
// XDocumentHandler // XDocumentHandler
void SAL_CALL startDocument() override; void SAL_CALL startDocument() override;
void SAL_CALL endDocument() override; void SAL_CALL endDocument() override;
......
...@@ -205,7 +205,10 @@ void XMLTableContext::startElement(const OUString &/*rName*/, const css::uno::Re ...@@ -205,7 +205,10 @@ void XMLTableContext::startElement(const OUString &/*rName*/, const css::uno::Re
const OUString &rAttributeValue = xAttribs->getValueByIndex(i); const OUString &rAttributeValue = xAttribs->getValueByIndex(i);
if (rAttributeName == "table:style-name") if (rAttributeName == "table:style-name")
{
FillStyles(rAttributeValue, mrImport.GetAutomaticTableStyles(), mrImport.GetTableStyles(), m_aPropertyList); FillStyles(rAttributeValue, mrImport.GetAutomaticTableStyles(), mrImport.GetTableStyles(), m_aPropertyList);
mrImport.HandlePageSpan(m_aPropertyList);
}
else else
{ {
OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8); OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "xmltbli.hxx" #include "xmltbli.hxx"
#include "XMLSectionContext.hxx" #include "XMLSectionContext.hxx"
#include "XMLTextListContext.hxx" #include "XMLTextListContext.hxx"
#include "xmlimp.hxx"
using namespace com::sun::star; using namespace com::sun::star;
...@@ -26,6 +27,12 @@ XMLBodyContentContext::XMLBodyContentContext(XMLImport &rImport) ...@@ -26,6 +27,12 @@ XMLBodyContentContext::XMLBodyContentContext(XMLImport &rImport)
{ {
} }
void XMLBodyContentContext::endElement(const OUString &/*rName*/)
{
if (mrImport.GetIsInPageSpan())
mrImport.GetGenerator().closePageSpan();
}
rtl::Reference<XMLImportContext> XMLBodyContentContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) rtl::Reference<XMLImportContext> XMLBodyContentContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
{ {
return CreateTextChildContext(mrImport, rName); return CreateTextChildContext(mrImport, rName);
......
...@@ -24,6 +24,7 @@ public: ...@@ -24,6 +24,7 @@ public:
XMLBodyContentContext(XMLImport &rImport); XMLBodyContentContext(XMLImport &rImport);
rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) override; rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) override;
void SAL_CALL endElement(const OUString &rName) override;
}; };
/// Context factory for body text, section, table cell, etc. /// Context factory for body text, section, table cell, etc.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment