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 : #ifndef SW_MS_MSFILTER_HXX
21 : #define SW_MS_MSFILTER_HXX
22 :
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>
36 :
37 : #include <boost/noncopyable.hpp>
38 :
39 : class SwDoc;
40 : class SwPaM;
41 : class String;
42 : class SwTableNode;
43 : class SwNodeIndex;
44 : class SwNoTxtNode;
45 : class SwTxtNode;
46 : class WW8TabDesc;
47 :
48 : namespace myImplHelpers
49 : {
50 : template<class C> class StyleMapperImpl;
51 : }
52 :
53 : class SwTxtFmtColl;
54 : class SwCharFmt;
55 : typedef myImplHelpers::StyleMapperImpl<SwTxtFmtColl> ParaMapper;
56 : typedef myImplHelpers::StyleMapperImpl<SwCharFmt> CharMapper;
57 :
58 : namespace sw
59 : {
60 : namespace ms
61 : {
62 : /** MSOffice appears to set the charset of unicode fonts to MS 932
63 :
64 : Arial Unicode MS for example is a unicode font, but word sets
65 : exported uses of it to the MS 932 charset
66 :
67 : @param eTextEncoding
68 : the OOo encoding to convert from
69 :
70 : @return
71 : a msoffice equivalent charset identifier
72 :
73 : @author
74 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
75 : */
76 : sal_uInt8 rtl_TextEncodingToWinCharset(rtl_TextEncoding eTextEncoding);
77 :
78 : /** Import a MSWord XE field. Suitable for .doc and .rtf
79 :
80 : @param rDoc
81 : the document to insert into
82 :
83 : @param rPaM
84 : the position in the document to insert into
85 :
86 : @param rXE
87 : the arguments of the original word XE field
88 :
89 : @author
90 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
91 : */
92 : void ImportXE(SwDoc &rDoc, SwPaM &rPaM, const String &rXE);
93 :
94 : /** Convert from DTTM to Writer's DateTime
95 :
96 : @author
97 : <a href="mailto:mmaher@openoffice.org">Martin Maher</a
98 : */
99 : long DateTime2DTTM( const DateTime& rDT );
100 :
101 : /** Convert from Word Date/Time field str to Writer's Date Time str
102 :
103 : @author
104 : <a href="mailto:mmaher@openoffice.org">Martin Maher</a
105 : */
106 : sal_uLong MSDateTimeFormatToSwFormat(String& rParams, SvNumberFormatter *pFormatter, sal_uInt16 &rLang, bool bHijri, sal_uInt16 nDocLang);
107 :
108 : /*Used to identify if the previous token is AM time field*/
109 : sal_Bool IsPreviousAM(String& rParams, xub_StrLen nPos);
110 :
111 : /*Used to identify if the next token is PM time field*/
112 : sal_Bool IsNextPM(String& rParams, xub_StrLen nPos);
113 :
114 : /** Used by MSDateTimeFormatToSwFormat to identify AM time fields
115 :
116 : @author
117 : <a href="mailto:mmaher@openoffice.org">Martin Maher</a
118 : */
119 : bool IsNotAM(String& rParams, xub_StrLen nPos);
120 :
121 : /** Another function used by MSDateTimeFormatToSwFormat
122 :
123 : @author
124 : <a href="mailto:mmaher@openoffice.org">Martin Maher</a
125 : */
126 : void SwapQuotesInField(String &rFmt);
127 :
128 : }
129 :
130 : namespace util
131 : {
132 : /// Redlining Authors, map word author key to writer author value
133 : typedef std::map<sal_uInt16, sal_uInt16> AuthorInfos;
134 :
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
142 :
143 : @param nIn
144 :
145 : @return nIn clipped to min/max 16bit value
146 :
147 : @author
148 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
149 : */
150 : SwTwips MakeSafePositioningValue(SwTwips nIn);
151 :
152 : /** Knows which writer style a given word style should be imported as
153 :
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.
158 :
159 : Additionally it then has to avoid name collisions such as
160 :
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..
166 :
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.
171 :
172 : @author
173 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
174 : */
175 : class ParaStyleMapper
176 : {
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();
183 :
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.
187 : */
188 : typedef std::pair<SwTxtFmtColl*, bool> StyleResult;
189 :
190 : /** Get the writer style which the word style should map to
191 :
192 : @param rName
193 : The name of the word style
194 :
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.
199 :
200 : @return
201 : The equivalent writer style packaged as a StyleResult to use
202 : for this word style.
203 :
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.
208 : */
209 : StyleResult GetStyle(const String& rName, ww::sti eSti);
210 : };
211 :
212 : /** Knows which writer style a given word style should be imported as
213 :
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.
218 :
219 : Additionally it then has to avoid name collisions such as
220 :
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..
226 :
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.
231 :
232 : @author
233 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
234 : */
235 : class CharStyleMapper
236 : {
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();
243 :
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.
247 : */
248 : typedef std::pair<SwCharFmt*, bool> StyleResult;
249 :
250 : /** Get the writer style which the word style should map to
251 :
252 : @param rName
253 : The name of the word style
254 :
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.
259 :
260 : @return
261 : The equivalent writer style packaged as a StyleResult to use
262 : for this word style.
263 :
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.
268 : */
269 : StyleResult GetStyle(const String& rName, ww::sti eSti);
270 : };
271 :
272 : /** Find suitable names for exporting this font
273 :
274 : Given a fontname description find the best primary and secondary
275 : fallback font to use from MSWord's persp font
276 :
277 : @author
278 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
279 :
280 : @see #i10242#/#i19164# for examples
281 : */
282 2257 : class FontMapExport
283 : {
284 : public:
285 : String msPrimary;
286 : String msSecondary;
287 : FontMapExport(const String &rFontDescription);
288 : };
289 :
290 0 : class InsertedTableClient : public SwClient
291 : {
292 : public:
293 : InsertedTableClient(SwTableNode & rNode);
294 : SwTableNode * GetTableNode();
295 : };
296 :
297 : /** Handle requirements for table formatting in insert->file mode.
298 :
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).
303 :
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.
310 :
311 : @author
312 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
313 :
314 : @see #i25782# for examples
315 : */
316 52 : class InsertedTablesManager
317 : {
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;
327 : };
328 :
329 : /**
330 : @author
331 : <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
332 : */
333 : class RedlineStack : public boost::noncopyable
334 : {
335 : private:
336 : std::vector<SwFltStackEntry *> maStack;
337 : typedef std::vector<SwFltStackEntry *>::reverse_iterator myriter;
338 : SwDoc &mrDoc;
339 : public:
340 245 : 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();
347 : };
348 :
349 : /**
350 : @author
351 : <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
352 : */
353 : class SetInDocAndDelete
354 : {
355 : private:
356 : SwDoc &mrDoc;
357 : public:
358 245 : explicit SetInDocAndDelete(SwDoc &rDoc) : mrDoc(rDoc) {}
359 : void operator()(SwFltStackEntry *pEntry);
360 : private:
361 : //No assignment
362 : SetInDocAndDelete& operator=(const SetInDocAndDelete&);
363 : };
364 :
365 : /**
366 : @author
367 : <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
368 : */
369 : class SetEndIfOpen //Subclass from something ?
370 : {
371 : private:
372 : const SwPosition &mrPos;
373 : public:
374 245 : explicit SetEndIfOpen(const SwPosition &rPos) : mrPos(rPos) {}
375 0 : void operator()(SwFltStackEntry *pEntry) const
376 : {
377 0 : if (pEntry->bOpen)
378 0 : pEntry->SetEndPos(mrPos);
379 0 : }
380 : private:
381 : //No assignment
382 : SetEndIfOpen& operator=(const SetEndIfOpen&);
383 : };
384 :
385 : /**
386 : @author
387 : <a href="mailto:mmaher@openoffice.org">Martin Maher</a>
388 : */
389 : class CompareRedlines:
390 : public std::binary_function<const SwFltStackEntry*, const SwFltStackEntry*,
391 : bool>
392 : {
393 : public:
394 : bool operator()(const SwFltStackEntry *pOneE, const SwFltStackEntry *pTwoE)
395 : const;
396 : };
397 :
398 : class WrtRedlineAuthor : public boost::noncopyable
399 : {
400 : protected:
401 : std::vector<OUString> maAuthors; // Array of Sw - Bookmarknames
402 :
403 : sal_uInt16 GetPos( const String& rNm );
404 : public:
405 0 : WrtRedlineAuthor() {}
406 0 : virtual ~WrtRedlineAuthor() {}
407 :
408 : sal_uInt16 AddName( const OUString& rNm );
409 : virtual void Write(Writer &rWrt) = 0;
410 : // std::vector<String> GetNames();
411 : };
412 :
413 : /** Given a SwNoTxtNode (ole/graphic) get original size
414 :
415 : Get the uncropped and unscaled size of the underlying graphic or
416 : ole object associated with a given SwNoTxtNode.
417 :
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
422 :
423 : @param rNd
424 : the SwNoTxtNode whose objects original size we want
425 :
426 : @return
427 : the uncropped unscaled size of the SwNoTxtNode
428 :
429 : @author
430 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
431 : */
432 : Size GetSwappedInSize(const SwNoTxtNode& rNd);
433 :
434 : struct CharRunEntry
435 : {
436 : xub_StrLen mnEndPos;
437 : sal_uInt16 mnScript;
438 : rtl_TextEncoding meCharSet;
439 : bool mbRTL;
440 622 : CharRunEntry(xub_StrLen nEndPos, sal_uInt16 nScript,
441 : rtl_TextEncoding eCharSet, bool bRTL)
442 : : mnEndPos(nEndPos), mnScript(nScript), meCharSet(eCharSet),
443 622 : mbRTL(bRTL)
444 : {
445 622 : }
446 : };
447 :
448 : typedef std::vector<CharRunEntry> CharRuns;
449 : typedef CharRuns::const_iterator cCharRunIter;
450 :
451 : /** Collect the ranges of Text which share
452 :
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.
456 :
457 : So this function finds these ranges and returns a STL container
458 : of CharRuns
459 :
460 : @param rTxtNd
461 : The TextNode we want to ranges from
462 :
463 : @param nStart
464 : The position in the TxtNode to start processing from
465 :
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+
470 :
471 : @return STL container of CharRuns which describe the shared
472 : direction, script and optionally script of the contigious sequences
473 : of characters
474 :
475 : @author
476 : <a href="mailto:cmc@openoffice.org">Caolán McNamara</a>
477 :
478 : @see #i22537# for example
479 : */
480 : CharRuns GetPseudoCharRuns(const SwTxtNode& rTxtNd,
481 : xub_StrLen nStart = 0, bool bSplitOnCharSet = false);
482 : }
483 : }
484 :
485 : #endif
486 :
487 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|