1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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>
48 namespace myImplHelpers
50 template<class C
> class StyleMapperImpl
;
55 typedef myImplHelpers::StyleMapperImpl
<SwTxtFmtColl
> ParaMapper
;
56 typedef myImplHelpers::StyleMapperImpl
<SwCharFmt
> CharMapper
;
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
68 the OOo encoding to convert from
71 a msoffice equivalent charset identifier
74 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
76 sal_uInt8
rtl_TextEncodingToWinCharset(rtl_TextEncoding eTextEncoding
);
78 /** Import a MSWord XE field. Suitable for .doc and .rtf
81 the document to insert into
84 the position in the document to insert into
87 the arguments of the original word XE field
90 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
92 void ImportXE(SwDoc
&rDoc
, SwPaM
&rPaM
, const String
&rXE
);
94 /** Convert from DTTM to Writer's DateTime
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
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
117 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
119 bool IsNotAM(String
& rParams
, xub_StrLen nPos
);
121 /** Another function used by MSDateTimeFormatToSwFormat
124 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
126 void SwapQuotesInField(String
&rFmt
);
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
145 @return nIn clipped to min/max 16bit value
148 <a href="mailto:cmc@openoffice.org">Caolá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.
173 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
175 class ParaStyleMapper
178 //I hate these things stupid pImpl things, but its warranted here
181 ParaStyleMapper(SwDoc
&rDoc
);
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
193 The name of the word style
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.
201 The equivalent writer style packaged as a StyleResult to use
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
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.
233 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
235 class CharStyleMapper
238 //I hate these things stupid pImpl things, but its warranted here
241 CharStyleMapper(SwDoc
&rDoc
);
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
253 The name of the word style
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.
261 The equivalent writer style packaged as a StyleResult to use
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
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
278 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
280 @see #i10242#/#i19164# for examples
287 FontMapExport(const String
&rFontDescription
);
290 class InsertedTableClient
: public SwClient
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
312 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
314 @see #i25782# for examples
316 class InsertedTablesManager
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
);
331 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
333 class RedlineStack
: public boost::noncopyable
336 std::vector
<SwFltStackEntry
*> maStack
;
337 typedef std::vector
<SwFltStackEntry
*>::reverse_iterator myriter
;
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
);
351 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
353 class SetInDocAndDelete
358 explicit SetInDocAndDelete(SwDoc
&rDoc
) : mrDoc(rDoc
) {}
359 void operator()(SwFltStackEntry
*pEntry
);
362 SetInDocAndDelete
& operator=(const SetInDocAndDelete
&);
367 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
369 class SetEndIfOpen
//Subclass from something ?
372 const SwPosition
&mrPos
;
374 explicit SetEndIfOpen(const SwPosition
&rPos
) : mrPos(rPos
) {}
375 void operator()(SwFltStackEntry
*pEntry
) const
378 pEntry
->SetEndPos(mrPos
);
382 SetEndIfOpen
& operator=(const SetEndIfOpen
&);
387 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
389 class CompareRedlines
:
390 public std::binary_function
<const SwFltStackEntry
*, const SwFltStackEntry
*,
394 bool operator()(const SwFltStackEntry
*pOneE
, const SwFltStackEntry
*pTwoE
)
398 class WrtRedlineAuthor
: public boost::noncopyable
401 std::vector
<OUString
> maAuthors
; // Array of Sw - Bookmarknames
403 sal_uInt16
GetPos( const String
& rNm
);
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
424 the SwNoTxtNode whose objects original size we want
427 the uncropped unscaled size of the SwNoTxtNode
430 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
432 Size
GetSwappedInSize(const SwNoTxtNode
& rNd
);
438 rtl_TextEncoding meCharSet
;
440 CharRunEntry(xub_StrLen nEndPos
, sal_uInt16 nScript
,
441 rtl_TextEncoding eCharSet
, bool bRTL
)
442 : mnEndPos(nEndPos
), mnScript(nScript
), meCharSet(eCharSet
),
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
461 The TextNode we want to ranges from
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
476 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
478 @see #i22537# for example
480 CharRuns
GetPseudoCharRuns(const SwTxtNode
& rTxtNd
,
481 xub_StrLen nStart
= 0, bool bSplitOnCharSet
= false);
487 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */