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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569 | /* -*- 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 <memory>
#include "xmlExport.hxx"
#include "xmlAutoStyle.hxx"
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmluconv.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/txtprmap.hxx>
#include <xmloff/numehelp.hxx>
#include "xmlHelper.hxx"
#include <strings.hxx>
#include "xmlPropertyHandler.hxx"
#include <com/sun/star/util/NumberFormat.hpp>
#include <com/sun/star/util/MeasureUnit.hpp>
#include <com/sun/star/report/GroupOn.hpp>
#include <com/sun/star/report/XFixedText.hpp>
#include <com/sun/star/report/XImageControl.hpp>
#include <com/sun/star/report/XShape.hpp>
#include <com/sun/star/report/XFunction.hpp>
#include <com/sun/star/awt/FontDescriptor.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/table/BorderLineStyle.hpp>
#include <com/sun/star/report/XFixedLine.hpp>
#include <RptDef.hxx>
#include <vcl/svapp.hxx>
#include <osl/diagnose.h>
#include <tools/color.hxx>
#include <iterator>
#define DEFAULT_LINE_WIDTH 2
namespace rptxml
{
using namespace xmloff;
using namespace comphelper;
using namespace ::com::sun::star;
using namespace ::com::sun::star::report;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::xml;
Reference< XInterface > ORptExportHelper::create(Reference< XComponentContext > const & xContext)
{
return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), SvXMLExportFlags::SETTINGS ));
}
OUString ORptExportHelper::getImplementationName_Static( )
{
return "com.sun.star.comp.report.XMLSettingsExporter";
}
Sequence< OUString > ORptExportHelper::getSupportedServiceNames_Static( )
{
Sequence< OUString > aSupported { "com.sun.star.document.ExportFilter" };
return aSupported;
}
Reference< XInterface > ORptContentExportHelper::create(Reference< XComponentContext > const & xContext)
{
return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), SvXMLExportFlags::CONTENT ));
}
OUString ORptContentExportHelper::getImplementationName_Static( )
{
return "com.sun.star.comp.report.XMLContentExporter";
}
Sequence< OUString > ORptContentExportHelper::getSupportedServiceNames_Static( )
{
Sequence< OUString > aSupported { "com.sun.star.document.ExportFilter" };
return aSupported;
}
Reference< XInterface > ORptStylesExportHelper::create(Reference< XComponentContext > const & xContext)
{
return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), SvXMLExportFlags::STYLES | SvXMLExportFlags::MASTERSTYLES | SvXMLExportFlags::AUTOSTYLES |
SvXMLExportFlags::FONTDECLS|SvXMLExportFlags::OASIS ));
}
OUString ORptStylesExportHelper::getImplementationName_Static( )
{
return "com.sun.star.comp.report.XMLStylesExporter";
}
Sequence< OUString > ORptStylesExportHelper::getSupportedServiceNames_Static( )
{
Sequence< OUString > aSupported { "com.sun.star.document.ExportFilter" };
return aSupported;
}
Reference< XInterface > ORptMetaExportHelper::create(Reference< XComponentContext > const & xContext)
{
return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), SvXMLExportFlags::META ));
}
OUString ORptMetaExportHelper::getImplementationName_Static( )
{
return "com.sun.star.comp.report.XMLMetaExporter";
}
Sequence< OUString > ORptMetaExportHelper::getSupportedServiceNames_Static( )
{
Sequence< OUString > aSupported { "com.sun.star.document.ExportFilter" };
return aSupported;
}
Reference< XInterface > ODBFullExportHelper::create(Reference< XComponentContext > const & xContext)
{
return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), SvXMLExportFlags::ALL));
}
OUString ODBFullExportHelper::getImplementationName_Static( )
{
return "com.sun.star.comp.report.XMLFullExporter";
}
Sequence< OUString > ODBFullExportHelper::getSupportedServiceNames_Static( )
{
Sequence< OUString > aSupported { "com.sun.star.document.ExportFilter" };
return aSupported;
}
namespace {
class OSpecialHandleXMLExportPropertyMapper : public SvXMLExportPropertyMapper
{
public:
explicit OSpecialHandleXMLExportPropertyMapper(const rtl::Reference< XMLPropertySetMapper >& rMapper) : SvXMLExportPropertyMapper(rMapper )
{
}
/** this method is called for every item that has the
MID_FLAG_SPECIAL_ITEM_EXPORT flag set */
virtual void handleSpecialItem(
SvXMLAttributeList& /*rAttrList*/,
const XMLPropertyState& /*rProperty*/,
const SvXMLUnitConverter& /*rUnitConverter*/,
const SvXMLNamespaceMap& /*rNamespaceMap*/,
const ::std::vector< XMLPropertyState >* /*pProperties*/ = nullptr,
sal_uInt32 /*nIdx*/ = 0 ) const override
{
// nothing to do here
}
};
}
static void lcl_adjustColumnSpanOverRows(ORptExport::TSectionsGrid& _rGrid)
{
for (auto& rEntry : _rGrid)
{
ORptExport::TGrid::iterator aRowIter = rEntry.second.begin();
ORptExport::TGrid::const_iterator aRowEnd = rEntry.second.end();
for (; aRowIter != aRowEnd; ++aRowIter)
{
if ( aRowIter->first )
{
sal_Int32 nColIndex = 0;
for (const auto& rCell : aRowIter->second)
{
if ( rCell.nRowSpan > 1 )
{
sal_Int32 nColSpan = rCell.nColSpan;
for (sal_Int32 i = 1; i < rCell.nRowSpan; ++i)
{
(aRowIter+i)->second[nColIndex].nColSpan = nColSpan;
}
}
++nColIndex;
}
}
}
}
}
ORptExport::ORptExport(const Reference< XComponentContext >& _rxContext, OUString const & implementationName, SvXMLExportFlags nExportFlag)
: SvXMLExport( util::MeasureUnit::MM_100TH, _rxContext, implementationName, XML_REPORT, SvXMLExportFlags::OASIS)
,m_bAllreadyFilled(false)
{
setExportFlags( SvXMLExportFlags::OASIS | nExportFlag);
GetMM100UnitConverter().SetCoreMeasureUnit(css::util::MeasureUnit::MM_100TH);
GetMM100UnitConverter().SetXMLMeasureUnit(css::util::MeasureUnit::CM);
// (getExportFlags() & EXPORT_CONTENT) != 0 ? : XML_N_OOO
GetNamespaceMap_().Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE ), XML_NAMESPACE_OFFICE );
GetNamespaceMap_().Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
GetNamespaceMap_().Add( GetXMLToken(XML_NP_RPT), GetXMLToken(XML_N_RPT), XML_NAMESPACE_REPORT );
GetNamespaceMap_().Add( GetXMLToken(XML_NP_SVG), GetXMLToken(XML_N_SVG_COMPAT), XML_NAMESPACE_SVG );
GetNamespaceMap_().Add( GetXMLToken(XML_NP_FORM), GetXMLToken(XML_N_FORM), XML_NAMESPACE_FORM );
GetNamespaceMap_().Add( GetXMLToken(XML_NP_DRAW), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW );
GetNamespaceMap_().Add( GetXMLToken(XML_NP_TEXT), GetXMLToken(XML_N_TEXT), XML_NAMESPACE_TEXT );
if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::FONTDECLS) )
GetNamespaceMap_().Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SCRIPTS|SvXMLExportFlags::SETTINGS) )
{
GetNamespaceMap_().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
}
if( getExportFlags() & SvXMLExportFlags::SETTINGS )
{
GetNamespaceMap_().Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG );
}
if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::FONTDECLS) )
{
GetNamespaceMap_().Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE );
}
// RDFa: needed for content and header/footer styles
if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
{
GetNamespaceMap_().Add( GetXMLToken(XML_NP_XHTML),GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
// loext, needed for paragraphs inside shapes
if (getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
{
GetNamespaceMap_().Add(
GetXMLToken(XML_NP_LO_EXT), GetXMLToken(XML_N_LO_EXT),
XML_NAMESPACE_LO_EXT);
}
}
// GRDDL: to convert RDFa and meta.xml to RDF
if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
{
GetNamespaceMap_().Add( GetXMLToken(XML_NP_GRDDL),GetXMLToken(XML_N_GRDDL), XML_NAMESPACE_GRDDL );
}
GetNamespaceMap_().Add( GetXMLToken(XML_NP_TABLE), GetXMLToken(XML_N_TABLE), XML_NAMESPACE_TABLE );
GetNamespaceMap_().Add( GetXMLToken(XML_NP_NUMBER), GetXMLToken(XML_N_NUMBER), XML_NAMESPACE_NUMBER );
m_sTableStyle = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_STYLE_NAME) );
m_sCellStyle = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_REPORT, GetXMLToken(XML_STYLE_NAME) );
m_xPropHdlFactory = new OXMLRptPropHdlFactory();
rtl::Reference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory();
rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper1 = new XMLPropertySetMapper(OXMLHelper::GetTableStyleProps(),xFac, true);
rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper2 = new XMLTextPropertySetMapper(TextPropMap::TABLE_DEFAULTS, true );
xTableStylesPropertySetMapper1->AddMapperEntry(xTableStylesPropertySetMapper2);
m_xTableStylesExportPropertySetMapper = new SvXMLExportPropertyMapper(xTableStylesPropertySetMapper1);
m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylePropertyMap( false, true);
m_xCellStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(m_xCellStylesPropertySetMapper);
m_xCellStylesExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(*this));
rtl::Reference < XMLPropertySetMapper > xColumnStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetColumnStyleProps(), m_xPropHdlFactory, true);
m_xColumnStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(xColumnStylesPropertySetMapper);
rtl::Reference < XMLPropertySetMapper > xRowStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetRowStyleProps(), m_xPropHdlFactory, true);
m_xRowStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(xRowStylesPropertySetMapper);
rtl::Reference < XMLPropertySetMapper > xPropMapper(new XMLTextPropertySetMapper( TextPropMap::PARA, true ));
m_xParaPropMapper = new OSpecialHandleXMLExportPropertyMapper( xPropMapper);
const OUString& sFamily( GetXMLToken(XML_PARAGRAPH) );
OUString aPrefix( 'P');
GetAutoStylePool()->AddFamily( XmlStyleFamily::TEXT_PARAGRAPH, sFamily,
m_xParaPropMapper, aPrefix );
GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_CELL, XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME,
m_xCellStylesExportPropertySetMapper, XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX);
GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_COLUMN, XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME,
m_xColumnStylesExportPropertySetMapper, XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX);
GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_ROW, XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME,
m_xRowStylesExportPropertySetMapper, XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX);
GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_TABLE, XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME,
m_xTableStylesExportPropertySetMapper, XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX);
}
Reference< XInterface > ORptExport::create(Reference< XComponentContext > const & xContext)
{
return *(new ORptExport(xContext, getImplementationName_Static(), SvXMLExportFlags::CONTENT | SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::FONTDECLS));
}
OUString ORptExport::getImplementationName_Static( )
{
return "com.sun.star.comp.report.ExportFilter";
}
uno::Sequence< OUString > ORptExport::getSupportedServiceNames_Static( )
{
uno::Sequence< OUString > aServices { "com.sun.star.document.ExportFilter" };
return aServices;
}
void ORptExport::exportFunctions(const Reference<XIndexAccess>& _xFunctions)
{
const sal_Int32 nCount = _xFunctions->getCount();
for (sal_Int32 i = 0; i< nCount; ++i)
{
uno::Reference< report::XFunction> xFunction(_xFunctions->getByIndex(i),uno::UNO_QUERY_THROW);
exportFunction(xFunction);
}
}
void ORptExport::exportFunction(const uno::Reference< XFunction>& _xFunction)
{
exportFormula(XML_FORMULA,_xFunction->getFormula());
beans::Optional< OUString> aInitial = _xFunction->getInitialFormula();
if ( aInitial.IsPresent && !aInitial.Value.isEmpty() )
exportFormula(XML_INITIAL_FORMULA ,aInitial.Value );
AddAttribute( XML_NAMESPACE_REPORT, XML_NAME , _xFunction->getName() );
if ( _xFunction->getPreEvaluated() )
AddAttribute( XML_NAMESPACE_REPORT, XML_PRE_EVALUATED , XML_TRUE );
if ( _xFunction->getDeepTraversing() )
AddAttribute( XML_NAMESPACE_REPORT, XML_DEEP_TRAVERSING , XML_TRUE );
SvXMLElementExport aFunction(*this,XML_NAMESPACE_REPORT, XML_FUNCTION, true, true);
}
void ORptExport::exportMasterDetailFields(const Reference<XReportComponent>& _xReportComponet)
{
const uno::Sequence< OUString> aMasterFields = _xReportComponet->getMasterFields();
if ( !aMasterFields.hasElements() )
return;
SvXMLElementExport aElement(*this,XML_NAMESPACE_REPORT, XML_MASTER_DETAIL_FIELDS, true, true);
const uno::Sequence< OUString> aDetailFields = _xReportComponet->getDetailFields();
OSL_ENSURE(aDetailFields.getLength() == aMasterFields.getLength(),"not equal length for master and detail fields!");
const OUString* pDetailFieldsIter = aDetailFields.getConstArray();
for(const OUString& rMasterField : aMasterFields)
{
AddAttribute( XML_NAMESPACE_REPORT, XML_MASTER , rMasterField );
if ( !pDetailFieldsIter->isEmpty() )
AddAttribute( XML_NAMESPACE_REPORT, XML_DETAIL , *pDetailFieldsIter );
SvXMLElementExport aPair(*this,XML_NAMESPACE_REPORT, XML_MASTER_DETAIL_FIELD, true, true);
++pDetailFieldsIter;
}
}
void ORptExport::exportReport(const Reference<XReportDefinition>& _xReportDefinition)
{
if ( !_xReportDefinition.is() )
return;
exportFunctions(_xReportDefinition->getFunctions().get());
exportGroupsExpressionAsFunction(_xReportDefinition->getGroups());
if ( _xReportDefinition->getReportHeaderOn() )
{
SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_REPORT_HEADER, true, true);
exportSection(_xReportDefinition->getReportHeader());
}
if ( _xReportDefinition->getPageHeaderOn() )
{
OUStringBuffer sValue;
sal_Int16 nRet = _xReportDefinition->getPageHeaderOption();
const SvXMLEnumMapEntry<sal_Int16>* aXML_EnumMap = OXMLHelper::GetReportPrintOptions();
if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) )
AddAttribute(XML_NAMESPACE_REPORT, XML_PAGE_PRINT_OPTION,sValue.makeStringAndClear());
SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_PAGE_HEADER, true, true);
exportSection(_xReportDefinition->getPageHeader(),true);
}
exportGroup(_xReportDefinition,0);
if ( _xReportDefinition->getPageFooterOn() )
{
OUStringBuffer sValue;
sal_Int16 nRet = _xReportDefinition->getPageFooterOption();
const SvXMLEnumMapEntry<sal_Int16>* aXML_EnumMap = OXMLHelper::GetReportPrintOptions();
if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) )
AddAttribute(XML_NAMESPACE_REPORT, XML_PAGE_PRINT_OPTION,sValue.makeStringAndClear());
SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_PAGE_FOOTER, true, true);
exportSection(_xReportDefinition->getPageFooter(),true);
}
if ( _xReportDefinition->getReportFooterOn() )
{
SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_REPORT_FOOTER, true, true);
exportSection(_xReportDefinition->getReportFooter());
}
}
void ORptExport::exportComponent(const Reference<XReportComponent>& _xReportComponent)
{
OSL_ENSURE(_xReportComponent.is(),"No component interface!");
if ( !_xReportComponent.is() )
return;
AddAttribute(XML_NAMESPACE_DRAW, XML_NAME,_xReportComponent->getName());
SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_REPORT_COMPONENT, false, false);
}
void ORptExport::exportFormatConditions(const Reference<XReportControlModel>& _xReportElement)
{
OSL_ENSURE(_xReportElement.is(),"_xReportElement is NULL -> GPF");
const sal_Int32 nCount = _xReportElement->getCount();
try
{
for (sal_Int32 i = 0; i < nCount ; ++i)
{
uno::Reference< report::XFormatCondition > xCond(_xReportElement->getByIndex(i),uno::UNO_QUERY);
if ( !xCond->getEnabled() )
AddAttribute(XML_NAMESPACE_REPORT, XML_ENABLED,XML_FALSE);
AddAttribute(XML_NAMESPACE_REPORT, XML_FORMULA,xCond->getFormula());
exportStyleName(xCond.get(),GetAttrList(),m_sCellStyle);
SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_FORMAT_CONDITION, true, true);
}
}
catch(uno::Exception&)
{
OSL_FAIL("Can not access format condition!");
}
}
void ORptExport::exportReportElement(const Reference<XReportControlModel>& _xReportElement)
{
OSL_ENSURE(_xReportElement.is(),"_xReportElement is NULL -> GPF");
if ( !_xReportElement->getPrintWhenGroupChange() )
AddAttribute(XML_NAMESPACE_REPORT, XML_PRINT_WHEN_GROUP_CHANGE, XML_FALSE );
if ( !_xReportElement->getPrintRepeatedValues() )
AddAttribute(XML_NAMESPACE_REPORT, XML_PRINT_REPEATED_VALUES,XML_FALSE);
SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_REPORT_ELEMENT, true, true);
if ( _xReportElement->getCount() )
{
exportFormatConditions(_xReportElement);
}
OUString sExpr = _xReportElement->getConditionalPrintExpression();
if ( !sExpr.isEmpty() )
{
exportFormula(XML_FORMULA,sExpr);
SvXMLElementExport aPrintExpr(*this,XML_NAMESPACE_REPORT, XML_CONDITIONAL_PRINT_EXPRESSION, true, true);
}
// only export when parent exists
uno::Reference< report::XSection> xParent(_xReportElement->getParent(),uno::UNO_QUERY);
if ( xParent.is() )
exportComponent(_xReportElement.get());
}
static void lcl_calculate(const ::std::vector<sal_Int32>& _aPosX,const ::std::vector<sal_Int32>& _aPosY,ORptExport::TGrid& _rColumns)
{
sal_Int32 nCountX = _aPosX.size() - 1;
sal_Int32 nCountY = _aPosY.size() - 1;
for (sal_Int32 j = 0; j < nCountY; ++j)
{
sal_Int32 nHeight = _aPosY[j+1] - _aPosY[j];
if ( nHeight )
for (sal_Int32 i = 0; i < nCountX ; ++i)
{
_rColumns[j].second[i] = ORptExport::TCell(1,1);
_rColumns[j].second[i].bSet = true;
}
}
}
void ORptExport::collectStyleNames(XmlStyleFamily _nFamily,const ::std::vector< sal_Int32>& _aSize, std::vector<OUString>& _rStyleNames)
{
::std::vector< XMLPropertyState > aPropertyStates;
aPropertyStates.emplace_back(0);
::std::vector<sal_Int32>::const_iterator aIter = _aSize.begin();
::std::vector<sal_Int32>::const_iterator aIter2 = aIter + 1;
::std::vector<sal_Int32>::const_iterator aEnd = _aSize.end();
for (;aIter2 != aEnd ; ++aIter,++aIter2)
{
sal_Int32 nValue = static_cast<sal_Int32>(*aIter2 - *aIter);
aPropertyStates[0].maValue <<= nValue;
_rStyleNames.push_back(GetAutoStylePool()->Add(_nFamily, aPropertyStates ));
}
}
void ORptExport::collectStyleNames(XmlStyleFamily _nFamily, const ::std::vector< sal_Int32>& _aSize, const ::std::vector< sal_Int32>& _aSizeAutoGrow, std::vector<OUString>& _rStyleNames)
{
::std::vector< XMLPropertyState > aPropertyStates;
aPropertyStates.emplace_back(0);
::std::vector<sal_Int32>::const_iterator aIter = _aSize.begin();
::std::vector<sal_Int32>::const_iterator aIter2 = aIter + 1;
::std::vector<sal_Int32>::const_iterator aEnd = _aSize.end();
for (;aIter2 != aEnd; ++aIter, ++aIter2)
{
sal_Int32 nValue = static_cast<sal_Int32>(*aIter2 - *aIter);
aPropertyStates[0].maValue <<= nValue;
// note: there cannot be 0-height rows, because a call to std::unique has removed them
// it cannot be predicted that the size of _aSizeAutoGrow has any relation to the size of
// _aSize, because of the same std::unique operation (and _aSizeAutoGrow wasn't even the same
// size before that), so the matching element in _aSizeAutoGrow has to be found by lookup.
::std::vector<sal_Int32>::const_iterator aAutoGrow = ::std::find(_aSizeAutoGrow.begin(), _aSizeAutoGrow.end(), *aIter2);
bool bAutoGrow = aAutoGrow != _aSizeAutoGrow.end();
// the mnIndex is into the array returned by OXMLHelper::GetRowStyleProps()
aPropertyStates[0].mnIndex = bAutoGrow ? 1 : 0;
_rStyleNames.push_back(GetAutoStylePool()->Add(_nFamily, aPropertyStates));
}
}
void ORptExport::exportSectionAutoStyle(const Reference<XSection>& _xProp)
{
OSL_ENSURE(_xProp != nullptr,"Section is NULL -> GPF");
exportAutoStyle(_xProp);
Reference<XReportDefinition> xReport = _xProp->getReportDefinition();
const awt::Size aSize = rptui::getStyleProperty<awt::Size>(xReport,PROPERTY_PAPERSIZE);
const sal_Int32 nOffset = rptui::getStyleProperty<sal_Int32>(xReport,PROPERTY_LEFTMARGIN);
const sal_Int32 nCount = _xProp->getCount();
::std::vector<sal_Int32> aColumnPos;
aColumnPos.reserve(2*(nCount + 1));
aColumnPos.push_back(nOffset);
aColumnPos.push_back(aSize.Width - rptui::getStyleProperty<sal_Int32>(xReport,PROPERTY_RIGHTMARGIN));
::std::vector<sal_Int32> aRowPos;
aRowPos.reserve(2*(nCount + 1));
aRowPos.push_back(0);
aRowPos.push_back(_xProp->getHeight());
::std::vector<sal_Int32> aRowPosAutoGrow;
aRowPosAutoGrow.reserve(2 * (nCount + 1));
sal_Int32 i;
for (i = 0 ; i< nCount ; ++i)
{
Reference<XReportComponent> xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY);
uno::Reference< XShape> xShape(xReportElement,uno::UNO_QUERY);
if ( xShape.is() )
continue;
OSL_ENSURE( xReportElement.is(),"NULL Element in Section!" );
if ( !xReportElement.is() )
continue;
sal_Int32 nX = xReportElement->getPositionX();
aColumnPos.push_back(nX);
Reference<XFixedLine> xFixedLine(xReportElement,uno::UNO_QUERY);
if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
{
sal_Int32 nWidth = static_cast<sal_Int32>(xReportElement->getWidth()*0.5);
nX += nWidth;
aColumnPos.push_back(nX);
nX += xReportElement->getWidth() - nWidth;
}
else
nX += xReportElement->getWidth();
aColumnPos.push_back(nX); // --nX why?
sal_Int32 nY = xReportElement->getPositionY();
aRowPos.push_back(nY);
nY += xReportElement->getHeight();
aRowPos.push_back(nY); // --nY why?
bool bAutoGrow = xReportElement->getAutoGrow();
if (bAutoGrow)
{
// the resulting table row ending at nY should auto-grow
aRowPosAutoGrow.push_back(nY);
}
}
::std::sort(aColumnPos.begin(),aColumnPos.end(),::std::less<sal_Int32>());
aColumnPos.erase(::std::unique(aColumnPos.begin(),aColumnPos.end()),aColumnPos.end());
// note: the aRowPos contains top and bottom position of every report control; we now compute the
// top of every row in the resulting table, by sorting and eliminating unnecessary duplicate
// positions. (the same for the columns in the preceding lines.)
::std::sort(aRowPos.begin(),aRowPos.end(),::std::less<sal_Int32>());
aRowPos.erase(::std::unique(aRowPos.begin(),aRowPos.end()),aRowPos.end());
TSectionsGrid::iterator aInsert = m_aSectionsGrid.emplace(
_xProp.get(),
TGrid(aRowPos.size() - 1,TGrid::value_type(false,TRow(aColumnPos.size() - 1)))
).first;
lcl_calculate(aColumnPos,aRowPos,aInsert->second);
TGridStyleMap::iterator aPos = m_aColumnStyleNames.emplace(_xProp.get(),std::vector<OUString>()).first;
collectStyleNames(XmlStyleFamily::TABLE_COLUMN,aColumnPos,aPos->second);
aPos = m_aRowStyleNames.emplace(_xProp.get(),std::vector<OUString>()).first;
collectStyleNames(XmlStyleFamily::TABLE_ROW, aRowPos, aRowPosAutoGrow, aPos->second);
sal_Int32 x1 = 0;
sal_Int32 y1 = 0;
sal_Int32 x2 = 0;
sal_Int32 y2 = 0;
sal_Int32 xi = 0;
sal_Int32 yi = 0;
bool isOverlap = false;
for (i = 0 ; i< nCount ; ++i)
{
Reference<XReportComponent> xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY);
uno::Reference< XShape> xShape(xReportElement,uno::UNO_QUERY);
if ( xShape.is() )
continue;
sal_Int32 nPos = xReportElement->getPositionX();
x1 = (::std::find(aColumnPos.begin(),aColumnPos.end(),nPos) - aColumnPos.begin());
Reference<XFixedLine> xFixedLine(xReportElement,uno::UNO_QUERY);
if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
nPos += static_cast<sal_Int32>(xReportElement->getWidth()*0.5);
else
nPos += xReportElement->getWidth(); // -1 why
x2 = (::std::find(aColumnPos.begin(),aColumnPos.end(),nPos) - aColumnPos.begin());
nPos = xReportElement->getPositionY();
y1 = (::std::find(aRowPos.begin(),aRowPos.end(),nPos) - aRowPos.begin());
nPos += xReportElement->getHeight(); // -1 why?
y2 = (::std::find(aRowPos.begin(),aRowPos.end(),nPos) - aRowPos.begin());
isOverlap = false;
yi = y1;
while(yi < y2 && !isOverlap) // find overlapping controls
{
xi = x1;
while(xi < x2 && !isOverlap)
{
if ( aInsert->second[yi].second[xi].xElement.is() )
{
isOverlap = true;
}
++xi;
}
++yi;
}
if (!isOverlap)
{
yi = y1;
while(yi < y2)
{
xi = x1;
while(xi < x2)
{
aInsert->second[yi].second[xi] = TCell();
++xi;
}
aInsert->second[yi].first = true;
++yi;
}
if (x2 - x1 != 0 && y2 - y1 != 0)
{
sal_Int32 nColSpan = x2 - x1;
sal_Int32 nRowSpan = y2 - y1;
aInsert->second[y1].second[x1] =
TCell(
nColSpan,
nRowSpan,
xReportElement
);
}
}
}
lcl_adjustColumnSpanOverRows(m_aSectionsGrid);
exportReportComponentAutoStyles(_xProp);
}
void ORptExport::exportReportComponentAutoStyles(const Reference<XSection>& _xProp)
{
const sal_Int32 nCount = _xProp->getCount();
for (sal_Int32 i = 0 ; i< nCount ; ++i)
{
const Reference<XReportComponent> xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY);
const Reference< report::XShape > xShape(xReportElement,uno::UNO_QUERY);
if ( xShape.is() )
{
rtl::Reference< XMLShapeExport > xShapeExport = GetShapeExport();
xShapeExport->seekShapes(_xProp.get());
SolarMutexGuard aGuard;
xShapeExport->collectShapeAutoStyles(xShape.get());
}
else
{
exportAutoStyle(xReportElement.get());
Reference<XFormattedField> xFormattedField(xReportElement,uno::UNO_QUERY);
if ( xFormattedField.is() )
{
try
{
const sal_Int32 nFormatCount = xFormattedField->getCount();
for (sal_Int32 j = 0; j < nFormatCount ; ++j)
{
uno::Reference< report::XFormatCondition > xCond(xFormattedField->getByIndex(j),uno::UNO_QUERY);
exportAutoStyle(xCond.get(),xFormattedField);
}
}
catch(uno::Exception&)
{
OSL_FAIL("Can not access format condition!");
}
}
}
}
}
void ORptExport::exportSection(const Reference<XSection>& _xSection,bool bHeader)
{
OSL_ENSURE(_xSection.is(),"Section is NULL -> GPF");
OUStringBuffer sValue;
AddAttribute(XML_NAMESPACE_TABLE, XML_NAME,_xSection->getName());
if ( !_xSection->getVisible() )
AddAttribute(XML_NAMESPACE_REPORT, XML_VISIBLE,XML_FALSE);
if ( !bHeader )
{
sal_Int16 nRet = _xSection->getForceNewPage();
const SvXMLEnumMapEntry<sal_Int16>* aXML_EnumMap = OXMLHelper::GetForceNewPageOptions();
if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) )
AddAttribute(XML_NAMESPACE_REPORT, XML_FORCE_NEW_PAGE,sValue.makeStringAndClear());
nRet = _xSection->getNewRowOrCol();
if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) )
AddAttribute(XML_NAMESPACE_REPORT, XML_FORCE_NEW_COLUMN,sValue.makeStringAndClear());
if ( _xSection->getKeepTogether() )
AddAttribute(XML_NAMESPACE_REPORT, XML_KEEP_TOGETHER, XML_TRUE );
}
exportStyleName(_xSection.get(),GetAttrList(),m_sTableStyle);
/// TODO export as table layout
SvXMLElementExport aComponents(*this,XML_NAMESPACE_TABLE, XML_TABLE, true, true);
OUString sExpr = _xSection->getConditionalPrintExpression();
if ( !sExpr.isEmpty() )
{
exportFormula(XML_FORMULA,sExpr);
SvXMLElementExport aPrintExpr(*this,XML_NAMESPACE_REPORT, XML_CONDITIONAL_PRINT_EXPRESSION, true, false);
}
exportContainer(_xSection);
}
void ORptExport::exportTableColumns(const Reference< XSection>& _xSection)
{
SvXMLElementExport aColumns(*this,XML_NAMESPACE_TABLE, XML_TABLE_COLUMNS, true, true);
TGridStyleMap::const_iterator aColFind = m_aColumnStyleNames.find(_xSection.get());
OSL_ENSURE(aColFind != m_aColumnStyleNames.end(),"ORptExport::exportTableColumns: Section not found in m_aColumnStyleNames!");
if ( aColFind == m_aColumnStyleNames.end() )
return;
for (auto& aCol : aColFind->second)
{
AddAttribute(m_sTableStyle, aCol);
SvXMLElementExport aColumn(*this,XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, true, true);
}
}
void ORptExport::exportContainer(const Reference< XSection>& _xSection)
{
OSL_ENSURE(_xSection.is(),"Section is NULL -> GPF");
exportTableColumns(_xSection);
TSectionsGrid::const_iterator aFind = m_aSectionsGrid.find(_xSection.get());
OSL_ENSURE(aFind != m_aSectionsGrid.end(),"ORptExport::exportContainer: Section not found in grid!");
if ( aFind == m_aSectionsGrid.end() )
return;
TGrid::const_iterator aRowIter = aFind->second.begin();
TGrid::const_iterator aRowEnd = aFind->second.end();
TGridStyleMap::const_iterator aRowFind = m_aRowStyleNames.find(_xSection.get());
auto aHeightIter = aRowFind->second.cbegin();
OSL_ENSURE(aRowFind->second.size() == aFind->second.size(),"Different count for rows");
bool bShapeHandled = false;
::std::map<sal_Int32,sal_Int32> aRowSpan;
for (sal_Int32 j = 0; aRowIter != aRowEnd; ++aRowIter,++j,++aHeightIter)
{
AddAttribute( m_sTableStyle,*aHeightIter );
SvXMLElementExport aRow(*this,XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true);
if ( aRowIter->first )
{
::std::vector< TCell >::const_iterator aColIter = aRowIter->second.begin();
::std::vector< TCell >::const_iterator aColEnd = aRowIter->second.end();
sal_Int32 nEmptyCellColSpan = 0;
for (; aColIter != aColEnd; ++aColIter)
{
bool bCoveredCell = false;
sal_Int32 nColSpan = 0;
sal_Int32 nColIndex = aColIter - aRowIter->second.begin();
::std::map<sal_Int32,sal_Int32>::iterator aRowSpanFind = aRowSpan.find(nColIndex);
if ( aRowSpanFind != aRowSpan.end() )
{
nColSpan = 1;
if ( !--(aRowSpanFind->second) )
aRowSpan.erase(aRowSpanFind);
if ( aColIter->nColSpan > 1 )
nColSpan += aColIter->nColSpan - 1;
bCoveredCell = true;
aColIter = aColIter + (aColIter->nColSpan - 1);
}
else if ( aColIter->bSet )
{
if ( nEmptyCellColSpan > 0 )
{
AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED, OUString::number(nEmptyCellColSpan) );
bCoveredCell = true;
nColSpan = nEmptyCellColSpan - 1;
nEmptyCellColSpan = 0;
}
sal_Int32 nSpan = aColIter->nColSpan;
if ( nSpan > 1 )
{
AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED, OUString::number(nSpan) );
nColSpan = nSpan - 1;
bCoveredCell = true;
}
nSpan = aColIter->nRowSpan;
if ( nSpan > 1 )
{
AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_ROWS_SPANNED, OUString::number(nSpan) );
aRowSpan[nColIndex] = nSpan - 1;
}
if ( aColIter->xElement.is() )
exportStyleName(aColIter->xElement.get(),GetAttrList(),m_sTableStyle);
// start <table:table-cell>
Reference<XFormattedField> xFormattedField(aColIter->xElement,uno::UNO_QUERY);
if ( xFormattedField.is() )
{
sal_Int32 nFormatKey = xFormattedField->getFormatKey();
XMLNumberFormatAttributesExportHelper aHelper(GetNumberFormatsSupplier(),*this);
bool bIsStandard = false;
sal_Int16 nCellType = aHelper.GetCellType(nFormatKey,bIsStandard);
// "Standard" means "no format set, value could be anything",
// so don't set a format attribute in this case.
// P.S.: "Standard" is called "General" in some languages
if (!bIsStandard)
{
if ( nCellType == util::NumberFormat::TEXT )
aHelper.SetNumberFormatAttributes("", "");
else
aHelper.SetNumberFormatAttributes(nFormatKey, 0.0, false);
}
}
SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, false);
if ( aColIter->xElement.is() )
{
// start <text:p>
SvXMLElementExport aParagraphContent(*this,XML_NAMESPACE_TEXT, XML_P, true, false);
Reference<XServiceInfo> xElement(aColIter->xElement,uno::UNO_QUERY);
if ( !bShapeHandled )
{
bShapeHandled = true;
exportShapes(_xSection,false);
}
uno::Reference< XShape > xShape(xElement,uno::UNO_QUERY);
uno::Reference< XFixedLine > xFixedLine(xElement,uno::UNO_QUERY);
if ( !xShape.is() && !xFixedLine.is() )
{
Reference<XReportControlModel> xReportElement(xElement,uno::UNO_QUERY);
Reference<XReportDefinition> xReportDefinition(xElement,uno::UNO_QUERY);
Reference< XImageControl > xImage(xElement,uno::UNO_QUERY);
Reference<XSection> xSection(xElement,uno::UNO_QUERY);
XMLTokenEnum eToken = XML_SECTION;
bool bExportData = false;
if ( xElement->supportsService(SERVICE_FIXEDTEXT) )
{
eToken = XML_FIXED_CONTENT;
}
else if ( xElement->supportsService(SERVICE_FORMATTEDFIELD) )
{
eToken = XML_FORMATTED_TEXT;
bExportData = true;
}
else if ( xElement->supportsService(SERVICE_IMAGECONTROL) )
{
eToken = XML_IMAGE;
OUString sTargetLocation = xImage->getImageURL();
if ( !sTargetLocation.isEmpty() )
{
sTargetLocation = GetRelativeReference(sTargetLocation);
AddAttribute(XML_NAMESPACE_FORM, XML_IMAGE_DATA,sTargetLocation);
}
bExportData = true;
OUStringBuffer sValue;
const SvXMLEnumMapEntry<sal_Int16>* aXML_ImageScaleEnumMap = OXMLHelper::GetImageScaleOptions();
if ( SvXMLUnitConverter::convertEnum( sValue, xImage->getScaleMode(),aXML_ImageScaleEnumMap ) )
AddAttribute(XML_NAMESPACE_REPORT, XML_SCALE, sValue.makeStringAndClear() );
}
else if ( xReportDefinition.is() )
{
eToken = XML_SUB_DOCUMENT;
}
if ( bExportData )
{
const bool bPageSet = exportFormula(XML_FORMULA,xReportElement->getDataField());
if ( bPageSet )
eToken = XML_FIXED_CONTENT;
else if ( eToken == XML_IMAGE )
AddAttribute(XML_NAMESPACE_REPORT, XML_PRESERVE_IRI, xImage->getPreserveIRI() ? XML_TRUE : XML_FALSE );
}
{
// start <report:eToken>
SvXMLElementExport aComponents(*this,XML_NAMESPACE_REPORT, eToken, false, false);
if ( eToken == XML_FIXED_CONTENT )
exportParagraph(xReportElement);
if ( xReportElement.is() )
exportReportElement(xReportElement);
if (eToken == XML_SUB_DOCUMENT && xReportDefinition.is())
{
SvXMLElementExport aOfficeElement( *this, XML_NAMESPACE_OFFICE, XML_BODY, true, true );
SvXMLElementExport aElem( *this, true,
XML_NAMESPACE_OFFICE, XML_REPORT,
true, true );
exportReportAttributes(xReportDefinition);
exportReport(xReportDefinition);
}
else if ( xSection.is() )
exportSection(xSection);
}
}
}
else if ( !bShapeHandled )
{
bShapeHandled = true;
exportShapes(_xSection);
}
aColIter = aColIter + (aColIter->nColSpan - 1);
}
else
++nEmptyCellColSpan;
if ( bCoveredCell )
{
for (sal_Int32 k = 0; k < nColSpan; ++k)
{
SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true);
}
}
}
if ( nEmptyCellColSpan )
{
{
AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED, OUString::number(nEmptyCellColSpan) );
SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
if ( !bShapeHandled )
{
bShapeHandled = true;
exportShapes(_xSection);
}
}
for (sal_Int32 k = 0; k < nEmptyCellColSpan; ++k)
{
SvXMLElementExport aCoveredCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true);
}
}
}
else
{ // empty rows
sal_Int32 nEmptyCellColSpan = aRowIter->second.size();
if ( nEmptyCellColSpan )
{
{
AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED, OUString::number(nEmptyCellColSpan) );
SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
if ( !bShapeHandled )
{
bShapeHandled = true;
exportShapes(_xSection);
}
}
for (sal_Int32 k = 1; k < nEmptyCellColSpan; ++k)
{
SvXMLElementExport aCoveredCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true);
}
}
}
}
}
OUString ORptExport::convertFormula(const OUString& _sFormula)
{
OUString sFormula = _sFormula;
if ( _sFormula == "rpt:" )
sFormula.clear();
return sFormula;
}
bool ORptExport::exportFormula(enum ::xmloff::token::XMLTokenEnum eName,const OUString& _sFormula)
{
const OUString sFieldData = convertFormula(_sFormula);
sal_Int32 nPageNumberIndex = sFieldData.indexOf("PageNumber()");
sal_Int32 nPageCountIndex = sFieldData.indexOf("PageCount()");
bool bRet = nPageNumberIndex != -1 || nPageCountIndex != -1;
if ( !bRet )
AddAttribute(XML_NAMESPACE_REPORT, eName,sFieldData);
return bRet;
}
void ORptExport::exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt,const OUString& _sName)
{
Reference<XPropertySet> xFind(_xProp);
TPropertyStyleMap::const_iterator aFind = m_aAutoStyleNames.find(xFind);
if ( aFind != m_aAutoStyleNames.end() )
{
_rAtt.AddAttribute( _sName,
aFind->second );
m_aAutoStyleNames.erase(aFind);
}
}
void ORptExport::exportGroup(const Reference<XReportDefinition>& _xReportDefinition,sal_Int32 _nPos,bool _bExportAutoStyle)
{
if ( !_xReportDefinition.is() )
return;
Reference< XGroups > xGroups = _xReportDefinition->getGroups();
if ( !xGroups.is() )
return;
sal_Int32 nCount = xGroups->getCount();
if ( _nPos >= 0 && _nPos < nCount )
{
Reference<XGroup> xGroup(xGroups->getByIndex(_nPos),uno::UNO_QUERY);
OSL_ENSURE(xGroup.is(),"No Group prepare for GPF");
if ( _bExportAutoStyle )
{
if ( xGroup->getHeaderOn() )
exportSectionAutoStyle(xGroup->getHeader());
exportGroup(_xReportDefinition,_nPos+1,_bExportAutoStyle);
if ( xGroup->getFooterOn() )
exportSectionAutoStyle(xGroup->getFooter());
}
else
{
if ( xGroup->getSortAscending() )
AddAttribute(XML_NAMESPACE_REPORT, XML_SORT_ASCENDING, XML_TRUE );
if ( xGroup->getStartNewColumn() )
AddAttribute(XML_NAMESPACE_REPORT, XML_START_NEW_COLUMN, XML_TRUE);
if ( xGroup->getResetPageNumber() )
AddAttribute(XML_NAMESPACE_REPORT, XML_RESET_PAGE_NUMBER, XML_TRUE );
const OUString sField = xGroup->getExpression();
OUString sExpression = sField;
if ( !sExpression.isEmpty() )
{
sal_Int32 nIndex = sExpression.indexOf('"');
while ( nIndex > -1 )
{
sExpression = sExpression.replaceAt(nIndex, 1, "\"\"");
nIndex = sExpression.indexOf('"',nIndex+2);
}
TGroupFunctionMap::const_iterator aGroupFind = m_aGroupFunctionMap.find(xGroup);
if ( aGroupFind != m_aGroupFunctionMap.end() )
sExpression = aGroupFind->second->getName();
sExpression = "rpt:HASCHANGED(\"" + sExpression + "\")";
}
AddAttribute(XML_NAMESPACE_REPORT, XML_SORT_EXPRESSION, sField);
AddAttribute(XML_NAMESPACE_REPORT, XML_GROUP_EXPRESSION,sExpression);
sal_Int16 nRet = xGroup->getKeepTogether();
OUStringBuffer sValue;
const SvXMLEnumMapEntry<sal_Int16>* aXML_KeepTogetherEnumMap = OXMLHelper::GetKeepTogetherOptions();
if ( SvXMLUnitConverter::convertEnum( sValue, nRet, aXML_KeepTogetherEnumMap ) )
AddAttribute(XML_NAMESPACE_REPORT, XML_KEEP_TOGETHER,sValue.makeStringAndClear());
SvXMLElementExport aGroup(*this,XML_NAMESPACE_REPORT, XML_GROUP, true, true);
exportFunctions(xGroup->getFunctions().get());
if ( xGroup->getHeaderOn() )
{
Reference<XSection> xSection = xGroup->getHeader();
if ( xSection->getRepeatSection() )
AddAttribute(XML_NAMESPACE_REPORT, XML_REPEAT_SECTION,XML_TRUE );
SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_GROUP_HEADER, true, true);
exportSection(xSection);
}
exportGroup(_xReportDefinition,_nPos+1,_bExportAutoStyle);
if ( xGroup->getFooterOn() )
{
Reference<XSection> xSection = xGroup->getFooter();
if ( xSection->getRepeatSection() )
AddAttribute(XML_NAMESPACE_REPORT, XML_REPEAT_SECTION,XML_TRUE );
SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_GROUP_FOOTER, true, true);
exportSection(xSection);
}
}
}
else if ( _bExportAutoStyle )
{
exportSectionAutoStyle(_xReportDefinition->getDetail());
}
else
{
SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_DETAIL, true, true);
exportSection(_xReportDefinition->getDetail());
}
}
void ORptExport::exportAutoStyle(XPropertySet* _xProp,const Reference<XFormattedField>& _xParentFormattedField)
{
const uno::Reference<report::XReportControlFormat> xFormat(_xProp,uno::UNO_QUERY);
if ( xFormat.is() )
{
try
{
const awt::FontDescriptor aFont = xFormat->getFontDescriptor();
OSL_ENSURE(!aFont.Name.isEmpty(),"No Font Name !");
GetFontAutoStylePool()->Add(aFont.Name,aFont.StyleName,static_cast<FontFamily>(aFont.Family),
static_cast<FontPitch>(aFont.Pitch),aFont.CharSet );
}
catch(beans::UnknownPropertyException&)
{
// not interested in
}
}
const uno::Reference< report::XShape> xShape(_xProp,uno::UNO_QUERY);
if ( xShape.is() )
{
::std::vector< XMLPropertyState > aPropertyStates( m_xParaPropMapper->Filter(_xProp) );
if ( !aPropertyStates.empty() )
m_aAutoStyleNames.emplace( _xProp,GetAutoStylePool()->Add( XmlStyleFamily::TEXT_PARAGRAPH, aPropertyStates ));
}
::std::vector< XMLPropertyState > aPropertyStates( m_xCellStylesExportPropertySetMapper->Filter(_xProp) );
Reference<XFixedLine> xFixedLine(_xProp,uno::UNO_QUERY);
if ( xFixedLine.is() )
{
uno::Reference<beans::XPropertySet> xBorderProp = OXMLHelper::createBorderPropertySet();
table::BorderLine2 aValue;
aValue.Color = sal_uInt32(COL_BLACK);
aValue.InnerLineWidth = aValue.LineDistance = 0;
aValue.OuterLineWidth = DEFAULT_LINE_WIDTH;
aValue.LineStyle = table::BorderLineStyle::SOLID;
aValue.LineWidth = DEFAULT_LINE_WIDTH;
awt::Point aPos = xFixedLine->getPosition();
awt::Size aSize = xFixedLine->getSize();
sal_Int32 nSectionHeight = xFixedLine->getSection()->getHeight();
OUString sBorderProp;
::std::vector< OUString> aProps;
if ( xFixedLine->getOrientation() == 1 ) // vertical
{
// check if border should be left
if ( !aPos.X )
{
sBorderProp = PROPERTY_BORDERLEFT;
aProps.emplace_back(PROPERTY_BORDERRIGHT);
}
else
{
sBorderProp = PROPERTY_BORDERRIGHT;
aProps.emplace_back(PROPERTY_BORDERLEFT);
}
aProps.emplace_back(PROPERTY_BORDERTOP);
aProps.emplace_back(PROPERTY_BORDERBOTTOM);
}
else // horizontal
{
// check if border should be bottom
if ( (aPos.Y + aSize.Height) == nSectionHeight )
{
sBorderProp = PROPERTY_BORDERBOTTOM;
aProps.emplace_back(PROPERTY_BORDERTOP);
}
else
{
sBorderProp = PROPERTY_BORDERTOP;
aProps.emplace_back(PROPERTY_BORDERBOTTOM);
}
aProps.emplace_back(PROPERTY_BORDERRIGHT);
aProps.emplace_back(PROPERTY_BORDERLEFT);
}
xBorderProp->setPropertyValue(sBorderProp,uno::makeAny(aValue));
aValue.Color = aValue.OuterLineWidth = aValue.LineWidth = 0;
aValue.LineStyle = table::BorderLineStyle::NONE;
uno::Any aEmpty;
aEmpty <<= aValue;
for (auto const& it : aProps)
{
xBorderProp->setPropertyValue(it, aEmpty);
}
::std::vector< XMLPropertyState > aBorderStates(m_xCellStylesExportPropertySetMapper->Filter(xBorderProp));
::std::copy(aBorderStates.begin(),aBorderStates.end(),::std::back_inserter(aPropertyStates));
}
else
{
const Reference<XFormattedField> xFormattedField(_xProp,uno::UNO_QUERY);
if ( (_xParentFormattedField.is() || xFormattedField.is()) && !aPropertyStates.empty() )
{
sal_Int32 nNumberFormat = 0;
if ( _xParentFormattedField.is() )
nNumberFormat = _xParentFormattedField->getFormatKey();
else
nNumberFormat = xFormattedField->getFormatKey();
{
sal_Int32 nStyleMapIndex = m_xCellStylesExportPropertySetMapper->getPropertySetMapper()->FindEntryIndex( CTF_RPT_NUMBERFORMAT );
addDataStyle(nNumberFormat);
XMLPropertyState aNumberStyleState( nStyleMapIndex, uno::makeAny( getDataStyleName(nNumberFormat) ) );
auto const iter(::std::find_if(
aPropertyStates.begin(), aPropertyStates.end(),
[nStyleMapIndex] (XMLPropertyState const& rItem)
{ return rItem.mnIndex == nStyleMapIndex; } ));
if (iter == aPropertyStates.end())
{
aPropertyStates.push_back( aNumberStyleState );
}
else
{ // there is already a property but it has the wrong type
// (integer not string); TODO: can we prevent it
// getting added earlier?
(*iter) = aNumberStyleState;
}
}
}
}
if ( !aPropertyStates.empty() )
m_aAutoStyleNames.emplace( _xProp,GetAutoStylePool()->Add( XmlStyleFamily::TABLE_CELL, aPropertyStates ));
}
void ORptExport::exportAutoStyle(const Reference<XSection>& _xProp)
{
::std::vector< XMLPropertyState > aPropertyStates( m_xTableStylesExportPropertySetMapper->Filter(_xProp.get()) );
if ( !aPropertyStates.empty() )
m_aAutoStyleNames.emplace( _xProp.get(),GetAutoStylePool()->Add( XmlStyleFamily::TABLE_TABLE, aPropertyStates ));
}
void ORptExport::SetBodyAttributes()
{
Reference<XReportDefinition> xProp(getReportDefinition());
exportReportAttributes(xProp);
}
void ORptExport::exportReportAttributes(const Reference<XReportDefinition>& _xReport)
{
if ( !_xReport.is() )
return;
OUStringBuffer sValue;
const SvXMLEnumMapEntry<sal_Int32>* aXML_CommnadTypeEnumMap = OXMLHelper::GetCommandTypeOptions();
if ( SvXMLUnitConverter::convertEnum( sValue, _xReport->getCommandType(), aXML_CommnadTypeEnumMap ) )
AddAttribute(XML_NAMESPACE_REPORT, XML_COMMAND_TYPE,sValue.makeStringAndClear());
OUString sComamnd = _xReport->getCommand();
if ( !sComamnd.isEmpty() )
AddAttribute(XML_NAMESPACE_REPORT, XML_COMMAND, sComamnd);
OUString sFilter( _xReport->getFilter() );
if ( !sFilter.isEmpty() )
AddAttribute( XML_NAMESPACE_REPORT, XML_FILTER, sFilter );
AddAttribute(XML_NAMESPACE_OFFICE, XML_MIMETYPE,_xReport->getMimeType());
bool bEscapeProcessing( _xReport->getEscapeProcessing() );
if ( !bEscapeProcessing )
AddAttribute( XML_NAMESPACE_REPORT, XML_ESCAPE_PROCESSING, ::xmloff::token::GetXMLToken( XML_FALSE ) );
OUString sName = _xReport->getCaption();
if ( !sName.isEmpty() )
AddAttribute(XML_NAMESPACE_OFFICE, XML_CAPTION,sName);
sName = _xReport->getName();
if ( !sName.isEmpty() )
AddAttribute(XML_NAMESPACE_DRAW, XML_NAME,sName);
}
void ORptExport::ExportContent_()
{
exportReport(getReportDefinition());
}
void ORptExport::ExportMasterStyles_()
{
GetPageExport()->exportMasterStyles( true );
}
void ORptExport::collectComponentStyles()
{
if ( m_bAllreadyFilled )
return;
m_bAllreadyFilled = true;
Reference<XReportDefinition> xProp(getReportDefinition());
if ( !xProp.is() )
return;
uno::Reference< report::XSection> xParent(xProp->getParent(),uno::UNO_QUERY);
if ( xParent.is() )
exportAutoStyle(xProp.get());
if ( xProp->getReportHeaderOn() )
exportSectionAutoStyle(xProp->getReportHeader());
if ( xProp->getPageHeaderOn() )
exportSectionAutoStyle(xProp->getPageHeader());
exportGroup(xProp,0,true);
if ( xProp->getPageFooterOn() )
exportSectionAutoStyle(xProp->getPageFooter());
if ( xProp->getReportFooterOn() )
exportSectionAutoStyle(xProp->getReportFooter());
}
void ORptExport::ExportAutoStyles_()
{
// there are no styles that require their own autostyles
if ( getExportFlags() & SvXMLExportFlags::CONTENT )
{
collectComponentStyles();
GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_TABLE);
GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_COLUMN);
GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_ROW);
GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_CELL);
exportDataStyles();
GetShapeExport()->exportAutoStyles();
}
// exported in _ExportMasterStyles
if( getExportFlags() & SvXMLExportFlags::MASTERSTYLES )
GetPageExport()->collectAutoStyles( false );
if( getExportFlags() & SvXMLExportFlags::MASTERSTYLES )
GetPageExport()->exportAutoStyles();
}
void ORptExport::ExportStyles_(bool bUsed)
{
SvXMLExport::ExportStyles_(bUsed);
// write draw:style-name for object graphic-styles
GetShapeExport()->ExportGraphicDefaults();
}
SvXMLAutoStylePoolP* ORptExport::CreateAutoStylePool()
{
return new OXMLAutoStylePoolP(*this);
}
void SAL_CALL ORptExport::setSourceDocument( const Reference< XComponent >& xDoc )
{
m_xReportDefinition.set(xDoc,UNO_QUERY_THROW);
SvXMLExport::setSourceDocument(xDoc);
}
void ORptExport::ExportFontDecls_()
{
GetFontAutoStylePool(); // make sure the pool is created
collectComponentStyles();
SvXMLExport::ExportFontDecls_();
}
void ORptExport::exportParagraph(const Reference< XReportControlModel >& _xReportElement)
{
OSL_PRECOND(_xReportElement.is(),"Element is null!");
// start <text:p>
SvXMLElementExport aParagraphContent(*this,XML_NAMESPACE_TEXT, XML_P, false, false);
if ( Reference<XFormattedField>(_xReportElement,uno::UNO_QUERY).is() )
{
OUString sFieldData = _xReportElement->getDataField();
static const char s_sPageNumber[] = "PageNumber()";
static const char s_sReportPrefix[] = "rpt:";
sFieldData = sFieldData.copy(strlen(s_sReportPrefix));<--- Argument 'strlen(s_sReportPrefix)' to function copy is always 4
sal_Int32 nPageNumberIndex = sFieldData.indexOf(s_sPageNumber);
if ( nPageNumberIndex != -1 )
{
sal_Int32 nIndex = 0;
do
{
OUString sToken = sFieldData.getToken( 0, '&', nIndex );
sToken = sToken.trim();
if ( !sToken.isEmpty() )
{
if ( sToken == s_sPageNumber )
{
AddAttribute(XML_NAMESPACE_TEXT, XML_SELECT_PAGE, "current" );
SvXMLElementExport aPageNumber(*this,XML_NAMESPACE_TEXT, XML_PAGE_NUMBER, false, false);
Characters("1");
}
else if ( sToken == "PageCount()" )
{
SvXMLElementExport aPageNumber(*this,XML_NAMESPACE_TEXT, XML_PAGE_COUNT, false, false);
Characters("1");
}
else
{
if ( sToken.startsWith("\"") && sToken.endsWith("\"") )
sToken = sToken.copy(1,sToken.getLength()-2);
bool bPrevCharIsSpace = false;
GetTextParagraphExport()->exportCharacterData(sToken, bPrevCharIsSpace);
}
}
}
while ( nIndex >= 0 );
}
}
Reference< XFixedText > xFT(_xReportElement,UNO_QUERY);
if ( xFT.is() )
{
OUString sExpr = xFT->getLabel();
bool bPrevCharIsSpace = false; // FIXME this looks quite broken - does the corresponding import filter do whitespace collapsing at all?
GetTextParagraphExport()->exportCharacterData(sExpr, bPrevCharIsSpace);
}
}
XMLShapeExport* ORptExport::CreateShapeExport()<--- The function 'CreateShapeExport' is never used.
{
XMLShapeExport* pShapeExport = new XMLShapeExport( *this, XMLTextParagraphExport::CreateShapeExtPropMapper( *this ) );
return pShapeExport;
}
void ORptExport::exportShapes(const Reference< XSection>& _xSection,bool _bAddParagraph)
{
rtl::Reference< XMLShapeExport > xShapeExport = GetShapeExport();
xShapeExport->seekShapes(_xSection.get());
const sal_Int32 nCount = _xSection->getCount();
::std::unique_ptr<SvXMLElementExport> pParagraphContent;
if ( _bAddParagraph )
pParagraphContent.reset(new SvXMLElementExport(*this,XML_NAMESPACE_TEXT, XML_P, true, false));
awt::Point aRefPoint;
aRefPoint.X = rptui::getStyleProperty<sal_Int32>(_xSection->getReportDefinition(),PROPERTY_LEFTMARGIN);
for (sal_Int32 i = 0; i < nCount; ++i)
{
uno::Reference< XShape > xShape(_xSection->getByIndex(i),uno::UNO_QUERY);
if ( xShape.is() )
{
::std::unique_ptr<SvXMLElementExport> pSubDocument;
uno::Reference< frame::XModel> xModel(xShape->getPropertyValue("Model"),uno::UNO_QUERY);
if ( xModel.is() ) // special handling for chart object
{
pSubDocument.reset(new SvXMLElementExport(*this,XML_NAMESPACE_REPORT, XML_SUB_DOCUMENT, false, false));
exportMasterDetailFields(xShape.get());
exportReportElement(xShape.get());
}
AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, XML_PARAGRAPH );
xShapeExport->exportShape(xShape.get(), SEF_DEFAULT|XMLShapeExportFlags::NO_WS,&aRefPoint);
}
}
}
void ORptExport::exportGroupsExpressionAsFunction(const Reference< XGroups>& _xGroups)
{
if ( !_xGroups.is() )
return;
uno::Reference< XFunctions> xFunctions = _xGroups->getReportDefinition()->getFunctions();
const sal_Int32 nCount = _xGroups->getCount();
for (sal_Int32 i = 0; i < nCount; ++i)
{
uno::Reference< XGroup> xGroup(_xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
const ::sal_Int16 nGroupOn = xGroup->getGroupOn();
if ( nGroupOn != report::GroupOn::DEFAULT )
{
uno::Reference< XFunction> xFunction = xFunctions->createFunction();
OUString sFunction,sPrefix,sPostfix;
OUString sExpression = xGroup->getExpression();
OUString sFunctionName;
OUString sInitialFormula;
switch(nGroupOn)
{
case report::GroupOn::PREFIX_CHARACTERS:
sFunction = "LEFT";
sPrefix = ";" + OUString::number(xGroup->getGroupInterval());
break;
case report::GroupOn::YEAR:
sFunction = "YEAR";
break;
case report::GroupOn::QUARTAL:
sFunction = "INT((MONTH";
sPostfix = "-1)/3)+1";
sFunctionName = "QUARTAL_" + sExpression;
break;
case report::GroupOn::MONTH:
sFunction = "MONTH";
break;
case report::GroupOn::WEEK:
sFunction = "WEEK";
break;
case report::GroupOn::DAY:
sFunction = "DAY";
break;
case report::GroupOn::HOUR:
sFunction = "HOUR";
break;
case report::GroupOn::MINUTE:
sFunction = "MINUTE";
break;
case report::GroupOn::INTERVAL:
{
sFunction = "INT";
uno::Reference< XFunction> xCountFunction = xFunctions->createFunction();
xCountFunction->setInitialFormula(beans::Optional< OUString>(true,OUString("rpt:0")));
OUString sCountName = sFunction + "_count_" + sExpression;
xCountFunction->setName(sCountName);
xCountFunction->setFormula( "rpt:[" + sCountName + "] + 1" );
exportFunction(xCountFunction);
sExpression = sCountName;
// The reference to sCountName in the formula of sFunctionName refers to the *old* value
// so we need to expand the formula of sCountName
sPrefix = " + 1) / " + OUString::number(xGroup->getGroupInterval());
sFunctionName = sFunction + "_" + sExpression;
sFunction += "(";
sInitialFormula = "rpt:0";
}
break;
default:
;
}
if ( sFunctionName.isEmpty() )
sFunctionName = sFunction + "_" + sExpression;
if ( !sFunction.isEmpty() )
{
const sal_Unicode pReplaceChars[] = { '(',')',';',',','+','-','[',']','/','*'};
for(sal_Unicode ch : pReplaceChars)
sFunctionName = sFunctionName.replace(ch,'_');
xFunction->setName(sFunctionName);
if ( !sInitialFormula.isEmpty() )
xFunction->setInitialFormula(beans::Optional< OUString>(true, sInitialFormula));
sFunction = "rpt:" + sFunction + "([" + sExpression + "]";
if ( !sPrefix.isEmpty() )
sFunction += sPrefix;
sFunction += ")";
if ( !sPostfix.isEmpty() )
sFunction += sPostfix;
xFunction->setFormula(sFunction);
exportFunction(xFunction);
m_aGroupFunctionMap.emplace(xGroup,xFunction);
}
}
}
}
}// rptxml
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|