1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <viewopt.hxx>
#include <SwPortionHandler.hxx>
#include "inftxt.hxx"
#include "porexp.hxx"
TextFrameIndex SwExpandPortion::GetModelPositionForViewPoint(const sal_uInt16 nOfst) const
{ return SwLinePortion::GetModelPositionForViewPoint( nOfst ); }
bool SwExpandPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) const
{
rText.clear();
// Do not do: return 0 != rText.Len();
// Reason being: empty fields replace CH_TXTATR with an empty string
return true;
}
void SwExpandPortion::HandlePortion( SwPortionHandler& rPH ) const
{
rPH.Special( GetLen(), OUString(), GetWhichPor() );
}
void SwExpandPortion::dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
TextFrameIndex& nOffset) const
{
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwExpandPortion"));
dumpAsXmlAttributes(pWriter, rText, nOffset);
nOffset += GetLen();
(void)xmlTextWriterEndElement(pWriter);
}
SwPosSize SwExpandPortion::GetTextSize( const SwTextSizeInfo &rInf ) const
{
SwTextSlot aDiffText( &rInf, this, false, false );
return rInf.GetTextSize();
}
bool SwExpandPortion::Format( SwTextFormatInfo &rInf )
{
SwTextSlot aDiffText( &rInf, this, true, false );
TextFrameIndex const nFullLen = rInf.GetLen();
// As odd as it may seem: the query for GetLen() must return
// false due to the ExpandPortions _after_ the aDiffText (see SoftHyphs)
// caused by the SetFull ...
if( !nFullLen )
{
// Do not Init(), because we need height and ascent
Width(0);
return false;
}
return SwTextPortion::Format( rInf );
}
void SwExpandPortion::Paint( const SwTextPaintInfo &rInf ) const
{
SwTextSlot aDiffText( &rInf, this, true, true );
const SwFont aOldFont = *rInf.GetFont();
if( GetJoinBorderWithPrev() )
const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetLeftBorder(nullptr);
if( GetJoinBorderWithNext() )
const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetRightBorder(nullptr);
rInf.DrawBackBrush( *this );
rInf.DrawBorder( *this );
// Do we have to repaint a post it portion?
if( rInf.OnWin() && mpNextPortion && !mpNextPortion->Width() )
mpNextPortion->PrePaint( rInf, this );
// The contents of field portions is not considered during the
// calculation of the directions. Therefore we let vcl handle
// the calculation by removing the BIDI_STRONG_FLAG temporarily.
SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
aLayoutModeModifier.SetAuto();
// ST2
if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
rInf.DrawMarkedText( *this, rInf.GetLen(), false,
nullptr != rInf.GetSmartTags(), nullptr != rInf.GetGrammarCheckList() );
else
rInf.DrawText( *this, rInf.GetLen() );
if( GetJoinBorderWithPrev() || GetJoinBorderWithNext() )
*const_cast<SwTextPaintInfo&>(rInf).GetFont() = aOldFont;
}
SwLinePortion *SwBlankPortion::Compress() { return this; }
/**
* If a Line is full of HardBlanks and overflows, we must not generate
* underflows!
* Causes problems with Fly
*/
sal_uInt16 SwBlankPortion::MayUnderflow( const SwTextFormatInfo &rInf,
TextFrameIndex const nIdx, bool bUnderflow)
{
if( rInf.StopUnderflow() )
return 0;
const SwLinePortion *pPos = rInf.GetRoot();
if( pPos->GetNextPortion() )
pPos = pPos->GetNextPortion();
while( pPos && pPos->IsBlankPortion() )
pPos = pPos->GetNextPortion();
if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
return 0; // There are just BlankPortions left
// If a Blank is preceding us, we do not need to trigger underflow
// If a Blank is succeeding us, we do not need to pass on the underflow
if (bUnderflow
&& nIdx + TextFrameIndex(1) < TextFrameIndex(rInf.GetText().getLength())
&& CH_BLANK == rInf.GetText()[sal_Int32(nIdx) + 1])
{
return 0;
}
if( nIdx && !const_cast<SwTextFormatInfo&>(rInf).GetFly() )
{
while( pPos && !pPos->IsFlyPortion() )
pPos = pPos->GetNextPortion();
if( !pPos )
{
// We check to see if there are useful line breaks, blanks or fields etc. left
// In case there still are some, no underflow
// If there are Flys, we still allow the underflow
TextFrameIndex nBlank = nIdx;
while( --nBlank > rInf.GetLineStart() )
{
const sal_Unicode cCh = rInf.GetChar( nBlank );
if( CH_BLANK == cCh ||
(( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
&& rInf.HasHint( nBlank ) ) )
break;
}
if( nBlank <= rInf.GetLineStart() )
return 0;
}
}
if (nIdx < TextFrameIndex(2))
return 1;
sal_Unicode const cCh(rInf.GetChar(nIdx - TextFrameIndex(1)));
if (CH_BLANK == cCh)
return 1;
if( CH_BREAK == cCh )
return 0;
return 2;
}
/**
* Format End of Line
*/
void SwBlankPortion::FormatEOL( SwTextFormatInfo &rInf )
{
sal_uInt16 nMay = MayUnderflow( rInf, rInf.GetIdx() - mnLineLength, true );
if( !nMay )
return;
if( nMay > 1 )
{
if( rInf.GetLast() == this )
rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
rInf.X( rInf.X() - PrtWidth() );
rInf.SetIdx( rInf.GetIdx() - GetLen() );
}
Truncate();
rInf.SetUnderflow( this );
if( rInf.GetLast()->IsKernPortion() )
rInf.SetUnderflow( rInf.GetLast() );
}
/**
* Pass on the underflows and trigger them ourselves!
*/
bool SwBlankPortion::Format( SwTextFormatInfo &rInf )
{
const bool bFull = rInf.IsUnderflow() || SwExpandPortion::Format( rInf );
if( bFull && MayUnderflow( rInf, rInf.GetIdx(), rInf.IsUnderflow() ) )
{
Truncate();
rInf.SetUnderflow( this );
if( rInf.GetLast()->IsKernPortion() )
rInf.SetUnderflow( rInf.GetLast() );
}
return bFull;
}
void SwBlankPortion::Paint( const SwTextPaintInfo &rInf ) const
{
if( !m_bMulti ) // No gray background for multiportion brackets
rInf.DrawViewOpt( *this, PortionType::Blank );
SwExpandPortion::Paint( rInf );
}
bool SwBlankPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) const
{
rText = OUString(m_cChar);
return true;
}
void SwBlankPortion::HandlePortion( SwPortionHandler& rPH ) const
{
rPH.Special( GetLen(), OUString( m_cChar ), GetWhichPor() );
}
void SwBlankPortion::dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
TextFrameIndex& nOffset) const
{
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwBlankPortion"));
dumpAsXmlAttributes(pWriter, rText, nOffset);
nOffset += GetLen();
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("char"),
BAD_CAST(OUString(m_cChar).toUtf8().getStr()));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("multi"),
BAD_CAST(OString::boolean(m_bMulti).getStr()));
(void)xmlTextWriterEndElement(pWriter);
}
SwPostItsPortion::SwPostItsPortion( bool bScrpt )
: m_bScript( bScrpt )
{
mnLineLength = TextFrameIndex(1);
SetWhichPor( PortionType::PostIts );
}
void SwPostItsPortion::Paint( const SwTextPaintInfo &rInf ) const
{
if( rInf.OnWin() && Width() )
rInf.DrawPostIts( IsScript() );
}
sal_uInt16 SwPostItsPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
{
// Unbelievable: PostIts are always visible
return rInf.OnWin() ? SwViewOption::GetPostItsWidth( rInf.GetOut() ) : 0;
}
bool SwPostItsPortion::Format( SwTextFormatInfo &rInf )
{
const bool bRet = SwLinePortion::Format( rInf );
// PostIts should not have an effect on line height etc.
SetAscent( 1 );
Height( 1 );
return bRet;
}
bool SwPostItsPortion::GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const
{
if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
rText = " ";
else
rText.clear();
return true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|