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/table/BorderLine2.hpp>
27 #include <com/sun/star/text/WrapTextMode.hpp>
28 #include <com/sun/star/uno/Any.h>
29 #include "PropertyIds.hxx"
31 #include <boost/optional.hpp>
34 #include "TagLogger.hxx"
36 namespace com
{ namespace sun
{ namespace star
{
44 class XMultiServiceFactory
;
57 namespace writerfilter
{
60 class DomainMapper_Impl
;
61 struct FloatingTableInfo
;
62 struct AnchoredObjectInfo
;
81 struct RedlineParams
: public virtual SvRefBase
87 // This can hold properties of runs that had formatted 'track changes' properties
88 css::uno::Sequence
< css::beans::PropertyValue
> m_aRevertProperties
;
91 typedef tools::SvRef
< RedlineParams
> RedlineParamsPtr
;
96 css::uno::Any m_aValue
;
97 GrabBagType m_GrabBagType
;
100 PropValue( const css::uno::Any
& rValue
, GrabBagType i_GrabBagType
)
102 , m_GrabBagType( i_GrabBagType
)
108 , m_GrabBagType( NO_GRAB_BAG
)
112 const css::uno::Any
& getValue() const { return m_aValue
; }
114 GrabBagType
getGrabBagType() const { return m_GrabBagType
; }
117 class PropertyMap
: public virtual SvRefBase
120 // Cache the property values for the GetPropertyValues() call(s).
121 std::vector
< css::beans::PropertyValue
> m_aValues
;
123 // marks context as footnote context - ::text( ) events contain either the footnote character or can be ignored
124 // depending on sprmCSymbol
125 css::uno::Reference
< css::text::XFootnote
> m_xFootnote
;
126 std::map
< PropertyIds
, PropValue
> m_vMap
;
127 std::vector
< RedlineParamsPtr
> m_aRedlines
;
130 typedef std::pair
< PropertyIds
, css::uno::Any
> Property
;
134 // Sequence: Grab Bags: The CHAR_GRAB_BAG has Name "CharInteropGrabBag" and the PARA_GRAB_BAG has Name "ParaInteropGrabBag"
135 // the contained properties are their Value.
136 css::uno::Sequence
< css::beans::PropertyValue
> GetPropertyValues( bool bCharGrabBag
= true );
138 // Add property, optionally overwriting existing attributes
139 void Insert( PropertyIds eId
, const css::uno::Any
& rAny
, bool bOverwrite
= true, GrabBagType i_GrabBagType
= NO_GRAB_BAG
);
141 // Remove a named property from *this, does nothing if the property id has not been set
142 void Erase( PropertyIds eId
);
144 // Imports properties from pMap
145 void InsertProps( const tools::SvRef
< PropertyMap
>& rMap
, const bool bOverwrite
= true );
147 // Returns a copy of the property if it exists, .first is its PropertyIds and .second is its Value (type css::uno::Any)
148 boost::optional
< Property
> getProperty( PropertyIds eId
) const;
150 // Has the property named been set (via Insert)?
151 bool isSet( PropertyIds eId
) const;
153 const css::uno::Reference
< css::text::XFootnote
>& GetFootnote() const { return m_xFootnote
; }
155 void SetFootnote( const css::uno::Reference
< css::text::XFootnote
>& xF
) { m_xFootnote
= xF
; }
157 virtual void insertTableProperties( const PropertyMap
*, const bool bOverwrite
= true );
159 const std::vector
< RedlineParamsPtr
>& Redlines() const { return m_aRedlines
; }
161 std::vector
< RedlineParamsPtr
>& Redlines() { return m_aRedlines
; }
163 void printProperties();
165 #ifdef DEBUG_WRITERFILTER
166 void dumpXml() const;
169 static css::table::ShadowFormat
getShadowFromBorder( const css::table::BorderLine2
& rBorder
);
174 if ( m_aValues
.size() )
179 typedef tools::SvRef
< PropertyMap
> PropertyMapPtr
;
181 class SectionPropertyMap
: public PropertyMap
184 enum class BorderApply
187 ToFirstPageInSection
= 1,
188 ToAllButFirstInSection
= 2
190 enum class BorderOffsetFrom
196 #ifdef DEBUG_WRITERFILTER
197 sal_Int32 m_nDebugSectionNumber
;
200 // 'temporarily' the section page settings are imported as page styles
201 // empty strings mark page settings as not yet imported
203 bool const m_bIsFirstSection
;
204 css::uno::Reference
< css::text::XTextRange
> m_xStartingRange
;
206 OUString m_sFirstPageStyleName
;
207 OUString m_sFollowPageStyleName
;
208 css::uno::Reference
< css::beans::XPropertySet
> m_aFirstPageStyle
;
209 css::uno::Reference
< css::beans::XPropertySet
> m_aFollowPageStyle
;
211 boost::optional
< css::table::BorderLine2
> m_oBorderLines
[4];
212 sal_Int32 m_nBorderDistances
[4];
213 BorderApply m_eBorderApply
;
214 BorderOffsetFrom m_eBorderOffsetFrom
;
215 bool m_bBorderShadows
[4];
218 sal_Int16 m_nColumnCount
;
219 sal_Int32 m_nColumnDistance
;
220 css::uno::Reference
< css::beans::XPropertySet
> m_xColumnContainer
;
221 std::vector
< sal_Int32
> m_aColWidth
;
222 std::vector
< sal_Int32
> m_aColDistance
;
224 bool m_bSeparatorLineIsOn
;
225 bool m_bEvenlySpaced
;
227 sal_Int32 m_nPageNumber
;
228 // Page number type is a value from css::style::NumberingType.
229 sal_Int16 m_nPageNumberType
;
230 sal_Int32 m_nBreakType
;
232 sal_Int32 m_nLeftMargin
;
233 sal_Int32 m_nRightMargin
;
234 sal_Int32 m_nTopMargin
;
235 sal_Int32 m_nBottomMargin
;
236 sal_Int32 m_nHeaderTop
;
237 sal_Int32 m_nHeaderBottom
;
239 sal_Int32 m_nGridType
;
240 sal_Int32 m_nGridLinePitch
;
241 sal_Int32 m_nDxtCharSpace
;
242 bool m_bGridSnapToChars
;
250 std::vector
<css::uno::Reference
<css::drawing::XShape
>> m_xRelativeWidthShapes
;
252 // The "Link To Previous" flag indicates whether the header/footer
253 // content should be taken from the previous section
254 bool m_bDefaultHeaderLinkToPrevious
;
255 bool m_bEvenPageHeaderLinkToPrevious
;
256 bool m_bFirstPageHeaderLinkToPrevious
;
257 bool m_bDefaultFooterLinkToPrevious
;
258 bool m_bEvenPageFooterLinkToPrevious
;
259 bool m_bFirstPageFooterLinkToPrevious
;
261 void ApplyProperties_( const css::uno::Reference
< css::beans::XPropertySet
>& xStyle
);
263 void DontBalanceTextColumns();
265 /// Check if document is protected. If so, ensure a section exists, and apply its protected value.
266 void ApplyProtectionProperties( css::uno::Reference
< css::beans::XPropertySet
>& xSection
, DomainMapper_Impl
& rDM_Impl
);
268 css::uno::Reference
< css::text::XTextColumns
> ApplyColumnProperties( const css::uno::Reference
< css::beans::XPropertySet
>& xFollowPageStyle
,
269 DomainMapper_Impl
& rDM_Impl
);
271 void CopyLastHeaderFooter( bool bFirstPage
, DomainMapper_Impl
& rDM_Impl
);
273 static void CopyHeaderFooter( const css::uno::Reference
< css::beans::XPropertySet
>& xPrevStyle
,
274 const css::uno::Reference
< css::beans::XPropertySet
>& xStyle
,
275 bool bOmitRightHeader
= false, bool bOmitLeftHeader
= false,
276 bool bOmitRightFooter
= false, bool bOmitLeftFooter
= false );
278 static void CopyHeaderFooterTextProperty( const css::uno::Reference
< css::beans::XPropertySet
>& xPrevStyle
,
279 const css::uno::Reference
< css::beans::XPropertySet
>& xStyle
,
280 PropertyIds ePropId
);
282 void PrepareHeaderFooterProperties( bool bFirstPage
);
284 bool HasHeader( bool bFirstPage
) const;
285 bool HasFooter( bool bFirstPage
) const;
287 static void SetBorderDistance( const css::uno::Reference
< css::beans::XPropertySet
>& xStyle
,
288 PropertyIds eMarginId
,
291 BorderOffsetFrom eOffsetFrom
,
292 sal_uInt32 nLineWidth
);
294 // Determines if conversion of a given floating table is wanted or not.
295 bool FloatingTableConversion( DomainMapper_Impl
& rDM_Impl
, FloatingTableInfo
& rInfo
);
297 /// Increases paragraph spacing according to Word 2013+ needs if necessary.
298 void HandleIncreasedAnchoredObjectSpacing(DomainMapper_Impl
& rDM_Impl
);
308 explicit SectionPropertyMap( bool bIsFirstSection
);
310 bool IsFirstSection() { return m_bIsFirstSection
; }
312 void SetStart( const css::uno::Reference
< css::text::XTextRange
>& xRange
) { m_xStartingRange
= xRange
; }
314 const css::uno::Reference
< css::text::XTextRange
>& GetStartingRange() const { return m_xStartingRange
; }
316 css::uno::Reference
< css::beans::XPropertySet
> GetPageStyle( const css::uno::Reference
< css::container::XNameContainer
>& xStyles
,
317 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xTextFactory
,
320 const OUString
& GetPageStyleName( bool bFirstPage
= false )
322 return bFirstPage
? m_sFirstPageStyleName
: m_sFollowPageStyleName
;
325 // @throws css::beans::UnknownPropertyException
326 // @throws css::beans::PropertyVetoException
327 // @throws css::lang::IllegalArgumentException
328 // @throws css::lang::WrappedTargetException
329 // @throws css::uno::RuntimeException
330 void InheritOrFinalizePageStyles( DomainMapper_Impl
& rDM_Impl
);
332 void SetBorder( BorderPosition ePos
, sal_Int32 nLineDistance
, const css::table::BorderLine2
& rBorderLine
, bool bShadow
);
333 void SetBorderApply( BorderApply nSet
) { m_eBorderApply
= nSet
; }
334 void SetBorderOffsetFrom( BorderOffsetFrom nSet
) { m_eBorderOffsetFrom
= nSet
; }
336 void SetColumnCount( sal_Int16 nCount
) { m_nColumnCount
= nCount
; }
337 sal_Int16
ColumnCount() const { return m_nColumnCount
; }
339 void SetColumnDistance( sal_Int32 nDist
) { m_nColumnDistance
= nDist
; }
340 void AppendColumnWidth( sal_Int32 nWidth
) { m_aColWidth
.push_back( nWidth
); }
341 void AppendColumnSpacing( sal_Int32 nDist
) { m_aColDistance
.push_back( nDist
); }
343 void SetTitlePage( bool bSet
) { m_bTitlePage
= bSet
; }
344 void SetSeparatorLine( bool bSet
) { m_bSeparatorLineIsOn
= bSet
; }
345 void SetEvenlySpaced( bool bSet
) { m_bEvenlySpaced
= bSet
; }
346 void SetPageNumber( sal_Int32 nSet
) { m_nPageNumber
= nSet
; }
347 void SetPageNumberType( sal_Int32 nSet
) { m_nPageNumberType
= nSet
; }
348 void SetBreakType( sal_Int32 nSet
) { m_nBreakType
= nSet
; }
349 // GetBreakType returns -1 if the breakType has not yet been identified for the section
350 sal_Int32
GetBreakType() { return m_nBreakType
; }
352 void SetLeftMargin( sal_Int32 nSet
) { m_nLeftMargin
= nSet
; }
353 sal_Int32
GetLeftMargin() { return m_nLeftMargin
; }
354 void SetRightMargin( sal_Int32 nSet
) { m_nRightMargin
= nSet
; }
355 sal_Int32
GetRightMargin() { return m_nRightMargin
; }
356 void SetTopMargin( sal_Int32 nSet
) { m_nTopMargin
= nSet
; }
357 void SetBottomMargin( sal_Int32 nSet
) { m_nBottomMargin
= nSet
; }
358 void SetHeaderTop( sal_Int32 nSet
) { m_nHeaderTop
= nSet
; }
359 void SetHeaderBottom( sal_Int32 nSet
) { m_nHeaderBottom
= nSet
; }
360 sal_Int32
GetPageWidth();
362 void SetGridType( sal_Int32 nSet
) { m_nGridType
= nSet
; }
363 void SetGridLinePitch( sal_Int32 nSet
) { m_nGridLinePitch
= nSet
; }
364 void SetGridSnapToChars( bool bSet
) { m_bGridSnapToChars
= bSet
; }
365 void SetDxtCharSpace( sal_Int32 nSet
) { m_nDxtCharSpace
= nSet
; }
367 void SetLnnMod( sal_Int32 nValue
) { m_nLnnMod
= nValue
; }
368 void SetLnc( sal_Int32 nValue
) { m_nLnc
= nValue
; }
369 void SetdxaLnn( sal_Int32 nValue
) { m_ndxaLnn
= nValue
; }
370 void SetLnnMin( sal_Int32 nValue
) { m_nLnnMin
= nValue
; }
372 void addRelativeWidthShape( css::uno::Reference
<css::drawing::XShape
> xShape
) { m_xRelativeWidthShapes
.push_back( xShape
); }
374 // determine which style gets the borders
375 void ApplyBorderToPageStyles( const css::uno::Reference
< css::container::XNameContainer
>& xStyles
,
376 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xTextFactory
,
377 BorderApply eBorderApply
, BorderOffsetFrom eOffsetFrom
);
379 void CloseSectionGroup( DomainMapper_Impl
& rDM_Impl
);
380 // Handling of margins, header and footer for any kind of sections breaks.
381 void HandleMarginsHeaderFooter( bool bFirstPage
, DomainMapper_Impl
& rDM_Impl
);
382 void ClearHeaderFooterLinkToPrevious( bool bHeader
, PageType eType
);
385 class ParagraphProperties
: public virtual SvRefBase
389 sal_Int32 m_nDropCap
; // drop, margin ST_DropCap
390 sal_Int32 m_nLines
; // number of lines of the drop cap
391 sal_Int32 m_w
; // width
392 sal_Int32 m_h
; // height
393 css::text::WrapTextMode m_nWrap
; // from ST_Wrap around, auto, none, notBeside, through, tight
394 sal_Int32 m_hAnchor
; // page, from ST_HAnchor margin, page, text
395 sal_Int32 m_vAnchor
; // around from ST_VAnchor margin, page, text
396 sal_Int32 m_x
; // x-position
398 sal_Int32 m_y
; // y-position
400 sal_Int32 m_hSpace
; // frame padding h
401 sal_Int32 m_vSpace
; // frame padding v
402 sal_Int32 m_hRule
; // from ST_HeightRule exact, atLeast, auto
403 sal_Int32 m_xAlign
; // from ST_XAlign center, inside, left, outside, right
404 sal_Int32 m_yAlign
; // from ST_YAlign bottom, center, inline, inside, outside, top
405 sal_Int8 m_nDropCapLength
; // number of characters
406 OUString m_sParaStyleName
;
408 css::uno::Reference
< css::text::XTextRange
> m_xStartingRange
; // start of a frame
409 css::uno::Reference
< css::text::XTextRange
> m_xEndingRange
; // end of the frame
412 ParagraphProperties();
414 ParagraphProperties(ParagraphProperties
const &) = default;
415 ParagraphProperties(ParagraphProperties
&&) = default;
416 ParagraphProperties
& operator =(ParagraphProperties
const &) = default;
417 ParagraphProperties
& operator =(ParagraphProperties
&&) = default;
419 // Does not compare the starting/ending range, m_sParaStyleName and m_nDropCapLength
420 bool operator==( const ParagraphProperties
& );
422 bool IsFrameMode() const { return m_bFrameMode
; }
423 void SetFrameMode( bool set
= true ) { m_bFrameMode
= set
; }
425 sal_Int32
GetDropCap() const { return m_nDropCap
; }
426 void SetDropCap( sal_Int32 nSet
) { m_nDropCap
= nSet
; }
428 sal_Int32
GetLines() const { return m_nLines
; }
429 void SetLines( sal_Int32 nSet
) { m_nLines
= nSet
; }
431 sal_Int32
Getw() const { return m_w
; }
432 void Setw( sal_Int32 nSet
) { m_w
= nSet
; }
434 sal_Int32
Geth() const { return m_h
; }
435 void Seth( sal_Int32 nSet
) { m_h
= nSet
; }
437 css::text::WrapTextMode
GetWrap() const { return m_nWrap
; }
438 void SetWrap( css::text::WrapTextMode nSet
) { m_nWrap
= nSet
; }
440 sal_Int32
GethAnchor() const { return m_hAnchor
; }
441 void SethAnchor( sal_Int32 nSet
) { m_hAnchor
= nSet
; }
443 sal_Int32
GetvAnchor() const { return m_vAnchor
; }
444 void SetvAnchor( sal_Int32 nSet
) { m_vAnchor
= nSet
; }
446 sal_Int32
Getx() const { return m_x
; }
447 void Setx( sal_Int32 nSet
) { m_x
= nSet
; m_bxValid
= true; }
448 bool IsxValid() const { return m_bxValid
; }
450 sal_Int32
Gety() const { return m_y
; }
451 void Sety( sal_Int32 nSet
) { m_y
= nSet
; m_byValid
= true; }
452 bool IsyValid() const { return m_byValid
; }
454 void SethSpace( sal_Int32 nSet
) { m_hSpace
= nSet
; }
455 sal_Int32
GethSpace() const { return m_hSpace
; }
457 sal_Int32
GetvSpace() const { return m_vSpace
; }
458 void SetvSpace( sal_Int32 nSet
) { m_vSpace
= nSet
; }
460 sal_Int32
GethRule() const { return m_hRule
; }
461 void SethRule( sal_Int32 nSet
) { m_hRule
= nSet
; }
463 sal_Int32
GetxAlign() const { return m_xAlign
; }
464 void SetxAlign( sal_Int32 nSet
) { m_xAlign
= nSet
; }
466 sal_Int32
GetyAlign() const { return m_yAlign
; }
467 void SetyAlign( sal_Int32 nSet
) { m_yAlign
= nSet
; }
469 sal_Int8
GetDropCapLength() const { return m_nDropCapLength
; }
470 void SetDropCapLength( sal_Int8 nSet
) { m_nDropCapLength
= nSet
; }
472 const css::uno::Reference
< css::text::XTextRange
>& GetStartingRange() const { return m_xStartingRange
; }
473 void SetStartingRange( const css::uno::Reference
< css::text::XTextRange
>& xSet
) { m_xStartingRange
= xSet
; }
475 const css::uno::Reference
< css::text::XTextRange
>& GetEndingRange() const { return m_xEndingRange
; }
476 void SetEndingRange( const css::uno::Reference
< css::text::XTextRange
>& xSet
) { m_xEndingRange
= xSet
; }
478 const OUString
& GetParaStyleName() const { return m_sParaStyleName
; }
479 void SetParaStyleName( const OUString
& rSet
) { m_sParaStyleName
= rSet
; }
481 void ResetFrameProperties();
484 typedef tools::SvRef
< ParagraphProperties
> ParagraphPropertiesPtr
;
486 /*-------------------------------------------------------------------------
487 property map of a stylesheet
488 -----------------------------------------------------------------------*/
490 #define WW_OUTLINE_MAX sal_Int16( 9 )
491 #define WW_OUTLINE_MIN sal_Int16( 0 )
493 class StyleSheetPropertyMap
495 , public ParagraphProperties
499 sal_Int16 mnListLevel
;
500 sal_Int16 mnOutlineLevel
;
504 explicit StyleSheetPropertyMap();
506 sal_Int32
GetListId() const { return mnListId
; }
507 void SetListId( sal_Int32 nId
) { mnListId
= nId
; }
509 sal_Int16
GetListLevel() const { return mnListLevel
; }
510 void SetListLevel( sal_Int16 nLevel
) { mnListLevel
= nLevel
; }
512 sal_Int16
GetOutlineLevel() const { return mnOutlineLevel
; }
513 void SetOutlineLevel( sal_Int16 nLevel
) { if ( nLevel
< WW_OUTLINE_MAX
) mnOutlineLevel
= nLevel
; }
515 sal_Int32
GetNumId() const { return mnNumId
; }
516 void SetNumId(sal_Int32 nId
) { mnNumId
= nId
; }
519 class ParagraphPropertyMap
521 , public ParagraphProperties
524 explicit ParagraphPropertyMap() {}
527 class TablePropertyMap
531 enum TablePropertyMapTarget
533 TablePropertyMapTarget_START
,
534 CELL_MAR_LEFT
= TablePropertyMapTarget_START
,
543 TablePropertyMapTarget_MAX
559 ValidValue m_aValidValues
[TablePropertyMapTarget_MAX
];
562 explicit TablePropertyMap() {}
564 bool getValue( TablePropertyMapTarget eWhich
, sal_Int32
& nFill
);
565 void setValue( TablePropertyMapTarget eWhich
, sal_Int32 nSet
);
567 virtual void insertTableProperties( const PropertyMap
*, const bool bOverwrite
= true ) override
;
570 typedef tools::SvRef
< TablePropertyMap
> TablePropertyMapPtr
;
572 } // namespace dmapper
573 } // namespace writerfilter
575 #endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAP_HXX
577 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */