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
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
|
/* -*- 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 <com/sun/star/xml/sax/SAXException.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
#include <com/sun/star/xml/sax/XAttributeList.hpp>
#include <rtl/ustrbuf.hxx>
#include <osl/diagnose.h>
#include <sax/tools/converter.hxx>
#include <xmloff/namespacemap.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlnamespace.hxx>
#include "PropType.hxx"
#include "DeepTContext.hxx"
#include "TransformerBase.hxx"
#include "TransformerActions.hxx"
#include "ActionMapTypesOASIS.hxx"
#include "MutableAttrList.hxx"
#include "PropertyActionsOASIS.hxx"
#include "StyleOASISTContext.hxx"
#include <xmloff/xmluconv.hxx>
using namespace ::xmloff::token;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::xml::sax;
const sal_uInt16 aAttrActionMaps[XML_PROP_TYPE_END] =
{
PROP_OASIS_GRAPHIC_ATTR_ACTIONS,
PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS, // DRAWING_PAGE
PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS,
PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS,
PROP_OASIS_TEXT_ATTR_ACTIONS,
PROP_OASIS_PARAGRAPH_ATTR_ACTIONS,
MAX_OASIS_PROP_ACTIONS, // RUBY
PROP_OASIS_SECTION_ATTR_ACTIONS,
PROP_OASIS_TABLE_ATTR_ACTIONS,
PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS,
PROP_OASIS_TABLE_ROW_ATTR_ACTIONS,
PROP_OASIS_TABLE_CELL_ATTR_ACTIONS,
PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS,
PROP_OASIS_CHART_ATTR_ACTIONS
};
class XMLPropertiesTContext_Impl : public XMLPersElemContentTContext
{
css::uno::Reference< css::xml::sax::XAttributeList > m_xAttrList;
XMLPropType m_ePropType;
bool const m_bControlStyle;
public:
void SetQNameAndPropType( const OUString& rQName,
XMLPropType ePropType )
{
m_ePropType = ePropType;
XMLTransformerContext::SetQName( rQName );
};
XMLPropertiesTContext_Impl( XMLTransformerBase& rTransformer,
const OUString& rQName,
XMLPropType eP,
bool _bControlStyle );
virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
virtual void Export() override;
static XMLPropType GetPropType( std::u16string_view rLocalName );
static OUString const & MergeUnderline( XMLTokenEnum eUnderline,
bool bBold, bool bDouble );
static OUString const & MergeLineThrough( XMLTokenEnum eLineThrough,
bool bBold, bool bDouble,
sal_Unicode c );
};
XMLPropertiesTContext_Impl::XMLPropertiesTContext_Impl(
XMLTransformerBase& rImp, const OUString& rQName, XMLPropType eP,
bool _bControlStyle ) :
XMLPersElemContentTContext( rImp, rQName, XML_NAMESPACE_STYLE,
XML_PROPERTIES),
m_ePropType( eP ),
m_bControlStyle( _bControlStyle )
{
}
void XMLPropertiesTContext_Impl::StartElement(
const Reference< XAttributeList >& rAttrList )
{
XMLTransformerActions *pActions = nullptr;
sal_uInt16 nActionMap = aAttrActionMaps[m_ePropType];
if( nActionMap < MAX_OASIS_PROP_ACTIONS )
{
pActions = GetTransformer().GetUserDefinedActions( nActionMap );
OSL_ENSURE( pActions, "go no actions" );
}
if( pActions )
{
rtl::Reference<XMLMutableAttributeList> pAttrList;
if( !m_xAttrList.is() )
{
pAttrList = new XMLMutableAttributeList();
m_xAttrList = pAttrList;
}
else
{
pAttrList =
static_cast< XMLMutableAttributeList * >( m_xAttrList.get() );
}
XMLTokenEnum eUnderline = XML_TOKEN_END;
bool bBoldUnderline = false, bDoubleUnderline = false;
XMLTokenEnum eLineThrough = XML_TOKEN_END;
bool bBoldLineThrough = false, bDoubleLineThrough = false;
sal_Unicode cLineThroughChar = 0;
bool bIntervalMinorFound = false;
double fIntervalMajor = 0.0;
sal_Int32 nIntervalMinorDivisor = 0;
// #i25616#
OUString aOpacityValueRemember;
OUString aImageOpacityValueRemember;
sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
for( sal_Int16 i=0; i < nAttrCount; i++ )
{
const OUString& rAttrName = rAttrList->getNameByIndex( i );
const OUString& rAttrValue = rAttrList->getValueByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix =
GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
&aLocalName );
XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
XMLTransformerActions::const_iterator aIter =
pActions->find( aKey );
if( aIter != pActions->end() )
{
switch( (*aIter).second.m_nActionType )
{
case XML_ATACTION_REMOVE:
break;
case XML_ATACTION_COPY:
pAttrList->AddAttribute( rAttrName, rAttrValue );
break;
case XML_ATACTION_RENAME:
{
OUString aNewAttrQName(
GetTransformer().GetNamespaceMap().GetQNameByKey(
(*aIter).second.GetQNamePrefixFromParam1(),
::xmloff::token::GetXMLToken(
(*aIter).second.GetQNameTokenFromParam1()) ) );
pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
}
break;
case XML_ATACTION_IN2INCH:
{
OUString aAttrValue( rAttrValue );
XMLTransformerBase::ReplaceSingleInWithInch(
aAttrValue );
pAttrList->AddAttribute( rAttrName, aAttrValue );
}
break;
case XML_ATACTION_INS2INCHS:
{
OUString aAttrValue( rAttrValue );
XMLTransformerBase::ReplaceInWithInch(
aAttrValue );
pAttrList->AddAttribute( rAttrName, aAttrValue );
}
break;
case XML_ATACTION_DECODE_STYLE_NAME_REF:
{
OUString aAttrValue( rAttrValue );
XMLTransformerBase::DecodeStyleName(aAttrValue);
pAttrList->AddAttribute( rAttrName, aAttrValue );
}
break;
case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF:
{
OUString aNewAttrQName(
GetTransformer().GetNamespaceMap().GetQNameByKey(
(*aIter).second.GetQNamePrefixFromParam1(),
::xmloff::token::GetXMLToken(
(*aIter).second.GetQNameTokenFromParam1()) ) );
OUString aAttrValue( rAttrValue );
XMLTransformerBase::DecodeStyleName(aAttrValue);
pAttrList->AddAttribute( aNewAttrQName, aAttrValue );
}
break;
case XML_ATACTION_NEG_PERCENT:
{
OUString aAttrValue( rAttrValue );
XMLTransformerBase::NegPercent(aAttrValue);
pAttrList->AddAttribute( rAttrName, aAttrValue );
}
break;
case XML_ATACTION_RENAME_NEG_PERCENT:
{
OUString aNewAttrQName(
GetTransformer().GetNamespaceMap().GetQNameByKey(
(*aIter).second.GetQNamePrefixFromParam1(),
::xmloff::token::GetXMLToken(
(*aIter).second.GetQNameTokenFromParam1()) ) );
OUString aAttrValue( rAttrValue );
XMLTransformerBase::NegPercent(aAttrValue);
pAttrList->AddAttribute( aNewAttrQName, aAttrValue );
}
break;
case XML_OPTACTION_LINE_MODE:
{
bool bWordMode =
IsXMLToken( rAttrValue, XML_SKIP_WHITE_SPACE );
OUString aAttrQName(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_FO,
GetXMLToken( XML_SCORE_SPACES ) ) );
sal_Int16 nIndex =
pAttrList->GetIndexByName( aAttrQName );
if( -1 != nIndex )
{
if( bWordMode )
{
const OUString& rOldValue =
pAttrList->getValueByIndex( nIndex );
if( !IsXMLToken( rOldValue, XML_TRUE ) )
{
pAttrList->SetValueByIndex( nIndex,
GetXMLToken( XML_TRUE ) );
}
}
}
else
{
const OUString& aAttrValue( GetXMLToken( bWordMode
? XML_FALSE
: XML_TRUE ) );
pAttrList->AddAttribute( aAttrQName, aAttrValue );
}
}
break;
case XML_OPTACTION_KEEP_WITH_NEXT:
{
const OUString& aAttrValue( GetXMLToken(
IsXMLToken( rAttrValue, XML_ALWAYS )
? XML_TRUE
: XML_FALSE) );
pAttrList->AddAttribute( rAttrName, aAttrValue );
}
break;
case XML_OPTACTION_UNDERLINE_WIDTH:
if( IsXMLToken( rAttrValue, XML_BOLD ) )
bBoldUnderline = true;
break;
case XML_OPTACTION_UNDERLINE_TYPE:
if( IsXMLToken( rAttrValue, XML_DOUBLE ) )
bDoubleUnderline = true;
break;
case XML_OPTACTION_UNDERLINE_STYLE:
eUnderline = GetTransformer().GetToken( rAttrValue );
break;
case XML_OPTACTION_LINETHROUGH_WIDTH:
if( IsXMLToken( rAttrValue, XML_BOLD ) )
bBoldLineThrough = true;
break;
case XML_OPTACTION_LINETHROUGH_TYPE:
if( IsXMLToken( rAttrValue, XML_DOUBLE ) )
bDoubleLineThrough = true;
break;
case XML_OPTACTION_LINETHROUGH_STYLE:
eLineThrough = GetTransformer().GetToken( rAttrValue );
break;
case XML_OPTACTION_LINETHROUGH_TEXT:
if( !rAttrValue.isEmpty() )
cLineThroughChar = rAttrValue[0];
break;
case XML_OPTACTION_INTERPOLATION:
{
// 0: none (default)
sal_Int32 nSplineType = 0;
if( IsXMLToken( rAttrValue, XML_CUBIC_SPLINE ))
nSplineType = 1;
else if( IsXMLToken( rAttrValue, XML_B_SPLINE ))
nSplineType = 2;
pAttrList->AddAttribute(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_CHART,
GetXMLToken( XML_SPLINES )),
OUString::number( nSplineType ));
}
break;
case XML_OPTACTION_INTERVAL_MAJOR:
pAttrList->AddAttribute( rAttrName, rAttrValue );
::sax::Converter::convertDouble(fIntervalMajor, rAttrValue);
break;
case XML_OPTACTION_INTERVAL_MINOR_DIVISOR:
::sax::Converter::convertNumber(nIntervalMinorDivisor, rAttrValue);
bIntervalMinorFound = true;
break;
case XML_OPTACTION_SYMBOL_TYPE:
{
// if symbol_type is "named-symbol" the "symbol"
// property is set in the action XML_OPTACTION_SYMBOL_NAME
sal_Int32 nSymbolType = 0;
if( IsXMLToken( rAttrValue, XML_NONE ))
nSymbolType = -3;
else if( IsXMLToken( rAttrValue, XML_AUTOMATIC ))
nSymbolType = -2;
else if( IsXMLToken( rAttrValue, XML_IMAGE ))
nSymbolType = -1;
if( nSymbolType < 0 )
pAttrList->AddAttribute(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_CHART,
GetXMLToken( XML_SYMBOL )),
OUString::number( nSymbolType ));
}
break;
case XML_OPTACTION_SYMBOL_NAME:
{
// assume "symbol-type" == "named-symbol"
sal_Int32 nSymbolType = -3; // NONE
// "square" just has an awkward token-name
if( IsXMLToken( rAttrValue, XML_GRADIENTSTYLE_SQUARE ))
nSymbolType = 0;
else if( IsXMLToken( rAttrValue, XML_DIAMOND ))
nSymbolType = 1;
else if( IsXMLToken( rAttrValue, XML_ARROW_DOWN ))
nSymbolType = 2;
else if( IsXMLToken( rAttrValue, XML_ARROW_UP ))
nSymbolType = 3;
else if( IsXMLToken( rAttrValue, XML_ARROW_RIGHT ))
nSymbolType = 4;
else if( IsXMLToken( rAttrValue, XML_ARROW_LEFT ))
nSymbolType = 5;
else if( IsXMLToken( rAttrValue, XML_BOW_TIE ))
nSymbolType = 6;
else if( IsXMLToken( rAttrValue, XML_HOURGLASS ))
nSymbolType = 7;
else if( IsXMLToken( rAttrValue, XML_CIRCLE ))
nSymbolType = 8;
else if( IsXMLToken( rAttrValue, XML_STAR ))
nSymbolType = 9;
else if( IsXMLToken( rAttrValue, XML_X ))
nSymbolType = 10;
else if( IsXMLToken( rAttrValue, XML_PLUS ))
nSymbolType = 11;
else if( IsXMLToken( rAttrValue, XML_ASTERISK ))
nSymbolType = 12;
else if( IsXMLToken( rAttrValue, XML_HORIZONTAL_BAR ))
nSymbolType = 13;
else if( IsXMLToken( rAttrValue, XML_VERTICAL_BAR ))
nSymbolType = 14;
if( nSymbolType >= 0 )
pAttrList->AddAttribute(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_CHART,
GetXMLToken( XML_SYMBOL )),
OUString::number( nSymbolType ));
}
break;
// #i25616#
case XML_OPTACTION_OPACITY:
aOpacityValueRemember = rAttrValue;
XMLTransformerBase::NegPercent(aOpacityValueRemember);
break;
// #i25616#
case XML_OPTACTION_IMAGE_OPACITY:
aImageOpacityValueRemember = rAttrValue;
XMLTransformerBase::NegPercent(aImageOpacityValueRemember);
break;
case XML_OPTACTION_KEEP_TOGETHER:
pAttrList->AddAttribute(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_STYLE,GetXMLToken(XML_BREAK_INSIDE)),
GetXMLToken(
IsXMLToken( rAttrValue, XML_ALWAYS )
? XML_COLUMNSPLIT_AVOID
: XML_AUTO ) );
break;
case XML_OPTACTION_CONTROL_TEXT_ALIGN:
if ( m_bControlStyle )
{
OUString aNewAttrQName(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_STYLE,
::xmloff::token::GetXMLToken(
XML_TEXT_ALIGN ) ) );
pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
}
else
{
OUString aNewAttrQName(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_FO,
::xmloff::token::GetXMLToken(
XML_TEXT_ALIGN ) ) );
pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
}
break;
case XML_ATACTION_CAPTION_ESCAPE_OASIS:
{
OUString aAttrValue( rAttrValue );
if( aAttrValue.indexOf( '%' ) != -1 )
{
sal_Int32 nValue = 0;
::sax::Converter::convertPercent(nValue, rAttrValue);
if( nValue )
{
nValue *= 100;
OUStringBuffer aOut;
::sax::Converter::convertPercent(aOut, nValue);
aAttrValue = aOut.makeStringAndClear();
}
}
else
{
XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue );
}
pAttrList->AddAttribute( rAttrName, aAttrValue );
}
break;
case XML_ATACTION_DECODE_PROTECT:
{
pAttrList->AddAttribute( rAttrName, rAttrValue );
if( rAttrValue.indexOf( GetXMLToken( XML_SIZE ) ) != -1 )
pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_DRAW,
GetXMLToken( XML_SIZE_PROTECT )), GetXMLToken( XML_TRUE ) );
if( rAttrValue.indexOf( GetXMLToken( XML_POSITION ) ) != -1 )
pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_DRAW,
GetXMLToken( XML_MOVE_PROTECT )), GetXMLToken( XML_TRUE ) );
}
break;
case XML_ATACTION_DRAW_MIRROR_OASIS: // renames style:mirror to draw:mirror and adapts values
{
// keep original for writer graphic objects
// Adapts attribute values (#i49139#)
OUStringBuffer aNewAttrValue;
SvXMLTokenEnumerator aTokenEnum( rAttrValue );
std::u16string_view aToken;
while( aTokenEnum.getNextToken( aToken ) )
{
if ( !aNewAttrValue.isEmpty() )
{
aNewAttrValue.append(" ");
}
if ( IsXMLToken( aToken, XML_HORIZONTAL_ON_EVEN ) )
{
aNewAttrValue.append(GetXMLToken( XML_HORIZONTAL_ON_LEFT_PAGES ));
}
else if ( IsXMLToken( aToken, XML_HORIZONTAL_ON_ODD ) )
{
aNewAttrValue.append(GetXMLToken( XML_HORIZONTAL_ON_RIGHT_PAGES ));
}
else
{
aNewAttrValue.append(aToken);
}
}
pAttrList->AddAttribute( rAttrName, aNewAttrValue.makeStringAndClear() );
// create old draw:mirror for drawing graphic objects
const OUString& aAttrValue( GetXMLToken( IsXMLToken( rAttrValue, XML_HORIZONTAL ) ? XML_TRUE : XML_FALSE ) );
pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_DRAW,
GetXMLToken( XML_MIRROR )), aAttrValue );
}
break;
case XML_ATACTION_GAMMA_OASIS: // converts percentage value to double
{
sal_Int32 nValue;
::sax::Converter::convertPercent( nValue, rAttrValue );
const double fValue = static_cast<double>(nValue) / 100.0;
pAttrList->AddAttribute( rAttrName, OUString::number( fValue ) );
}
break;
case XML_ATACTION_OPACITY_FIX:
{
sal_Int32 nValue;
if( rAttrValue.indexOf( '%' ) != -1 )
{
::sax::Converter::convertPercent(nValue, rAttrValue);
}
else
{
nValue = sal_Int32( rAttrValue.toDouble() * 100.0 );
}
nValue = 100 - nValue;
OUStringBuffer aOut;
::sax::Converter::convertPercent(aOut, nValue);
pAttrList->AddAttribute( rAttrName, aOut.makeStringAndClear() );
}
break;
default:
OSL_ENSURE( false, "unknown action" );
break;
}
}
else
{
pAttrList->AddAttribute( rAttrName, rAttrValue );
}
}
if( XML_TOKEN_END != eUnderline )
pAttrList->AddAttribute(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_STYLE,
GetXMLToken( XML_TEXT_UNDERLINE ) ),
MergeUnderline( eUnderline, bBoldUnderline,
bDoubleUnderline ) );
if( XML_TOKEN_END != eLineThrough )
pAttrList->AddAttribute(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_STYLE,
GetXMLToken( XML_TEXT_CROSSING_OUT ) ),
MergeLineThrough( eLineThrough, bBoldLineThrough,
bDoubleLineThrough, cLineThroughChar ) );
if( bIntervalMinorFound )
{
double fIntervalMinor = 0.0;
if( nIntervalMinorDivisor != 0)
fIntervalMinor = fIntervalMajor / static_cast< double >( nIntervalMinorDivisor );
OUStringBuffer aBuf;
::sax::Converter::convertDouble( aBuf, fIntervalMinor );
pAttrList->AddAttribute(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_CHART,
GetXMLToken( XML_INTERVAL_MINOR )),
aBuf.makeStringAndClear());
}
// #i25616#
if(!aOpacityValueRemember.isEmpty() || !aImageOpacityValueRemember.isEmpty())
{
pAttrList->AddAttribute(
GetTransformer().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_DRAW,
GetXMLToken( XML_TRANSPARENCY ) ),
!aImageOpacityValueRemember.isEmpty()
? aImageOpacityValueRemember : aOpacityValueRemember );
}
}
else
{
if( !m_xAttrList.is() )
{
m_xAttrList = new XMLMutableAttributeList( rAttrList, true );
}
else
{
static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
->AppendAttributeList( rAttrList );
}
}
}
void XMLPropertiesTContext_Impl::Export()
{
GetTransformer().GetDocHandler()->startElement( GetExportQName(), m_xAttrList );
ExportContent();
GetTransformer().GetDocHandler()->endElement( GetExportQName() );
}
XMLPropType XMLPropertiesTContext_Impl::GetPropType( std::u16string_view rLocalName )
{
XMLPropType eProp = XML_PROP_TYPE_END;
if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
eProp = XML_PROP_TYPE_GRAPHIC;
else if( IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) )
eProp = XML_PROP_TYPE_DRAWING_PAGE;
else if( IsXMLToken( rLocalName, XML_PAGE_LAYOUT_PROPERTIES ) )
eProp = XML_PROP_TYPE_PAGE_LAYOUT;
else if( IsXMLToken( rLocalName, XML_HEADER_FOOTER_PROPERTIES ) )
eProp = XML_PROP_TYPE_HEADER_FOOTER;
else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
eProp = XML_PROP_TYPE_TEXT;
else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
eProp = XML_PROP_TYPE_PARAGRAPH;
else if( IsXMLToken( rLocalName, XML_RUBY_PROPERTIES ) )
eProp = XML_PROP_TYPE_RUBY;
else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) )
eProp = XML_PROP_TYPE_SECTION;
else if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) )
eProp = XML_PROP_TYPE_TABLE;
else if( IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) )
eProp = XML_PROP_TYPE_TABLE_COLUMN;
else if( IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) )
eProp = XML_PROP_TYPE_TABLE_ROW;
else if( IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) )
eProp = XML_PROP_TYPE_TABLE_CELL;
else if( IsXMLToken( rLocalName, XML_LIST_LEVEL_PROPERTIES ) )
eProp = XML_PROP_TYPE_LIST_LEVEL;
else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
eProp = XML_PROP_TYPE_CHART;
return eProp;
}
OUString const & XMLPropertiesTContext_Impl::MergeUnderline(
XMLTokenEnum eUnderline, bool bBold, bool bDouble )
{
if( bDouble )
{
switch( eUnderline )
{
case XML_WAVE:
eUnderline = XML_DOUBLE_WAVE;
break;
default:
eUnderline = XML_DOUBLE;
break;
}
}
else if( bBold )
{
switch( eUnderline )
{
case XML_NONE:
case XML_SOLID:
eUnderline = XML_BOLD;
break;
case XML_DOTTED:
eUnderline = XML_BOLD_DOTTED;
break;
case XML_DASH:
eUnderline = XML_BOLD_DASH;
break;
case XML_LONG_DASH:
eUnderline = XML_BOLD_LONG_DASH;
break;
case XML_DOT_DASH:
eUnderline = XML_BOLD_DOT_DASH;
break;
case XML_DOT_DOT_DASH:
eUnderline = XML_BOLD_DOT_DOT_DASH;
break;
case XML_WAVE:
eUnderline = XML_BOLD_WAVE;
break;
default:
OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
break;
}
}
else
{
switch( eUnderline )
{
case XML_SOLID:
eUnderline = XML_SINGLE;
break;
case XML_NONE:
eUnderline = XML_NONE;
break;
default:
OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
break;
}
}
return GetXMLToken( eUnderline );
}
OUString const & XMLPropertiesTContext_Impl::MergeLineThrough(
XMLTokenEnum eLineThrough, bool bBold, bool bDouble,
sal_Unicode c )
{
if( c )
eLineThrough = c=='/' ? XML_SLASH : XML_uX;
else if( bDouble )
eLineThrough = XML_DOUBLE_LINE;
else if( bBold )
eLineThrough = XML_THICK_LINE;
else if( XML_NONE != eLineThrough )
eLineThrough = XML_SINGLE_LINE;
return GetXMLToken( eLineThrough );
}
XMLStyleOASISTContext::XMLStyleOASISTContext(XMLTransformerBase& rImp,
const OUString& rQName, bool bPersistent)
: XMLPersElemContentTContext(rImp, rQName)
, m_bPersistent(bPersistent)
, m_bControlStyle(false)
{
}
XMLStyleOASISTContext::XMLStyleOASISTContext(
XMLTransformerBase& rImp, const OUString& rQName,
sal_uInt16 nPrefix, ::xmloff::token::XMLTokenEnum eToken,
bool bPersistent)
: XMLPersElemContentTContext(rImp, rQName, nPrefix, eToken)
, m_bPersistent(bPersistent)
, m_bControlStyle(false)
{
}
XMLStyleOASISTContext::~XMLStyleOASISTContext()
{
}
rtl::Reference<XMLTransformerContext> XMLStyleOASISTContext::CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
const OUString& rQName,
const Reference< XAttributeList >& rAttrList )
{
rtl::Reference<XMLTransformerContext> pContext;
if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
{
XMLPropType ePropType =
XMLPropertiesTContext_Impl::GetPropType( rLocalName );
if( XML_PROP_TYPE_END != ePropType )
{
// if no properties context exist start a new one.
if( !m_xPropContext.is() )
m_xPropContext = new XMLPropertiesTContext_Impl(
GetTransformer(), rQName, ePropType, m_bControlStyle );
else
m_xPropContext->SetQNameAndPropType( rQName, ePropType );
pContext = m_xPropContext;
}
}
if( !pContext.is() )
{
// if a properties context exist close it
if( m_xPropContext.is() && !m_bPersistent )
{
m_xPropContext->Export();
m_xPropContext = nullptr;
}
pContext = m_bPersistent
? XMLPersElemContentTContext::CreateChildContext(
nPrefix, rLocalName, rQName, rAttrList )
: XMLTransformerContext::CreateChildContext(
nPrefix, rLocalName, rQName, rAttrList );
}
return pContext;
}
void XMLStyleOASISTContext::StartElement(
const Reference< XAttributeList >& rAttrList )
{
XMLTransformerActions *pActions =
GetTransformer().GetUserDefinedActions( OASIS_STYLE_ACTIONS );
OSL_ENSURE( pActions, "go no actions" );
Reference< XAttributeList > xAttrList( rAttrList );
rtl::Reference<XMLMutableAttributeList> pMutableAttrList;
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
sal_Int16 nFamilyAttr = -1;
m_bControlStyle = false;
for( sal_Int16 i=0; i < nAttrCount; i++ )
{
const OUString& rAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix =
GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
&aLocalName );
XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
XMLTransformerActions::const_iterator aIter =
pActions->find( aKey );
if( aIter != pActions->end() )
{
if( !pMutableAttrList )
{
pMutableAttrList =
new XMLMutableAttributeList( xAttrList );
xAttrList = pMutableAttrList;
}
const OUString& rAttrValue = xAttrList->getValueByIndex( i );
switch( (*aIter).second.m_nActionType )
{
case XML_ATACTION_STYLE_FAMILY:
if( IsXMLToken( rAttrValue, XML_GRAPHIC ) )
{
pMutableAttrList->SetValueByIndex(
i, GetXMLToken(XML_GRAPHICS) );
}
else
{
if( IsXMLToken( rAttrValue, XML_PARAGRAPH ) )
nFamilyAttr = i;
}
break;
case XML_ATACTION_STYLE_DISPLAY_NAME:
case XML_ATACTION_REMOVE:
pMutableAttrList->RemoveAttributeByIndex( i );
--i;
--nAttrCount;
break;
case XML_ATACTION_DECODE_STYLE_NAME:
m_bControlStyle = rAttrValue.startsWith( "ctrl" );
[[fallthrough]];
case XML_ATACTION_DECODE_STYLE_NAME_REF:
{
OUString aAttrValue( rAttrValue );
if( XMLTransformerBase::DecodeStyleName(aAttrValue) )
pMutableAttrList->SetValueByIndex( i, aAttrValue );
}
break;
case XML_ATACTION_IN2INCH:
{
OUString aAttrValue( rAttrValue );
if( XMLTransformerBase::ReplaceSingleInWithInch(
aAttrValue ) )
pMutableAttrList->SetValueByIndex( i, aAttrValue );
}
break;
case XML_ATACTION_NEG_PERCENT:
{
OUString aAttrValue( rAttrValue );
if( XMLTransformerBase::NegPercent(aAttrValue) )
pMutableAttrList->SetValueByIndex( i, aAttrValue );
}
break;
case XML_ATACTION_URI_OASIS:
{
OUString aAttrValue( rAttrValue );
if( GetTransformer().ConvertURIToOOo( aAttrValue,
static_cast< bool >((*aIter).second.m_nParam1)))
pMutableAttrList->SetValueByIndex( i, aAttrValue );
}
break;
default:
OSL_ENSURE( false, "unknown action" );
break;
}
}
}
if( m_bControlStyle && nFamilyAttr != -1 )
pMutableAttrList->SetValueByIndex( nFamilyAttr, GetXMLToken( XML_CONTROL ) );
if( m_bPersistent )
XMLPersElemContentTContext::StartElement( xAttrList );
else
GetTransformer().GetDocHandler()->startElement( GetExportQName(), xAttrList );
}
void XMLStyleOASISTContext::EndElement()
{
if( m_bPersistent )
{
XMLPersElemContentTContext::EndElement();
}
else
{
// if a properties context exist close it
if( m_xPropContext.is() )
{
m_xPropContext->Export();
m_xPropContext = nullptr;
}
GetTransformer().GetDocHandler()->endElement( GetExportQName() );
}
}
void XMLStyleOASISTContext::Characters( const OUString& )
{
// element content only:
}
void XMLStyleOASISTContext::ExportContent()
{
if( m_xPropContext.is() )
m_xPropContext->Export();
XMLPersElemContentTContext::ExportContent();
}
bool XMLStyleOASISTContext::IsPersistent() const
{
return m_bPersistent;
}
XMLTransformerActions *XMLStyleOASISTContext::CreateTransformerActions(
sal_uInt16 nType )
{
XMLTransformerActionInit const *pInit = nullptr;
switch( nType )
{
case PROP_OASIS_GRAPHIC_ATTR_ACTIONS:
pInit = aGraphicPropertyOASISAttrActionTable;
break;
case PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS:
pInit = aDrawingPagePropertyOASISAttrActionTable;
break;
case PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS:
pInit = aPageLayoutPropertyOASISAttrActionTable;
break;
case PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS:
pInit = aHeaderFooterPropertyOASISAttrActionTable;
break;
case PROP_OASIS_TEXT_ATTR_ACTIONS:
pInit = aTextPropertyOASISAttrActionTable;
break;
case PROP_OASIS_PARAGRAPH_ATTR_ACTIONS:
pInit = aParagraphPropertyOASISAttrActionTable;
break;
case PROP_OASIS_SECTION_ATTR_ACTIONS:
pInit = aSectionPropertyOASISAttrActionTable;
break;
case PROP_OASIS_TABLE_ATTR_ACTIONS:
pInit = aTablePropertyOASISAttrActionTable;
break;
case PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS:
pInit = aTableColumnPropertyOASISAttrActionTable;
break;
case PROP_OASIS_TABLE_ROW_ATTR_ACTIONS:
pInit = aTableRowPropertyOASISAttrActionTable;
break;
case PROP_OASIS_TABLE_CELL_ATTR_ACTIONS:
pInit = aTableCellPropertyOASISAttrActionTable;
break;
case PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS:
pInit = aListLevelPropertyOASISAttrActionTable;
break;
case PROP_OASIS_CHART_ATTR_ACTIONS:
pInit = aChartPropertyOASISAttrActionTable;
break;
}
XMLTransformerActions *pActions = nullptr;
if( pInit )
pActions = new XMLTransformerActions( pInit );
return pActions;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|