LCOV - code coverage report
Current view: top level - sw/source/core/inc - txtfly.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 33 37 89.2 %
Date: 2014-11-03 Functions: 14 15 93.3 %
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             : #ifndef INCLUDED_SW_SOURCE_CORE_INC_TXTFLY_HXX
      20             : #define INCLUDED_SW_SOURCE_CORE_INC_TXTFLY_HXX
      21             : 
      22             : #include "swtypes.hxx"
      23             : #include "swrect.hxx"
      24             : #include <fmtsrndenum.hxx>
      25             : #include <vector>
      26             : 
      27             : class OutputDevice;
      28             : class SwCntntFrm;
      29             : class SwPageFrm;
      30             : class SwTxtFly;
      31             : class SdrObject;
      32             : class SwTxtPaintInfo;
      33             : class SwFmt;
      34             : class TextRanger;
      35             : class SwAnchoredObject;
      36             : class SwTxtFrm;
      37             : class SwDrawTextInfo;
      38             : class SwContourCache;
      39             : 
      40             : typedef std::vector< SwAnchoredObject* > SwAnchoredObjList;
      41             : 
      42             : enum PAGESIDE { LEFT_SIDE, RIGHT_SIDE, DONTKNOW_SIDE };
      43             : 
      44             : /** Contour-cache global variable, initialized/destroyed in txtinit.cxx
      45             :     and needed in txtfly.cxx by text wrapping.
      46             :   */
      47             : extern SwContourCache *pContourCache;
      48             : 
      49             : #define POLY_CNT 20
      50             : #define POLY_MIN 5
      51             : #define POLY_MAX 4000
      52             : 
      53             : void ClrContourCache( const SdrObject *pObj );
      54             : 
      55             : class SwContourCache
      56             : {
      57             :     friend void ClrContourCache();
      58             :     const SdrObject *pSdrObj[ POLY_CNT ];
      59             :     TextRanger *pTextRanger[ POLY_CNT ];
      60             :     long nPntCnt;
      61             :     sal_uInt16 nObjCnt;
      62             :     const SwRect ContourRect( const SwFmt* pFmt, const SdrObject* pObj,
      63             :         const SwTxtFrm* pFrm, const SwRect &rLine, const long nXPos,
      64             :         const bool bRight );
      65             : 
      66             : public:
      67             :     SwContourCache();
      68             :     ~SwContourCache();
      69          26 :     const SdrObject* GetObject( sal_uInt16 nPos ) const{ return pSdrObj[ nPos ]; }
      70        3151 :     sal_uInt16 GetCount() const { return nObjCnt; }
      71             :     void ClrObject( sal_uInt16 nPos );
      72             : 
      73             :     /**
      74             :       Computes the rectangle that will cover the object in the given line.
      75             : 
      76             :       For _non_ contour-flow objects, this is simply the overlap area of
      77             :       BoundRect (including spacing), and the line, for contour-flow,
      78             :       the tools::PolyPolygon of the object gets traversed
      79             :      */
      80             :     static const SwRect CalcBoundRect( const SwAnchoredObject* pAnchoredObj,
      81             :                                        const SwRect &rLine,
      82             :                                        const SwTxtFrm* pFrm,
      83             :                                        const long nXPos,
      84             :                                        const bool bRight );
      85             : };
      86             : 
      87             : /**
      88             :    The purpose of this class is to be the universal interface between
      89             :    formatting/text output and the possibly overlapping free-flying frames.
      90             :    During formatting the formatter gets the information from SwTxtFly, whether
      91             :    a certain area is present by the attributes of an overlapping frame.
      92             :    Such areas are represented by dummy portions.
      93             : 
      94             :    The whole text output and touch-up is, again, forwarded to a SwTxtFly.
      95             :    This one decides, whether parts of the text need to be clipped and splits
      96             :    the areas for e.g. a DrawRect.
      97             : 
      98             :    Please note that all free-flying frames are located in a PtrArray, sorted
      99             :    by TopLeft.
     100             : 
     101             :    Internally we always use document-global values. The IN and OUT parameters
     102             :    are, however, adjusted to the needs of the LineIter most of the time. That
     103             :    is: they are converted to frame- and window-local coordinates.
     104             :    If multiple frames with wrap attributes are located on the same line, we get
     105             :    the following settings for the text flow:
     106             : 
     107             :         L/R    P     L     R     N
     108             :          P   -P-P- -P-L  -P R- -P N
     109             :          L   -L P- -L L  -L R- -L N
     110             :          R    R-P-  R-L   R R-  R N
     111             :          N    N P-  N L   N R-  N N
     112             : 
     113             :    (P=parallel, L=left, R=right, N=no wrap)
     114             : 
     115             :    We can describe the behaviour as follows:
     116             :    Every frame can push away text, with the restriction that it only has influence
     117             :    until the next frame.
     118             :  */
     119             : class SwTxtFly
     120             : {
     121             :     const SwPageFrm             * pPage;
     122             :     const SwAnchoredObject      * mpCurrAnchoredObj;
     123             :     const SwTxtFrm              * pCurrFrm;
     124             :     const SwCntntFrm            * pMaster;
     125             :     SwAnchoredObjList           * mpAnchoredObjList;
     126             : 
     127             :     long nMinBottom;
     128             :     long nNextTop;  /// Stores the upper edge of the "next" frame
     129             :     sal_uLong nIndex;
     130             : 
     131             :     bool bOn : 1;
     132             :     bool bTopRule: 1;
     133             :     bool mbIgnoreCurrentFrame: 1;
     134             :     bool mbIgnoreContour: 1;
     135             : 
     136             :     /** boolean, indicating if objects in page header|footer are considered for
     137             :         text frames not in page header|footer.
     138             :      */
     139             :     bool mbIgnoreObjsInHeaderFooter: 1;
     140             : 
     141             :     /**
     142             :         This method will be called during the LineIter formatting
     143             :             \li to compute the position of the next \c FlyPortion
     144             :             \li remember new overlappings after a change of the line height.
     145             : 
     146             :         \param[in] rPortion
     147             :             Scope: document global.
     148             :      */
     149             :     SwRect _GetFrm( const SwRect &rPortion, bool bTop ) const;
     150             : 
     151             :     SwAnchoredObjList* InitAnchoredObjList();
     152             : 
     153             :     SwAnchoredObjList* GetAnchoredObjList() const;
     154             : 
     155             :     /**
     156             :         Look for the first object which overlaps with the rectangle.
     157             :         Iterates over the anchored object list mpAnchoredObjList.
     158             :     */
     159             :     bool ForEach( const SwRect &rRect, SwRect* pRect, bool bAvoid ) const;
     160             : 
     161             :     /**
     162             :       \li There is less than 2cm space on both sides for the text:
     163             :       no surround (SURROUND_NONE)
     164             : 
     165             :       \li There is more than 2cm space on only one side:
     166             :       surround on that side (SURROUND_LEFT or SURROUND_RIGHT)
     167             : 
     168             :       \li There is more than 2cm space on both sides, the object is
     169             :       larger than 1.5cm: surround on the wider side
     170             :       (SURROUND_LET or SURROUND_RIGHT)
     171             : 
     172             :       \li There is more than 2cm space on both sides and the object
     173             :       width is less than 1.5cm: both sides surround (SURROUND_PARALLEL)
     174             :      */
     175             :     SwSurround _GetSurroundForTextWrap( const SwAnchoredObject* pAnchoredObj ) const;
     176             : 
     177             :     /**
     178             :        The right margin is the right margin or it is determined by the
     179             :        next object standing on the line.
     180             :      */
     181             :     void CalcRightMargin( SwRect &rFly,
     182             :                           SwAnchoredObjList::size_type nPos,
     183             :                           const SwRect &rLine ) const;
     184             : 
     185             :     /**
     186             :        The left margin is the left margin of the current PrintArea or
     187             :        it is determined by the last FlyFrm, which stands on the line.
     188             :      */
     189             :     void CalcLeftMargin( SwRect &rFly,
     190             :                          SwAnchoredObjList::size_type nPos,
     191             :                          const SwRect &rLine ) const;
     192             : 
     193             :     /**
     194             :        \return the position in sorted array
     195             :      */
     196             :     SwAnchoredObjList::size_type GetPos( const SwAnchoredObject* pAnchoredObj ) const;
     197             : 
     198             :     bool GetTop( const SwAnchoredObject* _pAnchoredObj,
     199             :                  const bool bInFtn,
     200             :                  const bool bInFooterOrHeader );
     201             : 
     202             :     SwTwips CalcMinBottom() const;
     203             : 
     204             :     const SwCntntFrm* _GetMaster();
     205             : 
     206             : public:
     207             : 
     208             :     SwTxtFly();
     209             :     SwTxtFly( const SwTxtFrm *pFrm );
     210             :     SwTxtFly( const SwTxtFly& rTxtFly );
     211             :     ~SwTxtFly();
     212             : 
     213             :     void CtorInitTxtFly( const SwTxtFrm *pFrm );
     214             : 
     215             :     void SetTopRule();
     216             : 
     217             :     SwRect GetFrm( const SwRect &rPortion, bool bTop = true ) const;
     218             :     bool IsOn() const;
     219             : 
     220             :     /**
     221             :         If there is no flying object frame standing in rRect (usually the current row),
     222             :         then we are turning ourself off.
     223             : 
     224             :         \param rRect is global to the document!
     225             :      */
     226             :     bool Relax( const SwRect &rRect );
     227             :     bool Relax();
     228             : 
     229             :     SwTwips GetMinBottom() const;
     230             :     const SwCntntFrm* GetMaster() const;
     231             : 
     232             :     // This temporary variable needs to be manipulated in const methods
     233             :     long GetNextTop() const;
     234             :     void SetNextTop( long nNew ) const;
     235             : 
     236             :     /**
     237             :       Determines the demanded rectangle for an anchored object,
     238             :       considering its surround for text wrapping.
     239             : 
     240             :       \param pAnchoredObj the object for which to get the bounds
     241             :       \param rLine the bounds of the line to format
     242             : 
     243             :       \return the flying object bounds
     244             :       */
     245             :     SwRect AnchoredObjToRect( const SwAnchoredObject* pAnchoredObj,
     246             :                               const SwRect& rRect ) const;
     247             : 
     248             :     /**
     249             :         This method is called by DrawText().
     250             : 
     251             :         Ensures that the overlapping frames (except the transparent frames) won't
     252             :         be scribbled by setting clip regions so that only the portions that are not
     253             :         in the area of FlyFrms that are opaque and above the current frame will
     254             :         be output.
     255             : 
     256             :         DrawText() takes over the on optimization!
     257             :      */
     258             :     bool DrawTextOpaque( SwDrawTextInfo &rInf );
     259             : 
     260             :     /**
     261             :         Two subtleties needs to be mentioned:
     262             :             \li DrawRect() is allowed over the ClipRects
     263             :             \li FlyToRect() returns bigger values than the frame data
     264             : 
     265             :         Ensure that the overlapping frames (except the transparent frames)
     266             :         won't be scribbled
     267             :      */
     268             :     void DrawFlyRect( OutputDevice* pOut, const SwRect &rRect,
     269             :                       const SwTxtPaintInfo &rInf, bool bNoGraphic = false );
     270             : 
     271             :     /**
     272             :         Used to switch off the SwTxtFly when there is no overlapping object (Relax).
     273             : 
     274             :         \param[in] the line area
     275             :         \return whether the line will be overlapped by a frame
     276             :      */
     277             :     bool IsAnyFrm( const SwRect &rLine ) const;
     278             : 
     279             :     /**
     280             :         Same as IsAnyFrm(const SwRect&), but uses the current frame print
     281             :         area
     282             :      */
     283             :     bool IsAnyFrm() const;
     284             : 
     285             :     /**
     286             :         true when a frame or DrawObj must to be taken in account. The optimizations
     287             :         like Paint/FormatEmpty for empty sentences or the virtual OutputDevice can
     288             :         be used only when false is returned.
     289             : 
     290             :         \param rRect
     291             :             The rectangle can be empty, the current frame is then used. The value is
     292             :             global to the document.
     293             :       */
     294             :     bool IsAnyObj( const SwRect& rRect ) const;
     295             : 
     296             :     void SetIgnoreCurrentFrame( bool bNew );
     297             :     void SetIgnoreContour( bool bNew );
     298             : 
     299             :     void SetIgnoreObjsInHeaderFooter( const bool bNew );
     300             : };
     301             : 
     302      162540 : inline SwAnchoredObjList* SwTxtFly::GetAnchoredObjList() const
     303             : {
     304             :     return mpAnchoredObjList
     305             :            ? mpAnchoredObjList
     306      162540 :            : const_cast<SwTxtFly*>(this)->InitAnchoredObjList();
     307             : }
     308             : 
     309       20044 : inline void SwTxtFly::SetTopRule()
     310             : {
     311       20044 :     bTopRule = false;
     312       20044 : }
     313             : 
     314      688213 : inline bool SwTxtFly::IsOn() const
     315             : {
     316      688213 :     return bOn;
     317             : }
     318             : 
     319           0 : inline bool SwTxtFly::Relax( const SwRect &rRect )
     320             : {
     321           0 :     if (bOn)
     322             :     {
     323           0 :         bOn = IsAnyFrm( rRect );
     324             :     }
     325           0 :     return bOn;
     326             : }
     327             : 
     328       26820 : inline bool SwTxtFly::Relax()
     329             : {
     330       26820 :     if (bOn)
     331             :     {
     332       10122 :         bOn = IsAnyFrm();
     333             :     }
     334       26820 :     return bOn;
     335             : }
     336             : 
     337       91923 : inline SwTwips SwTxtFly::GetMinBottom() const
     338             : {
     339       91923 :     return mpAnchoredObjList ? nMinBottom : CalcMinBottom();
     340             : }
     341             : 
     342       54785 : inline const SwCntntFrm* SwTxtFly::GetMaster() const
     343             : {
     344       54785 :     return pMaster ? pMaster : ((SwTxtFly*)this)->_GetMaster();
     345             : }
     346             : 
     347         168 : inline long SwTxtFly::GetNextTop() const
     348             : {
     349         168 :     return nNextTop;
     350             : }
     351             : 
     352        5732 : inline void SwTxtFly::SetNextTop( long nNew ) const
     353             : {
     354        5732 :     ((SwTxtFly*)this)->nNextTop = nNew;
     355        5732 : }
     356             : 
     357      306023 : inline SwRect SwTxtFly::GetFrm( const SwRect &rRect, bool bTop ) const
     358             : {
     359      306023 :     return bOn ? _GetFrm( rRect, bTop ) : SwRect();
     360             : }
     361             : 
     362      206368 : inline void SwTxtFly::SetIgnoreCurrentFrame( bool bNew )
     363             : {
     364      206368 :     mbIgnoreCurrentFrame = bNew;
     365      206368 : }
     366             : 
     367      103184 : inline void SwTxtFly::SetIgnoreContour( bool bNew )
     368             : {
     369      103184 :     mbIgnoreContour = bNew;
     370      103184 : }
     371             : 
     372      103184 : inline void SwTxtFly::SetIgnoreObjsInHeaderFooter( const bool bNew )
     373             : {
     374      103184 :     mbIgnoreObjsInHeaderFooter = bNew;
     375      103184 : }
     376             : 
     377             : #endif
     378             : 
     379             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10