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 16 : _PgBorder::_PgBorder( ) :
30 : m_nDistance( 0 ),
31 16 : m_ePos( BORDER_RIGHT )
32 : {
33 16 : }
34 :
35 60 : _PgBorder::~_PgBorder( )
36 : {
37 60 : }
38 :
39 4 : PageBordersHandler::PageBordersHandler( ) :
40 : LoggedProperties(dmapper_logger, "PageBordersHandler"),
41 : m_nDisplay( 0 ),
42 4 : m_nOffset( 0 )
43 : {
44 4 : }
45 :
46 8 : PageBordersHandler::~PageBordersHandler( )
47 : {
48 8 : }
49 :
50 4 : void PageBordersHandler::lcl_attribute( Id eName, Value& rVal )
51 : {
52 4 : int nIntValue = rVal.getInt( );
53 4 : 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 4 : switch ( nIntValue )
75 : {
76 : default:
77 : case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderOffset_page:
78 4 : m_nOffset = 1;
79 4 : break;
80 : case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderOffset_text:
81 0 : m_nOffset = 0;
82 0 : break;
83 : }
84 : }
85 4 : break;
86 : default:;
87 : }
88 4 : }
89 :
90 16 : void PageBordersHandler::lcl_sprm( Sprm& rSprm )
91 : {
92 16 : 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 16 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
100 16 : if( pProperties.get())
101 : {
102 16 : BorderHandlerPtr pBorderHandler( new BorderHandler( true ) );
103 16 : pProperties->resolve(*pBorderHandler);
104 16 : BorderPosition ePos = BorderPosition( 0 );
105 16 : switch( rSprm.getId( ) )
106 : {
107 : case NS_ooxml::LN_CT_PageBorders_top:
108 4 : ePos = BORDER_TOP;
109 4 : break;
110 : case NS_ooxml::LN_CT_PageBorders_left:
111 4 : ePos = BORDER_LEFT;
112 4 : break;
113 : case NS_ooxml::LN_CT_PageBorders_bottom:
114 4 : ePos = BORDER_BOTTOM;
115 4 : break;
116 : case NS_ooxml::LN_CT_PageBorders_right:
117 4 : ePos = BORDER_RIGHT;
118 4 : break;
119 : default:;
120 : }
121 :
122 16 : _PgBorder aPgBorder;
123 16 : aPgBorder.m_rLine = pBorderHandler->getBorderLine( );
124 16 : aPgBorder.m_nDistance = pBorderHandler->getLineDistance( );
125 16 : aPgBorder.m_ePos = ePos;
126 16 : m_aBorders.push_back( aPgBorder );
127 16 : }
128 : }
129 16 : break;
130 : default:;
131 : }
132 16 : }
133 :
134 4 : void PageBordersHandler::SetBorders( SectionPropertyMap* pSectContext )
135 : {
136 20 : for ( int i = 0, length = m_aBorders.size( ); i < length; i++ )
137 : {
138 16 : _PgBorder aBorder = m_aBorders[i];
139 16 : pSectContext->SetBorder( aBorder.m_ePos, aBorder.m_nDistance, aBorder.m_rLine );
140 16 : }
141 4 : }
142 :
143 30 : } }
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|