Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SW_MS_MSFILTER_HXX
30 : : #define SW_MS_MSFILTER_HXX
31 : :
32 : : #include <set>
33 : : #include <map>
34 : : #include <vector>
35 : : #include <swtypes.hxx> //SwTwips
36 : : #include <tools/string.hxx> //String
37 : : #include "wwstyles.hxx" //ww::sti
38 : : #include <rtl/textenc.h> //rtl_TextEncoding
39 : : #include <tools/gen.hxx> //Size
40 : : #include <filter/msfilter/util.hxx>
41 : : #include <fltshell.hxx> // fuer den Attribut Stack
42 : : #include <redline.hxx>
43 : : #include <shellio.hxx>
44 : : #include <svl/zforlist.hxx>
45 : :
46 : : #include <boost/noncopyable.hpp>
47 : :
48 : : #define CREATE_CONST_ASC(s) String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(s))
49 : :
50 : : class SwDoc;
51 : : class SwPaM;
52 : : class String;
53 : : class SwTableNode;
54 : : class SwNodeIndex;
55 : : class SwNoTxtNode;
56 : : class SwTxtNode;
57 : : class WW8TabDesc;
58 : :
59 : : namespace myImplHelpers
60 : : {
61 : : template<class C> class StyleMapperImpl;
62 : : }
63 : :
64 : : class SwTxtFmtColl;
65 : : class SwCharFmt;
66 : : typedef myImplHelpers::StyleMapperImpl<SwTxtFmtColl> ParaMapper;
67 : : typedef myImplHelpers::StyleMapperImpl<SwCharFmt> CharMapper;
68 : :
69 : : namespace sw
70 : : {
71 : : namespace ms
72 : : {
73 : : /** MSOffice appears to set the charset of unicode fonts to MS 932
74 : :
75 : : Arial Unicode MS for example is a unicode font, but word sets
76 : : exported uses of it to the MS 932 charset
77 : :
78 : : @param eTextEncoding
79 : : the OOo encoding to convert from
80 : :
81 : : @return
82 : : a msoffice equivalent charset identifier
83 : :
84 : : @author
85 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
86 : : */
87 : : sal_uInt8 rtl_TextEncodingToWinCharset(rtl_TextEncoding eTextEncoding);
88 : :
89 : : /** Import a MSWord XE field. Suitable for .doc and .rtf
90 : :
91 : : @param rDoc
92 : : the document to insert into
93 : :
94 : : @param rPaM
95 : : the position in the document to insert into
96 : :
97 : : @param rXE
98 : : the arguments of the original word XE field
99 : :
100 : : @author
101 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
102 : : */
103 : : void ImportXE(SwDoc &rDoc, SwPaM &rPaM, const String &rXE);
104 : :
105 : : /** Convert from DTTM to Writer's DateTime
106 : :
107 : : @author
108 : : <a href="mailto:mmaher@openoffice.org">Martin Maher</a
109 : : */
110 : : long DateTime2DTTM( const DateTime& rDT );
111 : :
112 : : /** Convert from Word Date/Time field str to Writer's Date Time str
113 : :
114 : : @author
115 : : <a href="mailto:mmaher@openoffice.org">Martin Maher</a
116 : : */
117 : : sal_uLong MSDateTimeFormatToSwFormat(String& rParams, SvNumberFormatter *pFormatter, sal_uInt16 &rLang, bool bHijri, sal_uInt16 nDocLang);
118 : :
119 : : /** Used by MSDateTimeFormatToSwFormat to identify AM time fields
120 : :
121 : : @author
122 : : <a href="mailto:mmaher@openoffice.org">Martin Maher</a
123 : : */
124 : : bool IsNotAM(String& rParams, xub_StrLen nPos);
125 : :
126 : : /** Another function used by MSDateTimeFormatToSwFormat
127 : :
128 : : @author
129 : : <a href="mailto:mmaher@openoffice.org">Martin Maher</a
130 : : */
131 : : void SwapQuotesInField(String &rFmt);
132 : :
133 : : }
134 : :
135 : : namespace util
136 : : {
137 : : /// Redlining Authors, map word author key to writer author value
138 : : typedef std::map<sal_uInt16, sal_uInt16> AuthorInfos;
139 : :
140 : : /** Clips a value to MAX/MIN 16bit value to make it safe for use
141 : : as a position value to give to writer. i.e. +-57.8cm. Sometimes
142 : : we see ridiculous values for positioning in rtf and word document,
143 : : this captures such ones and clips them to values which are
144 : : still outside the document, but of a value that doesn't cause
145 : : problems for writer's layout, e.g. see
146 : : http://www.openoffice.org/issues/show_bug.cgi?id=i9245
147 : :
148 : : @param nIn
149 : :
150 : : @return nIn clipped to min/max 16bit value
151 : :
152 : : @author
153 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
154 : : */
155 : : SwTwips MakeSafePositioningValue(SwTwips nIn);
156 : :
157 : : /** Knows which writer style a given word style should be imported as
158 : :
159 : : Mapping a word style to a writer style has to consider mapping
160 : : the word builtin styles like "Normal" as the default root style
161 : : to our default root style which is called "Default" in english,
162 : : and "Normal" in german.
163 : :
164 : : Additionally it then has to avoid name collisions such as
165 : :
166 : : a) styles "Normal" and "Default" in a single document, where
167 : : we can use the original distinct names "Normal" and "Default" and..
168 : : b) styles "Normal" and "Default" in a single document, where
169 : : we can not use the original names, and must come up with an
170 : : alternative name for one of them..
171 : :
172 : : And it needs to report to the importer if the style being mapped to
173 : : was already in existance, for the cut and paste/insert file mode we
174 : : should not modify the returned style if it is already in use as it
175 : : is does not belong to us to change.
176 : :
177 : : @author
178 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
179 : : */
180 : : class ParaStyleMapper
181 : : {
182 : : private:
183 : : //I hate these things stupid pImpl things, but its warranted here
184 : : ParaMapper *mpImpl;
185 : : public:
186 : : ParaStyleMapper(SwDoc &rDoc);
187 : : ~ParaStyleMapper();
188 : :
189 : : /** StyleResult
190 : : StyleResult is a std::pair of a pointer to a style and a flag
191 : : which is true if the style existed previously in the document.
192 : : */
193 : : typedef std::pair<SwTxtFmtColl*, bool> StyleResult;
194 : :
195 : : /** Get the writer style which the word style should map to
196 : :
197 : : @param rName
198 : : The name of the word style
199 : :
200 : : @param eSti
201 : : The style id of the word style, we are really only interested
202 : : in knowing if the style has either a builtin standard id, or is
203 : : a user defined style.
204 : :
205 : : @return
206 : : The equivalent writer style packaged as a StyleResult to use
207 : : for this word style.
208 : :
209 : : It will only return a failure in the pathological case of
210 : : catastropic failure elsewhere of there exist already styles
211 : : rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely
212 : : and impossible.
213 : : */
214 : : StyleResult GetStyle(const String& rName, ww::sti eSti);
215 : : };
216 : :
217 : : /** Knows which writer style a given word style should be imported as
218 : :
219 : : Mapping a word style to a writer style has to consider mapping
220 : : the word builtin styles like "Normal" as the default root style
221 : : to our default root style which is called "Default" in english,
222 : : and "Normal" in german.
223 : :
224 : : Additionally it then has to avoid name collisions such as
225 : :
226 : : a) styles "Normal" and "Default" in a single document, where
227 : : we can use the original distinct names "Normal" and "Default" and..
228 : : b) styles "Normal" and "Default" in a single document, where
229 : : we can not use the original names, and must come up with an
230 : : alternative name for one of them..
231 : :
232 : : And it needs to report to the importer if the style being mapped to
233 : : was already in existance, for the cut and paste/insert file mode we
234 : : should not modify the returned style if it is already in use as it
235 : : is does not belong to us to change.
236 : :
237 : : @author
238 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
239 : : */
240 : : class CharStyleMapper
241 : : {
242 : : private:
243 : : //I hate these things stupid pImpl things, but its warranted here
244 : : CharMapper *mpImpl;
245 : : public:
246 : : CharStyleMapper(SwDoc &rDoc);
247 : : ~CharStyleMapper();
248 : :
249 : : /** StyleResult
250 : : StyleResult is a std::pair of a pointer to a style and a flag
251 : : which is true if the style existed previously in the document.
252 : : */
253 : : typedef std::pair<SwCharFmt*, bool> StyleResult;
254 : :
255 : : /** Get the writer style which the word style should map to
256 : :
257 : : @param rName
258 : : The name of the word style
259 : :
260 : : @param eSti
261 : : The style id of the word style, we are really only interested
262 : : in knowing if the style has either a builtin standard id, or is
263 : : a user defined style.
264 : :
265 : : @return
266 : : The equivalent writer style packaged as a StyleResult to use
267 : : for this word style.
268 : :
269 : : It will only return a failure in the pathological case of
270 : : catastropic failure elsewhere of there exist already styles
271 : : rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely
272 : : and impossible.
273 : : */
274 : : StyleResult GetStyle(const String& rName, ww::sti eSti);
275 : : };
276 : :
277 : : /** Find suitable names for exporting this font
278 : :
279 : : Given a fontname description find the best primary and secondary
280 : : fallback font to use from MSWord's persp font
281 : :
282 : : @author
283 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
284 : :
285 : : @see #i10242#/#i19164# for examples
286 : : */
287 [ + - ]: 2460 : class FontMapExport
288 : : {
289 : : public:
290 : : String msPrimary;
291 : : String msSecondary;
292 : : FontMapExport(const String &rFontDescription);
293 : : };
294 : :
295 [ # # ]: 0 : class InsertedTableClient : public SwClient
296 : : {
297 : : public:
298 : : InsertedTableClient(SwTableNode & rNode);
299 : : SwTableNode * GetTableNode();
300 : : };
301 : :
302 : : /** Handle requirements for table formatting in insert->file mode.
303 : :
304 : : When inserting a table into a document which already has been
305 : : formatted and laid out (e.g using insert->file) then tables
306 : : must be handled in a special way, (or so previous comments and
307 : : code in the filters leads me to believe).
308 : :
309 : : Before the document is finalized the new tables need to have
310 : : their layout frms deleted and recalculated. This TableManager
311 : : detects the necessity to do this, and all tables inserted into
312 : : a document should be registered with this manager with
313 : : InsertTable, and before finialization DelAndMakeTblFrms should
314 : : be called.
315 : :
316 : : @author
317 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
318 : :
319 : : @see #i25782# for examples
320 : : */
321 : 108 : class InsertedTablesManager
322 : : {
323 : : public:
324 : : typedef std::map<InsertedTableClient *, SwNodeIndex *> TblMap;
325 : : typedef TblMap::iterator TblMapIter;
326 : : void DelAndMakeTblFrms();
327 : : void InsertTable(SwTableNode &rTableNode, SwPaM &rPaM);
328 : : InsertedTablesManager(const SwDoc &rDoc);
329 : : private:
330 : : bool mbHasRoot;
331 : : TblMap maTables;
332 : : };
333 : :
334 : : /**
335 : : @author
336 : : <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
337 : : */
338 : : class RedlineStack : public boost::noncopyable
339 : : {
340 : : private:
341 : : std::vector<SwFltStackEntry *> maStack;
342 : : typedef std::vector<SwFltStackEntry *>::reverse_iterator myriter;
343 : : SwDoc &mrDoc;
344 : : public:
345 [ + - ]: 378 : explicit RedlineStack(SwDoc &rDoc) : mrDoc(rDoc) {}
346 : : void open(const SwPosition& rPos, const SfxPoolItem& rAttr);
347 : : bool close(const SwPosition& rPos, RedlineType_t eType);
348 : : void close(const SwPosition& rPos, RedlineType_t eType,
349 : : WW8TabDesc* pTabDesc );
350 : : void closeall(const SwPosition& rPos);
351 : : ~RedlineStack();
352 : : };
353 : :
354 : : /**
355 : : @author
356 : : <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
357 : : */
358 : : class SetInDocAndDelete
359 : : {
360 : : private:
361 : : SwDoc &mrDoc;
362 : : public:
363 : 378 : explicit SetInDocAndDelete(SwDoc &rDoc) : mrDoc(rDoc) {}
364 : : void operator()(SwFltStackEntry *pEntry);
365 : : private:
366 : : //No assignment
367 : : SetInDocAndDelete& operator=(const SetInDocAndDelete&);
368 : : };
369 : :
370 : : /**
371 : : @author
372 : : <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
373 : : */
374 : : class SetEndIfOpen //Subclass from something ?
375 : : {
376 : : private:
377 : : const SwPosition &mrPos;
378 : : public:
379 : 378 : explicit SetEndIfOpen(const SwPosition &rPos) : mrPos(rPos) {}
380 : 0 : void operator()(SwFltStackEntry *pEntry) const
381 : : {
382 [ # # ]: 0 : if (pEntry->bOpen)
383 : 0 : pEntry->SetEndPos(mrPos);
384 : 0 : }
385 : : private:
386 : : //No assignment
387 : : SetEndIfOpen& operator=(const SetEndIfOpen&);
388 : : };
389 : :
390 : : /**
391 : : @author
392 : : <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
393 : : */
394 : : class CompareRedlines:
395 : : public std::binary_function<const SwFltStackEntry*, const SwFltStackEntry*,
396 : : bool>
397 : : {
398 : : public:
399 : : bool operator()(const SwFltStackEntry *pOneE, const SwFltStackEntry *pTwoE)
400 : : const;
401 : : };
402 : :
403 : : class WrtRedlineAuthor : public boost::noncopyable
404 : : {
405 : : protected:
406 : : std::vector<rtl::OUString> maAuthors; // Array of Sw - Bookmarknames
407 : :
408 : : sal_uInt16 GetPos( const String& rNm );
409 : : public:
410 [ # # ]: 0 : WrtRedlineAuthor() {}
411 [ # # ]: 0 : virtual ~WrtRedlineAuthor() {}
412 : :
413 : : sal_uInt16 AddName( const rtl::OUString& rNm );
414 : : virtual void Write(Writer &rWrt) = 0;
415 : : // std::vector<String> GetNames();
416 : : };
417 : :
418 : : /** Given a SwNoTxtNode (ole/graphic) get original size
419 : :
420 : : Get the uncropped and unscaled size of the underlying graphic or
421 : : ole object associated with a given SwNoTxtNode.
422 : :
423 : : This function will swap in the graphic if it is swapped out from
424 : : the graphic or object cache, but will swap it out if that was the
425 : : case, i.e. rNd is logically unchanged before and after
426 : : GetSwappedInSize, though not physically const
427 : :
428 : : @param rNd
429 : : the SwNoTxtNode whose objects original size we want
430 : :
431 : : @return
432 : : the uncropped unscaled size of the SwNoTxtNode
433 : :
434 : : @author
435 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
436 : : */
437 : : Size GetSwappedInSize(const SwNoTxtNode& rNd);
438 : :
439 : : struct CharRunEntry
440 : : {
441 : : xub_StrLen mnEndPos;
442 : : sal_uInt16 mnScript;
443 : : rtl_TextEncoding meCharSet;
444 : : bool mbRTL;
445 : 300 : CharRunEntry(xub_StrLen nEndPos, sal_uInt16 nScript,
446 : : rtl_TextEncoding eCharSet, bool bRTL)
447 : : : mnEndPos(nEndPos), mnScript(nScript), meCharSet(eCharSet),
448 : 300 : mbRTL(bRTL)
449 : : {
450 : 300 : }
451 : : };
452 : :
453 : : typedef std::vector<CharRunEntry> CharRuns;
454 : : typedef CharRuns::const_iterator cCharRunIter;
455 : :
456 : : /** Collect the ranges of Text which share
457 : :
458 : : Word generally requires characters which share the same direction,
459 : : the same script, and occasionally (depending on the format) the
460 : : same charset to be exported in independant chunks.
461 : :
462 : : So this function finds these ranges and returns a STL container
463 : : of CharRuns
464 : :
465 : : @param rTxtNd
466 : : The TextNode we want to ranges from
467 : :
468 : : @param nStart
469 : : The position in the TxtNode to start processing from
470 : :
471 : : @param bSplitOnCharSet
472 : : Set to true is we want to split on ranges of characters that
473 : : share a plausible charset for export to e.g. WW7- or perhaps
474 : : RTF format, not necessary for a unicode aware format like WW8+
475 : :
476 : : @return STL container of CharRuns which describe the shared
477 : : direction, script and optionally script of the contigious sequences
478 : : of characters
479 : :
480 : : @author
481 : : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
482 : :
483 : : @see #i22537# for example
484 : : */
485 : : CharRuns GetPseudoCharRuns(const SwTxtNode& rTxtNd,
486 : : xub_StrLen nStart = 0, bool bSplitOnCharSet = false);
487 : : }
488 : : }
489 : :
490 : : #endif
491 : :
492 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|