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