LCOV - code coverage report
Current view: top level - include/editeng - svxrtf.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 31 0.0 %
Date: 2014-11-03 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             : namespace vcl { 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, vcl::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 through
     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 through
     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             :     RTFPlainAttrMapIds aPlainMap;
     186             :     RTFPardAttrMapIds aPardMap;
     187             :     std::vector<sal_uInt16> aWhichMap;
     188             :     OUString  sBaseURL;
     189             : 
     190             :     SvxPosition* pInsPos;
     191             :     SfxItemPool* pAttrPool;
     192             :     Color*  pDfltColor;
     193             :     vcl::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             :     // Execute 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           0 :     SvxRTFStyleTbl& GetStyleTbl()               { return aStyleTbl; }
     313             :     SvxRTFItemStack& GetAttrStack()             { return aAttrStack; }
     314             :     SvxRTFColorTbl& GetColorTbl()               { return aColorTbl; }
     315             :     SvxRTFFontTbl& GetFontTbl()                 { return aFontTbl; }
     316             : 
     317             :     const OUString& GetBaseURL() const          { return sBaseURL; }
     318             : 
     319             : public:
     320             : 
     321             :     virtual SvParserState CallParser() SAL_OVERRIDE;
     322             : 
     323             :     inline const Color& GetColor( size_t nId ) const;
     324             :     const vcl::Font& GetFont( sal_uInt16 nId );      // Changes the default Font
     325             : 
     326             :     virtual bool IsEndPara( SvxNodeIdx* pNd, sal_Int32 nCnt ) const = 0;
     327             : 
     328             :     // to set a different attribute pool. May only be done prior to CallParser!
     329             :     // The maps are not generated anew!
     330           0 :     void SetAttrPool( SfxItemPool* pNewPool )   { pAttrPool = pNewPool; }
     331             :     // to set different WhichIds for a different pool.
     332           0 :     RTFPardAttrMapIds& GetPardMap() { return aPardMap; }
     333             :     RTFPlainAttrMapIds& GetPlainMap() { return aPlainMap; }
     334             :     // to be able to assign them from the outside as for example table cells
     335             :     void ReadBorderAttr( int nToken, SfxItemSet& rSet, int bTableDef=sal_False );
     336             :     void ReadBackgroundAttr( int nToken, SfxItemSet& rSet, int bTableDef=sal_False  );
     337             : 
     338             :     // for asynchronous read from the SvStream
     339             :     virtual void Continue( int nToken ) SAL_OVERRIDE;
     340             : 
     341             :     // get RTF default ItemSets. Must be used by pard/plain tokens or in
     342             :     // reset of Style-Items
     343             :     const SfxItemSet& GetRTFDefaults();
     344             :     virtual bool UncompressableStackEntry(const SvxRTFItemStackType &rSet) const;
     345             : };
     346             : 
     347             : // The stack for the attributes:
     348             : // this class may only be used by SvxRTFParser!
     349             : class EDITENG_DLLPUBLIC SvxRTFItemStackType
     350             : {
     351             :     friend class SvxRTFParser;
     352             : 
     353             :     SfxItemSet  aAttrSet;
     354             :     SvxNodeIdx  *pSttNd, *pEndNd;
     355             :     sal_Int32 nSttCnt, nEndCnt;
     356             :     SvxRTFItemStackList* pChildList;
     357             :     sal_uInt16 nStyleNo;
     358             : 
     359             :     SvxRTFItemStackType( SfxItemPool&, const sal_uInt16* pWhichRange,
     360             :                             const SvxPosition& );
     361             : 
     362             :     void Add( SvxRTFItemStackType* );
     363             :     void Compress( const SvxRTFParser& );
     364             : 
     365             : public:
     366             :     SvxRTFItemStackType( const SvxRTFItemStackType&, const SvxPosition&,
     367             :                         int bCopyAttr = sal_False );
     368             :     ~SvxRTFItemStackType();
     369             :     //cmc, I'm very suspicios about SetStartPos, it doesn't change
     370             :     //its children's starting position, and the implementation looks
     371             :     //bad, consider this deprecated.
     372             :     void SetStartPos( const SvxPosition& rPos );
     373             : 
     374             :     void MoveFullNode(const SvxNodeIdx &rOldNode,
     375             :         const SvxNodeIdx &rNewNode);
     376             : 
     377           0 :     sal_Int32 GetSttNodeIdx() const { return pSttNd->GetIdx(); }
     378           0 :     sal_Int32 GetEndNodeIdx() const { return pEndNd->GetIdx(); }
     379             : 
     380           0 :     const SvxNodeIdx& GetSttNode() const { return *pSttNd; }
     381           0 :     const SvxNodeIdx& GetEndNode() const { return *pEndNd; }
     382             : 
     383           0 :     sal_Int32 GetSttCnt() const { return nSttCnt; }
     384           0 :     sal_Int32 GetEndCnt() const { return nEndCnt; }
     385             : 
     386           0 :           SfxItemSet& GetAttrSet()          { return aAttrSet; }
     387             :     const SfxItemSet& GetAttrSet() const    { return aAttrSet; }
     388             : 
     389           0 :     sal_uInt16 StyleNo() const  { return nStyleNo; }
     390             : 
     391             :     void SetRTFDefaults( const SfxItemSet& rDefaults );
     392             : };
     393             : 
     394             : 
     395             : // ----------- Inline Implementations --------------
     396             : 
     397           0 : inline const Color& SvxRTFParser::GetColor( size_t nId ) const
     398             : {
     399           0 :     ColorPtr pColor = (ColorPtr)pDfltColor;
     400           0 :     if( nId < aColorTbl.size() )
     401           0 :         pColor = aColorTbl[ nId ];
     402           0 :     return *pColor;
     403             : }
     404             : 
     405           0 : inline SfxItemSet& SvxRTFParser::GetAttrSet()
     406             : {
     407             :     SvxRTFItemStackType* pTmp;
     408           0 :     if( bNewGroup || 0 == ( pTmp = aAttrStack.empty() ? 0 : aAttrStack.back()) )
     409           0 :         pTmp = _GetAttrSet();
     410           0 :     return pTmp->aAttrSet;
     411             : }
     412             : 
     413             : 
     414             : #endif
     415             :     // INCLUDED_EDITENG_SVXRTF_HXX
     416             : 
     417             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10