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