LCOV - code coverage report
Current view: top level - sw/source/filter/inc - msfilter.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 15 86.7 %
Date: 2015-06-13 12:38:46 Functions: 9 12 75.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11