bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / filter / inc / msfilter.hxx
blob5fbc9547ff124c1f5c0443f78b68b15329130b84
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SW_MS_MSFILTER_HXX
21 #define SW_MS_MSFILTER_HXX
23 #include <set>
24 #include <map>
25 #include <vector>
26 #include <swtypes.hxx> //SwTwips
27 #include <tools/string.hxx> //String
28 #include "wwstyles.hxx" //ww::sti
29 #include <rtl/textenc.h> //rtl_TextEncoding
30 #include <tools/gen.hxx> //Size
31 #include <filter/msfilter/util.hxx>
32 #include <fltshell.hxx> // fuer den Attribut Stack
33 #include <redline.hxx>
34 #include <shellio.hxx>
35 #include <svl/zforlist.hxx>
37 #include <boost/noncopyable.hpp>
39 class SwDoc;
40 class SwPaM;
41 class String;
42 class SwTableNode;
43 class SwNodeIndex;
44 class SwNoTxtNode;
45 class SwTxtNode;
46 class WW8TabDesc;
48 namespace myImplHelpers
50 template<class C> class StyleMapperImpl;
53 class SwTxtFmtColl;
54 class SwCharFmt;
55 typedef myImplHelpers::StyleMapperImpl<SwTxtFmtColl> ParaMapper;
56 typedef myImplHelpers::StyleMapperImpl<SwCharFmt> CharMapper;
58 namespace sw
60 namespace ms
62 /** MSOffice appears to set the charset of unicode fonts to MS 932
64 Arial Unicode MS for example is a unicode font, but word sets
65 exported uses of it to the MS 932 charset
67 @param eTextEncoding
68 the OOo encoding to convert from
70 @return
71 a msoffice equivalent charset identifier
73 @author
74 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
76 sal_uInt8 rtl_TextEncodingToWinCharset(rtl_TextEncoding eTextEncoding);
78 /** Import a MSWord XE field. Suitable for .doc and .rtf
80 @param rDoc
81 the document to insert into
83 @param rPaM
84 the position in the document to insert into
86 @param rXE
87 the arguments of the original word XE field
89 @author
90 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
92 void ImportXE(SwDoc &rDoc, SwPaM &rPaM, const String &rXE);
94 /** Convert from DTTM to Writer's DateTime
96 @author
97 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
99 long DateTime2DTTM( const DateTime& rDT );
101 /** Convert from Word Date/Time field str to Writer's Date Time str
103 @author
104 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
106 sal_uLong MSDateTimeFormatToSwFormat(String& rParams, SvNumberFormatter *pFormatter, sal_uInt16 &rLang, bool bHijri, sal_uInt16 nDocLang);
108 /*Used to identify if the previous token is AM time field*/
109 sal_Bool IsPreviousAM(String& rParams, xub_StrLen nPos);
111 /*Used to identify if the next token is PM time field*/
112 sal_Bool IsNextPM(String& rParams, xub_StrLen nPos);
114 /** Used by MSDateTimeFormatToSwFormat to identify AM time fields
116 @author
117 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
119 bool IsNotAM(String& rParams, xub_StrLen nPos);
121 /** Another function used by MSDateTimeFormatToSwFormat
123 @author
124 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
126 void SwapQuotesInField(String &rFmt);
130 namespace util
132 /// Redlining Authors, map word author key to writer author value
133 typedef std::map<sal_uInt16, sal_uInt16> AuthorInfos;
135 /** Clips a value to MAX/MIN 16bit value to make it safe for use
136 as a position value to give to writer. i.e. +-57.8cm. Sometimes
137 we see ridiculous values for positioning in rtf and word document,
138 this captures such ones and clips them to values which are
139 still outside the document, but of a value that doesn't cause
140 problems for writer's layout, e.g. see
141 http://www.openoffice.org/issues/show_bug.cgi?id=i9245
143 @param nIn
145 @return nIn clipped to min/max 16bit value
147 @author
148 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
150 SwTwips MakeSafePositioningValue(SwTwips nIn);
152 /** Knows which writer style a given word style should be imported as
154 Mapping a word style to a writer style has to consider mapping
155 the word builtin styles like "Normal" as the default root style
156 to our default root style which is called "Default" in english,
157 and "Normal" in german.
159 Additionally it then has to avoid name collisions such as
161 a) styles "Normal" and "Default" in a single document, where
162 we can use the original distinct names "Normal" and "Default" and..
163 b) styles "Normal" and "Default" in a single document, where
164 we can not use the original names, and must come up with an
165 alternative name for one of them..
167 And it needs to report to the importer if the style being mapped to
168 was already in existance, for the cut and paste/insert file mode we
169 should not modify the returned style if it is already in use as it
170 is does not belong to us to change.
172 @author
173 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
175 class ParaStyleMapper
177 private:
178 //I hate these things stupid pImpl things, but its warranted here
179 ParaMapper *mpImpl;
180 public:
181 ParaStyleMapper(SwDoc &rDoc);
182 ~ParaStyleMapper();
184 /** StyleResult
185 StyleResult is a std::pair of a pointer to a style and a flag
186 which is true if the style existed previously in the document.
188 typedef std::pair<SwTxtFmtColl*, bool> StyleResult;
190 /** Get the writer style which the word style should map to
192 @param rName
193 The name of the word style
195 @param eSti
196 The style id of the word style, we are really only interested
197 in knowing if the style has either a builtin standard id, or is
198 a user defined style.
200 @return
201 The equivalent writer style packaged as a StyleResult to use
202 for this word style.
204 It will only return a failure in the pathological case of
205 catastropic failure elsewhere of there exist already styles
206 rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely
207 and impossible.
209 StyleResult GetStyle(const String& rName, ww::sti eSti);
212 /** Knows which writer style a given word style should be imported as
214 Mapping a word style to a writer style has to consider mapping
215 the word builtin styles like "Normal" as the default root style
216 to our default root style which is called "Default" in english,
217 and "Normal" in german.
219 Additionally it then has to avoid name collisions such as
221 a) styles "Normal" and "Default" in a single document, where
222 we can use the original distinct names "Normal" and "Default" and..
223 b) styles "Normal" and "Default" in a single document, where
224 we can not use the original names, and must come up with an
225 alternative name for one of them..
227 And it needs to report to the importer if the style being mapped to
228 was already in existance, for the cut and paste/insert file mode we
229 should not modify the returned style if it is already in use as it
230 is does not belong to us to change.
232 @author
233 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
235 class CharStyleMapper
237 private:
238 //I hate these things stupid pImpl things, but its warranted here
239 CharMapper *mpImpl;
240 public:
241 CharStyleMapper(SwDoc &rDoc);
242 ~CharStyleMapper();
244 /** StyleResult
245 StyleResult is a std::pair of a pointer to a style and a flag
246 which is true if the style existed previously in the document.
248 typedef std::pair<SwCharFmt*, bool> StyleResult;
250 /** Get the writer style which the word style should map to
252 @param rName
253 The name of the word style
255 @param eSti
256 The style id of the word style, we are really only interested
257 in knowing if the style has either a builtin standard id, or is
258 a user defined style.
260 @return
261 The equivalent writer style packaged as a StyleResult to use
262 for this word style.
264 It will only return a failure in the pathological case of
265 catastropic failure elsewhere of there exist already styles
266 rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely
267 and impossible.
269 StyleResult GetStyle(const String& rName, ww::sti eSti);
272 /** Find suitable names for exporting this font
274 Given a fontname description find the best primary and secondary
275 fallback font to use from MSWord's persp font
277 @author
278 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
280 @see #i10242#/#i19164# for examples
282 class FontMapExport
284 public:
285 String msPrimary;
286 String msSecondary;
287 FontMapExport(const String &rFontDescription);
290 class InsertedTableClient : public SwClient
292 public:
293 InsertedTableClient(SwTableNode & rNode);
294 SwTableNode * GetTableNode();
297 /** Handle requirements for table formatting in insert->file mode.
299 When inserting a table into a document which already has been
300 formatted and laid out (e.g using insert->file) then tables
301 must be handled in a special way, (or so previous comments and
302 code in the filters leads me to believe).
304 Before the document is finalized the new tables need to have
305 their layout frms deleted and recalculated. This TableManager
306 detects the necessity to do this, and all tables inserted into
307 a document should be registered with this manager with
308 InsertTable, and before finialization DelAndMakeTblFrms should
309 be called.
311 @author
312 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
314 @see #i25782# for examples
316 class InsertedTablesManager
318 public:
319 typedef std::map<InsertedTableClient *, SwNodeIndex *> TblMap;
320 typedef TblMap::iterator TblMapIter;
321 void DelAndMakeTblFrms();
322 void InsertTable(SwTableNode &rTableNode, SwPaM &rPaM);
323 InsertedTablesManager(const SwDoc &rDoc);
324 private:
325 bool mbHasRoot;
326 TblMap maTables;
330 @author
331 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
333 class RedlineStack : public boost::noncopyable
335 private:
336 std::vector<SwFltStackEntry *> maStack;
337 typedef std::vector<SwFltStackEntry *>::reverse_iterator myriter;
338 SwDoc &mrDoc;
339 public:
340 explicit RedlineStack(SwDoc &rDoc) : mrDoc(rDoc) {}
341 void open(const SwPosition& rPos, const SfxPoolItem& rAttr);
342 bool close(const SwPosition& rPos, RedlineType_t eType);
343 void close(const SwPosition& rPos, RedlineType_t eType,
344 WW8TabDesc* pTabDesc );
345 void closeall(const SwPosition& rPos);
346 ~RedlineStack();
350 @author
351 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
353 class SetInDocAndDelete
355 private:
356 SwDoc &mrDoc;
357 public:
358 explicit SetInDocAndDelete(SwDoc &rDoc) : mrDoc(rDoc) {}
359 void operator()(SwFltStackEntry *pEntry);
360 private:
361 //No assignment
362 SetInDocAndDelete& operator=(const SetInDocAndDelete&);
366 @author
367 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
369 class SetEndIfOpen //Subclass from something ?
371 private:
372 const SwPosition &mrPos;
373 public:
374 explicit SetEndIfOpen(const SwPosition &rPos) : mrPos(rPos) {}
375 void operator()(SwFltStackEntry *pEntry) const
377 if (pEntry->bOpen)
378 pEntry->SetEndPos(mrPos);
380 private:
381 //No assignment
382 SetEndIfOpen& operator=(const SetEndIfOpen&);
386 @author
387 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
389 class CompareRedlines:
390 public std::binary_function<const SwFltStackEntry*, const SwFltStackEntry*,
391 bool>
393 public:
394 bool operator()(const SwFltStackEntry *pOneE, const SwFltStackEntry *pTwoE)
395 const;
398 class WrtRedlineAuthor : public boost::noncopyable
400 protected:
401 std::vector<OUString> maAuthors; // Array of Sw - Bookmarknames
403 sal_uInt16 GetPos( const String& rNm );
404 public:
405 WrtRedlineAuthor() {}
406 virtual ~WrtRedlineAuthor() {}
408 sal_uInt16 AddName( const OUString& rNm );
409 virtual void Write(Writer &rWrt) = 0;
410 // std::vector<String> GetNames();
413 /** Given a SwNoTxtNode (ole/graphic) get original size
415 Get the uncropped and unscaled size of the underlying graphic or
416 ole object associated with a given SwNoTxtNode.
418 This function will swap in the graphic if it is swapped out from
419 the graphic or object cache, but will swap it out if that was the
420 case, i.e. rNd is logically unchanged before and after
421 GetSwappedInSize, though not physically const
423 @param rNd
424 the SwNoTxtNode whose objects original size we want
426 @return
427 the uncropped unscaled size of the SwNoTxtNode
429 @author
430 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
432 Size GetSwappedInSize(const SwNoTxtNode& rNd);
434 struct CharRunEntry
436 xub_StrLen mnEndPos;
437 sal_uInt16 mnScript;
438 rtl_TextEncoding meCharSet;
439 bool mbRTL;
440 CharRunEntry(xub_StrLen nEndPos, sal_uInt16 nScript,
441 rtl_TextEncoding eCharSet, bool bRTL)
442 : mnEndPos(nEndPos), mnScript(nScript), meCharSet(eCharSet),
443 mbRTL(bRTL)
448 typedef std::vector<CharRunEntry> CharRuns;
449 typedef CharRuns::const_iterator cCharRunIter;
451 /** Collect the ranges of Text which share
453 Word generally requires characters which share the same direction,
454 the same script, and occasionally (depending on the format) the
455 same charset to be exported in independent chunks.
457 So this function finds these ranges and returns a STL container
458 of CharRuns
460 @param rTxtNd
461 The TextNode we want to ranges from
463 @param nStart
464 The position in the TxtNode to start processing from
466 @param bSplitOnCharSet
467 Set to true is we want to split on ranges of characters that
468 share a plausible charset for export to e.g. WW7- or perhaps
469 RTF format, not necessary for a unicode aware format like WW8+
471 @return STL container of CharRuns which describe the shared
472 direction, script and optionally script of the contigious sequences
473 of characters
475 @author
476 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
478 @see #i22537# for example
480 CharRuns GetPseudoCharRuns(const SwTxtNode& rTxtNd,
481 xub_StrLen nStart = 0, bool bSplitOnCharSet = false);
485 #endif
487 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */