android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / text / itrform2.hxx
blob2d71fad34cd5ea872e544cab5a7c8f3de774351f
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 "itrpaint.hxx"
23 class SwFlyCntPortion;
24 class SwDropPortion;
25 class SwFormatDrop;
26 class SwTextAttr;
27 class SwNumberPortion;
28 class SwErgoSumPortion;
29 class SwExpandPortion;
30 class SwMultiPortion;
31 class SwFootnotePortion;
33 class SwTextFormatter : public SwTextPainter
35 const SwFormatDrop *m_pDropFormat;
36 SwMultiPortion* m_pMulti; // during formatting a multi-portion
37 sal_uInt8 m_nContentEndHyph; // Counts consecutive hyphens at the line end
38 sal_uInt8 m_nContentMidHyph; // Counts consecutive hyphens before flies
39 TextFrameIndex m_nLeftScanIdx; // for increasing performance during
40 TextFrameIndex m_nRightScanIdx; // scanning for portion ends
41 bool m_bOnceMore : 1; // Another round?
42 bool m_bFlyInContentBase : 1; // Base reference that sets a character-bound frame
43 bool m_bTruncLines : 1; // Flag for extending the repaint rect, if needed
44 bool m_bUnclipped : 1; // Flag whether repaint is larger than the fixed line height
45 std::unique_ptr<sw::MergedAttrIterByEnd> m_pByEndIter; // HACK for TryNewNoLengthPortion
46 SwLinePortion* m_pFirstOfBorderMerge; // The first text portion of a joined border (during portion building)
48 SwLinePortion *NewPortion(SwTextFormatInfo &rInf, ::std::optional<TextFrameIndex>);
49 SwTextPortion *NewTextPortion( SwTextFormatInfo &rInf );
50 SwLinePortion *NewExtraPortion( SwTextFormatInfo &rInf );
51 SwTabPortion *NewTabPortion( SwTextFormatInfo &rInf, bool bAuto ) const;
52 SwNumberPortion *NewNumberPortion( SwTextFormatInfo &rInf ) const;
53 SwDropPortion *NewDropPortion( SwTextFormatInfo &rInf );
54 SwNumberPortion *NewFootnoteNumPortion( SwTextFormatInfo const &rInf ) const;
55 SwErgoSumPortion *NewErgoSumPortion( SwTextFormatInfo const &rInf ) const;
56 SwExpandPortion *NewFieldPortion( SwTextFormatInfo &rInf,
57 const SwTextAttr *pHt ) const;
58 SwFootnotePortion *NewFootnotePortion( SwTextFormatInfo &rInf, SwTextAttr *pHt );
60 /**
61 Sets a new portion for an object anchored as character
63 SwFlyCntPortion *NewFlyCntPortion( SwTextFormatInfo &rInf,
64 SwTextAttr *pHt ) const;
65 SwLinePortion *WhichFirstPortion( SwTextFormatInfo &rInf );
66 SwTextPortion *WhichTextPor( SwTextFormatInfo &rInf ) const;
67 SwExpandPortion * TryNewNoLengthPortion( SwTextFormatInfo const & rInfo );
69 // The center piece of formatting
70 void BuildPortions( SwTextFormatInfo &rInf );
72 bool BuildMultiPortion( SwTextFormatInfo &rInf, SwMultiPortion& rMulti );
74 /**
75 Calculation of the emulated right side.
77 Determines the next object, that reaches into the rest of the line and
78 constructs the appropriate FlyPortion.
79 SwTextFly::GetFrame(const SwRect&, bool) will be needed for this.
81 The right edge can be shortened by flys
83 void CalcFlyWidth( SwTextFormatInfo &rInf );
85 // Is overloaded by SwTextFormatter because of UpdatePos
86 void CalcAdjustLine( SwLineLayout *pCurr );
88 // considers line spacing attributes
89 void CalcRealHeight( bool bNewLine = false );
91 // Transfers the data to rInf
92 void FeedInf( SwTextFormatInfo &rInf ) const;
94 // Treats underflow situations
95 SwLinePortion *Underflow( SwTextFormatInfo &rInf );
97 // Calculates the ascent and the height from the fontmetric
98 void CalcAscent( SwTextFormatInfo &rInf, SwLinePortion *pPor );
100 // determines, if an optimized repaint rectangle is allowed
101 bool AllowRepaintOpt() const;
103 // Is called by FormatLine
104 void FormatReset( SwTextFormatInfo &rInf );
107 The position of the portions changes with the adjustment.
109 This method updates the reference point of the anchored as character objects,
110 for example after adjustment change (right alignment, justified, etc.)
111 Mainly to correct the X position.
113 void UpdatePos(SwLineLayout *pCurr, Point aStart, TextFrameIndex nStartIdx,
114 bool bAlways = false ) const;
117 Set all anchored as character objects to the passed BaseLine
118 (in Y direction).
120 void AlignFlyInCntBase( tools::Long nBaseLine ) const;
123 This is called after the real height of the line has been calculated
124 Therefore it is possible, that more flys from below intersect with the
125 line, or that flys from above do not intersect with the line anymore.
126 We check this and return true, meaning that the line has to be
127 formatted again.
129 bool ChkFlyUnderflow( SwTextFormatInfo &rInf ) const;
131 // Insert portion
132 void InsertPortion( SwTextFormatInfo &rInf, SwLinePortion *pPor );
134 // Guess height for the DropPortion
135 void GuessDropHeight( const sal_uInt16 nLines );
137 public:
138 // Calculate the height for the DropPortion
139 void CalcDropHeight( const sal_uInt16 nLines );
141 // Calculates the paragraphs bottom, takes anchored objects within it into
142 // account which have a wrap setting of "wrap at 1st paragraph"
143 SwTwips CalcBottomLine() const;
145 // Takes character-bound objects into account when calculating the
146 // repaint rect in lines with fixed line height
147 void CalcUnclipped( SwTwips& rTop, SwTwips& rBottom );
149 // Amongst others for DropCaps
150 bool CalcOnceMore();
152 void CtorInitTextFormatter( SwTextFrame *pFrame, SwTextFormatInfo *pInf );
153 SwTextFormatter(SwTextFrame *pTextFrame, SwTextFormatInfo *pTextFormatInf)
154 : SwTextPainter(pTextFrame->GetTextNodeFirst())
155 , m_bUnclipped(false)
157 CtorInitTextFormatter( pTextFrame, pTextFormatInf );
159 virtual ~SwTextFormatter() override;
161 TextFrameIndex FormatLine(TextFrameIndex nStart);
163 void RecalcRealHeight();
165 // We format a line for interactive hyphenation
166 bool Hyphenate(SwInterHyphInfoTextFrame & rInf);
168 // A special method for QuoVadis texts:
169 // nErgo is the page number of the ErgoSum Footnote
170 // At 0 it's still unclear
171 TextFrameIndex FormatQuoVadis(TextFrameIndex nStart);
173 // The emergency break: Cancel formatting, discard line
174 bool IsStop() const { return GetInfo().IsStop(); }
176 // The counterpart: Continue formatting at all costs
177 bool IsNewLine() const { return GetInfo().IsNewLine(); }
179 // FormatQuick(); Refresh formatting information
180 bool IsQuick() const { return GetInfo().IsQuick(); }
182 // Create a SwLineLayout if needed, which avoids Footnote/Fly to oscillate
183 void MakeDummyLine();
185 // SwTextIter functionality
186 void Insert( SwLineLayout *pLine );
188 // The remaining height to the page border
189 sal_uInt16 GetFrameRstHeight() const;
191 // How wide would you be without any bounds (Flys etc.)?
192 SwTwips CalcFitToContent_( );
194 SwLinePortion* MakeRestPortion(const SwLineLayout* pLine, TextFrameIndex nPos);
196 const SwFormatDrop *GetDropFormat() const { return m_pDropFormat; }
197 void ClearDropFormat() { m_pDropFormat = nullptr; }
199 SwMultiPortion *GetMulti() const { return m_pMulti; }
201 bool IsOnceMore() const { return m_bOnceMore; }
202 void SetOnceMore( bool bNew ) { m_bOnceMore = bNew; }
204 bool HasTruncLines() const { return m_bTruncLines; }
205 void SetTruncLines( bool bNew ) { m_bTruncLines = bNew; }
207 bool IsUnclipped() const { return m_bUnclipped; }
208 void SetUnclipped( bool bNew ) { m_bUnclipped = bNew; }
210 bool IsFlyInCntBase() const { return m_bFlyInContentBase; }
211 void SetFlyInCntBase( bool bNew = true ) { m_bFlyInContentBase = bNew; }
213 SwTextFormatInfo &GetInfo()
214 { return static_cast<SwTextFormatInfo&>(SwTextIter::GetInfo()); }
215 const SwTextFormatInfo &GetInfo() const
216 { return static_cast<const SwTextFormatInfo&>(SwTextIter::GetInfo()); }
218 void InitCntHyph() { CntHyphens( m_nContentEndHyph, m_nContentMidHyph ); }
219 const sal_uInt8 &CntEndHyph() const { return m_nContentEndHyph; }
220 const sal_uInt8 &CntMidHyph() const { return m_nContentMidHyph; }
221 sal_uInt8 &CntEndHyph() { return m_nContentEndHyph; }
222 sal_uInt8 &CntMidHyph() { return m_nContentMidHyph; }
225 * Merge border of the drop portion with modifying the font of
226 * the portions' part. Removing left or right border.
227 * @param rPortion drop portion for merge
229 static void MergeCharacterBorder( SwDropPortion const & rPortion );
232 * Merge border of the line portion with setting the portion's
233 * m_bJoinBorderWidthNext and m_bJoinBorderWidthPrev members and
234 * changing the size (width, height and ascent) of the portion
235 * to get a merged border.
236 * @param rPortion portion for merge
237 * @param pPrev portion immediately before rPortion
238 * @param rInf contain information
240 void MergeCharacterBorder( SwLinePortion& rPortion, SwLinePortion const *pPrev, SwTextFormatInfo& rInf );
242 bool ClearIfIsFirstOfBorderMerge(SwLinePortion const *pPortion);
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */