LibreOffice Module sw (master)  1
porlay.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #pragma once
20 
21 #include <libxml/xmlwriter.h>
22 
23 #include <scriptinfo.hxx>
24 
25 #include <swrect.hxx>
26 #include <swtypes.hxx>
27 #include "portxt.hxx"
28 #include <svx/ctredlin.hxx>
29 
30 #include <vector>
31 #include <deque>
32 
33 class SwMarginPortion;
34 class SwDropPortion;
35 class SwTextFormatter;
36 
38 {
39 private:
42 
43 public:
44  SwCharRange(TextFrameIndex const nInitStart = TextFrameIndex(0),
45  TextFrameIndex const nInitLen = TextFrameIndex(0))
46  : m_nStart( nInitStart ), m_nLen(nInitLen) {}
47  TextFrameIndex & Start() { return m_nStart; }
48  TextFrameIndex const& Start() const { return m_nStart; }
49  void LeftMove(TextFrameIndex const nNew)
50  { if ( nNew < m_nStart ) { m_nLen += m_nStart-nNew; m_nStart = nNew; } }
51  TextFrameIndex & Len() { return m_nLen; }
52  TextFrameIndex const& Len() const { return m_nLen; }
53  bool operator<(const SwCharRange &rRange) const
54  { return m_nStart < rRange.m_nStart; }
55  bool operator>(const SwCharRange &rRange) const
56  { return m_nStart + m_nLen > rRange.m_nStart + rRange.m_nLen; }
57  bool operator!=(const SwCharRange &rRange) const
58  { return *this < rRange || *this > rRange; }
59  SwCharRange &operator+=(const SwCharRange &rRange);
60 };
61 
62 // SwRepaint is a document-global SwRect
63 // nOfst states from where in the first line should be painted
64 // nRightOfst gives the right margin
65 class SwRepaint : public SwRect
66 {
69 public:
70  SwRepaint() : SwRect(), m_nOffset( 0 ), m_nRightOffset( 0 ) {}
71 
72  SwTwips GetOffset() const { return m_nOffset; }
73  void SetOffset( const SwTwips nNew ) { m_nOffset = nNew; }
74  SwTwips GetRightOfst() const { return m_nRightOffset; }
75  void SetRightOfst( const SwTwips nNew ) { m_nRightOffset = nNew; }
76 };
77 
81 {
82 private:
83  SwLineLayout *m_pNext; // The next Line
84  std::unique_ptr<std::vector<tools::Long>> m_pLLSpaceAdd; // Used for justified alignment
85  std::unique_ptr<std::deque<sal_uInt16>> m_pKanaComp; // Used for Kana compression
86  SwTwips m_nRealHeight; // The height resulting from line spacing and register
87  SwTwips m_nTextHeight; // The max height of all non-FlyCnt portions in this Line
88  bool m_bFormatAdj : 1;
89  bool m_bDummy : 1;
90  bool m_bEndHyph : 1;
91  bool m_bMidHyph : 1;
92  bool m_bFly : 1;
93  bool m_bRest : 1;
94  bool m_bBlinking : 1;
95  bool m_bClipping : 1; // Clipping needed for exact line height
96  bool m_bContent : 1; // Text for line numbering
97  bool m_bRedline : 1; // The Redlining
98  bool m_bRedlineEnd: 1; // Redlining for paragraph mark: tracked change at the end
99  bool m_bForcedLeftMargin : 1; // Left adjustment moved by the Fly
100  bool m_bHanging : 1; // Contains a hanging portion in the margin
101  bool m_bUnderscore : 1;
102 
103  enum RedlineType m_eRedlineEnd; // redline type of pilcrow and line break symbols
104 
105  OUString m_sRedlineText; // shortened text of (first) tracked deletion shown in margin
106 
107  SwTwips GetHangingMargin_() const;
108 
109  void DeleteNext();
110 public:
111  // From SwPosSize
112  using SwPosSize::Height;
113  virtual void Height(const SwTwips nNew, const bool bText = true) override;
114 
115  // From SwLinePortion
116  virtual SwLinePortion *Insert( SwLinePortion *pPortion ) override;
117  virtual SwLinePortion *Append( SwLinePortion *pPortion ) override;
118  SwLinePortion *GetFirstPortion() const;
119 
120  // Flags
121  void ResetFlags();
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 SetFly( const bool bNew ) { m_bFly = bNew; }
129  bool IsFly() const { return m_bFly; }
130  void SetRest( const bool bNew ) { m_bRest = bNew; }
131  bool IsRest() const { return m_bRest; }
132  void SetBlinking( const bool bNew ) { m_bBlinking = bNew; }
133  bool IsBlinking() const { return m_bBlinking; }
134  void SetContent( const bool bNew ) { m_bContent = bNew; }
135  bool HasContent() const { return m_bContent; }
136  void SetRedline( const bool bNew ) { m_bRedline = bNew; }
137  bool HasRedline() const { return m_bRedline; }
138  void SetRedlineEnd( const bool bNew ) { m_bRedlineEnd = bNew; }
139  bool HasRedlineEnd() const { return m_bRedlineEnd; }
140  void SetRedlineEndType( const enum RedlineType eNew ) { m_eRedlineEnd = eNew; }
141  RedlineType GetRedlineEndType() const { return m_eRedlineEnd; }
142  void SetRedlineText ( const OUString& sText ) { m_sRedlineText = sText; }
143  const OUString* GetRedlineText() const { return &m_sRedlineText; }
144  void SetForcedLeftMargin() { m_bForcedLeftMargin = true; }
145  bool HasForcedLeftMargin() const { return m_bForcedLeftMargin; }
146  void SetHanging( const bool bNew ) { m_bHanging = bNew; }
147  bool IsHanging() const { return m_bHanging; }
148  void SetUnderscore( const bool bNew ) { m_bUnderscore = bNew; }
149  bool HasUnderscore() const { return m_bUnderscore; }
150 
151  // Respecting empty dummy lines
152  void SetDummy( const bool bNew ) { m_bDummy = bNew; }
153  bool IsDummy() const { return m_bDummy; }
154 
155  void SetClipping( const bool bNew ) { m_bClipping = bNew; }
156  bool IsClipping() const { return m_bClipping; }
157 
158  SwLineLayout();
159  virtual ~SwLineLayout() override;
160 
161  SwLineLayout *GetNext() { return m_pNext; }
162  const SwLineLayout *GetNext() const { return m_pNext; }
163  void SetNext( SwLineLayout *pNew ) { m_pNext = pNew; }
164 
165  void Init( SwLinePortion *pNextPortion = nullptr);
166 
167  // Collects the data for the line
168  void CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf );
169 
170  void SetRealHeight( SwTwips nNew ) { m_nRealHeight = nNew; }
171  SwTwips GetRealHeight() const { return m_nRealHeight; }
172 
173  SwTwips GetTextHeight() const { return m_nTextHeight; }
174 
175  // Creates the glue chain for short lines
176  SwMarginPortion *CalcLeftMargin();
177 
179  { return GetHangingMargin_(); }
180 
181  // For special treatment for empty lines
182  virtual bool Format( SwTextFormatInfo &rInf ) override;
183 
184  // Stuff for justified alignment
185  bool IsSpaceAdd() const { return m_pLLSpaceAdd != nullptr; }
186  void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
187  void CreateSpaceAdd( const tools::Long nInit = 0 );
188  void FinishSpaceAdd() { m_pLLSpaceAdd.reset(); }
189  sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(m_pLLSpaceAdd->size()); }
190  void SetLLSpaceAdd( tools::Long nNew, sal_uInt16 nIdx )
191  {
192  if ( nIdx == GetLLSpaceAddCount() )
193  m_pLLSpaceAdd->push_back( nNew );
194  else
195  (*m_pLLSpaceAdd)[ nIdx ] = nNew;
196  }
197  tools::Long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*m_pLLSpaceAdd)[ nIdx ]; }
198  void RemoveFirstLLSpaceAdd() { m_pLLSpaceAdd->erase( m_pLLSpaceAdd->begin() ); }
199  std::vector<tools::Long>* GetpLLSpaceAdd() const { return m_pLLSpaceAdd.get(); }
200 
201  // Stuff for Kana compression
202  void SetKanaComp( std::unique_ptr<std::deque<sal_uInt16>> pNew ){ m_pKanaComp = std::move(pNew); }
203  void FinishKanaComp() { m_pKanaComp.reset(); }
204  std::deque<sal_uInt16>* GetpKanaComp() const { return m_pKanaComp.get(); }
205  std::deque<sal_uInt16>& GetKanaComp() { return *m_pKanaComp; }
206 
239  void MaxAscentDescent( SwTwips& _orAscent,
240  SwTwips& _orDescent,
241  SwTwips& _orObjAscent,
242  SwTwips& _orObjDescent,
243  const SwLinePortion* _pDontConsiderPortion = nullptr,
244  const bool _bNoFlyCntPorAndLinePor = false ) const;
245 
246  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
247 };
248 
252 {
253  // Area that needs repainting
255  // Area that needs reformatting
258 
259  // Fraction aZoom;
261 
262  // If a SwTextFrame is locked, no changes occur to the formatting data (under
263  // pLine) (compare with Orphans)
264  bool m_bFlys : 1; // Overlapping Flys?
265  bool m_bPrep : 1; // PREP_*
266  bool m_bPrepWidows : 1; // PrepareHint::Widows
267  bool m_bPrepAdjust : 1; // PrepareHint::AdjustSizeWithoutFormatting
268  bool m_bPrepMustFit : 1; // PrepareHint::MustFit
269  bool m_bFollowField : 1; // We have a bit of field left for the Follow
270 
271  bool m_bFixLineHeight : 1; // Fixed line height
272  bool m_bFootnoteNum : 1; // contains a footnotenumberportion
273  bool m_bMargin : 1; // contains a hanging punctuation in the margin
274 
275 public:
276  SwParaPortion();
277  virtual ~SwParaPortion() override;
278 
279  // Resets all formatting information (except for bFlys)
280  inline void FormatReset();
281 
282  // Resets the Flags
283  inline void ResetPreps();
284 
285  // Get/Set methods
287  const SwRepaint& GetRepaint() const { return m_aRepaint; }
289  const SwCharRange& GetReformat() const { return m_aReformat; }
291  const tools::Long& GetDelta() const { return m_nDelta; }
293  const SwScriptInfo& GetScriptInfo() const { return m_aScriptInfo; }
294 
295  // For SwTextFrame::Format: returns the paragraph's current length
296  TextFrameIndex GetParLen() const;
297 
298  // For Prepare()
299  bool UpdateQuoVadis( std::u16string_view rQuo );
300 
301  // Flags
302  void SetFly() { m_bFlys = true; }
303  bool HasFly() const { return m_bFlys; }
304 
305  // Preps
306  void SetPrep() { m_bPrep = true; }
307  bool IsPrep() const { return m_bPrep; }
308  void SetPrepWidows() { m_bPrepWidows = true; }
309  bool IsPrepWidows() const { return m_bPrepWidows; }
310  void SetPrepMustFit( const bool bNew ) { m_bPrepMustFit = bNew; }
311  bool IsPrepMustFit() const { return m_bPrepMustFit; }
312  void SetPrepAdjust() { m_bPrepAdjust = true; }
313  bool IsPrepAdjust() const { return m_bPrepAdjust; }
314  void SetFollowField( const bool bNew ) { m_bFollowField = bNew; }
315  bool IsFollowField() const { return m_bFollowField; }
317  bool IsFixLineHeight() const { return m_bFixLineHeight; }
318 
319  void SetFootnoteNum( const bool bNew ) { m_bFootnoteNum = bNew; }
320  bool IsFootnoteNum() const { return m_bFootnoteNum; }
321  void SetMargin( const bool bNew = true ) { m_bMargin = bNew; }
322  bool IsMargin() const { return m_bMargin; }
323 
324  // Set nErgo in the QuoVadisPortion
325  void SetErgoSumNum( const OUString &rErgo );
326 
327  const SwDropPortion *FindDropPortion() const;
328 
329  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
330 };
331 
333 {
335 }
336 
338 {
339  m_nDelta = 0;
341  // bFlys needs to be retained in SwTextFrame::Format_() so that empty
342  // paragraphs that needed to avoid Frames with no flow, reformat
343  // when the Frame disappears from the Area
344  // bFlys = false;
345  ResetPreps();
347 }
348 
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetRedlineText(const OUString &sText)
Definition: porlay.hxx:142
bool HasContent() const
Definition: porlay.hxx:135
std::deque< sal_uInt16 > * GetpKanaComp() const
Definition: porlay.hxx:204
void SetRedlineEndType(const enum RedlineType eNew)
Definition: porlay.hxx:140
void SetRest(const bool bNew)
Definition: porlay.hxx:130
bool IsFootnoteNum() const
Definition: porlay.hxx:320
SwScriptInfo m_aScriptInfo
Definition: porlay.hxx:257
const SwRepaint & GetRepaint() const
Definition: porlay.hxx:287
void SetKanaComp(std::unique_ptr< std::deque< sal_uInt16 >> pNew)
Definition: porlay.hxx:202
bool IsPrepAdjust() const
Definition: porlay.hxx:313
const SwCharRange & GetReformat() const
Definition: porlay.hxx:289
void SetFormatAdj(const bool bNew)
Definition: porlay.hxx:122
bool IsClipping() const
Definition: porlay.hxx:156
void SetPrepAdjust()
Definition: porlay.hxx:312
void Init()
bool IsHanging() const
Definition: porlay.hxx:147
void SetFly(const bool bNew)
Definition: porlay.hxx:128
bool IsRest() const
Definition: porlay.hxx:131
bool m_bFixLineHeight
Definition: porlay.hxx:271
SwLineLayout * GetNext()
Definition: porlay.hxx:161
SwCharRange & operator+=(const SwCharRange &rRange)
Definition: porlay.cxx:789
std::deque< sal_uInt16 > & GetKanaComp()
Definition: porlay.hxx:205
OUString m_sRedlineText
Definition: porlay.hxx:105
long Long
SwTwips GetHangingMargin() const
Definition: porlay.hxx:178
void SetFootnoteNum(const bool bNew)
Definition: porlay.hxx:319
virtual ~SwParaPortion() override
Definition: porlay.cxx:2490
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: porlay.cxx:2523
void SetErgoSumNum(const OUString &rErgo)
Definition: txtftn.cxx:1512
bool m_bMargin
Definition: porlay.hxx:273
bool operator>(const SwCharRange &rRange) const
Definition: porlay.hxx:55
bool IsPrep() const
Definition: porlay.hxx:307
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: porlin.cxx:320
SwTwips m_nTextHeight
Definition: porlay.hxx:87
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
RedlineType GetRedlineEndType() const
Definition: porlay.hxx:141
bool HasForcedLeftMargin() const
Definition: porlay.hxx:145
const tools::Long & GetDelta() const
Definition: porlay.hxx:291
bool IsEndHyph() const
Definition: porlay.hxx:125
Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
Definition: porlay.hxx:251
tools::Long GetLLSpaceAdd(sal_uInt16 nIdx)
Definition: porlay.hxx:197
TextFrameIndex & Start()
Definition: porlay.hxx:47
bool HasRedlineEnd() const
Definition: porlay.hxx:139
bool operator!=(const SwCharRange &rRange) const
Definition: porlay.hxx:57
void SetFly()
Definition: porlay.hxx:302
TextFrameIndex const & Start() const
Definition: porlay.hxx:48
SwTwips GetTextHeight() const
Definition: porlay.hxx:173
sal_uInt16 GetLLSpaceAddCount() const
Definition: porlay.hxx:189
SwCharRange m_aReformat
Definition: porlay.hxx:256
void SetClipping(const bool bNew)
Definition: porlay.hxx:155
void FormatReset()
Definition: porlay.hxx:337
bool HasFly() const
Definition: porlay.hxx:303
bool operator<(const SwCharRange &rRange) const
Definition: porlay.hxx:53
bool IsSpaceAdd() const
Definition: porlay.hxx:185
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:439
SwTwips m_nRealHeight
Definition: porlay.hxx:86
This portion represents a part of the paragraph string.
Definition: portxt.hxx:26
void SetRedline(const bool bNew)
Definition: porlay.hxx:136
tools::Long & GetDelta()
Definition: porlay.hxx:290
bool IsFollowField() const
Definition: porlay.hxx:315
bool IsBlinking() const
Definition: porlay.hxx:133
const SwLineLayout * GetNext() const
Definition: porlay.hxx:162
void SetEndHyph(const bool bNew)
Definition: porlay.hxx:124
struct _xmlTextWriter * xmlTextWriterPtr
bool m_bPrepAdjust
Definition: porlay.hxx:267
virtual SwLinePortion * Append(SwLinePortion *pPortion)
Definition: porlin.cxx:189
TextFrameIndex m_nStart
Definition: porlay.hxx:40
const OUString * GetRedlineText() const
Definition: porlay.hxx:143
bool IsDummy() const
Definition: porlay.hxx:153
TextFrameIndex const & Len() const
Definition: porlay.hxx:52
tools::Long m_nDelta
Definition: porlay.hxx:260
Collection of SwLinePortion instances, representing one line of text.
Definition: porlay.hxx:80
SwTwips GetRealHeight() const
Definition: porlay.hxx:171
SwCharRange & GetReformat()
Definition: porlay.hxx:288
void SetRedlineEnd(const bool bNew)
Definition: porlay.hxx:138
void FinishKanaComp()
Definition: porlay.hxx:203
std::unique_ptr< std::deque< sal_uInt16 > > m_pKanaComp
Definition: porlay.hxx:85
bool IsPrepWidows() const
Definition: porlay.hxx:309
void FinishSpaceAdd()
Definition: porlay.hxx:188
std::unique_ptr< std::vector< tools::Long > > m_pLLSpaceAdd
Definition: porlay.hxx:84
bool m_bPrep
Definition: porlay.hxx:265
const SwScriptInfo & GetScriptInfo() const
Definition: porlay.hxx:293
bool IsFormatAdj() const
Definition: porlay.hxx:123
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwTwips Height() const
Definition: possiz.hxx:50
TextFrameIndex GetParLen() const
Definition: porlay.cxx:2494
bool m_bPrepMustFit
Definition: porlay.hxx:268
SwCharRange(TextFrameIndex const nInitStart=TextFrameIndex(0), TextFrameIndex const nInitLen=TextFrameIndex(0))
Definition: porlay.hxx:44
SwTwips GetRightOfst() const
Definition: porlay.hxx:74
TextFrameIndex m_nLen
Definition: porlay.hxx:41
void LeftMove(TextFrameIndex const nNew)
Definition: porlay.hxx:49
tools::Long SwTwips
Definition: swtypes.hxx:52
bool IsMargin() const
Definition: porlay.hxx:322
void ResetPreps()
Definition: porlay.hxx:332
SwTwips m_nOffset
Definition: porlay.hxx:67
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:51
void SetForcedLeftMargin()
Definition: porlay.hxx:144
bool IsPrepMustFit() const
Definition: porlay.hxx:311
bool IsMidHyph() const
Definition: porlay.hxx:127
void SetHanging(const bool bNew)
Definition: porlay.hxx:146
void SetFixLineHeight()
Definition: porlay.hxx:316
bool UpdateQuoVadis(std::u16string_view rQuo)
Is called in SwTextFrame::Prepare()
Definition: txtftn.cxx:1534
void SetNext(SwLineLayout *pNew)
Definition: porlay.hxx:163
SwRepaint & GetRepaint()
Definition: porlay.hxx:286
void SetDummy(const bool bNew)
Definition: porlay.hxx:152
void RemoveFirstLLSpaceAdd()
Definition: porlay.hxx:198
void SetRightOfst(const SwTwips nNew)
Definition: porlay.hxx:75
bool IsFly() const
Definition: porlay.hxx:129
SwRepaint()
Definition: porlay.hxx:70
SwScriptInfo & GetScriptInfo()
Definition: porlay.hxx:292
void SetPrep()
Definition: porlay.hxx:306
void SetRealHeight(SwTwips nNew)
Definition: porlay.hxx:170
void SetFollowField(const bool bNew)
Definition: porlay.hxx:314
bool IsFixLineHeight() const
Definition: porlay.hxx:317
const SwDropPortion * FindDropPortion() const
Definition: porlay.cxx:2506
constexpr sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:58
void SetPrepMustFit(const bool bNew)
Definition: porlay.hxx:310
void SetPrepWidows()
Definition: porlay.hxx:308
void SetMargin(const bool bNew=true)
Definition: porlay.hxx:321
bool m_bPrepWidows
Definition: porlay.hxx:266
SwTwips GetOffset() const
Definition: porlay.hxx:72
bool m_bFlys
Definition: porlay.hxx:264
bool HasRedline() const
Definition: porlay.hxx:137
RedlineType
void SetContent(const bool bNew)
Definition: porlay.hxx:134
void SetOffset(const SwTwips nNew)
Definition: porlay.hxx:73
SwTwips m_nRightOffset
Definition: porlay.hxx:68
std::vector< tools::Long > * GetpLLSpaceAdd() const
Definition: porlay.hxx:199
void SetMidHyph(const bool bNew)
Definition: porlay.hxx:126
bool m_bFootnoteNum
Definition: porlay.hxx:272
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
TextFrameIndex & Len()
Definition: porlay.hxx:51
void SetBlinking(const bool bNew)
Definition: porlay.hxx:132
virtual SwLinePortion * Insert(SwLinePortion *pPortion)
Definition: porlin.cxx:168
bool m_bFollowField
Definition: porlay.hxx:269
bool HasUnderscore() const
Definition: porlay.hxx:149
void SetUnderscore(const bool bNew)
Definition: porlay.hxx:148
SwLineLayout * m_pNext
Definition: porlay.hxx:83
void SetLLSpaceAdd(tools::Long nNew, sal_uInt16 nIdx)
Definition: porlay.hxx:190
SwRepaint m_aRepaint
Definition: porlay.hxx:254