bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / PageMasterExportPropMapper.cxx
blob961c5eb08382a2c3dd45ee5029163872b4e41712
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "PageMasterExportPropMapper.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <comphelper/types.hxx>
23 #include <com/sun/star/table/BorderLine2.hpp>
24 #include <xmloff/PageMasterStyleMap.hxx>
25 #include <tools/debug.hxx>
26 #include <rtl/ustrbuf.hxx>
27 #include <comphelper/extract.hxx>
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::beans;
32 using namespace ::comphelper;
33 using namespace ::xmloff::token;
36 //______________________________________________________________________________
38 static inline sal_Bool lcl_HasSameLineWidth( const table::BorderLine2& rLine1, const table::BorderLine2& rLine2 )
40 return (rLine1.InnerLineWidth == rLine2.InnerLineWidth) &&
41 (rLine1.OuterLineWidth == rLine2.OuterLineWidth) &&
42 (rLine1.LineDistance == rLine2.LineDistance) &&
43 (rLine1.LineWidth == rLine2.LineWidth);
46 inline sal_Bool operator==( const table::BorderLine2& rLine1, const table::BorderLine2& rLine2 )
48 return (rLine1.Color == rLine2.Color) &&
49 lcl_HasSameLineWidth( rLine1, rLine2 ) &&
50 ( rLine1.LineStyle == rLine2.LineStyle );
53 static inline void lcl_RemoveState( XMLPropertyState* pState )
55 pState->mnIndex = -1;
56 pState->maValue.clear();
59 static void lcl_RemoveStateIfZero16( XMLPropertyState* pState )
61 sal_Int16 nValue = sal_Int16();
62 if( (pState->maValue >>= nValue) && !nValue )
63 lcl_RemoveState( pState );
66 static void lcl_AddState(::std::vector< XMLPropertyState >& rPropState, sal_Int32 nIndex, const OUString& rProperty, uno::Reference< beans::XPropertySet >& xProps)
68 if(::cppu::any2bool(xProps->getPropertyValue(rProperty)))
69 rPropState.push_back(XMLPropertyState (nIndex, cppu::bool2any(sal_True)));
72 //______________________________________________________________________________
73 // helper struct to handle equal XMLPropertyState's for page, header and footer
75 struct XMLPropertyStateBuffer
77 XMLPropertyState* pPMMarginAll;
78 XMLPropertyState* pPMMarginTop;
79 XMLPropertyState* pPMMarginBottom;
80 XMLPropertyState* pPMMarginLeft;
81 XMLPropertyState* pPMMarginRight;
83 XMLPropertyState* pPMBorderAll;
84 XMLPropertyState* pPMBorderTop;
85 XMLPropertyState* pPMBorderBottom;
86 XMLPropertyState* pPMBorderLeft;
87 XMLPropertyState* pPMBorderRight;
89 XMLPropertyState* pPMBorderWidthAll;
90 XMLPropertyState* pPMBorderWidthTop;
91 XMLPropertyState* pPMBorderWidthBottom;
92 XMLPropertyState* pPMBorderWidthLeft;
93 XMLPropertyState* pPMBorderWidthRight;
95 XMLPropertyState* pPMPaddingAll;
96 XMLPropertyState* pPMPaddingTop;
97 XMLPropertyState* pPMPaddingBottom;
98 XMLPropertyState* pPMPaddingLeft;
99 XMLPropertyState* pPMPaddingRight;
101 XMLPropertyStateBuffer();
102 void ContextFilter( ::std::vector< XMLPropertyState >& rPropState );
105 XMLPropertyStateBuffer::XMLPropertyStateBuffer()
106 : pPMMarginAll( NULL )
107 , pPMMarginTop( NULL )
108 , pPMMarginBottom( NULL )
109 , pPMMarginLeft( NULL )
110 , pPMMarginRight( NULL )
112 pPMBorderAll( NULL ),
113 pPMBorderTop( NULL ),
114 pPMBorderBottom( NULL ),
115 pPMBorderLeft( NULL ),
116 pPMBorderRight( NULL ),
118 pPMBorderWidthAll( NULL ),
119 pPMBorderWidthTop( NULL ),
120 pPMBorderWidthBottom( NULL ),
121 pPMBorderWidthLeft( NULL ),
122 pPMBorderWidthRight( NULL ),
124 pPMPaddingAll( NULL ),
125 pPMPaddingTop( NULL ),
126 pPMPaddingBottom( NULL ),
127 pPMPaddingLeft( NULL ),
128 pPMPaddingRight( NULL )
132 void XMLPropertyStateBuffer::ContextFilter( ::std::vector< XMLPropertyState >& )
134 if (pPMMarginAll)
136 lcl_RemoveState(pPMMarginAll); // #i117696# do not write fo:margin
139 if( pPMBorderAll )
141 if( pPMBorderTop && pPMBorderBottom && pPMBorderLeft && pPMBorderRight )
143 table::BorderLine2 aLineTop, aLineBottom, aLineLeft, aLineRight;
145 pPMBorderTop->maValue >>= aLineTop;
146 pPMBorderBottom->maValue >>= aLineBottom;
147 pPMBorderLeft->maValue >>= aLineLeft;
148 pPMBorderRight->maValue >>= aLineRight;
150 if( (aLineTop == aLineBottom) && (aLineBottom == aLineLeft) && (aLineLeft == aLineRight) )
152 lcl_RemoveState( pPMBorderTop );
153 lcl_RemoveState( pPMBorderBottom );
154 lcl_RemoveState( pPMBorderLeft );
155 lcl_RemoveState( pPMBorderRight );
157 else
158 lcl_RemoveState( pPMBorderAll );
160 else
161 lcl_RemoveState( pPMBorderAll );
164 if( pPMBorderWidthAll )
166 if( pPMBorderWidthTop && pPMBorderWidthBottom && pPMBorderWidthLeft && pPMBorderWidthRight )
168 table::BorderLine2 aLineTop, aLineBottom, aLineLeft, aLineRight;
170 pPMBorderWidthTop->maValue >>= aLineTop;
171 pPMBorderWidthBottom->maValue >>= aLineBottom;
172 pPMBorderWidthLeft->maValue >>= aLineLeft;
173 pPMBorderWidthRight->maValue >>= aLineRight;
175 if( lcl_HasSameLineWidth( aLineTop, aLineBottom ) &&
176 lcl_HasSameLineWidth( aLineBottom, aLineLeft ) &&
177 lcl_HasSameLineWidth( aLineLeft, aLineRight ) )
179 lcl_RemoveState( pPMBorderWidthTop );
180 lcl_RemoveState( pPMBorderWidthBottom );
181 lcl_RemoveState( pPMBorderWidthLeft );
182 lcl_RemoveState( pPMBorderWidthRight );
184 else
185 lcl_RemoveState( pPMBorderWidthAll );
187 else
188 lcl_RemoveState( pPMBorderWidthAll );
191 if( pPMPaddingAll )
193 if( pPMPaddingTop && pPMPaddingBottom && pPMPaddingLeft && pPMPaddingRight )
195 sal_Int32 nTop = 0, nBottom = 0, nLeft = 0, nRight = 0;
197 pPMPaddingTop->maValue >>= nTop;
198 pPMPaddingBottom->maValue >>= nBottom;
199 pPMPaddingLeft->maValue >>= nLeft;
200 pPMPaddingRight->maValue >>= nRight;
202 if( (nTop == nBottom) && (nBottom == nLeft) && (nLeft == nRight) )
204 lcl_RemoveState( pPMPaddingTop );
205 lcl_RemoveState( pPMPaddingBottom );
206 lcl_RemoveState( pPMPaddingLeft );
207 lcl_RemoveState( pPMPaddingRight );
209 else
210 lcl_RemoveState( pPMPaddingAll );
212 else
213 lcl_RemoveState( pPMPaddingAll );
217 //______________________________________________________________________________
219 XMLPageMasterExportPropMapper::XMLPageMasterExportPropMapper(
220 const UniReference< XMLPropertySetMapper >& rMapper,
221 SvXMLExport& rExport ) :
222 SvXMLExportPropertyMapper( rMapper ),
223 aBackgroundImageExport( rExport ),
224 aTextColumnsExport( rExport ),
225 aFootnoteSeparatorExport( rExport )
229 XMLPageMasterExportPropMapper::~XMLPageMasterExportPropMapper()
233 void XMLPageMasterExportPropMapper::handleElementItem(
234 SvXMLExport&,
235 const XMLPropertyState& rProperty,
236 sal_uInt16 /*nFlags*/,
237 const ::std::vector< XMLPropertyState >* pProperties,
238 sal_uInt32 nIdx ) const
240 XMLPageMasterExportPropMapper* pThis = (XMLPageMasterExportPropMapper*) this;
242 sal_uInt32 nContextId = getPropertySetMapper()->GetEntryContextId( rProperty.mnIndex );
243 switch( nContextId )
245 case CTF_PM_GRAPHICURL:
246 case CTF_PM_HEADERGRAPHICURL:
247 case CTF_PM_FOOTERGRAPHICURL:
249 DBG_ASSERT( pProperties && (nIdx >= 2), "property vector missing" );
250 sal_Int32 nPos;
251 sal_Int32 nFilter;
252 switch( nContextId )
254 case CTF_PM_GRAPHICURL:
255 nPos = CTF_PM_GRAPHICPOSITION;
256 nFilter = CTF_PM_GRAPHICFILTER;
257 break;
258 case CTF_PM_HEADERGRAPHICURL:
259 nPos = CTF_PM_HEADERGRAPHICPOSITION;
260 nFilter = CTF_PM_HEADERGRAPHICFILTER;
261 break;
262 case CTF_PM_FOOTERGRAPHICURL:
263 nPos = CTF_PM_FOOTERGRAPHICPOSITION;
264 nFilter = CTF_PM_FOOTERGRAPHICFILTER;
265 break;
266 default:
267 nPos = 0; // TODO What values should this be?
268 nFilter = 0;
270 const Any* pPos = NULL;
271 const Any* pFilter = NULL;
272 if( pProperties && (nIdx >= 2) )
274 const XMLPropertyState& rPos = (*pProperties)[nIdx - 2];
275 DBG_ASSERT( getPropertySetMapper()->GetEntryContextId( rPos.mnIndex ) == nPos,
276 "invalid property map: pos expected" );
277 if( getPropertySetMapper()->GetEntryContextId( rPos.mnIndex ) == nPos )
278 pPos = &rPos.maValue;
280 const XMLPropertyState& rFilter = (*pProperties)[nIdx - 1];
281 DBG_ASSERT( getPropertySetMapper()->GetEntryContextId( rFilter.mnIndex ) == nFilter,
282 "invalid property map: filter expected" );
283 if( getPropertySetMapper()->GetEntryContextId( rFilter.mnIndex ) == nFilter )
284 pFilter = &rFilter.maValue;
286 sal_uInt32 nPropIndex = rProperty.mnIndex;
287 pThis->aBackgroundImageExport.exportXML( rProperty.maValue, pPos, pFilter, NULL,
288 getPropertySetMapper()->GetEntryNameSpace( nPropIndex ),
289 getPropertySetMapper()->GetEntryXMLName( nPropIndex ) );
291 break;
292 case CTF_PM_TEXTCOLUMNS:
293 pThis->aTextColumnsExport.exportXML( rProperty.maValue );
294 break;
295 case CTF_PM_FTN_LINE_WEIGHT:
296 pThis->aFootnoteSeparatorExport.exportXML( pProperties, nIdx,
297 getPropertySetMapper());
298 break;
302 void XMLPageMasterExportPropMapper::handleSpecialItem(
303 SvXMLAttributeList&,
304 const XMLPropertyState&,
305 const SvXMLUnitConverter&,
306 const SvXMLNamespaceMap&,
307 const ::std::vector< XMLPropertyState >*,
308 sal_uInt32 /*nIdx*/) const
312 void XMLPageMasterExportPropMapper::ContextFilter(
313 bool bEnableFoFontFamily,
314 ::std::vector< XMLPropertyState >& rPropState,
315 Reference< XPropertySet > rPropSet ) const
317 XMLPropertyStateBuffer aPageBuffer;
318 XMLPropertyStateBuffer aHeaderBuffer;
319 XMLPropertyStateBuffer aFooterBuffer;
321 XMLPropertyState* pPMHeaderHeight = NULL;
322 XMLPropertyState* pPMHeaderMinHeight = NULL;
323 XMLPropertyState* pPMHeaderDynamic = NULL;
325 XMLPropertyState* pPMFooterHeight = NULL;
326 XMLPropertyState* pPMFooterMinHeight = NULL;
327 XMLPropertyState* pPMFooterDynamic = NULL;
329 XMLPropertyState* pPMScaleTo = NULL;
330 XMLPropertyState* pPMScaleToPages = NULL;
331 XMLPropertyState* pPMScaleToX = NULL;
332 XMLPropertyState* pPMScaleToY = NULL;
333 XMLPropertyState* pPMStandardMode = NULL;
334 XMLPropertyState* pPMGridBaseWidth = NULL;
335 // same as pPMGridSnapTo but for backward compatibility only
336 XMLPropertyState* pPMGridSnapToChars = NULL;
337 XMLPropertyState* pPMGridSnapTo = NULL;
339 XMLPropertyState* pPrint = NULL;
341 UniReference < XMLPropertySetMapper > aPropMapper(getPropertySetMapper());
343 for( ::std::vector< XMLPropertyState >::iterator aIter = rPropState.begin(); aIter != rPropState.end(); ++aIter )
345 XMLPropertyState *pProp = &(*aIter);
346 sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex );
347 sal_Int16 nFlag = nContextId & CTF_PM_FLAGMASK;
348 sal_Int16 nSimpleId = nContextId & (~CTF_PM_FLAGMASK | XML_PM_CTF_START);
349 sal_Int16 nPrintId = nContextId & CTF_PM_PRINTMASK;
351 XMLPropertyStateBuffer* pBuffer;
352 switch( nFlag )
354 case CTF_PM_HEADERFLAG: pBuffer = &aHeaderBuffer; break;
355 case CTF_PM_FOOTERFLAG: pBuffer = &aFooterBuffer; break;
356 default: pBuffer = &aPageBuffer; break;
359 switch( nSimpleId )
361 case CTF_PM_MARGINALL: pBuffer->pPMMarginAll = pProp; break;
362 case CTF_PM_MARGINTOP: pBuffer->pPMMarginTop = pProp; break;
363 case CTF_PM_MARGINBOTTOM: pBuffer->pPMMarginBottom = pProp; break;
364 case CTF_PM_MARGINLEFT: pBuffer->pPMMarginLeft = pProp; break;
365 case CTF_PM_MARGINRIGHT: pBuffer->pPMMarginRight = pProp; break;
366 case CTF_PM_BORDERALL: pBuffer->pPMBorderAll = pProp; break;
367 case CTF_PM_BORDERTOP: pBuffer->pPMBorderTop = pProp; break;
368 case CTF_PM_BORDERBOTTOM: pBuffer->pPMBorderBottom = pProp; break;
369 case CTF_PM_BORDERLEFT: pBuffer->pPMBorderLeft = pProp; break;
370 case CTF_PM_BORDERRIGHT: pBuffer->pPMBorderRight = pProp; break;
371 case CTF_PM_BORDERWIDTHALL: pBuffer->pPMBorderWidthAll = pProp; break;
372 case CTF_PM_BORDERWIDTHTOP: pBuffer->pPMBorderWidthTop = pProp; break;
373 case CTF_PM_BORDERWIDTHBOTTOM: pBuffer->pPMBorderWidthBottom = pProp; break;
374 case CTF_PM_BORDERWIDTHLEFT: pBuffer->pPMBorderWidthLeft = pProp; break;
375 case CTF_PM_BORDERWIDTHRIGHT: pBuffer->pPMBorderWidthRight = pProp; break;
376 case CTF_PM_PADDINGALL: pBuffer->pPMPaddingAll = pProp; break;
377 case CTF_PM_PADDINGTOP: pBuffer->pPMPaddingTop = pProp; break;
378 case CTF_PM_PADDINGBOTTOM: pBuffer->pPMPaddingBottom = pProp; break;
379 case CTF_PM_PADDINGLEFT: pBuffer->pPMPaddingLeft = pProp; break;
380 case CTF_PM_PADDINGRIGHT: pBuffer->pPMPaddingRight = pProp; break;
383 switch( nContextId )
385 case CTF_PM_HEADERHEIGHT: pPMHeaderHeight = pProp; break;
386 case CTF_PM_HEADERMINHEIGHT: pPMHeaderMinHeight = pProp; break;
387 case CTF_PM_HEADERDYNAMIC: pPMHeaderDynamic = pProp; break;
388 case CTF_PM_FOOTERHEIGHT: pPMFooterHeight = pProp; break;
389 case CTF_PM_FOOTERMINHEIGHT: pPMFooterMinHeight = pProp; break;
390 case CTF_PM_FOOTERDYNAMIC: pPMFooterDynamic = pProp; break;
391 case CTF_PM_SCALETO: pPMScaleTo = pProp; break;
392 case CTF_PM_SCALETOPAGES: pPMScaleToPages = pProp; break;
393 case CTF_PM_SCALETOX: pPMScaleToX = pProp; break;
394 case CTF_PM_SCALETOY: pPMScaleToY = pProp; break;
395 case CTF_PM_STANDARD_MODE: pPMStandardMode = pProp; break;
396 case CTP_PM_GRID_BASE_WIDTH: pPMGridBaseWidth = pProp; break;
397 case CTP_PM_GRID_SNAP_TO_CHARS: pPMGridSnapToChars = pProp; break;
398 case CTP_PM_GRID_SNAP_TO: pPMGridSnapTo = pProp; break;
400 if (nPrintId == CTF_PM_PRINTMASK)
402 pPrint = pProp;
403 lcl_RemoveState(pPrint);
407 if( pPMStandardMode && !getBOOL(pPMStandardMode->maValue) )
409 lcl_RemoveState(pPMStandardMode);
410 if( pPMGridBaseWidth )
411 lcl_RemoveState(pPMGridBaseWidth);
412 if( pPMGridSnapToChars )
413 lcl_RemoveState(pPMGridSnapToChars);
414 if (pPMGridSnapTo)
416 lcl_RemoveState(pPMGridSnapTo);
420 if( pPMGridBaseWidth && pPMStandardMode )
421 lcl_RemoveState(pPMStandardMode);
423 aPageBuffer.ContextFilter( rPropState );
424 aHeaderBuffer.ContextFilter( rPropState );
425 aFooterBuffer.ContextFilter( rPropState );
427 if( pPMHeaderHeight && (!pPMHeaderDynamic || (pPMHeaderDynamic && getBOOL( pPMHeaderDynamic->maValue ))) )
428 lcl_RemoveState( pPMHeaderHeight );
429 if( pPMHeaderMinHeight && pPMHeaderDynamic && !getBOOL( pPMHeaderDynamic->maValue ) )
430 lcl_RemoveState( pPMHeaderMinHeight );
431 if( pPMHeaderDynamic )
432 lcl_RemoveState( pPMHeaderDynamic );
434 if( pPMFooterHeight && (!pPMFooterDynamic || (pPMFooterDynamic && getBOOL( pPMFooterDynamic->maValue ))) )
435 lcl_RemoveState( pPMFooterHeight );
436 if( pPMFooterMinHeight && pPMFooterDynamic && !getBOOL( pPMFooterDynamic->maValue ) )
437 lcl_RemoveState( pPMFooterMinHeight );
438 if( pPMFooterDynamic )
439 lcl_RemoveState( pPMFooterDynamic );
441 if( pPMScaleTo )
442 lcl_RemoveStateIfZero16( pPMScaleTo );
443 if( pPMScaleToPages )
444 lcl_RemoveStateIfZero16( pPMScaleToPages );
445 if( pPMScaleToX )
446 lcl_RemoveStateIfZero16( pPMScaleToX );
447 if( pPMScaleToY )
448 lcl_RemoveStateIfZero16( pPMScaleToY );
450 if (pPrint)
452 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_ANNOTATIONS), "PrintAnnotations", rPropSet);
453 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_CHARTS), "PrintCharts", rPropSet);
454 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_DRAWING), "PrintDrawing", rPropSet);
455 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_FORMULAS), "PrintFormulas", rPropSet);
456 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_GRID), "PrintGrid", rPropSet);
457 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_HEADERS), "PrintHeaders", rPropSet);
458 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_OBJECTS), "PrintObjects", rPropSet);
459 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_ZEROVALUES), "PrintZeroValues", rPropSet);
462 SvXMLExportPropertyMapper::ContextFilter(bEnableFoFontFamily, rPropState, rPropSet);
465 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */