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