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