1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <viewopt.hxx>
21 #include <SwPortionHandler.hxx>
25 TextFrameIndex
SwExpandPortion::GetModelPositionForViewPoint(const sal_uInt16 nOfst
) const
26 { return SwLinePortion::GetModelPositionForViewPoint( nOfst
); }
28 bool SwExpandPortion::GetExpText( const SwTextSizeInfo
&, OUString
&rText
) const
31 // Do not do: return 0 != rText.Len();
32 // Reason being: empty fields replace CH_TXTATR with an empty string
36 void SwExpandPortion::HandlePortion( SwPortionHandler
& rPH
) const
38 rPH
.Special( GetLen(), OUString(), GetWhichPor() );
41 void SwExpandPortion::dumpAsXml(xmlTextWriterPtr pWriter
, const OUString
& rText
,
42 TextFrameIndex
& nOffset
) const
44 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwExpandPortion"));
45 dumpAsXmlAttributes(pWriter
, rText
, nOffset
);
48 (void)xmlTextWriterEndElement(pWriter
);
51 SwPosSize
SwExpandPortion::GetTextSize( const SwTextSizeInfo
&rInf
) const
53 SwTextSlot
aDiffText( &rInf
, this, false, false );
54 return rInf
.GetTextSize();
57 bool SwExpandPortion::Format( SwTextFormatInfo
&rInf
)
59 SwTextSlot
aDiffText( &rInf
, this, true, false );
60 TextFrameIndex
const nFullLen
= rInf
.GetLen();
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 ...
67 // Do not Init(), because we need height and ascent
71 return SwTextPortion::Format( rInf
);
74 void SwExpandPortion::Paint( const SwTextPaintInfo
&rInf
) const
76 rInf
.DrawCSDFHighlighting(*this); // here it detects as CS and not DF
78 SwTextSlot
aDiffText( &rInf
, this, true, true );
79 const SwFont aOldFont
= *rInf
.GetFont();
80 if( GetJoinBorderWithPrev() )
81 const_cast<SwTextPaintInfo
&>(rInf
).GetFont()->SetLeftBorder(nullptr);
82 if( GetJoinBorderWithNext() )
83 const_cast<SwTextPaintInfo
&>(rInf
).GetFont()->SetRightBorder(nullptr);
84 // rInf.DrawCSDFHighlighting(*this); // here it detects as DF and only the '/' is detected as CS
86 rInf
.DrawBackBrush( *this );
87 rInf
.DrawBorder( *this );
89 // Do we have to repaint a post it portion?
90 if( rInf
.OnWin() && mpNextPortion
&& !mpNextPortion
->Width() )
91 mpNextPortion
->PrePaint( rInf
, this );
93 // The contents of field portions is not considered during the
94 // calculation of the directions. Therefore we let vcl handle
95 // the calculation by removing the BIDI_STRONG_FLAG temporarily.
96 SwLayoutModeModifier
aLayoutModeModifier( *rInf
.GetOut() );
97 aLayoutModeModifier
.SetAuto();
100 if ( rInf
.GetSmartTags() || rInf
.GetGrammarCheckList() )
101 rInf
.DrawMarkedText( *this, rInf
.GetLen(), false,
102 nullptr != rInf
.GetSmartTags(), nullptr != rInf
.GetGrammarCheckList() );
104 rInf
.DrawText( *this, rInf
.GetLen() );
106 if( GetJoinBorderWithPrev() || GetJoinBorderWithNext() )
107 *const_cast<SwTextPaintInfo
&>(rInf
).GetFont() = aOldFont
;
110 SwLinePortion
*SwBlankPortion::Compress() { return this; }
113 * If a Line is full of HardBlanks and overflows, we must not generate
115 * Causes problems with Fly
117 sal_uInt16
SwBlankPortion::MayUnderflow( const SwTextFormatInfo
&rInf
,
118 TextFrameIndex
const nIdx
, bool bUnderflow
)
120 if( rInf
.StopUnderflow() )
122 const SwLinePortion
*pPos
= rInf
.GetRoot();
123 if( pPos
->GetNextPortion() )
124 pPos
= pPos
->GetNextPortion();
125 while( pPos
&& pPos
->IsBlankPortion() )
126 pPos
= pPos
->GetNextPortion();
127 if( !pPos
|| !rInf
.GetIdx() || ( !pPos
->GetLen() && pPos
== rInf
.GetRoot() ) )
128 return 0; // There are just BlankPortions left
130 // If a Blank is preceding us, we do not need to trigger underflow
131 // If a Blank is succeeding us, we do not need to pass on the underflow
133 && nIdx
+ TextFrameIndex(1) < TextFrameIndex(rInf
.GetText().getLength())
134 && CH_BLANK
== rInf
.GetText()[sal_Int32(nIdx
) + 1])
138 if( nIdx
&& !const_cast<SwTextFormatInfo
&>(rInf
).GetFly() )
140 while( pPos
&& !pPos
->IsFlyPortion() )
141 pPos
= pPos
->GetNextPortion();
144 // We check to see if there are useful line breaks, blanks or fields etc. left
145 // In case there still are some, no underflow
146 // If there are Flys, we still allow the underflow
147 TextFrameIndex nBlank
= nIdx
;
148 while( --nBlank
> rInf
.GetLineStart() )
150 const sal_Unicode cCh
= rInf
.GetChar( nBlank
);
151 if( CH_BLANK
== cCh
||
152 (( CH_TXTATR_BREAKWORD
== cCh
|| CH_TXTATR_INWORD
== cCh
)
153 && rInf
.HasHint( nBlank
) ) )
156 if( nBlank
<= rInf
.GetLineStart() )
160 if (nIdx
< TextFrameIndex(2))
162 sal_Unicode
const cCh(rInf
.GetChar(nIdx
- TextFrameIndex(1)));
165 if( CH_BREAK
== cCh
)
173 void SwBlankPortion::FormatEOL( SwTextFormatInfo
&rInf
)
175 sal_uInt16 nMay
= MayUnderflow( rInf
, rInf
.GetIdx() - mnLineLength
, true );
181 if( rInf
.GetLast() == this )
182 rInf
.SetLast( FindPrevPortion( rInf
.GetRoot() ) );
183 rInf
.X( rInf
.X() - PrtWidth() );
184 rInf
.SetIdx( rInf
.GetIdx() - GetLen() );
187 rInf
.SetUnderflow( this );
188 if( rInf
.GetLast()->IsKernPortion() )
189 rInf
.SetUnderflow( rInf
.GetLast() );
193 * Pass on the underflows and trigger them ourselves!
195 bool SwBlankPortion::Format( SwTextFormatInfo
&rInf
)
197 const bool bFull
= rInf
.IsUnderflow() || SwExpandPortion::Format( rInf
);
198 if( bFull
&& MayUnderflow( rInf
, rInf
.GetIdx(), rInf
.IsUnderflow() ) )
201 rInf
.SetUnderflow( this );
202 if( rInf
.GetLast()->IsKernPortion() )
203 rInf
.SetUnderflow( rInf
.GetLast() );
208 void SwBlankPortion::Paint( const SwTextPaintInfo
&rInf
) const
210 // Draw field shade (can be disabled individually)
211 if (!m_bMulti
) // No gray background for multiportion brackets
212 rInf
.DrawViewOpt(*this, PortionType::Blank
);
214 if (m_cChar
== CHAR_HARDBLANK
)
216 if (rInf
.GetOpt().IsBlank())
219 OUString aMarker
= u
"°";
221 SwPosSize
aMarkerSize(rInf
.GetTextSize(aMarker
));
222 Point
aPos(rInf
.GetPos());
224 std::shared_ptr
<SwRect
> pPortionRect
= std::make_shared
<SwRect
>();
225 rInf
.CalcRect(*this, pPortionRect
.get());
226 aPos
.AdjustX((pPortionRect
->Width() / 2) - (aMarkerSize
.Width() / 2));
228 SwTextPaintInfo
aInf(rInf
, &aMarker
);
230 SwTextPortion aMarkerPor
;
231 aMarkerPor
.Width(aMarkerSize
.Width());
232 aMarkerPor
.Height(aMarkerSize
.Height());
233 aMarkerPor
.SetAscent(GetAscent());
235 Color colorBackup
= aInf
.GetFont()->GetColor();
236 aInf
.GetFont()->SetColor(NON_PRINTING_CHARACTER_COLOR
);
237 aInf
.DrawText(aMarkerPor
, TextFrameIndex(aMarker
.getLength()), true);
238 aInf
.GetFont()->SetColor(colorBackup
);
243 SwExpandPortion::Paint(rInf
);
247 bool SwBlankPortion::GetExpText( const SwTextSizeInfo
& /*rInf*/, OUString
&rText
) const
249 rText
= OUString(m_cChar
);
254 void SwBlankPortion::HandlePortion( SwPortionHandler
& rPH
) const
256 rPH
.Special( GetLen(), OUString( m_cChar
), GetWhichPor() );
259 void SwBlankPortion::dumpAsXml(xmlTextWriterPtr pWriter
, const OUString
& rText
,
260 TextFrameIndex
& nOffset
) const
262 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwBlankPortion"));
263 dumpAsXmlAttributes(pWriter
, rText
, nOffset
);
266 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("char"),
267 BAD_CAST(OUString(m_cChar
).toUtf8().getStr()));
268 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("multi"),
269 BAD_CAST(OString::boolean(m_bMulti
).getStr()));
271 (void)xmlTextWriterEndElement(pWriter
);
274 SwPostItsPortion::SwPostItsPortion( bool bScrpt
)
275 : m_bScript( bScrpt
)
277 mnLineLength
= TextFrameIndex(1);
278 SetWhichPor( PortionType::PostIts
);
281 void SwPostItsPortion::Paint( const SwTextPaintInfo
&rInf
) const
283 if( rInf
.OnWin() && Width() )
284 rInf
.DrawPostIts( IsScript() );
287 sal_uInt16
SwPostItsPortion::GetViewWidth( const SwTextSizeInfo
&rInf
) const
289 // Unbelievable: PostIts are always visible
290 return rInf
.OnWin() ? SwViewOption::GetPostItsWidth( rInf
.GetOut() ) : 0;
293 bool SwPostItsPortion::Format( SwTextFormatInfo
&rInf
)
295 const bool bRet
= SwLinePortion::Format( rInf
);
296 // PostIts should not have an effect on line height etc.
302 bool SwPostItsPortion::GetExpText( const SwTextSizeInfo
&rInf
, OUString
&rText
) const
304 if( rInf
.OnWin() && rInf
.GetOpt().IsPostIts() )
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */