LCOV - code coverage report
Current view: top level - sw/source/core/layout - layhelp.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 23 23 100.0 %
Date: 2015-06-13 12:38:46 Functions: 21 21 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SW_SOURCE_CORE_LAYOUT_LAYHELP_HXX
      21             : #define INCLUDED_SW_SOURCE_CORE_LAYOUT_LAYHELP_HXX
      22             : 
      23             : #include <swrect.hxx>
      24             : #include <vector>
      25             : #include <deque>
      26             : 
      27             : class SwDoc;
      28             : class SwFrm;
      29             : class SwLayoutFrm;
      30             : class SwPageFrm;
      31             : class SwFlyFrm;
      32             : class SwSectionFrm;
      33             : class SwSectionNode;
      34             : class SvStream;
      35             : 
      36             : /*
      37             :  * Contains the page break information and the text frame positions
      38             :  * of the document (after loading)
      39             :  * and is used inside the constructor of the layout rootframe to
      40             :  * insert content and text frames at the right pages.
      41             :  * For every page of the main text (body content, no footnotes, text frames etc.)
      42             :  * we have the nodeindex of the first content at the page,
      43             :  * the type of content ( table or paragraph )
      44             :  * and if it's not the first part of the table/paragraph,
      45             :  * the row/character-offset inside the table/paragraph.
      46             :  * The text frame positions are stored in the SwPageFlyCache array.
      47             :  */
      48             : 
      49             : class SwFlyCache;
      50             : typedef boost::ptr_vector<SwFlyCache> SwPageFlyCache;
      51             : 
      52          41 : class SwLayCacheImpl
      53             : {
      54             :     std::vector<sal_uLong> mIndices;
      55             :     std::deque<sal_Int32> aOffset;
      56             :     std::vector<sal_uInt16> aType;
      57             :     SwPageFlyCache aFlyCache;
      58             :     bool bUseFlyCache;
      59             :     void Insert( sal_uInt16 nType, sal_uLong nIndex, sal_Int32 nOffset );
      60             : 
      61             : public:
      62          41 :     SwLayCacheImpl() : mIndices(), aOffset(), aType(), aFlyCache(), bUseFlyCache(false) {}
      63             : 
      64        1482 :     size_t size() const { return mIndices.size(); }
      65             : 
      66             :     bool Read( SvStream& rStream );
      67             : 
      68        1231 :     sal_uLong GetBreakIndex( sal_uInt16 nIdx ) const { return mIndices[ nIdx ]; }
      69          67 :     sal_Int32 GetBreakOfst( size_t nIdx ) const { return aOffset[ nIdx ]; }
      70          65 :     sal_uInt16 GetBreakType( sal_uInt16 nIdx ) const { return aType[ nIdx ]; }
      71             : 
      72         109 :     size_t GetFlyCount() const { return aFlyCache.size(); }
      73          12 :     SwFlyCache& GetFlyCache( size_t nIdx ) { return aFlyCache[ nIdx ]; }
      74             : 
      75           2 :     bool IsUseFlyCache() const { return bUseFlyCache; }
      76             : };
      77             : 
      78             : // Helps to create the sectionframes during the _InsertCnt-function
      79             : // by controlling nested sections.
      80             : class SwActualSection
      81             : {
      82             :     SwActualSection *pUpper;
      83             :     SwSectionFrm    *pSectFrm;
      84             :     SwSectionNode   *pSectNode;
      85             : public:
      86             :     SwActualSection( SwActualSection *pUpper,
      87             :                      SwSectionFrm    *pSect,
      88             :                      SwSectionNode   *pNd );
      89             : 
      90         295 :     SwSectionFrm    *GetSectionFrm()                    { return pSectFrm; }
      91         117 :     void             SetSectionFrm( SwSectionFrm *p )   { pSectFrm = p; }
      92          42 :     SwSectionNode   *GetSectionNode()                   { return pSectNode;}
      93         674 :     SwActualSection *GetUpper()                         { return pUpper; }
      94             : };
      95             : 
      96             : // Helps during the _InsertCnt-function to create new pages.
      97             : // If there's a layoutcache available, this information is used.
      98             : class SwLayHelper
      99             : {
     100             :     SwFrm* &rpFrm;
     101             :     SwFrm* &rpPrv;
     102             :     SwPageFrm* &rpPage;
     103             :     SwLayoutFrm* &rpLay;
     104             :     SwActualSection* &rpActualSection;
     105             :     bool &rbBreakAfter;
     106             :     SwDoc* pDoc;
     107             :     SwLayCacheImpl* pImpl;
     108             :     sal_uLong nMaxParaPerPage;
     109             :     sal_uLong nParagraphCnt;
     110             :     sal_uLong nStartOfContent;
     111             :     sal_uInt16 nIndex;                      // the index in the page break array
     112             :     size_t nFlyIdx;                         // the index in the fly cache array
     113             :     bool bFirst : 1;
     114             :     void _CheckFlyCache( SwPageFrm* pPage );
     115             : public:
     116             :     SwLayHelper( SwDoc *pD, SwFrm* &rpF, SwFrm* &rpP, SwPageFrm* &rpPg,
     117             :             SwLayoutFrm* &rpL, SwActualSection* &rpA, bool &rBrk,
     118             :             sal_uLong nNodeIndex, bool bCache );
     119             :     ~SwLayHelper();
     120             :     sal_uLong CalcPageCount();
     121             :     bool CheckInsert( sal_uLong nNodeIndex );
     122             : 
     123             :     bool CheckInsertPage();
     124             : 
     125             :     /// Look for fresh text frames at this (new) page and set them to the right
     126             :     /// position, if they are in the fly cache.
     127        3042 :     void CheckFlyCache( SwPageFrm* pPage )
     128        3042 :     { if( pImpl && nFlyIdx < pImpl->GetFlyCount() ) _CheckFlyCache( pPage ); }
     129             : };
     130             : 
     131             : // Contains the data structures that are required to read and write a layout cache.
     132             : #define SW_LAYCACHE_IO_REC_PAGES    'p'
     133             : #define SW_LAYCACHE_IO_REC_PARA     'P'
     134             : #define SW_LAYCACHE_IO_REC_TABLE    'T'
     135             : #define SW_LAYCACHE_IO_REC_FLY      'F'
     136             : 
     137             : #define SW_LAYCACHE_IO_VERSION_MAJOR    1
     138             : #define SW_LAYCACHE_IO_VERSION_MINOR    1
     139             : 
     140          56 : class SwLayCacheIoImpl
     141             : {
     142             : private:
     143             :     struct RecTypeSize {
     144             :         sal_uInt8 type;
     145             :         sal_uLong size;
     146         903 :         RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
     147             :     };
     148             :     std::vector<RecTypeSize> aRecords;
     149             : 
     150             :     SvStream        *pStream;
     151             : 
     152             :     sal_uLong           nFlagRecEnd;
     153             : 
     154             :     sal_uInt16          nMajorVersion;
     155             :     sal_uInt16          nMinorVersion;
     156             : 
     157             :     bool            bWriteMode : 1;
     158             :     bool            bError : 1;
     159             : 
     160             : public:
     161             :     SwLayCacheIoImpl( SvStream& rStrm, bool bWrtMd );
     162             : 
     163             :     /// Get input or output stream
     164         875 :     SvStream& GetStream() const { return *pStream; }
     165             : 
     166             :     /// Open a record of type "nType"
     167             :     bool OpenRec( sal_uInt8 nType );
     168             : 
     169             :     /// Close a record of type "nType". This skips any unread data that
     170             :     /// remains in the record.
     171             :     bool CloseRec( sal_uInt8 nType );
     172             : 
     173             :     /// Return the number of bytes contained in the current record that
     174             :     /// haven't been read by now.
     175             :     sal_uInt32 BytesLeft();
     176             : 
     177             :     /// Return the current record's type
     178             :     sal_uInt8 Peek();
     179             : 
     180             :     /// Skip the current record
     181             :     void SkipRec();
     182             : 
     183             :     /// Open a flag record for reading. The uppermost four bits are flags,
     184             :     /// while the lowermost are the flag record's size. Flag records cannot
     185             :     /// be nested.
     186             :     sal_uInt8 OpenFlagRec();
     187             : 
     188             :     /// Open flag record for writing;
     189             :     void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
     190             : 
     191             :     /// Close a flag record. Any bytes left are skipped.
     192             :     void CloseFlagRec();
     193             : 
     194         865 :     bool HasError() const { return bError; }
     195             : 
     196          41 :     sal_uInt16 GetMajorVersion() const { return nMajorVersion; }
     197          41 :     sal_uInt16 GetMinorVersion() const { return nMinorVersion; }
     198             : };
     199             : 
     200             : // Stored information about text frames:
     201             : class SwFlyCache : public SwRect // position and size
     202             : {
     203             : public:
     204             :     sal_uLong nOrdNum;      ///< Id to recognize text frames
     205             :     sal_uInt16 nPageNum;    ///< page number
     206          33 :     SwFlyCache( sal_uInt16 nP, sal_uLong nO, long nXL, long nYL, long nWL, long nHL ) :
     207          33 :         SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
     208             : };
     209             : 
     210             : #endif
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11