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

Generated by: LCOV version 1.10