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 void PositionHandler::setPositionOffset(const OUString
& sText
, bool vertical
)
140 savedPositionOffsetV
= ConversionHelper::convertEMUToMM100( sText
.toInt32());
142 savedPositionOffsetH
= ConversionHelper::convertEMUToMM100( sText
.toInt32());
145 void PositionHandler::setAlignH(const OUString
& sText
)
148 savedAlignH
= text::HoriOrientation::LEFT
;
149 else if( sText
== "right" )
150 savedAlignH
= text::HoriOrientation::RIGHT
;
151 else if( sText
== "center" )
152 savedAlignH
= text::HoriOrientation::CENTER
;
153 else if( sText
== "inside" )
154 savedAlignH
= text::HoriOrientation::INSIDE
;
155 else if( sText
== "outside" )
156 savedAlignH
= text::HoriOrientation::OUTSIDE
;
159 void PositionHandler::setAlignV(const OUString
& sText
)
162 savedAlignV
= text::VertOrientation::TOP
;
163 else if( sText
== "bottom" )
164 savedAlignV
= text::VertOrientation::BOTTOM
;
165 else if( sText
== "center" )
166 savedAlignV
= text::VertOrientation::CENTER
;
167 else if( sText
== "inside" )
168 savedAlignV
= text::VertOrientation::NONE
;
169 else if( sText
== "outside" )
170 savedAlignV
= text::VertOrientation::NONE
;
173 WrapHandler::WrapHandler( ) :
174 LoggedProperties(dmapper_logger
, "WrapHandler"),
180 WrapHandler::~WrapHandler( )
184 void WrapHandler::lcl_attribute( Id aName
, Value
& rVal
)
188 case NS_ooxml::LN_CT_Wrap_type
:
189 m_nType
= sal_Int32( rVal
.getInt( ) );
191 case NS_ooxml::LN_CT_Wrap_side
:
192 m_nSide
= sal_Int32( rVal
.getInt( ) );
198 void WrapHandler::lcl_sprm( Sprm
& )
202 sal_Int32
WrapHandler::getWrapMode( )
204 // The wrap values do not map directly to our wrap mode,
205 // e.g. none in .docx actually means through in LO.
206 sal_Int32 nMode
= com::sun::star::text::WrapTextMode_THROUGHT
;
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
:
217 case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_left
:
218 nMode
= com::sun::star::text::WrapTextMode_LEFT
;
220 case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_right
:
221 nMode
= com::sun::star::text::WrapTextMode_RIGHT
;
224 nMode
= com::sun::star::text::WrapTextMode_PARALLEL
;
228 case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_topAndBottom
:
229 nMode
= com::sun::star::text::WrapTextMode_NONE
;
231 case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_none
:
233 nMode
= com::sun::star::text::WrapTextMode_THROUGHT
;
240 void GraphicZOrderHelper::addItem( uno::Reference
< beans::XPropertySet
> props
, sal_Int32 relativeHeight
)
242 items
[ relativeHeight
] = props
;
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 sal_Int32
GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight
)
250 Items::const_iterator it
= items
.begin();
251 while( it
!= items
.end())
253 // std::map is iterated sorted by key
254 // if there is an item that has the same z-order, we belong under it
255 if( it
->first
>= relativeHeight
)
256 break; // this is the first one higher, we belong right before it
260 if( it
== items
.end()) // we're topmost
264 sal_Int32
itemZOrder(0);
266 if( it
->second
->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
267 .GetName( PROP_Z_ORDER
)) >>= itemZOrder
)
268 return itemZOrder
+ 1; // after the topmost
272 sal_Int32
itemZOrder(0);
273 if( it
->second
->getPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier()
274 .GetName( PROP_Z_ORDER
)) >>= itemZOrder
)
275 return itemZOrder
; // before the item
277 SAL_WARN( "writerfilter", "findZOrder() didn't find item z-order" );
278 return 0; // this should not(?) happen
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */