summaryrefslogtreecommitdiff
path: root/sw/source/filter/basflt/fltini.cxx
blob: 5aa4b747f84fcb5934eaec258c75a34a8b2df18c (plain)
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
/* -*- 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 <string.h>
#include <hintids.hxx>
#include <i18nlangtag/lang.h>
#include <i18nlangtag/languagetag.hxx>
#include <vcl/msgbox.hxx>
#include <svtools/parhtml.hxx>
#include <sot/storage.hxx>
#include <comphelper/classids.hxx>
#include <sfx2/app.hxx>
#include <sfx2/docfilt.hxx>
#include <sfx2/fcontnr.hxx>
#include <sfx2/docfile.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/tstpitem.hxx>
#include <doc.hxx>
#include <docary.hxx>
#include <pam.hxx>
#include <shellio.hxx>
#include <docsh.hxx>
#include <wdocsh.hxx>
#include <fltini.hxx>
#include <hints.hxx>
#include <init.hxx>
#include <frmatr.hxx>
#include <fmtfsize.hxx>
#include <swtable.hxx>
#include <fmtcntnt.hxx>
#include <editeng/boxitem.hxx>
#include <frmfmt.hxx>
#include <numrule.hxx>
#include <ndtxt.hxx>
#include <swfltopt.hxx>
#include <swerror.h>
#include <swdll.hxx>
#include <osl/module.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/util/XMacroExpander.hpp>
#include <rtl/bootstrap.hxx>

using namespace utl;
using namespace com::sun::star::uno;
using namespace com::sun::star;

SwRead ReadAscii = 0, ReadHTML = 0, ReadXML = 0;

Reader* GetRTFReader();
Reader* GetWW8Reader();

// Note: if editing, please don't forget to modify also the enum
// ReaderWriterEnum and aFilterDetect in shellio.hxx
SwReaderWriterEntry aReaderWriter[] =
{
    SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter,  true  ),
    SwReaderWriterEntry( 0,               &::GetASCWriter,  false ),
    SwReaderWriterEntry( &::GetWW8Reader, nullptr,          true  ),
    SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer,  true  ),
    SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter,  true  ),
    SwReaderWriterEntry( 0,               &::GetHTMLWriter, true  ),
    SwReaderWriterEntry( &::GetWW8Reader, 0,                true  ),
    SwReaderWriterEntry( 0,               &::GetXMLWriter,  true  ),
    SwReaderWriterEntry( 0,               &::GetASCWriter,  false ),
    SwReaderWriterEntry( 0,               &::GetASCWriter,  true  )
};

Reader* SwReaderWriterEntry::GetReader()
{
    if ( pReader )
        return pReader;
    else if ( fnGetReader )
    {
        pReader = (*fnGetReader)();
        return pReader;
    }
    return NULL;
}

void SwReaderWriterEntry::GetWriter( const OUString& rNm, const OUString& rBaseURL, WriterRef& xWrt ) const
{
    if ( fnGetWriter )
        (*fnGetWriter)( rNm, rBaseURL, xWrt );
    else
        xWrt = WriterRef(0);
}

SwRead SwGetReaderXML() // SW_DLLPUBLIC
{
        return ReadXML;
}

inline void _SetFltPtr( sal_uInt16 rPos, SwRead pReader )
{
        aReaderWriter[ rPos ].pReader = pReader;
}

namespace sw {

Filters::Filters()
{
    _SetFltPtr( READER_WRITER_BAS, (ReadAscii = new AsciiReader) );
    _SetFltPtr( READER_WRITER_HTML, (ReadHTML = new HTMLReader) );
    _SetFltPtr( READER_WRITER_XML, (ReadXML = new XMLReader)  );
    _SetFltPtr( READER_WRITER_TEXT_DLG, ReadAscii );
    _SetFltPtr( READER_WRITER_TEXT, ReadAscii );
}

Filters::~Filters()
{
    // kill Readers
    for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
    {
        SwReaderWriterEntry& rEntry = aReaderWriter[n];
        if( rEntry.bDelReader && rEntry.pReader )
            delete rEntry.pReader, rEntry.pReader = NULL;
    }
}

#ifndef DISABLE_DYNLOADING

oslGenericFunction Filters::GetMswordLibSymbol( const char *pSymbol )
{
    if (!msword_.is())
    {
        OUString url("$LO_LIB_DIR/" SVLIBRARY("msword"));
        rtl::Bootstrap::expandMacros(url);
        bool ok = msword_.load( url, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY );
        SAL_WARN_IF(!ok, "sw", "failed to load msword library");
    }
    if (msword_.is())
        return msword_.getFunctionSymbol( OUString::createFromAscii( pSymbol ) );
    return NULL;
}

#endif

}

namespace SwReaderWriter {

Reader* GetReader( ReaderWriterEnum eReader )
{
    return aReaderWriter[eReader].GetReader();
}

void GetWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
{
    for( int n = 0; n < MAXFILTER; ++n )
        if ( aFilterDetect[n].IsFilter( rFltName ) )
        {
            aReaderWriter[n].GetWriter( rFltName, rBaseURL, xRet );
            break;
        }
}

SwRead GetReader( const OUString& rFltName )
{
    SwRead pRead = 0;
    for( int n = 0; n < MAXFILTER; ++n )
    {
        if ( aFilterDetect[n].IsFilter( rFltName ) )
        {
            pRead = aReaderWriter[n].GetReader();
            // add special treatment for some readers
            if ( pRead )
                pRead->SetFltName( rFltName );
            break;
        }
    }
    return pRead;
}

} // namespace SwReaderWriter

bool Writer::IsStgWriter() const { return false; }

bool StgWriter::IsStgWriter() const { return true; }

// Read Filter Flags; used by WW8 / W4W / EXCEL / LOTUS

/*
<FilterFlags>
        <Excel_Lotus>
                <MinRow cfg:type="long">0</MinRow>
                <MaxRow cfg:type="long">0</MaxRow>
                <MinCol cfg:type="long">0</MinCol>
                <MaxCol cfg:type="long">0</MaxCol>
        </Excel_Lotus>
        <W4W>
                <W4WHD cfg:type="long">0</W4WHD>
                <W4WFT cfg:type="long">0</W4WFT>
                <W4W000 cfg:type="long">0</W4W000>
        </W4W>
        <WinWord>
                <WW1F cfg:type="long">0</WW1F>
                <WW cfg:type="long">0</WW>
                <WW8 cfg:type="long">0</WW8>
                <WWF cfg:type="long">0</WWF>
                <WWFA0 cfg:type="long">0</WWFA0>
                <WWFA1 cfg:type="long">0</WWFA1>
                <WWFA2 cfg:type="long">0</WWFA2>
                <WWFB0 cfg:type="long">0</WWFB0>
                <WWFB1 cfg:type="long">0</WWFB1>
                <WWFB2 cfg:type="long">0</WWFB2>
                <WWFLX cfg:type="long">0</WWFLX>
                <WWFLY cfg:type="long">0</WWFLY>
                <WWFT cfg:type="long">0</WWFT>
                <WWWR cfg:type="long">0</WWWR>
        </WinWord>
        <Writer>
                <SW3Imp cfg:type="long">0</SW3Imp>
        </Writer>
</FilterFlags>
*/

#define FILTER_OPTION_ROOT      OUString("Office.Writer/FilterFlags")

SwFilterOptions::SwFilterOptions( sal_uInt16 nCnt, const sal_Char** ppNames,
                                                                sal_uInt32* pValues )
    : ConfigItem( FILTER_OPTION_ROOT )
{
    GetValues( nCnt, ppNames, pValues );
}

void SwFilterOptions::GetValues( sal_uInt16 nCnt, const sal_Char** ppNames,
                                                                        sal_uInt32* pValues )
{
    Sequence<OUString> aNames( nCnt );
    OUString* pNames = aNames.getArray();
    sal_uInt16 n;

    for( n = 0; n < nCnt; ++n )
        pNames[ n ] = OUString::createFromAscii( ppNames[ n ] );
    Sequence<Any> aValues = GetProperties( aNames );

    if( nCnt == aValues.getLength() )
    {
        const Any* pAnyValues = aValues.getConstArray();
        for( n = 0; n < nCnt; ++n )
            pValues[ n ] = pAnyValues[ n ].hasValue()
                                            ? *static_cast<sal_uInt32 const *>(pAnyValues[ n ].getValue())
                                            : 0;
    }
    else
    {
        for( n = 0; n < nCnt; ++n )
            pValues[ n ] = 0;
    }
}

void SwFilterOptions::ImplCommit() {}
void SwFilterOptions::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}

void StgReader::SetFltName( const OUString& rFltNm )
{
    if( SW_STORAGE_READER & GetReaderType() )
        aFltName = rFltNm;
}

SwRelNumRuleSpaces::SwRelNumRuleSpaces( SwDoc& rDoc, bool bNDoc )
{
    pNumRuleTable = new SwNumRuleTable();
    pNumRuleTable->reserve(8);
    if( !bNDoc )
        pNumRuleTable->insert( pNumRuleTable->begin(),
            rDoc.GetNumRuleTable().begin(), rDoc.GetNumRuleTable().end() );
}

SwRelNumRuleSpaces::~SwRelNumRuleSpaces()
{
    if( pNumRuleTable )
    {
        pNumRuleTable->clear();
        delete pNumRuleTable;
    }
}

void CalculateFlySize(SfxItemSet& rFlySet, const SwNodeIndex& rAnchor,
        SwTwips nPageWidth)
{
    const SfxPoolItem* pItem = 0;
    if( SfxItemState::SET != rFlySet.GetItemState( RES_FRM_SIZE, true, &pItem ) ||
            MINFLY > static_cast<const SwFormatFrmSize*>(pItem)->GetWidth() )
    {
        SwFormatFrmSize aSz(static_cast<const SwFormatFrmSize&>(rFlySet.Get(RES_FRM_SIZE)));
        if (pItem)
            aSz = static_cast<const SwFormatFrmSize&>(*pItem);

        SwTwips nWidth;
        // determine the width; if there is a table use the width of the table;
        // otherwise use the width of the page
        const SwTableNode* pTableNd = rAnchor.GetNode().FindTableNode();
        if( pTableNd )
            nWidth = pTableNd->GetTable().GetFrameFormat()->GetFrmSize().GetWidth();
        else
            nWidth = nPageWidth;

        const SwNodeIndex* pSttNd = static_cast<const SwFormatContent&>(rFlySet.Get( RES_CNTNT )).
                                                                GetContentIdx();
        if( pSttNd )
        {
            bool bOnlyOneNode = true;
            sal_uLong nMinFrm = 0;
            sal_uLong nMaxFrm = 0;
            SwTextNode* pFirstTextNd = 0;
            SwNodeIndex aIdx( *pSttNd, 1 );
            SwNodeIndex aEnd( *pSttNd->GetNode().EndOfSectionNode() );
            while( aIdx < aEnd )
            {
                SwTextNode *pTextNd = aIdx.GetNode().GetTextNode();
                if( pTextNd )
                {
                    if( !pFirstTextNd )
                        pFirstTextNd = pTextNd;
                    else if( pFirstTextNd != pTextNd )
                    {
                        // forget it
                        bOnlyOneNode = false;
                        break;
                    }

                    sal_uLong nAbsMinCnts;
                    pTextNd->GetMinMaxSize( aIdx.GetIndex(), nMinFrm, nMaxFrm, nAbsMinCnts );
                }
                ++aIdx;
            }

            if( bOnlyOneNode )
            {
                if( nMinFrm < MINLAY && pFirstTextNd )
                {
                    // if the first node don't contained any content, then
                    // insert one char in it calc again and delete once again
                    SwIndex aNdIdx( pFirstTextNd );
                    pFirstTextNd->InsertText(OUString("MM"), aNdIdx);
                    sal_uLong nAbsMinCnts;
                    pFirstTextNd->GetMinMaxSize( pFirstTextNd->GetIndex(),
                                                                    nMinFrm, nMaxFrm, nAbsMinCnts );
                    aNdIdx -= 2;
                    pFirstTextNd->EraseText( aNdIdx, 2 );
                }

                // consider border and distance to content
                const SvxBoxItem& rBoxItem = static_cast<const SvxBoxItem&>(rFlySet.Get( RES_BOX ));
                SvxBoxItemLine nLine = SvxBoxItemLine::LEFT;
                for( int i = 0; i < 2; ++i )
                {
                    const editeng::SvxBorderLine* pLn = rBoxItem.GetLine( nLine );
                    if( pLn )
                    {
                        sal_uInt16 nWidthTmp = pLn->GetOutWidth() + pLn->GetInWidth();
                        nWidthTmp = nWidthTmp + rBoxItem.GetDistance( nLine );
                        nMinFrm += nWidthTmp;
                        nMaxFrm += nWidthTmp;
                    }
                    nLine = SvxBoxItemLine::RIGHT;
                }

                // enforce minimum width for contents
                if( nMinFrm < MINLAY )
                    nMinFrm = MINLAY;
                if( nMaxFrm < MINLAY )
                    nMaxFrm = MINLAY;

                if( nWidth > (sal_uInt16)nMaxFrm )
                    nWidth = nMaxFrm;
                else if( nWidth > (sal_uInt16)nMinFrm )
                    nWidth = nMinFrm;
            }
        }

        if( MINFLY > nWidth )
            nWidth = MINFLY;

        aSz.SetWidth( nWidth );
        if( MINFLY > aSz.GetHeight() )
            aSz.SetHeight( MINFLY );
        rFlySet.Put( aSz );
    }
    else if( MINFLY > static_cast<const SwFormatFrmSize*>(pItem)->GetHeight() )
    {
        SwFormatFrmSize aSz( *static_cast<const SwFormatFrmSize*>(pItem) );
        aSz.SetHeight( MINFLY );
        rFlySet.Put( aSz );
    }
}

namespace
{

struct CharSetNameMap
{
    rtl_TextEncoding eCode;
    const sal_Char* pName;
};

const CharSetNameMap *GetCharSetNameMap()
{
    static const CharSetNameMap aMapArr[] =
    {
#   define IMPLENTRY(X) { RTL_TEXTENCODING_##X, #X }
        IMPLENTRY(DONTKNOW),
        IMPLENTRY(MS_1252),
        IMPLENTRY(APPLE_ROMAN),
        IMPLENTRY(IBM_437),
        IMPLENTRY(IBM_850),
        IMPLENTRY(IBM_860),
        IMPLENTRY(IBM_861),
        IMPLENTRY(IBM_863),
        IMPLENTRY(IBM_865),
        IMPLENTRY(SYMBOL),
        IMPLENTRY(ASCII_US),
        IMPLENTRY(ISO_8859_1),
        IMPLENTRY(ISO_8859_2),
        IMPLENTRY(ISO_8859_3),
        IMPLENTRY(ISO_8859_4),
        IMPLENTRY(ISO_8859_5),
        IMPLENTRY(ISO_8859_6),
        IMPLENTRY(ISO_8859_7),
        IMPLENTRY(ISO_8859_8),
        IMPLENTRY(ISO_8859_9),
        IMPLENTRY(ISO_8859_14),
        IMPLENTRY(ISO_8859_15),
        IMPLENTRY(IBM_737),
        IMPLENTRY(IBM_775),
        IMPLENTRY(IBM_852),
        IMPLENTRY(IBM_855),
        IMPLENTRY(IBM_857),
        IMPLENTRY(IBM_862),
        IMPLENTRY(IBM_864),
        IMPLENTRY(IBM_866),
        IMPLENTRY(IBM_869),
        IMPLENTRY(MS_874),
        IMPLENTRY(MS_1250),
        IMPLENTRY(MS_1251),
        IMPLENTRY(MS_1253),
        IMPLENTRY(MS_1254),
        IMPLENTRY(MS_1255),
        IMPLENTRY(MS_1256),
        IMPLENTRY(MS_1257),
        IMPLENTRY(MS_1258),
        IMPLENTRY(APPLE_ARABIC),
        IMPLENTRY(APPLE_CENTEURO),
        IMPLENTRY(APPLE_CROATIAN),
        IMPLENTRY(APPLE_CYRILLIC),
        IMPLENTRY(APPLE_DEVANAGARI),
        IMPLENTRY(APPLE_FARSI),
        IMPLENTRY(APPLE_GREEK),
        IMPLENTRY(APPLE_GUJARATI),
        IMPLENTRY(APPLE_GURMUKHI),
        IMPLENTRY(APPLE_HEBREW),
        IMPLENTRY(APPLE_ICELAND),
        IMPLENTRY(APPLE_ROMANIAN),
        IMPLENTRY(APPLE_THAI),
        IMPLENTRY(APPLE_TURKISH),
        IMPLENTRY(APPLE_UKRAINIAN),
        IMPLENTRY(APPLE_CHINSIMP),
        IMPLENTRY(APPLE_CHINTRAD),
        IMPLENTRY(APPLE_JAPANESE),
        IMPLENTRY(APPLE_KOREAN),
        IMPLENTRY(MS_932),
        IMPLENTRY(MS_936),
        IMPLENTRY(MS_949),
        IMPLENTRY(MS_950),
        IMPLENTRY(SHIFT_JIS),
        IMPLENTRY(GB_2312),
        IMPLENTRY(GBT_12345),
        IMPLENTRY(GBK),
        IMPLENTRY(BIG5),
        IMPLENTRY(EUC_JP),
        IMPLENTRY(EUC_CN),
        IMPLENTRY(EUC_TW),
        IMPLENTRY(ISO_2022_JP),
        IMPLENTRY(ISO_2022_CN),
        IMPLENTRY(KOI8_R),
        IMPLENTRY(KOI8_U),
        IMPLENTRY(UTF7),
        IMPLENTRY(UTF8),
        IMPLENTRY(ISO_8859_10),
        IMPLENTRY(ISO_8859_13),
        IMPLENTRY(EUC_KR),
        IMPLENTRY(ISO_2022_KR),
        IMPLENTRY(JIS_X_0201),
        IMPLENTRY(JIS_X_0208),
        IMPLENTRY(JIS_X_0212),
        IMPLENTRY(MS_1361),
        IMPLENTRY(GB_18030),
        IMPLENTRY(BIG5_HKSCS),
        IMPLENTRY(TIS_620),
        IMPLENTRY(PT154),
        IMPLENTRY(UCS4),
        IMPLENTRY(UCS2),
        IMPLENTRY(UNICODE),
        {0,0}       //Last
    };
    return &aMapArr[0];
}

/*
 Get a rtl_TextEncoding from its name
 */
rtl_TextEncoding CharSetFromName(const OUString& rChrSetStr)
{
    const CharSetNameMap *pStart = GetCharSetNameMap();
    rtl_TextEncoding nRet = pStart->eCode;

    for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
    {
        if(rChrSetStr.equalsIgnoreAsciiCaseAscii(pMap->pName))
        {
            nRet = pMap->eCode;
            break;
        }
    }

    OSL_ENSURE(nRet != pStart->eCode, "TXT: That was an unknown language!");

        return nRet;
}

/*
 Get the String name of an rtl_TextEncoding
 */
OUString NameFromCharSet(rtl_TextEncoding nChrSet)
{
    const CharSetNameMap *pStart = GetCharSetNameMap();
    const char *pRet = pStart->pName;

    for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
    {
        if (nChrSet == pMap->eCode)
        {
            pRet = pMap->pName;
            break;
        }
    }

    OSL_ENSURE(pRet != pStart->pName, "TXT: That was an unknown language!");

    return OUString::createFromAscii(pRet);
}

}

// for the automatic conversion (mail/news/...)
// The user data contains the options for the ascii import/export filter.
// The format is:
//      1. CharSet - as ascii chars
//      2. LineEnd - as CR/LR/CRLF
//      3. Fontname
//      4. Language
// the delimiter character is ","

void SwAsciiOptions::ReadUserData( const OUString& rStr )
{
    sal_Int32 nToken = 0;
    int nCnt = 0;
    do {
        const OUString sToken = rStr.getToken( 0, ',', nToken );
        if (!sToken.isEmpty())
        {
            switch( nCnt )
            {
            case 0:         // CharSet
                eCharSet = CharSetFromName(sToken);
                break;
            case 1:         // LineEnd
                if (sToken.equalsIgnoreAsciiCase("CRLF"))
                    eCRLF_Flag = LINEEND_CRLF;
                else if (sToken.equalsIgnoreAsciiCase("LF"))
                    eCRLF_Flag = LINEEND_LF;
                else
                    eCRLF_Flag = LINEEND_CR;
                break;
            case 2:         // fontname
                sFont = sToken;
                break;
            case 3:         // Language
                nLanguage = LanguageTag::convertToLanguageTypeWithFallback( sToken );
                break;
            }
        }
        ++nCnt;
    } while( -1 != nToken );
}

void SwAsciiOptions::WriteUserData(OUString& rStr)
{
    // 1. charset
    rStr = NameFromCharSet(eCharSet) + ",";

    // 2. LineEnd
    switch(eCRLF_Flag)
    {
    case LINEEND_CRLF:
        rStr += "CRLF";
        break;
    case LINEEND_CR:
        rStr += "CR";
        break;
    case LINEEND_LF:
        rStr += "LF";
        break;
    }
    rStr += ",";

    // 3. Fontname
    rStr += sFont + ",";

    // 4. Language
    if (nLanguage)
    {
        rStr += LanguageTag::convertToBcp47(nLanguage);
    }
    rStr += ",";
}

#ifdef DISABLE_DYNLOADING

extern "C" {
    Reader *ImportRTF();
    void ExportRTF( const OUString&, const OUString& rBaseURL, WriterRef& );
    Reader *ImportDOC();
    void ExportDOC( const OUString&, const OUString& rBaseURL, WriterRef& );
    sal_uLong SaveOrDelMSVBAStorage_ww8( SfxObjectShell&, SotStorage&, sal_Bool, const OUString& );
    sal_uLong GetSaveWarningOfMSVBAStorage_ww8( SfxObjectShell& );
}

#endif

Reader* GetRTFReader()
{
#ifndef DISABLE_DYNLOADING

    FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportRTF" ) );

    if ( pFunction )
        return (*pFunction)();

    return NULL;
#else
    return ImportRTF();
#endif

}

void GetRTFWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
{
#ifndef DISABLE_DYNLOADING
    FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportRTF" ) );

    if ( pFunction )
        (*pFunction)( rFltName, rBaseURL, xRet );
    else
        xRet = WriterRef(0);
#else
    ExportRTF( rFltName, rBaseURL, xRet );
#endif
}

Reader* GetWW8Reader()
{
#ifndef DISABLE_DYNLOADING
    FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportDOC" ) );

    if ( pFunction )
        return (*pFunction)();

    return NULL;
#else
    return ImportDOC();
#endif
}

void GetWW8Writer( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
{
#ifndef DISABLE_DYNLOADING
    FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportDOC" ) );

    if ( pFunction )
        (*pFunction)( rFltName, rBaseURL, xRet );
    else
        xRet = WriterRef(0);
#else
    ExportDOC( rFltName, rBaseURL, xRet );
#endif
}

typedef sal_uLong ( SAL_CALL *SaveOrDel )( SfxObjectShell&, SotStorage&, sal_Bool, const OUString& );
typedef sal_uLong ( SAL_CALL *GetSaveWarning )( SfxObjectShell& );

sal_uLong SaveOrDelMSVBAStorage( SfxObjectShell& rDoc, SotStorage& rStor, bool bSaveInto, const OUString& rStorageName )
{
#ifndef DISABLE_DYNLOADING
    SaveOrDel pFunction = reinterpret_cast<SaveOrDel>( SwGlobals::getFilters().GetMswordLibSymbol( "SaveOrDelMSVBAStorage_ww8" ) );
    if( pFunction )
        return pFunction( rDoc, rStor, bSaveInto, rStorageName );
    return ERRCODE_NONE;
#else
    return SaveOrDelMSVBAStorage_ww8( rDoc, rStor, bSaveInto, rStorageName );
#endif
}

sal_uLong GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocS )
{
#ifndef DISABLE_DYNLOADING
    GetSaveWarning pFunction = reinterpret_cast<GetSaveWarning>( SwGlobals::getFilters().GetMswordLibSymbol( "GetSaveWarningOfMSVBAStorage_ww8" ) );
    if( pFunction )
        return pFunction( rDocS );
    return ERRCODE_NONE;
#else
    return GetSaveWarningOfMSVBAStorage_ww8( rDocS );
#endif
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */