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
|
/* -*- 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 <hintids.hxx>
#include <vcl/font.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/langitem.hxx>
#include <doc.hxx>
#include <docary.hxx>
#include <numrule.hxx>
#include <paratr.hxx>
#include <charfmt.hxx>
#include <ndtxt.hxx>
#include <unotools/fontcfg.hxx>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <sprmids.hxx>
#include "ww8attributeoutput.hxx"
#include "writerhelper.hxx"
#include "writerwordglue.hxx"
#include "wrtww8.hxx"
#include "ww8par.hxx"
using namespace ::com::sun::star;
using namespace sw::types;
using namespace sw::util;
sal_uInt16 MSWordExportBase::DuplicateNumRule( const SwNumRule *pRule, sal_uInt8 nLevel, sal_uInt16 nVal )
{
sal_uInt16 nNumId = USHRT_MAX;
const OUString sPrefix("WW8TempExport" + OUString::number( m_nUniqueList++ ));
SwNumRule* pMyNumRule =
new SwNumRule( m_pDoc->GetUniqueNumRuleName( &sPrefix ),
SvxNumberFormat::LABEL_WIDTH_AND_POSITION );
m_pUsedNumTable->push_back( pMyNumRule );
for ( sal_uInt16 i = 0; i < MAXLEVEL; i++ )
{
const SwNumFormat& rSubRule = pRule->Get(i);
pMyNumRule->Set( i, rSubRule );
}
SwNumFormat aNumFormat( pMyNumRule->Get( nLevel ) );
aNumFormat.SetStart( nVal );
pMyNumRule->Set( nLevel, aNumFormat );
nNumId = GetId( *pMyNumRule );
// Map the old list to our new list
m_aRuleDuplicates[GetId( *pRule )] = nNumId;
return nNumId;
}
sal_uInt16 MSWordExportBase::GetId( const SwNumRule& rNumRule )
{
if ( !m_pUsedNumTable )
{
m_pUsedNumTable = new SwNumRuleTable;
m_pUsedNumTable->insert( m_pUsedNumTable->begin(), m_pDoc->GetNumRuleTable().begin(), m_pDoc->GetNumRuleTable().end() );
// Check, if the outline rule is already inserted into <pUsedNumTable>.
// If yes, do not insert it again.
bool bOutlineRuleAdded( false );
for ( sal_uInt16 n = m_pUsedNumTable->size(); n; )
{
const SwNumRule& rRule = *(*m_pUsedNumTable)[ --n ];
if ( !SwDoc::IsUsed( rRule ) )
{
m_pUsedNumTable->erase( m_pUsedNumTable->begin() + n );
}
else if ( &rRule == m_pDoc->GetOutlineNumRule() )
{
bOutlineRuleAdded = true;
}
}
if ( !bOutlineRuleAdded )
{
// still need to paste the OutlineRule
SwNumRule* pR = m_pDoc->GetOutlineNumRule();
m_pUsedNumTable->push_back( pR );
}
}
SwNumRule* p = const_cast<SwNumRule*>(&rNumRule);
sal_uInt16 nRet = static_cast<sal_uInt16>(m_pUsedNumTable->GetPos(p));
// Is this list now duplicated into a new list which we should use
// #i77812# - perform 'deep' search in duplication map
::std::map<sal_uInt16,sal_uInt16>::const_iterator aResult = m_aRuleDuplicates.end();
do {
aResult = m_aRuleDuplicates.find(nRet);
if ( aResult != m_aRuleDuplicates.end() )
{
nRet = (*aResult).second;
}
} while ( aResult != m_aRuleDuplicates.end() );
return nRet;
}
// GetFirstLineOffset should problem never appear unadorned apart from
// here in the ww export filter
sal_Int16 GetWordFirstLineOffset(const SwNumFormat &rFormat)
{
OSL_ENSURE( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION,
"<GetWordFirstLineOffset> - misusage: position-and-space-mode does not equal LABEL_WIDTH_AND_POSITION" );
short nFirstLineOffset;
if (rFormat.GetNumAdjust() == SVX_ADJUST_RIGHT)
nFirstLineOffset = -rFormat.GetCharTextDistance();
else
nFirstLineOffset = rFormat.GetFirstLineOffset();
return nFirstLineOffset;
}
void WW8Export::WriteNumbering()
{
if ( !m_pUsedNumTable )
return; // no numbering is used
// list formats - LSTF
pFib->fcPlcfLst = pTableStrm->Tell();
SwWW8Writer::WriteShort( *pTableStrm, m_pUsedNumTable->size() );
NumberingDefinitions();
// set len to FIB
pFib->lcbPlcfLst = pTableStrm->Tell() - pFib->fcPlcfLst;
// list formats - LVLF
AbstractNumberingDefinitions();
// list formats - LFO
OutOverrideListTab();
// list formats - ListNames
OutListNamesTab();
}
void WW8AttributeOutput::NumberingDefinition( sal_uInt16 nId, const SwNumRule &rRule )
{
SwWW8Writer::WriteLong( *m_rWW8Export.pTableStrm, nId );
SwWW8Writer::WriteLong( *m_rWW8Export.pTableStrm, nId );
// not associated with a Style
for ( int i = 0; i < WW8ListManager::nMaxLevel; ++i )
SwWW8Writer::WriteShort( *m_rWW8Export.pTableStrm, 0xFFF );
sal_uInt8 nFlags = 0, nDummy = 0;
if ( rRule.IsContinusNum() )
nFlags |= 0x1;
m_rWW8Export.pTableStrm->WriteUChar( nFlags ).WriteUChar( nDummy );
}
void MSWordExportBase::NumberingDefinitions()
{
if ( !m_pUsedNumTable )
return; // no numbering is used
sal_uInt16 nCount = m_pUsedNumTable->size();
// Write static data of SwNumRule - LSTF
for ( sal_uInt16 n = 0; n < nCount; ++n )
{
const SwNumRule& rRule = *(*m_pUsedNumTable)[ n ];
AttrOutput().NumberingDefinition( n + 1, rRule );
}
}
static sal_uInt8 GetLevelNFC( sal_uInt16 eNumType, const SfxItemSet *pOutSet)
{
sal_uInt8 nRet = 0;
switch( eNumType )
{
case SVX_NUM_CHARS_UPPER_LETTER:
case SVX_NUM_CHARS_UPPER_LETTER_N: nRet = 3; break;
case SVX_NUM_CHARS_LOWER_LETTER:
case SVX_NUM_CHARS_LOWER_LETTER_N: nRet = 4; break;
case SVX_NUM_ROMAN_UPPER: nRet = 1; break;
case SVX_NUM_ROMAN_LOWER: nRet = 2; break;
case SVX_NUM_BITMAP:
case SVX_NUM_CHAR_SPECIAL: nRet = 23; break;
case SVX_NUM_FULL_WIDTH_ARABIC: nRet = 14; break;
case SVX_NUM_CIRCLE_NUMBER: nRet = 18;break;
case SVX_NUM_NUMBER_LOWER_ZH:
nRet = 35;
if ( pOutSet ) {
const SvxLanguageItem rLang = static_cast<const SvxLanguageItem&>( pOutSet->Get( RES_CHRATR_CJK_LANGUAGE,true) );
const LanguageType eLang = rLang.GetLanguage();
if (LANGUAGE_CHINESE_SIMPLIFIED ==eLang) {
nRet = 39;
}
}
break;
case SVX_NUM_NUMBER_UPPER_ZH: nRet = 38; break;
case SVX_NUM_NUMBER_UPPER_ZH_TW: nRet = 34;break;
case SVX_NUM_TIAN_GAN_ZH: nRet = 30; break;
case SVX_NUM_DI_ZI_ZH: nRet = 31; break;
case SVX_NUM_NUMBER_TRADITIONAL_JA: nRet = 16; break;
case SVX_NUM_AIU_FULLWIDTH_JA: nRet = 20; break;
case SVX_NUM_AIU_HALFWIDTH_JA: nRet = 12; break;
case SVX_NUM_IROHA_FULLWIDTH_JA: nRet = 21; break;
case SVX_NUM_IROHA_HALFWIDTH_JA: nRet = 13; break;
case style::NumberingType::HANGUL_SYLLABLE_KO: nRet = 24; break;// ganada
case style::NumberingType::HANGUL_JAMO_KO: nRet = 25; break;// chosung
case style::NumberingType::HANGUL_CIRCLED_SYLLABLE_KO: nRet = 24; break;
case style::NumberingType::HANGUL_CIRCLED_JAMO_KO: nRet = 25; break;
case style::NumberingType::NUMBER_HANGUL_KO: nRet = 41; break;
case style::NumberingType::NUMBER_UPPER_KO: nRet = 44; break;
case SVX_NUM_NUMBER_NONE: nRet = 0xff; break;
}
return nRet;
}
void WW8AttributeOutput::NumberingLevel( sal_uInt8 /*nLevel*/,
sal_uInt16 nStart,
sal_uInt16 nNumberingType,
SvxAdjust eAdjust,
const sal_uInt8 *pNumLvlPos,
sal_uInt8 nFollow,
const wwFont *pFont,
const SfxItemSet *pOutSet,
sal_Int16 nIndentAt,
sal_Int16 nFirstLineIndex,
sal_Int16 nListTabPos,
const OUString &rNumberingString,
const SvxBrushItem* pBrush //For i120928,to transfer graphic of bullet
)
{
// Start value
SwWW8Writer::WriteLong( *m_rWW8Export.pTableStrm, nStart );
// Type
m_rWW8Export.pTableStrm->WriteUChar( GetLevelNFC( nNumberingType ,pOutSet) );
// Justification
sal_uInt8 nAlign;
switch ( eAdjust )
{
case SVX_ADJUST_CENTER:
nAlign = 1;
break;
case SVX_ADJUST_RIGHT:
nAlign = 2;
break;
default:
nAlign = 0;
break;
}
m_rWW8Export.pTableStrm->WriteUChar( nAlign );
// Write the rgbxchNums[9], positions of placeholders for paragraph
// numbers in the text
m_rWW8Export.pTableStrm->Write( pNumLvlPos, WW8ListManager::nMaxLevel );
// Type of the character between the bullet and the text
m_rWW8Export.pTableStrm->WriteUChar( nFollow );
// dxaSoace/dxaIndent (Word 6 compatibility)
SwWW8Writer::WriteLong( *m_rWW8Export.pTableStrm, 0 );
SwWW8Writer::WriteLong( *m_rWW8Export.pTableStrm, 0 );
// cbGrpprlChpx
ww::bytes aCharAtrs;
if ( pOutSet )
{
ww::bytes* pOldpO = m_rWW8Export.pO;
m_rWW8Export.pO = &aCharAtrs;
if ( pFont )
{
sal_uInt16 nFontID = m_rWW8Export.m_aFontHelper.GetId( *pFont );
m_rWW8Export.InsUInt16( NS_sprm::LN_CRgFtc0 );
m_rWW8Export.InsUInt16( nFontID );
m_rWW8Export.InsUInt16( NS_sprm::LN_CRgFtc2 );
m_rWW8Export.InsUInt16( nFontID );
}
m_rWW8Export.OutputItemSet( *pOutSet, false, true, i18n::ScriptType::LATIN, m_rWW8Export.m_bExportModeRTF );
//For i120928,achieve graphic's index of bullet from the bullet bookmark
if (SVX_NUM_BITMAP == nNumberingType && pBrush)
{
int nIndex = m_rWW8Export.GetGrfIndex(*pBrush);
if ( nIndex != -1 )
{
m_rWW8Export.InsUInt16(NS_sprm::LN_CPbiIBullet);
m_rWW8Export.InsUInt32(nIndex);
m_rWW8Export.InsUInt16(NS_sprm::LN_CPbiGrf);
m_rWW8Export.InsUInt16(1);
}
}
m_rWW8Export.pO = pOldpO;
}
m_rWW8Export.pTableStrm->WriteUChar( sal_uInt8( aCharAtrs.size() ) );
// cbGrpprlPapx
sal_uInt8 aPapSprms [] = {
0x5e, 0x84, 0, 0, // sprmPDxaLeft
0x60, 0x84, 0, 0, // sprmPDxaLeft1
0x15, 0xc6, 0x05, 0x00, 0x01, 0, 0, 0x06
};
m_rWW8Export.pTableStrm->WriteUChar( sal_uInt8( sizeof( aPapSprms ) ) );
// reserved
SwWW8Writer::WriteShort( *m_rWW8Export.pTableStrm, 0 );
// pap sprms
sal_uInt8* pData = aPapSprms + 2;
Set_UInt16( pData, nIndentAt );
pData += 2;
Set_UInt16( pData, nFirstLineIndex );
pData += 5;
Set_UInt16( pData, nListTabPos );
m_rWW8Export.pTableStrm->Write( aPapSprms, sizeof( aPapSprms ));
// write Chpx
if( !aCharAtrs.empty() )
m_rWW8Export.pTableStrm->Write( aCharAtrs.data(), aCharAtrs.size() );
// write the num string
SwWW8Writer::WriteShort( *m_rWW8Export.pTableStrm, rNumberingString.getLength() );
SwWW8Writer::WriteString16( *m_rWW8Export.pTableStrm, rNumberingString, false );
}
void MSWordExportBase::AbstractNumberingDefinitions()
{
sal_uInt16 nCount = m_pUsedNumTable->size();
sal_uInt16 n;
// prepare the NodeNum to generate the NumString
SwNumberTree::tNumberVector aNumVector;
for ( n = 0; n < WW8ListManager::nMaxLevel; ++n )
aNumVector.push_back( n );
for( n = 0; n < nCount; ++n )
{
AttrOutput().StartAbstractNumbering( n + 1 );
const SwNumRule& rRule = *(*m_pUsedNumTable)[ n ];
sal_uInt8 nLvl;
sal_uInt8 nLevels = static_cast< sal_uInt8 >(rRule.IsContinusNum() ?
WW8ListManager::nMinLevel : WW8ListManager::nMaxLevel);
for( nLvl = 0; nLvl < nLevels; ++nLvl )
{
// write the static data of the SwNumFormat of this level
sal_uInt8 aNumLvlPos[WW8ListManager::nMaxLevel] = { 0,0,0,0,0,0,0,0,0 };
const SwNumFormat& rFormat = rRule.Get( nLvl );
sal_uInt8 nFollow = 0;
// #i86652#
if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
nFollow = 2; // ixchFollow: 0 - tab, 1 - blank, 2 - nothing
}
else if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
{
switch ( rFormat.GetLabelFollowedBy() )
{
case SvxNumberFormat::LISTTAB:
{
// 0 (tab) unless there would be no content before the tab, in which case 2 (nothing)
nFollow = (SVX_NUM_NUMBER_NONE != rFormat.GetNumberingType()) ? 0 : 2;
}
break;
case SvxNumberFormat::SPACE:
{
// 1 (space) unless there would be no content before the space in which case 2 (nothing)
nFollow = (SVX_NUM_NUMBER_NONE != rFormat.GetNumberingType()) ? 1 : 2;
}
break;
case SvxNumberFormat::NOTHING:
{
nFollow = 2;
}
break;
default:
{
nFollow = 0;
OSL_FAIL( "unknown GetLabelFollowedBy() return value" );
}
}
}
// Build the NumString for this Level
OUString sNumStr;
OUString sFontName;
bool bWriteBullet = false;
const vcl::Font* pBulletFont=0;
rtl_TextEncoding eChrSet=0;
FontFamily eFamily=FAMILY_DECORATIVE;
if( SVX_NUM_CHAR_SPECIAL == rFormat.GetNumberingType() ||
SVX_NUM_BITMAP == rFormat.GetNumberingType() )
{
sNumStr = OUString(rFormat.GetBulletChar());
bWriteBullet = true;
pBulletFont = rFormat.GetBulletFont();
if (!pBulletFont)
{
pBulletFont = &numfunc::GetDefBulletFont();
}
eChrSet = pBulletFont->GetCharSet();
sFontName = pBulletFont->GetName();
eFamily = pBulletFont->GetFamily();
if ( IsStarSymbol(sFontName) )
SubstituteBullet( sNumStr, eChrSet, sFontName );
// #i86652#
if ( rFormat.GetPositionAndSpaceMode() ==
SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
// <nFollow = 2>, if minimum label width equals 0 and
// minimum distance between label and text equals 0
nFollow = ( rFormat.GetFirstLineOffset() == 0 &&
rFormat.GetCharTextDistance() == 0 )
? 2 : 0; // ixchFollow: 0 - tab, 1 - blank, 2 - nothing
}
}
else
{
if (SVX_NUM_NUMBER_NONE != rFormat.GetNumberingType())
{
sal_uInt8* pLvlPos = aNumLvlPos;
// the numbering string has to be restrict
// to the level currently working on.
sNumStr = rRule.MakeNumString(aNumVector, false, true, nLvl);
// now search the nums in the string
for( sal_uInt8 i = 0; i <= nLvl; ++i )
{
OUString sSrch( OUString::number( i ));
sal_Int32 nFnd = sNumStr.indexOf( sSrch );
if( -1 != nFnd )
{
*pLvlPos = (sal_uInt8)(nFnd + rFormat.GetPrefix().getLength() + 1 );
++pLvlPos;
sNumStr = sNumStr.replaceAt( nFnd, 1, OUString((char)i) );
}
}
// #i86652#
if ( rFormat.GetPositionAndSpaceMode() ==
SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
// <nFollow = 2>, if minimum label width equals 0 and
// minimum distance between label and text equals 0
nFollow = ( rFormat.GetFirstLineOffset() == 0 &&
rFormat.GetCharTextDistance() == 0 )
? 2 : 0; // ixchFollow: 0 - tab, 1 - blank, 2 - nothing
}
}
if( !rFormat.GetPrefix().isEmpty() )
sNumStr = rFormat.GetPrefix() + sNumStr;
sNumStr += rFormat.GetSuffix();
}
// Attributes of the numbering
wwFont *pPseudoFont = NULL;
const SfxItemSet* pOutSet = NULL;
// cbGrpprlChpx
SfxItemSet aSet( m_pDoc->GetAttrPool(), RES_CHRATR_BEGIN,
RES_CHRATR_END );
if ( rFormat.GetCharFormat() || bWriteBullet )
{
if ( bWriteBullet )
{
pOutSet = &aSet;
if ( rFormat.GetCharFormat() )
aSet.Put( rFormat.GetCharFormat()->GetAttrSet() );
aSet.ClearItem( RES_CHRATR_CJK_FONT );
aSet.ClearItem( RES_CHRATR_FONT );
if ( sFontName.isEmpty() )
sFontName = pBulletFont->GetName();
pPseudoFont = new wwFont( sFontName, pBulletFont->GetPitch(),
eFamily, eChrSet);
}
else
pOutSet = &rFormat.GetCharFormat()->GetAttrSet();
}
sal_Int16 nIndentAt = 0;
sal_Int16 nFirstLineIndex = 0;
sal_Int16 nListTabPos = 0;
// #i86652#
if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
nIndentAt = nListTabPos = rFormat.GetAbsLSpace();
nFirstLineIndex = GetWordFirstLineOffset(rFormat);
}
else if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
{
nIndentAt = static_cast<sal_Int16>(rFormat.GetIndentAt());
nFirstLineIndex = static_cast<sal_Int16>(rFormat.GetFirstLineIndent());
nListTabPos = rFormat.GetLabelFollowedBy() == SvxNumberFormat::LISTTAB?
static_cast<sal_Int16>( rFormat.GetListtabPos() ) : 0;
}
AttrOutput().NumberingLevel( nLvl,
rFormat.GetStart(),
rFormat.GetNumberingType(),
rFormat.GetNumAdjust(),
aNumLvlPos,
nFollow,
pPseudoFont, pOutSet,
nIndentAt, nFirstLineIndex, nListTabPos,
sNumStr,
rFormat.GetNumberingType()==SVX_NUM_BITMAP ? rFormat.GetBrush():0);
delete pPseudoFont;
}
AttrOutput().EndAbstractNumbering();
}
}
void WW8Export::OutOverrideListTab()
{
if( !m_pUsedNumTable )
return ; // no numbering is used
// write the "list format override" - LFO
sal_uInt16 nCount = m_pUsedNumTable->size();
sal_uInt16 n;
pFib->fcPlfLfo = pTableStrm->Tell();
SwWW8Writer::WriteLong( *pTableStrm, nCount );
for( n = 0; n < nCount; ++n )
{
SwWW8Writer::WriteLong( *pTableStrm, n + 1 );
SwWW8Writer::FillCount( *pTableStrm, 12 );
}
for( n = 0; n < nCount; ++n )
SwWW8Writer::WriteLong( *pTableStrm, -1 ); // no overwrite
// set len to FIB
pFib->lcbPlfLfo = pTableStrm->Tell() - pFib->fcPlfLfo;
}
void WW8Export::OutListNamesTab()
{
if( !m_pUsedNumTable )
return ; // no numbering is used
// write the "list format override" - LFO
sal_uInt16 nNms = 0, nCount = m_pUsedNumTable->size();
pFib->fcSttbListNames = pTableStrm->Tell();
SwWW8Writer::WriteShort( *pTableStrm, -1 );
SwWW8Writer::WriteLong( *pTableStrm, nCount );
for( ; nNms < nCount; ++nNms )
{
const SwNumRule& rRule = *(*m_pUsedNumTable)[ nNms ];
OUString sNm;
if( !rRule.IsAutoRule() )
sNm = rRule.GetName();
SwWW8Writer::WriteShort( *pTableStrm, sNm.getLength() );
if (!sNm.isEmpty())
SwWW8Writer::WriteString16(*pTableStrm, sNm, false);
}
SwWW8Writer::WriteLong( *pTableStrm, pFib->fcSttbListNames + 2, nNms );
// set len to FIB
pFib->lcbSttbListNames = pTableStrm->Tell() - pFib->fcSttbListNames;
}
// old WW95-Code
void WW8Export::OutputOlst( const SwNumRule& rRule )
{
assert(false); // TODO
static const sal_uInt8 aAnlvBase[] = { // Defaults
1,0,0, // Upper Roman
0x0C, // Hanging Indent, fPrev
0,0,1,0x80,0,0,1,0,0x1b,1,0,0 };
static const sal_uInt8 aSprmOlstHdr[] = { 133, 212 };
pO->insert( pO->end(), aSprmOlstHdr, aSprmOlstHdr+sizeof( aSprmOlstHdr ) );
WW8_OLST aOlst;
memset( &aOlst, 0, sizeof(aOlst) );
sal_uInt8* pC = aOlst.rgch;
sal_uInt8* pChars = pC;
sal_uInt16 nCharLen = 64;
for (sal_uInt16 j = 0; j < WW8ListManager::nMaxLevel; j++ ) // 9 variable ANLVs
{
memcpy( &aOlst.rganlv[j], aAnlvBase, sizeof( WW8_ANLV ) ); // Defaults
const SwNumFormat* pFormat = rRule.GetNumFormat( j );
if( pFormat )
BuildAnlvBase( aOlst.rganlv[j], pChars, nCharLen, rRule,
*pFormat, (sal_uInt8)j );
}
pO->insert( pO->end(), reinterpret_cast<sal_uInt8*>(&aOlst), reinterpret_cast<sal_uInt8*>(&aOlst)+sizeof( aOlst ) );
}
void WW8Export::Out_WwNumLvl( sal_uInt8 nWwLevel )
{
pO->push_back( 13 );
pO->push_back( nWwLevel );
}
void WW8Export::Out_SwNumLvl( sal_uInt8 nSwLevel )
{
OSL_ENSURE( nSwLevel < MAXLEVEL, "numbered?");
Out_WwNumLvl( nSwLevel + 1 );
}
void WW8Export::BuildAnlvBulletBase(WW8_ANLV& rAnlv, sal_uInt8*& rpCh,
sal_uInt16& rCharLen, const SwNumFormat& rFormat)
{
rAnlv.nfc = 11;
sal_uInt8 nb = 0; // type of number
switch (rFormat.GetNumAdjust())
{
case SVX_ADJUST_RIGHT:
nb = 2;
break;
case SVX_ADJUST_CENTER:
nb = 1;
break;
case SVX_ADJUST_BLOCK:
case SVX_ADJUST_BLOCKLINE:
nb = 3;
break;
case SVX_ADJUST_LEFT:
case SVX_ADJUST_END:
break;
}
// #i86652#
if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
if (GetWordFirstLineOffset(rFormat) < 0)
nb |= 0x8; // number will be displayed using a hanging indent
}
rAnlv.aBits1 = nb;
if (1 < rCharLen)
{
const vcl::Font& rFont = rFormat.GetBulletFont()
? *rFormat.GetBulletFont()
: numfunc::GetDefBulletFont();
OUString sNumStr = OUString(rFormat.GetBulletChar());
rtl_TextEncoding eChrSet = rFont.GetCharSet();
OUString sFontName = rFont.GetName();
sal_uInt16 nFontId;
if ( IsStarSymbol(sFontName) )
{
/*
If we are starsymbol then in ww7- mode we will always convert to a
windows 8bit symbol font and an index into it, to conversion to
8 bit is complete at this stage.
*/
SubstituteBullet(sNumStr, eChrSet, sFontName);
wwFont aPseudoFont(sFontName, rFont.GetPitch(), rFont.GetFamily(),
eChrSet);
nFontId = m_aFontHelper.GetId(aPseudoFont);
*rpCh = static_cast<sal_uInt8>(sNumStr[0]);
}
else
{
/*
Otherwise we are a unicode char and need to be converted back to
an 8 bit format. We happen to know that if the font is already an
8 bit windows font currently, staroffice promotes the char into
the F000->F0FF range, so we can undo this, and we'll be back to
the equivalent 8bit location, otherwise we have to convert from
true unicode to an 8bit charset
*/
nFontId = m_aFontHelper.GetId(rFont);
sal_Unicode cChar = sNumStr[0];
if ( (eChrSet == RTL_TEXTENCODING_SYMBOL) && (cChar >= 0xF000) && (
cChar <= 0xF0FF) )
{
*rpCh = static_cast< sal_uInt8 >(cChar - 0xF000);
}
else
*rpCh = OUStringToOString(OUString(cChar), eChrSet).toChar();
}
rpCh++;
rCharLen--;
ShortToSVBT16(nFontId, rAnlv.ftc);
rAnlv.cbTextBefore = 1;
}
// #i86652#
if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
ShortToSVBT16( -GetWordFirstLineOffset(rFormat), rAnlv.dxaIndent );
ShortToSVBT16( rFormat.GetCharTextDistance(), rAnlv.dxaSpace );
}
else
{
ShortToSVBT16( 0, rAnlv.dxaIndent );
ShortToSVBT16( 0, rAnlv.dxaSpace );
}
}
void MSWordExportBase::SubstituteBullet( OUString& rNumStr,
rtl_TextEncoding& rChrSet, OUString& rFontName ) const
{
if (!m_bSubstituteBullets)
return;
OUString sFontName = rFontName;
// If Bullet char is "", don't change
if (rNumStr[0] != sal_Unicode(0x0))
{
rNumStr = rNumStr.replaceAt(0, 1, OUString(
msfilter::util::bestFitOpenSymbolToMSFont(rNumStr[0], rChrSet, sFontName)));
}
rFontName = sFontName;
}
static void SwWw8_InsertAnlText( const OUString& rStr, sal_uInt8*& rpCh,
sal_uInt16& rCharLen, sal_uInt8& r8Len )
{
sal_uInt8 nb = 0;
ww::bytes aO;
SwWW8Writer::InsAsString8( aO, rStr, RTL_TEXTENCODING_MS_1252 );
sal_uInt16 nCnt = aO.size();
if( nCnt && nCnt < rCharLen )
{
nb = (sal_uInt8)nCnt;
std::copy( aO.begin(), aO.end(), rpCh );
rpCh += nCnt;
rCharLen = rCharLen - nCnt;
}
r8Len = nb;
}
void WW8Export::BuildAnlvBase(WW8_ANLV& rAnlv, sal_uInt8*& rpCh,
sal_uInt16& rCharLen, const SwNumRule& rRul, const SwNumFormat& rFormat,
sal_uInt8 nSwLevel)
{
const SfxItemSet *pOutSet = NULL;
if (rFormat.GetCharFormat())
pOutSet = &rFormat.GetCharFormat()->GetAttrSet();
rAnlv.nfc = GetLevelNFC(rFormat.GetNumberingType(),pOutSet );
sal_uInt8 nb = 0;
switch (rFormat.GetNumAdjust())
{
case SVX_ADJUST_RIGHT:
nb = 2;
break;
case SVX_ADJUST_CENTER:
nb = 1;
break;
case SVX_ADJUST_BLOCK:
case SVX_ADJUST_BLOCKLINE:
nb = 3;
break;
case SVX_ADJUST_LEFT:
case SVX_ADJUST_END:
break;
}
bool bInclUpper = rFormat.GetIncludeUpperLevels() > 0;
if( bInclUpper )
nb |= 0x4; // include previous levels
if (GetWordFirstLineOffset(rFormat) < 0)
nb |= 0x8; // number will be displayed using a hanging indent
rAnlv.aBits1 = nb;
if( bInclUpper && !rRul.IsContinusNum() )
{
if( (nSwLevel >= WW8ListManager::nMinLevel )
&& (nSwLevel<= WW8ListManager::nMaxLevel )
&& (rFormat.GetNumberingType() != SVX_NUM_NUMBER_NONE ) ) // UEberhaupt Nummerierung ?
{ // -> suche, ob noch Zahlen davor
sal_uInt8 nUpper = rFormat.GetIncludeUpperLevels();
if( (nUpper <= WW8ListManager::nMaxLevel) &&
(rRul.Get(nUpper).GetNumberingType() != SVX_NUM_NUMBER_NONE ) ) // Nummerierung drueber ?
{
// dann Punkt einfuegen
SwWw8_InsertAnlText( ".", rpCh, rCharLen,
rAnlv.cbTextBefore );
}
}
}
else
{
SwWw8_InsertAnlText( rFormat.GetPrefix(), rpCh, rCharLen,
rAnlv.cbTextBefore );
SwWw8_InsertAnlText( rFormat.GetSuffix(), rpCh, rCharLen,
rAnlv.cbTextAfter );
}
ShortToSVBT16( rFormat.GetStart(), rAnlv.iStartAt );
// #i86652#
if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
ShortToSVBT16( -GetWordFirstLineOffset(rFormat), rAnlv.dxaIndent );
ShortToSVBT16( rFormat.GetCharTextDistance(), rAnlv.dxaSpace );
}
else
{
ShortToSVBT16( 0, rAnlv.dxaIndent );
ShortToSVBT16( 0, rAnlv.dxaSpace );
}
}
void WW8Export::Out_NumRuleAnld( const SwNumRule& rRul, const SwNumFormat& rFormat,
sal_uInt8 nSwLevel )
{
static const sal_uInt8 aSprmAnldDefault[54] = {
12, 52,
1,0,0,0x0c,0,0,1,0x80,0,0,1,0,0x1b,1,0,0,0x2e,
0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
sal_uInt8 aSprmAnld[54];
memcpy( aSprmAnld, aSprmAnldDefault, sizeof( aSprmAnld ) );
WW8_ANLD* pA = reinterpret_cast<WW8_ANLD*>(aSprmAnld + 2); // handy pointer
sal_uInt8* pChars = pA->rgchAnld;
sal_uInt16 nCharLen = 31;
if( nSwLevel == 11 )
BuildAnlvBulletBase( pA->eAnlv, pChars, nCharLen, rFormat );
else
BuildAnlvBase( pA->eAnlv, pChars, nCharLen, rRul, rFormat, nSwLevel );
// ... spit it out
OutSprmBytes( reinterpret_cast<sal_uInt8*>(&aSprmAnld), sizeof( aSprmAnld ) );
}
// Return: is it an outline?
bool WW8Export::Out_SwNum(const SwTextNode* pNd)
{
int nLevel = pNd->GetActualListLevel();
if (nLevel < 0 || nLevel >= MAXLEVEL)
{
OSL_FAIL("Invalid level");
return false;
}
sal_uInt8 nSwLevel = static_cast< sal_uInt8 >(nLevel);
const SwNumRule* pRul = pNd->GetNumRule();
if( !pRul || nSwLevel == WW8ListManager::nMaxLevel)
return false;
bool bRet = true;
SwNumFormat aFormat(pRul->Get(nSwLevel));
// #i86652#
if ( aFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
const SvxLRSpaceItem& rLR = ItemGet<SvxLRSpaceItem>(*pNd, RES_LR_SPACE);
aFormat.SetAbsLSpace(writer_cast<short>(aFormat.GetAbsLSpace() + rLR.GetLeft()));
}
if (
aFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE ||
aFormat.GetNumberingType() == SVX_NUM_CHAR_SPECIAL ||
aFormat.GetNumberingType() == SVX_NUM_BITMAP
)
{
Out_WwNumLvl(11);
Out_NumRuleAnld(*pRul, aFormat, 11);
bRet = false;
}
else if (
pRul->IsContinusNum() ||
(pRul->Get(1).GetIncludeUpperLevels() <= 1)
)
{
Out_WwNumLvl(10);
Out_NumRuleAnld(*pRul, aFormat, 10);
bRet = false;
}
else
{
Out_SwNumLvl(nSwLevel);
Out_NumRuleAnld(*pRul, aFormat, nSwLevel);
}
return bRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|