LibreOffice Module sw (master)  1
porlin.cxx
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 
20 #include <vcl/outdev.hxx>
21 #include <SwPortionHandler.hxx>
22 
23 #include "porlin.hxx"
24 #include "inftxt.hxx"
25 #include "pormulti.hxx"
26 #include <blink.hxx>
27 #if OSL_DEBUG_LEVEL > 0
28 
29 static bool ChkChain( SwLinePortion *pStart )
30 {
31  SwLinePortion *pPor = pStart->GetNextPortion();
32  sal_uInt16 nCount = 0;
33  while( pPor )
34  {
35  ++nCount;
36  OSL_ENSURE( nCount < 200 && pPor != pStart,
37  "ChkChain(): lost in chains" );
38  if( nCount >= 200 || pPor == pStart )
39  {
40  // the lifesaver
41  pPor = pStart->GetNextPortion();
42  pStart->SetNextPortion(nullptr);
43  pPor->Truncate();
44  pStart->SetNextPortion( pPor );
45  return false;
46  }
47  pPor = pPor->GetNextPortion();
48  }
49  return true;
50 }
51 #endif
52 
54 {
55  if( pBlink )
56  pBlink->Delete( this );
57 }
58 
60 {
61  return GetLen() || Width() ? this : nullptr;
62 }
63 
64 sal_uInt16 SwLinePortion::GetViewWidth( const SwTextSizeInfo & ) const
65 {
66  return 0;
67 }
68 
70  mpNextPortion( nullptr ),
71  nLineLength( 0 ),
72  nAscent( 0 ),
73  nWhichPor( PortionType::NONE ),
74  m_bJoinBorderWithPrev(false),
75  m_bJoinBorderWithNext(false)
76 {
77 }
78 
80  const SwLinePortion* pLast ) const
81 {
82  OSL_ENSURE( rInf.OnWin(), "SwLinePortion::PrePaint: don't prepaint on a printer");
83  OSL_ENSURE( !Width(), "SwLinePortion::PrePaint: For Width()==0 only!");
84 
85  const sal_uInt16 nViewWidth = GetViewWidth( rInf );
86 
87  if( ! nViewWidth )
88  return;
89 
90  const sal_uInt16 nHalfView = nViewWidth / 2;
91  sal_uInt16 nLastWidth = pLast->Width();
92 
93  if ( pLast->InSpaceGrp() && rInf.GetSpaceAdd() )
94  nLastWidth = nLastWidth + static_cast<sal_uInt16>(pLast->CalcSpacing( rInf.GetSpaceAdd(), rInf ));
95 
96  sal_uInt16 nPos;
97  SwTextPaintInfo aInf( rInf );
98 
99  const bool bBidiPor = rInf.GetTextFrame()->IsRightToLeft() !=
100  bool( ComplexTextLayoutFlags::BiDiRtl & rInf.GetOut()->GetLayoutMode() );
101 
102  sal_uInt16 nDir = bBidiPor ?
103  1800 :
104  rInf.GetFont()->GetOrientation( rInf.GetTextFrame()->IsVertical() );
105 
106  // pLast == this *only* for the 1st portion in the line so nLastWidth is 0;
107  // allow this too, will paint outside the frame but might look better...
108  if (nLastWidth > nHalfView || pLast == this)
109  {
110  switch (nDir)
111  {
112  case 0:
113  nPos = sal_uInt16( rInf.X() );
114  nPos += nLastWidth - nHalfView;
115  aInf.X( nPos );
116  break;
117  case 900:
118  nPos = sal_uInt16( rInf.Y() );
119  nPos -= nLastWidth - nHalfView;
120  aInf.Y( nPos );
121  break;
122  case 1800:
123  nPos = sal_uInt16( rInf.X() );
124  nPos -= nLastWidth - nHalfView;
125  aInf.X( nPos );
126  break;
127  case 2700:
128  nPos = sal_uInt16( rInf.Y() );
129  nPos += nLastWidth - nHalfView;
130  aInf.Y( nPos );
131  break;
132  }
133  }
134 
135  SwLinePortion *pThis = const_cast<SwLinePortion*>(this);
136  pThis->Width( nViewWidth );
137  Paint( aInf );
138  pThis->Width(0);
139 }
140 
142 {
143  if( GetLen() == rInf.GetLen() )
144  *static_cast<SwPosSize*>(this) = GetTextSize( rInf );
145  else
146  {
147  SwTextSizeInfo aInf( rInf );
148  aInf.SetLen( GetLen() );
149  *static_cast<SwPosSize*>(this) = GetTextSize( aInf );
150  }
151 }
152 
153 // all following portions will be deleted
155 {
157  do
158  {
159  OSL_ENSURE( pPos != this, "SwLinePortion::Truncate: loop" );
160  SwLinePortion *pLast = pPos;
161  pPos = pPos->GetNextPortion();
162  pLast->SetNextPortion( nullptr );
163  delete pLast;
164 
165  } while( pPos );
166 
167  mpNextPortion = nullptr;
168 }
169 
170 // It always will be inserted after us.
172 {
174  SetNextPortion( pIns );
175 #if OSL_DEBUG_LEVEL > 0
176  ChkChain( this );
177 #endif
178  return pIns;
179 }
180 
182 {
183  SwLinePortion *pPos = this;
184  // Find the end and link pLinPortion to the last one...
185  while( pPos->GetNextPortion() )
186  {
187  pPos = pPos->GetNextPortion();
188  }
189  return pPos;
190 }
191 
193 {
194  SwLinePortion *pPos = FindLastPortion();
195  pPos->SetNextPortion( pIns );
196  pIns->SetNextPortion( nullptr );
197 #if OSL_DEBUG_LEVEL > 0
198  ChkChain( this );
199 #endif
200  return pIns;
201 }
202 
204 {
205  SwLinePortion *pPrev = pVictim->FindPrevPortion( this );
206  OSL_ENSURE( pPrev, "SwLinePortion::Cut(): can't cut" );
207  pPrev->SetNextPortion( pVictim->GetNextPortion() );
208  pVictim->SetNextPortion(nullptr);
209  return pVictim;
210 }
211 
213 {
214  OSL_ENSURE( pRoot != this, "SwLinePortion::FindPrevPortion(): invalid root" );
215  SwLinePortion *pPos = const_cast<SwLinePortion*>(pRoot);
216  while( pPos->GetNextPortion() && pPos->GetNextPortion() != this )
217  {
218  pPos = pPos->GetNextPortion();
219  }
220  OSL_ENSURE( pPos->GetNextPortion(),
221  "SwLinePortion::FindPrevPortion: blowing in the wind");
222  return pPos;
223 }
224 
226 {
227  if( nOfst > ( PrtWidth() / 2 ) )
228  return GetLen();
229  else
230  return TextFrameIndex(0);
231 }
232 
234 {
235  OSL_ENSURE( false, "SwLinePortion::GetTextSize: don't ask me about sizes, "
236  "I'm only a stupid SwLinePortion" );
237  return SwPosSize();
238 }
239 
241 {
242  if( rInf.X() > rInf.Width() )
243  {
244  Truncate();
245  rInf.SetUnderflow( this );
246  return true;
247  }
248 
249  const SwLinePortion *pLast = rInf.GetLast();
250  Height( pLast->Height() );
251  SetAscent( pLast->GetAscent() );
252  const sal_uInt16 nNewWidth = static_cast<sal_uInt16>(rInf.X() + PrtWidth());
253  // Only portions with true width can return true
254  // Notes for example never set bFull==true
255  if( rInf.Width() <= nNewWidth && PrtWidth() && ! IsKernPortion() )
256  {
257  Truncate();
258  if( nNewWidth > rInf.Width() )
259  PrtWidth( nNewWidth - rInf.Width() );
260  rInf.GetLast()->FormatEOL( rInf );
261  return true;
262  }
263  return false;
264 }
265 
266 // Format end of line
267 
269 { }
270 
272 {
273  bool bB2T = rInf.GetDirection() == DIR_BOTTOM2TOP;
274  const bool bFrameDir = rInf.GetTextFrame()->IsRightToLeft();
275  bool bCounterDir = ( ! bFrameDir && DIR_RIGHT2LEFT == rInf.GetDirection() ) ||
276  ( bFrameDir && DIR_LEFT2RIGHT == rInf.GetDirection() );
277 
278  if ( InSpaceGrp() && rInf.GetSpaceAdd() )
279  {
280  SwTwips nTmp = PrtWidth() + CalcSpacing( rInf.GetSpaceAdd(), rInf );
281  if( rInf.IsRotated() )
282  rInf.Y( rInf.Y() + ( bB2T ? -nTmp : nTmp ) );
283  else if ( bCounterDir )
284  rInf.X( rInf.X() - nTmp );
285  else
286  rInf.X( rInf.X() + nTmp );
287  }
288  else
289  {
290  if( InFixMargGrp() && !IsMarginPortion() )
291  {
292  rInf.IncSpaceIdx();
293  rInf.IncKanaIdx();
294  }
295  if( rInf.IsRotated() )
296  rInf.Y( rInf.Y() + ( bB2T ? -PrtWidth() : PrtWidth() ) );
297  else if ( bCounterDir )
298  rInf.X( rInf.X() - PrtWidth() );
299  else
300  rInf.X( rInf.X() + PrtWidth() );
301  }
302  if( IsMultiPortion() && static_cast<SwMultiPortion*>(this)->HasTabulator() )
303  rInf.IncSpaceIdx();
304 
305  rInf.SetIdx( rInf.GetIdx() + GetLen() );
306 }
307 
308 long SwLinePortion::CalcSpacing( long , const SwTextSizeInfo & ) const
309 {
310  return 0;
311 }
312 
313 bool SwLinePortion::GetExpText( const SwTextSizeInfo &, OUString & ) const
314 {
315  return false;
316 }
317 
319 {
320  rPH.Special( GetLen(), OUString(), GetWhichPor(), Height(), Width() );
321 }
322 
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool Format(SwTextFormatInfo &rInf)
Definition: porlin.cxx:240
void Move(SwTextPaintInfo &rInf)
Definition: porlin.cxx:271
bool InSpaceGrp() const
Definition: porlin.hxx:109
sal_uInt16 Height() const
Definition: possiz.hxx:44
SwFont * GetFont()
Definition: inftxt.hxx:238
void Truncate_()
Definition: porlin.cxx:154
void CalcTextSize(const SwTextSizeInfo &rInfo)
Definition: porlin.cxx:141
static bool ChkChain(SwLinePortion *pStart)
Definition: porlin.cxx:29
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
ComplexTextLayoutFlags GetLayoutMode() const
long SwTwips
Definition: swtypes.hxx:49
sal_uInt16 GetOrientation(const bool bVertLayout=false, const bool bVertFormatLRBT=false) const
Definition: swfont.cxx:433
virtual SwLinePortion * Compress()
Definition: porlin.cxx:59
bool IsMarginPortion() const
Definition: porlin.hxx:124
virtual void Paint(const SwTextPaintInfo &rInf) const =0
void IncSpaceIdx()
Definition: inftxt.hxx:445
int nCount
long GetSpaceAdd() const
Definition: inftxt.hxx:447
#define DIR_BOTTOM2TOP
Definition: inftxt.hxx:55
sal_uInt8 GetDirection() const
Definition: inftxt.hxx:224
bool InFixMargGrp() const
Definition: porlin.hxx:108
SwTwips Y() const
Definition: inftxt.hxx:387
virtual void Special(TextFrameIndex nLength, const OUString &rText, PortionType nType, sal_Int32 nHeight=0, sal_Int32 nWidth=0, const SwFont *pFont=nullptr)=0
special portion.
void IncKanaIdx()
Definition: inftxt.hxx:328
virtual SwLinePortion * Append(SwLinePortion *pPortion)
Definition: porlin.cxx:192
virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const
the parameter is actually SwTwips apparently?
Definition: porlin.cxx:225
virtual sal_uInt16 GetViewWidth(const SwTextSizeInfo &rInf) const
Definition: porlin.cxx:64
#define DIR_LEFT2RIGHT
Definition: inftxt.hxx:54
SwPosSize(const sal_uInt16 nW=0, const sal_uInt16 nH=0)
Definition: possiz.hxx:31
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const
Definition: porlin.cxx:313
vcl::RenderContext * GetOut()
Definition: inftxt.hxx:231
void SetUnderflow(SwLinePortion *pNew)
Definition: inftxt.hxx:607
bool IsKernPortion() const
Definition: porlin.hxx:132
sal_uInt16 Width() const
Definition: inftxt.hxx:534
virtual void HandlePortion(SwPortionHandler &rPH) const
Definition: porlin.cxx:318
PortionType
Definition: txttypes.hxx:23
TextFrameIndex GetIdx() const
Definition: inftxt.hxx:278
void PrePaint(const SwTextPaintInfo &rInf, const SwLinePortion *pLast) const
Definition: porlin.cxx:79
SwLinePortion * Cut(SwLinePortion *pVictim)
Definition: porlin.cxx:203
TextFrameIndex GetLen() const
Definition: porlin.hxx:74
SwTextFrame * GetTextFrame()
Definition: inftxt.hxx:291
void Truncate()
Definition: porlin.hxx:196
SwLinePortion * mpNextPortion
Definition: porlin.hxx:54
bool IsMultiPortion() const
Definition: porlin.hxx:134
SwTwips X() const
Definition: inftxt.hxx:385
virtual ~SwLinePortion()
Definition: porlin.cxx:53
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:50
#define DIR_RIGHT2LEFT
Definition: inftxt.hxx:56
void SetLen(const TextFrameIndex nNew)
Definition: inftxt.hxx:281
PortionType GetWhichPor() const
Definition: porlin.hxx:95
SwLinePortion * FindLastPortion()
Definition: porlin.cxx:181
bool OnWin() const
Definition: inftxt.hxx:199
bool IsRightToLeft() const
Definition: frame.hxx:965
virtual SwPosSize GetTextSize(const SwTextSizeInfo &rInfo) const
Definition: porlin.cxx:233
TextFrameIndex GetLen() const
Definition: inftxt.hxx:280
SwLinePortion * FindPrevPortion(const SwLinePortion *pRoot)
Definition: porlin.cxx:212
sal_uInt16 Width() const
Definition: possiz.hxx:46
SwLinePortion * GetLast()
Definition: inftxt.hxx:567
void SetNextPortion(SwLinePortion *pNew)
Definition: porlin.hxx:76
void SetAscent(const sal_uInt16 nNewAsc)
Definition: porlin.hxx:79
bool IsVertical() const
Definition: frame.hxx:951
virtual void FormatEOL(SwTextFormatInfo &rInf)
Definition: porlin.cxx:268
bool IsRotated() const
Definition: inftxt.hxx:226
sal_uInt16 PrtWidth() const
Definition: porlin.hxx:81
SwLinePortion * GetNextPortion() const
Definition: porlin.hxx:72
void SetIdx(const TextFrameIndex nNew)
Definition: inftxt.hxx:279
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...
virtual long CalcSpacing(long nSpaceAdd, const SwTextSizeInfo &rInf) const
Definition: porlin.cxx:308
sal_uInt16 & GetAscent()
Definition: porlin.hxx:77
virtual SwLinePortion * Insert(SwLinePortion *pPortion)
Definition: porlin.cxx:171
sal_uInt16 nPos