LCOV - code coverage report
Current view: top level - include/editeng - svxrtf.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 32 0.0 %
Date: 2014-04-11 Functions: 0 27 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_EDITENG_SVXRTF_HXX
      21             : #define INCLUDED_EDITENG_SVXRTF_HXX
      22             : 
      23             : #include <svl/itemset.hxx>
      24             : #include <svtools/parrtf.hxx>
      25             : #include <rtl/ustring.hxx>
      26             : 
      27             : #include <editeng/editengdllapi.h>
      28             : 
      29             : #include <deque>
      30             : #include <utility>
      31             : #include <vector>
      32             : #include <boost/ptr_container/ptr_map.hpp>
      33             : #include <boost/ptr_container/ptr_vector.hpp>
      34             : 
      35             : class Font;
      36             : class Color;
      37             : class Graphic;
      38             : class DateTime;
      39             : struct SvxRTFStyleType;
      40             : class SvxRTFItemStackType;
      41           0 : class SvxRTFItemStackList : public boost::ptr_vector<SvxRTFItemStackType> {};
      42             : 
      43             : namespace com { namespace sun { namespace star {
      44             :     namespace document {
      45             :         class XDocumentProperties;
      46             :     }
      47             :     namespace util {
      48             :         struct DateTime;
      49             :     }
      50             : } } }
      51             : 
      52             : 
      53             : // Mapper-Classes for the various requirements on Document positions
      54             : //        Swg - NodePosition is a SwIndex, which is used internally
      55             : // EditEngine - ULONG to list of paragraphs
      56             : 
      57             : 
      58           0 : class SvxNodeIdx
      59             : {
      60             : public:
      61           0 :     virtual ~SvxNodeIdx() {}
      62             :     virtual sal_Int32   GetIdx() const = 0;
      63             :     virtual SvxNodeIdx* Clone() const = 0;  // Cloning itself
      64             : };
      65             : 
      66           0 : class SvxPosition
      67             : {
      68             : public:
      69           0 :     virtual ~SvxPosition() {}
      70             : 
      71             :     virtual sal_Int32   GetNodeIdx() const = 0;
      72             :     virtual sal_Int32   GetCntIdx() const = 0;
      73             : 
      74             :     virtual SvxPosition* Clone() const = 0; // Cloning itself
      75             :     virtual SvxNodeIdx* MakeNodeIdx() const = 0; // Cloning NodeIndex
      76             : };
      77             : 
      78             : 
      79             : typedef Color* ColorPtr;
      80             : typedef std::deque< ColorPtr > SvxRTFColorTbl;
      81             : typedef boost::ptr_map<short, Font> SvxRTFFontTbl;
      82             : typedef boost::ptr_map<sal_uInt16, SvxRTFStyleType> SvxRTFStyleTbl;
      83             : 
      84             : // SvxRTFItemStack can't be "std::stack< SvxRTFItemStackType* >" type, because
      85             : // the methods are using operator[] in sw/source/filter/rtf/rtftbl.cxx file
      86             : typedef std::deque< SvxRTFItemStackType* > SvxRTFItemStack;
      87             : 
      88             : // own helper classes for the RTF Parser
      89           0 : struct SvxRTFStyleType
      90             : {
      91             :     SfxItemSet aAttrSet;        // the attributes of Style (+ derivate!)
      92             :     OUString sName;
      93             :     sal_uInt16 nBasedOn, nNext;
      94             :     bool bBasedOnIsSet;
      95             :     sal_uInt8 nOutlineNo;
      96             :     bool bIsCharFmt;
      97             : 
      98             :     SvxRTFStyleType( SfxItemPool& rPool, const sal_uInt16* pWhichRange );
      99             : };
     100             : 
     101             : 
     102             : // Here are the IDs for all character attributes, which can be detected by
     103             : // SvxParser and can be set in a SfxItemSet. The IDs are set correctly throught
     104             : // the SlotIds from POOL.
     105             : struct RTFPlainAttrMapIds
     106             : {
     107             :     sal_uInt16  nCaseMap,
     108             :             nBgColor,
     109             :             nColor,
     110             :             nContour,
     111             :             nCrossedOut,
     112             :             nEscapement,
     113             :             nFont,
     114             :             nFontHeight,
     115             :             nKering,
     116             :             nLanguage,
     117             :             nPosture,
     118             :             nShadowed,
     119             :             nUnderline,
     120             :             nOverline,
     121             :             nWeight,
     122             :             nWordlineMode,
     123             :             nAutoKerning,
     124             :             nCJKFont,
     125             :             nCJKFontHeight,
     126             :             nCJKLanguage,
     127             :             nCJKPosture,
     128             :             nCJKWeight,
     129             :             nCTLFont,
     130             :             nCTLFontHeight,
     131             :             nCTLLanguage,
     132             :             nCTLPosture,
     133             :             nCTLWeight,
     134             :             nEmphasis,
     135             :             nTwoLines,
     136             :             nCharScaleX,
     137             :             nHorzVert,
     138             :             nRuby,
     139             :             nRelief,
     140             :             nHidden
     141             :             ;
     142             :     RTFPlainAttrMapIds( const SfxItemPool& rPool );
     143             : };
     144             : 
     145             : // Here are the IDs for all paragraph attributes, which can be detected by
     146             : // SvxParser and can be set in a SfxItemSet. The IDs are set correctly throught
     147             : // the SlotIds from POOL.
     148             : struct RTFPardAttrMapIds
     149             : {
     150             :     sal_uInt16  nLinespacing,
     151             :             nAdjust,
     152             :             nTabStop,
     153             :             nHyphenzone,
     154             :             nLRSpace,
     155             :             nULSpace,
     156             :             nBrush,
     157             :             nBox,
     158             :             nShadow,
     159             :             nOutlineLvl,
     160             :             nSplit,
     161             :             nKeep,
     162             :             nFontAlign,
     163             :             nScriptSpace,
     164             :             nHangPunct,
     165             :             nForbRule,
     166             :             nDirection
     167             :             ;
     168             :     RTFPardAttrMapIds( const SfxItemPool& rPool );
     169             : };
     170             : 
     171             : 
     172             : 
     173             : 
     174             : 
     175             : 
     176             : class EDITENG_DLLPUBLIC SvxRTFParser : public SvRTFParser
     177             : {
     178             :     SvStream &rStrm;
     179             :     SvxRTFColorTbl  aColorTbl;
     180             :     SvxRTFFontTbl   aFontTbl;
     181             :     SvxRTFStyleTbl  aStyleTbl;
     182             :     SvxRTFItemStack aAttrStack;
     183             :     SvxRTFItemStackList aAttrSetList;
     184             : 
     185             :     std::vector<sal_uInt16> aPlainMap;
     186             :     std::vector<sal_uInt16> aPardMap;
     187             :     std::vector<sal_uInt16> aWhichMap;
     188             :     OUString  sBaseURL;
     189             : 
     190             :     SvxPosition* pInsPos;
     191             :     SfxItemPool* pAttrPool;
     192             :     Color*  pDfltColor;
     193             :     Font*   pDfltFont;
     194             :     ::com::sun::star::uno::Reference<
     195             :         ::com::sun::star::document::XDocumentProperties> m_xDocProps;
     196             :     SfxItemSet *pRTFDefaults;
     197             : 
     198             :     long    nVersionNo;
     199             :     int     nDfltFont;
     200             : 
     201             :     bool    bNewDoc : 1;            // sal_False - Reading in an existing
     202             :     bool    bNewGroup : 1;          // sal_True - there was an opening parenthesis
     203             :     bool    bIsSetDfltTab : 1;      // sal_True - DefTab was loaded
     204             :     bool    bChkStyleAttr : 1;      // sal_True - StyleSheets are evaluated
     205             :     bool    bCalcValue : 1;         // sal_True - Twip values adapt to App
     206             :     bool    bPardTokenRead : 1;     // sal_True - Token \pard was detected
     207             :     bool    bReadDocInfo : 1;       // sal_True - DocInfo to read
     208             :     bool    bIsLeftToRightDef : 1;  // sal_True - in LeftToRight char run def.
     209             :                                         // sal_False - in RightToLeft char run def.
     210             :     bool    bIsInReadStyleTab : 1;  // sal_True - in ReadStyleTable
     211             : 
     212             :     void ClearColorTbl();
     213             :     void ClearFontTbl();
     214             :     void ClearStyleTbl();
     215             :     void ClearAttrStack();
     216             : 
     217             :     SvxRTFItemStackType* _GetAttrSet( int bCopyAttr=sal_False );  // Create new ItemStackType:s
     218             :     void _ClearStyleAttr( SvxRTFItemStackType& rStkType );
     219             : 
     220             :     // Sets all the attributes that are different from the current
     221             :     void SetAttrSet( SfxItemSet& rAttrSet, SvxPosition& rSttPos );
     222             :     void SetAttrSet( SvxRTFItemStackType &rSet );
     223             :     void SetDefault( int nToken, int nValue );
     224             : 
     225             :     // Excecute pard / plain
     226             :     void RTFPardPlain( int bPard, SfxItemSet** ppSet );
     227             : 
     228             :     void BuildWhichTbl();
     229             : 
     230             :     enum RTF_CharTypeDef
     231             :     {
     232             :         NOTDEF_CHARTYPE,
     233             :         LOW_CHARTYPE,
     234             :         HIGH_CHARTYPE,
     235             :         DOUBLEBYTE_CHARTYPE
     236             :     };
     237             : 
     238             :         // set latin/asian/complex character attributes
     239             :     void SetScriptAttr(
     240             :         RTF_CharTypeDef eType, SfxItemSet& rSet, SfxPoolItem& rItem );
     241             : 
     242             : protected:
     243             :     virtual void EnterEnvironment();
     244             :     virtual void LeaveEnvironment();
     245             :     virtual void ResetPard();
     246             :     virtual void InsertPara() = 0;
     247             : 
     248             : 
     249             :     OUString& DelCharAtEnd( OUString& rStr, const sal_Unicode cDel );
     250             : 
     251             :     // is called for each token that is recognized in CallParser
     252             :     virtual void NextToken( int nToken ) SAL_OVERRIDE;
     253             : 
     254             :     virtual void ReadBitmapData() SAL_OVERRIDE;
     255             :     virtual void ReadOLEData() SAL_OVERRIDE;
     256             : 
     257             :     void ReadStyleTable();
     258             :     void ReadColorTable();
     259             :     void ReadFontTable();
     260             :     void ReadAttr( int nToken, SfxItemSet* pSet );
     261             :     void ReadTabAttr( int nToken, SfxItemSet& rSet );
     262             : 
     263             :     // Read Document-Info
     264             :     ::com::sun::star::util::DateTime GetDateTimeStamp( );
     265             :     OUString& GetTextToEndGroup( OUString& rStr );
     266             :     virtual void ReadInfo( const sal_Char* pChkForVerNo = 0 );
     267             : 
     268             :     inline SfxItemSet& GetAttrSet();
     269             :     // no text yet inserted? (SttPos from the top stack entry!)
     270             :     bool IsAttrSttPos();
     271             :     void AttrGroupEnd();        // edit the current, delete from stack
     272             :     void SetAllAttrOfStk();     // end all Attr. and set it into doc
     273             : 
     274             : 
     275             :     virtual void InsertText() = 0;
     276             :     virtual void MovePos( int bForward = sal_True ) = 0;
     277             :     virtual void SetEndPrevPara( SvxNodeIdx*& rpNodePos,
     278             :                                  sal_Int32& rCntPos )=0;
     279             :     virtual void SetAttrInDoc( SvxRTFItemStackType &rSet );
     280             :     // for Tokens, which are not evaluated in ReadAttr
     281             :     virtual void UnknownAttrToken( int nToken, SfxItemSet* pSet );
     282             : 
     283             :     // if no-one would like to have any twips
     284             :     virtual void CalcValue();
     285             : 
     286             :     SvxRTFParser( SfxItemPool& rAttrPool,
     287             :                     SvStream& rIn,
     288             :                     ::com::sun::star::uno::Reference<
     289             :                         ::com::sun::star::document::XDocumentProperties> i_xDocProps,
     290             :                     int bReadNewDoc = sal_True );
     291             :     virtual ~SvxRTFParser();
     292             : 
     293             :     bool IsNewDoc() const               { return bNewDoc; }
     294           0 :     void SetNewDoc( bool bFlag )        { bNewDoc = bFlag; }
     295             :     bool IsNewGroup() const             { return bNewGroup; }
     296             :     void SetNewGroup( bool bFlag )      { bNewGroup = bFlag; }
     297           0 :     bool IsChkStyleAttr() const         { return bChkStyleAttr; }
     298           0 :     void SetChkStyleAttr( bool bFlag )  { bChkStyleAttr = bFlag; }
     299           0 :     bool IsCalcValue() const            { return bCalcValue; }
     300           0 :     void SetCalcValue( bool bFlag )     { bCalcValue = bFlag; }
     301             :     bool IsPardTokenRead() const        { return bPardTokenRead; }
     302             :     void SetPardTokenRead( bool bFlag ) { bPardTokenRead = bFlag; }
     303             :     bool IsReadDocInfo() const          { return bReadDocInfo; }
     304             :     void SetReadDocInfo( bool bFlag )   { bReadDocInfo = bFlag; }
     305             : 
     306             :     // Query/Set the current insert position
     307             :     SvxPosition& GetInsPos() const      { return *pInsPos; }
     308             :     void SetInsPos( const SvxPosition& rNew );
     309             : 
     310             :     long GetVersionNo() const           { return nVersionNo; }
     311             : 
     312             :     // Query/Set the mapping IDs for the Pard/Plain attributes
     313             :     //(Set: It is noted in the pointers, which thus does not create a copy)
     314             :     void AddPardAttr( sal_uInt16 nWhich ) { aPardMap.push_back( nWhich ); }
     315             :     void AddPlainAttr( sal_uInt16 nWhich ) { aPlainMap.push_back( nWhich ); }
     316             : 
     317           0 :     SvxRTFStyleTbl& GetStyleTbl()               { return aStyleTbl; }
     318             :     SvxRTFItemStack& GetAttrStack()             { return aAttrStack; }
     319             :     SvxRTFColorTbl& GetColorTbl()               { return aColorTbl; }
     320             :     SvxRTFFontTbl& GetFontTbl()                 { return aFontTbl; }
     321             : 
     322             :     const OUString& GetBaseURL() const          { return sBaseURL; }
     323             : 
     324             : public:
     325             : 
     326             :     virtual SvParserState CallParser() SAL_OVERRIDE;
     327             : 
     328             :     inline const Color& GetColor( size_t nId ) const;
     329             :     const Font& GetFont( sal_uInt16 nId );      // Changes the dflt Font
     330             : 
     331             :     virtual bool IsEndPara( SvxNodeIdx* pNd, sal_Int32 nCnt ) const = 0;
     332             : 
     333             :     // to det a different attribute pool. May only be done prior to CallParser!
     334             :     // The maps are not generated anew!
     335           0 :     void SetAttrPool( SfxItemPool* pNewPool )   { pAttrPool = pNewPool; }
     336             :     // to set different WhichIds for a different pool.
     337           0 :     RTFPardAttrMapIds& GetPardMap()
     338           0 :                         { return (RTFPardAttrMapIds&)*aPardMap.begin(); }
     339             :     RTFPlainAttrMapIds& GetPlainMap()
     340             :                         { return (RTFPlainAttrMapIds&)*aPlainMap.begin(); }
     341             :     // to be able to assign them from the outside as for example table cells
     342             :     void ReadBorderAttr( int nToken, SfxItemSet& rSet, int bTableDef=sal_False );
     343             :     void ReadBackgroundAttr( int nToken, SfxItemSet& rSet, int bTableDef=sal_False  );
     344             : 
     345             :     // for asynchronous read from the SvStream
     346             :     virtual void Continue( int nToken ) SAL_OVERRIDE;
     347             : 
     348             :     // get RTF default ItemSets. Must be used by pard/plain tokens or in
     349             :     // reset of Style-Items
     350             :     const SfxItemSet& GetRTFDefaults();
     351             :     virtual bool UncompressableStackEntry(const SvxRTFItemStackType &rSet) const;
     352             : };
     353             : 
     354             : // The stack for the attributes:
     355             : // this class may only be used by SvxRTFParser!
     356             : class EDITENG_DLLPUBLIC SvxRTFItemStackType
     357             : {
     358             :     friend class SvxRTFParser;
     359             : 
     360             :     SfxItemSet  aAttrSet;
     361             :     SvxNodeIdx  *pSttNd, *pEndNd;
     362             :     sal_Int32 nSttCnt, nEndCnt;
     363             :     SvxRTFItemStackList* pChildList;
     364             :     sal_uInt16 nStyleNo;
     365             : 
     366             :     SvxRTFItemStackType( SfxItemPool&, const sal_uInt16* pWhichRange,
     367             :                             const SvxPosition& );
     368             : 
     369             :     void Add( SvxRTFItemStackType* );
     370             :     void Compress( const SvxRTFParser& );
     371             : 
     372             : public:
     373             :     SvxRTFItemStackType( const SvxRTFItemStackType&, const SvxPosition&,
     374             :                         int bCopyAttr = sal_False );
     375             :     ~SvxRTFItemStackType();
     376             :     //cmc, I'm very suspicios about SetStartPos, it doesn't change
     377             :     //its children's starting position, and the implementation looks
     378             :     //bad, consider this deprecated.
     379             :     void SetStartPos( const SvxPosition& rPos );
     380             : 
     381             :     void MoveFullNode(const SvxNodeIdx &rOldNode,
     382             :         const SvxNodeIdx &rNewNode);
     383             : 
     384           0 :     sal_Int32 GetSttNodeIdx() const { return pSttNd->GetIdx(); }
     385           0 :     sal_Int32 GetEndNodeIdx() const { return pEndNd->GetIdx(); }
     386             : 
     387           0 :     const SvxNodeIdx& GetSttNode() const { return *pSttNd; }
     388           0 :     const SvxNodeIdx& GetEndNode() const { return *pEndNd; }
     389             : 
     390           0 :     sal_Int32 GetSttCnt() const { return nSttCnt; }
     391           0 :     sal_Int32 GetEndCnt() const { return nEndCnt; }
     392             : 
     393           0 :           SfxItemSet& GetAttrSet()          { return aAttrSet; }
     394             :     const SfxItemSet& GetAttrSet() const    { return aAttrSet; }
     395             : 
     396           0 :     sal_uInt16 StyleNo() const  { return nStyleNo; }
     397             : 
     398             :     void SetRTFDefaults( const SfxItemSet& rDefaults );
     399             : };
     400             : 
     401             : 
     402             : // ----------- Inline Implementations --------------
     403             : 
     404           0 : inline const Color& SvxRTFParser::GetColor( size_t nId ) const
     405             : {
     406           0 :     ColorPtr pColor = (ColorPtr)pDfltColor;
     407           0 :     if( nId < aColorTbl.size() )
     408           0 :         pColor = aColorTbl[ nId ];
     409           0 :     return *pColor;
     410             : }
     411             : 
     412           0 : inline SfxItemSet& SvxRTFParser::GetAttrSet()
     413             : {
     414             :     SvxRTFItemStackType* pTmp;
     415           0 :     if( bNewGroup || 0 == ( pTmp = aAttrStack.empty() ? 0 : aAttrStack.back()) )
     416           0 :         pTmp = _GetAttrSet();
     417           0 :     return pTmp->aAttrSet;
     418             : }
     419             : 
     420             : 
     421             : #endif
     422             :     // INCLUDED_EDITENG_SVXRTF_HXX
     423             : 
     424             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10