1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "ConversionHelper.hxx"
20 #include "GraphicHelpers.hxx"
22 #include <ooxml/resourceids.hxx>
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>
29 #include "dmapperLoggers.hxx"
34 namespace writerfilter
{
37 using namespace com::sun::star
;
39 int PositionHandler::savedPositionOffsetV
= 0;
40 int PositionHandler::savedPositionOffsetH
= 0;
41 int PositionHandler::savedAlignV
= text::VertOrientation::NONE
;
42 int PositionHandler::savedAlignH
= text::HoriOrientation::NONE
;
44 PositionHandler::PositionHandler( bool vertical
) :
45 LoggedProperties(dmapper_logger
, "PositionHandler")
47 m_nRelation
= text::RelOrientation::FRAME
;
50 m_nPosition
= savedPositionOffsetV
;
51 m_nOrient
= savedAlignV
;
52 savedPositionOffsetV
= 0;
53 savedAlignV
= text::VertOrientation::NONE
;
57 m_nPosition
= savedPositionOffsetH
;
58 m_nOrient
= savedAlignH
;
59 savedPositionOffsetH
= 0;
60 savedAlignH
= text::HoriOrientation::NONE
;
64 PositionHandler::~PositionHandler( )
68 void PositionHandler::lcl_attribute( Id aName
, Value
& rVal
)
70 sal_Int32 nIntValue
= rVal
.getInt( );
73 case NS_ooxml::LN_CT_PosV_relativeFrom
:
75 // TODO There are some other unhandled values
76 static Id pVertRelValues
[] =
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
84 static sal_Int16 pVertRelations
[] =
86 text::RelOrientation::PAGE_PRINT_AREA
,
87 text::RelOrientation::PAGE_FRAME
,
88 text::RelOrientation::FRAME
,
89 text::RelOrientation::TEXT_LINE
92 for ( int i
= 0; i
< 4; i
++ )
94 if ( pVertRelValues
[i
] == sal_uInt32( nIntValue
) )
95 m_nRelation
= pVertRelations
[i
];
99 case NS_ooxml::LN_CT_PosH_relativeFrom
:
101 // TODO There are some other unhandled values
102 static Id pHoriRelValues
[] =
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
110 static sal_Int16 pHoriRelations
[] =
112 text::RelOrientation::PAGE_PRINT_AREA
,
113 text::RelOrientation::PAGE_FRAME
,
114 text::RelOrientation::FRAME
,
115 text::RelOrientation::CHAR
,
118 for ( int i
= 0; i
< 4; i
++ )
120 if ( pHoriRelValues
[i
] == sal_uInt32( nIntValue
) )
121 m_nRelation
= pHoriRelations
[i
];
126 #ifdef DEBUG_DOMAINMAPPER
127 dmapper_logger
->element("unhandled");
133 void PositionHandler::lcl_sprm( Sprm
& )
137 sal_Int16
PositionHandler::orientation() const
139 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 if( m_nOrient
== text::VertOrientation::TOP
)
143 return text::VertOrientation::BOTTOM
;
144 else if( m_nOrient
== text::VertOrientation::BOTTOM
)
145 return text::VertOrientation::TOP
;
150 sal_Int16
PositionHandler::relation() const
155 sal_Int32
PositionHandler::position() const
160 void PositionHandler::setPositionOffset(const OUString
& sText
, bool vertical
)
163 savedPositionOffsetV
= ConversionHelper::convertEMUToMM100( sText
.toInt32());
165 savedPositionOffsetH
= ConversionHelper::convertEMUToMM100( sText
.toInt32());
168 void PositionHandler::setAlignH(const OUString
& sText
)
171 savedAlignH
= text::HoriOrientation::LEFT
;
172 else if( sText
== "right" )
173 savedAlignH
= text::HoriOrientation::RIGHT
;
174 else if( sText
== "center" )
175 savedAlignH
= text::HoriOrientation::CENTER
;
176 else if( sText
== "inside" )
177 savedAlignH
= text::HoriOrientation::INSIDE
;
178 else if( sText
== "outside" )
179 savedAlignH
= text::HoriOrientation::OUTSIDE
;
182 void PositionHandler::setAlignV(const OUString
& sText
)
185 savedAlignV
= text::VertOrientation::TOP
;
186 else if( sText
== "bottom" )
187 savedAlignV
= text::VertOrientation::BOTTOM
;
188 else if( sText
== "center" )
189 savedAlignV
= text::VertOrientation::CENTER
;
190 else if( sText
== "inside" )
191 savedAlignV
= text::VertOrientation::NONE
;
192 else if( sText
== "outside" )
193 savedAlignV
= text::VertOrientation::NONE
;
196 WrapHandler::WrapHandler( ) :
197 LoggedProperties(dmapper_logger
, "WrapHandler"),
203 WrapHandler::~WrapHandler( )
207 void WrapHandler::lcl_attribute( Id aName
, Value
& rVal
)
211 case NS_ooxml::LN_CT_Wrap_type
:
212 m_nType
= sal_Int32( rVal
.getInt( ) );
214 case NS_ooxml::LN_CT_Wrap_side
:
215 m_nSide
= sal_Int32( rVal
.getInt( ) );
221 void WrapHandler::lcl_sprm( Sprm
& )
225 sal_Int32
WrapHandler::getWrapMode( )
227 // The wrap values do not map directly to our wrap mode,
228 // e.g. none in .docx actually means through in LO.
229 sal_Int32 nMode
= com::sun::star::text::WrapTextMode_THROUGHT
;
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
:
240 case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_left
:
241 nMode
= com::sun::star::text::WrapTextMode_LEFT
;
243 case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_right
:
244 nMode
= com::sun::star::text::WrapTextMode_RIGHT
;
247 nMode
= com::sun::star::text::WrapTextMode_PARALLEL
;
251 case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_topAndBottom
:
252 nMode
= com::sun::star::text::WrapTextMode_NONE
;
254 case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_none
:
256 nMode
= com::sun::star::text::WrapTextMode_THROUGHT
;
263 void GraphicZOrderHelper::addItem( uno::Reference
< beans::XPropertySet
> props
, sal_Int32 relativeHeight
)
265 items
[ relativeHeight
] = props
;
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 sal_Int32
GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight
)
273 Items::const_iterator it
= items
.begin();
274 while( it
!= items
.end())
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 if( it
->first
>= relativeHeight
)
279 break; // this is the first one higher, we belong right before it
283 if( it
== items
.end()) // we're topmost
287 sal_Int32
itemZOrder(0);
289 if( it
->second
->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
290 .GetName( PROP_Z_ORDER
)) >>= itemZOrder
)
291 return itemZOrder
+ 1; // after the topmost
295 sal_Int32
itemZOrder(0);
296 if( it
->second
->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
297 .GetName( PROP_Z_ORDER
)) >>= itemZOrder
)
298 return itemZOrder
; // before the item
300 SAL_WARN( "writerfilter", "findZOrder() didn't find item z-order" );
301 return 0; // this should not(?) happen
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */