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 #ifndef INCLUDED_SW_SOURCE_CORE_TEXT_PORLAY_HXX
20 #define INCLUDED_SW_SOURCE_CORE_TEXT_PORLAY_HXX
21 
22 #include <scriptinfo.hxx>
23 
24 #include <swrect.hxx>
25 #include <swtypes.hxx>
26 #include "portxt.hxx"
27 
28 #include <vector>
29 #include <deque>
30 
31 class SwMarginPortion;
32 class SwDropPortion;
33 class SwTextFormatter;
34 
36 {
37 private:
40 
41 public:
42  SwCharRange(TextFrameIndex const nInitStart = TextFrameIndex(0),
43  TextFrameIndex const nInitLen = TextFrameIndex(0))
44  : nStart( nInitStart ), nLen(nInitLen) {}
45  TextFrameIndex & Start() { return nStart; }
46  TextFrameIndex const& Start() const { return nStart; }
47  void LeftMove(TextFrameIndex const nNew)
48  { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
49  TextFrameIndex & Len() { return nLen; }
50  TextFrameIndex const& Len() const { return nLen; }
51  bool operator<(const SwCharRange &rRange) const
52  { return nStart < rRange.nStart; }
53  bool operator>(const SwCharRange &rRange) const
54  { return nStart + nLen > rRange.nStart + rRange.nLen; }
55  bool operator!=(const SwCharRange &rRange) const
56  { return *this < rRange || *this > rRange; }
57  SwCharRange &operator+=(const SwCharRange &rRange);
58 };
59 
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
64 {
67 public:
68  SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
69 
70  SwTwips GetOfst() const { return nOfst; }
71  void SetOfst( const SwTwips nNew ) { nOfst = nNew; }
72  SwTwips GetRightOfst() const { return nRightOfst; }
73  void SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
74 };
75 
79 {
80 private:
81  SwLineLayout *m_pNext; // The next Line
82  std::unique_ptr<std::vector<long>> m_pLLSpaceAdd; // Used for justified alignment
83  std::unique_ptr<std::deque<sal_uInt16>> m_pKanaComp; // Used for Kana compression
84  sal_uInt16 m_nRealHeight; // The height resulting from line spacing and register
85  bool m_bFormatAdj : 1;
86  bool m_bDummy : 1;
87  bool m_bEndHyph : 1;
88  bool m_bMidHyph : 1;
89  bool m_bFly : 1;
90  bool m_bRest : 1;
91  bool m_bBlinking : 1;
92  bool m_bClipping : 1; // Clipping needed for exact line height
93  bool m_bContent : 1; // Text for line numbering
94  bool m_bRedline : 1; // The Redlining
95  bool m_bForcedLeftMargin : 1; // Left adjustment moved by the Fly
96  bool m_bHanging : 1; // Contains a hanging portion in the margin
97  bool m_bUnderscore : 1;
98 
99  SwTwips GetHangingMargin_() const;
100 
101  void DeleteNext();
102 public:
103  // From SwLinePortion
104  virtual SwLinePortion *Insert( SwLinePortion *pPortion ) override;
105  virtual SwLinePortion *Append( SwLinePortion *pPortion ) override;
107 
108  // Flags
109  void ResetFlags();
110  void SetFormatAdj( const bool bNew ) { m_bFormatAdj = bNew; }
111  bool IsFormatAdj() const { return m_bFormatAdj; }
112  void SetEndHyph( const bool bNew ) { m_bEndHyph = bNew; }
113  bool IsEndHyph() const { return m_bEndHyph; }
114  void SetMidHyph( const bool bNew ) { m_bMidHyph = bNew; }
115  bool IsMidHyph() const { return m_bMidHyph; }
116  void SetFly( const bool bNew ) { m_bFly = bNew; }
117  bool IsFly() const { return m_bFly; }
118  void SetRest( const bool bNew ) { m_bRest = bNew; }
119  bool IsRest() const { return m_bRest; }
120  void SetBlinking( const bool bNew ) { m_bBlinking = bNew; }
121  bool IsBlinking() const { return m_bBlinking; }
122  void SetContent( const bool bNew ) { m_bContent = bNew; }
123  bool HasContent() const { return m_bContent; }
124  void SetRedline( const bool bNew ) { m_bRedline = bNew; }
125  bool HasRedline() const { return m_bRedline; }
127  bool HasForcedLeftMargin() const { return m_bForcedLeftMargin; }
128  void SetHanging( const bool bNew ) { m_bHanging = bNew; }
129  bool IsHanging() const { return m_bHanging; }
130  void SetUnderscore( const bool bNew ) { m_bUnderscore = bNew; }
131  bool HasUnderscore() const { return m_bUnderscore; }
132 
133  // Respecting empty dummy lines
134  void SetDummy( const bool bNew ) { m_bDummy = bNew; }
135  bool IsDummy() const { return m_bDummy; }
136 
137  void SetClipping( const bool bNew ) { m_bClipping = bNew; }
138  bool IsClipping() const { return m_bClipping; }
139 
140  SwLineLayout();
141  virtual ~SwLineLayout() override;
142 
143  SwLineLayout *GetNext() { return m_pNext; }
144  const SwLineLayout *GetNext() const { return m_pNext; }
145  void SetNext( SwLineLayout *pNew ) { m_pNext = pNew; }
146 
147  void Init( SwLinePortion *pNextPortion = nullptr);
148 
149  // Collects the data for the line
150  void CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf );
151 
152  void SetRealHeight( sal_uInt16 nNew ) { m_nRealHeight = nNew; }
153  sal_uInt16 GetRealHeight() const { return m_nRealHeight; }
154 
155  // Creates the glue chain for short lines
157 
159  { return GetHangingMargin_(); }
160 
161  // For special treatment for empty lines
162  virtual bool Format( SwTextFormatInfo &rInf ) override;
163 
164  // Stuff for justified alignment
165  bool IsSpaceAdd() { return m_pLLSpaceAdd != nullptr; }
166  void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
167  void CreateSpaceAdd( const long nInit = 0 );
168  void FinishSpaceAdd() { m_pLLSpaceAdd.reset(); }
169  sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(m_pLLSpaceAdd->size()); }
170  void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
171  {
172  if ( nIdx == GetLLSpaceAddCount() )
173  m_pLLSpaceAdd->push_back( nNew );
174  else
175  (*m_pLLSpaceAdd)[ nIdx ] = nNew;
176  }
177  long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*m_pLLSpaceAdd)[ nIdx ]; }
178  void RemoveFirstLLSpaceAdd() { m_pLLSpaceAdd->erase( m_pLLSpaceAdd->begin() ); }
179  std::vector<long>* GetpLLSpaceAdd() const { return m_pLLSpaceAdd.get(); }
180 
181  // Stuff for Kana compression
182  void SetKanaComp( std::unique_ptr<std::deque<sal_uInt16>> pNew ){ m_pKanaComp = std::move(pNew); }
183  void FinishKanaComp() { m_pKanaComp.reset(); }
184  std::deque<sal_uInt16>* GetpKanaComp() const { return m_pKanaComp.get(); }
185  std::deque<sal_uInt16>& GetKanaComp() { return *m_pKanaComp; }
186 
219  void MaxAscentDescent( SwTwips& _orAscent,
220  SwTwips& _orDescent,
221  SwTwips& _orObjAscent,
222  SwTwips& _orObjDescent,
223  const SwLinePortion* _pDontConsiderPortion = nullptr,
224  const bool _bNoFlyCntPorAndLinePor = false ) const;
225 };
226 
230 {
231  // Area that needs repainting
233  // Area that needs reformatting
236 
237  // Fraction aZoom;
238  long m_nDelta;
239 
240  // If a SwTextFrame is locked, no changes occur to the formatting data (under
241  // pLine) (compare with Orphans)
242  bool m_bFlys : 1; // Overlapping Flys?
243  bool m_bPrep : 1; // PREP_*
244  bool m_bPrepWidows : 1; // PREP_WIDOWS
245  bool m_bPrepAdjust : 1; // PREP_ADJUST_FRM
246  bool m_bPrepMustFit : 1; // PREP_MUST_FIT
247  bool m_bFollowField : 1; // We have a bit of field left for the Follow
248 
249  bool m_bFixLineHeight : 1; // Fixed line height
250  bool m_bFootnoteNum : 1; // contains a footnotenumberportion
251  bool m_bMargin : 1; // contains a hanging punctuation in the margin
252 
253 public:
254  SwParaPortion();
255  virtual ~SwParaPortion() override;
256 
257  // Resets all formatting information (except for bFlys)
258  inline void FormatReset();
259 
260  // Resets the Flags
261  inline void ResetPreps();
262 
263  // Get/Set methods
265  const SwRepaint& GetRepaint() const { return m_aRepaint; }
267  const SwCharRange& GetReformat() const { return m_aReformat; }
268  long& GetDelta() { return m_nDelta; }
269  const long& GetDelta() const { return m_nDelta; }
271  const SwScriptInfo& GetScriptInfo() const { return m_aScriptInfo; }
272 
273  // For SwTextFrame::Format: returns the paragraph's current length
274  TextFrameIndex GetParLen() const;
275 
276  // For Prepare()
277  bool UpdateQuoVadis( const OUString &rQuo );
278 
279  // Flags
280  void SetFly() { m_bFlys = true; }
281  bool HasFly() const { return m_bFlys; }
282 
283  // Preps
284  void SetPrep() { m_bPrep = true; }
285  bool IsPrep() const { return m_bPrep; }
286  void SetPrepWidows() { m_bPrepWidows = true; }
287  bool IsPrepWidows() const { return m_bPrepWidows; }
288  void SetPrepMustFit( const bool bNew ) { m_bPrepMustFit = bNew; }
289  bool IsPrepMustFit() const { return m_bPrepMustFit; }
290  void SetPrepAdjust() { m_bPrepAdjust = true; }
291  bool IsPrepAdjust() const { return m_bPrepAdjust; }
292  void SetFollowField( const bool bNew ) { m_bFollowField = bNew; }
293  bool IsFollowField() const { return m_bFollowField; }
295  bool IsFixLineHeight() const { return m_bFixLineHeight; }
296 
297  void SetFootnoteNum( const bool bNew ) { m_bFootnoteNum = bNew; }
298  bool IsFootnoteNum() const { return m_bFootnoteNum; }
299  void SetMargin( const bool bNew = true ) { m_bMargin = bNew; }
300  bool IsMargin() const { return m_bMargin; }
301 
302  // Set nErgo in the QuoVadisPortion
303  void SetErgoSumNum( const OUString &rErgo );
304 
305  const SwDropPortion *FindDropPortion() const;
306 };
307 
309 {
311 }
312 
314 {
315  m_nDelta = 0;
317  // bFlys needs to be retained in SwTextFrame::Format_() so that empty
318  // paragraphs that needed to avoid Frames with no flow, reformat
319  // when the Frame disappears from the Area
320  // bFlys = false;
321  ResetPreps();
323 }
324 
325 #endif
326 
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< std::vector< long > > m_pLLSpaceAdd
Definition: porlay.hxx:82
virtual SwLinePortion * Insert(SwLinePortion *pPortion) override
Definition: porlay.cxx:214
bool HasContent() const
Definition: porlay.hxx:123
std::deque< sal_uInt16 > * GetpKanaComp() const
Definition: porlay.hxx:184
void SetRest(const bool bNew)
Definition: porlay.hxx:118
bool IsFootnoteNum() const
Definition: porlay.hxx:298
SwScriptInfo m_aScriptInfo
Definition: porlay.hxx:235
const SwRepaint & GetRepaint() const
Definition: porlay.hxx:265
void SetKanaComp(std::unique_ptr< std::deque< sal_uInt16 >> pNew)
Definition: porlay.hxx:182
bool IsPrepAdjust() const
Definition: porlay.hxx:291
const SwCharRange & GetReformat() const
Definition: porlay.hxx:267
void SetFormatAdj(const bool bNew)
Definition: porlay.hxx:110
SwTwips GetHangingMargin_() const
Definition: porlay.cxx:2205
bool IsClipping() const
Definition: porlay.hxx:138
void SetPrepAdjust()
Definition: porlay.hxx:290
bool IsHanging() const
Definition: porlay.hxx:129
TextFrameIndex nStart
Definition: porlay.hxx:38
void SetFly(const bool bNew)
Definition: porlay.hxx:116
bool IsRest() const
Definition: porlay.hxx:119
bool m_bFixLineHeight
Definition: porlay.hxx:249
SwLineLayout * GetNext()
Definition: porlay.hxx:143
SwTwips GetOfst() const
Definition: porlay.hxx:70
SwCharRange & operator+=(const SwCharRange &rRange)
Definition: porlay.cxx:679
SwMarginPortion * CalcLeftMargin()
Definition: porlay.cxx:262
std::deque< sal_uInt16 > & GetKanaComp()
Definition: porlay.hxx:185
long & GetDelta()
Definition: porlay.hxx:268
bool m_bBlinking
Definition: porlay.hxx:91
bool m_bEndHyph
Definition: porlay.hxx:87
SwTwips GetHangingMargin() const
Definition: porlay.hxx:158
void SetFootnoteNum(const bool bNew)
Definition: porlay.hxx:297
virtual ~SwParaPortion() override
Definition: porlay.cxx:2159
void CalcLine(SwTextFormatter &rLine, SwTextFormatInfo &rInf)
Definition: porlay.cxx:332
void SetErgoSumNum(const OUString &rErgo)
Definition: txtftn.cxx:1470
bool m_bMargin
Definition: porlay.hxx:251
bool IsSpaceAdd()
Definition: porlay.hxx:165
long SwTwips
Definition: swtypes.hxx:49
bool operator>(const SwCharRange &rRange) const
Definition: porlay.hxx:53
bool IsPrep() const
Definition: porlay.hxx:285
void MaxAscentDescent(SwTwips &_orAscent, SwTwips &_orDescent, SwTwips &_orObjAscent, SwTwips &_orObjDescent, const SwLinePortion *_pDontConsiderPortion=nullptr, const bool _bNoFlyCntPorAndLinePor=false) const
determine ascent and descent for positioning of as-character anchored object
Definition: porlay.cxx:609
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
bool HasForcedLeftMargin() const
Definition: porlay.hxx:127
bool IsEndHyph() const
Definition: porlay.hxx:113
Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
Definition: porlay.hxx:229
bool m_bMidHyph
Definition: porlay.hxx:88
TextFrameIndex & Start()
Definition: porlay.hxx:45
bool operator!=(const SwCharRange &rRange) const
Definition: porlay.hxx:55
std::vector< long > * GetpLLSpaceAdd() const
Definition: porlay.hxx:179
void SetFly()
Definition: porlay.hxx:280
TextFrameIndex const & Start() const
Definition: porlay.hxx:46
virtual ~SwLineLayout() override
Definition: porlay.cxx:204
sal_uInt16 GetLLSpaceAddCount() const
Definition: porlay.hxx:169
SwCharRange m_aReformat
Definition: porlay.hxx:234
bool m_bFormatAdj
Definition: porlay.hxx:85
void SetClipping(const bool bNew)
Definition: porlay.hxx:137
void FormatReset()
Definition: porlay.hxx:313
SwTwips nRightOfst
Definition: porlay.hxx:66
bool HasFly() const
Definition: porlay.hxx:281
void ResetFlags()
Definition: porlay.cxx:658
bool operator<(const SwCharRange &rRange) const
Definition: porlay.hxx:51
void SetOfst(const SwTwips nNew)
Definition: porlay.hxx:71
bool m_bClipping
Definition: porlay.hxx:92
This portion represents a part of the paragraph string.
Definition: portxt.hxx:27
void InitSpaceAdd()
Definition: porlay.cxx:301
void SetRedline(const bool bNew)
Definition: porlay.hxx:124
bool IsFollowField() const
Definition: porlay.hxx:293
bool IsBlinking() const
Definition: porlay.hxx:121
const SwLineLayout * GetNext() const
Definition: porlay.hxx:144
void SetEndHyph(const bool bNew)
Definition: porlay.hxx:112
void SetRealHeight(sal_uInt16 nNew)
Definition: porlay.hxx:152
TextFrameIndex nLen
Definition: porlay.hxx:39
bool m_bHanging
Definition: porlay.hxx:96
bool m_bPrepAdjust
Definition: porlay.hxx:245
bool IsDummy() const
Definition: porlay.hxx:135
TextFrameIndex const & Len() const
Definition: porlay.hxx:50
Collection of SwLinePortion instances, representing one line of text.
Definition: porlay.hxx:78
SwCharRange & GetReformat()
Definition: porlay.hxx:266
sal_uInt16 m_nRealHeight
Definition: porlay.hxx:84
SwLinePortion * GetFirstPortion() const
Definition: porlay.cxx:673
void FinishKanaComp()
Definition: porlay.hxx:183
std::unique_ptr< std::deque< sal_uInt16 > > m_pKanaComp
Definition: porlay.hxx:83
bool IsPrepWidows() const
Definition: porlay.hxx:287
void FinishSpaceAdd()
Definition: porlay.hxx:168
bool m_bRedline
Definition: porlay.hxx:94
virtual SwLinePortion * Append(SwLinePortion *pPortion) override
Definition: porlay.cxx:239
bool m_bPrep
Definition: porlay.hxx:243
const SwScriptInfo & GetScriptInfo() const
Definition: porlay.hxx:271
bool IsFormatAdj() const
Definition: porlay.hxx:111
TextFrameIndex GetParLen() const
Definition: porlay.cxx:2163
bool m_bPrepMustFit
Definition: porlay.hxx:246
void SetLLSpaceAdd(long nNew, sal_uInt16 nIdx)
Definition: porlay.hxx:170
SwCharRange(TextFrameIndex const nInitStart=TextFrameIndex(0), TextFrameIndex const nInitLen=TextFrameIndex(0))
Definition: porlay.hxx:42
SwTwips GetRightOfst() const
Definition: porlay.hxx:72
void LeftMove(TextFrameIndex const nNew)
Definition: porlay.hxx:47
bool IsMargin() const
Definition: porlay.hxx:300
SwTwips nOfst
Definition: porlay.hxx:65
void ResetPreps()
Definition: porlay.hxx:308
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: porlay.cxx:251
const long & GetDelta() const
Definition: porlay.hxx:269
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:49
void SetForcedLeftMargin()
Definition: porlay.hxx:126
long GetLLSpaceAdd(sal_uInt16 nIdx)
Definition: porlay.hxx:177
bool IsPrepMustFit() const
Definition: porlay.hxx:289
bool IsMidHyph() const
Definition: porlay.hxx:115
void SetHanging(const bool bNew)
Definition: porlay.hxx:128
void SetFixLineHeight()
Definition: porlay.hxx:294
void SetNext(SwLineLayout *pNew)
Definition: porlay.hxx:145
SwRepaint & GetRepaint()
Definition: porlay.hxx:264
void SetDummy(const bool bNew)
Definition: porlay.hxx:134
void RemoveFirstLLSpaceAdd()
Definition: porlay.hxx:178
void SetRightOfst(const SwTwips nNew)
Definition: porlay.hxx:73
bool IsFly() const
Definition: porlay.hxx:117
bool m_bContent
Definition: porlay.hxx:93
SwRepaint()
Definition: porlay.hxx:68
SwScriptInfo & GetScriptInfo()
Definition: porlay.hxx:270
void SetPrep()
Definition: porlay.hxx:284
void SetFollowField(const bool bNew)
Definition: porlay.hxx:292
bool IsFixLineHeight() const
Definition: porlay.hxx:295
bool m_bForcedLeftMargin
Definition: porlay.hxx:95
const SwDropPortion * FindDropPortion() const
Definition: porlay.cxx:2175
void SetPrepMustFit(const bool bNew)
Definition: porlay.hxx:288
void SetPrepWidows()
Definition: porlay.hxx:286
void SetMargin(const bool bNew=true)
Definition: porlay.hxx:299
sal_uInt16 GetRealHeight() const
Definition: porlay.hxx:153
void DeleteNext()
Definition: porlay.cxx:182
bool m_bUnderscore
Definition: porlay.hxx:97
bool m_bPrepWidows
Definition: porlay.hxx:244
bool m_bFlys
Definition: porlay.hxx:242
bool HasRedline() const
Definition: porlay.hxx:125
void SetContent(const bool bNew)
Definition: porlay.hxx:122
void SetMidHyph(const bool bNew)
Definition: porlay.hxx:114
bool m_bFootnoteNum
Definition: porlay.hxx:250
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:49
void SetBlinking(const bool bNew)
Definition: porlay.hxx:120
bool m_bRest
Definition: porlay.hxx:90
bool m_bDummy
Definition: porlay.hxx:86
const sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:61
bool m_bFollowField
Definition: porlay.hxx:247
bool HasUnderscore() const
Definition: porlay.hxx:131
long m_nDelta
Definition: porlay.hxx:238
void SetUnderscore(const bool bNew)
Definition: porlay.hxx:130
void CreateSpaceAdd(const long nInit=0)
Definition: porlay.cxx:309
bool m_bFly
Definition: porlay.hxx:89
SwLineLayout * m_pNext
Definition: porlay.hxx:81
void Init(SwLinePortion *pNextPortion=nullptr)
Definition: porlay.cxx:2192
SwRepaint m_aRepaint
Definition: porlay.hxx:232
bool UpdateQuoVadis(const OUString &rQuo)
Is called in SwTextFrame::Prepare()
Definition: txtftn.cxx:1492