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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <oox/export/vmlexport.hxx>
#include <oox/token/tokens.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustring.hxx>
#include <tools/stream.hxx>
#include <cstdio>
using rtl::OString;
using rtl::OStringBuffer;
using rtl::OUString;
using rtl::OUStringBuffer;
using namespace sax_fastparser;
using namespace oox::vml;
VMLExport::VMLExport( ::sax_fastparser::FSHelperPtr pSerializer )
: EscherEx( EscherExGlobalRef(new EscherExGlobal(0)), 0 ),
m_pSerializer( pSerializer ),
m_pShapeAttrList( NULL ),
m_nShapeType( ESCHER_ShpInst_Nil ),
m_pShapeStyle( new OStringBuffer( 200 ) ),
m_pShapeTypeWritten( new bool[ ESCHER_ShpInst_COUNT ] )
{
mnGroupLevel = 1;
memset( m_pShapeTypeWritten, 0, ESCHER_ShpInst_COUNT * sizeof( bool ) );
}
VMLExport::~VMLExport()
{
delete mpOutStrm, mpOutStrm = NULL;
delete m_pShapeStyle, m_pShapeStyle = NULL;
delete[] m_pShapeTypeWritten, m_pShapeTypeWritten = NULL;
}
void VMLExport::OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance )
{
EscherEx::OpenContainer( nEscherContainer, nRecInstance );
if ( nEscherContainer == ESCHER_SpContainer )
{
// opening a shape container
#if OSL_DEBUG_LEVEL > 0
if ( m_nShapeType != ESCHER_ShpInst_Nil )
fprintf( stderr, "Warning! VMLExport::OpenContainer(): opening shape inside a shape.\n" );
#endif
m_nShapeType = ESCHER_ShpInst_Nil;
m_pShapeAttrList = m_pSerializer->createAttrList();
if ( m_pShapeStyle->getLength() )
m_pShapeStyle->makeStringAndClear();
m_pShapeStyle->ensureCapacity( 200 );
// postpone the output so that we are able to write even the elements
// that we learn inside Commit()
m_pSerializer->mark();
}
}
void VMLExport::CloseContainer()
{
if ( mRecTypes.back() == ESCHER_SpContainer )
{
// write the shape now when we have all the info
sal_Int32 nShapeElement = StartShape();
m_pSerializer->mergeTopMarks();
EndShape( nShapeElement );
// cleanup
m_nShapeType = ESCHER_ShpInst_Nil;
m_pShapeAttrList = NULL;
}
EscherEx::CloseContainer();
}
sal_uInt32 VMLExport::EnterGroup( const String& rShapeName, const Rectangle* pRect )
{
sal_uInt32 nShapeId = GenerateShapeId();
OStringBuffer aStyle( 200 );
FastAttributeList *pAttrList = m_pSerializer->createAttrList();
pAttrList->add( XML_id, ShapeIdString( nShapeId ) );
if ( rShapeName.Len() )
pAttrList->add( XML_alt, OUStringToOString( OUString( rShapeName ), RTL_TEXTENCODING_UTF8 ) );
// style
if ( pRect )
AddRectangleDimensions( aStyle, *pRect );
if ( aStyle.getLength() )
pAttrList->add( XML_style, aStyle.makeStringAndClear() );
// coordorigin/coordsize
if ( pRect && ( mnGroupLevel == 1 ) )
{
pAttrList->add( XML_coordorigin,
OStringBuffer( 20 ).append( sal_Int32( pRect->Left() ) )
.append( "," ).append( sal_Int32( pRect->Top() ) )
.makeStringAndClear() );
pAttrList->add( XML_coordsize,
OStringBuffer( 20 ).append( sal_Int32( pRect->Right() ) - sal_Int32( pRect->Left() ) )
.append( "," ).append( sal_Int32( pRect->Bottom() ) - sal_Int32( pRect->Top() ) )
.makeStringAndClear() );
}
m_pSerializer->startElementNS( XML_v, XML_group, XFastAttributeListRef( pAttrList ) );
mnGroupLevel++;
return nShapeId;
}
void VMLExport::LeaveGroup()
{
--mnGroupLevel;
m_pSerializer->endElementNS( XML_v, XML_group );
}
void VMLExport::AddShape( sal_uInt32 nShapeType, sal_uInt32 nShapeFlags, sal_uInt32 nShapeId )
{
m_nShapeType = nShapeType;
m_nShapeFlags = nShapeFlags;
m_pShapeAttrList->add( XML_id, ShapeIdString( nShapeId ) );
}
static void impl_AddArrowHead( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nValue )
{
if ( !pAttrList )
return;
const char *pArrowHead = NULL;
switch ( nValue )
{
case ESCHER_LineNoEnd: pArrowHead = "none"; break;
case ESCHER_LineArrowEnd: pArrowHead = "block"; break;
case ESCHER_LineArrowStealthEnd: pArrowHead = "classic"; break;
case ESCHER_LineArrowDiamondEnd: pArrowHead = "diamond"; break;
case ESCHER_LineArrowOvalEnd: pArrowHead = "oval"; break;
case ESCHER_LineArrowOpenEnd: pArrowHead = "open"; break;
}
if ( pArrowHead )
pAttrList->add( nElement, pArrowHead );
}
static void impl_AddArrowLength( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nValue )
{
if ( !pAttrList )
return;
const char *pArrowLength = NULL;
switch ( nValue )
{
case ESCHER_LineShortArrow: pArrowLength = "short"; break;
case ESCHER_LineMediumLenArrow: pArrowLength = "medium"; break;
case ESCHER_LineLongArrow: pArrowLength = "long"; break;
}
if ( pArrowLength )
pAttrList->add( nElement, pArrowLength );
}
static void impl_AddArrowWidth( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nValue )
{
if ( !pAttrList )
return;
const char *pArrowWidth = NULL;
switch ( nValue )
{
case ESCHER_LineNarrowArrow: pArrowWidth = "narrow"; break;
case ESCHER_LineMediumWidthArrow: pArrowWidth = "medium"; break;
case ESCHER_LineWideArrow: pArrowWidth = "wide"; break;
}
if ( pArrowWidth )
pAttrList->add( nElement, pArrowWidth );
}
static void impl_AddBool( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, bool bValue )
{
if ( !pAttrList )
return;
pAttrList->add( nElement, bValue? "t": "f" );
}
static void impl_AddColor( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nColor )
{
#if OSL_DEBUG_LEVEL > 0
if ( nColor & 0xFF000000 )
fprintf( stderr, "TODO: this is not a RGB value!\n" );
#endif
if ( !pAttrList || ( nColor & 0xFF000000 ) )
return;
nColor = ( ( nColor & 0xFF ) << 16 ) + ( nColor & 0xFF00 ) + ( ( nColor & 0xFF0000 ) >> 16 );
const char *pColor = NULL;
char pRgbColor[10];
switch ( nColor )
{
case 0x000000: pColor = "black"; break;
case 0xC0C0C0: pColor = "silver"; break;
case 0x808080: pColor = "gray"; break;
case 0xFFFFFF: pColor = "white"; break;
case 0x800000: pColor = "maroon"; break;
case 0xFF0000: pColor = "red"; break;
case 0x800080: pColor = "purple"; break;
case 0xFF00FF: pColor = "fuchsia"; break;
case 0x008000: pColor = "green"; break;
case 0x00FF00: pColor = "lime"; break;
case 0x808000: pColor = "olive"; break;
case 0xFFFF00: pColor = "yellow"; break;
case 0x000080: pColor = "navy"; break;
case 0x0000FF: pColor = "blue"; break;
case 0x008080: pColor = "teal"; break;
case 0x00FFFF: pColor = "aqua"; break;
default:
{
snprintf( pRgbColor, sizeof( pRgbColor ), "#%06x", static_cast< unsigned int >( nColor ) ); // not too handy to use OString::valueOf() here :-(
pColor = pRgbColor;
}
break;
}
pAttrList->add( nElement, pColor );
}
static void impl_AddInt( sax_fastparser::FastAttributeList *pAttrList, sal_Int32 nElement, sal_uInt32 nValue )
{
if ( !pAttrList )
return;
pAttrList->add( nElement, OString::valueOf( static_cast< sal_Int32 >( nValue ) ).getStr() );
}
inline sal_uInt16 impl_GetUInt16( const sal_uInt8* &pVal )
{
sal_uInt16 nRet = *pVal++;
nRet += ( *pVal++ ) << 8;
return nRet;
}
inline sal_Int32 impl_GetPointComponent( const sal_uInt8* &pVal, sal_uInt16 nPointSize )
{
sal_Int32 nRet = 0;
if ( ( nPointSize == 0xfff0 ) || ( nPointSize == 4 ) )
{
sal_uInt16 nUnsigned = *pVal++;
nUnsigned += ( *pVal++ ) << 8;
nRet = sal_Int16( nUnsigned );
}
else if ( nPointSize == 8 )
{
sal_uInt32 nUnsigned = *pVal++;
nUnsigned += ( *pVal++ ) << 8;
nUnsigned += ( *pVal++ ) << 16;
nUnsigned += ( *pVal++ ) << 24;
nRet = nUnsigned;
}
return nRet;
}
void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect )
{
if ( m_nShapeType == ESCHER_ShpInst_Nil )
return;
// postpone the output of the embedded elements so that they are written
// inside the shapes
m_pSerializer->mark();
// dimensions
if ( m_nShapeType == ESCHER_ShpInst_Line )
AddLineDimensions( rRect );
else
AddRectangleDimensions( *m_pShapeStyle, rRect );
// properties
bool bAlreadyWritten[ 0xFFF ];
memset( bAlreadyWritten, 0, sizeof( bAlreadyWritten ) );
const EscherProperties &rOpts = rProps.GetOpts();
for ( EscherProperties::const_iterator it = rOpts.begin(); it != rOpts.end(); ++it )
{
sal_uInt16 nId = ( it->nPropId & 0x0FFF );
if ( bAlreadyWritten[ nId ] )
continue;
switch ( nId )
{
case ESCHER_Prop_WrapText: // 133
{
const char *pWrapType = NULL;
switch ( it->nPropValue )
{
case ESCHER_WrapSquare:
case ESCHER_WrapByPoints: pWrapType = "square"; break; // these two are equivalent according to the docu
case ESCHER_WrapNone: pWrapType = "none"; break;
case ESCHER_WrapTopBottom: pWrapType = "topAndBottom"; break;
case ESCHER_WrapThrough: pWrapType = "through"; break;
}
if ( pWrapType )
m_pSerializer->singleElementNS( XML_v, XML_wrap,
FSNS( XML_v, XML_type ), pWrapType,
FSEND );
}
bAlreadyWritten[ ESCHER_Prop_WrapText ] = true;
break;
// coordorigin
case ESCHER_Prop_geoLeft: // 320
case ESCHER_Prop_geoTop: // 321
{
sal_uInt32 nLeft = 0, nTop = 0;
if ( nId == ESCHER_Prop_geoLeft )
{
nLeft = it->nPropValue;
rProps.GetOpt( ESCHER_Prop_geoTop, nTop );
}
else
{
nTop = it->nPropValue;
rProps.GetOpt( ESCHER_Prop_geoLeft, nLeft );
}
m_pShapeAttrList->add( XML_coordorigin,
OStringBuffer( 20 ).append( sal_Int32( nLeft ) )
.append( "," ).append( sal_Int32( nTop ) )
.makeStringAndClear() );
}
bAlreadyWritten[ ESCHER_Prop_geoLeft ] = true;
bAlreadyWritten[ ESCHER_Prop_geoTop ] = true;
break;
// coordsize
case ESCHER_Prop_geoRight: // 322
case ESCHER_Prop_geoBottom: // 323
{
sal_uInt32 nLeft = 0, nRight = 0, nTop = 0, nBottom = 0;
rProps.GetOpt( ESCHER_Prop_geoLeft, nLeft );
rProps.GetOpt( ESCHER_Prop_geoTop, nTop );
if ( nId == ESCHER_Prop_geoRight )
{
nRight = it->nPropValue;
rProps.GetOpt( ESCHER_Prop_geoBottom, nBottom );
}
else
{
nBottom = it->nPropValue;
rProps.GetOpt( ESCHER_Prop_geoRight, nRight );
}
m_pShapeAttrList->add( XML_coordsize,
OStringBuffer( 20 ).append( sal_Int32( nRight ) - sal_Int32( nLeft ) )
.append( "," ).append( sal_Int32( nBottom ) - sal_Int32( nTop ) )
.makeStringAndClear() );
}
bAlreadyWritten[ ESCHER_Prop_geoRight ] = true;
bAlreadyWritten[ ESCHER_Prop_geoBottom ] = true;
break;
case ESCHER_Prop_pVertices: // 325
case ESCHER_Prop_pSegmentInfo: // 326
{
EscherPropSortStruct aVertices;
EscherPropSortStruct aSegments;
if ( rProps.GetOpt( ESCHER_Prop_pVertices, aVertices ) &&
rProps.GetOpt( ESCHER_Prop_pSegmentInfo, aSegments ) )
{
const sal_uInt8 *pVerticesIt = aVertices.pBuf + 6;
const sal_uInt8 *pSegmentIt = aSegments.pBuf;
OStringBuffer aPath( 512 );
sal_uInt16 nPointSize = aVertices.pBuf[4] + ( aVertices.pBuf[5] << 8 );
// number of segments
sal_uInt16 nSegments = impl_GetUInt16( pSegmentIt );
pSegmentIt += 4;
for ( ; nSegments; --nSegments )
{
sal_uInt16 nSeg = impl_GetUInt16( pSegmentIt );
switch ( nSeg )
{
case 0x4000: // moveto
{
sal_Int32 nX = impl_GetPointComponent( pVerticesIt, nPointSize );
sal_Int32 nY = impl_GetPointComponent( pVerticesIt, nPointSize );
aPath.append( "m" ).append( nX ).append( "," ).append( nY );
}
break;
case 0xb300:
case 0xac00:
break;
case 0x0001: // lineto
{
sal_Int32 nX = impl_GetPointComponent( pVerticesIt, nPointSize );
sal_Int32 nY = impl_GetPointComponent( pVerticesIt, nPointSize );
aPath.append( "l" ).append( nX ).append( "," ).append( nY );
}
break;
case 0x2001: // curveto
{
sal_Int32 nX1 = impl_GetPointComponent( pVerticesIt, nPointSize );
sal_Int32 nY1 = impl_GetPointComponent( pVerticesIt, nPointSize );
sal_Int32 nX2 = impl_GetPointComponent( pVerticesIt, nPointSize );
sal_Int32 nY2 = impl_GetPointComponent( pVerticesIt, nPointSize );
sal_Int32 nX3 = impl_GetPointComponent( pVerticesIt, nPointSize );
sal_Int32 nY3 = impl_GetPointComponent( pVerticesIt, nPointSize );
aPath.append( "c" ).append( nX1 ).append( "," ).append( nY1 ).append( "," )
.append( nX2 ).append( "," ).append( nY2 ).append( "," )
.append( nX3 ).append( "," ).append( nY3 );
}
break;
case 0xaa00: // nofill
aPath.append( "nf" );
break;
case 0xab00: // nostroke
aPath.append( "ns" );
break;
case 0x6001: // close
aPath.append( "x" );
break;
case 0x8000: // end
aPath.append( "e" );
break;
default:
#if OSL_DEBUG_LEVEL > 0
fprintf( stderr, "TODO: unhandled segment '%x' in the path\n", nSeg );
#endif
break;
}
}
if ( aPath.getLength() )
m_pShapeAttrList->add( XML_path, aPath.getStr() );
}
#if OSL_DEBUG_LEVEL > 0
else
fprintf( stderr, "TODO: unhandled shape path, missing either pVertices or pSegmentInfo.\n" );
#endif
}
bAlreadyWritten[ ESCHER_Prop_pVertices ] = true;
bAlreadyWritten[ ESCHER_Prop_pSegmentInfo ] = true;
break;
case ESCHER_Prop_fillType: // 384
case ESCHER_Prop_fillColor: // 385
case ESCHER_Prop_fillBackColor: // 387
case ESCHER_Prop_fNoFillHitTest: // 447
{
sal_uInt32 nValue;
sax_fastparser::FastAttributeList *pAttrList = m_pSerializer->createAttrList();
if ( rProps.GetOpt( ESCHER_Prop_fillType, nValue ) )
{
const char *pFillType = NULL;
switch ( nValue )
{
case ESCHER_FillSolid: pFillType = "solid"; break;
// TODO case ESCHER_FillPattern: pFillType = ""; break;
// TODO case ESCHER_FillTexture: pFillType = ""; break;
// TODO case ESCHER_FillPicture: pFillType = ""; break;
// TODO case ESCHER_FillShade: pFillType = ""; break;
// TODO case ESCHER_FillShadeCenter: pFillType = ""; break;
// TODO case ESCHER_FillShadeShape: pFillType = ""; break;
// TODO case ESCHER_FillShadeScale: pFillType = ""; break;
// TODO case ESCHER_FillShadeTitle: pFillType = ""; break;
// TODO case ESCHER_FillBackground: pFillType = ""; break;
default:
#if OSL_DEBUG_LEVEL > 0
fprintf( stderr, "TODO: unhandled fill type\n" );
#endif
break;
}
if ( pFillType )
pAttrList->add( XML_type, pFillType );
}
if ( rProps.GetOpt( ESCHER_Prop_fillColor, nValue ) )
impl_AddColor( m_pShapeAttrList, XML_fillcolor, nValue );
if ( rProps.GetOpt( ESCHER_Prop_fillBackColor, nValue ) )
impl_AddColor( pAttrList, XML_color2, nValue );
if ( rProps.GetOpt( ESCHER_Prop_fNoFillHitTest, nValue ) )
impl_AddBool( pAttrList, XML_detectmouseclick, nValue );
m_pSerializer->singleElementNS( XML_v, XML_fill, XFastAttributeListRef( pAttrList ) );
}
bAlreadyWritten[ ESCHER_Prop_fillType ] = true;
bAlreadyWritten[ ESCHER_Prop_fillColor ] = true;
bAlreadyWritten[ ESCHER_Prop_fillBackColor ] = true;
bAlreadyWritten[ ESCHER_Prop_fNoFillHitTest ] = true;
break;
case ESCHER_Prop_lineColor: // 448
case ESCHER_Prop_lineWidth: // 459
case ESCHER_Prop_lineDashing: // 462
case ESCHER_Prop_lineStartArrowhead: // 464
case ESCHER_Prop_lineEndArrowhead: // 465
case ESCHER_Prop_lineStartArrowWidth: // 466
case ESCHER_Prop_lineStartArrowLength: // 467
case ESCHER_Prop_lineEndArrowWidth: // 468
case ESCHER_Prop_lineEndArrowLength: // 469
case ESCHER_Prop_lineJoinStyle: // 470
case ESCHER_Prop_lineEndCapStyle: // 471
{
sal_uInt32 nValue;
sax_fastparser::FastAttributeList *pAttrList = m_pSerializer->createAttrList();
if ( rProps.GetOpt( ESCHER_Prop_lineColor, nValue ) )
impl_AddColor( pAttrList, XML_color, nValue );
if ( rProps.GetOpt( ESCHER_Prop_lineWidth, nValue ) )
impl_AddInt( pAttrList, XML_weight, nValue );
if ( rProps.GetOpt( ESCHER_Prop_lineDashing, nValue ) )
{
const char *pDashStyle = NULL;
switch ( nValue )
{
case ESCHER_LineSolid: pDashStyle = "solid"; break;
case ESCHER_LineDashSys: pDashStyle = "shortdash"; break;
case ESCHER_LineDotSys: pDashStyle = "shortdot"; break;
case ESCHER_LineDashDotSys: pDashStyle = "shortdashdot"; break;
case ESCHER_LineDashDotDotSys: pDashStyle = "shortdashdotdot"; break;
case ESCHER_LineDotGEL: pDashStyle = "dot"; break;
case ESCHER_LineDashGEL: pDashStyle = "dash"; break;
case ESCHER_LineLongDashGEL: pDashStyle = "longdash"; break;
case ESCHER_LineDashDotGEL: pDashStyle = "dashdot"; break;
case ESCHER_LineLongDashDotGEL: pDashStyle = "longdashdot"; break;
case ESCHER_LineLongDashDotDotGEL: pDashStyle = "longdashdotdot"; break;
}
if ( pDashStyle )
pAttrList->add( XML_dashstyle, pDashStyle );
}
if ( rProps.GetOpt( ESCHER_Prop_lineStartArrowhead, nValue ) )
impl_AddArrowHead( pAttrList, XML_startarrow, nValue );
if ( rProps.GetOpt( ESCHER_Prop_lineEndArrowhead, nValue ) )
impl_AddArrowHead( pAttrList, XML_endarrow, nValue );
if ( rProps.GetOpt( ESCHER_Prop_lineStartArrowWidth, nValue ) )
impl_AddArrowWidth( pAttrList, XML_startarrowwidth, nValue );
if ( rProps.GetOpt( ESCHER_Prop_lineStartArrowLength, nValue ) )
impl_AddArrowLength( pAttrList, XML_startarrowlength, nValue );
if ( rProps.GetOpt( ESCHER_Prop_lineEndArrowWidth, nValue ) )
impl_AddArrowWidth( pAttrList, XML_endarrowwidth, nValue );
if ( rProps.GetOpt( ESCHER_Prop_lineEndArrowLength, nValue ) )
impl_AddArrowLength( pAttrList, XML_endarrowlength, nValue );
if ( rProps.GetOpt( ESCHER_Prop_lineJoinStyle, nValue ) )
{
const char *pJoinStyle = NULL;
switch ( nValue )
{
case ESCHER_LineJoinBevel: pJoinStyle = "bevel"; break;
case ESCHER_LineJoinMiter: pJoinStyle = "miter"; break;
case ESCHER_LineJoinRound: pJoinStyle = "round"; break;
}
if ( pJoinStyle )
pAttrList->add( XML_joinstyle, pJoinStyle );
}
if ( rProps.GetOpt( ESCHER_Prop_lineEndCapStyle, nValue ) )
{
const char *pEndCap = NULL;
switch ( nValue )
{
case ESCHER_LineEndCapRound: pEndCap = "round"; break;
case ESCHER_LineEndCapSquare: pEndCap = "square"; break;
case ESCHER_LineEndCapFlat: pEndCap = "flat"; break;
}
if ( pEndCap )
pAttrList->add( XML_endcap, pEndCap );
}
m_pSerializer->singleElementNS( XML_v, XML_stroke, XFastAttributeListRef( pAttrList ) );
}
bAlreadyWritten[ ESCHER_Prop_lineColor ] = true;
bAlreadyWritten[ ESCHER_Prop_lineWidth ] = true;
bAlreadyWritten[ ESCHER_Prop_lineDashing ] = true;
bAlreadyWritten[ ESCHER_Prop_lineStartArrowhead ] = true;
bAlreadyWritten[ ESCHER_Prop_lineEndArrowhead ] = true;
bAlreadyWritten[ ESCHER_Prop_lineStartArrowWidth ] = true;
bAlreadyWritten[ ESCHER_Prop_lineStartArrowLength ] = true;
bAlreadyWritten[ ESCHER_Prop_lineEndArrowWidth ] = true;
bAlreadyWritten[ ESCHER_Prop_lineEndArrowLength ] = true;
bAlreadyWritten[ ESCHER_Prop_lineJoinStyle ] = true;
bAlreadyWritten[ ESCHER_Prop_lineEndCapStyle ] = true;
break;
case ESCHER_Prop_fHidden:
if ( !it->nPropValue )
m_pShapeStyle->append( ";visibility:hidden" );
break;
case ESCHER_Prop_shadowColor:
case ESCHER_Prop_fshadowObscured:
{
sal_uInt32 nValue = 0;
bool bShadow = false;
bool bObscured = false;
if ( rProps.GetOpt( ESCHER_Prop_fshadowObscured, nValue ) )
{
bShadow = (( nValue & 0x20002 ) == 0x20002 );
bObscured = (( nValue & 0x10001 ) == 0x10001 );
}
if ( bShadow )
{
sax_fastparser::FastAttributeList *pAttrList = m_pSerializer->createAttrList();
impl_AddBool( pAttrList, XML_on, bShadow );
impl_AddBool( pAttrList, XML_obscured, bObscured );
if ( rProps.GetOpt( ESCHER_Prop_shadowColor, nValue ) )
impl_AddColor( pAttrList, XML_color, nValue );
m_pSerializer->singleElementNS( XML_v, XML_shadow, XFastAttributeListRef( pAttrList ) );
bAlreadyWritten[ ESCHER_Prop_fshadowObscured ] = true;
bAlreadyWritten[ ESCHER_Prop_shadowColor ] = true;
}
}
break;
default:
#if OSL_DEBUG_LEVEL > 0
fprintf( stderr, "TODO VMLExport::Commit(), unimplemented id: %d, value: %" SAL_PRIuUINT32 ", data: [%" SAL_PRIuUINT32 ", %p]\n",
it->nPropId, it->nPropValue, it->nPropSize, it->pBuf );
if ( it->nPropSize )
{
const sal_uInt8 *pIt = it->pBuf;
fprintf( stderr, " ( " );
for ( int nCount = it->nPropSize; nCount; --nCount )
{
fprintf( stderr, "%02x ", *pIt );
++pIt;
}
fprintf( stderr, ")\n" );
}
#endif
break;
}
}
m_pSerializer->mergeTopMarks( sax_fastparser::MERGE_MARKS_POSTPONE );
}
OString VMLExport::ShapeIdString( sal_uInt32 nId )
{
return OStringBuffer( 20 ).append( "shape_" ).append( sal_Int64( nId ) ).makeStringAndClear();
}
void VMLExport::AddLineDimensions( const Rectangle& rRectangle )
{
// style
if ( m_pShapeStyle->getLength() )
m_pShapeStyle->append( ";" );
m_pShapeStyle->append( "position:absolute" );
switch ( m_nShapeFlags & 0xC0 )
{
case 0x40: m_pShapeStyle->append( ";flip:y" ); break;
case 0x80: m_pShapeStyle->append( ";flip:x" ); break;
case 0xC0: m_pShapeStyle->append( ";flip:xy" ); break;
}
// the actual dimensions
OString aLeft, aTop, aRight, aBottom;
if ( mnGroupLevel == 1 )
{
const OString aPt( "pt" );
aLeft = OString::valueOf( double( rRectangle.Left() ) / 20 ) + aPt;
aTop = OString::valueOf( double( rRectangle.Top() ) / 20 ) + aPt;
aRight = OString::valueOf( double( rRectangle.Right() ) / 20 ) + aPt;
aBottom = OString::valueOf( double( rRectangle.Bottom() ) / 20 ) + aPt;
}
else
{
aLeft = OString::valueOf( rRectangle.Left() );
aTop = OString::valueOf( rRectangle.Top() );
aRight = OString::valueOf( rRectangle.Right() );
aBottom = OString::valueOf( rRectangle.Bottom() );
}
m_pShapeAttrList->add( XML_from,
OStringBuffer( 20 ).append( aLeft )
.append( "," ).append( aTop )
.makeStringAndClear() );
m_pShapeAttrList->add( XML_to,
OStringBuffer( 20 ).append( aRight )
.append( "," ).append( aBottom )
.makeStringAndClear() );
}
void VMLExport::AddRectangleDimensions( rtl::OStringBuffer& rBuffer, const Rectangle& rRectangle )
{
if ( rBuffer.getLength() )
rBuffer.append( ";" );
rBuffer.append( "position:absolute;" );
if ( mnGroupLevel == 1 )
{
rBuffer.append( "margin-left:" ).append( double( rRectangle.Left() ) / 20 )
.append( "pt;margin-top:" ).append( double( rRectangle.Top() ) / 20 )
.append( "pt;width:" ).append( double( rRectangle.Right() - rRectangle.Left() ) / 20 )
.append( "pt;height:" ).append( double( rRectangle.Bottom() - rRectangle.Top() ) / 20 )
.append( "pt" );
}
else
{
rBuffer.append( "left:" ).append( rRectangle.Left() )
.append( ";top:" ).append( rRectangle.Top() )
.append( ";width:" ).append( rRectangle.Right() - rRectangle.Left() )
.append( ";height:" ).append( rRectangle.Bottom() - rRectangle.Top() );
}
}
void VMLExport::AddShapeAttribute( sal_Int32 nAttribute, const rtl::OString& rValue )
{
m_pShapeAttrList->add( nAttribute, rValue );
}
extern const char* pShapeTypes[];
sal_Int32 VMLExport::StartShape()
{
if ( m_nShapeType == ESCHER_ShpInst_Nil )
return -1;
// some of the shapes have their own name ;-)
sal_Int32 nShapeElement = -1;
bool bReferToShapeType = false;
switch ( m_nShapeType )
{
case ESCHER_ShpInst_NotPrimitive: nShapeElement = XML_shape; break;
case ESCHER_ShpInst_Rectangle: nShapeElement = XML_rect; break;
case ESCHER_ShpInst_RoundRectangle: nShapeElement = XML_roundrect; break;
case ESCHER_ShpInst_Ellipse: nShapeElement = XML_oval; break;
case ESCHER_ShpInst_Arc: nShapeElement = XML_arc; break;
case ESCHER_ShpInst_Line: nShapeElement = XML_line; break;
default:
if ( m_nShapeType < ESCHER_ShpInst_COUNT )
{
nShapeElement = XML_shape;
// a predefined shape?
const char* pShapeType = pShapeTypes[ m_nShapeType ];
if ( pShapeType )
{
bReferToShapeType = true;
if ( !m_pShapeTypeWritten[ m_nShapeType ] )
{
m_pSerializer->write( pShapeType );
m_pShapeTypeWritten[ m_nShapeType ] = true;
}
}
else
{
// rectangle is probably the best fallback...
nShapeElement = XML_rect;
}
}
break;
}
// add style
m_pShapeAttrList->add( XML_style, m_pShapeStyle->makeStringAndClear() );
if ( nShapeElement >= 0 )
{
if ( bReferToShapeType )
{
m_pShapeAttrList->add( XML_type, OStringBuffer( 20 )
.append( "shapetype_" ).append( sal_Int32( m_nShapeType ) )
.makeStringAndClear() );
}
// start of the shape
m_pSerializer->startElementNS( XML_v, nShapeElement, XFastAttributeListRef( m_pShapeAttrList ) );
}
return nShapeElement;
}
void VMLExport::EndShape( sal_Int32 nShapeElement )
{
if ( nShapeElement >= 0 )
{
// end of the shape
m_pSerializer->endElementNS( XML_v, nShapeElement );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|