summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-04-01 17:44:14 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-04-01 18:59:26 +0200
commitf3cf833f7079ce8d2f53681cae1b430a875cc320 (patch)
tree248921bddd88a9d1c75e510b20aee77a7d7ead99
parentf4b22d037bc45792ae2f778e03a1cae1b3e2b484 (diff)
tdf#141345 sw page gutter margin: reimplement ODF filter
See <https://issues.oasis-open.org/browse/OFFICE-4105>, the proposal is to include the gutter in the left/top/right margin to have better backwards compatibility, at the price of more complex xmloff code. This works by increasing the left/top/right margin on export (so even if gutter margin is ignored at import time, the layout will look fine, just the editing will be poor) and decreasing on import. Change-Id: I852e5c7366e8641abd61e136f9390466585953fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113464 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sw/qa/extras/odfexport/data/gutter-left.odtbin19355 -> 8519 bytes
-rw-r--r--xmloff/inc/PageMasterStyleMap.hxx1
-rw-r--r--xmloff/qa/unit/data/rtl-gutter.fodt2
-rw-r--r--xmloff/source/style/PageMasterExportPropMapper.cxx83
-rw-r--r--xmloff/source/style/PageMasterExportPropMapper.hxx3
-rw-r--r--xmloff/source/style/PageMasterImportPropMapper.cxx75
-rw-r--r--xmloff/source/style/PageMasterStyleMap.cxx2
-rw-r--r--xmloff/source/style/XMLPageExport.cxx20
8 files changed, 183 insertions, 3 deletions
diff --git a/sw/qa/extras/odfexport/data/gutter-left.odt b/sw/qa/extras/odfexport/data/gutter-left.odt
index a5ce541ef078..a047ecaa3353 100644
--- a/sw/qa/extras/odfexport/data/gutter-left.odt
+++ b/sw/qa/extras/odfexport/data/gutter-left.odt
Binary files differ
diff --git a/xmloff/inc/PageMasterStyleMap.hxx b/xmloff/inc/PageMasterStyleMap.hxx
index 97f32ecae002..657b17d467ad 100644
--- a/xmloff/inc/PageMasterStyleMap.hxx
+++ b/xmloff/inc/PageMasterStyleMap.hxx
@@ -81,6 +81,7 @@
#define CTF_PM_MARGINRIGHT (XML_PM_CTF_START + 0x001E)
#define CTF_PM_WRITINGMODE (XML_PM_CTF_START + 0x001F)
#define CTF_PM_RTLGUTTER (XML_PM_CTF_START + 0x0020)
+#define CTF_PM_MARGINGUTTER (XML_PM_CTF_START + 0x0021)
#define CTF_PM_PAGEUSAGE (XML_PM_CTF_START + 0x0031)
#define CTF_PM_GRAPHICPOSITION (XML_PM_CTF_START + 0x0032)
diff --git a/xmloff/qa/unit/data/rtl-gutter.fodt b/xmloff/qa/unit/data/rtl-gutter.fodt
index ad08d4f33d1a..81524fcede6f 100644
--- a/xmloff/qa/unit/data/rtl-gutter.fodt
+++ b/xmloff/qa/unit/data/rtl-gutter.fodt
@@ -2,7 +2,7 @@
<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:mimetype="application/vnd.oasis.opendocument.text">
<office:automatic-styles>
<style:page-layout style:name="pm1">
- <style:page-layout-properties fo:page-width="21.0cm" fo:page-height="29.7cm" fo:margin-top="2.54cm" fo:margin-bottom="2.54cm" fo:margin-left="2.54cm" fo:margin-right="2.54cm" style:writing-mode="rl-tb" loext:margin-gutter="2.54cm"/>
+ <style:page-layout-properties fo:page-width="21.0cm" fo:page-height="29.7cm" fo:margin-top="2.54cm" fo:margin-bottom="2.54cm" fo:margin-left="2.54cm" fo:margin-right="5.08cm" style:writing-mode="rl-tb" loext:margin-gutter="2.54cm"/>
</style:page-layout>
</office:automatic-styles>
<office:master-styles>
diff --git a/xmloff/source/style/PageMasterExportPropMapper.cxx b/xmloff/source/style/PageMasterExportPropMapper.cxx
index 4ef4de901eb0..725ad6f9e510 100644
--- a/xmloff/source/style/PageMasterExportPropMapper.cxx
+++ b/xmloff/source/style/PageMasterExportPropMapper.cxx
@@ -87,6 +87,13 @@ struct XMLPropertyStateBuffer
XMLPropertyState* pPMPaddingLeft;
XMLPropertyState* pPMPaddingRight;
+ XMLPropertyState* pPMMarginGutter;
+ XMLPropertyState* pPMMarginLeft;
+ XMLPropertyState* pPMRtlGutter;
+ XMLPropertyState* pPMMarginRight;
+ bool m_bGutterAtTop;
+ XMLPropertyState* pPMMarginTop;
+
XMLPropertyStateBuffer();
void ContextFilter( ::std::vector< XMLPropertyState >& rPropState );
};
@@ -112,12 +119,66 @@ XMLPropertyStateBuffer::XMLPropertyStateBuffer()
pPMPaddingTop( nullptr ),
pPMPaddingBottom( nullptr ),
pPMPaddingLeft( nullptr ),
- pPMPaddingRight( nullptr )
+ pPMPaddingRight( nullptr ),
+
+ pPMMarginGutter( nullptr ),
+ pPMMarginLeft( nullptr ),
+ pPMRtlGutter( nullptr ),
+ pPMMarginRight( nullptr ),
+ m_bGutterAtTop( false ),
+ pPMMarginTop( nullptr )
{
}
void XMLPropertyStateBuffer::ContextFilter( ::std::vector< XMLPropertyState >& )
{
+ if (pPMMarginGutter)
+ {
+ sal_Int32 nGutterMargin{};
+ pPMMarginGutter->maValue >>= nGutterMargin;
+ if (m_bGutterAtTop)
+ {
+ if (nGutterMargin && pPMMarginTop)
+ {
+ // Increase top margin to include gutter.
+ sal_Int32 nTopMargin{};
+ pPMMarginTop->maValue >>= nTopMargin;
+ nTopMargin += nGutterMargin;
+ pPMMarginTop->maValue <<= nTopMargin;
+ }
+ }
+ else
+ {
+ bool bRtlGutter{};
+ if (nGutterMargin && pPMRtlGutter)
+ {
+ pPMRtlGutter->maValue >>= bRtlGutter;
+ }
+ if (bRtlGutter)
+ {
+ if (nGutterMargin && pPMMarginRight)
+ {
+ // Increase right margin to include gutter.
+ sal_Int32 nRightMargin{};
+ pPMMarginRight->maValue >>= nRightMargin;
+ nRightMargin += nGutterMargin;
+ pPMMarginRight->maValue <<= nRightMargin;
+ }
+ }
+ else
+ {
+ if (nGutterMargin && pPMMarginLeft)
+ {
+ // Increase left margin to include gutter.
+ sal_Int32 nLeftMargin{};
+ pPMMarginLeft->maValue >>= nLeftMargin;
+ nLeftMargin += nGutterMargin;
+ pPMMarginLeft->maValue <<= nLeftMargin;
+ }
+ }
+ }
+ }
+
if (pPMMarginAll)
{
lcl_RemoveState(pPMMarginAll); // #i117696# do not write fo:margin
@@ -299,6 +360,11 @@ void XMLPageMasterExportPropMapper::ContextFilter(
const Reference< XPropertySet >& rPropSet ) const
{
XMLPropertyStateBuffer aPageBuffer;
+ if (m_bGutterAtTop)
+ {
+ aPageBuffer.m_bGutterAtTop = true;
+ }
+
XMLPropertyStateBuffer aHeaderBuffer;
XMLPropertyStateBuffer aFooterBuffer;
@@ -383,6 +449,21 @@ void XMLPageMasterExportPropMapper::ContextFilter(
case CTF_PM_PADDINGBOTTOM: pBuffer->pPMPaddingBottom = pProp; break;
case CTF_PM_PADDINGLEFT: pBuffer->pPMPaddingLeft = pProp; break;
case CTF_PM_PADDINGRIGHT: pBuffer->pPMPaddingRight = pProp; break;
+ case CTF_PM_MARGINGUTTER:
+ pBuffer->pPMMarginGutter = pProp;
+ break;
+ case CTF_PM_MARGINLEFT:
+ pBuffer->pPMMarginLeft = pProp;
+ break;
+ case CTF_PM_RTLGUTTER:
+ pBuffer->pPMRtlGutter = pProp;
+ break;
+ case CTF_PM_MARGINRIGHT:
+ pBuffer->pPMMarginRight = pProp;
+ break;
+ case CTF_PM_MARGINTOP:
+ pBuffer->pPMMarginTop = pProp;
+ break;
}
switch( nContextId )
diff --git a/xmloff/source/style/PageMasterExportPropMapper.hxx b/xmloff/source/style/PageMasterExportPropMapper.hxx
index b66af4be262f..8aa2debc8654 100644
--- a/xmloff/source/style/PageMasterExportPropMapper.hxx
+++ b/xmloff/source/style/PageMasterExportPropMapper.hxx
@@ -29,6 +29,7 @@ class XMLPageMasterExportPropMapper : public SvXMLExportPropertyMapper
XMLBackgroundImageExport aBackgroundImageExport;
XMLTextColumnsExport aTextColumnsExport;
XMLFootnoteSeparatorExport aFootnoteSeparatorExport;
+ bool m_bGutterAtTop = false;
virtual void ContextFilter(
bool bEnableFoFontFamily,
@@ -58,6 +59,8 @@ public:
const ::std::vector< XMLPropertyState >* pProperties,
sal_uInt32 nIdx
) const override;
+
+ void SetGutterAtTop(bool bGutterAtTop) { m_bGutterAtTop = bGutterAtTop; }
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/style/PageMasterImportPropMapper.cxx b/xmloff/source/style/PageMasterImportPropMapper.cxx
index ae80775aac8b..cee84997dfdd 100644
--- a/xmloff/source/style/PageMasterImportPropMapper.cxx
+++ b/xmloff/source/style/PageMasterImportPropMapper.cxx
@@ -23,6 +23,10 @@
#include <xmloff/maptype.hxx>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
#include <xmloff/xmlimp.hxx>
#include <xmloff/xmlprmap.hxx>
#include <memory>
@@ -124,6 +128,8 @@ void PageMasterImportPropertyMapper::finished(std::vector< XMLPropertyState >& r
XMLPropertyState* pAllFooterMarginProperty = nullptr;
XMLPropertyState* pFooterMargins[4] = { nullptr, nullptr, nullptr, nullptr };
std::unique_ptr<XMLPropertyState> pNewFooterMargins[4];
+ XMLPropertyState* pMarginGutter = nullptr;
+ XMLPropertyState* pRtlGutter = nullptr;
for (auto& rProp : rProperties)
{
@@ -192,6 +198,12 @@ void PageMasterImportPropertyMapper::finished(std::vector< XMLPropertyState >& r
pMargins[XML_LINE_LEFT] = property; break;
case CTF_PM_MARGINRIGHT :
pMargins[XML_LINE_RIGHT] = property; break;
+ case CTF_PM_MARGINGUTTER:
+ pMarginGutter = property;
+ break;
+ case CTF_PM_RTLGUTTER:
+ pRtlGutter = property;
+ break;
case CTF_PM_HEADERMARGINALL :
pAllHeaderMarginProperty = property; break;
case CTF_PM_HEADERMARGINTOP :
@@ -433,6 +445,69 @@ void PageMasterImportPropertyMapper::finished(std::vector< XMLPropertyState >& r
rProperties.push_back(*xFooterDynamic);
xFooterDynamic.reset();
}
+
+ if (pMarginGutter)
+ {
+ sal_Int32 nGutterMargin{};
+ pMarginGutter->maValue >>= nGutterMargin;
+
+ bool bGutterAtTop{};
+ uno::Reference<lang::XServiceInfo> xSI(GetImport().GetModel(), uno::UNO_QUERY);
+ if (xSI.is() && xSI->supportsService("com.sun.star.text.TextDocument"))
+ {
+ uno::Reference<lang::XMultiServiceFactory> xFac(GetImport().GetModel(), uno::UNO_QUERY);
+ if (xFac.is())
+ {
+ uno::Reference<beans::XPropertySet> xProps(
+ xFac->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
+ if (xProps.is())
+ {
+ xProps->getPropertyValue("GutterAtTop") >>= bGutterAtTop;
+ }
+ }
+ }
+ if (bGutterAtTop)
+ {
+ if (nGutterMargin && pMargins[XML_LINE_TOP])
+ {
+ // Decrease top margin to not include gutter.
+ sal_Int32 nTopMargin{};
+ pMargins[XML_LINE_TOP]->maValue >>= nTopMargin;
+ nTopMargin -= nGutterMargin;
+ pMargins[XML_LINE_TOP]->maValue <<= nTopMargin;
+ }
+ }
+ else
+ {
+ bool bRtlGutter{};
+ if (nGutterMargin && pRtlGutter)
+ {
+ pRtlGutter->maValue >>= bRtlGutter;
+ }
+ if (bRtlGutter)
+ {
+ if (nGutterMargin && pMargins[XML_LINE_RIGHT])
+ {
+ // Decrease right margin to not include gutter.
+ sal_Int32 nRightMargin{};
+ pMargins[XML_LINE_RIGHT]->maValue >>= nRightMargin;
+ nRightMargin -= nGutterMargin;
+ pMargins[XML_LINE_RIGHT]->maValue <<= nRightMargin;
+ }
+ }
+ else
+ {
+ if (nGutterMargin && pMargins[XML_LINE_LEFT])
+ {
+ // Decrease left margin to not include gutter.
+ sal_Int32 nLeftMargin{};
+ pMargins[XML_LINE_LEFT]->maValue >>= nLeftMargin;
+ nLeftMargin -= nGutterMargin;
+ pMargins[XML_LINE_LEFT]->maValue <<= nLeftMargin;
+ }
+ }
+ }
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/style/PageMasterStyleMap.cxx b/xmloff/source/style/PageMasterStyleMap.cxx
index dabea33b93ee..7dd3432985fb 100644
--- a/xmloff/source/style/PageMasterStyleMap.cxx
+++ b/xmloff/source/style/PageMasterStyleMap.cxx
@@ -156,7 +156,7 @@ const XMLPropertyMapEntry aXMLPageMasterStyleMap[] =
PLMAP( "FootnoteLineTextDistance", XML_NAMESPACE_STYLE, XML__EMPTY, XML_TYPE_MEASURE|MID_FLAG_SPECIAL_ITEM, CTF_PM_FTN_LINE_DISTANCE ),
PLMAP( "FootnoteLineWeight", XML_NAMESPACE_STYLE, XML_FOOTNOTE_SEP, XML_TYPE_MEASURE16|MID_FLAG_ELEMENT_ITEM, CTF_PM_FTN_LINE_WEIGHT ),
PLMAP( "FootnoteLineStyle", XML_NAMESPACE_STYLE, XML_EMPTY, XML_TYPE_STRING|MID_FLAG_ELEMENT_ITEM, CTF_PM_FTN_LINE_STYLE ),
- PLMAP_EXT("GutterMargin", XML_NAMESPACE_LO_EXT, XML_MARGIN_GUTTER, XML_TYPE_MEASURE, 0),
+ PLMAP_EXT("GutterMargin", XML_NAMESPACE_LO_EXT, XML_MARGIN_GUTTER, XML_TYPE_MEASURE, CTF_PM_MARGINGUTTER),
//////////////////////////////////////////////////////////////////////////
//Index 92: Section for 'header-style' own section, all members *have* to use CTF_PM_HEADERFLAG in the context entry (the 5th one)
diff --git a/xmloff/source/style/XMLPageExport.cxx b/xmloff/source/style/XMLPageExport.cxx
index 140b2d31a60e..0f00a2c13bb6 100644
--- a/xmloff/source/style/XMLPageExport.cxx
+++ b/xmloff/source/style/XMLPageExport.cxx
@@ -225,6 +225,26 @@ XMLPageExport::XMLPageExport(SvXMLExport & rExp)
"Page Styles not found for export!" );
}
}
+
+ if (GetExport().GetModelType() == SvtModuleOptions::EFactory::WRITER)
+ {
+ uno::Reference<lang::XMultiServiceFactory> xFac(GetExport().GetModel(), uno::UNO_QUERY);
+ if (xFac.is())
+ {
+ uno::Reference<beans::XPropertySet> xProps(
+ xFac->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
+ if (xProps.is())
+ {
+ bool bGutterAtTop{};
+ xProps->getPropertyValue("GutterAtTop") >>= bGutterAtTop;
+ if (bGutterAtTop)
+ {
+ static_cast<XMLPageMasterExportPropMapper*>(xPageMasterExportPropMapper.get())
+ ->SetGutterAtTop(true);
+ }
+ }
+ }
+ }
}
XMLPageExport::~XMLPageExport()