1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_CORE_INC_TXTFLY_HXX
20 #define INCLUDED_SW_SOURCE_CORE_INC_TXTFLY_HXX
22 #include <editeng/txtrange.hxx>
23 #include <tools/solar.h>
24 #include <swtypes.hxx>
26 #include <com/sun/star/text/WrapTextMode.hpp>
34 class SwAnchoredObject
;
39 typedef std::vector
< SwAnchoredObject
* > SwAnchoredObjList
;
41 /** Contour-cache global variable, initialized/destroyed in txtinit.cxx
42 and needed in txtfly.cxx by text wrapping.
44 extern SwContourCache
*pContourCache
;
50 void ClrContourCache( const SdrObject
*pObj
);
54 friend void ClrContourCache();
57 const SdrObject
*mpSdrObj
;
58 std::unique_ptr
<TextRanger
> mxTextRanger
;
60 std::vector
<CacheItem
> mvItems
;
61 tools::Long mnPointCount
;
62 SwRect
ContourRect( const SwFormat
* pFormat
, const SdrObject
* pObj
,
63 const SwTextFrame
* pFrame
, const SwRect
&rLine
, const tools::Long nXPos
,
69 const SdrObject
* GetObject( sal_uInt16 nPos
) const{ return mvItems
[ nPos
].mpSdrObj
; }
70 sal_uInt16
GetCount() const { return mvItems
.size(); }
71 void ClrObject( sal_uInt16 nPos
);
74 Computes the rectangle that will cover the object in the given line.
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
80 static SwRect
CalcBoundRect( const SwAnchoredObject
* pAnchoredObj
,
82 const SwTextFrame
* pFrame
,
83 const tools::Long nXPos
,
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 SwTextFly, whether
91 a certain area is present by the attributes of an overlapping frame.
92 Such areas are represented by dummy portions.
94 The whole text output and touch-up is, again, forwarded to a SwTextFly.
95 This one decides, whether parts of the text need to be clipped and splits
96 the areas for e.g. a DrawRect.
98 Please note that all free-flying frames are located in a PtrArray, sorted
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:
108 P -P-P- -P-L -P R- -P N
109 L -L P- -L L -L R- -L N
113 (P=parallel, L=left, R=right, N=no wrap)
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.
121 const SwPageFrame
* m_pPage
;
122 const SwAnchoredObject
* mpCurrAnchoredObj
;
123 const SwTextFrame
* m_pCurrFrame
;
124 const SwTextFrame
* m_pMaster
;
125 std::unique_ptr
<SwAnchoredObjList
> mpAnchoredObjList
;
127 tools::Long m_nMinBottom
;
128 tools::Long m_nNextTop
; /// Stores the upper edge of the "next" frame
129 sal_uLong m_nCurrFrameNodeIndex
;
133 bool mbIgnoreCurrentFrame
: 1;
134 bool mbIgnoreContour
: 1;
136 /** boolean, indicating if objects in page header|footer are considered for
137 text frames not in page header|footer.
139 bool mbIgnoreObjsInHeaderFooter
: 1;
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.
147 Scope: document global.
149 SwRect
GetFrame_( const SwRect
&rPortion
) const;
151 SwAnchoredObjList
* InitAnchoredObjList();
153 SwAnchoredObjList
* GetAnchoredObjList() const;
156 Look for the first object which overlaps with the rectangle.
157 Iterates over the anchored object list mpAnchoredObjList.
159 bool ForEach( const SwRect
&rRect
, SwRect
* pRect
, bool bAvoid
) const;
162 \li There is less than 2cm space on both sides for the text:
163 no surround (css::text::WrapTextMode_NONE)
165 \li There is more than 2cm space on only one side:
166 surround on that side (css::text::WrapTextMode_LEFT or css::text::WrapTextMode_RIGHT)
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 (css::text::WrapTextMode_LEFT or css::text::WrapTextMode_RIGHT)
172 \li There is more than 2cm space on both sides and the object
173 width is less than 1.5cm: both sides surround (css::text::WrapTextMode_PARALLEL)
175 css::text::WrapTextMode
GetSurroundForTextWrap( const SwAnchoredObject
* pAnchoredObj
) const;
178 The right margin is the right margin or it is determined by the
179 next object standing on the line.
181 void CalcRightMargin( SwRect
&rFly
,
182 SwAnchoredObjList::size_type nPos
,
183 const SwRect
&rLine
) const;
186 The left margin is the left margin of the current PrintArea or
187 it is determined by the last FlyFrame, which stands on the line.
189 void CalcLeftMargin( SwRect
&rFly
,
190 SwAnchoredObjList::size_type nPos
,
191 const SwRect
&rLine
) const;
194 \return the position in sorted array
196 SwAnchoredObjList::size_type
GetPos( const SwAnchoredObject
* pAnchoredObj
) const;
198 bool GetTop( const SwAnchoredObject
* _pAnchoredObj
,
199 const bool bInFootnote
,
200 const bool bInFooterOrHeader
);
202 SwTwips
CalcMinBottom() const;
204 const SwTextFrame
* GetMaster_();
209 SwTextFly( const SwTextFrame
*pFrame
);
210 SwTextFly( const SwTextFly
& rTextFly
);
213 void CtorInitTextFly( const SwTextFrame
*pFrame
);
217 SwRect
GetFrame( const SwRect
&rPortion
) const;
221 If there is no flying object frame standing in rRect (usually the current row),
222 then we are turning ourself off.
224 \param rRect is global to the document!
226 bool Relax( const SwRect
&rRect
);
229 SwTwips
GetMinBottom() const;
230 const SwTextFrame
* GetMaster() const;
232 // This temporary variable needs to be manipulated in const methods
233 tools::Long
GetNextTop() const;
234 void SetNextTop( tools::Long nNew
) const;
237 Determines the demanded rectangle for an anchored object,
238 considering its surround for text wrapping.
240 \param pAnchoredObj the object for which to get the bounds
241 \param rLine the bounds of the line to format
243 \return the flying object bounds
245 SwRect
AnchoredObjToRect( const SwAnchoredObject
* pAnchoredObj
,
246 const SwRect
& rRect
) const;
249 This method is called by DrawText().
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 FlyFrames that are opaque and above the current frame will
256 DrawText() takes over the on optimization!
258 void DrawTextOpaque( SwDrawTextInfo
&rInf
);
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
265 Ensure that the overlapping frames (except the transparent frames)
268 void DrawFlyRect( OutputDevice
* pOut
, const SwRect
&rRect
);
271 Used to switch off the SwTextFly when there is no overlapping object (Relax).
273 \param[in] the line area
274 \return whether the line will be overlapped by a frame
276 bool IsAnyFrame( const SwRect
&rLine
) const;
279 Same as IsAnyFrame(const SwRect&), but uses the current frame print
282 bool IsAnyFrame() const;
285 true when a frame or DrawObj must be taken in account. The optimizations
286 like Paint/FormatEmpty for empty sentences or the virtual OutputDevice can
287 be used only when false is returned.
290 The rectangle can be empty, the current frame is then used. The value is
291 global to the document.
293 bool IsAnyObj( const SwRect
& rRect
) const;
295 void SetIgnoreCurrentFrame( bool bNew
);
296 void SetIgnoreContour( bool bNew
);
298 void SetIgnoreObjsInHeaderFooter( const bool bNew
);
301 inline SwAnchoredObjList
* SwTextFly::GetAnchoredObjList() const
303 return mpAnchoredObjList
304 ? mpAnchoredObjList
.get()
305 : const_cast<SwTextFly
*>(this)->InitAnchoredObjList();
308 inline void SwTextFly::SetTopRule()
313 inline bool SwTextFly::IsOn() const
318 inline bool SwTextFly::Relax( const SwRect
&rRect
)
322 m_bOn
= IsAnyFrame( rRect
);
327 inline bool SwTextFly::Relax()
331 m_bOn
= IsAnyFrame();
336 inline SwTwips
SwTextFly::GetMinBottom() const
338 return mpAnchoredObjList
? m_nMinBottom
: CalcMinBottom();
341 inline const SwTextFrame
* SwTextFly::GetMaster() const
343 return m_pMaster
? m_pMaster
: const_cast<SwTextFly
*>(this)->GetMaster_();
346 inline tools::Long
SwTextFly::GetNextTop() const
351 inline void SwTextFly::SetNextTop( tools::Long nNew
) const
353 const_cast<SwTextFly
*>(this)->m_nNextTop
= nNew
;
356 inline SwRect
SwTextFly::GetFrame( const SwRect
&rRect
) const
358 return m_bOn
? GetFrame_( rRect
) : SwRect();
361 inline void SwTextFly::SetIgnoreCurrentFrame( bool bNew
)
363 mbIgnoreCurrentFrame
= bNew
;
366 inline void SwTextFly::SetIgnoreContour( bool bNew
)
368 mbIgnoreContour
= bNew
;
371 inline void SwTextFly::SetIgnoreObjsInHeaderFooter( const bool bNew
)
373 mbIgnoreObjsInHeaderFooter
= bNew
;
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */