1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: msfilter.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
33 #ifndef SW_MS_MSFILTER_HXX
34 #define SW_MS_MSFILTER_HXX
39 # include <swtypes.hxx> //SwTwips
40 # include <tools/string.hxx> //String
41 # include "wwstyles.hxx" //ww::sti
42 # include <rtl/textenc.h> //rtl_TextEncoding
43 # include <tools/gen.hxx> //Size
44 #include <tools/datetime.hxx>
45 #include <fltshell.hxx> // fuer den Attribut Stack
46 #include <redline.hxx>
47 #include <shellio.hxx>
48 #include <svtools/zforlist.hxx>
50 #define CREATE_CONST_ASC(s) String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(s))
61 namespace myImplHelpers
63 template<class C
> class StyleMapperImpl
;
68 typedef myImplHelpers::StyleMapperImpl
<SwTxtFmtColl
> ParaMapper
;
69 typedef myImplHelpers::StyleMapperImpl
<SwCharFmt
> CharMapper
;
75 /** MSOffice appears to set the charset of unicode fonts to MS 932
77 Arial Unicode MS for example is a unicode font, but word sets
78 exported uses of it to the MS 932 charset
81 the OOo encoding to convert from
84 a msoffice equivalent charset identifier
87 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
89 sal_uInt8
rtl_TextEncodingToWinCharset(rtl_TextEncoding eTextEncoding
);
91 /** Import a MSWord XE field. Suitable for .doc and .rtf
94 the document to insert into
97 the position in the document to insert into
100 the arguments of the original word XE field
103 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
105 void ImportXE(SwDoc
&rDoc
, SwPaM
&rPaM
, const String
&rXE
);
107 /** Convert from DTTM to Writer's DateTime
110 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
112 DateTime
DTTM2DateTime( long lDTTM
);
114 /** Convert from DTTM to Writer's DateTime
117 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
119 long DateTime2DTTM( const DateTime
& rDT
);
121 /** Convert from Word Date/Time field str to Writer's Date Time str
124 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
126 ULONG
MSDateTimeFormatToSwFormat(String
& rParams
, SvNumberFormatter
*pFormatter
, USHORT
&rLang
, bool bHijri
);
128 /** Used by MSDateTimeFormatToSwFormat to identify AM time fields
131 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
133 bool IsNotAM(String
& rParams
, xub_StrLen nPos
);
135 /** Another function used by MSDateTimeFormatToSwFormat
138 <a href="mailto:mmaher@openoffice.org">Martin Maher</a
140 void SwapQuotesInField(String
&rFmt
);
147 typedef AuthorInfo
* AuthorInfo_Ptr
;
149 /// Redlining Authors
155 AuthorInfo(USHORT nWWAuthorId_
, USHORT nOurId_
= 0):
156 nWWAuthorId( nWWAuthorId_
),
159 bool operator==(const AuthorInfo
& rEntry
) const
161 return (nWWAuthorId
== rEntry
.nWWAuthorId
);
163 bool operator<(const AuthorInfo
& rEntry
) const
165 return (nWWAuthorId
< rEntry
.nWWAuthorId
);
169 SV_DECL_PTRARR_SORT_DEL(AuthorInfos
, AuthorInfo_Ptr
,16,16)
171 /** Clips a value to MAX/MIN 16bit value to make it safe for use
172 as a position value to give to writer. i.e. +-57.8cm. Sometimes
173 we see ridiculous values for positioning in rtf and word document,
174 this captures such ones and clips them to values which are
175 still outside the document, but of a value that doesn't cause
176 problems for writer's layout, e.g. see
177 http://www.openoffice.org/issues/show_bug.cgi?id=i9245
181 @return nIn clipped to min/max 16bit value
184 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
186 SwTwips
MakeSafePositioningValue(SwTwips nIn
);
188 /** Knows which writer style a given word style should be imported as
190 Mapping a word style to a writer style has to consider mapping
191 the word builtin styles like "Normal" as the default root style
192 to our default root style which is called "Default" in english,
193 and "Normal" in german.
195 Additionally it then has to avoid name collisions such as
197 a) styles "Normal" and "Default" in a single document, where
198 we can use the original distinct names "Normal" and "Default" and..
199 b) styles "Normal" and "Default" in a single document, where
200 we can not use the original names, and must come up with an
201 alternative name for one of them..
203 And it needs to report to the importer if the style being mapped to
204 was already in existance, for the cut and paste/insert file mode we
205 should not modify the returned style if it is already in use as it
206 is does not belong to us to change.
209 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
211 class ParaStyleMapper
214 //I hate these things stupid pImpl things, but its warranted here
217 ParaStyleMapper(SwDoc
&rDoc
);
221 StyleResult is a std::pair of a pointer to a style and a flag
222 which is true if the style existed previously in the document.
224 typedef std::pair
<SwTxtFmtColl
*, bool> StyleResult
;
226 /** Get the writer style which the word style should map to
229 The name of the word style
232 The style id of the word style, we are really only interested
233 in knowing if the style has either a builtin standard id, or is
234 a user defined style.
237 The equivalent writer style packaged as a StyleResult to use
240 It will only return a failure in the pathological case of
241 catastropic failure elsewhere of there exist already styles
242 rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely
245 StyleResult
GetStyle(const String
& rName
, ww::sti eSti
);
248 /** Knows which writer style a given word style should be imported as
250 Mapping a word style to a writer style has to consider mapping
251 the word builtin styles like "Normal" as the default root style
252 to our default root style which is called "Default" in english,
253 and "Normal" in german.
255 Additionally it then has to avoid name collisions such as
257 a) styles "Normal" and "Default" in a single document, where
258 we can use the original distinct names "Normal" and "Default" and..
259 b) styles "Normal" and "Default" in a single document, where
260 we can not use the original names, and must come up with an
261 alternative name for one of them..
263 And it needs to report to the importer if the style being mapped to
264 was already in existance, for the cut and paste/insert file mode we
265 should not modify the returned style if it is already in use as it
266 is does not belong to us to change.
269 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
271 class CharStyleMapper
274 //I hate these things stupid pImpl things, but its warranted here
277 CharStyleMapper(SwDoc
&rDoc
);
281 StyleResult is a std::pair of a pointer to a style and a flag
282 which is true if the style existed previously in the document.
284 typedef std::pair
<SwCharFmt
*, bool> StyleResult
;
286 /** Get the writer style which the word style should map to
289 The name of the word style
292 The style id of the word style, we are really only interested
293 in knowing if the style has either a builtin standard id, or is
294 a user defined style.
297 The equivalent writer style packaged as a StyleResult to use
300 It will only return a failure in the pathological case of
301 catastropic failure elsewhere of there exist already styles
302 rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely
305 StyleResult
GetStyle(const String
& rName
, ww::sti eSti
);
308 /** Find suitable names for exporting this font
310 Given a fontname description find the best primary and secondary
311 fallback font to use from MSWord's persp font
314 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
316 @see #i10242#/#i19164# for examples
323 bool HasDistinctSecondary() const;
324 FontMapExport(const String
&rFontDescription
);
327 class InsertedTableClient
: public SwClient
330 InsertedTableClient(SwTableNode
& rNode
);
331 SwTableNode
* GetTableNode();
334 /** Handle requirements for table formatting in insert->file mode.
336 When inserting a table into a document which already has been
337 formatted and laid out (e.g using insert->file) then tables
338 must be handled in a special way, (or so previous comments and
339 code in the filters leads me to believe).
341 Before the document is finalized the new tables need to have
342 their layout frms deleted and recalculated. This TableManager
343 detects the necessity to do this, and all tables inserted into
344 a document should be registered with this manager with
345 InsertTable, and before finialization DelAndMakeTblFrms should
349 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
351 @see #i25782# for examples
353 class InsertedTablesManager
356 typedef std::map
<InsertedTableClient
*, SwNodeIndex
*> TblMap
;
357 typedef TblMap::iterator TblMapIter
;
358 void DelAndMakeTblFrms();
359 void InsertTable(SwTableNode
&rTableNode
, SwPaM
&rPaM
);
360 InsertedTablesManager(const SwDoc
&rDoc
);
368 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
373 std::vector
<SwFltStackEntry
*> maStack
;
374 typedef std::vector
<SwFltStackEntry
*>::reverse_iterator myriter
;
377 explicit RedlineStack(SwDoc
&rDoc
) : mrDoc(rDoc
) {}
378 void open(const SwPosition
& rPos
, const SfxPoolItem
& rAttr
);
379 bool close(const SwPosition
& rPos
, RedlineType_t eType
);
380 void close(const SwPosition
& rPos
, RedlineType_t eType
,
381 WW8TabDesc
* pTabDesc
);
382 void closeall(const SwPosition
& rPos
);
386 RedlineStack(const RedlineStack
&);
387 RedlineStack
& operator=(const RedlineStack
&);
392 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
394 class SetInDocAndDelete
399 explicit SetInDocAndDelete(SwDoc
&rDoc
) : mrDoc(rDoc
) {}
400 void operator()(SwFltStackEntry
*pEntry
);
403 SetInDocAndDelete
& operator=(const SetInDocAndDelete
&);
408 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
410 class CloseIfOpen
//Subclass from something ?
413 const SwPosition
&mrPos
;
415 explicit CloseIfOpen(const SwPosition
&rPos
) : mrPos(rPos
) {}
416 void operator()(SwFltStackEntry
*pEntry
) const
419 pEntry
->SetEndPos(mrPos
);
423 CloseIfOpen
& operator=(const CloseIfOpen
&);
428 <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
430 class CompareRedlines
:
431 public std::binary_function
<const SwFltStackEntry
*, const SwFltStackEntry
*,
435 bool operator()(const SwFltStackEntry
*pOneE
, const SwFltStackEntry
*pTwoE
)
439 class WrtRedlineAuthor
442 std::vector
<String
> maAuthors
; // Array of Sw - Bookmarknames
444 USHORT
GetPos( const String
& rNm
);
447 WrtRedlineAuthor(const WrtRedlineAuthor
&);
448 WrtRedlineAuthor
& operator=(const WrtRedlineAuthor
&);
450 WrtRedlineAuthor() {}
451 virtual ~WrtRedlineAuthor() {}
453 USHORT
AddName( const String
& rNm
);
454 virtual void Write(Writer
&rWrt
) = 0;
455 // std::vector<String> GetNames();
458 /** Given a SwNoTxtNode (ole/graphic) get original size
460 Get the uncropped and unscaled size of the underlying graphic or
461 ole object associated with a given SwNoTxtNode.
463 This function will swap in the graphic if it is swapped out from
464 the graphic or object cache, but will swap it out if that was the
465 case, i.e. rNd is logically unchanged before and after
466 GetSwappedInSize, though not physically const
469 the SwNoTxtNode whose objects original size we want
472 the uncropped unscaled size of the SwNoTxtNode
475 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
477 Size
GetSwappedInSize(const SwNoTxtNode
& rNd
);
483 rtl_TextEncoding meCharSet
;
485 CharRunEntry(xub_StrLen nEndPos
, sal_uInt16 nScript
,
486 rtl_TextEncoding eCharSet
, bool bRTL
)
487 : mnEndPos(nEndPos
), mnScript(nScript
), meCharSet(eCharSet
),
493 typedef std::vector
<CharRunEntry
> CharRuns
;
494 typedef CharRuns::const_iterator cCharRunIter
;
496 /** Collect the ranges of Text which share
498 Word generally requires characters which share the same direction,
499 the same script, and occasionally (depending on the format) the
500 same charset to be exported in independant chunks.
502 So this function finds these ranges and returns a STL container
506 The TextNode we want to ranges from
509 The position in the TxtNode to start processing from
511 @param bSplitOnCharSet
512 Set to true is we want to split on ranges of characters that
513 share a plausible charset for export to e.g. WW7- or perhaps
514 RTF format, not necessary for a unicode aware format like WW8+
516 @return STL container of CharRuns which describe the shared
517 direction, script and optionally script of the contigious sequences
521 <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
523 @see #i22537# for example
525 CharRuns
GetPseudoCharRuns(const SwTxtNode
& rTxtNd
,
526 xub_StrLen nStart
= 0, bool bSplitOnCharSet
= false);
531 /* vi:set tabstop=4 shiftwidth=4 expandtab: */