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>
22#include <SwPortionHandler.hxx>
23#include "inftxt.hxx"
24#include "porexp.hxx"
25
28
29bool SwExpandPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) const
30{
31 rText.clear();
32 // Do not do: return 0 != rText.Len();
33 // Reason being: empty fields replace CH_TXTATR with an empty string
34 return true;
35}
36
38{
39 rPH.Special( GetLen(), OUString(), GetWhichPor() );
40}
41
42void SwExpandPortion::dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
43 TextFrameIndex& nOffset) const
44{
45 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwExpandPortion"));
46 dumpAsXmlAttributes(pWriter, rText, nOffset);
47 nOffset += GetLen();
48
49 (void)xmlTextWriterEndElement(pWriter);
50}
51
53{
54 SwTextSlot aDiffText( &rInf, this, false, false );
55 return rInf.GetTextSize();
56}
57
59{
60 SwTextSlot aDiffText( &rInf, this, true, false );
61 TextFrameIndex const nFullLen = rInf.GetLen();
62
63 // As odd as it may seem: the query for GetLen() must return
64 // false due to the ExpandPortions _after_ the aDiffText (see SoftHyphs)
65 // caused by the SetFull ...
66 if( !nFullLen )
67 {
68 // Do not Init(), because we need height and ascent
69 Width(0);
70 return false;
71 }
72 return SwTextPortion::Format( rInf );
73}
74
75void SwExpandPortion::Paint( const SwTextPaintInfo &rInf ) const
76{
77 rInf.DrawCSDFHighlighting(*this); // here it detects as CS and not DF
78
79 SwTextSlot aDiffText( &rInf, this, true, true );
80 const SwFont aOldFont = *rInf.GetFont();
82 const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetLeftBorder(nullptr);
84 const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetRightBorder(nullptr);
85// rInf.DrawCSDFHighlighting(*this); // here it detects as DF and only the '/' is detected as CS
86
87 rInf.DrawBackBrush( *this );
88 rInf.DrawBorder( *this );
89
90 // Do we have to repaint a post it portion?
91 if( rInf.OnWin() && mpNextPortion && !mpNextPortion->Width() )
92 mpNextPortion->PrePaint( rInf, this );
93
94 // The contents of field portions is not considered during the
95 // calculation of the directions. Therefore we let vcl handle
96 // the calculation by removing the BIDI_STRONG_FLAG temporarily.
97 SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
98 aLayoutModeModifier.SetAuto();
99
100 // ST2
101 if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
102 rInf.DrawMarkedText( *this, rInf.GetLen(), false,
103 nullptr != rInf.GetSmartTags(), nullptr != rInf.GetGrammarCheckList() );
104 else
105 rInf.DrawText( *this, rInf.GetLen() );
106
108 *const_cast<SwTextPaintInfo&>(rInf).GetFont() = aOldFont;
109}
110
112
119 TextFrameIndex const nIdx, bool bUnderflow)
120{
121 if( rInf.StopUnderflow() )
122 return 0;
123 const SwLinePortion *pPos = rInf.GetRoot();
124 if( pPos->GetNextPortion() )
125 pPos = pPos->GetNextPortion();
126 while( pPos && pPos->IsBlankPortion() )
127 pPos = pPos->GetNextPortion();
128 if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
129 return 0; // There are just BlankPortions left
130
131 // If a Blank is preceding us, we do not need to trigger underflow
132 // If a Blank is succeeding us, we do not need to pass on the underflow
133 if (bUnderflow
134 && nIdx + TextFrameIndex(1) < TextFrameIndex(rInf.GetText().getLength())
135 && CH_BLANK == rInf.GetText()[sal_Int32(nIdx) + 1])
136 {
137 return 0;
138 }
139 if( nIdx && !const_cast<SwTextFormatInfo&>(rInf).GetFly() )
140 {
141 while( pPos && !pPos->IsFlyPortion() )
142 pPos = pPos->GetNextPortion();
143 if( !pPos )
144 {
145 // We check to see if there are useful line breaks, blanks or fields etc. left
146 // In case there still are some, no underflow
147 // If there are Flys, we still allow the underflow
148 TextFrameIndex nBlank = nIdx;
149 while( --nBlank > rInf.GetLineStart() )
150 {
151 const sal_Unicode cCh = rInf.GetChar( nBlank );
152 if( CH_BLANK == cCh ||
153 (( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
154 && rInf.HasHint( nBlank ) ) )
155 break;
156 }
157 if( nBlank <= rInf.GetLineStart() )
158 return 0;
159 }
160 }
161 if (nIdx < TextFrameIndex(2))
162 return 1;
163 sal_Unicode const cCh(rInf.GetChar(nIdx - TextFrameIndex(1)));
164 if (CH_BLANK == cCh)
165 return 1;
166 if( CH_BREAK == cCh )
167 return 0;
168 return 2;
169}
170
175{
176 sal_uInt16 nMay = MayUnderflow( rInf, rInf.GetIdx() - mnLineLength, true );
177 if( !nMay )
178 return;
179
180 if( nMay > 1 )
181 {
182 if( rInf.GetLast() == this )
183 rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
184 rInf.X( rInf.X() - PrtWidth() );
185 rInf.SetIdx( rInf.GetIdx() - GetLen() );
186 }
187 Truncate();
188 rInf.SetUnderflow( this );
189 if( rInf.GetLast()->IsKernPortion() )
190 rInf.SetUnderflow( rInf.GetLast() );
191}
192
197{
198 const bool bFull = rInf.IsUnderflow() || SwExpandPortion::Format( rInf );
199 if( bFull && MayUnderflow( rInf, rInf.GetIdx(), rInf.IsUnderflow() ) )
200 {
201 Truncate();
202 rInf.SetUnderflow( this );
203 if( rInf.GetLast()->IsKernPortion() )
204 rInf.SetUnderflow( rInf.GetLast() );
205 }
206 return bFull;
207}
208
209void SwBlankPortion::Paint( const SwTextPaintInfo &rInf ) const
210{
211 // Draw field shade (can be disabled individually)
212 if (!m_bMulti) // No gray background for multiportion brackets
213 rInf.DrawViewOpt(*this, PortionType::Blank);
214
215 if (m_cChar == CHAR_HARDBLANK)
216 {
217 if (rInf.GetOpt().IsBlank())
218 {
219 // Draw tilde or degree sign
220 OUString aMarker = (rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess()
222 ? u"~"
223 : u"°");
224
225 SwPosSize aMarkerSize(rInf.GetTextSize(aMarker));
226 Point aPos(rInf.GetPos());
227
228 std::shared_ptr<SwRect> pPortionRect = std::make_shared<SwRect>();
229 rInf.CalcRect(*this, pPortionRect.get());
230 aPos.AdjustX((pPortionRect->Width() / 2) - (aMarkerSize.Width() / 2));
231
232 SwTextPaintInfo aInf(rInf, &aMarker);
233 aInf.SetPos(aPos);
234 SwTextPortion aMarkerPor;
235 aMarkerPor.Width(aMarkerSize.Width());
236 aMarkerPor.Height(aMarkerSize.Height());
237 aMarkerPor.SetAscent(GetAscent());
238
239 Color colorBackup = aInf.GetFont()->GetColor();
241 aInf.DrawText(aMarkerPor, TextFrameIndex(aMarker.getLength()), true);
242 aInf.GetFont()->SetColor(colorBackup);
243 }
244 }
245 else
246 {
248 }
249}
250
251bool SwBlankPortion::GetExpText( const SwTextSizeInfo& rInf, OUString &rText ) const
252{
256 rText = OUString(CH_BLANK);
257 else
258 rText = OUString(m_cChar);
259
260 return true;
261}
262
264{
265 rPH.Special( GetLen(), OUString( m_cChar ), GetWhichPor() );
266}
267
268void SwBlankPortion::dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
269 TextFrameIndex& nOffset) const
270{
271 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwBlankPortion"));
272 dumpAsXmlAttributes(pWriter, rText, nOffset);
273 nOffset += GetLen();
274
275 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("char"),
276 BAD_CAST(OUString(m_cChar).toUtf8().getStr()));
277 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("multi"),
278 BAD_CAST(OString::boolean(m_bMulti).getStr()));
279
280 (void)xmlTextWriterEndElement(pWriter);
281}
282
284 : m_bScript( bScrpt )
285{
288}
289
291{
292 if( rInf.OnWin() && Width() )
293 rInf.DrawPostIts( IsScript() );
294}
295
296sal_uInt16 SwPostItsPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
297{
298 // Unbelievable: PostIts are always visible
299 return rInf.OnWin() ? SwViewOption::GetPostItsWidth( rInf.GetOut() ) : 0;
300}
301
303{
304 const bool bRet = SwLinePortion::Format( rInf );
305 // PostIts should not have an effect on line height etc.
306 SetAscent( 1 );
307 Height( 1 );
308 return bRet;
309}
310
311bool SwPostItsPortion::GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const
312{
313 if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
314 rText = " ";
315 else
316 rText.clear();
317 return true;
318}
319
320/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 get(DocumentSettingId id) const =0
Return the specified document setting.
tools::Long AdjustX(tools::Long nHorzMove)
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:251
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: porexp.cxx:263
virtual void FormatEOL(SwTextFormatInfo &rInf) override
Format End of Line.
Definition: porexp.cxx:174
bool m_bMulti
Definition: porexp.hxx:45
void dumpAsXml(xmlTextWriterPtr pWriter, const OUString &rText, TextFrameIndex &nOffset) const override
Definition: porexp.cxx:268
virtual bool Format(SwTextFormatInfo &rInf) override
Pass on the underflows and trigger them ourselves!
Definition: porexp.cxx:196
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:118
virtual SwLinePortion * Compress() override
Definition: porexp.cxx:111
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:209
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:190
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:75
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:29
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: porexp.cxx:58
void dumpAsXml(xmlTextWriterPtr pWriter, const OUString &rText, TextFrameIndex &nOffset) const override
Definition: porexp.cxx:42
virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const override
the parameter is actually SwTwips apparently?
Definition: porexp.cxx:26
virtual SwPosSize GetTextSize(const SwTextSizeInfo &rInfo) const override
Definition: porexp.cxx:52
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: porexp.cxx:37
To take Asian or other languages into consideration, an SwFont object consists of 3 SwSubFonts (Latin...
Definition: swfont.hxx:135
void SetRightBorder(const editeng::SvxBorderLine *pRightBorder)
Definition: swfont.cxx:97
void SetColor(const Color &rColor)
Definition: swfont.hxx:421
const Color & GetColor() const
Definition: swfont.hxx:280
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:333
SwLinePortion * mpNextPortion
Definition: porlin.hxx:55
virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const
the parameter is actually SwTwips apparently?
Definition: porlin.cxx:226
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
SwTwips & GetAscent()
Definition: porlin.hxx:80
SwLinePortion * FindPrevPortion(const SwLinePortion *pRoot)
Definition: porlin.cxx:213
bool IsFlyPortion() const
Definition: porlin.hxx:134
SwTwips PrtWidth() const
Definition: porlin.hxx:84
virtual bool Format(SwTextFormatInfo &rInf)
Definition: porlin.cxx:241
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:296
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porexp.cxx:311
SwPostItsPortion(bool bScrpt)
Definition: porexp.cxx:283
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: porexp.cxx:302
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: porexp.cxx:290
SwLinePortion * GetLast()
Definition: inftxt.hxx:566
SwLineLayout * GetRoot()
Definition: inftxt.hxx:562
TextFrameIndex GetLineStart() const
Definition: inftxt.hxx:595
bool IsUnderflow() const
Definition: inftxt.hxx:588
void SetLast(SwLinePortion *pNewLast)
Definition: inftxt.hxx:567
void SetUnderflow(SwLinePortion *pNew)
Definition: inftxt.hxx:606
SwDoc & GetDoc()
Definition: txtfrm.hxx:475
void DrawCSDFHighlighting(const SwLinePortion &rPor) const
Definition: inftxt.cxx:1336
void DrawMarkedText(const SwLinePortion &rPor, TextFrameIndex nLen, const bool bWrong, const bool bSmartTags, const bool bGrammarCheck) const
Definition: inftxt.hxx:767
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:753
SwTwips X() const
Definition: inftxt.hxx:382
void SetPos(const Point &rNew)
Definition: inftxt.hxx:435
const Point & GetPos() const
Definition: inftxt.hxx:434
void CalcRect(const SwLinePortion &rPor, SwRect *pRect, SwRect *pIntersect=nullptr, const bool bInsideBox=false) const
Calculate the rectangular area where the portion takes place.
Definition: inftxt.cxx:735
void DrawBackBrush(const SwLinePortion &rPor) const
Definition: inftxt.cxx:1158
sw::WrongListIterator * GetGrammarCheckList() const
Definition: inftxt.hxx:457
void DrawPostIts(bool bScript) const
Definition: inftxt.cxx:1056
void DrawViewOpt(const SwLinePortion &rPor, PortionType nWhich, const Color *pColor=nullptr) const
Definition: inftxt.cxx:1470
void DrawBorder(const SwLinePortion &rPor) const
Draw character border around a line portion.
Definition: inftxt.cxx:1291
sw::WrongListIterator * GetSmartTags() const
Definition: inftxt.hxx:460
This portion represents a part of the paragraph string.
Definition: portxt.hxx:27
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:442
SwTextFrame * GetTextFrame()
Definition: inftxt.hxx:288
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:395
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:488
For the text replacement and restoration of SwTextSizeInfo.
Definition: inftxt.hxx:680
bool IsBlank(bool bHard=false) const
Definition: viewopt.hxx:351
bool IsPostIts() const
Definition: viewopt.hxx:425
static sal_uInt16 GetPostItsWidth(const OutputDevice *pOut)
Definition: viewopt.cxx:214
struct _xmlTextWriter * xmlTextWriterPtr
float u
#define CH_TXTATR_INWORD
Definition: hintids.hxx:175
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:174
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
#define CHAR_HARDBLANK
Definition: swtypes.hxx:173
#define NON_PRINTING_CHARACTER_COLOR
Definition: txtfrm.hxx:57
sal_uInt16 sal_Unicode