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 .
20 #include "BorderHandler.hxx"
21 #include "PageBordersHandler.hxx"
23 #include <ooxml/resourceids.hxx>
25 namespace writerfilter::dmapper
{
27 PgBorder::PgBorder( ) :
29 m_ePos( BORDER_RIGHT
),
34 PageBordersHandler::PageBordersHandler( ) :
35 LoggedProperties("PageBordersHandler"),
36 m_eBorderApply(SectionPropertyMap::BorderApply::ToAllInSection
),
37 m_eOffsetFrom(SectionPropertyMap::BorderOffsetFrom::Text
)
41 PageBordersHandler::~PageBordersHandler( )
45 void PageBordersHandler::lcl_attribute( Id eName
, Value
& rVal
)
47 int nIntValue
= rVal
.getInt( );
50 case NS_ooxml::LN_CT_PageBorders_display
:
55 case NS_ooxml::LN_Value_doc_ST_PageBorderDisplay_allPages
:
56 m_eBorderApply
= SectionPropertyMap::BorderApply::ToAllInSection
;
58 case NS_ooxml::LN_Value_doc_ST_PageBorderDisplay_firstPage
:
59 m_eBorderApply
= SectionPropertyMap::BorderApply::ToFirstPageInSection
;
61 case NS_ooxml::LN_Value_doc_ST_PageBorderDisplay_notFirstPage
:
62 m_eBorderApply
= SectionPropertyMap::BorderApply::ToAllButFirstInSection
;
67 case NS_ooxml::LN_CT_PageBorders_offsetFrom
:
72 case NS_ooxml::LN_Value_doc_ST_PageBorderOffset_page
:
73 m_eOffsetFrom
= SectionPropertyMap::BorderOffsetFrom::Edge
;
75 case NS_ooxml::LN_Value_doc_ST_PageBorderOffset_text
:
76 m_eOffsetFrom
= SectionPropertyMap::BorderOffsetFrom::Text
;
85 void PageBordersHandler::lcl_sprm( Sprm
& rSprm
)
87 switch ( rSprm
.getId( ) )
89 case NS_ooxml::LN_CT_PageBorders_top
:
90 case NS_ooxml::LN_CT_PageBorders_left
:
91 case NS_ooxml::LN_CT_PageBorders_bottom
:
92 case NS_ooxml::LN_CT_PageBorders_right
:
94 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
97 auto pBorderHandler
= std::make_shared
<BorderHandler
>( true );
98 pProperties
->resolve(*pBorderHandler
);
99 BorderPosition ePos
= BorderPosition( 0 );
100 switch( rSprm
.getId( ) )
102 case NS_ooxml::LN_CT_PageBorders_top
:
105 case NS_ooxml::LN_CT_PageBorders_left
:
108 case NS_ooxml::LN_CT_PageBorders_bottom
:
109 ePos
= BORDER_BOTTOM
;
111 case NS_ooxml::LN_CT_PageBorders_right
:
118 aPgBorder
.m_rLine
= pBorderHandler
->getBorderLine( );
119 aPgBorder
.m_nDistance
= pBorderHandler
->getLineDistance( );
120 aPgBorder
.m_ePos
= ePos
;
121 aPgBorder
.m_bShadow
= pBorderHandler
->getShadow();
122 if (pBorderHandler
->getLineType() != NS_ooxml::LN_Value_ST_Border_none
)
124 m_aBorders
.push_back( aPgBorder
);
133 void PageBordersHandler::SetBorders( SectionPropertyMap
* pSectContext
)
135 for (const PgBorder
& rBorder
: m_aBorders
)
137 pSectContext
->SetBorder( rBorder
.m_ePos
, rBorder
.m_nDistance
, rBorder
.m_rLine
, rBorder
.m_bShadow
);
139 pSectContext
->SetBorderApply(m_eBorderApply
);
140 pSectContext
->SetBorderOffsetFrom(m_eOffsetFrom
);
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */