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
27
28bool 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
41void SwExpandPortion::dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
42 TextFrameIndex& nOffset) const
43{
44 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwExpandPortion"));
45 dumpAsXmlAttributes(pWriter, rText, nOffset);
46 nOffset += GetLen();
47
48 (void)xmlTextWriterEndElement(pWriter);
49}
50
52{
53 SwTextSlot aDiffText( &rInf, this, false, false );
54 return rInf.GetTextSize();
55}
56
58{
59 SwTextSlot aDiffText( &rInf, this, true, false );
60 TextFrameIndex const nFullLen = rInf.GetLen();
61
62 // As odd as it may seem: the query for GetLen() must return
63 // false due to the ExpandPortions _after_ the aDiffText (see SoftHyphs)
64 // caused by the SetFull ...
65 if( !nFullLen )
66 {
67 // Do not Init(), because we need height and ascent
68 Width(0);
69 return false;
70 }
71 return SwTextPortion::Format( rInf );
72}
73
74void SwExpandPortion::Paint( const SwTextPaintInfo &rInf ) const
75{
76 SwTextSlot aDiffText( &rInf, this, true, true );
77 const SwFont aOldFont = *rInf.GetFont();
79 const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetLeftBorder(nullptr);
81 const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetRightBorder(nullptr);
82
83 rInf.DrawBackBrush( *this );
84 rInf.DrawBorder( *this );
85
86 // Do we have to repaint a post it portion?
87 if( rInf.OnWin() && mpNextPortion && !mpNextPortion->Width() )
88 mpNextPortion->PrePaint( rInf, this );
89
90 // The contents of field portions is not considered during the
91 // calculation of the directions. Therefore we let vcl handle
92 // the calculation by removing the BIDI_STRONG_FLAG temporarily.
93 SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
94 aLayoutModeModifier.SetAuto();
95
96 // ST2
97 if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
98 rInf.DrawMarkedText( *this, rInf.GetLen(), false,
99 nullptr != rInf.GetSmartTags(), nullptr != rInf.GetGrammarCheckList() );
100 else
101 rInf.DrawText( *this, rInf.GetLen() );
102
104 *const_cast<SwTextPaintInfo&>(rInf).GetFont() = aOldFont;
105}
106
108
115 TextFrameIndex const nIdx, bool bUnderflow)
116{
117 if( rInf.StopUnderflow() )
118 return 0;
119 const SwLinePortion *pPos = rInf.GetRoot();
120 if( pPos->GetNextPortion() )
121 pPos = pPos->GetNextPortion();
122 while( pPos && pPos->IsBlankPortion() )
123 pPos = pPos->GetNextPortion();
124 if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
125 return 0; // There are just BlankPortions left
126
127 // If a Blank is preceding us, we do not need to trigger underflow
128 // If a Blank is succeeding us, we do not need to pass on the underflow
129 if (bUnderflow
130 && nIdx + TextFrameIndex(1) < TextFrameIndex(rInf.GetText().getLength())
131 && CH_BLANK == rInf.GetText()[sal_Int32(nIdx) + 1])
132 {
133 return 0;
134 }
135 if( nIdx && !const_cast<SwTextFormatInfo&>(rInf).GetFly() )
136 {
137 while( pPos && !pPos->IsFlyPortion() )
138 pPos = pPos->GetNextPortion();
139 if( !pPos )
140 {
141 // We check to see if there are useful line breaks, blanks or fields etc. left
142 // In case there still are some, no underflow
143 // If there are Flys, we still allow the underflow
144 TextFrameIndex nBlank = nIdx;
145 while( --nBlank > rInf.GetLineStart() )
146 {
147 const sal_Unicode cCh = rInf.GetChar( nBlank );
148 if( CH_BLANK == cCh ||
149 (( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
150 && rInf.HasHint( nBlank ) ) )
151 break;
152 }
153 if( nBlank <= rInf.GetLineStart() )
154 return 0;
155 }
156 }
157 if (nIdx < TextFrameIndex(2))
158 return 1;
159 sal_Unicode const cCh(rInf.GetChar(nIdx - TextFrameIndex(1)));
160 if (CH_BLANK == cCh)
161 return 1;
162 if( CH_BREAK == cCh )
163 return 0;
164 return 2;
165}
166
171{
172 sal_uInt16 nMay = MayUnderflow( rInf, rInf.GetIdx() - mnLineLength, true );
173 if( !nMay )
174 return;
175
176 if( nMay > 1 )
177 {
178 if( rInf.GetLast() == this )
179 rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
180 rInf.X( rInf.X() - PrtWidth() );
181 rInf.SetIdx( rInf.GetIdx() - GetLen() );
182 }
183 Truncate();
184 rInf.SetUnderflow( this );
185 if( rInf.GetLast()->IsKernPortion() )
186 rInf.SetUnderflow( rInf.GetLast() );
187}
188
193{
194 const bool bFull = rInf.IsUnderflow() || SwExpandPortion::Format( rInf );
195 if( bFull && MayUnderflow( rInf, rInf.GetIdx(), rInf.IsUnderflow() ) )
196 {
197 Truncate();
198 rInf.SetUnderflow( this );
199 if( rInf.GetLast()->IsKernPortion() )
200 rInf.SetUnderflow( rInf.GetLast() );
201 }
202 return bFull;
203}
204
205void SwBlankPortion::Paint( const SwTextPaintInfo &rInf ) const
206{
207 if( !m_bMulti ) // No gray background for multiportion brackets
208 rInf.DrawViewOpt( *this, PortionType::Blank );
210}
211
212bool SwBlankPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) const
213{
214 rText = OUString(m_cChar);
215 return true;
216}
217
219{
220 rPH.Special( GetLen(), OUString( m_cChar ), GetWhichPor() );
221}
222
223void SwBlankPortion::dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
224 TextFrameIndex& nOffset) const
225{
226 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwBlankPortion"));
227 dumpAsXmlAttributes(pWriter, rText, nOffset);
228 nOffset += GetLen();
229
230 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("char"),
231 BAD_CAST(OUString(m_cChar).toUtf8().getStr()));
232 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("multi"),
233 BAD_CAST(OString::boolean(m_bMulti).getStr()));
234
235 (void)xmlTextWriterEndElement(pWriter);
236}
237
239 : m_bScript( bScrpt )
240{
243}
244
246{
247 if( rInf.OnWin() && Width() )
248 rInf.DrawPostIts( IsScript() );
249}
250
251sal_uInt16 SwPostItsPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
252{
253 // Unbelievable: PostIts are always visible
254 return rInf.OnWin() ? SwViewOption::GetPostItsWidth( rInf.GetOut() ) : 0;
255}
256
258{
259 const bool bRet = SwLinePortion::Format( rInf );
260 // PostIts should not have an effect on line height etc.
261 SetAscent( 1 );
262 Height( 1 );
263 return bRet;
264}
265
266bool SwPostItsPortion::GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const
267{
268 if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
269 rText = " ";
270 else
271 rText.clear();
272 return true;
273}
274
275/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
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 GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:212
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: porexp.cxx:218
virtual void FormatEOL(SwTextFormatInfo &rInf) override
Format End of Line.
Definition: porexp.cxx:170
bool m_bMulti
Definition: porexp.hxx:45
void dumpAsXml(xmlTextWriterPtr pWriter, const OUString &rText, TextFrameIndex &nOffset) const override
Definition: porexp.cxx:223
virtual bool Format(SwTextFormatInfo &rInf) override
Pass on the underflows and trigger them ourselves!
Definition: porexp.cxx:192
sal_Unicode m_cChar
Definition: porexp.hxx:44
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:114
virtual SwLinePortion * Compress() override
Definition: porexp.cxx:107
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:205
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:74
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:28
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: porexp.cxx:57
void dumpAsXml(xmlTextWriterPtr pWriter, const OUString &rText, TextFrameIndex &nOffset) const override
Definition: porexp.cxx:41
virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const override
the parameter is actually SwTwips apparently?
Definition: porexp.cxx:25
virtual SwPosSize GetTextSize(const SwTextSizeInfo &rInfo) const override
Definition: porexp.cxx:51
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: porexp.cxx:36
void SetRightBorder(const editeng::SvxBorderLine *pRightBorder)
Definition: swfont.cxx:97
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:52
TextFrameIndex mnLineLength
Definition: porlin.hxx:57
bool IsBlankPortion() const
Definition: porlin.hxx:120
void dumpAsXmlAttributes(xmlTextWriterPtr writer, std::u16string_view rText, TextFrameIndex nOffset) const
Definition: porlin.cxx:330
SwLinePortion * mpNextPortion
Definition: porlin.hxx:55
virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const
the parameter is actually SwTwips apparently?
Definition: porlin.cxx:223
SwLinePortion * GetNextPortion() const
Definition: porlin.hxx:75
void SetAscent(const SwTwips nNewAsc)
Definition: porlin.hxx:82
bool GetJoinBorderWithPrev() const
Definition: porlin.hxx:177
PortionType GetWhichPor() const
Definition: porlin.hxx:102
TextFrameIndex GetLen() const
Definition: porlin.hxx:77
bool IsKernPortion() const
Definition: porlin.hxx:141
bool GetJoinBorderWithNext() const
Definition: porlin.hxx:178
void Truncate()
Definition: porlin.hxx:214
SwLinePortion * FindPrevPortion(const SwLinePortion *pRoot)
Definition: porlin.cxx:210
bool IsFlyPortion() const
Definition: porlin.hxx:134
SwTwips PrtWidth() const
Definition: porlin.hxx:84
virtual bool Format(SwTextFormatInfo &rInf)
Definition: porlin.cxx:238
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:101
void PrePaint(const SwTextPaintInfo &rInf, const SwLinePortion *pLast) const
Definition: porlin.cxx:77
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
virtual void Special(TextFrameIndex nLength, const OUString &rText, PortionType nType)=0
special portion.
SwTwips Width() const
Definition: possiz.hxx:51
SwTwips Height() const
Definition: possiz.hxx:49
bool IsScript() const
Definition: porexp.hxx:75
virtual sal_uInt16 GetViewWidth(const SwTextSizeInfo &rInf) const override
Definition: porexp.cxx:251
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:266
SwPostItsPortion(bool bScrpt)
Definition: porexp.cxx:238
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: porexp.cxx:257
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:245
SwLinePortion * GetLast()
Definition: inftxt.hxx:564
SwLineLayout * GetRoot()
Definition: inftxt.hxx:560
TextFrameIndex GetLineStart() const
Definition: inftxt.hxx:593
bool IsUnderflow() const
Definition: inftxt.hxx:586
void SetLast(SwLinePortion *pNewLast)
Definition: inftxt.hxx:565
void SetUnderflow(SwLinePortion *pNew)
Definition: inftxt.hxx:604
void DrawMarkedText(const SwLinePortion &rPor, TextFrameIndex nLen, const bool bWrong, const bool bSmartTags, const bool bGrammarCheck) const
Definition: inftxt.hxx:765
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:751
SwTwips X() const
Definition: inftxt.hxx:382
void DrawBackBrush(const SwLinePortion &rPor) const
Definition: inftxt.cxx:1146
sw::WrongListIterator * GetGrammarCheckList() const
Definition: inftxt.hxx:455
void DrawPostIts(bool bScript) const
Definition: inftxt.cxx:1044
void DrawViewOpt(const SwLinePortion &rPor, PortionType nWhich, const Color *pColor=nullptr) const
Definition: inftxt.cxx:1308
void DrawBorder(const SwLinePortion &rPor) const
Draw character border around a line portion.
Definition: inftxt.cxx:1296
sw::WrongListIterator * GetSmartTags() const
Definition: inftxt.hxx:458
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:445
vcl::RenderContext * GetOut()
Definition: inftxt.hxx:225
const SwViewOption & GetOpt() const
Definition: inftxt.hxx:239
SwFont * GetFont()
Definition: inftxt.hxx:232
bool OnWin() const
Definition: inftxt.hxx:193
void SetIdx(const TextFrameIndex nNew)
Definition: inftxt.hxx:274
SwPosSize GetTextSize(OutputDevice *pOut, const SwScriptInfo *pSI, const OUString &rText, TextFrameIndex nIdx, TextFrameIndex nLen) const
Definition: inftxt.cxx:385
bool StopUnderflow() const
Definition: inftxt.hxx:198
sal_Unicode GetChar(TextFrameIndex const nPos) const
Definition: inftxt.hxx:241
TextFrameIndex GetLen() const
Definition: inftxt.hxx:275
const OUString & GetText() const
Definition: inftxt.hxx:240
TextFrameIndex GetIdx() const
Definition: inftxt.hxx:273
bool HasHint(TextFrameIndex nPos) const
Definition: inftxt.cxx:478
For the text replacement and restoration of SwTextSizeInfo.
Definition: inftxt.hxx:678
bool IsPostIts() const
Definition: viewopt.hxx:369
static sal_uInt16 GetPostItsWidth(const OutputDevice *pOut)
Definition: viewopt.cxx:137
#define CH_TXTATR_INWORD
Definition: hintids.hxx:171
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:170
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
const sal_Unicode CH_BREAK
Definition: swfont.hxx:43
const sal_Unicode CH_BLANK
Definition: swfont.hxx:42
sal_uInt16 sal_Unicode