LibreOffice Module sw (master)  1
layhelp.hxx
Go to the documentation of this file.
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 <nodeoffset.hxx>
25 
26 #include <tools/solar.h>
27 
28 #include <memory>
29 #include <vector>
30 #include <deque>
31 
32 class SwDoc;
33 class SwFrame;
34 class SwLayoutFrame;
35 class SwPageFrame;
36 class SwSectionFrame;
37 class SwSectionNode;
38 class SvStream;
39 
40 /*
41  * Contains the page break information and the text frame positions
42  * of the document (after loading)
43  * and is used inside the constructor of the layout rootframe to
44  * insert content and text frames at the right pages.
45  * For every page of the main text (body content, no footnotes, text frames etc.)
46  * we have the nodeindex of the first content at the page,
47  * the type of content ( table or paragraph )
48  * and if it's not the first part of the table/paragraph,
49  * the row/character-offset inside the table/paragraph.
50  * The text frame positions are stored in the SwPageFlyCache array.
51  */
52 
53 class SwFlyCache;
54 typedef std::vector<SwFlyCache> SwPageFlyCache;
55 
57 {
58  std::vector<SwNodeOffset> mIndices;
60  std::deque<sal_Int32> m_aOffset;
61  std::vector<sal_uInt16> m_aType;
64  void Insert( sal_uInt16 nType, SwNodeOffset nIndex, sal_Int32 nOffset );
65 
66 public:
67  inline SwLayCacheImpl();
68 
69  size_t size() const { return mIndices.size(); }
70 
71  bool Read( SvStream& rStream );
72 
73  SwNodeOffset GetBreakIndex( size_t nIdx ) const { return mIndices[ nIdx ]; }
74  sal_Int32 GetBreakOfst( size_t nIdx ) const { return m_aOffset[ nIdx ]; }
75  sal_uInt16 GetBreakType( size_t nIdx ) const { return m_aType[ nIdx ]; }
76 
77  inline size_t GetFlyCount() const;
78  inline SwFlyCache& GetFlyCache( size_t nIdx );
79 
80  bool IsUseFlyCache() const { return m_bUseFlyCache; }
81 };
82 
83 // Helps to create the sectionframes during the InsertCnt_-function
84 // by controlling nested sections.
86 {
90 public:
92  SwSectionFrame *pSect,
93  SwSectionNode *pNd );
94 
96  void SetSectionFrame( SwSectionFrame *p ) { m_pSectFrame = p; }
98  void SetUpper(SwActualSection *p) { m_pUpper = p; }
100 };
101 
105 {
110  std::unique_ptr<SwActualSection> &mrpActualSection;
117  size_t mnIndex;
118  size_t mnFlyIdx;
119  bool mbFirst : 1;
120  void CheckFlyCache_( SwPageFrame* pPage );
121 public:
122  SwLayHelper( SwDoc *pD, SwFrame* &rpF, SwFrame* &rpP, SwPageFrame* &rpPg,
123  SwLayoutFrame* &rpL, std::unique_ptr<SwActualSection> &rpA,
124  SwNodeOffset nNodeIndex, bool bCache );
125  ~SwLayHelper();
127  bool CheckInsert( SwNodeOffset nNodeIndex );
128 
129  bool CheckInsertPage();
130 
133  void CheckFlyCache( SwPageFrame* pPage )
134  { if( mpImpl && mnFlyIdx < mpImpl->GetFlyCount() ) CheckFlyCache_( pPage ); }
135 };
136 
137 // Contains the data structures that are required to read and write a layout cache.
138 #define SW_LAYCACHE_IO_REC_PAGES 'p'
139 #define SW_LAYCACHE_IO_REC_PARA 'P'
140 #define SW_LAYCACHE_IO_REC_TABLE 'T'
141 #define SW_LAYCACHE_IO_REC_FLY 'F'
142 
143 #define SW_LAYCACHE_IO_VERSION_MAJOR 1
144 #define SW_LAYCACHE_IO_VERSION_MINOR 1
145 
147 {
148 private:
149  struct RecTypeSize {
152  RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
153  };
154  std::vector<RecTypeSize> m_aRecords;
155 
157 
159 
160  sal_uInt16 m_nMajorVersion;
161  sal_uInt16 m_nMinorVersion;
162 
163  bool m_bWriteMode : 1;
164  bool m_bError : 1;
165 
166 public:
167  SwLayCacheIoImpl( SvStream& rStrm, bool bWrtMd );
168 
170  SvStream& GetStream() const { return *m_pStream; }
171 
173  void OpenRec( sal_uInt8 nType );
174 
177  void CloseRec();
178 
181  sal_uInt32 BytesLeft();
182 
184  sal_uInt8 Peek();
185 
187  void SkipRec();
188 
193 
195  void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
196 
198  void CloseFlagRec();
199 
200  bool HasError() const { return m_bError; }
201 
202  sal_uInt16 GetMajorVersion() const { return m_nMajorVersion; }
203  sal_uInt16 GetMinorVersion() const { return m_nMinorVersion; }
204 };
205 
206 // Stored information about text frames:
207 class SwFlyCache : public SwRect // position and size
208 {
209 public:
211  sal_uInt16 nPageNum;
212  SwFlyCache( sal_uInt16 nP, sal_uLong nO, tools::Long nXL, tools::Long nYL, tools::Long nWL, tools::Long nHL ) :
213  SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
214 };
215 
216 SwLayCacheImpl::SwLayCacheImpl() : m_bUseFlyCache(false) {}
217 
218 size_t SwLayCacheImpl::GetFlyCount() const { return m_FlyCache.size(); }
219 
220 SwFlyCache& SwLayCacheImpl::GetFlyCache( size_t nIdx ) { return m_FlyCache[ nIdx ]; }
221 
222 #endif
223 
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwPageFlyCache m_FlyCache
Definition: layhelp.hxx:62
Base class of the Writer layout elements.
Definition: frame.hxx:314
RecTypeSize(sal_uInt8 typ, sal_uLong siz)
Definition: layhelp.hxx:152
std::deque< sal_Int32 > m_aOffset
either a textframe character offset, or a row index inside a table
Definition: layhelp.hxx:60
bool m_bUseFlyCache
Definition: layhelp.hxx:63
void CloseRec()
Close a record.
Definition: laycache.cxx:1091
bool IsUseFlyCache() const
Definition: layhelp.hxx:80
SvStream * m_pStream
Definition: layhelp.hxx:156
SwActualSection(SwActualSection *pUpper, SwSectionFrame *pSect, SwSectionNode *pNd)
helper class to create not nested section frames for nested sections.
Definition: laycache.cxx:454
sal_uIntPtr sal_uLong
long Long
void CheckFlyCache(SwPageFrame *pPage)
Look for fresh text frames at this (new) page and set them to the right position, if they are in the ...
Definition: layhelp.hxx:133
Definition: doc.hxx:187
Helps during the InsertCnt_ function to create new pages.
Definition: layhelp.hxx:104
SwFrame *& mrpPrv
Definition: layhelp.hxx:107
void OpenRec(sal_uInt8 nType)
Open a record of type "nType".
Definition: laycache.cxx:1062
SwFlyCache(sal_uInt16 nP, sal_uLong nO, tools::Long nXL, tools::Long nYL, tools::Long nWL, tools::Long nHL)
Definition: layhelp.hxx:212
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
size_t size() const
Definition: layhelp.hxx:69
sal_uLong nOrdNum
Id to recognize text frames.
Definition: layhelp.hxx:210
std::unique_ptr< SwActualSection > & mrpActualSection
Definition: layhelp.hxx:110
SwActualSection * GetUpper()
Definition: layhelp.hxx:99
void SetUpper(SwActualSection *p)
Definition: layhelp.hxx:98
size_t GetFlyCount() const
Definition: layhelp.hxx:218
size_t mnIndex
the index in the page break array
Definition: layhelp.hxx:117
sal_uInt16 GetMajorVersion() const
Definition: layhelp.hxx:202
sal_uInt16 GetMinorVersion() const
Definition: layhelp.hxx:203
sal_uInt8 OpenFlagRec()
Open a flag record for reading.
Definition: laycache.cxx:1167
void SkipRec()
Skip the current record.
Definition: laycache.cxx:1159
SwSectionNode * m_pSectNode
Definition: layhelp.hxx:89
sal_uInt16 m_nMajorVersion
Definition: layhelp.hxx:160
sal_uInt16 nPageNum
page number
Definition: layhelp.hxx:211
std::vector< RecTypeSize > m_aRecords
Definition: layhelp.hxx:154
bool Read(SvStream &rStream)
Definition: laycache.cxx:87
SwFlyCache & GetFlyCache(size_t nIdx)
Definition: layhelp.hxx:220
SwNodeOffset mnStartOfContent
Definition: layhelp.hxx:116
bool HasError() const
Definition: layhelp.hxx:200
sal_uInt32 BytesLeft()
Return the number of bytes contained in the current record that haven't been read by now...
Definition: laycache.cxx:1129
SwSectionNode * GetSectionNode()
Definition: layhelp.hxx:97
SwLayCacheImpl * mpImpl
Definition: layhelp.hxx:113
sal_uInt16 GetBreakType(size_t nIdx) const
Definition: layhelp.hxx:75
void CloseFlagRec()
Close a flag record. Any bytes left are skipped.
Definition: laycache.cxx:1186
size_t mnFlyIdx
the index in the fly cache array
Definition: layhelp.hxx:118
void SetSectionFrame(SwSectionFrame *p)
Definition: layhelp.hxx:96
A page of the document layout.
Definition: pagefrm.hxx:57
sal_uInt8 Peek()
Return the current record's type.
Definition: laycache.cxx:1142
sal_uLong mnMaxParaPerPage
Definition: layhelp.hxx:114
SwSectionFrame * GetSectionFrame()
Definition: layhelp.hxx:95
std::vector< SwNodeOffset > mIndices
Definition: layhelp.hxx:58
SwLayCacheIoImpl(SvStream &rStrm, bool bWrtMd)
Definition: laycache.cxx:1045
SwNodeOffset GetBreakIndex(size_t nIdx) const
Definition: layhelp.hxx:73
SwLayoutFrame *& mrpLay
Definition: layhelp.hxx:109
unsigned char sal_uInt8
bool mbBreakAfter
Definition: layhelp.hxx:111
std::vector< SwFlyCache > SwPageFlyCache
Definition: layhelp.hxx:53
SwFrame *& mrpFrame
Definition: layhelp.hxx:106
SvStream & GetStream() const
Get input or output stream.
Definition: layhelp.hxx:170
SwActualSection * m_pUpper
Definition: layhelp.hxx:87
bool mbFirst
Definition: layhelp.hxx:119
SwSectionFrame * m_pSectFrame
Definition: layhelp.hxx:88
sal_Int32 GetBreakOfst(size_t nIdx) const
Definition: layhelp.hxx:74
SwLayHelper(SwDoc *pD, SwFrame *&rpF, SwFrame *&rpP, SwPageFrame *&rpPg, SwLayoutFrame *&rpL, std::unique_ptr< SwActualSection > &rpA, SwNodeOffset nNodeIndex, bool bCache)
helper class, which utilizes the layout cache information to distribute the document content to the r...
Definition: laycache.cxx:519
bool CheckInsertPage()
inserts a page and return true, if
Definition: laycache.cxx:636
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame...
Definition: layfrm.hxx:35
SwDoc * mpDoc
Definition: layhelp.hxx:112
void Insert(sal_uInt16 nType, SwNodeOffset nIndex, sal_Int32 nOffset)
Definition: laycache.cxx:80
void CheckFlyCache_(SwPageFrame *pPage)
If a new page is inserted, the last page is analysed.
Definition: laycache.cxx:968
sal_uLong CalcPageCount()
Does NOT really calculate the page count, it returns the page count value from the layout cache...
Definition: laycache.cxx:572
sal_uLong mnParagraphCnt
Definition: layhelp.hxx:115
sal_uLong m_nFlagRecEnd
Definition: layhelp.hxx:158
sal_uInt16 m_nMinorVersion
Definition: layhelp.hxx:161
std::vector< sal_uInt16 > m_aType
Definition: layhelp.hxx:61
SwPageFrame *& mrpPage
Definition: layhelp.hxx:108
bool m_bDetectedRangeSegmentation false
bool CheckInsert(SwNodeOffset nNodeIndex)
entry point for the InsertCnt_-function.
Definition: laycache.cxx:713