1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "PageBordersHandler.hxx"
23 
24 #include <ooxml/resourceids.hxx>
25 
26 #include "dmapperLoggers.hxx"
27 
28 namespace writerfilter {
29 namespace dmapper {
30 
_PgBorder()31 _PgBorder::_PgBorder( ) :
32     m_nDistance( 0 ),
33     m_ePos( BORDER_RIGHT )
34 {
35 }
36 
~_PgBorder()37 _PgBorder::~_PgBorder( )
38 {
39 }
40 
PageBordersHandler()41 PageBordersHandler::PageBordersHandler( ) :
42 LoggedProperties(dmapper_logger, "PageBordersHandler"),
43 m_nDisplay( 0 ),
44 m_nOffset( 0 )
45 {
46 }
47 
~PageBordersHandler()48 PageBordersHandler::~PageBordersHandler( )
49 {
50 }
51 
lcl_attribute(Id eName,Value & rVal)52 void PageBordersHandler::lcl_attribute( Id eName, Value& rVal )
53 {
54     int nIntValue = rVal.getInt( );
55     switch ( eName )
56     {
57         case NS_ooxml::LN_CT_PageBorders_display:
58         {
59             switch ( nIntValue )
60             {
61                 default:
62                 case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_allPages:
63                     m_nDisplay = 0;
64                     break;
65                 case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_firstPage:
66                     m_nDisplay = 1;
67                     break;
68                 case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_notFirstPage:
69                     m_nDisplay = 2;
70                     break;
71             }
72         }
73         break;
74         case NS_ooxml::LN_CT_PageBorders_offsetFrom:
75         {
76             switch ( nIntValue )
77             {
78                 default:
79                 case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderOffset_page:
80                     m_nOffset = 1;
81                     break;
82                 case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderOffset_text:
83                     m_nOffset = 0;
84                     break;
85             }
86         }
87         break;
88         default:;
89     }
90 }
91 
lcl_sprm(Sprm & rSprm)92 void PageBordersHandler::lcl_sprm( Sprm& rSprm )
93 {
94     switch ( rSprm.getId( ) )
95     {
96         case NS_ooxml::LN_CT_PageBorders_top:
97         case NS_ooxml::LN_CT_PageBorders_left:
98         case NS_ooxml::LN_CT_PageBorders_bottom:
99         case NS_ooxml::LN_CT_PageBorders_right:
100         {
101             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
102             if( pProperties.get())
103             {
104                 BorderHandlerPtr pBorderHandler( new BorderHandler( true ) );
105                 pProperties->resolve(*pBorderHandler);
106                 BorderPosition ePos = BorderPosition( 0 );
107                 switch( rSprm.getId( ) )
108                 {
109                     case NS_ooxml::LN_CT_PageBorders_top:
110                         ePos = BORDER_TOP;
111                     break;
112                     case NS_ooxml::LN_CT_PageBorders_left:
113                         ePos = BORDER_LEFT;
114                     break;
115                     case NS_ooxml::LN_CT_PageBorders_bottom:
116                         ePos = BORDER_BOTTOM;
117                     break;
118                     case NS_ooxml::LN_CT_PageBorders_right:
119                         ePos = BORDER_RIGHT;
120                     break;
121                     default:;
122                 }
123 
124                 _PgBorder aPgBorder;
125                 aPgBorder.m_rLine = pBorderHandler->getBorderLine( );
126                 aPgBorder.m_nDistance = pBorderHandler->getLineDistance( );
127                 aPgBorder.m_ePos = ePos;
128                 m_aBorders.push_back( aPgBorder );
129             }
130         }
131         break;
132         default:;
133     }
134 }
135 
SetBorders(SectionPropertyMap * pSectContext)136 void PageBordersHandler::SetBorders( SectionPropertyMap* pSectContext )
137 {
138     for ( int i = 0, length = m_aBorders.size( ); i < length; i++ )
139     {
140         _PgBorder aBorder = m_aBorders[i];
141         pSectContext->SetBorder( aBorder.m_ePos, aBorder.m_nDistance, aBorder.m_rLine );
142     }
143 }
144 
145 } }
146