Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "PageBordersHandler.hxx"
21 :
22 : #include <ooxml/resourceids.hxx>
23 :
24 : #include "dmapperLoggers.hxx"
25 :
26 : namespace writerfilter {
27 : namespace dmapper {
28 :
29 8 : _PgBorder::_PgBorder( ) :
30 : m_nDistance( 0 ),
31 8 : m_ePos( BORDER_RIGHT )
32 : {
33 8 : }
34 :
35 30 : _PgBorder::~_PgBorder( )
36 : {
37 30 : }
38 :
39 2 : PageBordersHandler::PageBordersHandler( ) :
40 : LoggedProperties(dmapper_logger, "PageBordersHandler"),
41 : m_nDisplay( 0 ),
42 2 : m_nOffset( 0 )
43 : {
44 2 : }
45 :
46 4 : PageBordersHandler::~PageBordersHandler( )
47 : {
48 4 : }
49 :
50 2 : void PageBordersHandler::lcl_attribute( Id eName, Value& rVal )
51 : {
52 2 : int nIntValue = rVal.getInt( );
53 2 : switch ( eName )
54 : {
55 : case NS_ooxml::LN_CT_PageBorders_display:
56 : {
57 0 : switch ( nIntValue )
58 : {
59 : default:
60 : case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_allPages:
61 0 : m_nDisplay = 0;
62 0 : break;
63 : case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_firstPage:
64 0 : m_nDisplay = 1;
65 0 : break;
66 : case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_notFirstPage:
67 0 : m_nDisplay = 2;
68 0 : break;
69 : }
70 : }
71 0 : break;
72 : case NS_ooxml::LN_CT_PageBorders_offsetFrom:
73 : {
74 2 : switch ( nIntValue )
75 : {
76 : default:
77 : case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderOffset_page:
78 2 : m_nOffset = 1;
79 2 : break;
80 : case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderOffset_text:
81 0 : m_nOffset = 0;
82 0 : break;
83 : }
84 : }
85 2 : break;
86 : default:;
87 : }
88 2 : }
89 :
90 8 : void PageBordersHandler::lcl_sprm( Sprm& rSprm )
91 : {
92 8 : switch ( rSprm.getId( ) )
93 : {
94 : case NS_ooxml::LN_CT_PageBorders_top:
95 : case NS_ooxml::LN_CT_PageBorders_left:
96 : case NS_ooxml::LN_CT_PageBorders_bottom:
97 : case NS_ooxml::LN_CT_PageBorders_right:
98 : {
99 8 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
100 8 : if( pProperties.get())
101 : {
102 8 : BorderHandlerPtr pBorderHandler( new BorderHandler( true ) );
103 8 : pProperties->resolve(*pBorderHandler);
104 8 : BorderPosition ePos = BorderPosition( 0 );
105 8 : switch( rSprm.getId( ) )
106 : {
107 : case NS_ooxml::LN_CT_PageBorders_top:
108 2 : ePos = BORDER_TOP;
109 2 : break;
110 : case NS_ooxml::LN_CT_PageBorders_left:
111 2 : ePos = BORDER_LEFT;
112 2 : break;
113 : case NS_ooxml::LN_CT_PageBorders_bottom:
114 2 : ePos = BORDER_BOTTOM;
115 2 : break;
116 : case NS_ooxml::LN_CT_PageBorders_right:
117 2 : ePos = BORDER_RIGHT;
118 2 : break;
119 : default:;
120 : }
121 :
122 8 : _PgBorder aPgBorder;
123 8 : aPgBorder.m_rLine = pBorderHandler->getBorderLine( );
124 8 : aPgBorder.m_nDistance = pBorderHandler->getLineDistance( );
125 8 : aPgBorder.m_ePos = ePos;
126 8 : m_aBorders.push_back( aPgBorder );
127 8 : }
128 : }
129 8 : break;
130 : default:;
131 : }
132 8 : }
133 :
134 2 : void PageBordersHandler::SetBorders( SectionPropertyMap* pSectContext )
135 : {
136 10 : for ( int i = 0, length = m_aBorders.size( ); i < length; i++ )
137 : {
138 8 : _PgBorder aBorder = m_aBorders[i];
139 8 : pSectContext->SetBorder( aBorder.m_ePos, aBorder.m_nDistance, aBorder.m_rLine );
140 8 : }
141 2 : }
142 :
143 15 : } }
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|