android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / text / porlay.hxx
blob3b07b7016118a5f0abf33c5dacaf15254faf85d9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
21 #include <scriptinfo.hxx>
23 #include <swrect.hxx>
24 #include <swtypes.hxx>
25 #include "portxt.hxx"
26 #include <svx/ctredlin.hxx>
28 #include <vector>
29 #include <deque>
31 class SwMarginPortion;
32 class SwDropPortion;
33 class SwTextFormatter;
35 class SwCharRange
37 private:
38 TextFrameIndex m_nStart;
39 TextFrameIndex m_nLen;
41 public:
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
65 SwTwips m_nOffset;
66 SwTwips m_nRightOffset;
67 public:
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 SW_DLLPUBLIC SwLineLayout : public SwTextPortion
80 private:
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 bool m_bFormatAdj : 1;
87 bool m_bDummy : 1;
88 bool m_bEndHyph : 1;
89 bool m_bMidHyph : 1;
90 bool m_bFly : 1;
91 bool m_bRest : 1;
92 bool m_bBlinking : 1;
93 bool m_bClipping : 1; // Clipping needed for exact line height
94 bool m_bContent : 1; // Text for line numbering
95 bool m_bRedline : 1; // The Redlining
96 bool m_bRedlineEnd: 1; // Redlining for paragraph mark: tracked change at the end
97 bool m_bForcedLeftMargin : 1; // Left adjustment moved by the Fly
98 bool m_bHanging : 1; // Contains a hanging portion in the margin
99 bool m_bUnderscore : 1;
101 enum RedlineType m_eRedlineEnd; // redline type of pilcrow and line break symbols
103 OUString m_sRedlineText; // shortened text of (first) tracked deletion shown in margin
105 SwTwips GetHangingMargin_() const;
107 void DeleteNext();
108 public:
109 // From SwPosSize
110 using SwPosSize::Height;
111 virtual void Height(const SwTwips nNew, const bool bText = true) override;
113 // From SwLinePortion
114 virtual SwLinePortion *Insert( SwLinePortion *pPortion ) override;
115 virtual SwLinePortion *Append( SwLinePortion *pPortion ) override;
116 SwLinePortion *GetFirstPortion() const;
118 // Flags
119 void ResetFlags();
120 void SetFormatAdj( const bool bNew ) { m_bFormatAdj = bNew; }
121 bool IsFormatAdj() const { return m_bFormatAdj; }
122 void SetEndHyph( const bool bNew ) { m_bEndHyph = bNew; }
123 bool IsEndHyph() const { return m_bEndHyph; }
124 void SetMidHyph( const bool bNew ) { m_bMidHyph = bNew; }
125 bool IsMidHyph() const { return m_bMidHyph; }
126 void SetFly( const bool bNew ) { m_bFly = bNew; }
127 bool IsFly() const { return m_bFly; }
128 void SetRest( const bool bNew ) { m_bRest = bNew; }
129 bool IsRest() const { return m_bRest; }
130 void SetBlinking( const bool bNew ) { m_bBlinking = bNew; }
131 bool IsBlinking() const { return m_bBlinking; }
132 void SetContent( const bool bNew ) { m_bContent = bNew; }
133 bool HasContent() const { return m_bContent; }
134 void SetRedline( const bool bNew ) { m_bRedline = bNew; }
135 bool HasRedline() const { return m_bRedline; }
136 void SetRedlineEnd( const bool bNew ) { m_bRedlineEnd = bNew; }
137 bool HasRedlineEnd() const { return m_bRedlineEnd; }
138 void SetRedlineEndType( const enum RedlineType eNew ) { m_eRedlineEnd = eNew; }
139 RedlineType GetRedlineEndType() const { return m_eRedlineEnd; }
140 void SetRedlineText ( const OUString& sText ) { m_sRedlineText = sText; }
141 const OUString* GetRedlineText() const { return &m_sRedlineText; }
142 void SetForcedLeftMargin() { m_bForcedLeftMargin = true; }
143 bool HasForcedLeftMargin() const { return m_bForcedLeftMargin; }
144 void SetHanging( const bool bNew ) { m_bHanging = bNew; }
145 bool IsHanging() const { return m_bHanging; }
146 void SetUnderscore( const bool bNew ) { m_bUnderscore = bNew; }
147 bool HasUnderscore() const { return m_bUnderscore; }
149 // Respecting empty dummy lines
150 void SetDummy( const bool bNew ) { m_bDummy = bNew; }
151 bool IsDummy() const { return m_bDummy; }
153 void SetClipping( const bool bNew ) { m_bClipping = bNew; }
154 bool IsClipping() const { return m_bClipping; }
156 SwLineLayout();
157 virtual ~SwLineLayout() override;
159 SwLineLayout *GetNext() { return m_pNext; }
160 const SwLineLayout *GetNext() const { return m_pNext; }
161 void SetNext( SwLineLayout *pNew ) { m_pNext = pNew; }
163 void Init( SwLinePortion *pNextPortion = nullptr);
165 // Collects the data for the line
166 void CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf );
168 void SetRealHeight( SwTwips nNew ) { m_nRealHeight = nNew; }
169 SwTwips GetRealHeight() const { return m_nRealHeight; }
171 SwTwips GetTextHeight() const { return m_nTextHeight; }
173 // Creates the glue chain for short lines
174 SwMarginPortion *CalcLeftMargin();
176 SwTwips GetHangingMargin() const
177 { return GetHangingMargin_(); }
179 // For special treatment for empty lines
180 virtual bool Format( SwTextFormatInfo &rInf ) override;
182 // Stuff for justified alignment
183 bool IsSpaceAdd() const { return m_pLLSpaceAdd != nullptr; }
184 void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
185 void CreateSpaceAdd( const tools::Long nInit = 0 );
186 void FinishSpaceAdd() { m_pLLSpaceAdd.reset(); }
187 sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(m_pLLSpaceAdd->size()); }
188 void SetLLSpaceAdd( tools::Long nNew, sal_uInt16 nIdx )
190 if ( nIdx == GetLLSpaceAddCount() )
191 m_pLLSpaceAdd->push_back( nNew );
192 else
193 (*m_pLLSpaceAdd)[ nIdx ] = nNew;
195 tools::Long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*m_pLLSpaceAdd)[ nIdx ]; }
196 void RemoveFirstLLSpaceAdd() { m_pLLSpaceAdd->erase( m_pLLSpaceAdd->begin() ); }
197 std::vector<tools::Long>* GetpLLSpaceAdd() const { return m_pLLSpaceAdd.get(); }
199 // Stuff for Kana compression
200 void SetKanaComp( std::unique_ptr<std::deque<sal_uInt16>> pNew ){ m_pKanaComp = std::move(pNew); }
201 void FinishKanaComp() { m_pKanaComp.reset(); }
202 std::deque<sal_uInt16>* GetpKanaComp() const { return m_pKanaComp.get(); }
203 std::deque<sal_uInt16>& GetKanaComp() { return *m_pKanaComp; }
205 /** determine ascent and descent for positioning of as-character anchored
206 object
208 OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
209 Method calculates maximum ascents and descents of the line layout.
210 One value considering as-character anchored objects, one without these
211 objects.
212 Portions for other anchored objects aren't considered.
213 OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
214 to control, if the fly content portions and line portion are considered.
216 @param _orAscent
217 output parameter - maximum ascent without as-character anchored objects
219 @param _orDescent
220 output parameter - maximum descent without as-character anchored objects
222 @param _orObjAscent
223 output parameter - maximum ascent with as-character anchored objects
225 @param _orObjDescent
226 output parameter - maximum descent with as-character anchored objects
228 @param _pDontConsiderPortion
229 input parameter - portion, which isn't considered for calculating
230 <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
231 as-character anchored object or it isn't as high as the line.
233 @param _bNoFlyCntPorAndLinePor
234 optional input parameter - boolean, indicating that fly content portions
235 and the line portion are considered or not.
237 void MaxAscentDescent( SwTwips& _orAscent,
238 SwTwips& _orDescent,
239 SwTwips& _orObjAscent,
240 SwTwips& _orObjDescent,
241 const SwLinePortion* _pDontConsiderPortion = nullptr,
242 const bool _bNoFlyCntPorAndLinePor = false ) const;
244 void dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
245 TextFrameIndex& nOffset) const override;
248 /// Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
249 /// Typically owned by an SwTextFrame.
250 class SwParaPortion : public SwLineLayout
252 // Area that needs repainting
253 SwRepaint m_aRepaint;
254 // Area that needs reformatting
255 SwCharRange m_aReformat;
256 SwScriptInfo m_aScriptInfo;
258 // Fraction aZoom;
259 tools::Long m_nDelta;
261 // If a SwTextFrame is locked, no changes occur to the formatting data (under
262 // pLine) (compare with Orphans)
263 bool m_bFlys : 1; // Overlapping Flys?
264 bool m_bPrep : 1; // PREP_*
265 bool m_bPrepWidows : 1; // PrepareHint::Widows
266 bool m_bPrepAdjust : 1; // PrepareHint::AdjustSizeWithoutFormatting
267 bool m_bPrepMustFit : 1; // PrepareHint::MustFit
268 bool m_bFollowField : 1; // We have a bit of field left for the Follow
270 bool m_bFixLineHeight : 1; // Fixed line height
271 bool m_bFootnoteNum : 1; // is the frame that may contain a footnotenumberportion
272 bool m_bMargin : 1; // contains a hanging punctuation in the margin
274 public:
275 SwParaPortion();
276 virtual ~SwParaPortion() override;
278 // Resets all formatting information (except for bFlys)
279 inline void FormatReset();
281 // Resets the Flags
282 inline void ResetPreps();
284 // Get/Set methods
285 SwRepaint& GetRepaint() { return m_aRepaint; }
286 const SwRepaint& GetRepaint() const { return m_aRepaint; }
287 SwCharRange& GetReformat() { return m_aReformat; }
288 const SwCharRange& GetReformat() const { return m_aReformat; }
289 void SetDelta(tools::Long nDelta) { m_nDelta = nDelta; }
290 tools::Long GetDelta() const { return m_nDelta; }
291 SwScriptInfo& GetScriptInfo() { return m_aScriptInfo; }
292 const SwScriptInfo& GetScriptInfo() const { return m_aScriptInfo; }
294 // For SwTextFrame::Format: returns the paragraph's current length
295 TextFrameIndex GetParLen() const;
297 // For Prepare()
298 bool UpdateQuoVadis( std::u16string_view rQuo );
300 // Flags
301 void SetFly() { m_bFlys = true; }
302 bool HasFly() const { return m_bFlys; }
304 // Preps
305 void SetPrep() { m_bPrep = true; }
306 bool IsPrep() const { return m_bPrep; }
307 void SetPrepWidows() { m_bPrepWidows = true; }
308 bool IsPrepWidows() const { return m_bPrepWidows; }
309 void SetPrepMustFit( const bool bNew ) { m_bPrepMustFit = bNew; }
310 bool IsPrepMustFit() const { return m_bPrepMustFit; }
311 void SetPrepAdjust() { m_bPrepAdjust = true; }
312 bool IsPrepAdjust() const { return m_bPrepAdjust; }
313 void SetFollowField( const bool bNew ) { m_bFollowField = bNew; }
314 bool IsFollowField() const { return m_bFollowField; }
315 void SetFixLineHeight() { m_bFixLineHeight = true; }
316 bool IsFixLineHeight() const { return m_bFixLineHeight; }
318 void SetFootnoteNum( const bool bNew ) { m_bFootnoteNum = bNew; }
319 bool IsFootnoteNum() const { return m_bFootnoteNum; }
320 void SetMargin( const bool bNew = true ) { m_bMargin = bNew; }
321 bool IsMargin() const { return m_bMargin; }
322 enum FootnoteOrNot { OnlyNumbering, FootnoteToo };
323 bool HasNumberingPortion(FootnoteOrNot) const;
324 bool HasContentPortions() const;
326 // Set nErgo in the QuoVadisPortion
327 void SetErgoSumNum( const OUString &rErgo );
329 const SwDropPortion *FindDropPortion() const;
331 void dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
332 TextFrameIndex& nOffset) const override;
335 inline void SwParaPortion::ResetPreps()
337 m_bPrep = m_bPrepWidows = m_bPrepAdjust = m_bPrepMustFit = false;
340 inline void SwParaPortion::FormatReset()
342 m_nDelta = 0;
343 m_aReformat = SwCharRange(TextFrameIndex(0), TextFrameIndex(COMPLETE_STRING));
344 // bFlys needs to be retained in SwTextFrame::Format_() so that empty
345 // paragraphs that needed to avoid Frames with no flow, reformat
346 // when the Frame disappears from the Area
347 // bFlys = false;
348 ResetPreps();
349 m_bFollowField = m_bFixLineHeight = m_bMargin = false;
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */