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 16 : PositionHandler::PositionHandler( bool vertical ) :
45 16 : LoggedProperties(dmapper_logger, "PositionHandler")
46 : {
47 16 : m_nRelation = text::RelOrientation::FRAME;
48 16 : if( vertical )
49 : {
50 8 : m_nPosition = savedPositionOffsetV;
51 8 : m_nOrient = savedAlignV;
52 8 : savedPositionOffsetV = 0;
53 8 : savedAlignV = text::VertOrientation::NONE;
54 : }
55 : else
56 : {
57 8 : m_nPosition = savedPositionOffsetH;
58 8 : m_nOrient = savedAlignH;
59 8 : savedPositionOffsetH = 0;
60 8 : savedAlignH = text::HoriOrientation::NONE;
61 : }
62 16 : }
63 :
64 32 : PositionHandler::~PositionHandler( )
65 : {
66 32 : }
67 :
68 10 : void PositionHandler::lcl_attribute( Id aName, Value& rVal )
69 : {
70 10 : sal_Int32 nIntValue = rVal.getInt( );
71 10 : 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 25 : for ( int i = 0; i < 4; i++ )
93 : {
94 20 : if ( pVertRelValues[i] == sal_uInt32( nIntValue ) )
95 5 : m_nRelation = pVertRelations[i];
96 : }
97 : }
98 5 : 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 25 : for ( int i = 0; i < 4; i++ )
119 : {
120 20 : if ( pHoriRelValues[i] == sal_uInt32( nIntValue ) )
121 5 : m_nRelation = pHoriRelations[i];
122 : }
123 : }
124 5 : break;
125 : default:
126 : #ifdef DEBUG_DOMAINMAPPER
127 : dmapper_logger->element("unhandled");
128 : #endif
129 0 : break;
130 : }
131 10 : }
132 :
133 10 : void PositionHandler::lcl_sprm( Sprm& )
134 : {
135 10 : }
136 :
137 16 : sal_Int16 PositionHandler::orientation() const
138 : {
139 16 : if( m_nRelation == text::RelOrientation::TEXT_LINE )
140 : { // It appears that to 'line of text' alignment is backwards to other alignments,
141 : // 'top' meaning putting on top of the line instead of having top at the line.
142 3 : if( m_nOrient == text::VertOrientation::TOP )
143 0 : return text::VertOrientation::BOTTOM;
144 3 : else if( m_nOrient == text::VertOrientation::BOTTOM )
145 0 : return text::VertOrientation::TOP;
146 : }
147 16 : return m_nOrient;
148 : }
149 :
150 16 : sal_Int16 PositionHandler::relation() const
151 : {
152 16 : return m_nRelation;
153 : }
154 :
155 16 : sal_Int32 PositionHandler::position() const
156 : {
157 16 : return m_nPosition;
158 : }
159 :
160 14 : void PositionHandler::setPositionOffset(const OUString & sText, bool vertical)
161 : {
162 14 : if( vertical )
163 7 : savedPositionOffsetV = ConversionHelper::convertEMUToMM100( sText.toInt32());
164 : else
165 7 : savedPositionOffsetH = ConversionHelper::convertEMUToMM100( sText.toInt32());
166 14 : }
167 :
168 1 : void PositionHandler::setAlignH(const OUString & sText)
169 : {
170 1 : if( sText == "left")
171 0 : savedAlignH = text::HoriOrientation::LEFT;
172 1 : else if( sText == "right" )
173 0 : savedAlignH = text::HoriOrientation::RIGHT;
174 1 : else if( sText == "center" )
175 1 : savedAlignH = text::HoriOrientation::CENTER;
176 0 : else if( sText == "inside" )
177 0 : savedAlignH = text::HoriOrientation::INSIDE;
178 0 : else if( sText == "outside" )
179 0 : savedAlignH = text::HoriOrientation::OUTSIDE;
180 1 : }
181 :
182 1 : void PositionHandler::setAlignV(const OUString & sText)
183 : {
184 1 : if( sText == "top" )
185 1 : savedAlignV = text::VertOrientation::TOP;
186 0 : else if( sText == "bottom" )
187 0 : savedAlignV = text::VertOrientation::BOTTOM;
188 0 : else if( sText == "center" )
189 0 : savedAlignV = text::VertOrientation::CENTER;
190 0 : else if( sText == "inside" )
191 0 : savedAlignV = text::VertOrientation::NONE;
192 0 : else if( sText == "outside" )
193 0 : savedAlignV = text::VertOrientation::NONE;
194 1 : }
195 :
196 13 : WrapHandler::WrapHandler( ) :
197 : LoggedProperties(dmapper_logger, "WrapHandler"),
198 : m_nType( 0 ),
199 13 : m_nSide( 0 )
200 : {
201 13 : }
202 :
203 26 : WrapHandler::~WrapHandler( )
204 : {
205 26 : }
206 :
207 19 : void WrapHandler::lcl_attribute( Id aName, Value& rVal )
208 : {
209 19 : switch ( aName )
210 : {
211 : case NS_ooxml::LN_CT_Wrap_type:
212 9 : m_nType = sal_Int32( rVal.getInt( ) );
213 9 : break;
214 : case NS_ooxml::LN_CT_Wrap_side:
215 0 : m_nSide = sal_Int32( rVal.getInt( ) );
216 0 : break;
217 : default:;
218 : }
219 19 : }
220 :
221 0 : void WrapHandler::lcl_sprm( Sprm& )
222 : {
223 0 : }
224 :
225 13 : sal_Int32 WrapHandler::getWrapMode( )
226 : {
227 : // The wrap values do not map directly to our wrap mode,
228 : // e.g. none in .docx actually means through in LO.
229 13 : sal_Int32 nMode = com::sun::star::text::WrapTextMode_THROUGHT;
230 :
231 13 : switch ( m_nType )
232 : {
233 : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_square:
234 : // through and tight are somewhat complicated, approximate
235 : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_tight:
236 : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_through:
237 : {
238 9 : switch ( m_nSide )
239 : {
240 : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_left:
241 0 : nMode = com::sun::star::text::WrapTextMode_LEFT;
242 0 : break;
243 : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_right:
244 0 : nMode = com::sun::star::text::WrapTextMode_RIGHT;
245 0 : break;
246 : default:
247 9 : nMode = com::sun::star::text::WrapTextMode_PARALLEL;
248 : }
249 : }
250 9 : break;
251 : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_topAndBottom:
252 0 : nMode = com::sun::star::text::WrapTextMode_NONE;
253 0 : break;
254 : case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_none:
255 : default:
256 4 : nMode = com::sun::star::text::WrapTextMode_THROUGHT;
257 : }
258 :
259 13 : return nMode;
260 : }
261 :
262 :
263 47 : void GraphicZOrderHelper::addItem( uno::Reference< beans::XPropertySet > props, sal_Int32 relativeHeight )
264 : {
265 47 : items[ relativeHeight ] = props;
266 47 : }
267 :
268 : // The relativeHeight value in .docx is an arbitrary number, where only the relative ordering matters.
269 : // But in Writer, the z-order is index in 0..(numitems-1) range, so whenever a new item needs to be
270 : // added in the proper z-order, it is necessary to find the proper index.
271 47 : sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight )
272 : {
273 47 : Items::const_iterator it = items.begin();
274 101 : while( it != items.end())
275 : {
276 : // std::map is iterated sorted by key
277 : // if there is an item that has the same z-order, we belong under it
278 25 : if( it->first >= relativeHeight )
279 18 : break; // this is the first one higher, we belong right before it
280 : else
281 7 : ++it;
282 : }
283 47 : if( it == items.end()) // we're topmost
284 : {
285 29 : if( items.empty())
286 53 : return 0;
287 5 : sal_Int32 itemZOrder(0);
288 5 : --it;
289 20 : if( it->second->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
290 15 : .GetName( PROP_Z_ORDER )) >>= itemZOrder )
291 5 : return itemZOrder + 1; // after the topmost
292 : }
293 : else
294 : {
295 18 : sal_Int32 itemZOrder(0);
296 72 : if( it->second->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
297 54 : .GetName( PROP_Z_ORDER )) >>= itemZOrder )
298 18 : return itemZOrder; // before the item
299 : }
300 : SAL_WARN( "writerfilter", "findZOrder() didn't find item z-order" );
301 0 : return 0; // this should not(?) happen
302 : }
303 :
304 24 : } }
305 :
306 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|