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

Generated by: LCOV version 1.10