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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
|
/* -*- 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 <hintids.hxx>
#include <sfx2/printer.hxx>
#include <editeng/lspcitem.hxx>
#include <editeng/adjustitem.hxx>
#include <editeng/escapementitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/pgrditem.hxx>
#include <vcl/window.hxx>
#include <vcl/svapp.hxx>
#include <viewsh.hxx>
#include <viewopt.hxx>
#include <ndtxt.hxx>
#include <pagefrm.hxx>
#include <paratr.hxx>
#include <SwPortionHandler.hxx>
#include "porrst.hxx"
#include "inftxt.hxx"
#include "txtpaint.hxx"
#include <swfntcch.hxx>
#include <tgrditem.hxx>
#include <pagedesc.hxx>
#include <frmatr.hxx>
#include "redlnitr.hxx"
#include "porfly.hxx"
#include "atrhndl.hxx"
#include <rootfrm.hxx>
#include <IDocumentRedlineAccess.hxx>
#include <IDocumentSettingAccess.hxx>
#include <IDocumentDeviceAccess.hxx>
#include <crsrsh.hxx>
SwTmpEndPortion::SwTmpEndPortion( const SwLinePortion &rPortion )
{
Height( rPortion.Height() );
SetAscent( rPortion.GetAscent() );
SetWhichPor( POR_TMPEND );
}
void SwTmpEndPortion::Paint( const SwTextPaintInfo &rInf ) const
{
if (rInf.OnWin() && rInf.GetOpt().IsParagraph())
{
const SwFont* pOldFnt = rInf.GetFont();
SwFont aFont(*pOldFnt);
aFont.SetColor(NON_PRINTING_CHARACTER_COLOR);
const_cast<SwTextPaintInfo&>(rInf).SetFont(&aFont);
// draw the pilcrow
rInf.DrawText(OUString(CH_PAR), *this);
const_cast<SwTextPaintInfo&>(rInf).SetFont(const_cast<SwFont*>(pOldFnt));
}
}
SwBreakPortion::SwBreakPortion( const SwLinePortion &rPortion )
: SwLinePortion( rPortion )
{
nLineLength = TextFrameIndex(1);
SetWhichPor( POR_BRK );
}
TextFrameIndex SwBreakPortion::GetCursorOfst(const sal_uInt16) const
{
return TextFrameIndex(0);
}
sal_uInt16 SwBreakPortion::GetViewWidth( const SwTextSizeInfo & ) const
{ return 0; }
SwLinePortion *SwBreakPortion::Compress()
{ return (GetPortion() && GetPortion()->InTextGrp() ? nullptr : this); }
void SwBreakPortion::Paint( const SwTextPaintInfo &rInf ) const
{
if( rInf.OnWin() && rInf.GetOpt().IsLineBreak() )
rInf.DrawLineBreak( *this );
}
bool SwBreakPortion::Format( SwTextFormatInfo &rInf )
{
const SwLinePortion *pRoot = rInf.GetRoot();
Width( 0 );
Height( pRoot->Height() );
SetAscent( pRoot->GetAscent() );
if (rInf.GetIdx() + TextFrameIndex(1) == TextFrameIndex(rInf.GetText().getLength()))
rInf.SetNewLine( true );
return true;
}
void SwBreakPortion::HandlePortion( SwPortionHandler& rPH ) const
{
rPH.Text( GetLen(), GetWhichPor() );
}
SwKernPortion::SwKernPortion( SwLinePortion &rPortion, short nKrn,
bool bBG, bool bGK ) :
nKern( nKrn ), bBackground( bBG ), bGridKern( bGK )
{
Height( rPortion.Height() );
SetAscent( rPortion.GetAscent() );
nLineLength = TextFrameIndex(0);
SetWhichPor( POR_KERN );
if( nKern > 0 )
Width( nKern );
rPortion.Insert( this );
}
SwKernPortion::SwKernPortion( const SwLinePortion& rPortion ) :
nKern( 0 ), bBackground( false ), bGridKern( true )
{
Height( rPortion.Height() );
SetAscent( rPortion.GetAscent() );
nLineLength = TextFrameIndex(0);
SetWhichPor( POR_KERN );
}
void SwKernPortion::Paint( const SwTextPaintInfo &rInf ) const
{
if( Width() )
{
// bBackground is set for Kerning Portions between two fields
if ( bBackground )
rInf.DrawViewOpt( *this, POR_FLD );
rInf.DrawBackBrush( *this );
if (GetJoinBorderWithNext() ||GetJoinBorderWithPrev())
rInf.DrawBorder( *this );
// do we have to repaint a post it portion?
if( rInf.OnWin() && pPortion && !pPortion->Width() )
pPortion->PrePaint( rInf, this );
if( rInf.GetFont()->IsPaintBlank() )
{
SwRect aClipRect;
rInf.CalcRect( *this, &aClipRect );
SwSaveClip aClip( const_cast<OutputDevice*>(rInf.GetOut()) );
aClip.ChgClip( aClipRect );
rInf.DrawText(" ", *this, TextFrameIndex(0), TextFrameIndex(2), true );
}
}
}
void SwKernPortion::FormatEOL( SwTextFormatInfo &rInf )
{
if ( bGridKern )
return;
if( rInf.GetLast() == this )
rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
if( nKern < 0 )
Width( -nKern );
else
Width( 0 );
rInf.GetLast()->FormatEOL( rInf );
}
SwArrowPortion::SwArrowPortion( const SwLinePortion &rPortion ) :
bLeft( true )
{
Height( rPortion.Height() );
SetAscent( rPortion.GetAscent() );
nLineLength = TextFrameIndex(0);
SetWhichPor( POR_ARROW );
}
SwArrowPortion::SwArrowPortion( const SwTextPaintInfo &rInf )
: bLeft( false )
{
Height( static_cast<sal_uInt16>(rInf.GetTextFrame()->getFramePrintArea().Height()) );
aPos.setX( rInf.GetTextFrame()->getFrameArea().Left() +
rInf.GetTextFrame()->getFramePrintArea().Right() );
aPos.setY( rInf.GetTextFrame()->getFrameArea().Top() +
rInf.GetTextFrame()->getFramePrintArea().Bottom() );
SetWhichPor( POR_ARROW );
}
void SwArrowPortion::Paint( const SwTextPaintInfo &rInf ) const
{
const_cast<SwArrowPortion*>(this)->aPos = rInf.GetPos();
}
SwLinePortion *SwArrowPortion::Compress() { return this; }
SwTwips SwTextFrame::EmptyHeight() const
{
if (IsCollapse()) {
SwViewShell *pSh = getRootFrame()->GetCurrShell();
if ( dynamic_cast<const SwCursorShell*>( pSh ) != nullptr ) {
SwCursorShell *pCrSh = static_cast<SwCursorShell*>(pSh);
SwContentFrame *pCurrFrame=pCrSh->GetCurrFrame();
if (pCurrFrame==static_cast<SwContentFrame const *>(this)) {
// do nothing
} else {
return 1;
}
} else {
return 1;
}
}
OSL_ENSURE( ! IsVertical() || ! IsSwapped(),"SwTextFrame::EmptyHeight with swapped frame" );
SwFont *pFnt;
const SwTextNode& rTextNode = *GetTextNodeForParaProps();
const IDocumentSettingAccess* pIDSA = rTextNode.getIDocumentSettingAccess();
SwViewShell *pSh = getRootFrame()->GetCurrShell();
if ( rTextNode.HasSwAttrSet() )
{
const SwAttrSet *pAttrSet = &( rTextNode.GetSwAttrSet() );
pFnt = new SwFont( pAttrSet, pIDSA );
}
else
{
SwFontAccess aFontAccess( &rTextNode.GetAnyFormatColl(), pSh);
pFnt = new SwFont( aFontAccess.Get()->GetFont() );
pFnt->ChkMagic( pSh, pFnt->GetActual() );
}
if ( IsVertical() )
pFnt->SetVertical( 2700 );
OutputDevice* pOut = pSh ? pSh->GetOut() : nullptr;
if ( !pOut || !pSh->GetViewOptions()->getBrowseMode() ||
pSh->GetViewOptions()->IsPrtFormat() )
{
pOut = rTextNode.getIDocumentDeviceAccess().getReferenceDevice(true);
}
const IDocumentRedlineAccess& rIDRA = rTextNode.getIDocumentRedlineAccess();
if( IDocumentRedlineAccess::IsShowChanges( rIDRA.GetRedlineFlags() ) )
{
const SwRedlineTable::size_type nRedlPos = rIDRA.GetRedlinePos( rTextNode, USHRT_MAX );
if( SwRedlineTable::npos != nRedlPos )
{
SwAttrHandler aAttrHandler;
aAttrHandler.Init(rTextNode.GetSwAttrSet(),
*rTextNode.getIDocumentSettingAccess());
SwRedlineItr aRedln( rTextNode, *pFnt, aAttrHandler,
nRedlPos, SwRedlineItr::Mode::Show);
}
}
SwTwips nRet;
if( !pOut )
nRet = IsVertical() ?
getFramePrintArea().SSize().Width() + 1 :
getFramePrintArea().SSize().Height() + 1;
else
{
pFnt->SetFntChg( true );
pFnt->ChgPhysFnt( pSh, *pOut );
nRet = pFnt->GetHeight( pSh, *pOut );
}
delete pFnt;
return nRet;
}
bool SwTextFrame::FormatEmpty()
{
OSL_ENSURE( ! IsVertical() || ! IsSwapped(),"SwTextFrame::FormatEmpty with swapped frame" );
bool bCollapse = EmptyHeight( ) == 1 && IsCollapse( );
// sw_redlinehide: just disable FormatEmpty optimisation for now
if (HasFollow() || GetMergedPara() || GetTextNodeFirst()->GetpSwpHints() ||
nullptr != GetTextNodeForParaProps()->GetNumRule() ||
GetTextNodeFirst()->HasHiddenCharAttribute(true) ||
IsInFootnote() || ( HasPara() && GetPara()->IsPrepMustFit() ) )
return false;
const SwAttrSet& aSet = GetTextNodeForParaProps()->GetSwAttrSet();
const SvxAdjust nAdjust = aSet.GetAdjust().GetAdjust();
if( !bCollapse && ( ( ( ! IsRightToLeft() && ( SvxAdjust::Left != nAdjust ) ) ||
( IsRightToLeft() && ( SvxAdjust::Right != nAdjust ) ) ) ||
aSet.GetRegister().GetValue() ) )
return false;
const SvxLineSpacingItem &rSpacing = aSet.GetLineSpacing();
if( !bCollapse && ( SvxLineSpaceRule::Min == rSpacing.GetLineSpaceRule() ||
SvxLineSpaceRule::Fix == rSpacing.GetLineSpaceRule() ||
aSet.GetLRSpace().IsAutoFirst() ) )
return false;
SwTextFly aTextFly( this );
SwRect aRect;
bool bFirstFlyCheck = 0 != getFramePrintArea().Height();
if ( !bCollapse && bFirstFlyCheck &&
aTextFly.IsOn() && aTextFly.IsAnyObj( aRect ) )
return false;
SwTwips nHeight = EmptyHeight();
if (aSet.GetParaGrid().GetValue() &&
IsInDocBody() )
{
SwTextGridItem const*const pGrid(GetGridItem(FindPageFrame()));
if ( pGrid )
nHeight = pGrid->GetBaseHeight() + pGrid->GetRubyHeight();
}
SwRectFnSet aRectFnSet(this);
const SwTwips nChg = nHeight - aRectFnSet.GetHeight(getFramePrintArea());
if( !nChg )
SetUndersized( false );
AdjustFrame( nChg );
if( HasBlinkPor() )
{
ClearPara();
ResetBlinkPor();
}
SetCacheIdx( USHRT_MAX );
if( !IsEmpty() )
{
SetEmpty( true );
SetCompletePaint();
}
if( !bCollapse && !bFirstFlyCheck &&
aTextFly.IsOn() && aTextFly.IsAnyObj( aRect ) )
return false;
// #i35635# - call method <HideAndShowObjects()>
// to assure that objects anchored at the empty paragraph are
// correctly visible resp. invisible.
HideAndShowObjects();
return true;
}
bool SwTextFrame::FillRegister( SwTwips& rRegStart, sal_uInt16& rRegDiff )
{
const SwFrame *pFrame = this;
rRegDiff = 0;
while( !( ( SwFrameType::Body | SwFrameType::Fly )
& pFrame->GetType() ) && pFrame->GetUpper() )
pFrame = pFrame->GetUpper();
if( ( SwFrameType::Body| SwFrameType::Fly ) & pFrame->GetType() )
{
SwRectFnSet aRectFnSet(pFrame);
rRegStart = aRectFnSet.GetPrtTop(*pFrame);
pFrame = pFrame->FindPageFrame();
if( pFrame->IsPageFrame() )
{
SwPageDesc* pDesc = const_cast<SwPageFrame*>(static_cast<const SwPageFrame*>(pFrame))->FindPageDesc();
if( pDesc )
{
rRegDiff = pDesc->GetRegHeight();
if( !rRegDiff )
{
const SwTextFormatColl *pFormat = pDesc->GetRegisterFormatColl();
if( pFormat )
{
const SvxLineSpacingItem &rSpace = pFormat->GetLineSpacing();
if( SvxLineSpaceRule::Fix == rSpace.GetLineSpaceRule() )
{
rRegDiff = rSpace.GetLineHeight();
pDesc->SetRegHeight( rRegDiff );
pDesc->SetRegAscent( ( 4 * rRegDiff ) / 5 );
}
else
{
SwViewShell *pSh = getRootFrame()->GetCurrShell();
SwFontAccess aFontAccess( pFormat, pSh );
SwFont aFnt( aFontAccess.Get()->GetFont() );
OutputDevice *pOut = nullptr;
if( !pSh || !pSh->GetViewOptions()->getBrowseMode() ||
pSh->GetViewOptions()->IsPrtFormat() )
pOut = GetDoc().getIDocumentDeviceAccess().getReferenceDevice( true );
if( pSh && !pOut )
pOut = pSh->GetWin();
if( !pOut )
pOut = Application::GetDefaultDevice();
MapMode aOldMap( pOut->GetMapMode() );
pOut->SetMapMode( MapMode( MapUnit::MapTwip ) );
aFnt.ChgFnt( pSh, *pOut );
rRegDiff = aFnt.GetHeight( pSh, *pOut );
sal_uInt16 nNetHeight = rRegDiff;
switch( rSpace.GetLineSpaceRule() )
{
case SvxLineSpaceRule::Auto:
break;
case SvxLineSpaceRule::Min:
{
if( rRegDiff < rSpace.GetLineHeight() )
rRegDiff = rSpace.GetLineHeight();
break;
}
default:
OSL_FAIL( ": unknown LineSpaceRule" );
}
switch( rSpace.GetInterLineSpaceRule() )
{
case SvxInterLineSpaceRule::Off:
break;
case SvxInterLineSpaceRule::Prop:
{
long nTmp = rSpace.GetPropLineSpace();
if( nTmp < 50 )
nTmp = nTmp ? 50 : 100;
nTmp *= rRegDiff;
nTmp /= 100;
if( !nTmp )
++nTmp;
rRegDiff = static_cast<sal_uInt16>(nTmp);
nNetHeight = rRegDiff;
break;
}
case SvxInterLineSpaceRule::Fix:
{
rRegDiff = rRegDiff + rSpace.GetInterLineSpace();
nNetHeight = rRegDiff;
break;
}
default: OSL_FAIL( ": unknown InterLineSpaceRule" );
}
pDesc->SetRegHeight( rRegDiff );
pDesc->SetRegAscent( rRegDiff - nNetHeight +
aFnt.GetAscent( pSh, *pOut ) );
pOut->SetMapMode( aOldMap );
}
}
}
const long nTmpDiff = pDesc->GetRegAscent() - rRegDiff;
if ( aRectFnSet.IsVert() )
rRegStart -= nTmpDiff;
else
rRegStart += nTmpDiff;
}
}
}
return ( 0 != rRegDiff );
}
void SwHiddenTextPortion::Paint( const SwTextPaintInfo & rInf) const
{
#ifdef DBG_UTIL
OutputDevice* pOut = const_cast<OutputDevice*>(rInf.GetOut());
Color aCol( SwViewOption::GetFieldShadingsColor() );
Color aOldColor( pOut->GetFillColor() );
pOut->SetFillColor( aCol );
Point aPos( rInf.GetPos() );
aPos.AdjustY( -150 );
aPos.AdjustX( -25 );
SwRect aRect( aPos, Size( 100, 200 ) );
pOut->DrawRect( aRect.SVRect() );
pOut->SetFillColor( aOldColor );
#else
(void)rInf;
#endif
}
bool SwHiddenTextPortion::Format( SwTextFormatInfo &rInf )
{
Width( 0 );
rInf.GetTextFrame()->HideFootnotes( rInf.GetIdx(), rInf.GetIdx() + GetLen() );
return false;
};
void SwControlCharPortion::Paint( const SwTextPaintInfo &rInf ) const
{
if ( Width() ) // is only set during prepaint mode
{
rInf.DrawViewOpt( *this, POR_CONTROLCHAR );
if ( !rInf.GetOpt().IsPagePreview() &&
!rInf.GetOpt().IsReadonly() &&
SwViewOption::IsFieldShadings() &&
CHAR_ZWNBSP != mcChar )
{
SwFont aTmpFont( *rInf.GetFont() );
aTmpFont.SetEscapement( CHAR_ZWSP == mcChar ? DFLT_ESC_AUTO_SUB : -25 );
const sal_uInt16 nProp = 40;
aTmpFont.SetProportion( nProp ); // a smaller font
SwFontSave aFontSave( rInf, &aTmpFont );
OUString aOutString;
switch ( mcChar )
{
case CHAR_ZWSP :
aOutString = "/"; break;
// case CHAR_LRM :
// rText = sal_Unicode(0x2514); break;
// case CHAR_RLM :
// rText = sal_Unicode(0x2518); break;
}
if ( !mnHalfCharWidth )
mnHalfCharWidth = rInf.GetTextSize( aOutString ).Width() / 2;
Point aOldPos = rInf.GetPos();
Point aNewPos( aOldPos );
aNewPos.setX( aNewPos.X() + ( Width() / 2 ) - mnHalfCharWidth );
const_cast< SwTextPaintInfo& >( rInf ).SetPos( aNewPos );
rInf.DrawText( aOutString, *this );
const_cast< SwTextPaintInfo& >( rInf ).SetPos( aOldPos );
}
}
}
bool SwControlCharPortion::Format( SwTextFormatInfo &rInf )
{
const SwLinePortion* pRoot = rInf.GetRoot();
Width( 0 );
Height( pRoot->Height() );
SetAscent( pRoot->GetAscent() );
return false;
}
sal_uInt16 SwControlCharPortion::GetViewWidth( const SwTextSizeInfo& rInf ) const
{
if( !mnViewWidth )
mnViewWidth = rInf.GetTextSize(OUString(' ')).Width();
return mnViewWidth;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|