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 :
20 : #include <oox/export/vmlexport.hxx>
21 :
22 : #include <oox/token/tokens.hxx>
23 :
24 : #include <rtl/strbuf.hxx>
25 : #include <rtl/ustring.hxx>
26 :
27 : #include <tools/stream.hxx>
28 : #include <svx/svdotext.hxx>
29 : #include <vcl/cvtgrf.hxx>
30 :
31 : #include <cstdio>
32 :
33 :
34 : using namespace sax_fastparser;
35 : using namespace oox::vml;
36 :
37 24 : VMLExport::VMLExport( ::sax_fastparser::FSHelperPtr pSerializer, VMLTextExport* pTextExport )
38 24 : : EscherEx( EscherExGlobalRef(new EscherExGlobal(0)), 0 ),
39 : m_pSerializer( pSerializer ),
40 : m_pTextExport( pTextExport ),
41 : m_pSdrObject( 0 ),
42 : m_pShapeAttrList( NULL ),
43 : m_nShapeType( ESCHER_ShpInst_Nil ),
44 24 : m_pShapeStyle( new OStringBuffer( 200 ) ),
45 72 : m_pShapeTypeWritten( new bool[ ESCHER_ShpInst_COUNT ] )
46 : {
47 24 : mnGroupLevel = 1;
48 24 : memset( m_pShapeTypeWritten, 0, ESCHER_ShpInst_COUNT * sizeof( bool ) );
49 24 : }
50 :
51 72 : VMLExport::~VMLExport()
52 : {
53 24 : delete mpOutStrm, mpOutStrm = NULL;
54 24 : delete m_pShapeStyle, m_pShapeStyle = NULL;
55 24 : delete[] m_pShapeTypeWritten, m_pShapeTypeWritten = NULL;
56 48 : }
57 :
58 0 : void VMLExport::OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance )
59 : {
60 0 : EscherEx::OpenContainer( nEscherContainer, nRecInstance );
61 :
62 0 : if ( nEscherContainer == ESCHER_SpContainer )
63 : {
64 : // opening a shape container
65 : #if OSL_DEBUG_LEVEL > 0
66 : if ( m_nShapeType != ESCHER_ShpInst_Nil )
67 : fprintf( stderr, "Warning! VMLExport::OpenContainer(): opening shape inside a shape.\n" );
68 : #endif
69 0 : m_nShapeType = ESCHER_ShpInst_Nil;
70 0 : m_pShapeAttrList = m_pSerializer->createAttrList();
71 :
72 0 : if ( m_pShapeStyle->getLength() )
73 0 : m_pShapeStyle->makeStringAndClear();
74 :
75 0 : m_pShapeStyle->ensureCapacity( 200 );
76 :
77 : // postpone the output so that we are able to write even the elements
78 : // that we learn inside Commit()
79 0 : m_pSerializer->mark();
80 : }
81 0 : }
82 :
83 0 : void VMLExport::CloseContainer()
84 : {
85 0 : if ( mRecTypes.back() == ESCHER_SpContainer )
86 : {
87 : // write the shape now when we have all the info
88 0 : sal_Int32 nShapeElement = StartShape();
89 :
90 0 : m_pSerializer->mergeTopMarks();
91 :
92 0 : EndShape( nShapeElement );
93 :
94 : // cleanup
95 0 : m_nShapeType = ESCHER_ShpInst_Nil;
96 0 : m_pShapeAttrList = NULL;
97 : }
98 :
99 0 : EscherEx::CloseContainer();
100 0 : }
101 :
102 0 : sal_uInt32 VMLExport::EnterGroup( const String& rShapeName, const Rectangle* pRect )
103 : {
104 0 : sal_uInt32 nShapeId = GenerateShapeId();
105 :
106 0 : OStringBuffer aStyle( 200 );
107 0 : FastAttributeList *pAttrList = m_pSerializer->createAttrList();
108 :
109 0 : pAttrList->add( XML_id, ShapeIdString( nShapeId ) );
110 :
111 0 : if ( rShapeName.Len() )
112 0 : pAttrList->add( XML_alt, OUStringToOString( OUString( rShapeName ), RTL_TEXTENCODING_UTF8 ) );
113 :
114 : // style
115 0 : if ( pRect )
116 0 : AddRectangleDimensions( aStyle, *pRect );
117 :
118 0 : if ( aStyle.getLength() )
119 0 : pAttrList->add( XML_style, aStyle.makeStringAndClear() );
120 :
121 : // coordorigin/coordsize
122 0 : if ( pRect && ( mnGroupLevel == 1 ) )
123 : {
124 : pAttrList->add( XML_coordorigin,
125 0 : OStringBuffer( 20 ).append( sal_Int32( pRect->Left() ) )
126 0 : .append( "," ).append( sal_Int32( pRect->Top() ) )
127 0 : .makeStringAndClear() );
128 :
129 : pAttrList->add( XML_coordsize,
130 0 : OStringBuffer( 20 ).append( sal_Int32( pRect->Right() ) - sal_Int32( pRect->Left() ) )
131 0 : .append( "," ).append( sal_Int32( pRect->Bottom() ) - sal_Int32( pRect->Top() ) )
132 0 : .makeStringAndClear() );
133 : }
134 :
135 0 : m_pSerializer->startElementNS( XML_v, XML_group, XFastAttributeListRef( pAttrList ) );
136 :
137 0 : mnGroupLevel++;
138 0 : return nShapeId;
139 : }
140 :
141 0 : void VMLExport::LeaveGroup()
142 : {
143 0 : --mnGroupLevel;
144 0 : m_pSerializer->endElementNS( XML_v, XML_group );
145 0 : }
146 :
147 0 : void VMLExport::AddShape( sal_uInt32 nShapeType, sal_uInt32 nShapeFlags, sal_uInt32 nShapeId )
148 : {
149 0 : m_nShapeType = nShapeType;
150 0 : m_nShapeFlags = nShapeFlags;
151 :
152 0 : m_pShapeAttrList->add( XML_id, ShapeIdString( nShapeId ) );
153 0 : }
154 :
155 0 : static void impl_AddArrowHead( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nValue )
156 : {
157 0 : if ( !pAttrList )
158 0 : return;
159 :
160 0 : const char *pArrowHead = NULL;
161 0 : switch ( nValue )
162 : {
163 0 : case ESCHER_LineNoEnd: pArrowHead = "none"; break;
164 0 : case ESCHER_LineArrowEnd: pArrowHead = "block"; break;
165 0 : case ESCHER_LineArrowStealthEnd: pArrowHead = "classic"; break;
166 0 : case ESCHER_LineArrowDiamondEnd: pArrowHead = "diamond"; break;
167 0 : case ESCHER_LineArrowOvalEnd: pArrowHead = "oval"; break;
168 0 : case ESCHER_LineArrowOpenEnd: pArrowHead = "open"; break;
169 : }
170 :
171 0 : if ( pArrowHead )
172 0 : pAttrList->add( nElement, pArrowHead );
173 : }
174 :
175 0 : static void impl_AddArrowLength( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nValue )
176 : {
177 0 : if ( !pAttrList )
178 0 : return;
179 :
180 0 : const char *pArrowLength = NULL;
181 0 : switch ( nValue )
182 : {
183 0 : case ESCHER_LineShortArrow: pArrowLength = "short"; break;
184 0 : case ESCHER_LineMediumLenArrow: pArrowLength = "medium"; break;
185 0 : case ESCHER_LineLongArrow: pArrowLength = "long"; break;
186 : }
187 :
188 0 : if ( pArrowLength )
189 0 : pAttrList->add( nElement, pArrowLength );
190 : }
191 :
192 0 : static void impl_AddArrowWidth( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nValue )
193 : {
194 0 : if ( !pAttrList )
195 0 : return;
196 :
197 0 : const char *pArrowWidth = NULL;
198 0 : switch ( nValue )
199 : {
200 0 : case ESCHER_LineNarrowArrow: pArrowWidth = "narrow"; break;
201 0 : case ESCHER_LineMediumWidthArrow: pArrowWidth = "medium"; break;
202 0 : case ESCHER_LineWideArrow: pArrowWidth = "wide"; break;
203 : }
204 :
205 0 : if ( pArrowWidth )
206 0 : pAttrList->add( nElement, pArrowWidth );
207 : }
208 :
209 0 : static void impl_AddBool( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, bool bValue )
210 : {
211 0 : if ( !pAttrList )
212 0 : return;
213 :
214 0 : pAttrList->add( nElement, bValue? "t": "f" );
215 : }
216 :
217 0 : static void impl_AddColor( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nColor )
218 : {
219 : #if OSL_DEBUG_LEVEL > 0
220 : if ( nColor & 0xFF000000 )
221 : fprintf( stderr, "TODO: this is not a RGB value!\n" );
222 : #endif
223 :
224 0 : if ( !pAttrList || ( nColor & 0xFF000000 ) )
225 0 : return;
226 :
227 0 : nColor = ( ( nColor & 0xFF ) << 16 ) + ( nColor & 0xFF00 ) + ( ( nColor & 0xFF0000 ) >> 16 );
228 :
229 0 : const char *pColor = NULL;
230 : char pRgbColor[10];
231 0 : switch ( nColor )
232 : {
233 0 : case 0x000000: pColor = "black"; break;
234 0 : case 0xC0C0C0: pColor = "silver"; break;
235 0 : case 0x808080: pColor = "gray"; break;
236 0 : case 0xFFFFFF: pColor = "white"; break;
237 0 : case 0x800000: pColor = "maroon"; break;
238 0 : case 0xFF0000: pColor = "red"; break;
239 0 : case 0x800080: pColor = "purple"; break;
240 0 : case 0xFF00FF: pColor = "fuchsia"; break;
241 0 : case 0x008000: pColor = "green"; break;
242 0 : case 0x00FF00: pColor = "lime"; break;
243 0 : case 0x808000: pColor = "olive"; break;
244 0 : case 0xFFFF00: pColor = "yellow"; break;
245 0 : case 0x000080: pColor = "navy"; break;
246 0 : case 0x0000FF: pColor = "blue"; break;
247 0 : case 0x008080: pColor = "teal"; break;
248 0 : case 0x00FFFF: pColor = "aqua"; break;
249 : default:
250 : {
251 0 : snprintf( pRgbColor, sizeof( pRgbColor ), "#%06x", static_cast< unsigned int >( nColor ) ); // not too handy to use OString::valueOf() here :-(
252 0 : pColor = pRgbColor;
253 : }
254 0 : break;
255 : }
256 :
257 0 : pAttrList->add( nElement, pColor );
258 : }
259 :
260 0 : static void impl_AddInt( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nValue )
261 : {
262 0 : if ( !pAttrList )
263 0 : return;
264 :
265 0 : pAttrList->add( nElement, OString::valueOf( static_cast< sal_Int32 >( nValue ) ).getStr() );
266 : }
267 :
268 0 : inline sal_uInt16 impl_GetUInt16( const sal_uInt8* &pVal )
269 : {
270 0 : sal_uInt16 nRet = *pVal++;
271 0 : nRet += ( *pVal++ ) << 8;
272 0 : return nRet;
273 : }
274 :
275 0 : inline sal_Int32 impl_GetPointComponent( const sal_uInt8* &pVal, sal_uInt16 nPointSize )
276 : {
277 0 : sal_Int32 nRet = 0;
278 0 : if ( ( nPointSize == 0xfff0 ) || ( nPointSize == 4 ) )
279 : {
280 0 : sal_uInt16 nUnsigned = *pVal++;
281 0 : nUnsigned += ( *pVal++ ) << 8;
282 :
283 0 : nRet = sal_Int16( nUnsigned );
284 : }
285 0 : else if ( nPointSize == 8 )
286 : {
287 0 : sal_uInt32 nUnsigned = *pVal++;
288 0 : nUnsigned += ( *pVal++ ) << 8;
289 0 : nUnsigned += ( *pVal++ ) << 16;
290 0 : nUnsigned += ( *pVal++ ) << 24;
291 :
292 0 : nRet = nUnsigned;
293 : }
294 :
295 0 : return nRet;
296 : }
297 :
298 0 : void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect )
299 : {
300 0 : if ( m_nShapeType == ESCHER_ShpInst_Nil )
301 0 : return;
302 :
303 : // postpone the output of the embedded elements so that they are written
304 : // inside the shapes
305 0 : m_pSerializer->mark();
306 :
307 : // dimensions
308 0 : if ( m_nShapeType == ESCHER_ShpInst_Line )
309 0 : AddLineDimensions( rRect );
310 : else
311 0 : AddRectangleDimensions( *m_pShapeStyle, rRect );
312 :
313 : // properties
314 : bool bAlreadyWritten[ 0xFFF ];
315 0 : memset( bAlreadyWritten, 0, sizeof( bAlreadyWritten ) );
316 0 : const EscherProperties &rOpts = rProps.GetOpts();
317 0 : for ( EscherProperties::const_iterator it = rOpts.begin(); it != rOpts.end(); ++it )
318 : {
319 0 : sal_uInt16 nId = ( it->nPropId & 0x0FFF );
320 :
321 0 : if ( bAlreadyWritten[ nId ] )
322 0 : continue;
323 :
324 0 : switch ( nId )
325 : {
326 : case ESCHER_Prop_WrapText: // 133
327 : {
328 0 : const char *pWrapType = NULL;
329 0 : switch ( it->nPropValue )
330 : {
331 : case ESCHER_WrapSquare:
332 0 : case ESCHER_WrapByPoints: pWrapType = "square"; break; // these two are equivalent according to the docu
333 0 : case ESCHER_WrapNone: pWrapType = "none"; break;
334 0 : case ESCHER_WrapTopBottom: pWrapType = "topAndBottom"; break;
335 0 : case ESCHER_WrapThrough: pWrapType = "through"; break;
336 : }
337 0 : if ( pWrapType )
338 : m_pSerializer->singleElementNS( XML_v, XML_wrap,
339 : FSNS( XML_v, XML_type ), pWrapType,
340 0 : FSEND );
341 : }
342 0 : bAlreadyWritten[ ESCHER_Prop_WrapText ] = true;
343 0 : break;
344 :
345 : // coordorigin
346 : case ESCHER_Prop_geoLeft: // 320
347 : case ESCHER_Prop_geoTop: // 321
348 : {
349 0 : sal_uInt32 nLeft = 0, nTop = 0;
350 :
351 0 : if ( nId == ESCHER_Prop_geoLeft )
352 : {
353 0 : nLeft = it->nPropValue;
354 0 : rProps.GetOpt( ESCHER_Prop_geoTop, nTop );
355 : }
356 : else
357 : {
358 0 : nTop = it->nPropValue;
359 0 : rProps.GetOpt( ESCHER_Prop_geoLeft, nLeft );
360 : }
361 :
362 : m_pShapeAttrList->add( XML_coordorigin,
363 0 : OStringBuffer( 20 ).append( sal_Int32( nLeft ) )
364 0 : .append( "," ).append( sal_Int32( nTop ) )
365 0 : .makeStringAndClear() );
366 : }
367 0 : bAlreadyWritten[ ESCHER_Prop_geoLeft ] = true;
368 0 : bAlreadyWritten[ ESCHER_Prop_geoTop ] = true;
369 0 : break;
370 :
371 : // coordsize
372 : case ESCHER_Prop_geoRight: // 322
373 : case ESCHER_Prop_geoBottom: // 323
374 : {
375 0 : sal_uInt32 nLeft = 0, nRight = 0, nTop = 0, nBottom = 0;
376 0 : rProps.GetOpt( ESCHER_Prop_geoLeft, nLeft );
377 0 : rProps.GetOpt( ESCHER_Prop_geoTop, nTop );
378 :
379 0 : if ( nId == ESCHER_Prop_geoRight )
380 : {
381 0 : nRight = it->nPropValue;
382 0 : rProps.GetOpt( ESCHER_Prop_geoBottom, nBottom );
383 : }
384 : else
385 : {
386 0 : nBottom = it->nPropValue;
387 0 : rProps.GetOpt( ESCHER_Prop_geoRight, nRight );
388 : }
389 :
390 : m_pShapeAttrList->add( XML_coordsize,
391 0 : OStringBuffer( 20 ).append( sal_Int32( nRight ) - sal_Int32( nLeft ) )
392 0 : .append( "," ).append( sal_Int32( nBottom ) - sal_Int32( nTop ) )
393 0 : .makeStringAndClear() );
394 : }
395 0 : bAlreadyWritten[ ESCHER_Prop_geoRight ] = true;
396 0 : bAlreadyWritten[ ESCHER_Prop_geoBottom ] = true;
397 0 : break;
398 :
399 : case ESCHER_Prop_pVertices: // 325
400 : case ESCHER_Prop_pSegmentInfo: // 326
401 : {
402 : EscherPropSortStruct aVertices;
403 : EscherPropSortStruct aSegments;
404 :
405 0 : if ( rProps.GetOpt( ESCHER_Prop_pVertices, aVertices ) &&
406 0 : rProps.GetOpt( ESCHER_Prop_pSegmentInfo, aSegments ) )
407 : {
408 0 : const sal_uInt8 *pVerticesIt = aVertices.pBuf + 6;
409 0 : const sal_uInt8 *pSegmentIt = aSegments.pBuf;
410 0 : OStringBuffer aPath( 512 );
411 :
412 0 : sal_uInt16 nPointSize = aVertices.pBuf[4] + ( aVertices.pBuf[5] << 8 );
413 :
414 : // number of segments
415 0 : sal_uInt16 nSegments = impl_GetUInt16( pSegmentIt );
416 0 : pSegmentIt += 4;
417 :
418 0 : for ( ; nSegments; --nSegments )
419 : {
420 0 : sal_uInt16 nSeg = impl_GetUInt16( pSegmentIt );
421 0 : switch ( nSeg )
422 : {
423 : case 0x4000: // moveto
424 : {
425 0 : sal_Int32 nX = impl_GetPointComponent( pVerticesIt, nPointSize );
426 0 : sal_Int32 nY = impl_GetPointComponent( pVerticesIt, nPointSize );
427 0 : aPath.append( "m" ).append( nX ).append( "," ).append( nY );
428 : }
429 0 : break;
430 : case 0xb300:
431 : case 0xac00:
432 0 : break;
433 : case 0x0001: // lineto
434 : {
435 0 : sal_Int32 nX = impl_GetPointComponent( pVerticesIt, nPointSize );
436 0 : sal_Int32 nY = impl_GetPointComponent( pVerticesIt, nPointSize );
437 0 : aPath.append( "l" ).append( nX ).append( "," ).append( nY );
438 : }
439 0 : break;
440 : case 0x2001: // curveto
441 : {
442 0 : sal_Int32 nX1 = impl_GetPointComponent( pVerticesIt, nPointSize );
443 0 : sal_Int32 nY1 = impl_GetPointComponent( pVerticesIt, nPointSize );
444 0 : sal_Int32 nX2 = impl_GetPointComponent( pVerticesIt, nPointSize );
445 0 : sal_Int32 nY2 = impl_GetPointComponent( pVerticesIt, nPointSize );
446 0 : sal_Int32 nX3 = impl_GetPointComponent( pVerticesIt, nPointSize );
447 0 : sal_Int32 nY3 = impl_GetPointComponent( pVerticesIt, nPointSize );
448 0 : aPath.append( "c" ).append( nX1 ).append( "," ).append( nY1 ).append( "," )
449 0 : .append( nX2 ).append( "," ).append( nY2 ).append( "," )
450 0 : .append( nX3 ).append( "," ).append( nY3 );
451 : }
452 0 : break;
453 : case 0xaa00: // nofill
454 0 : aPath.append( "nf" );
455 0 : break;
456 : case 0xab00: // nostroke
457 0 : aPath.append( "ns" );
458 0 : break;
459 : case 0x6001: // close
460 0 : aPath.append( "x" );
461 0 : break;
462 : case 0x8000: // end
463 0 : aPath.append( "e" );
464 0 : break;
465 : default:
466 : // See EscherPropertyContainer::CreateCustomShapeProperties, by default nSeg is simply the number of points.
467 0 : for (int i = 0; i < nSeg; ++i)
468 : {
469 0 : sal_Int32 nX = impl_GetPointComponent(pVerticesIt, nPointSize);
470 0 : sal_Int32 nY = impl_GetPointComponent(pVerticesIt, nPointSize);
471 0 : aPath.append("l").append(nX).append(",").append(nY);
472 : }
473 0 : break;
474 : }
475 : }
476 :
477 0 : if ( aPath.getLength() )
478 0 : m_pShapeAttrList->add( XML_path, aPath.getStr() );
479 : }
480 : #if OSL_DEBUG_LEVEL > 0
481 : else
482 : fprintf( stderr, "TODO: unhandled shape path, missing either pVertices or pSegmentInfo.\n" );
483 : #endif
484 : }
485 0 : bAlreadyWritten[ ESCHER_Prop_pVertices ] = true;
486 0 : bAlreadyWritten[ ESCHER_Prop_pSegmentInfo ] = true;
487 0 : break;
488 :
489 : case ESCHER_Prop_fillType: // 384
490 : case ESCHER_Prop_fillColor: // 385
491 : case ESCHER_Prop_fillBackColor: // 387
492 : case ESCHER_Prop_fillBlip: // 390
493 : case ESCHER_Prop_fNoFillHitTest: // 447
494 : {
495 : sal_uInt32 nValue;
496 0 : sax_fastparser::FastAttributeList *pAttrList = m_pSerializer->createAttrList();
497 :
498 0 : if ( rProps.GetOpt( ESCHER_Prop_fillType, nValue ) )
499 : {
500 0 : const char *pFillType = NULL;
501 0 : switch ( nValue )
502 : {
503 0 : case ESCHER_FillSolid: pFillType = "solid"; break;
504 : // TODO case ESCHER_FillPattern: pFillType = ""; break;
505 0 : case ESCHER_FillTexture: pFillType = "tile"; break;
506 : // TODO case ESCHER_FillPicture: pFillType = ""; break;
507 : // TODO case ESCHER_FillShade: pFillType = ""; break;
508 : // TODO case ESCHER_FillShadeCenter: pFillType = ""; break;
509 : // TODO case ESCHER_FillShadeShape: pFillType = ""; break;
510 : // TODO case ESCHER_FillShadeScale: pFillType = ""; break;
511 : // TODO case ESCHER_FillShadeTitle: pFillType = ""; break;
512 : // TODO case ESCHER_FillBackground: pFillType = ""; break;
513 : default:
514 : #if OSL_DEBUG_LEVEL > 0
515 : fprintf( stderr, "TODO: unhandled fill type\n" );
516 : #endif
517 0 : break;
518 : }
519 0 : if ( pFillType )
520 0 : pAttrList->add( XML_type, pFillType );
521 : }
522 :
523 0 : if ( rProps.GetOpt( ESCHER_Prop_fillColor, nValue ) )
524 0 : impl_AddColor( m_pShapeAttrList, XML_fillcolor, nValue );
525 :
526 0 : if ( rProps.GetOpt( ESCHER_Prop_fillBackColor, nValue ) )
527 0 : impl_AddColor( pAttrList, XML_color2, nValue );
528 :
529 : EscherPropSortStruct aStruct;
530 0 : if ( rProps.GetOpt( ESCHER_Prop_fillBlip, aStruct ) && m_pTextExport)
531 : {
532 0 : SvMemoryStream aStream;
533 0 : int nHeaderSize = 25; // The first bytes are WW8-specific, we're only interested in the PNG
534 0 : aStream.Write(aStruct.pBuf + nHeaderSize, aStruct.nPropSize - nHeaderSize);
535 0 : aStream.Seek(0);
536 0 : Graphic aGraphic;
537 0 : GraphicConverter::Import(aStream, aGraphic, CVT_PNG);
538 0 : OUString aImageId = m_pTextExport->GetDrawingML().WriteImage( aGraphic );
539 0 : pAttrList->add(FSNS(XML_r, XML_id), OUStringToOString(aImageId, RTL_TEXTENCODING_UTF8));
540 : }
541 :
542 0 : if ( rProps.GetOpt( ESCHER_Prop_fNoFillHitTest, nValue ) )
543 0 : impl_AddBool( pAttrList, XML_detectmouseclick, nValue );
544 :
545 0 : m_pSerializer->singleElementNS( XML_v, XML_fill, XFastAttributeListRef( pAttrList ) );
546 : }
547 0 : bAlreadyWritten[ ESCHER_Prop_fillType ] = true;
548 0 : bAlreadyWritten[ ESCHER_Prop_fillColor ] = true;
549 0 : bAlreadyWritten[ ESCHER_Prop_fillBackColor ] = true;
550 0 : bAlreadyWritten[ ESCHER_Prop_fillBlip ] = true;
551 0 : bAlreadyWritten[ ESCHER_Prop_fNoFillHitTest ] = true;
552 0 : break;
553 :
554 : case ESCHER_Prop_lineColor: // 448
555 : case ESCHER_Prop_lineWidth: // 459
556 : case ESCHER_Prop_lineDashing: // 462
557 : case ESCHER_Prop_lineStartArrowhead: // 464
558 : case ESCHER_Prop_lineEndArrowhead: // 465
559 : case ESCHER_Prop_lineStartArrowWidth: // 466
560 : case ESCHER_Prop_lineStartArrowLength: // 467
561 : case ESCHER_Prop_lineEndArrowWidth: // 468
562 : case ESCHER_Prop_lineEndArrowLength: // 469
563 : case ESCHER_Prop_lineJoinStyle: // 470
564 : case ESCHER_Prop_lineEndCapStyle: // 471
565 : {
566 : sal_uInt32 nValue;
567 0 : sax_fastparser::FastAttributeList *pAttrList = m_pSerializer->createAttrList();
568 :
569 0 : if ( rProps.GetOpt( ESCHER_Prop_lineColor, nValue ) )
570 0 : impl_AddColor( pAttrList, XML_color, nValue );
571 :
572 0 : if ( rProps.GetOpt( ESCHER_Prop_lineWidth, nValue ) )
573 0 : impl_AddInt( pAttrList, XML_weight, nValue );
574 :
575 0 : if ( rProps.GetOpt( ESCHER_Prop_lineDashing, nValue ) )
576 : {
577 0 : const char *pDashStyle = NULL;
578 0 : switch ( nValue )
579 : {
580 0 : case ESCHER_LineSolid: pDashStyle = "solid"; break;
581 0 : case ESCHER_LineDashSys: pDashStyle = "shortdash"; break;
582 0 : case ESCHER_LineDotSys: pDashStyle = "shortdot"; break;
583 0 : case ESCHER_LineDashDotSys: pDashStyle = "shortdashdot"; break;
584 0 : case ESCHER_LineDashDotDotSys: pDashStyle = "shortdashdotdot"; break;
585 0 : case ESCHER_LineDotGEL: pDashStyle = "dot"; break;
586 0 : case ESCHER_LineDashGEL: pDashStyle = "dash"; break;
587 0 : case ESCHER_LineLongDashGEL: pDashStyle = "longdash"; break;
588 0 : case ESCHER_LineDashDotGEL: pDashStyle = "dashdot"; break;
589 0 : case ESCHER_LineLongDashDotGEL: pDashStyle = "longdashdot"; break;
590 0 : case ESCHER_LineLongDashDotDotGEL: pDashStyle = "longdashdotdot"; break;
591 : }
592 0 : if ( pDashStyle )
593 0 : pAttrList->add( XML_dashstyle, pDashStyle );
594 : }
595 :
596 0 : if ( rProps.GetOpt( ESCHER_Prop_lineStartArrowhead, nValue ) )
597 0 : impl_AddArrowHead( pAttrList, XML_startarrow, nValue );
598 :
599 0 : if ( rProps.GetOpt( ESCHER_Prop_lineEndArrowhead, nValue ) )
600 0 : impl_AddArrowHead( pAttrList, XML_endarrow, nValue );
601 :
602 0 : if ( rProps.GetOpt( ESCHER_Prop_lineStartArrowWidth, nValue ) )
603 0 : impl_AddArrowWidth( pAttrList, XML_startarrowwidth, nValue );
604 :
605 0 : if ( rProps.GetOpt( ESCHER_Prop_lineStartArrowLength, nValue ) )
606 0 : impl_AddArrowLength( pAttrList, XML_startarrowlength, nValue );
607 :
608 0 : if ( rProps.GetOpt( ESCHER_Prop_lineEndArrowWidth, nValue ) )
609 0 : impl_AddArrowWidth( pAttrList, XML_endarrowwidth, nValue );
610 :
611 0 : if ( rProps.GetOpt( ESCHER_Prop_lineEndArrowLength, nValue ) )
612 0 : impl_AddArrowLength( pAttrList, XML_endarrowlength, nValue );
613 :
614 0 : if ( rProps.GetOpt( ESCHER_Prop_lineJoinStyle, nValue ) )
615 : {
616 0 : const char *pJoinStyle = NULL;
617 0 : switch ( nValue )
618 : {
619 0 : case ESCHER_LineJoinBevel: pJoinStyle = "bevel"; break;
620 0 : case ESCHER_LineJoinMiter: pJoinStyle = "miter"; break;
621 0 : case ESCHER_LineJoinRound: pJoinStyle = "round"; break;
622 : }
623 0 : if ( pJoinStyle )
624 0 : pAttrList->add( XML_joinstyle, pJoinStyle );
625 : }
626 :
627 0 : if ( rProps.GetOpt( ESCHER_Prop_lineEndCapStyle, nValue ) )
628 : {
629 0 : const char *pEndCap = NULL;
630 0 : switch ( nValue )
631 : {
632 0 : case ESCHER_LineEndCapRound: pEndCap = "round"; break;
633 0 : case ESCHER_LineEndCapSquare: pEndCap = "square"; break;
634 0 : case ESCHER_LineEndCapFlat: pEndCap = "flat"; break;
635 : }
636 0 : if ( pEndCap )
637 0 : pAttrList->add( XML_endcap, pEndCap );
638 : }
639 :
640 0 : m_pSerializer->singleElementNS( XML_v, XML_stroke, XFastAttributeListRef( pAttrList ) );
641 : }
642 0 : bAlreadyWritten[ ESCHER_Prop_lineColor ] = true;
643 0 : bAlreadyWritten[ ESCHER_Prop_lineWidth ] = true;
644 0 : bAlreadyWritten[ ESCHER_Prop_lineDashing ] = true;
645 0 : bAlreadyWritten[ ESCHER_Prop_lineStartArrowhead ] = true;
646 0 : bAlreadyWritten[ ESCHER_Prop_lineEndArrowhead ] = true;
647 0 : bAlreadyWritten[ ESCHER_Prop_lineStartArrowWidth ] = true;
648 0 : bAlreadyWritten[ ESCHER_Prop_lineStartArrowLength ] = true;
649 0 : bAlreadyWritten[ ESCHER_Prop_lineEndArrowWidth ] = true;
650 0 : bAlreadyWritten[ ESCHER_Prop_lineEndArrowLength ] = true;
651 0 : bAlreadyWritten[ ESCHER_Prop_lineJoinStyle ] = true;
652 0 : bAlreadyWritten[ ESCHER_Prop_lineEndCapStyle ] = true;
653 0 : break;
654 :
655 : case ESCHER_Prop_fHidden:
656 0 : if ( !it->nPropValue )
657 0 : m_pShapeStyle->append( ";visibility:hidden" );
658 0 : break;
659 : case ESCHER_Prop_shadowColor:
660 : case ESCHER_Prop_fshadowObscured:
661 : {
662 0 : sal_uInt32 nValue = 0;
663 0 : bool bShadow = false;
664 0 : bool bObscured = false;
665 0 : if ( rProps.GetOpt( ESCHER_Prop_fshadowObscured, nValue ) )
666 : {
667 0 : bShadow = (( nValue & 0x20002 ) == 0x20002 );
668 0 : bObscured = (( nValue & 0x10001 ) == 0x10001 );
669 : }
670 0 : if ( bShadow )
671 : {
672 0 : sax_fastparser::FastAttributeList *pAttrList = m_pSerializer->createAttrList();
673 0 : impl_AddBool( pAttrList, XML_on, bShadow );
674 0 : impl_AddBool( pAttrList, XML_obscured, bObscured );
675 :
676 0 : if ( rProps.GetOpt( ESCHER_Prop_shadowColor, nValue ) )
677 0 : impl_AddColor( pAttrList, XML_color, nValue );
678 :
679 0 : m_pSerializer->singleElementNS( XML_v, XML_shadow, XFastAttributeListRef( pAttrList ) );
680 0 : bAlreadyWritten[ ESCHER_Prop_fshadowObscured ] = true;
681 0 : bAlreadyWritten[ ESCHER_Prop_shadowColor ] = true;
682 : }
683 : }
684 0 : break;
685 : default:
686 : #if OSL_DEBUG_LEVEL > 0
687 : fprintf( stderr, "TODO VMLExport::Commit(), unimplemented id: %d, value: %" SAL_PRIuUINT32 ", data: [%" SAL_PRIuUINT32 ", %p]\n",
688 : nId, it->nPropValue, it->nPropSize, it->pBuf );
689 : if ( it->nPropSize )
690 : {
691 : const sal_uInt8 *pIt = it->pBuf;
692 : fprintf( stderr, " ( " );
693 : for ( int nCount = it->nPropSize; nCount; --nCount )
694 : {
695 : fprintf( stderr, "%02x ", *pIt );
696 : ++pIt;
697 : }
698 : fprintf( stderr, ")\n" );
699 : }
700 : #endif
701 0 : break;
702 : }
703 : }
704 :
705 0 : m_pSerializer->mergeTopMarks( sax_fastparser::MERGE_MARKS_POSTPONE );
706 : }
707 :
708 0 : OString VMLExport::ShapeIdString( sal_uInt32 nId )
709 : {
710 0 : return OStringBuffer( 20 ).append( "shape_" ).append( sal_Int64( nId ) ).makeStringAndClear();
711 : }
712 :
713 0 : void VMLExport::AddLineDimensions( const Rectangle& rRectangle )
714 : {
715 : // style
716 0 : if ( m_pShapeStyle->getLength() )
717 0 : m_pShapeStyle->append( ";" );
718 :
719 0 : m_pShapeStyle->append( "position:absolute" );
720 :
721 0 : switch ( m_nShapeFlags & 0xC0 )
722 : {
723 0 : case 0x40: m_pShapeStyle->append( ";flip:y" ); break;
724 0 : case 0x80: m_pShapeStyle->append( ";flip:x" ); break;
725 0 : case 0xC0: m_pShapeStyle->append( ";flip:xy" ); break;
726 : }
727 :
728 : // the actual dimensions
729 0 : OString aLeft, aTop, aRight, aBottom;
730 :
731 0 : if ( mnGroupLevel == 1 )
732 : {
733 0 : const OString aPt( "pt" );
734 0 : aLeft = OString::valueOf( double( rRectangle.Left() ) / 20 ) + aPt;
735 0 : aTop = OString::valueOf( double( rRectangle.Top() ) / 20 ) + aPt;
736 0 : aRight = OString::valueOf( double( rRectangle.Right() ) / 20 ) + aPt;
737 0 : aBottom = OString::valueOf( double( rRectangle.Bottom() ) / 20 ) + aPt;
738 : }
739 : else
740 : {
741 0 : aLeft = OString::valueOf( rRectangle.Left() );
742 0 : aTop = OString::valueOf( rRectangle.Top() );
743 0 : aRight = OString::valueOf( rRectangle.Right() );
744 0 : aBottom = OString::valueOf( rRectangle.Bottom() );
745 : }
746 :
747 : m_pShapeAttrList->add( XML_from,
748 0 : OStringBuffer( 20 ).append( aLeft )
749 0 : .append( "," ).append( aTop )
750 0 : .makeStringAndClear() );
751 :
752 : m_pShapeAttrList->add( XML_to,
753 0 : OStringBuffer( 20 ).append( aRight )
754 0 : .append( "," ).append( aBottom )
755 0 : .makeStringAndClear() );
756 0 : }
757 :
758 0 : void VMLExport::AddRectangleDimensions( OStringBuffer& rBuffer, const Rectangle& rRectangle )
759 : {
760 0 : if ( rBuffer.getLength() )
761 0 : rBuffer.append( ";" );
762 :
763 0 : rBuffer.append( "position:absolute;" );
764 :
765 0 : if ( mnGroupLevel == 1 )
766 : {
767 0 : rBuffer.append( "margin-left:" ).append( double( rRectangle.Left() ) / 20 )
768 0 : .append( "pt;margin-top:" ).append( double( rRectangle.Top() ) / 20 )
769 0 : .append( "pt;width:" ).append( double( rRectangle.Right() - rRectangle.Left() ) / 20 )
770 0 : .append( "pt;height:" ).append( double( rRectangle.Bottom() - rRectangle.Top() ) / 20 )
771 0 : .append( "pt" );
772 : }
773 : else
774 : {
775 0 : rBuffer.append( "left:" ).append( rRectangle.Left() )
776 0 : .append( ";top:" ).append( rRectangle.Top() )
777 0 : .append( ";width:" ).append( rRectangle.Right() - rRectangle.Left() )
778 0 : .append( ";height:" ).append( rRectangle.Bottom() - rRectangle.Top() );
779 : }
780 0 : }
781 :
782 0 : void VMLExport::AddShapeAttribute( sal_Int32 nAttribute, const OString& rValue )
783 : {
784 0 : m_pShapeAttrList->add( nAttribute, rValue );
785 0 : }
786 :
787 : extern const char* pShapeTypes[];
788 :
789 0 : sal_Int32 VMLExport::StartShape()
790 : {
791 0 : if ( m_nShapeType == ESCHER_ShpInst_Nil )
792 0 : return -1;
793 :
794 : // some of the shapes have their own name ;-)
795 0 : sal_Int32 nShapeElement = -1;
796 0 : bool bReferToShapeType = false;
797 0 : switch ( m_nShapeType )
798 : {
799 0 : case ESCHER_ShpInst_NotPrimitive: nShapeElement = XML_shape; break;
800 0 : case ESCHER_ShpInst_Rectangle: nShapeElement = XML_rect; break;
801 0 : case ESCHER_ShpInst_RoundRectangle: nShapeElement = XML_roundrect; break;
802 0 : case ESCHER_ShpInst_Ellipse: nShapeElement = XML_oval; break;
803 0 : case ESCHER_ShpInst_Arc: nShapeElement = XML_arc; break;
804 0 : case ESCHER_ShpInst_Line: nShapeElement = XML_line; break;
805 : default:
806 0 : if ( m_nShapeType < ESCHER_ShpInst_COUNT )
807 : {
808 0 : nShapeElement = XML_shape;
809 :
810 : // a predefined shape?
811 0 : const char* pShapeType = pShapeTypes[ m_nShapeType ];
812 0 : if ( pShapeType )
813 : {
814 0 : bReferToShapeType = true;
815 0 : if ( !m_pShapeTypeWritten[ m_nShapeType ] )
816 : {
817 0 : m_pSerializer->write( pShapeType );
818 0 : m_pShapeTypeWritten[ m_nShapeType ] = true;
819 : }
820 : }
821 : else
822 : {
823 : // rectangle is probably the best fallback...
824 0 : nShapeElement = XML_rect;
825 : }
826 : }
827 0 : break;
828 : }
829 :
830 : // add style
831 0 : m_pShapeAttrList->add( XML_style, m_pShapeStyle->makeStringAndClear() );
832 :
833 0 : if ( nShapeElement >= 0 )
834 : {
835 0 : if ( bReferToShapeType )
836 : {
837 : m_pShapeAttrList->add( XML_type, OStringBuffer( 20 )
838 0 : .append( "shapetype_" ).append( sal_Int32( m_nShapeType ) )
839 0 : .makeStringAndClear() );
840 : }
841 :
842 : // start of the shape
843 0 : m_pSerializer->startElementNS( XML_v, nShapeElement, XFastAttributeListRef( m_pShapeAttrList ) );
844 : }
845 :
846 : // now check if we have some text and we have a text exporter registered
847 0 : const SdrTextObj* pTxtObj = PTR_CAST(SdrTextObj, m_pSdrObject);
848 0 : if (pTxtObj && m_pTextExport)
849 : {
850 0 : const OutlinerParaObject* pParaObj = 0;
851 0 : bool bOwnParaObj = false;
852 :
853 : /*
854 : #i13885#
855 : When the object is actively being edited, that text is not set into
856 : the objects normal text object, but lives in a seperate object.
857 : */
858 0 : if (pTxtObj->IsTextEditActive())
859 : {
860 0 : pParaObj = pTxtObj->GetEditOutlinerParaObject();
861 0 : bOwnParaObj = true;
862 : }
863 : else
864 : {
865 0 : pParaObj = pTxtObj->GetOutlinerParaObject();
866 : }
867 :
868 0 : if( pParaObj )
869 : {
870 : // this is reached only in case some text is attached to the shape
871 0 : m_pTextExport->WriteOutliner(*pParaObj);
872 0 : if( bOwnParaObj )
873 0 : delete pParaObj;
874 : }
875 : }
876 :
877 0 : return nShapeElement;
878 : }
879 :
880 0 : void VMLExport::EndShape( sal_Int32 nShapeElement )
881 : {
882 0 : if ( nShapeElement >= 0 )
883 : {
884 : // end of the shape
885 0 : m_pSerializer->endElementNS( XML_v, nShapeElement );
886 : }
887 0 : }
888 :
889 0 : sal_uInt32 VMLExport::AddSdrObject( const SdrObject& rObj )
890 : {
891 0 : m_pSdrObject = &rObj;
892 0 : return EscherEx::AddSdrObject(rObj);
893 51 : }
894 :
895 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|