LibreOffice Module sw (master)  1
porexp.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 <viewopt.hxx>
21 #include <SwPortionHandler.hxx>
22 #include "inftxt.hxx"
23 #include "porexp.hxx"
24 
25 TextFrameIndex SwExpandPortion::GetCursorOfst(const sal_uInt16 nOfst) const
26 { return SwLinePortion::GetCursorOfst( nOfst ); }
27 
28 bool SwExpandPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) const
29 {
30  rText.clear();
31  // Do not do: return 0 != rText.Len();
32  // Reason being: empty fields replace CH_TXTATR with an empty string
33  return true;
34 }
35 
37 {
38  rPH.Special( GetLen(), OUString(), GetWhichPor() );
39 }
40 
42 {
43  SwTextSlot aDiffText( &rInf, this, false, false );
44  return rInf.GetTextSize();
45 }
46 
48 {
49  SwTextSlot aDiffText( &rInf, this, true, false );
50  TextFrameIndex const nFullLen = rInf.GetLen();
51 
52  // As odd as it may seem: the query for GetLen() must return
53  // false due to the ExpandPortions _after_ the aDiffText (see SoftHyphs)
54  // caused by the SetFull ...
55  if( !nFullLen )
56  {
57  // Do not Init(), because we need height and ascent
58  Width(0);
59  return false;
60  }
61  return SwTextPortion::Format( rInf );
62 }
63 
64 void SwExpandPortion::Paint( const SwTextPaintInfo &rInf ) const
65 {
66  SwTextSlot aDiffText( &rInf, this, true, true );
67  const SwFont aOldFont = *rInf.GetFont();
68  if( GetJoinBorderWithPrev() )
69  const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetLeftBorder(nullptr);
70  if( GetJoinBorderWithNext() )
71  const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetRightBorder(nullptr);
72 
73  rInf.DrawBackBrush( *this );
74  rInf.DrawBorder( *this );
75 
76  // Do we have to repaint a post it portion?
77  if( rInf.OnWin() && mpNextPortion && !mpNextPortion->Width() )
78  mpNextPortion->PrePaint( rInf, this );
79 
80  // The contents of field portions is not considered during the
81  // calculation of the directions. Therefore we let vcl handle
82  // the calculation by removing the BIDI_STRONG_FLAG temporarily.
83  SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
84  aLayoutModeModifier.SetAuto();
85 
86  // ST2
87  if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
88  rInf.DrawMarkedText( *this, rInf.GetLen(), false,
89  nullptr != rInf.GetSmartTags(), nullptr != rInf.GetGrammarCheckList() );
90  else
91  rInf.DrawText( *this, rInf.GetLen() );
92 
94  *const_cast<SwTextPaintInfo&>(rInf).GetFont() = aOldFont;
95 }
96 
98 
105  TextFrameIndex const nIdx, bool bUnderflow)
106 {
107  if( rInf.StopUnderflow() )
108  return 0;
109  const SwLinePortion *pPos = rInf.GetRoot();
110  if( pPos->GetNextPortion() )
111  pPos = pPos->GetNextPortion();
112  while( pPos && pPos->IsBlankPortion() )
113  pPos = pPos->GetNextPortion();
114  if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
115  return 0; // There are just BlankPortions left
116 
117  // If a Blank is preceding us, we do not need to trigger underflow
118  // If a Blank is succeeding us, we do not need to pass on the underflow
119  if (bUnderflow
120  && nIdx + TextFrameIndex(1) < TextFrameIndex(rInf.GetText().getLength())
121  && CH_BLANK == rInf.GetText()[sal_Int32(nIdx) + 1])
122  {
123  return 0;
124  }
125  if( nIdx && !const_cast<SwTextFormatInfo&>(rInf).GetFly() )
126  {
127  while( pPos && !pPos->IsFlyPortion() )
128  pPos = pPos->GetNextPortion();
129  if( !pPos )
130  {
131  // We check to see if there are useful line breaks, blanks or fields etc. left
132  // In case there still are some, no underflow
133  // If there are Flys, we still allow the underflow
134  TextFrameIndex nBlank = nIdx;
135  while( --nBlank > rInf.GetLineStart() )
136  {
137  const sal_Unicode cCh = rInf.GetChar( nBlank );
138  if( CH_BLANK == cCh ||
139  (( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
140  && rInf.HasHint( nBlank ) ) )
141  break;
142  }
143  if( nBlank <= rInf.GetLineStart() )
144  return 0;
145  }
146  }
147  if (nIdx < TextFrameIndex(2))
148  return 1;
149  sal_Unicode const cCh(rInf.GetChar(nIdx - TextFrameIndex(1)));
150  if (CH_BLANK == cCh)
151  return 1;
152  if( CH_BREAK == cCh )
153  return 0;
154  return 2;
155 }
156 
161 {
162  sal_uInt16 nMay = MayUnderflow( rInf, rInf.GetIdx() - nLineLength, true );
163  if( nMay )
164  {
165  if( nMay > 1 )
166  {
167  if( rInf.GetLast() == this )
168  rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
169  rInf.X( rInf.X() - PrtWidth() );
170  rInf.SetIdx( rInf.GetIdx() - GetLen() );
171  }
172  Truncate();
173  rInf.SetUnderflow( this );
174  if( rInf.GetLast()->IsKernPortion() )
175  rInf.SetUnderflow( rInf.GetLast() );
176  }
177 }
178 
183 {
184  const bool bFull = rInf.IsUnderflow() || SwExpandPortion::Format( rInf );
185  if( bFull && MayUnderflow( rInf, rInf.GetIdx(), rInf.IsUnderflow() ) )
186  {
187  Truncate();
188  rInf.SetUnderflow( this );
189  if( rInf.GetLast()->IsKernPortion() )
190  rInf.SetUnderflow( rInf.GetLast() );
191  }
192  return bFull;
193 }
194 
195 void SwBlankPortion::Paint( const SwTextPaintInfo &rInf ) const
196 {
197  if( !m_bMulti ) // No gray background for multiportion brackets
198  rInf.DrawViewOpt( *this, PortionType::Blank );
199  SwExpandPortion::Paint( rInf );
200 }
201 
202 bool SwBlankPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) const
203 {
204  rText = OUString(m_cChar);
205  return true;
206 }
207 
209 {
210  rPH.Special( GetLen(), OUString( m_cChar ), GetWhichPor() );
211 }
212 
214  : bScript( bScrpt )
215 {
218 }
219 
220 void SwPostItsPortion::Paint( const SwTextPaintInfo &rInf ) const
221 {
222  if( rInf.OnWin() && Width() )
223  rInf.DrawPostIts( IsScript() );
224 }
225 
226 sal_uInt16 SwPostItsPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
227 {
228  // Unbelievable: PostIts are always visible
229  return rInf.OnWin() ? SwViewOption::GetPostItsWidth( rInf.GetOut() ) : 0;
230 }
231 
233 {
234  const bool bRet = SwLinePortion::Format( rInf );
235  // PostIts should not have an effect on line height etc.
236  SetAscent( 1 );
237  Height( 1 );
238  return bRet;
239 }
240 
241 bool SwPostItsPortion::GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const
242 {
243  if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
244  rText = " ";
245  else
246  rText.clear();
247  return true;
248 }
249 
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool Format(SwTextFormatInfo &rInf)
Definition: porlin.cxx:241
const sal_Unicode CH_BREAK
Definition: swfont.hxx:43
void DrawBackBrush(const SwLinePortion &rPor) const
Definition: inftxt.cxx:1123
virtual TextFrameIndex GetCursorOfst(sal_uInt16 nOfst) const override
the parameter is actually SwTwips apparently?
Definition: porexp.cxx:25
bool IsUnderflow() const
Definition: inftxt.hxx:588
sal_uInt16 Height() const
Definition: possiz.hxx:44
SwFont * GetFont()
Definition: inftxt.hxx:238
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:64
bool GetJoinBorderWithPrev() const
Definition: porlin.hxx:168
bool IsPostIts() const
Definition: viewopt.hxx:256
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
void SetLast(SwLinePortion *pNewLast)
Definition: inftxt.hxx:567
void DrawBorder(const SwLinePortion &rPor) const
Draw character border around a line portion.
Definition: inftxt.cxx:1270
sw::WrongListIterator * GetGrammarCheckList() const
Definition: inftxt.hxx:458
void DrawText(const OUString &rText, const SwLinePortion &rPor, TextFrameIndex nIdx=TextFrameIndex(0), TextFrameIndex nLen=TextFrameIndex(COMPLETE_STRING), const bool bKern=false) const
Definition: inftxt.hxx:746
void DrawPostIts(bool bScript) const
Definition: inftxt.cxx:1016
bool HasHint(TextFrameIndex nPos) const
Definition: inftxt.cxx:478
SwPosSize GetTextSize(OutputDevice *pOut, const SwScriptInfo *pSI, const OUString &rText, TextFrameIndex nIdx, TextFrameIndex nLen) const
Definition: inftxt.cxx:386
bool const m_bMulti
Definition: porexp.hxx:42
static sal_uInt16 GetPostItsWidth(const OutputDevice *pOut)
Definition: viewopt.cxx:128
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:43
sal_uInt16 sal_Unicode
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: porexp.cxx:36
sw::WrongListIterator * GetSmartTags() const
Definition: inftxt.hxx:461
#define CH_TXTATR_INWORD
Definition: hintids.hxx:44
sal_Unicode GetChar(TextFrameIndex const nPos) const
Definition: inftxt.hxx:247
static sal_uInt16 MayUnderflow(const SwTextFormatInfo &rInf, TextFrameIndex nIdx, bool bUnderflow)
If a Line is full of HardBlanks and overflows, we must not generate underflows! Causes problems with ...
Definition: porexp.cxx:104
SwPostItsPortion(bool bScrpt)
Definition: porexp.cxx:213
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:444
virtual SwLinePortion * Compress() override
Definition: porexp.cxx:97
TextFrameIndex GetLineStart() const
Definition: inftxt.hxx:595
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:28
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:220
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.
const SwViewOption & GetOpt() const
Definition: inftxt.hxx:245
virtual TextFrameIndex GetCursorOfst(sal_uInt16 nOfst) const
the parameter is actually SwTwips apparently?
Definition: porlin.cxx:226
TextFrameIndex nLineLength
Definition: porlin.hxx:56
vcl::RenderContext * GetOut()
Definition: inftxt.hxx:231
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:94
void SetUnderflow(SwLinePortion *pNew)
Definition: inftxt.hxx:606
bool IsFlyPortion() const
Definition: porlin.hxx:125
const sal_Unicode CH_BLANK
Definition: swfont.hxx:42
bool IsKernPortion() const
Definition: porlin.hxx:132
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:202
SwLineLayout * GetRoot()
Definition: inftxt.hxx:562
TextFrameIndex GetIdx() const
Definition: inftxt.hxx:278
void PrePaint(const SwTextPaintInfo &rInf, const SwLinePortion *pLast) const
Definition: porlin.cxx:81
TextFrameIndex GetLen() const
Definition: porlin.hxx:74
virtual bool Format(SwTextFormatInfo &rInf) override
Pass on the underflows and trigger them ourselves!
Definition: porexp.cxx:182
const OUString & GetText() const
Definition: inftxt.hxx:246
bool IsScript() const
Definition: porexp.hxx:69
void Truncate()
Definition: porlin.hxx:196
SwLinePortion * mpNextPortion
Definition: porlin.hxx:54
SwTwips X() const
Definition: inftxt.hxx:385
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:50
virtual sal_uInt16 GetViewWidth(const SwTextSizeInfo &rInf) const override
Definition: porexp.cxx:226
For the text replacement and restoration of SwTextSizeInfo.
Definition: inftxt.hxx:677
virtual void FormatEOL(SwTextFormatInfo &rInf) override
Format End of Line.
Definition: porexp.cxx:160
PortionType GetWhichPor() const
Definition: porlin.hxx:95
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:241
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:195
bool OnWin() const
Definition: inftxt.hxx:199
TextFrameIndex GetLen() const
Definition: inftxt.hxx:280
SwLinePortion * FindPrevPortion(const SwLinePortion *pRoot)
Definition: porlin.cxx:213
sal_uInt16 Width() const
Definition: possiz.hxx:46
SwLinePortion * GetLast()
Definition: inftxt.hxx:566
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: porexp.cxx:208
bool StopUnderflow() const
Definition: inftxt.hxx:204
void SetAscent(const sal_uInt16 nNewAsc)
Definition: porlin.hxx:79
sal_Unicode m_cChar
Definition: porexp.hxx:41
sal_uInt16 PrtWidth() const
Definition: porlin.hxx:81
bool GetJoinBorderWithNext() const
Definition: porlin.hxx:169
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 bool Format(SwTextFormatInfo &rInf) override
Definition: porexp.cxx:47
virtual SwPosSize GetTextSize(const SwTextSizeInfo &rInfo) const override
Definition: porexp.cxx:41
void DrawMarkedText(const SwLinePortion &rPor, TextFrameIndex nLen, const bool bWrong, const bool bSmartTags, const bool bGrammarCheck) const
Definition: inftxt.hxx:760
void DrawViewOpt(const SwLinePortion &rPor, PortionType nWhich) const
Definition: inftxt.cxx:1282
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: porexp.cxx:232
bool IsBlankPortion() const
Definition: porlin.hxx:113