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