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 .
21 #include <scriptinfo.hxx>
24 #include <swtypes.hxx>
26 #include <svx/ctredlin.hxx>
31 class SwMarginPortion
;
33 class SwTextFormatter
;
38 TextFrameIndex m_nStart
;
39 TextFrameIndex m_nLen
;
42 SwCharRange(TextFrameIndex
const nInitStart
= TextFrameIndex(0),
43 TextFrameIndex
const nInitLen
= TextFrameIndex(0))
44 : m_nStart( nInitStart
), m_nLen(nInitLen
) {}
45 TextFrameIndex
& Start() { return m_nStart
; }
46 TextFrameIndex
const& Start() const { return m_nStart
; }
47 void LeftMove(TextFrameIndex
const nNew
)
48 { if ( nNew
< m_nStart
) { m_nLen
+= m_nStart
-nNew
; m_nStart
= nNew
; } }
49 TextFrameIndex
& Len() { return m_nLen
; }
50 TextFrameIndex
const& Len() const { return m_nLen
; }
51 bool operator<(const SwCharRange
&rRange
) const
52 { return m_nStart
< rRange
.m_nStart
; }
53 bool operator>(const SwCharRange
&rRange
) const
54 { return m_nStart
+ m_nLen
> rRange
.m_nStart
+ rRange
.m_nLen
; }
55 bool operator!=(const SwCharRange
&rRange
) const
56 { return *this < rRange
|| *this > rRange
; }
57 SwCharRange
&operator+=(const SwCharRange
&rRange
);
60 // SwRepaint is a document-global SwRect
61 // nOfst states from where in the first line should be painted
62 // nRightOfst gives the right margin
63 class SwRepaint
: public SwRect
66 SwTwips m_nRightOffset
;
68 SwRepaint() : SwRect(), m_nOffset( 0 ), m_nRightOffset( 0 ) {}
70 SwTwips
GetOffset() const { return m_nOffset
; }
71 void SetOffset( const SwTwips nNew
) { m_nOffset
= nNew
; }
72 SwTwips
GetRightOfst() const { return m_nRightOffset
; }
73 void SetRightOfst( const SwTwips nNew
) { m_nRightOffset
= nNew
; }
76 /// Collection of SwLinePortion instances, representing one line of text.
77 /// Typically owned by an SwParaPortion.
78 class SAL_DLLPUBLIC_RTTI SwLineLayout
: public SwTextPortion
81 SwLineLayout
*m_pNext
; // The next Line
82 std::unique_ptr
<std::vector
<tools::Long
>> m_pLLSpaceAdd
; // Used for justified alignment
83 std::unique_ptr
<std::deque
<sal_uInt16
>> m_pKanaComp
; // Used for Kana compression
84 SwTwips m_nRealHeight
; // The height resulting from line spacing and register
85 SwTwips m_nTextHeight
; // The max height of all non-FlyCnt portions in this Line
86 SwTwips m_nExtraAscent
= 0;
87 SwTwips m_nExtraDescent
= 0;
88 bool m_bFormatAdj
: 1;
96 bool m_bClipping
: 1; // Clipping needed for exact line height
97 bool m_bContent
: 1; // Text for line numbering
98 bool m_bRedline
: 1; // The Redlining
99 bool m_bRedlineEnd
: 1; // Redlining for paragraph mark: tracked change at the end
100 bool m_bForcedLeftMargin
: 1; // Left adjustment moved by the Fly
101 bool m_bHanging
: 1; // Contains a hanging portion in the margin
103 enum RedlineType m_eRedlineEnd
; // redline type of pilcrow and line break symbols
105 OUString m_sRedlineText
; // shortened text of (first) tracked deletion shown in margin
107 SwTwips
GetHangingMargin_() const;
112 using SwPosSize::Height
;
113 virtual void Height(const SwTwips nNew
, const bool bText
= true) override
;
115 // From SwLinePortion
116 virtual SwLinePortion
*Insert( SwLinePortion
*pPortion
) override
;
117 virtual SwLinePortion
*Append( SwLinePortion
*pPortion
) override
;
118 SW_DLLPUBLIC SwLinePortion
*GetFirstPortion() const;
122 void SetFormatAdj( const bool bNew
) { m_bFormatAdj
= bNew
; }
123 bool IsFormatAdj() const { return m_bFormatAdj
; }
124 void SetEndHyph( const bool bNew
) { m_bEndHyph
= bNew
; }
125 bool IsEndHyph() const { return m_bEndHyph
; }
126 void SetMidHyph( const bool bNew
) { m_bMidHyph
= bNew
; }
127 bool IsMidHyph() const { return m_bMidHyph
; }
128 void SetLastHyph( const bool bNew
) { m_bLastHyph
= bNew
; }
129 bool IsLastHyph() const { return m_bLastHyph
; }
130 void SetFly( const bool bNew
) { m_bFly
= bNew
; }
131 bool IsFly() const { return m_bFly
; }
132 void SetRest( const bool bNew
) { m_bRest
= bNew
; }
133 bool IsRest() const { return m_bRest
; }
134 void SetBlinking( const bool bNew
) { m_bBlinking
= bNew
; }
135 bool IsBlinking() const { return m_bBlinking
; }
136 void SetContent( const bool bNew
) { m_bContent
= bNew
; }
137 bool HasContent() const { return m_bContent
; }
138 void SetRedline( const bool bNew
) { m_bRedline
= bNew
; }
139 bool HasRedline() const { return m_bRedline
; }
140 void SetRedlineEnd( const bool bNew
) { m_bRedlineEnd
= bNew
; }
141 bool HasRedlineEnd() const { return m_bRedlineEnd
; }
142 void SetRedlineEndType( const enum RedlineType eNew
) { m_eRedlineEnd
= eNew
; }
143 RedlineType
GetRedlineEndType() const { return m_eRedlineEnd
; }
144 void SetRedlineText ( const OUString
& sText
) { m_sRedlineText
= sText
; }
145 const OUString
* GetRedlineText() const { return &m_sRedlineText
; }
146 void SetForcedLeftMargin() { m_bForcedLeftMargin
= true; }
147 bool HasForcedLeftMargin() const { return m_bForcedLeftMargin
; }
148 void SetHanging( const bool bNew
) { m_bHanging
= bNew
; }
149 bool IsHanging() const { return m_bHanging
; }
151 // Respecting empty dummy lines
152 void SetDummy( const bool bNew
) { m_bDummy
= bNew
; }
153 bool IsDummy() const { return m_bDummy
; }
155 void SetClipping( const bool bNew
) { m_bClipping
= bNew
; }
156 bool IsClipping() const { return m_bClipping
; }
159 virtual ~SwLineLayout() override
;
161 SwLineLayout
*GetNext() { return m_pNext
; }
162 const SwLineLayout
*GetNext() const { return m_pNext
; }
163 void SetNext( SwLineLayout
*pNew
) { m_pNext
= pNew
; }
165 void Init( SwLinePortion
*pNextPortion
= nullptr);
167 // Collects the data for the line
168 void CalcLine( SwTextFormatter
&rLine
, SwTextFormatInfo
&rInf
);
170 void SetRealHeight( SwTwips nNew
) { m_nRealHeight
= nNew
; }
171 SwTwips
GetRealHeight() const { return m_nRealHeight
; }
173 SwTwips
GetTextHeight() const { return m_nTextHeight
; }
175 void SetExtraAscent(SwTwips nNew
) { m_nExtraAscent
= nNew
; }
176 SwTwips
GetExtraAscent() const { return m_nExtraAscent
; }
178 void SetExtraDescent(SwTwips nNew
) { m_nExtraDescent
= nNew
; }
179 SwTwips
GetExtraDescent() const { return m_nExtraDescent
; }
181 // Creates the glue chain for short lines
182 SwMarginPortion
*CalcLeftMargin();
184 SwTwips
GetHangingMargin() const
185 { return GetHangingMargin_(); }
187 // For special treatment for empty lines
188 virtual bool Format( SwTextFormatInfo
&rInf
) override
;
190 // Stuff for justified alignment
191 bool IsSpaceAdd() const { return m_pLLSpaceAdd
!= nullptr; }
192 void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
193 void CreateSpaceAdd( const tools::Long nInit
= 0 );
194 void FinishSpaceAdd() { m_pLLSpaceAdd
.reset(); }
195 sal_uInt16
GetLLSpaceAddCount() const { return sal::static_int_cast
< sal_uInt16
>(m_pLLSpaceAdd
->size()); }
196 void SetLLSpaceAdd( tools::Long nNew
, sal_uInt16 nIdx
)
198 if ( nIdx
== GetLLSpaceAddCount() )
199 m_pLLSpaceAdd
->push_back( nNew
);
201 (*m_pLLSpaceAdd
)[ nIdx
] = nNew
;
203 tools::Long
GetLLSpaceAdd( sal_uInt16 nIdx
) { return (*m_pLLSpaceAdd
)[ nIdx
]; }
204 void RemoveFirstLLSpaceAdd() { m_pLLSpaceAdd
->erase( m_pLLSpaceAdd
->begin() ); }
205 std::vector
<tools::Long
>* GetpLLSpaceAdd() const { return m_pLLSpaceAdd
.get(); }
207 // Stuff for Kana compression
208 void SetKanaComp( std::unique_ptr
<std::deque
<sal_uInt16
>> pNew
){ m_pKanaComp
= std::move(pNew
); }
209 void FinishKanaComp() { m_pKanaComp
.reset(); }
210 std::deque
<sal_uInt16
>* GetpKanaComp() const { return m_pKanaComp
.get(); }
211 std::deque
<sal_uInt16
>& GetKanaComp() { return *m_pKanaComp
; }
213 /** determine ascent and descent for positioning of as-character anchored
216 OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
217 Method calculates maximum ascents and descents of the line layout.
218 One value considering as-character anchored objects, one without these
220 Portions for other anchored objects aren't considered.
221 OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
222 to control, if the fly content portions and line portion are considered.
225 output parameter - maximum ascent without as-character anchored objects
228 output parameter - maximum descent without as-character anchored objects
231 output parameter - maximum ascent with as-character anchored objects
234 output parameter - maximum descent with as-character anchored objects
236 @param _pDontConsiderPortion
237 input parameter - portion, which isn't considered for calculating
238 <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
239 as-character anchored object or it isn't as high as the line.
241 @param _bNoFlyCntPorAndLinePor
242 optional input parameter - boolean, indicating that fly content portions
243 and the line portion are considered or not.
245 void MaxAscentDescent( SwTwips
& _orAscent
,
247 SwTwips
& _orObjAscent
,
248 SwTwips
& _orObjDescent
,
249 const SwLinePortion
* _pDontConsiderPortion
= nullptr,
250 const bool _bNoFlyCntPorAndLinePor
= false ) const;
252 void dumpAsXml(xmlTextWriterPtr pWriter
, const OUString
& rText
,
253 TextFrameIndex
& nOffset
) const override
;
256 /// Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
257 /// Typically owned by an SwTextFrame.
258 class SwParaPortion
: public SwLineLayout
260 // Area that needs repainting
261 SwRepaint m_aRepaint
;
262 // Area that needs reformatting
263 SwCharRange m_aReformat
;
264 SwScriptInfo m_aScriptInfo
;
267 tools::Long m_nDelta
;
269 // If a SwTextFrame is locked, no changes occur to the formatting data (under
270 // pLine) (compare with Orphans)
271 bool m_bFlys
: 1; // Overlapping Flys?
272 bool m_bPrep
: 1; // PREP_*
273 bool m_bPrepWidows
: 1; // PrepareHint::Widows
274 bool m_bPrepAdjust
: 1; // PrepareHint::AdjustSizeWithoutFormatting
275 bool m_bPrepMustFit
: 1; // PrepareHint::MustFit
276 bool m_bFollowField
: 1; // We have a bit of field left for the Follow
278 bool m_bFixLineHeight
: 1; // Fixed line height
279 bool m_bFootnoteNum
: 1; // is the frame that may contain a footnotenumberportion
280 bool m_bMargin
: 1; // contains a hanging punctuation in the margin
284 virtual ~SwParaPortion() override
;
286 // Resets all formatting information (except for bFlys)
287 inline void FormatReset();
290 inline void ResetPreps();
293 SwRepaint
& GetRepaint() { return m_aRepaint
; }
294 const SwRepaint
& GetRepaint() const { return m_aRepaint
; }
295 SwCharRange
& GetReformat() { return m_aReformat
; }
296 const SwCharRange
& GetReformat() const { return m_aReformat
; }
297 void SetDelta(tools::Long nDelta
) { m_nDelta
= nDelta
; }
298 tools::Long
GetDelta() const { return m_nDelta
; }
299 SwScriptInfo
& GetScriptInfo() { return m_aScriptInfo
; }
300 const SwScriptInfo
& GetScriptInfo() const { return m_aScriptInfo
; }
302 // For SwTextFrame::Format: returns the paragraph's current length
303 TextFrameIndex
GetParLen() const;
306 bool UpdateQuoVadis( std::u16string_view rQuo
);
309 void SetFly() { m_bFlys
= true; }
310 bool HasFly() const { return m_bFlys
; }
313 void SetPrep() { m_bPrep
= true; }
314 bool IsPrep() const { return m_bPrep
; }
315 void SetPrepWidows() { m_bPrepWidows
= true; }
316 bool IsPrepWidows() const { return m_bPrepWidows
; }
317 void SetPrepMustFit( const bool bNew
) { m_bPrepMustFit
= bNew
; }
318 bool IsPrepMustFit() const { return m_bPrepMustFit
; }
319 void SetPrepAdjust() { m_bPrepAdjust
= true; }
320 bool IsPrepAdjust() const { return m_bPrepAdjust
; }
321 void SetFollowField( const bool bNew
) { m_bFollowField
= bNew
; }
322 bool IsFollowField() const { return m_bFollowField
; }
323 void SetFixLineHeight() { m_bFixLineHeight
= true; }
324 bool IsFixLineHeight() const { return m_bFixLineHeight
; }
326 void SetFootnoteNum( const bool bNew
) { m_bFootnoteNum
= bNew
; }
327 bool IsFootnoteNum() const { return m_bFootnoteNum
; }
328 void SetMargin( const bool bNew
= true ) { m_bMargin
= bNew
; }
329 bool IsMargin() const { return m_bMargin
; }
330 enum FootnoteOrNot
{ OnlyNumbering
, FootnoteToo
};
331 bool HasNumberingPortion(FootnoteOrNot
) const;
332 bool HasContentPortions() const;
334 // Set nErgo in the QuoVadisPortion
335 void SetErgoSumNum( const OUString
&rErgo
);
337 const SwDropPortion
*FindDropPortion() const;
339 void dumpAsXml(xmlTextWriterPtr pWriter
, const OUString
& rText
,
340 TextFrameIndex
& nOffset
) const override
;
343 inline void SwParaPortion::ResetPreps()
345 m_bPrep
= m_bPrepWidows
= m_bPrepAdjust
= m_bPrepMustFit
= false;
348 inline void SwParaPortion::FormatReset()
351 m_aReformat
= SwCharRange(TextFrameIndex(0), TextFrameIndex(COMPLETE_STRING
));
352 // bFlys needs to be retained in SwTextFrame::Format_() so that empty
353 // paragraphs that needed to avoid Frames with no flow, reformat
354 // when the Frame disappears from the Area
357 m_bFollowField
= m_bFixLineHeight
= m_bMargin
= false;
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */