Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <string.h>
21 : #include <stdio.h>
22 : #include <hintids.hxx>
23 : #include <i18nlangtag/lang.h>
24 : #include <i18nlangtag/languagetag.hxx>
25 : #include <vcl/msgbox.hxx>
26 : #include <svtools/parhtml.hxx>
27 : #include <sot/storage.hxx>
28 : #include <comphelper/classids.hxx>
29 : #include <sfx2/app.hxx>
30 : #include <sfx2/docfilt.hxx>
31 : #include <sfx2/fcontnr.hxx>
32 : #include <sfx2/docfile.hxx>
33 : #include <editeng/lrspitem.hxx>
34 : #include <editeng/tstpitem.hxx>
35 : #include <doc.hxx>
36 : #include <docary.hxx>
37 : #include <pam.hxx>
38 : #include <shellio.hxx>
39 : #include <docsh.hxx>
40 : #include <wdocsh.hxx>
41 : #include <fltini.hxx>
42 : #include <hints.hxx>
43 : #include <init.hxx>
44 : #include <frmatr.hxx>
45 : #include <fmtfsize.hxx>
46 : #include <swtable.hxx>
47 : #include <fmtcntnt.hxx>
48 : #include <editeng/boxitem.hxx>
49 : #include <frmfmt.hxx>
50 : #include <numrule.hxx>
51 : #include <ndtxt.hxx>
52 : #include <swfltopt.hxx>
53 : #include <swerror.h>
54 : #include <swdll.hxx>
55 : #include <osl/module.hxx>
56 : #include <comphelper/processfactory.hxx>
57 : #include <com/sun/star/beans/XPropertySet.hpp>
58 : #include <com/sun/star/util/XMacroExpander.hpp>
59 : #include <rtl/bootstrap.hxx>
60 :
61 : using namespace utl;
62 : using namespace com::sun::star::uno;
63 : using namespace com::sun::star;
64 :
65 : SwRead ReadAscii = 0, ReadHTML = 0, ReadXML = 0;
66 :
67 : Reader* GetRTFReader();
68 : Reader* GetWW8Reader();
69 :
70 : // Note: if editing, please don't forget to modify also the enum
71 : // ReaderWriterEnum and aFilterDetect in shellio.hxx
72 90 : SwReaderWriterEntry aReaderWriter[] =
73 : {
74 : SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, true ),
75 : SwReaderWriterEntry( 0, &::GetASCWriter, false ),
76 : SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer, true ),
77 : SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer, true ),
78 : SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, true ),
79 : SwReaderWriterEntry( 0, &::GetHTMLWriter, true ),
80 : SwReaderWriterEntry( &::GetWW8Reader, 0, true ),
81 : SwReaderWriterEntry( 0, &::GetXMLWriter, true ),
82 : SwReaderWriterEntry( 0, &::GetASCWriter, false ),
83 : SwReaderWriterEntry( 0, &::GetASCWriter, true )
84 90 : };
85 :
86 222 : Reader* SwReaderWriterEntry::GetReader()
87 : {
88 222 : if ( pReader )
89 204 : return pReader;
90 18 : else if ( fnGetReader )
91 : {
92 18 : pReader = (*fnGetReader)();
93 18 : return pReader;
94 : }
95 0 : return NULL;
96 : }
97 :
98 15464 : void SwReaderWriterEntry::GetWriter( const OUString& rNm, const OUString& rBaseURL, WriterRef& xWrt ) const
99 : {
100 15464 : if ( fnGetWriter )
101 15464 : (*fnGetWriter)( rNm, rBaseURL, xWrt );
102 : else
103 0 : xWrt = WriterRef(0);
104 15464 : }
105 :
106 0 : SwRead SwGetReaderXML() // SW_DLLPUBLIC
107 : {
108 0 : return ReadXML;
109 : }
110 :
111 450 : inline void _SetFltPtr( sal_uInt16 rPos, SwRead pReader )
112 : {
113 450 : aReaderWriter[ rPos ].pReader = pReader;
114 450 : }
115 :
116 : namespace sw {
117 :
118 90 : Filters::Filters()
119 : {
120 90 : _SetFltPtr( READER_WRITER_BAS, (ReadAscii = new AsciiReader) );
121 90 : _SetFltPtr( READER_WRITER_HTML, (ReadHTML = new HTMLReader) );
122 90 : _SetFltPtr( READER_WRITER_XML, (ReadXML = new XMLReader) );
123 90 : _SetFltPtr( READER_WRITER_TEXT_DLG, ReadAscii );
124 90 : _SetFltPtr( READER_WRITER_TEXT, ReadAscii );
125 90 : }
126 :
127 180 : Filters::~Filters()
128 : {
129 : // kill Readers
130 990 : for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
131 : {
132 900 : SwReaderWriterEntry& rEntry = aReaderWriter[n];
133 900 : if( rEntry.bDelReader && rEntry.pReader )
134 288 : delete rEntry.pReader, rEntry.pReader = NULL;
135 : }
136 90 : }
137 :
138 : #ifndef DISABLE_DYNLOADING
139 :
140 54 : oslGenericFunction Filters::GetMswordLibSymbol( const char *pSymbol )
141 : {
142 54 : if (!msword_.is())
143 : {
144 16 : OUString url("$LO_LIB_DIR/" SVLIBRARY("msword"));
145 16 : rtl::Bootstrap::expandMacros(url);
146 16 : bool ok = msword_.load( url, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY );
147 16 : SAL_WARN_IF(!ok, "sw", "failed to load msword library");
148 : }
149 54 : if (msword_.is())
150 54 : return msword_.getFunctionSymbol( OUString::createFromAscii( pSymbol ) );
151 0 : return NULL;
152 : }
153 :
154 : #endif
155 :
156 : }
157 :
158 : namespace SwReaderWriter {
159 :
160 2 : SW_DLLPUBLIC Reader* GetReader( ReaderWriterEnum eReader )
161 : {
162 2 : return aReaderWriter[eReader].GetReader();
163 : }
164 :
165 15464 : SW_DLLPUBLIC void GetWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
166 : {
167 138922 : for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
168 138922 : if ( aFilterDetect[n].IsFilter( rFltName ) )
169 : {
170 15464 : aReaderWriter[n].GetWriter( rFltName, rBaseURL, xRet );
171 15464 : break;
172 : }
173 15464 : }
174 :
175 220 : SwRead GetReader( const OUString& rFltName )
176 : {
177 220 : SwRead pRead = 0;
178 966 : for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
179 966 : if ( aFilterDetect[n].IsFilter( rFltName ) )
180 : {
181 220 : pRead = aReaderWriter[n].GetReader();
182 : // add special treatment for some readers
183 220 : if ( pRead )
184 220 : pRead->SetFltName( rFltName );
185 220 : break;
186 : }
187 220 : return pRead;
188 : }
189 :
190 : } // namespace SwReaderWriter
191 :
192 0 : void Writer::SetVersion( const OUString&, long ) {}
193 :
194 15456 : bool Writer::IsStgWriter() const { return false; }
195 :
196 126 : bool StgWriter::IsStgWriter() const { return true; }
197 :
198 220 : bool SwReader::NeedsPasswd( const Reader& /*rOptions*/ )
199 : {
200 220 : return false;
201 : }
202 :
203 0 : bool SwReader::CheckPasswd( const OUString& /*rPasswd*/, const Reader& /*rOptions*/ )
204 : {
205 0 : return true;
206 : }
207 :
208 : // Read Filter Flags; used by WW8 / W4W / EXCEL / LOTUS
209 :
210 : /*
211 : <FilterFlags>
212 : <Excel_Lotus>
213 : <MinRow cfg:type="long">0</MinRow>
214 : <MaxRow cfg:type="long">0</MaxRow>
215 : <MinCol cfg:type="long">0</MinCol>
216 : <MaxCol cfg:type="long">0</MaxCol>
217 : </Excel_Lotus>
218 : <W4W>
219 : <W4WHD cfg:type="long">0</W4WHD>
220 : <W4WFT cfg:type="long">0</W4WFT>
221 : <W4W000 cfg:type="long">0</W4W000>
222 : </W4W>
223 : <WinWord>
224 : <WW1F cfg:type="long">0</WW1F>
225 : <WW cfg:type="long">0</WW>
226 : <WW8 cfg:type="long">0</WW8>
227 : <WWF cfg:type="long">0</WWF>
228 : <WWFA0 cfg:type="long">0</WWFA0>
229 : <WWFA1 cfg:type="long">0</WWFA1>
230 : <WWFA2 cfg:type="long">0</WWFA2>
231 : <WWFB0 cfg:type="long">0</WWFB0>
232 : <WWFB1 cfg:type="long">0</WWFB1>
233 : <WWFB2 cfg:type="long">0</WWFB2>
234 : <WWFLX cfg:type="long">0</WWFLX>
235 : <WWFLY cfg:type="long">0</WWFLY>
236 : <WWFT cfg:type="long">0</WWFT>
237 : <WWWR cfg:type="long">0</WWWR>
238 : </WinWord>
239 : <Writer>
240 : <SW3Imp cfg:type="long">0</SW3Imp>
241 : </Writer>
242 : </FilterFlags>
243 : */
244 :
245 : #define FILTER_OPTION_ROOT OUString("Office.Writer/FilterFlags")
246 :
247 190 : SwFilterOptions::SwFilterOptions( sal_uInt16 nCnt, const sal_Char** ppNames,
248 : sal_uInt32* pValues )
249 190 : : ConfigItem( FILTER_OPTION_ROOT )
250 : {
251 190 : GetValues( nCnt, ppNames, pValues );
252 190 : }
253 :
254 190 : void SwFilterOptions::GetValues( sal_uInt16 nCnt, const sal_Char** ppNames,
255 : sal_uInt32* pValues )
256 : {
257 190 : Sequence<OUString> aNames( nCnt );
258 190 : OUString* pNames = aNames.getArray();
259 : sal_uInt16 n;
260 :
261 2660 : for( n = 0; n < nCnt; ++n )
262 2470 : pNames[ n ] = OUString::createFromAscii( ppNames[ n ] );
263 380 : Sequence<Any> aValues = GetProperties( aNames );
264 :
265 190 : if( nCnt == aValues.getLength() )
266 : {
267 190 : const Any* pAnyValues = aValues.getConstArray();
268 2660 : for( n = 0; n < nCnt; ++n )
269 2470 : pValues[ n ] = pAnyValues[ n ].hasValue()
270 2470 : ? *(sal_uInt32*)pAnyValues[ n ].getValue()
271 4940 : : 0;
272 : }
273 : else
274 0 : for( n = 0; n < nCnt; ++n )
275 190 : pValues[ n ] = 0;
276 190 : }
277 :
278 0 : void SwFilterOptions::Commit() {}
279 0 : void SwFilterOptions::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
280 :
281 192 : void StgReader::SetFltName( const OUString& rFltNm )
282 : {
283 192 : if( SW_STORAGE_READER & GetReaderType() )
284 192 : aFltName = rFltNm;
285 192 : }
286 :
287 186 : SwRelNumRuleSpaces::SwRelNumRuleSpaces( SwDoc& rDoc, bool bNDoc )
288 : {
289 186 : pNumRuleTbl = new SwNumRuleTbl();
290 186 : pNumRuleTbl->reserve(8);
291 186 : if( !bNDoc )
292 0 : pNumRuleTbl->insert( pNumRuleTbl->begin(),
293 0 : rDoc.GetNumRuleTbl().begin(), rDoc.GetNumRuleTbl().end() );
294 186 : }
295 :
296 186 : SwRelNumRuleSpaces::~SwRelNumRuleSpaces()
297 : {
298 186 : if( pNumRuleTbl )
299 : {
300 186 : pNumRuleTbl->clear();
301 186 : delete pNumRuleTbl;
302 : }
303 186 : }
304 :
305 6 : void CalculateFlySize(SfxItemSet& rFlySet, const SwNodeIndex& rAnchor,
306 : SwTwips nPageWidth)
307 : {
308 6 : const SfxPoolItem* pItem = 0;
309 6 : if( SfxItemState::SET != rFlySet.GetItemState( RES_FRM_SIZE, true, &pItem ) ||
310 0 : MINFLY > ((SwFmtFrmSize*)pItem)->GetWidth() )
311 : {
312 6 : SwFmtFrmSize aSz((SwFmtFrmSize&)rFlySet.Get(RES_FRM_SIZE, true));
313 6 : if (pItem)
314 0 : aSz = (SwFmtFrmSize&)(*pItem);
315 :
316 : SwTwips nWidth;
317 : // determine the width; if there is a table use the width of the table;
318 : // otherwise use the width of the page
319 6 : const SwTableNode* pTblNd = rAnchor.GetNode().FindTableNode();
320 6 : if( pTblNd )
321 0 : nWidth = pTblNd->GetTable().GetFrmFmt()->GetFrmSize().GetWidth();
322 : else
323 6 : nWidth = nPageWidth;
324 :
325 6 : const SwNodeIndex* pSttNd = ((SwFmtCntnt&)rFlySet.Get( RES_CNTNT )).
326 6 : GetCntntIdx();
327 6 : if( pSttNd )
328 : {
329 6 : bool bOnlyOneNode = true;
330 6 : sal_uLong nMinFrm = 0;
331 6 : sal_uLong nMaxFrm = 0;
332 6 : SwTxtNode* pFirstTxtNd = 0;
333 6 : SwNodeIndex aIdx( *pSttNd, 1 );
334 12 : SwNodeIndex aEnd( *pSttNd->GetNode().EndOfSectionNode() );
335 18 : while( aIdx < aEnd )
336 : {
337 12 : SwTxtNode *pTxtNd = aIdx.GetNode().GetTxtNode();
338 12 : if( pTxtNd )
339 : {
340 12 : if( !pFirstTxtNd )
341 6 : pFirstTxtNd = pTxtNd;
342 6 : else if( pFirstTxtNd != pTxtNd )
343 : {
344 : // forget it
345 6 : bOnlyOneNode = false;
346 6 : break;
347 : }
348 :
349 : sal_uLong nAbsMinCnts;
350 : pTxtNd->GetMinMaxSize( aIdx.GetIndex(), nMinFrm,
351 6 : nMaxFrm, nAbsMinCnts );
352 : }
353 6 : ++aIdx;
354 : }
355 :
356 6 : if( bOnlyOneNode )
357 : {
358 0 : if( nMinFrm < MINLAY && pFirstTxtNd )
359 : {
360 : // if the first node dont contained any content, then
361 : // insert one char in it calc again and delete once again
362 0 : SwIndex aNdIdx( pFirstTxtNd );
363 0 : pFirstTxtNd->InsertText(OUString("MM"), aNdIdx);
364 : sal_uLong nAbsMinCnts;
365 : pFirstTxtNd->GetMinMaxSize( pFirstTxtNd->GetIndex(),
366 0 : nMinFrm, nMaxFrm, nAbsMinCnts );
367 0 : aNdIdx -= 2;
368 0 : pFirstTxtNd->EraseText( aNdIdx, 2 );
369 : }
370 :
371 : // consider border and distance to content
372 0 : const SvxBoxItem& rBoxItem = (SvxBoxItem&)rFlySet.Get( RES_BOX );
373 0 : sal_uInt16 nLine = BOX_LINE_LEFT;
374 0 : for( int i = 0; i < 2; ++i )
375 : {
376 0 : const editeng::SvxBorderLine* pLn = rBoxItem.GetLine( nLine );
377 0 : if( pLn )
378 : {
379 0 : sal_uInt16 nWidthTmp = pLn->GetOutWidth() + pLn->GetInWidth();
380 0 : nWidthTmp = nWidthTmp + rBoxItem.GetDistance( nLine );
381 0 : nMinFrm += nWidthTmp;
382 0 : nMaxFrm += nWidthTmp;
383 : }
384 0 : nLine = BOX_LINE_RIGHT;
385 : }
386 :
387 : // enforce minimum width for contents
388 0 : if( nMinFrm < MINLAY )
389 0 : nMinFrm = MINLAY;
390 0 : if( nMaxFrm < MINLAY )
391 0 : nMaxFrm = MINLAY;
392 :
393 0 : if( nWidth > (sal_uInt16)nMaxFrm )
394 0 : nWidth = nMaxFrm;
395 0 : else if( nWidth > (sal_uInt16)nMinFrm )
396 0 : nWidth = nMinFrm;
397 6 : }
398 : }
399 :
400 6 : if( MINFLY > nWidth )
401 0 : nWidth = MINFLY;
402 :
403 6 : aSz.SetWidth( nWidth );
404 6 : if( MINFLY > aSz.GetHeight() )
405 6 : aSz.SetHeight( MINFLY );
406 6 : rFlySet.Put( aSz );
407 : }
408 0 : else if( MINFLY > ((SwFmtFrmSize*)pItem)->GetHeight() )
409 : {
410 0 : SwFmtFrmSize aSz( *(SwFmtFrmSize*)pItem );
411 0 : aSz.SetHeight( MINFLY );
412 0 : rFlySet.Put( aSz );
413 : }
414 6 : }
415 :
416 : namespace
417 : {
418 :
419 : struct CharSetNameMap
420 : {
421 : rtl_TextEncoding eCode;
422 : const sal_Char* pName;
423 : };
424 :
425 6 : const CharSetNameMap *GetCharSetNameMap()
426 : {
427 : static const CharSetNameMap aMapArr[] =
428 : {
429 : # define IMPLENTRY(X) { RTL_TEXTENCODING_##X, "" #X "" }
430 : IMPLENTRY(DONTKNOW),
431 : IMPLENTRY(MS_1252),
432 : IMPLENTRY(APPLE_ROMAN),
433 : IMPLENTRY(IBM_437),
434 : IMPLENTRY(IBM_850),
435 : IMPLENTRY(IBM_860),
436 : IMPLENTRY(IBM_861),
437 : IMPLENTRY(IBM_863),
438 : IMPLENTRY(IBM_865),
439 : IMPLENTRY(SYMBOL),
440 : IMPLENTRY(ASCII_US),
441 : IMPLENTRY(ISO_8859_1),
442 : IMPLENTRY(ISO_8859_2),
443 : IMPLENTRY(ISO_8859_3),
444 : IMPLENTRY(ISO_8859_4),
445 : IMPLENTRY(ISO_8859_5),
446 : IMPLENTRY(ISO_8859_6),
447 : IMPLENTRY(ISO_8859_7),
448 : IMPLENTRY(ISO_8859_8),
449 : IMPLENTRY(ISO_8859_9),
450 : IMPLENTRY(ISO_8859_14),
451 : IMPLENTRY(ISO_8859_15),
452 : IMPLENTRY(IBM_737),
453 : IMPLENTRY(IBM_775),
454 : IMPLENTRY(IBM_852),
455 : IMPLENTRY(IBM_855),
456 : IMPLENTRY(IBM_857),
457 : IMPLENTRY(IBM_862),
458 : IMPLENTRY(IBM_864),
459 : IMPLENTRY(IBM_866),
460 : IMPLENTRY(IBM_869),
461 : IMPLENTRY(MS_874),
462 : IMPLENTRY(MS_1250),
463 : IMPLENTRY(MS_1251),
464 : IMPLENTRY(MS_1253),
465 : IMPLENTRY(MS_1254),
466 : IMPLENTRY(MS_1255),
467 : IMPLENTRY(MS_1256),
468 : IMPLENTRY(MS_1257),
469 : IMPLENTRY(MS_1258),
470 : IMPLENTRY(APPLE_ARABIC),
471 : IMPLENTRY(APPLE_CENTEURO),
472 : IMPLENTRY(APPLE_CROATIAN),
473 : IMPLENTRY(APPLE_CYRILLIC),
474 : IMPLENTRY(APPLE_DEVANAGARI),
475 : IMPLENTRY(APPLE_FARSI),
476 : IMPLENTRY(APPLE_GREEK),
477 : IMPLENTRY(APPLE_GUJARATI),
478 : IMPLENTRY(APPLE_GURMUKHI),
479 : IMPLENTRY(APPLE_HEBREW),
480 : IMPLENTRY(APPLE_ICELAND),
481 : IMPLENTRY(APPLE_ROMANIAN),
482 : IMPLENTRY(APPLE_THAI),
483 : IMPLENTRY(APPLE_TURKISH),
484 : IMPLENTRY(APPLE_UKRAINIAN),
485 : IMPLENTRY(APPLE_CHINSIMP),
486 : IMPLENTRY(APPLE_CHINTRAD),
487 : IMPLENTRY(APPLE_JAPANESE),
488 : IMPLENTRY(APPLE_KOREAN),
489 : IMPLENTRY(MS_932),
490 : IMPLENTRY(MS_936),
491 : IMPLENTRY(MS_949),
492 : IMPLENTRY(MS_950),
493 : IMPLENTRY(SHIFT_JIS),
494 : IMPLENTRY(GB_2312),
495 : IMPLENTRY(GBT_12345),
496 : IMPLENTRY(GBK),
497 : IMPLENTRY(BIG5),
498 : IMPLENTRY(EUC_JP),
499 : IMPLENTRY(EUC_CN),
500 : IMPLENTRY(EUC_TW),
501 : IMPLENTRY(ISO_2022_JP),
502 : IMPLENTRY(ISO_2022_CN),
503 : IMPLENTRY(KOI8_R),
504 : IMPLENTRY(KOI8_U),
505 : IMPLENTRY(UTF7),
506 : IMPLENTRY(UTF8),
507 : IMPLENTRY(ISO_8859_10),
508 : IMPLENTRY(ISO_8859_13),
509 : IMPLENTRY(EUC_KR),
510 : IMPLENTRY(ISO_2022_KR),
511 : IMPLENTRY(JIS_X_0201),
512 : IMPLENTRY(JIS_X_0208),
513 : IMPLENTRY(JIS_X_0212),
514 : IMPLENTRY(MS_1361),
515 : IMPLENTRY(GB_18030),
516 : IMPLENTRY(BIG5_HKSCS),
517 : IMPLENTRY(TIS_620),
518 : IMPLENTRY(PT154),
519 : IMPLENTRY(UCS4),
520 : IMPLENTRY(UCS2),
521 : IMPLENTRY(UNICODE),
522 : {0,0} //Last
523 : };
524 6 : return &aMapArr[0];
525 : }
526 :
527 : /*
528 : Get a rtl_TextEncoding from its name
529 : */
530 6 : rtl_TextEncoding CharSetFromName(const OUString& rChrSetStr)
531 : {
532 6 : const CharSetNameMap *pStart = GetCharSetNameMap();
533 6 : rtl_TextEncoding nRet = pStart->eCode;
534 :
535 462 : for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
536 : {
537 462 : if(rChrSetStr.equalsIgnoreAsciiCaseAscii(pMap->pName))
538 : {
539 6 : nRet = pMap->eCode;
540 6 : break;
541 : }
542 : }
543 :
544 : OSL_ENSURE(nRet != pStart->eCode, "TXT: That was an unknown language!");
545 :
546 6 : return nRet;
547 : }
548 :
549 : /*
550 : Get the String name of an rtl_TextEncoding
551 : */
552 0 : OUString NameFromCharSet(rtl_TextEncoding nChrSet)
553 : {
554 0 : const CharSetNameMap *pStart = GetCharSetNameMap();
555 0 : const char *pRet = pStart->pName;
556 :
557 0 : for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
558 : {
559 0 : if (nChrSet == pMap->eCode)
560 : {
561 0 : pRet = pMap->pName;
562 0 : break;
563 : }
564 : }
565 :
566 : OSL_ENSURE(pRet != pStart->pName, "TXT: That was an unknown language!");
567 :
568 0 : return OUString::createFromAscii(pRet);
569 : }
570 :
571 : }
572 :
573 : // for the automatic conversion (mail/news/...)
574 : // The user data contains the options for the ascii import/export filter.
575 : // The format is:
576 : // 1. CharSet - as ascii chars
577 : // 2. LineEnd - as CR/LR/CRLF
578 : // 3. Fontname
579 : // 4. Language
580 : // the delimiter character is ","
581 :
582 6 : void SwAsciiOptions::ReadUserData( const OUString& rStr )
583 : {
584 6 : sal_Int32 nToken = 0;
585 6 : sal_uInt16 nCnt = 0;
586 24 : do {
587 24 : const OUString sToken = rStr.getToken( 0, ',', nToken );
588 24 : if (!sToken.isEmpty())
589 : {
590 24 : switch( nCnt )
591 : {
592 : case 0: // CharSet
593 6 : eCharSet = CharSetFromName(sToken);
594 6 : break;
595 : case 1: // LineEnd
596 6 : if (sToken.equalsIgnoreAsciiCase("CRLF"))
597 0 : eCRLF_Flag = LINEEND_CRLF;
598 6 : else if (sToken.equalsIgnoreAsciiCase("LF"))
599 6 : eCRLF_Flag = LINEEND_LF;
600 : else
601 0 : eCRLF_Flag = LINEEND_CR;
602 6 : break;
603 : case 2: // fontname
604 6 : sFont = sToken;
605 6 : break;
606 : case 3: // Language
607 6 : nLanguage = LanguageTag::convertToLanguageTypeWithFallback( sToken );
608 6 : break;
609 : }
610 : }
611 24 : ++nCnt;
612 24 : } while( -1 != nToken );
613 6 : }
614 :
615 0 : void SwAsciiOptions::WriteUserData(OUString& rStr)
616 : {
617 : // 1. charset
618 0 : rStr = NameFromCharSet(eCharSet) + ",";
619 :
620 : // 2. LineEnd
621 0 : switch(eCRLF_Flag)
622 : {
623 : case LINEEND_CRLF:
624 0 : rStr += "CRLF";
625 0 : break;
626 : case LINEEND_CR:
627 0 : rStr += "CR";
628 0 : break;
629 : case LINEEND_LF:
630 0 : rStr += "LF";
631 0 : break;
632 : }
633 0 : rStr += ",";
634 :
635 : // 3. Fontname
636 0 : rStr += sFont + ",";
637 :
638 : // 4. Language
639 0 : if (nLanguage)
640 : {
641 0 : rStr += LanguageTag::convertToBcp47(nLanguage);
642 : }
643 0 : rStr += ",";
644 0 : }
645 :
646 : #ifdef DISABLE_DYNLOADING
647 :
648 : extern "C" {
649 : Reader *ImportRTF();
650 : void ExportRTF( const OUString&, const OUString& rBaseURL, WriterRef& );
651 : Reader *ImportDOC();
652 : void ExportDOC( const OUString&, const OUString& rBaseURL, WriterRef& );
653 : sal_uLong SaveOrDelMSVBAStorage_ww8( SfxObjectShell&, SotStorage&, sal_Bool, const OUString& );
654 : sal_uLong GetSaveWarningOfMSVBAStorage_ww8( SfxObjectShell& );
655 : }
656 :
657 : #endif
658 :
659 2 : Reader* GetRTFReader()
660 : {
661 : #ifndef DISABLE_DYNLOADING
662 :
663 2 : FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportRTF" ) );
664 :
665 2 : if ( pFunction )
666 2 : return (*pFunction)();
667 :
668 0 : return NULL;
669 : #else
670 : return ImportRTF();
671 : #endif
672 :
673 : }
674 :
675 2 : void GetRTFWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
676 : {
677 : #ifndef DISABLE_DYNLOADING
678 2 : FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportRTF" ) );
679 :
680 2 : if ( pFunction )
681 2 : (*pFunction)( rFltName, rBaseURL, xRet );
682 : else
683 0 : xRet = WriterRef(0);
684 : #else
685 : ExportRTF( rFltName, rBaseURL, xRet );
686 : #endif
687 2 : }
688 :
689 16 : Reader* GetWW8Reader()
690 : {
691 : #ifndef DISABLE_DYNLOADING
692 16 : FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportDOC" ) );
693 :
694 16 : if ( pFunction )
695 16 : return (*pFunction)();
696 :
697 0 : return NULL;
698 : #else
699 : return ImportDOC();
700 : #endif
701 : }
702 :
703 34 : void GetWW8Writer( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
704 : {
705 : #ifndef DISABLE_DYNLOADING
706 34 : FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportDOC" ) );
707 :
708 34 : if ( pFunction )
709 34 : (*pFunction)( rFltName, rBaseURL, xRet );
710 : else
711 0 : xRet = WriterRef(0);
712 : #else
713 : ExportDOC( rFltName, rBaseURL, xRet );
714 : #endif
715 34 : }
716 :
717 : typedef sal_uLong ( SAL_CALL *SaveOrDel )( SfxObjectShell&, SotStorage&, sal_Bool, const OUString& );
718 : typedef sal_uLong ( SAL_CALL *GetSaveWarning )( SfxObjectShell& );
719 :
720 0 : sal_uLong SaveOrDelMSVBAStorage( SfxObjectShell& rDoc, SotStorage& rStor, bool bSaveInto, const OUString& rStorageName )
721 : {
722 : #ifndef DISABLE_DYNLOADING
723 0 : SaveOrDel pFunction = reinterpret_cast<SaveOrDel>( SwGlobals::getFilters().GetMswordLibSymbol( "SaveOrDelMSVBAStorage_ww8" ) );
724 0 : if( pFunction )
725 0 : return pFunction( rDoc, rStor, bSaveInto, rStorageName );
726 0 : return ERRCODE_NONE;
727 : #else
728 : return SaveOrDelMSVBAStorage_ww8( rDoc, rStor, bSaveInto, rStorageName );
729 : #endif
730 : }
731 :
732 0 : sal_uLong GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocS )
733 : {
734 : #ifndef DISABLE_DYNLOADING
735 0 : GetSaveWarning pFunction = reinterpret_cast<GetSaveWarning>( SwGlobals::getFilters().GetMswordLibSymbol( "GetSaveWarningOfMSVBAStorage_ww8" ) );
736 0 : if( pFunction )
737 0 : return pFunction( rDocS );
738 0 : return ERRCODE_NONE;
739 : #else
740 : return GetSaveWarningOfMSVBAStorage_ww8( rDocS );
741 : #endif
742 270 : }
743 :
744 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|