1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
21 #include "PageMasterImportPropMapper.hxx"
22 #include <PageMasterStyleMap.hxx>
23 #include <xmloff/maptype.hxx>
24 #include <com/sun/star/table/BorderLine2.hpp>
25 #include <com/sun/star/container/XNameContainer.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <xmloff/xmlimp.hxx>
31 #include <xmloff/xmlprmap.hxx>
32 #include <memory>
33 
34 #define XML_LINE_LEFT 0
35 #define XML_LINE_RIGHT 1
36 #define XML_LINE_TOP 2
37 #define XML_LINE_BOTTOM 3
38 
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::container;
42 
PageMasterImportPropertyMapper(const rtl::Reference<XMLPropertySetMapper> & rMapper,SvXMLImport & rImp)43 PageMasterImportPropertyMapper::PageMasterImportPropertyMapper(
44         const rtl::Reference< XMLPropertySetMapper >& rMapper,
45         SvXMLImport& rImp ) :
46     SvXMLImportPropertyMapper( rMapper, rImp ),
47     rImport( rImp )
48 {
49 }
50 
~PageMasterImportPropertyMapper()51 PageMasterImportPropertyMapper::~PageMasterImportPropertyMapper()
52 {
53 }
54 
handleSpecialItem(XMLPropertyState & rProperty,std::vector<XMLPropertyState> & rProperties,const OUString & rValue,const SvXMLUnitConverter & rUnitConverter,const SvXMLNamespaceMap & rNamespaceMap) const55 bool PageMasterImportPropertyMapper::handleSpecialItem(
56         XMLPropertyState& rProperty,
57         std::vector< XMLPropertyState >& rProperties,
58         const OUString& rValue,
59         const SvXMLUnitConverter& rUnitConverter,
60         const SvXMLNamespaceMap& rNamespaceMap ) const
61 {
62     bool bRet = false;
63     sal_Int16 nContextID =
64             getPropertySetMapper()->GetEntryContextId(rProperty.mnIndex);
65 
66     if( CTF_PM_REGISTER_STYLE==nContextID )
67     {
68         OUString sDisplayName( rImport.GetStyleDisplayName(
69                     XmlStyleFamily::TEXT_PARAGRAPH, rValue ) );
70         Reference < XNameContainer > xParaStyles =
71             rImport.GetTextImport()->GetParaStyles();
72         if( xParaStyles.is() && xParaStyles->hasByName( sDisplayName ) )
73         {
74             rProperty.maValue <<= sDisplayName;
75             bRet = true;
76         }
77     }
78     else
79     {
80         bRet = SvXMLImportPropertyMapper::handleSpecialItem(
81                     rProperty, rProperties, rValue,
82                     rUnitConverter, rNamespaceMap );
83     }
84 
85     return bRet;
86 }
87 
88 
finished(std::vector<XMLPropertyState> & rProperties,sal_Int32 nStartIndex,sal_Int32 nEndIndex) const89 void PageMasterImportPropertyMapper::finished(std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
90 {
91     SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
92     XMLPropertyState* pAllPaddingProperty = nullptr;
93     XMLPropertyState* pPadding[4] = { nullptr, nullptr, nullptr, nullptr };
94     XMLPropertyState* pNewPadding[4] = { nullptr, nullptr, nullptr, nullptr };
95     XMLPropertyState* pAllBorderProperty = nullptr;
96     XMLPropertyState* pBorders[4] = { nullptr, nullptr, nullptr, nullptr };
97     XMLPropertyState* pNewBorders[4] = { nullptr, nullptr, nullptr, nullptr };
98     XMLPropertyState* pAllBorderWidthProperty = nullptr;
99     XMLPropertyState* pBorderWidths[4] = { nullptr, nullptr, nullptr, nullptr };
100     XMLPropertyState* pAllHeaderPaddingProperty = nullptr;
101     XMLPropertyState* pHeaderPadding[4] = { nullptr, nullptr, nullptr, nullptr };
102     XMLPropertyState* pHeaderNewPadding[4] = { nullptr, nullptr, nullptr, nullptr };
103     XMLPropertyState* pAllHeaderBorderProperty = nullptr;
104     XMLPropertyState* pHeaderBorders[4] = { nullptr, nullptr, nullptr, nullptr };
105     XMLPropertyState* pHeaderNewBorders[4] = { nullptr, nullptr, nullptr, nullptr };
106     XMLPropertyState* pAllHeaderBorderWidthProperty = nullptr;
107     XMLPropertyState* pHeaderBorderWidths[4] = { nullptr, nullptr, nullptr, nullptr };
108     XMLPropertyState* pAllFooterPaddingProperty = nullptr;
109     XMLPropertyState* pFooterPadding[4] = { nullptr, nullptr, nullptr, nullptr };
110     XMLPropertyState* pFooterNewPadding[4] = { nullptr, nullptr, nullptr, nullptr };
111     XMLPropertyState* pAllFooterBorderProperty = nullptr;
112     XMLPropertyState* pFooterBorders[4] = { nullptr, nullptr, nullptr, nullptr };
113     XMLPropertyState* pFooterNewBorders[4] = { nullptr, nullptr, nullptr, nullptr };
114     XMLPropertyState* pAllFooterBorderWidthProperty = nullptr;
115     XMLPropertyState* pFooterBorderWidths[4] = { nullptr, nullptr, nullptr, nullptr };
116     XMLPropertyState* pHeaderHeight = nullptr;
117     XMLPropertyState* pHeaderMinHeight = nullptr;
118     std::unique_ptr<XMLPropertyState> xHeaderDynamic;
119     XMLPropertyState* pFooterHeight = nullptr;
120     XMLPropertyState* pFooterMinHeight = nullptr;
121     std::unique_ptr<XMLPropertyState> xFooterDynamic;
122     XMLPropertyState* pAllMarginProperty = nullptr;
123     XMLPropertyState* pMargins[4] = { nullptr, nullptr, nullptr, nullptr };
124     std::unique_ptr<XMLPropertyState> pNewMargins[4];
125     XMLPropertyState* pAllHeaderMarginProperty = nullptr;
126     XMLPropertyState* pHeaderMargins[4] = { nullptr, nullptr, nullptr, nullptr };
127     std::unique_ptr<XMLPropertyState> pNewHeaderMargins[4];
128     XMLPropertyState* pAllFooterMarginProperty = nullptr;
129     XMLPropertyState* pFooterMargins[4] = { nullptr, nullptr, nullptr, nullptr };
130     std::unique_ptr<XMLPropertyState> pNewFooterMargins[4];
131     XMLPropertyState* pMarginGutter = nullptr;
132     XMLPropertyState* pRtlGutter = nullptr;
133 
134     for (auto& rProp : rProperties)
135     {
136         XMLPropertyState *property = &rProp;
137         sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
138         if (property->mnIndex >= nStartIndex && property->mnIndex < nEndIndex)
139         {
140             switch (nContextID)
141             {
142                 case CTF_PM_PADDINGALL                  : pAllPaddingProperty = property; break;
143                 case CTF_PM_PADDINGLEFT                 : pPadding[XML_LINE_LEFT] = property; break;
144                 case CTF_PM_PADDINGRIGHT                : pPadding[XML_LINE_RIGHT] = property; break;
145                 case CTF_PM_PADDINGTOP                  : pPadding[XML_LINE_TOP] = property; break;
146                 case CTF_PM_PADDINGBOTTOM               : pPadding[XML_LINE_BOTTOM] = property; break;
147                 case CTF_PM_BORDERALL                   : pAllBorderProperty = property; break;
148                 case CTF_PM_BORDERLEFT                  : pBorders[XML_LINE_LEFT] = property; break;
149                 case CTF_PM_BORDERRIGHT                 : pBorders[XML_LINE_RIGHT] = property; break;
150                 case CTF_PM_BORDERTOP                   : pBorders[XML_LINE_TOP] = property; break;
151                 case CTF_PM_BORDERBOTTOM                : pBorders[XML_LINE_BOTTOM] = property; break;
152                 case CTF_PM_BORDERWIDTHALL              : pAllBorderWidthProperty = property; break;
153                 case CTF_PM_BORDERWIDTHLEFT             : pBorderWidths[XML_LINE_LEFT] = property; break;
154                 case CTF_PM_BORDERWIDTHRIGHT            : pBorderWidths[XML_LINE_RIGHT] = property; break;
155                 case CTF_PM_BORDERWIDTHTOP              : pBorderWidths[XML_LINE_TOP] = property; break;
156                 case CTF_PM_BORDERWIDTHBOTTOM           : pBorderWidths[XML_LINE_BOTTOM] = property; break;
157                 case CTF_PM_HEADERPADDINGALL            : pAllHeaderPaddingProperty = property; break;
158                 case CTF_PM_HEADERPADDINGLEFT           : pHeaderPadding[XML_LINE_LEFT] = property; break;
159                 case CTF_PM_HEADERPADDINGRIGHT          : pHeaderPadding[XML_LINE_RIGHT] = property; break;
160                 case CTF_PM_HEADERPADDINGTOP            : pHeaderPadding[XML_LINE_TOP] = property; break;
161                 case CTF_PM_HEADERPADDINGBOTTOM         : pHeaderPadding[XML_LINE_BOTTOM] = property; break;
162                 case CTF_PM_HEADERBORDERALL             : pAllHeaderBorderProperty = property; break;
163                 case CTF_PM_HEADERBORDERLEFT            : pHeaderBorders[XML_LINE_LEFT] = property; break;
164                 case CTF_PM_HEADERBORDERRIGHT           : pHeaderBorders[XML_LINE_RIGHT] = property; break;
165                 case CTF_PM_HEADERBORDERTOP             : pHeaderBorders[XML_LINE_TOP] = property; break;
166                 case CTF_PM_HEADERBORDERBOTTOM          : pHeaderBorders[XML_LINE_BOTTOM] = property; break;
167                 case CTF_PM_HEADERBORDERWIDTHALL        : pAllHeaderBorderWidthProperty = property; break;
168                 case CTF_PM_HEADERBORDERWIDTHLEFT       : pHeaderBorderWidths[XML_LINE_LEFT] = property; break;
169                 case CTF_PM_HEADERBORDERWIDTHRIGHT      : pHeaderBorderWidths[XML_LINE_RIGHT] = property; break;
170                 case CTF_PM_HEADERBORDERWIDTHTOP        : pHeaderBorderWidths[XML_LINE_TOP] = property; break;
171                 case CTF_PM_HEADERBORDERWIDTHBOTTOM     : pHeaderBorderWidths[XML_LINE_BOTTOM] = property; break;
172                 case CTF_PM_FOOTERPADDINGALL            : pAllFooterPaddingProperty = property; break;
173                 case CTF_PM_FOOTERPADDINGLEFT           : pFooterPadding[XML_LINE_LEFT] = property; break;
174                 case CTF_PM_FOOTERPADDINGRIGHT          : pFooterPadding[XML_LINE_RIGHT] = property; break;
175                 case CTF_PM_FOOTERPADDINGTOP            : pFooterPadding[XML_LINE_TOP] = property; break;
176                 case CTF_PM_FOOTERPADDINGBOTTOM         : pFooterPadding[XML_LINE_BOTTOM] = property; break;
177                 case CTF_PM_FOOTERBORDERALL             : pAllFooterBorderProperty = property; break;
178                 case CTF_PM_FOOTERBORDERLEFT            : pFooterBorders[XML_LINE_LEFT] = property; break;
179                 case CTF_PM_FOOTERBORDERRIGHT           : pFooterBorders[XML_LINE_RIGHT] = property; break;
180                 case CTF_PM_FOOTERBORDERTOP             : pFooterBorders[XML_LINE_TOP] = property; break;
181                 case CTF_PM_FOOTERBORDERBOTTOM          : pFooterBorders[XML_LINE_BOTTOM] = property; break;
182                 case CTF_PM_FOOTERBORDERWIDTHALL        : pAllFooterBorderWidthProperty = property; break;
183                 case CTF_PM_FOOTERBORDERWIDTHLEFT       : pFooterBorderWidths[XML_LINE_LEFT] = property; break;
184                 case CTF_PM_FOOTERBORDERWIDTHRIGHT      : pFooterBorderWidths[XML_LINE_RIGHT] = property; break;
185                 case CTF_PM_FOOTERBORDERWIDTHTOP        : pFooterBorderWidths[XML_LINE_TOP] = property; break;
186                 case CTF_PM_FOOTERBORDERWIDTHBOTTOM     : pFooterBorderWidths[XML_LINE_BOTTOM] = property; break;
187                 case CTF_PM_HEADERHEIGHT                : pHeaderHeight = property; break;
188                 case CTF_PM_HEADERMINHEIGHT             : pHeaderMinHeight = property; break;
189                 case CTF_PM_FOOTERHEIGHT                : pFooterHeight = property; break;
190                 case CTF_PM_FOOTERMINHEIGHT             : pFooterMinHeight = property; break;
191                 case CTF_PM_MARGINALL   :
192                       pAllMarginProperty = property; break;
193                 case CTF_PM_MARGINTOP   :
194                       pMargins[XML_LINE_TOP] = property; break;
195                 case CTF_PM_MARGINBOTTOM:
196                       pMargins[XML_LINE_BOTTOM] = property; break;
197                 case CTF_PM_MARGINLEFT  :
198                       pMargins[XML_LINE_LEFT] = property; break;
199                 case CTF_PM_MARGINRIGHT :
200                       pMargins[XML_LINE_RIGHT] = property; break;
201                 case CTF_PM_MARGINGUTTER:
202                     pMarginGutter = property;
203                     break;
204                 case CTF_PM_RTLGUTTER:
205                     pRtlGutter = property;
206                     break;
207                 case CTF_PM_HEADERMARGINALL   :
208                       pAllHeaderMarginProperty = property; break;
209                 case CTF_PM_HEADERMARGINTOP   :
210                       pHeaderMargins[XML_LINE_TOP] = property; break;
211                 case CTF_PM_HEADERMARGINBOTTOM:
212                       pHeaderMargins[XML_LINE_BOTTOM] = property; break;
213                 case CTF_PM_HEADERMARGINLEFT  :
214                       pHeaderMargins[XML_LINE_LEFT] = property; break;
215                 case CTF_PM_HEADERMARGINRIGHT :
216                       pHeaderMargins[XML_LINE_RIGHT] = property; break;
217                 case CTF_PM_FOOTERMARGINALL   :
218                       pAllFooterMarginProperty = property; break;
219                 case CTF_PM_FOOTERMARGINTOP   :
220                       pFooterMargins[XML_LINE_TOP] = property; break;
221                 case CTF_PM_FOOTERMARGINBOTTOM:
222                       pFooterMargins[XML_LINE_BOTTOM] = property; break;
223                 case CTF_PM_FOOTERMARGINLEFT  :
224                       pFooterMargins[XML_LINE_LEFT] = property; break;
225                 case CTF_PM_FOOTERMARGINRIGHT :
226                       pFooterMargins[XML_LINE_RIGHT] = property; break;
227             }
228         }
229     }
230 
231     for (sal_uInt16 i = 0; i < 4; i++)
232     {
233         if (pAllMarginProperty && !pMargins[i])
234         {
235             pNewMargins[i].reset(new XMLPropertyState(
236                 pAllMarginProperty->mnIndex + 1 + i,
237                 pAllMarginProperty->maValue));
238         }
239         if (pAllHeaderMarginProperty && !pHeaderMargins[i])
240         {
241             pNewHeaderMargins[i].reset(new XMLPropertyState(
242                 pAllHeaderMarginProperty->mnIndex + 1 + i,
243                 pAllHeaderMarginProperty->maValue));
244         }
245         if (pAllFooterMarginProperty && !pFooterMargins[i])
246         {
247             pNewFooterMargins[i].reset(new XMLPropertyState(
248                 pAllFooterMarginProperty->mnIndex + 1 + i,
249                 pAllFooterMarginProperty->maValue));
250         }
251         if (pAllPaddingProperty && !pPadding[i])
252             pNewPadding[i] = new XMLPropertyState(pAllPaddingProperty->mnIndex + 1 + i, pAllPaddingProperty->maValue);
253         if (pAllBorderProperty && !pBorders[i])
254         {
255             pNewBorders[i] = new XMLPropertyState(pAllBorderProperty->mnIndex + 1 + i, pAllBorderProperty->maValue);
256             pBorders[i] = pNewBorders[i];
257         }
258         if( !pBorderWidths[i] )
259             pBorderWidths[i] = pAllBorderWidthProperty;
260         else
261             pBorderWidths[i]->mnIndex = -1;
262         if( pBorders[i] )
263         {
264             table::BorderLine2 aBorderLine;
265             pBorders[i]->maValue >>= aBorderLine;
266             if( pBorderWidths[i] )
267             {
268                 table::BorderLine2 aBorderLineWidth;
269                 pBorderWidths[i]->maValue >>= aBorderLineWidth;
270                 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
271                 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
272                 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
273                 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
274                 pBorders[i]->maValue <<= aBorderLine;
275             }
276         }
277         if (pAllHeaderPaddingProperty && !pHeaderPadding[i])
278             pHeaderNewPadding[i] = new XMLPropertyState(pAllHeaderPaddingProperty->mnIndex + 1 + i, pAllHeaderPaddingProperty->maValue);
279         if (pAllHeaderBorderProperty && !pHeaderBorders[i])
280             pHeaderNewBorders[i] = new XMLPropertyState(pAllHeaderBorderProperty->mnIndex + 1 + i, pAllHeaderBorderProperty->maValue);
281         if( !pHeaderBorderWidths[i] )
282             pHeaderBorderWidths[i] = pAllHeaderBorderWidthProperty;
283         else
284             pHeaderBorderWidths[i]->mnIndex = -1;
285         if( pHeaderBorders[i] )
286         {
287             table::BorderLine2 aBorderLine;
288             pHeaderBorders[i]->maValue >>= aBorderLine;
289             if( pHeaderBorderWidths[i] )
290             {
291                 table::BorderLine2 aBorderLineWidth;
292                 pHeaderBorderWidths[i]->maValue >>= aBorderLineWidth;
293                 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
294                 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
295                 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
296                 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
297                 pHeaderBorders[i]->maValue <<= aBorderLine;
298             }
299         }
300         if (pAllFooterPaddingProperty && !pFooterPadding[i])
301             pFooterNewPadding[i] = new XMLPropertyState(pAllFooterPaddingProperty->mnIndex + 1 + i, pAllFooterPaddingProperty->maValue);
302         if (pAllFooterBorderProperty && !pFooterBorders[i])
303             pFooterNewBorders[i] = new XMLPropertyState(pAllFooterBorderProperty->mnIndex + 1 + i, pAllFooterBorderProperty->maValue);
304         if( !pFooterBorderWidths[i] )
305             pFooterBorderWidths[i] = pAllFooterBorderWidthProperty;
306         else
307             pFooterBorderWidths[i]->mnIndex = -1;
308         if( pFooterBorders[i] )
309         {
310             table::BorderLine2 aBorderLine;
311             pFooterBorders[i]->maValue >>= aBorderLine;
312             if( pFooterBorderWidths[i] )
313             {
314                 table::BorderLine2 aBorderLineWidth;
315                 pFooterBorderWidths[i]->maValue >>= aBorderLineWidth;
316                 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
317                 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
318                 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
319                 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
320                 pFooterBorders[i]->maValue <<= aBorderLine;
321             }
322         }
323     }
324 
325     if (pHeaderHeight)
326     {
327         xHeaderDynamic.reset(new XMLPropertyState(pHeaderHeight->mnIndex + 2, Any(false)));
328     }
329     if (pHeaderMinHeight)
330     {
331         xHeaderDynamic.reset(new XMLPropertyState(pHeaderMinHeight->mnIndex + 1, Any(true)));
332     }
333     if (pFooterHeight)
334     {
335         xFooterDynamic.reset(new XMLPropertyState(pFooterHeight->mnIndex + 2, Any(false)));
336     }
337     if (pFooterMinHeight)
338     {
339         xFooterDynamic.reset(new XMLPropertyState(pFooterMinHeight->mnIndex + 1, Any(true)));
340     }
341 
342     // fdo#38056: nerf the various AllFoo properties so they do not override
343     // the individual Foo properties later on
344     if (pAllPaddingProperty)
345     {
346         pAllPaddingProperty->mnIndex = -1;
347     }
348     if (pAllBorderProperty)
349     {
350         pAllBorderProperty->mnIndex = -1;
351     }
352     if (pAllBorderWidthProperty)
353     {
354         pAllBorderWidthProperty->mnIndex = -1;
355     }
356     if (pAllHeaderPaddingProperty)
357     {
358         pAllHeaderPaddingProperty->mnIndex = -1;
359     }
360     if (pAllHeaderBorderProperty)
361     {
362         pAllHeaderBorderProperty->mnIndex = -1;
363     }
364     if (pAllHeaderBorderWidthProperty)
365     {
366         pAllHeaderBorderWidthProperty->mnIndex = -1;
367     }
368     if (pAllFooterPaddingProperty)
369     {
370         pAllFooterPaddingProperty->mnIndex = -1;
371     }
372     if (pAllFooterBorderProperty)
373     {
374         pAllFooterBorderProperty->mnIndex = -1;
375     }
376     if (pAllFooterBorderWidthProperty)
377     {
378         pAllFooterBorderWidthProperty->mnIndex = -1;
379     }
380     if (pAllMarginProperty)
381     {
382         pAllMarginProperty->mnIndex = -1;
383     }
384     if (pAllHeaderMarginProperty)
385     {
386         pAllHeaderMarginProperty->mnIndex = -1;
387     }
388     if (pAllFooterMarginProperty)
389     {
390         pAllFooterMarginProperty->mnIndex = -1;
391     }
392 
393     for (sal_uInt16 i = 0; i < 4; i++)
394     {
395         if (pNewMargins[i])
396         {
397             rProperties.push_back(*pNewMargins[i]);
398         }
399         if (pNewHeaderMargins[i])
400         {
401             rProperties.push_back(*pNewHeaderMargins[i]);
402         }
403         if (pNewFooterMargins[i])
404         {
405             rProperties.push_back(*pNewFooterMargins[i]);
406         }
407         if (pNewPadding[i])
408         {
409             rProperties.push_back(*pNewPadding[i]);
410             delete pNewPadding[i];
411         }
412         if (pNewBorders[i])
413         {
414             rProperties.push_back(*pNewBorders[i]);
415             delete pNewBorders[i];
416         }
417         if (pHeaderNewPadding[i])
418         {
419             rProperties.push_back(*pHeaderNewPadding[i]);
420             delete pHeaderNewPadding[i];
421         }
422         if (pHeaderNewBorders[i])
423         {
424             rProperties.push_back(*pHeaderNewBorders[i]);
425             delete pHeaderNewBorders[i];
426         }
427         if (pFooterNewPadding[i])
428         {
429             rProperties.push_back(*pFooterNewPadding[i]);
430             delete pFooterNewPadding[i];
431         }
432         if (pFooterNewBorders[i])
433         {
434             rProperties.push_back(*pFooterNewBorders[i]);
435             delete pFooterNewBorders[i];
436         }
437     }
438     if(xHeaderDynamic)
439     {
440         rProperties.push_back(*xHeaderDynamic);
441         xHeaderDynamic.reset();
442     }
443     if(xFooterDynamic)
444     {
445         rProperties.push_back(*xFooterDynamic);
446         xFooterDynamic.reset();
447     }
448 
449     if (pMarginGutter)
450     {
451         sal_Int32 nGutterMargin{};
452         pMarginGutter->maValue >>= nGutterMargin;
453 
454         bool bGutterAtTop{};
455         uno::Reference<lang::XServiceInfo> xSI(GetImport().GetModel(), uno::UNO_QUERY);
456         if (xSI.is() && xSI->supportsService("com.sun.star.text.TextDocument"))
457         {
458             uno::Reference<lang::XMultiServiceFactory> xFac(GetImport().GetModel(), uno::UNO_QUERY);
459             if (xFac.is())
460             {
461                 uno::Reference<beans::XPropertySet> xProps(
462                     xFac->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
463                 if (xProps.is())
464                 {
465                     xProps->getPropertyValue("GutterAtTop") >>= bGutterAtTop;
466                 }
467             }
468         }
469         if (bGutterAtTop)
470         {
471             if (nGutterMargin && pMargins[XML_LINE_TOP])
472             {
473                 // Decrease top margin to not include gutter.
474                 sal_Int32 nTopMargin{};
475                 pMargins[XML_LINE_TOP]->maValue >>= nTopMargin;
476                 nTopMargin -= nGutterMargin;
477                 pMargins[XML_LINE_TOP]->maValue <<= nTopMargin;
478             }
479         }
480         else
481         {
482             bool bRtlGutter{};
483             if (nGutterMargin && pRtlGutter)
484             {
485                 pRtlGutter->maValue >>= bRtlGutter;
486             }
487             if (bRtlGutter)
488             {
489                 if (nGutterMargin && pMargins[XML_LINE_RIGHT])
490                 {
491                     // Decrease right margin to not include gutter.
492                     sal_Int32 nRightMargin{};
493                     pMargins[XML_LINE_RIGHT]->maValue >>= nRightMargin;
494                     nRightMargin -= nGutterMargin;
495                     pMargins[XML_LINE_RIGHT]->maValue <<= nRightMargin;
496                 }
497             }
498             else
499             {
500                 if (nGutterMargin && pMargins[XML_LINE_LEFT])
501                 {
502                     // Decrease left margin to not include gutter.
503                     sal_Int32 nLeftMargin{};
504                     pMargins[XML_LINE_LEFT]->maValue >>= nLeftMargin;
505                     nLeftMargin -= nGutterMargin;
506                     pMargins[XML_LINE_LEFT]->maValue <<= nLeftMargin;
507                 }
508             }
509         }
510     }
511 }
512 
513 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
514