1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAP_HXX
20 #define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAP_HXX
22 #include <rtl/ustring.hxx>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/uno/Any.h>
27 #include "PropertyIds.hxx"
29 #include <boost/optional.hpp>
33 #include "TagLogger.hxx"
35 namespace com
{namespace sun
{namespace star
{
43 class XMultiServiceFactory
;
56 namespace writerfilter
{
58 class DomainMapper_Impl
;
84 /// This can hold properties of runs that had formatted 'track changes' properties
85 css::uno::Sequence
<css::beans::PropertyValue
> m_aRevertProperties
;
87 typedef std::shared_ptr
< RedlineParams
> RedlineParamsPtr
;
91 css::uno::Any m_aValue
;
92 GrabBagType m_GrabBagType
;
95 PropValue(const css::uno::Any
& rValue
, GrabBagType i_GrabBagType
= NO_GRAB_BAG
) :
96 m_aValue(rValue
), m_GrabBagType(i_GrabBagType
) {}
98 PropValue() : m_aValue(), m_GrabBagType(NO_GRAB_BAG
) {}
100 const css::uno::Any
& getValue() const { return m_aValue
; }
101 bool hasGrabBag() const { return m_GrabBagType
!= NO_GRAB_BAG
; }
102 GrabBagType
getGrabBagType() const { return m_GrabBagType
; }
107 /// Cache the property values for the GetPropertyValues() call(s).
108 std::vector
<css::beans::PropertyValue
> m_aValues
;
110 //marks context as footnote context - ::text( ) events contain either the footnote character or can be ignored
111 //depending on sprmCSymbol
112 sal_Unicode m_cFootnoteSymbol
; // 0 == invalid
113 sal_Int32 m_nFootnoteFontId
; // negative values are invalid ids
114 OUString m_sFootnoteFontName
;
115 css::uno::Reference
<css::text::XFootnote
> m_xFootnote
;
117 std::map
< PropertyIds
, PropValue
> m_vMap
;
119 typedef std::map
<PropertyIds
,PropValue
>::const_iterator MapIterator
;
121 std::vector
< RedlineParamsPtr
> m_aRedlines
;
131 typedef std::pair
<PropertyIds
,css::uno::Any
> Property
;
134 virtual ~PropertyMap();
136 css::uno::Sequence
<css::beans::PropertyValue
> GetPropertyValues(bool bCharGrabBag
= true);
137 //Sequence: Grab Bags: The CHAR_GRAB_BAG has Name "CharInteropGrabBag" and the PARA_GRAB_BAG has Name "ParaInteropGrabBag"
138 // the contained properties are their Value.
139 bool hasEmptyPropertyValues() const {return m_aValues
.empty();}
141 //Add property, optionally overwriting existing attributes
142 void Insert(PropertyIds eId
, const css::uno::Any
& rAny
, bool bOverwrite
= true, GrabBagType i_GrabBagType
= NO_GRAB_BAG
);
143 void Insert( PropertyIds eId
, const PropValue
& rValue
, bool bOverwrite
= true );
144 //Remove a named property from *this, does nothing if the property id has not been set
145 void Erase( PropertyIds eId
);
147 //Imports properties from pMap, overwriting those with the same PropertyIds as the current map
148 void InsertProps(const std::shared_ptr
<PropertyMap
>& rMap
);
150 //Returns a copy of the property if it exists, .first is its PropertyIds and .second is its Value (type css::uno::Any)
151 boost::optional
<Property
> getProperty( PropertyIds eId
) const;
153 //Has the property named been set (via Insert)?
154 bool isSet( PropertyIds eId
) const;
156 const css::uno::Reference
<css::text::XFootnote
>& GetFootnote() const { return m_xFootnote
; }
157 void SetFootnote(css::uno::Reference
<css::text::XFootnote
> const& xF
) { m_xFootnote
= xF
; }
159 sal_Unicode
GetFootnoteSymbol() const { return m_cFootnoteSymbol
;}
160 void SetFootnoteSymbol(sal_Unicode cSet
) { m_cFootnoteSymbol
= cSet
;}
162 sal_Int32
GetFootnoteFontId() const { return m_nFootnoteFontId
;}
163 void SetFootnoteFontId(sal_Int32 nSet
) { m_nFootnoteFontId
= nSet
;}
165 const OUString
& GetFootnoteFontName() const { return m_sFootnoteFontName
;}
166 void SetFootnoteFontName( const OUString
& rSet
) { m_sFootnoteFontName
= rSet
;}
168 virtual void insertTableProperties( const PropertyMap
* );
170 const std::vector
< RedlineParamsPtr
>& Redlines() const { return m_aRedlines
; }
171 std::vector
< RedlineParamsPtr
>& Redlines() { return m_aRedlines
; }
173 void printProperties();
174 #ifdef DEBUG_WRITERFILTER
175 void dumpXml() const;
177 static css::table::ShadowFormat
getShadowFromBorder(const css::table::BorderLine2
& rBorder
);
180 typedef std::shared_ptr
<PropertyMap
> PropertyMapPtr
;
182 class SectionPropertyMap
: public PropertyMap
185 sal_Int32 nSectionNumber
;
187 //'temporarily' the section page settings are imported as page styles
188 // empty strings mark page settings as not yet imported
190 bool m_bIsFirstSection
;
191 css::uno::Reference
<css::text::XTextRange
> m_xStartingRange
;
193 OUString m_sFirstPageStyleName
;
194 OUString m_sFollowPageStyleName
;
195 css::uno::Reference
<css::beans::XPropertySet
> m_aFirstPageStyle
;
196 css::uno::Reference
<css::beans::XPropertySet
> m_aFollowPageStyle
;
198 css::table::BorderLine2
* m_pBorderLines
[4];
199 sal_Int32 m_nBorderDistances
[4];
200 sal_Int32 m_nBorderParams
;
201 bool m_bBorderShadows
[4];
204 sal_Int16 m_nColumnCount
;
205 sal_Int32 m_nColumnDistance
;
206 ::std::vector
< sal_Int32
> m_aColWidth
;
207 ::std::vector
< sal_Int32
> m_aColDistance
;
209 bool m_bSeparatorLineIsOn
;
210 bool m_bEvenlySpaced
;
213 bool m_bPageNoRestart
;
214 sal_Int32 m_nPageNumber
;
215 sal_Int32 m_nBreakType
;
216 sal_Int32 m_nPaperBin
;
217 sal_Int32 m_nFirstPaperBin
;
219 sal_Int32 m_nLeftMargin
;
220 sal_Int32 m_nRightMargin
;
221 sal_Int32 m_nTopMargin
;
222 sal_Int32 m_nBottomMargin
;
223 sal_Int32 m_nHeaderTop
;
224 sal_Int32 m_nHeaderBottom
;
226 sal_Int32 m_nDzaGutter
;
230 sal_Int32 m_nGridType
;
231 sal_Int32 m_nGridLinePitch
;
232 sal_Int32 m_nDxtCharSpace
;
233 bool m_bGridSnapToChars
;
241 void _ApplyProperties(css::uno::Reference
<css::beans::XPropertySet
> const& xStyle
);
242 css::uno::Reference
<css::text::XTextColumns
> ApplyColumnProperties(css::uno::Reference
<css::beans::XPropertySet
> const& xFollowPageStyle
,
243 DomainMapper_Impl
& rDM_Impl
);
244 void CopyLastHeaderFooter( bool bFirstPage
, DomainMapper_Impl
& rDM_Impl
);
245 static void CopyHeaderFooter(css::uno::Reference
<css::beans::XPropertySet
> xPrevStyle
,
246 css::uno::Reference
<css::beans::XPropertySet
> xStyle
);
247 void PrepareHeaderFooterProperties( bool bFirstPage
);
248 bool HasHeader( bool bFirstPage
) const;
249 bool HasFooter( bool bFirstPage
) const;
251 static void SetBorderDistance(css::uno::Reference
<css::beans::XPropertySet
> const& xStyle
,
252 PropertyIds eMarginId
,
255 sal_Int32 nOffsetFrom
,
256 sal_uInt32 nLineWidth
);
259 explicit SectionPropertyMap(bool bIsFirstSection
);
260 virtual ~SectionPropertyMap();
269 void SetStart(const css::uno::Reference
<css::text::XTextRange
>& xRange
)
271 m_xStartingRange
= xRange
;
274 css::uno::Reference
<css::text::XTextRange
> GetStartingRange() const { return m_xStartingRange
; }
276 css::uno::Reference
<css::beans::XPropertySet
> GetPageStyle(const css::uno::Reference
<css::container::XNameContainer
>& xStyles
,
277 const css::uno::Reference
<css::lang::XMultiServiceFactory
>& xTextFactory
,
280 void SetBorder(BorderPosition ePos
, sal_Int32 nLineDistance
, const css::table::BorderLine2
& rBorderLine
, bool bShadow
);
281 void SetBorderParams( sal_Int32 nSet
) { m_nBorderParams
= nSet
; }
283 void SetColumnCount( sal_Int16 nCount
) { m_nColumnCount
= nCount
; }
284 sal_Int16
ColumnCount() const { return m_nColumnCount
; }
285 void SetColumnDistance( sal_Int32 nDist
) { m_nColumnDistance
= nDist
; }
286 void AppendColumnWidth( sal_Int32 nWidth
) { m_aColWidth
.push_back( nWidth
); }
287 void AppendColumnSpacing( sal_Int32 nDist
) {m_aColDistance
.push_back( nDist
); }
289 void SetTitlePage( bool bSet
) { m_bTitlePage
= bSet
; }
290 void SetSeparatorLine( bool bSet
) { m_bSeparatorLineIsOn
= bSet
; }
291 void SetEvenlySpaced( bool bSet
) { m_bEvenlySpaced
= bSet
; }
292 void SetLandscape( bool bSet
) { m_bIsLandscape
= bSet
; }
293 void SetPageNoRestart( bool bSet
) { m_bPageNoRestart
= bSet
; }
294 void SetPageNumber( sal_Int32 nSet
) { m_nPageNumber
= nSet
; }
295 void SetBreakType( sal_Int32 nSet
) { m_nBreakType
= nSet
; }
296 sal_Int32
GetBreakType( ) { return m_nBreakType
; }
297 void SetPaperBin( sal_Int32 nSet
);
298 void SetFirstPaperBin( sal_Int32 nSet
);
300 void SetLeftMargin( sal_Int32 nSet
) { m_nLeftMargin
= nSet
; }
301 sal_Int32
GetLeftMargin() { return m_nLeftMargin
; }
302 void SetRightMargin( sal_Int32 nSet
) { m_nRightMargin
= nSet
; }
303 sal_Int32
GetRightMargin() { return m_nRightMargin
; }
304 void SetTopMargin( sal_Int32 nSet
) { m_nTopMargin
= nSet
; }
305 void SetBottomMargin( sal_Int32 nSet
) { m_nBottomMargin
= nSet
; }
306 void SetHeaderTop( sal_Int32 nSet
) { m_nHeaderTop
= nSet
; }
307 void SetHeaderBottom( sal_Int32 nSet
) { m_nHeaderBottom
= nSet
; }
308 sal_Int32
GetPageWidth();
310 void SetGutterRTL( bool bSet
) { m_bGutterRTL
= bSet
;}
311 void SetDzaGutter( sal_Int32 nSet
) {m_nDzaGutter
= nSet
; }
312 void SetSFBiDi( bool bSet
) { m_bSFBiDi
= bSet
;}
314 void SetGridType(sal_Int32 nSet
) { m_nGridType
= nSet
; }
315 void SetGridLinePitch( sal_Int32 nSet
) { m_nGridLinePitch
= nSet
; }
316 void SetGridSnapToChars( bool bSet
) { m_bGridSnapToChars
= bSet
; }
317 void SetDxtCharSpace( sal_Int32 nSet
) { m_nDxtCharSpace
= nSet
; }
319 void SetLnnMod( sal_Int32 nValue
) { m_nLnnMod
= nValue
; }
320 void SetLnc( sal_Int32 nValue
) { m_nLnc
= nValue
; }
321 void SetdxaLnn( sal_Int32 nValue
) { m_ndxaLnn
= nValue
; }
322 void SetLnnMin( sal_Int32 nValue
) { m_nLnnMin
= nValue
; }
324 //determine which style gets the borders
325 void ApplyBorderToPageStyles(const css::uno::Reference
<css::container::XNameContainer
>& xStyles
,
326 const css::uno::Reference
<css::lang::XMultiServiceFactory
>& xTextFactory
,
329 void CloseSectionGroup( DomainMapper_Impl
& rDM_Impl
);
330 /// Handling of margins, header and footer for any kind of sections breaks.
331 void HandleMarginsHeaderFooter(DomainMapper_Impl
& rDM_Impl
);
336 class ParagraphProperties
339 sal_Int32 m_nDropCap
; //drop, margin ST_DropCap
340 sal_Int32 m_nLines
; //number of lines of the drop cap
341 sal_Int32 m_w
; //width
342 sal_Int32 m_h
; //height
343 sal_Int32 m_nWrap
; // from ST_Wrap around, auto, none, notBeside, through, tight
344 sal_Int32 m_hAnchor
; // page, from ST_HAnchor margin, page, text
345 sal_Int32 m_vAnchor
; // around from ST_VAnchor margin, page, text
346 sal_Int32 m_x
; //x-position
348 sal_Int32 m_y
; //y-position
350 sal_Int32 m_hSpace
; //frame padding h
351 sal_Int32 m_vSpace
; //frame padding v
352 sal_Int32 m_hRule
; // from ST_HeightRule exact, atLeast, auto
353 sal_Int32 m_xAlign
; // from ST_XAlign center, inside, left, outside, right
354 sal_Int32 m_yAlign
; // from ST_YAlign bottom, center, inline, inside, outside, top
357 sal_Int8 m_nDropCapLength
; //number of characters
359 OUString m_sParaStyleName
;
361 css::uno::Reference
<css::text::XTextRange
> m_xStartingRange
; // start of a frame
362 css::uno::Reference
<css::text::XTextRange
> m_xEndingRange
; // end of the frame
365 ParagraphProperties();
366 ParagraphProperties(const ParagraphProperties
&);
367 virtual ~ParagraphProperties();
369 bool operator==(const ParagraphProperties
&); //does not compare the starting/ending range, m_sParaStyleName and m_nDropCapLength
371 void SetFrameMode( bool set
= true ) { m_bFrameMode
= set
; }
372 bool IsFrameMode()const { return m_bFrameMode
; }
374 void SetDropCap( sal_Int32 nSet
) { m_nDropCap
= nSet
; }
375 sal_Int32
GetDropCap()const { return m_nDropCap
; }
377 void SetLines( sal_Int32 nSet
) { m_nLines
= nSet
; }
378 sal_Int32
GetLines() const { return m_nLines
; }
380 void Setw( sal_Int32 nSet
) { m_w
= nSet
; }
381 sal_Int32
Getw() const { return m_w
; }
383 void Seth( sal_Int32 nSet
) { m_h
= nSet
; }
384 sal_Int32
Geth() const { return m_h
; }
386 void SetWrap( sal_Int32 nSet
) { m_nWrap
= nSet
; }
387 sal_Int32
GetWrap() const { return m_nWrap
; }
389 void SethAnchor( sal_Int32 nSet
) { m_hAnchor
= nSet
; }
390 sal_Int32
GethAnchor() const { return m_hAnchor
;}
392 void SetvAnchor( sal_Int32 nSet
) { m_vAnchor
= nSet
; }
393 sal_Int32
GetvAnchor() const { return m_vAnchor
; }
395 void Setx( sal_Int32 nSet
) { m_x
= nSet
; m_bxValid
= true;}
396 sal_Int32
Getx() const { return m_x
; }
397 bool IsxValid() const {return m_bxValid
;}
399 void Sety( sal_Int32 nSet
) { m_y
= nSet
; m_byValid
= true;}
400 sal_Int32
Gety()const { return m_y
; }
401 bool IsyValid() const {return m_byValid
;}
403 void SethSpace( sal_Int32 nSet
) { m_hSpace
= nSet
; }
404 sal_Int32
GethSpace()const { return m_hSpace
; }
406 void SetvSpace( sal_Int32 nSet
) { m_vSpace
= nSet
; }
407 sal_Int32
GetvSpace()const { return m_vSpace
; }
409 void SethRule( sal_Int32 nSet
) { m_hRule
= nSet
; }
410 sal_Int32
GethRule() const { return m_hRule
; }
412 void SetxAlign( sal_Int32 nSet
) { m_xAlign
= nSet
; }
413 sal_Int32
GetxAlign()const { return m_xAlign
; }
415 void SetyAlign( sal_Int32 nSet
) { m_yAlign
= nSet
; }
416 sal_Int32
GetyAlign()const { return m_yAlign
; }
418 void SetAnchorLock( bool bSet
) {m_bAnchorLock
= bSet
; }
420 sal_Int8
GetDropCapLength() const { return m_nDropCapLength
;}
421 void SetDropCapLength(sal_Int8 nSet
) { m_nDropCapLength
= nSet
;}
423 css::uno::Reference
<css::text::XTextRange
> GetStartingRange() const { return m_xStartingRange
; }
424 void SetStartingRange(css::uno::Reference
<css::text::XTextRange
> const& xSet
) { m_xStartingRange
= xSet
; }
426 css::uno::Reference
<css::text::XTextRange
> GetEndingRange() const { return m_xEndingRange
; }
427 void SetEndingRange(css::uno::Reference
<css::text::XTextRange
> const& xSet
) { m_xEndingRange
= xSet
; }
429 void SetParaStyleName( const OUString
& rSet
) { m_sParaStyleName
= rSet
;}
430 const OUString
& GetParaStyleName() const { return m_sParaStyleName
;}
432 void ResetFrameProperties();
434 typedef std::shared_ptr
<ParagraphProperties
> ParagraphPropertiesPtr
;
435 /*-------------------------------------------------------------------------
436 property map of a stylesheet
437 -----------------------------------------------------------------------*/
439 #define WW_OUTLINE_MAX sal_Int16( 9 )
440 #define WW_OUTLINE_MIN sal_Int16( 0 )
442 class StyleSheetPropertyMap
: public PropertyMap
, public ParagraphProperties
445 //special table style properties
446 sal_Int32 mnCT_Spacing_line
;
447 sal_Int32 mnCT_Spacing_lineRule
;
449 OUString msCT_Fonts_ascii
;
450 bool mbCT_TrPrBase_tblHeader
;
451 sal_Int32 mnCT_TrPrBase_jc
;
453 sal_Int32 mnCT_TblWidth_w
;
454 sal_Int32 mnCT_TblWidth_type
;
456 bool mbCT_Spacing_lineSet
;
457 bool mbCT_Spacing_lineRuleSet
;
459 bool mbCT_TrPrBase_tblHeaderSet
;
460 bool mbCT_TrPrBase_jcSet
;
462 bool mbCT_TblWidth_wSet
;
463 bool mbCT_TblWidth_typeSet
;
466 sal_Int16 mnListLevel
;
468 sal_Int16 mnOutlineLevel
;
472 explicit StyleSheetPropertyMap();
473 virtual ~StyleSheetPropertyMap();
475 void SetCT_Spacing_line( sal_Int32 nSet
)
476 {mnCT_Spacing_line
= nSet
; mbCT_Spacing_lineSet
= true; }
477 void SetCT_Spacing_lineRule( sal_Int32 nSet
)
478 {mnCT_Spacing_lineRule
= nSet
; mbCT_Spacing_lineRuleSet
= true; }
480 void SetCT_Fonts_ascii( const OUString
& rSet
)
481 {msCT_Fonts_ascii
= rSet
; }
482 void SetCT_TrPrBase_tblHeader( bool bSet
)
483 {mbCT_TrPrBase_tblHeader
= bSet
; mbCT_TrPrBase_tblHeaderSet
= true; }
484 void SetCT_TrPrBase_jc( sal_Int32 nSet
)
485 {mnCT_TrPrBase_jc
= nSet
; mbCT_TrPrBase_jcSet
= true; }
487 void SetCT_TblWidth_w( sal_Int32 nSet
)
488 { mnCT_TblWidth_w
= nSet
; mbCT_TblWidth_wSet
= true; }
489 void SetCT_TblWidth_type( sal_Int32 nSet
)
490 {mnCT_TblWidth_type
= nSet
; mbCT_TblWidth_typeSet
= true; }
492 bool GetCT_Spacing_line( sal_Int32
& rToFill
) const
494 if( mbCT_Spacing_lineSet
)
495 rToFill
= mnCT_Spacing_line
;
496 return mbCT_Spacing_lineSet
;
498 bool GetCT_Spacing_lineRule(sal_Int32
& rToFill
) const
500 if( mbCT_Spacing_lineRuleSet
)
501 rToFill
= mnCT_Spacing_lineRule
;
502 return mbCT_Spacing_lineRuleSet
;
505 bool GetCT_Fonts_ascii(OUString
& rToFill
) const
507 if( msCT_Fonts_ascii
.getLength() > 0 )
508 rToFill
= msCT_Fonts_ascii
;
509 return msCT_Fonts_ascii
.getLength() > 0;
511 bool GetCT_TrPrBase_tblHeader(bool& rToFill
) const
513 if( mbCT_TrPrBase_tblHeaderSet
)
514 rToFill
= mbCT_TrPrBase_tblHeader
;
515 return mbCT_TrPrBase_tblHeaderSet
;
517 bool GetCT_TrPrBase_jc( sal_Int32
& rToFill
)const
519 if( mbCT_TrPrBase_jcSet
)
520 rToFill
= mnCT_TrPrBase_jc
;
521 return mbCT_TrPrBase_jcSet
;
523 sal_Int32
GetListId() const { return mnListId
; }
524 void SetListId(sal_Int32 nId
) { mnListId
= nId
; }
526 sal_Int16
GetListLevel() const { return mnListLevel
; }
527 void SetListLevel(sal_Int16 nLevel
) { mnListLevel
= nLevel
; }
529 sal_Int16
GetOutlineLevel() const { return mnOutlineLevel
; }
530 void SetOutlineLevel(sal_Int16 nLevel
)
532 if ( nLevel
< WW_OUTLINE_MAX
)
533 mnOutlineLevel
= nLevel
;
536 sal_Int32
GetNumId() const { return mnNumId
; }
537 void SetNumId(sal_Int32 nId
) { mnNumId
= nId
; }
541 class ParagraphPropertyMap
: public PropertyMap
, public ParagraphProperties
544 explicit ParagraphPropertyMap();
545 virtual ~ParagraphPropertyMap();
550 class TablePropertyMap
: public PropertyMap
553 enum TablePropertyMapTarget
555 TablePropertyMapTarget_START
,
556 CELL_MAR_LEFT
= TablePropertyMapTarget_START
,
565 TablePropertyMapTarget_MAX
576 ValidValue m_aValidValues
[TablePropertyMapTarget_MAX
];
579 explicit TablePropertyMap();
580 virtual ~TablePropertyMap();
582 bool getValue( TablePropertyMapTarget eWhich
, sal_Int32
& nFill
);
583 void setValue( TablePropertyMapTarget eWhich
, sal_Int32 nSet
);
585 virtual void insertTableProperties( const PropertyMap
* ) SAL_OVERRIDE
;
587 typedef std::shared_ptr
<TablePropertyMap
> TablePropertyMapPtr
;
588 } //namespace dmapper
589 } //namespace writerfilter
592 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */