Branch data 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 : : #include "ConversionHelper.hxx"
20 : : #include "GraphicHelpers.hxx"
21 : :
22 : : #include <ooxml/resourceids.hxx>
23 : :
24 : : #include <com/sun/star/text/HoriOrientation.hpp>
25 : : #include <com/sun/star/text/VertOrientation.hpp>
26 : : #include <com/sun/star/text/RelOrientation.hpp>
27 : : #include <com/sun/star/text/WrapTextMode.hpp>
28 : :
29 : : #include "dmapperLoggers.hxx"
30 : :
31 : : #include <iostream>
32 : : using namespace std;
33 : :
34 : : namespace writerfilter {
35 : : namespace dmapper {
36 : :
37 : : using namespace com::sun::star;
38 : :
39 : : int PositionHandler::savedPositionOffsetV = 0;
40 : : int PositionHandler::savedPositionOffsetH = 0;
41 : : int PositionHandler::savedAlignV = text::VertOrientation::NONE;
42 : : int PositionHandler::savedAlignH = text::HoriOrientation::NONE;
43 : :
44 : 24 : PositionHandler::PositionHandler( bool vertical ) :
45 [ + - ][ + - ]: 24 : LoggedProperties(dmapper_logger, "PositionHandler")
[ + - ][ + - ]
46 : : {
47 : 24 : m_nRelation = text::RelOrientation::FRAME;
48 [ + + ]: 24 : if( vertical )
49 : : {
50 : 12 : m_nPosition = savedPositionOffsetV;
51 : 12 : m_nOrient = savedAlignV;
52 : 12 : savedPositionOffsetV = 0;
53 : 12 : savedAlignV = text::VertOrientation::NONE;
54 : : }
55 : : else
56 : : {
57 : 12 : m_nPosition = savedPositionOffsetH;
58 : 12 : m_nOrient = savedAlignH;
59 : 12 : savedPositionOffsetH = 0;
60 : 12 : savedAlignH = text::HoriOrientation::NONE;
61 : : }
62 : 24 : }
63 : :
64 : 24 : PositionHandler::~PositionHandler( )
65 : : {
66 [ - + ]: 48 : }
67 : :
68 : 24 : void PositionHandler::lcl_attribute( Id aName, Value& rVal )
69 : : {
70 : 24 : sal_Int32 nIntValue = rVal.getInt( );
71 [ + + - ]: 24 : switch ( aName )
72 : : {
73 : : case NS_ooxml::LN_CT_PosV_relativeFrom:
74 : : {
75 : : // TODO There are some other unhandled values
76 : : static Id pVertRelValues[] =
77 : : {
78 : : NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_margin,
79 : : NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_page,
80 : : NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_paragraph,
81 : : NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_line
82 : : };
83 : :
84 : : static sal_Int16 pVertRelations[] =
85 : : {
86 : : text::RelOrientation::PAGE_PRINT_AREA,
87 : : text::RelOrientation::PAGE_FRAME,
88 : : text::RelOrientation::FRAME,
89 : : text::RelOrientation::TEXT_LINE
90 : : };
91 : :
92 [ + + ]: 60 : for ( int i = 0; i < 4; i++ )
93 : : {
94 [ + + ]: 48 : if ( pVertRelValues[i] == sal_uInt32( nIntValue ) )
95 : 12 : m_nRelation = pVertRelations[i];
96 : : }
97 : : }
98 : 12 : break;
99 : : case NS_ooxml::LN_CT_PosH_relativeFrom:
100 : : {
101 : : // TODO There are some other unhandled values
102 : : static Id pHoriRelValues[] =
103 : : {
104 : : NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_margin,
105 : : NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_page,
106 : : NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_column,
107 : : NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_character
108 : : };
109 : :
110 : : static sal_Int16 pHoriRelations[] =
111 : : {
112 : : text::RelOrientation::PAGE_PRINT_AREA,
113 : : text::RelOrientation::PAGE_FRAME,
114 : : text::RelOrientation::FRAME,
115 : : text::RelOrientation::CHAR,
116 : : };
117 : :
118 [ + + ]: 60 : for ( int i = 0; i < 4; i++ )
119 : : {
120 [ + + ]: 48 : if ( pHoriRelValues[i] == sal_uInt32( nIntValue ) )
121 : 12 : m_nRelation = pHoriRelations[i];
122 : : }
123 : : }
124 : 12 : break;
125 : : default:
126 : : #ifdef DEBUG_DOMAINMAPPER
127 : : dmapper_logger->element("unhandled");
128 : : #endif
129 : 0 : break;
130 : : }
131 : 24 : }
132 : :
133 : 24 : void PositionHandler::lcl_sprm( Sprm& )
134 : : {
135 : 24 : }
136 : :
137 : 24 : void PositionHandler::setPositionOffset(const OUString & sText, bool vertical)
138 : : {
139 [ + + ]: 24 : if( vertical )
140 : 12 : savedPositionOffsetV = ConversionHelper::convertEMUToMM100( sText.toInt32());
141 : : else
142 : 12 : savedPositionOffsetH = ConversionHelper::convertEMUToMM100( sText.toInt32());
143 : 24 : }
144 : :
145 : 0 : void PositionHandler::setAlignH(const OUString & sText)
146 : : {
147 [ # # ]: 0 : if( sText == "left")
148 : 0 : savedAlignH = text::HoriOrientation::LEFT;
149 [ # # ]: 0 : else if( sText == "right" )
150 : 0 : savedAlignH = text::HoriOrientation::RIGHT;
151 [ # # ]: 0 : else if( sText == "center" )
152 : 0 : savedAlignH = text::HoriOrientation::CENTER;
153 [ # # ]: 0 : else if( sText == "inside" )
154 : 0 : savedAlignH = text::HoriOrientation::INSIDE;
155 [ # # ]: 0 : else if( sText == "outside" )
156 : 0 : savedAlignH = text::HoriOrientation::OUTSIDE;
157 : 0 : }
158 : :
159 : 0 : void PositionHandler::setAlignV(const OUString & sText)
160 : : {
161 [ # # ]: 0 : if( sText == "top" )
162 : 0 : savedAlignV = text::VertOrientation::TOP;
163 [ # # ]: 0 : else if( sText == "bottom" )
164 : 0 : savedAlignV = text::VertOrientation::BOTTOM;
165 [ # # ]: 0 : else if( sText == "center" )
166 : 0 : savedAlignV = text::VertOrientation::CENTER;
167 [ # # ]: 0 : else if( sText == "inside" )
168 : 0 : savedAlignV = text::VertOrientation::NONE;
169 [ # # ]: 0 : else if( sText == "outside" )
170 : 0 : savedAlignV = text::VertOrientation::NONE;
171 : 0 : }
172 : :
173 : 0 : WrapHandler::WrapHandler( ) :
174 : : LoggedProperties(dmapper_logger, "WrapHandler"),
175 : : m_nType( 0 ),
176 [ # # ][ # # ]: 0 : m_nSide( 0 )
[ # # ][ # # ]
177 : : {
178 : 0 : }
179 : :
180 : 0 : WrapHandler::~WrapHandler( )
181 : : {
182 [ # # ]: 0 : }
183 : :
184 : 0 : void WrapHandler::lcl_attribute( Id aName, Value& rVal )
185 : : {
186 [ # # # ]: 0 : switch ( aName )
187 : : {
188 : : case NS_ooxml::LN_CT_Wrap_type:
189 : 0 : m_nType = sal_Int32( rVal.getInt( ) );
190 : 0 : break;
191 : : case NS_ooxml::LN_CT_Wrap_side:
192 : 0 : m_nSide = sal_Int32( rVal.getInt( ) );
193 : 0 : break;
194 : : default:;
195 : : }
196 : 0 : }
197 : :
198 : 0 : void WrapHandler::lcl_sprm( Sprm& )
199 : : {
200 : 0 : }
201 : :
202 : 0 : sal_Int32 WrapHandler::getWrapMode( )
203 : : {
204 : : // The wrap values do not map directly to our wrap mode,
205 : : // e.g. none in .docx actually means through in LO.
206 : 0 : sal_Int32 nMode = com::sun::star::text::WrapTextMode_THROUGHT;
207 : :
208 [ # # # ]: 0 : switch ( m_nType )
209 : : {
210 : : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_square:
211 : : // through and tight are somewhat complicated, approximate
212 : : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_tight:
213 : : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_through:
214 : : {
215 [ # # # ]: 0 : switch ( m_nSide )
216 : : {
217 : : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_left:
218 : 0 : nMode = com::sun::star::text::WrapTextMode_LEFT;
219 : 0 : break;
220 : : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_right:
221 : 0 : nMode = com::sun::star::text::WrapTextMode_RIGHT;
222 : 0 : break;
223 : : default:
224 : 0 : nMode = com::sun::star::text::WrapTextMode_PARALLEL;
225 : : }
226 : : }
227 : 0 : break;
228 : : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_topAndBottom:
229 : 0 : nMode = com::sun::star::text::WrapTextMode_NONE;
230 : 0 : break;
231 : : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_none:
232 : : default:
233 : 0 : nMode = com::sun::star::text::WrapTextMode_THROUGHT;
234 : : }
235 : :
236 : 0 : return nMode;
237 : : }
238 : :
239 : :
240 : 21 : void GraphicZOrderHelper::addItem( uno::Reference< beans::XPropertySet > props, sal_Int32 relativeHeight )
241 : : {
242 : 21 : items[ relativeHeight ] = props;
243 : 21 : }
244 : :
245 : : // The relativeHeight value in .docx is an arbitrary number, where only the relative ordering matters.
246 : : // But in Writer, the z-order is index in 0..(numitems-1) range, so whenever a new item needs to be
247 : : // added in the proper z-order, it is necessary to find the proper index.
248 : 21 : sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight )
249 : : {
250 : 21 : Items::const_iterator it = items.begin();
251 [ + + ]: 27 : while( it != items.end())
252 : : {
253 : : // std::map is iterated sorted by key
254 [ + + ]: 15 : if( it->first > relativeHeight )
255 : 9 : break; // this is the first one higher, we belong right before it
256 : : else
257 : 6 : ++it;
258 : : }
259 [ + + ]: 21 : if( it == items.end()) // we're topmost
260 : : {
261 [ + + ]: 12 : if( items.empty())
262 : 9 : return 0;
263 : 3 : sal_Int32 itemZOrder(0);
264 : 3 : --it;
265 [ + - + - ]: 6 : if( it->second->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
[ + - ]
266 [ + - ][ + - ]: 3 : .GetName( PROP_Z_ORDER )) >>= itemZOrder )
267 : 12 : return itemZOrder + 1; // after the topmost
268 : : }
269 : : else
270 : : {
271 : 9 : sal_Int32 itemZOrder(0);
272 [ + - ]: 18 : if( it->second->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
[ + - + - ]
273 [ + - ][ + - ]: 9 : .GetName( PROP_Z_ORDER )) >>= itemZOrder )
274 : 9 : return itemZOrder; // before the item
275 : : }
276 : : SAL_WARN( "writerfilter", "findZOrder() didn't find item z-order" );
277 : 21 : return 0; // this should not(?) happen
278 : : }
279 : :
280 [ + - ][ + - ]: 60 : } }
281 : :
282 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|