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 "ConversionHelper.hxx"
23 #include "GraphicHelpers.hxx"
24 
25 #include <ooxml/resourceids.hxx>
26 
27 #include <com/sun/star/text/HoriOrientation.hpp>
28 #include <com/sun/star/text/VertOrientation.hpp>
29 #include <com/sun/star/text/RelOrientation.hpp>
30 #include <com/sun/star/text/WrapTextMode.hpp>
31 
32 #include "dmapperLoggers.hxx"
33 
34 #include <iostream>
35 using namespace std;
36 
37 namespace writerfilter {
38 namespace dmapper {
39 
40 using namespace com::sun::star;
41 
PositionHandler()42 PositionHandler::PositionHandler( ) :
43 LoggedProperties(dmapper_logger, "PositionHandler")
44 {
45     m_nOrient = text::VertOrientation::NONE;
46     m_nRelation = text::RelOrientation::FRAME;
47     m_nPosition = 0;
48 }
49 
~PositionHandler()50 PositionHandler::~PositionHandler( )
51 {
52 }
53 
lcl_attribute(Id aName,Value & rVal)54 void PositionHandler::lcl_attribute( Id aName, Value& rVal )
55 {
56     sal_Int32 nIntValue = rVal.getInt( );
57     switch ( aName )
58     {
59         case NS_ooxml::LN_CT_PosV_relativeFrom:
60             {
61                 // TODO There are some other unhandled values
62                 static Id pVertRelValues[] =
63                 {
64                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_margin,
65                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_page,
66                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_paragraph,
67                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_line
68                 };
69 
70                 static sal_Int16 pVertRelations[] =
71                 {
72                     text::RelOrientation::PAGE_PRINT_AREA,
73                     text::RelOrientation::PAGE_FRAME,
74                     text::RelOrientation::FRAME,
75                     text::RelOrientation::TEXT_LINE
76                 };
77 
78                 for ( int i = 0; i < 4; i++ )
79                 {
80                     if ( pVertRelValues[i] == sal_uInt32( nIntValue ) )
81                         m_nRelation = pVertRelations[i];
82                 }
83             }
84             break;
85         case NS_ooxml::LN_CT_PosH_relativeFrom:
86             {
87                 // TODO There are some other unhandled values
88                 static Id pHoriRelValues[] =
89                 {
90                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_margin,
91                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_page,
92                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_column,
93                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_character
94                 };
95 
96                 static sal_Int16 pHoriRelations[] =
97                 {
98                     text::RelOrientation::PAGE_PRINT_AREA,
99                     text::RelOrientation::PAGE_FRAME,
100                     text::RelOrientation::FRAME,
101                     text::RelOrientation::CHAR,
102                 };
103 
104                 for ( int i = 0; i < 4; i++ )
105                 {
106                     if ( pHoriRelValues[i] == sal_uInt32( nIntValue ) )
107                         m_nRelation = pHoriRelations[i];
108                 }
109             }
110             break;
111         default:
112 #ifdef DEBUG_DOMAINMAPPER
113             dmapper_logger->element("unhandled");
114 #endif
115             break;
116     }
117 }
118 
lcl_sprm(Sprm & rSprm)119 void PositionHandler::lcl_sprm( Sprm& rSprm )
120 {
121     Value::Pointer_t pValue = rSprm.getValue();
122     sal_Int32 nIntValue = pValue->getInt();
123 
124     switch ( rSprm.getId( ) )
125     {
126         case NS_ooxml::LN_CT_PosV_align:
127             {
128                 static Id pVertValues[] =
129                 {
130                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignV_top,
131                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignV_bottom,
132                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignV_center,
133                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignV_inside,
134                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignV_outside
135                 };
136 
137                 static sal_Int16 pVertOrients[] =
138                 {
139                     text::VertOrientation::TOP,
140                     text::VertOrientation::BOTTOM,
141                     text::VertOrientation::CENTER,
142                     text::VertOrientation::NONE,
143                     text::VertOrientation::NONE
144                 };
145 
146                 for ( int i = 0; i < 5; i++ )
147                 {
148                     if ( pVertValues[i] == sal_uInt32( nIntValue ) )
149                         m_nOrient = pVertOrients[i];
150                 }
151             }
152             break;
153         case NS_ooxml::LN_CT_PosH_align:
154             {
155                 static Id pHoriValues[] =
156                 {
157                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignH_left,
158                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignH_right,
159                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignH_center,
160                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignH_inside,
161                     NS_ooxml::LN_Value_wordprocessingDrawing_ST_AlignH_outside
162                 };
163 
164                 static sal_Int16 pHoriOrients[] =
165                 {
166                     text::HoriOrientation::LEFT,
167                     text::HoriOrientation::RIGHT,
168                     text::HoriOrientation::CENTER,
169                     text::HoriOrientation::INSIDE,
170                     text::HoriOrientation::OUTSIDE
171                 };
172 
173                 for ( int i = 0; i < 5; i++ )
174                 {
175                     if ( pHoriValues[i] == sal_uInt32( nIntValue ) )
176                         m_nOrient = pHoriOrients[i];
177                 }
178             }
179             break;
180         case NS_ooxml::LN_CT_PosH_posOffset:
181         case NS_ooxml::LN_CT_PosV_posOffset:
182             m_nPosition = ConversionHelper::convertEMUToMM100( nIntValue );
183         default:
184 #ifdef DEBUG_DOMAINMAPPER
185             dmapper_logger->element("unhandled");
186 #endif
187             break;
188     }
189 }
190 
WrapHandler()191 WrapHandler::WrapHandler( ) :
192 LoggedProperties(dmapper_logger, "WrapHandler"),
193     m_nType( 0 ),
194     m_nSide( 0 )
195 {
196 }
197 
~WrapHandler()198 WrapHandler::~WrapHandler( )
199 {
200 }
201 
lcl_attribute(Id aName,Value & rVal)202 void WrapHandler::lcl_attribute( Id aName, Value& rVal )
203 {
204     switch ( aName )
205     {
206         case NS_ooxml::LN_CT_Wrap_type:
207             m_nType = sal_Int32( rVal.getInt( ) );
208             break;
209         case NS_ooxml::LN_CT_Wrap_side:
210             m_nSide = sal_Int32( rVal.getInt( ) );
211             break;
212         default:;
213     }
214 }
215 
lcl_sprm(Sprm &)216 void WrapHandler::lcl_sprm( Sprm& )
217 {
218 }
219 
getWrapMode()220 sal_Int32 WrapHandler::getWrapMode( )
221 {
222     sal_Int32 nMode = com::sun::star::text::WrapTextMode_NONE;
223 
224     switch ( m_nType )
225     {
226         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_square:
227         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_tight:
228             {
229                 switch ( m_nSide )
230                 {
231                     case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_left:
232                         nMode = com::sun::star::text::WrapTextMode_LEFT;
233                         break;
234                     case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_right:
235                         nMode = com::sun::star::text::WrapTextMode_RIGHT;
236                         break;
237                     default:
238                         nMode = com::sun::star::text::WrapTextMode_PARALLEL;
239                 }
240             }
241             break;
242         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_through:
243             nMode = com::sun::star::text::WrapTextMode_THROUGHT;
244             break;
245         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_topAndBottom:
246         case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_none:
247         default:
248             nMode = com::sun::star::text::WrapTextMode_NONE;
249     }
250 
251     return nMode;
252 }
253 
254 } }
255