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 <hintids.hxx>
23 #include <com/sun/star/i18n/ScriptType.hpp>
24 #include <editeng/lspcitem.hxx>
25 #include <txtflcnt.hxx>
27 #include <flyfrms.hxx>
28 #include <fmtflcnt.hxx>
30 #include <ftninfo.hxx>
31 #include <charfmt.hxx>
32 #include <editeng/charrotateitem.hxx>
35 #include <viewopt.hxx>
37 #include "itrform2.hxx"
45 #include "porhyph.hxx"
46 #include "pordrop.hxx"
47 #include "redlnitr.hxx"
48 #include <sortedobjs.hxx>
49 #include <fmtanchr.hxx>
50 #include <pagefrm.hxx>
51 #include <tgrditem.hxx>
53 #include "pormulti.hxx"
54 #include <unotools/charclass.hxx>
55 #include <xmloff/odffields.hxx>
56 #include <IDocumentSettingAccess.hxx>
58 #include <IDocumentMarkAccess.hxx>
59 #include <comphelper/processfactory.hxx>
60 #include <vcl/pdfextoutdevdata.hxx>
61 #include <comphelper/string.hxx>
63 #include <unocrsrhelper.hxx>
64 #include <textcontentcontrol.hxx>
65 #include <com/sun/star/rdf/Statement.hpp>
66 #include <com/sun/star/rdf/URI.hpp>
67 #include <com/sun/star/rdf/URIs.hpp>
68 #include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
69 #include <com/sun/star/rdf/XLiteral.hpp>
70 #include <com/sun/star/text/XTextContent.hpp>
72 using namespace ::com::sun::star
;
75 //! Calculates and sets optimal repaint offset for the current line
76 tools::Long
lcl_CalcOptRepaint( SwTextFormatter
&rThis
,
77 SwLineLayout
const &rCurr
,
78 TextFrameIndex nOldLineEnd
,
79 const std::vector
<tools::Long
> &rFlyStarts
);
80 //! Determine if we need to build hidden portions
81 bool lcl_BuildHiddenPortion(const SwTextSizeInfo
& rInf
, TextFrameIndex
&rPos
);
83 // Check whether the two font has the same border
84 bool lcl_HasSameBorder(const SwFont
& rFirst
, const SwFont
& rSecond
);
87 static void ClearFly( SwTextFormatInfo
&rInf
)
93 void SwTextFormatter::CtorInitTextFormatter( SwTextFrame
*pNewFrame
, SwTextFormatInfo
*pNewInf
)
95 CtorInitTextPainter( pNewFrame
, pNewInf
);
97 m_pDropFormat
= GetInfo().GetDropFormat();
101 m_bFlyInContentBase
= false;
102 m_bTruncLines
= false;
103 m_nContentEndHyph
= 0;
104 m_nContentMidHyph
= 0;
105 m_nLeftScanIdx
= TextFrameIndex(COMPLETE_STRING
);
106 m_nRightScanIdx
= TextFrameIndex(0);
107 m_pByEndIter
.reset();
108 m_pFirstOfBorderMerge
= nullptr;
110 if (m_nStart
> TextFrameIndex(GetInfo().GetText().getLength()))
112 OSL_ENSURE( false, "+SwTextFormatter::CTOR: bad offset" );
113 m_nStart
= TextFrameIndex(GetInfo().GetText().getLength());
118 SwTextFormatter::~SwTextFormatter()
120 // Extremely unlikely, but still possible
121 // e.g.: field splits up, widows start to matter
122 if( GetInfo().GetRest() )
124 delete GetInfo().GetRest();
125 GetInfo().SetRest(nullptr);
129 void SwTextFormatter::Insert( SwLineLayout
*pLay
)
131 // Insert BEHIND the current element
134 pLay
->SetNext( m_pCurr
->GetNext() );
135 m_pCurr
->SetNext( pLay
);
141 sal_uInt16
SwTextFormatter::GetFrameRstHeight() const
143 // We want the rest height relative to the page.
144 // If we're in a table, then pFrame->GetUpper() is not the page.
146 // GetFrameRstHeight() is being called with Footnote.
147 // Wrong: const SwFrame *pUpper = pFrame->GetUpper();
148 const SwFrame
*pPage
= m_pFrame
->FindPageFrame();
149 const SwTwips nHeight
= pPage
->getFrameArea().Top()
150 + pPage
->getFramePrintArea().Top()
151 + pPage
->getFramePrintArea().Height() - Y();
153 return m_pCurr
->Height();
155 return sal_uInt16( nHeight
);
158 bool SwTextFormatter::ClearIfIsFirstOfBorderMerge(const SwLinePortion
* pPortion
)
160 if (pPortion
== m_pFirstOfBorderMerge
)
162 m_pFirstOfBorderMerge
= nullptr;
168 SwLinePortion
*SwTextFormatter::Underflow( SwTextFormatInfo
&rInf
)
170 // Save values and initialize rInf
171 SwLinePortion
*pUnderflow
= rInf
.GetUnderflow();
175 // We format backwards, i.e. attribute changes can happen the next
177 // Can be seen in 8081.sdw, if you enter text in the first line
179 TextFrameIndex
const nSoftHyphPos
= rInf
.GetSoftHyphPos();
180 TextFrameIndex
const nUnderScorePos
= rInf
.GetUnderScorePos();
182 // Save flys and set to 0, or else segmentation fault
183 // Not ClearFly(rInf) !
184 SwFlyPortion
*pFly
= rInf
.GetFly();
185 rInf
.SetFly( nullptr );
188 rInf
.SetLast( m_pCurr
);
189 // pUnderflow does not need to be deleted, because it will drown in the following
191 rInf
.SetUnderflow(nullptr);
192 rInf
.SetSoftHyphPos( nSoftHyphPos
);
193 rInf
.SetUnderScorePos( nUnderScorePos
);
194 rInf
.SetPaintOfst( GetLeftMargin() );
196 // We look for the portion with the under-flow position
197 SwLinePortion
*pPor
= m_pCurr
->GetFirstPortion();
198 if( pPor
!= pUnderflow
)
200 // pPrev will be the last portion before pUnderflow,
201 // which still has a real width.
202 // Exception: SoftHyphPortion must not be forgotten, of course!
203 // Although they don't have a width.
204 SwLinePortion
*pTmpPrev
= pPor
;
205 while( pPor
&& pPor
!= pUnderflow
)
207 if( !pPor
->IsKernPortion() &&
208 ( pPor
->Width() || pPor
->IsSoftHyphPortion() ) )
210 while( pTmpPrev
!= pPor
)
212 pTmpPrev
->Move( rInf
);
213 rInf
.SetLast( pTmpPrev
);
214 pTmpPrev
= pTmpPrev
->GetNextPortion();
215 OSL_ENSURE( pTmpPrev
, "Underflow: losing control!" );
218 pPor
= pPor
->GetNextPortion();
221 if( pPor
&& // Skip flys and initials when underflow.
222 ( pPor
->IsFlyPortion() || pPor
->IsDropPortion() ||
223 pPor
->IsFlyCntPortion() ) )
226 rInf
.SetLast( pPor
);
227 rInf
.SetStopUnderflow( true );
232 // What? The under-flow portion is not in the portion chain?
233 OSL_ENSURE( pPor
, "SwTextFormatter::Underflow: overflow but underflow" );
236 if ( pPor
==rInf
.GetLast() )
238 // We end up here, if the portion triggering the under-flow
239 // spans over the whole line. E.g. if a word spans across
240 // multiple lines and flows into a fly in the second line.
243 return pPor
; // Is that enough?
247 // X + Width == 0 with SoftHyph > Line?!
248 if( !pPor
|| !(rInf
.X() + pPor
->Width()) )
254 // Preparing for Format()
255 // We need to chip off the chain behind pLast, because we Insert after the Format()
258 // line width is adjusted, so that pPor does not fit to current
260 rInf
.Width( rInf
.X() + (pPor
->Width() ? pPor
->Width() - 1 : 0) );
261 rInf
.SetLen( pPor
->GetLen() );
262 rInf
.SetFull( false );
265 // We need to recalculate the FlyPortion due to the following reason:
266 // If the base line is lowered by a big font in the middle of the line,
267 // causing overlapping with a fly, the FlyPortion has a wrong size/fixed
270 CalcFlyWidth( rInf
);
272 rInf
.GetLast()->SetNextPortion(nullptr);
274 // The SwLineLayout is an exception to this, which splits at the first
276 // Here only the other way around:
277 if( rInf
.GetLast() == m_pCurr
)
279 if( pPor
->InTextGrp() && !pPor
->InExpGrp() )
281 const PortionType nOldWhich
= m_pCurr
->GetWhichPor();
282 *static_cast<SwLinePortion
*>(m_pCurr
) = *pPor
;
283 m_pCurr
->SetNextPortion( pPor
->GetNextPortion() );
284 m_pCurr
->SetWhichPor( nOldWhich
);
285 pPor
->SetNextPortion( nullptr );
291 // Make sure that m_pFirstOfBorderMerge does not point to a portion which
292 // will be deleted by Truncate() below.
293 SwLinePortion
* pNext
= pPor
->GetNextPortion();
296 if (ClearIfIsFirstOfBorderMerge(pNext
))
298 pNext
= pNext
->GetNextPortion();
301 SwLinePortion
*const pRest( rInf
.GetRest() );
302 if (pRest
&& pRest
->InFieldGrp() &&
303 static_cast<SwFieldPortion
*>(pRest
)->IsNoLength())
305 // HACK: decrement again, so we pick up the suffix in next line!
306 m_pByEndIter
->PrevAttr();
309 rInf
.SetRest(nullptr);
313 void SwTextFormatter::InsertPortion( SwTextFormatInfo
&rInf
,
314 SwLinePortion
*pPor
)
316 SwLinePortion
*pLast
= nullptr;
317 // The new portion is inserted, but everything's different for
319 if( pPor
== m_pCurr
)
321 if ( m_pCurr
->GetNextPortion() )
324 pPor
= m_pCurr
->GetNextPortion();
327 // i#112181 - Prevent footnote anchor being wrapped to next line
328 // without preceding word
329 rInf
.SetOtherThanFootnoteInside( rInf
.IsOtherThanFootnoteInside() || !pPor
->IsFootnotePortion() );
333 pLast
= rInf
.GetLast();
334 if( pLast
->GetNextPortion() )
336 while( pLast
->GetNextPortion() )
337 pLast
= pLast
->GetNextPortion();
338 rInf
.SetLast( pLast
);
340 pLast
->Insert( pPor
);
342 rInf
.SetOtherThanFootnoteInside( rInf
.IsOtherThanFootnoteInside() || !pPor
->IsFootnotePortion() );
345 if( m_pCurr
->Height() < pPor
->Height() )
346 m_pCurr
->Height( pPor
->Height(), pPor
->IsTextPortion() );
347 if( m_pCurr
->GetAscent() < pPor
->GetAscent() )
348 m_pCurr
->SetAscent( pPor
->GetAscent() );
349 if( m_pCurr
->GetHangingBaseline() < pPor
->GetHangingBaseline() )
350 m_pCurr
->SetHangingBaseline( pPor
->GetHangingBaseline() );
352 if (GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::MS_WORD_COMP_MIN_LINE_HEIGHT_BY_FLY
))
354 // For DOCX with compat=14 the only shape in line defines height of the line in spite of used font
355 if (pLast
->IsFlyCntPortion() && pPor
->IsTextPortion() && pPor
->GetLen() == TextFrameIndex(0))
357 m_pCurr
->SetAscent(pLast
->GetAscent());
358 m_pCurr
->Height(pLast
->Height());
363 // Sometimes chains are constructed (e.g. by hyphenate)
364 rInf
.SetLast( pPor
);
367 if (!pPor
->IsDropPortion())
368 MergeCharacterBorder(*pPor
, pLast
, rInf
);
371 rInf
.SetLast( pPor
);
373 pPor
= pPor
->GetNextPortion();
377 void SwTextFormatter::BuildPortions( SwTextFormatInfo
&rInf
)
379 OSL_ENSURE( rInf
.GetText().getLength() < COMPLETE_STRING
,
380 "SwTextFormatter::BuildPortions: bad text length in info" );
382 rInf
.ChkNoHyph( CntEndHyph(), CntMidHyph() );
384 // First NewTextPortion() decides whether pCurr ends up in pPor.
385 // We need to make sure that the font is being set in any case.
386 // This is done automatically in CalcAscent.
387 rInf
.SetLast( m_pCurr
);
388 rInf
.ForcedLeftMargin( 0 );
390 OSL_ENSURE( m_pCurr
->FindLastPortion() == m_pCurr
, "pLast supposed to equal pCurr" );
392 if( !m_pCurr
->GetAscent() && !m_pCurr
->Height() )
393 CalcAscent( rInf
, m_pCurr
);
397 // Width() is shortened in CalcFlyWidth if we have a FlyPortion
398 OSL_ENSURE( !rInf
.X() || m_pMulti
, "SwTextFormatter::BuildPortion X=0?" );
399 CalcFlyWidth( rInf
);
400 SwFlyPortion
*pFly
= rInf
.GetFly();
403 if ( 0 < pFly
->GetFix() )
409 ::std::optional
<TextFrameIndex
> oMovedFlyIndex
;
410 if (SwTextFrame
const*const pFollow
= GetTextFrame()->GetFollow())
412 // flys are always on master!
413 if (GetTextFrame()->GetDrawObjs() && pFollow
->GetUpper() != GetTextFrame()->GetUpper())
415 for (SwAnchoredObject
const*const pAnchoredObj
: *GetTextFrame()->GetDrawObjs())
417 // tdf#146500 try to stop where a fly is anchored in the follow
418 // that has recently been moved (presumably by splitting this
419 // frame); similar to check in SwFlowFrame::MoveBwd()
420 if (pAnchoredObj
->RestartLayoutProcess()
421 && !pAnchoredObj
->IsTmpConsiderWrapInfluence())
423 SwFormatAnchor
const& rAnchor(pAnchoredObj
->GetFrameFormat().GetAnchor());
424 assert(rAnchor
.GetAnchorId() == RndStdIds::FLY_AT_CHAR
|| rAnchor
.GetAnchorId() == RndStdIds::FLY_AT_PARA
);
425 TextFrameIndex
const nAnchor(GetTextFrame()->MapModelToViewPos(*rAnchor
.GetContentAnchor()));
426 if (pFollow
->GetOffset() <= nAnchor
427 && (pFollow
->GetFollow() == nullptr
428 || nAnchor
< pFollow
->GetFollow()->GetOffset()))
430 if (!oMovedFlyIndex
|| nAnchor
< *oMovedFlyIndex
)
432 oMovedFlyIndex
.emplace(nAnchor
);
440 SwLinePortion
*pPor
= NewPortion(rInf
, oMovedFlyIndex
);
443 SwTextGridItem
const*const pGrid(GetGridItem(m_pFrame
->FindPageFrame()));
444 const bool bHasGrid
= pGrid
&& rInf
.SnapToGrid() &&
445 GRID_LINES_CHARS
== pGrid
->GetGridType();
448 const SwDoc
& rDoc
= rInf
.GetTextFrame()->GetDoc();
449 const sal_uInt16 nGridWidth
= bHasGrid
? GetGridWidth(*pGrid
, rDoc
) : 0;
451 // used for grid mode only:
452 // the pointer is stored, because after formatting of non-asian text,
453 // the width of the kerning portion has to be adjusted
454 // Inserting a SwKernPortion before a SwTabPortion isn't necessary
455 // and will break the SwTabPortion.
456 SwKernPortion
* pGridKernPortion
= nullptr;
459 SwTwips nUnderLineStart
= 0;
462 while( pPor
&& !rInf
.IsStop() )
464 OSL_ENSURE(rInf
.GetLen() < TextFrameIndex(COMPLETE_STRING
) &&
465 rInf
.GetIdx() <= TextFrameIndex(rInf
.GetText().getLength()),
466 "SwTextFormatter::BuildPortions: bad length in info" );
468 // We have to check the script for fields in order to set the
469 // correct nActual value for the font.
470 if( pPor
->InFieldGrp() )
471 static_cast<SwFieldPortion
*>(pPor
)->CheckScript( rInf
);
473 if( ! bHasGrid
&& rInf
.HasScriptSpace() &&
474 rInf
.GetLast() && rInf
.GetLast()->InTextGrp() &&
475 rInf
.GetLast()->Width() && !rInf
.GetLast()->InNumberGrp() )
477 SwFontScript nNxtActual
= rInf
.GetFont()->GetActual();
478 SwFontScript nLstActual
= nNxtActual
;
479 sal_uInt16 nLstHeight
= o3tl::narrowing
<sal_uInt16
>(rInf
.GetFont()->GetHeight());
480 bool bAllowBehind
= false;
481 const CharClass
& rCC
= GetAppCharClass();
483 // are there any punctuation characters on both sides
484 // of the kerning portion?
485 if ( pPor
->InFieldGrp() )
488 if ( static_cast<SwFieldPortion
*>(pPor
)->GetExpText( rInf
, aAltText
) &&
489 !aAltText
.isEmpty() )
491 bAllowBehind
= rCC
.isLetterNumeric( aAltText
, 0 );
493 const SwFont
* pTmpFnt
= static_cast<SwFieldPortion
*>(pPor
)->GetFont();
495 nNxtActual
= pTmpFnt
->GetActual();
500 const OUString
& rText
= rInf
.GetText();
501 sal_Int32 nIdx
= sal_Int32(rInf
.GetIdx());
502 bAllowBehind
= nIdx
< rText
.getLength() && rCC
.isLetterNumeric(rText
, nIdx
);
505 const SwLinePortion
* pLast
= rInf
.GetLast();
506 if ( bAllowBehind
&& pLast
)
508 bool bAllowBefore
= false;
510 if ( pLast
->InFieldGrp() )
513 if ( static_cast<const SwFieldPortion
*>(pLast
)->GetExpText( rInf
, aAltText
) &&
514 !aAltText
.isEmpty() )
516 bAllowBefore
= rCC
.isLetterNumeric( aAltText
, aAltText
.getLength() - 1 );
518 const SwFont
* pTmpFnt
= static_cast<const SwFieldPortion
*>(pLast
)->GetFont();
521 nLstActual
= pTmpFnt
->GetActual();
522 nLstHeight
= o3tl::narrowing
<sal_uInt16
>(pTmpFnt
->GetHeight());
526 else if ( rInf
.GetIdx() )
528 bAllowBefore
= rCC
.isLetterNumeric(rInf
.GetText(), sal_Int32(rInf
.GetIdx()) - 1);
529 // Note: ScriptType returns values in [1,4]
531 nLstActual
= SwFontScript(m_pScriptInfo
->ScriptType(rInf
.GetIdx() - TextFrameIndex(1)) - 1);
535 // does the kerning portion still fit into the line?
536 if( bAllowBefore
&& ( nLstActual
!= nNxtActual
) &&
537 // tdf#89288 we want to insert space between CJK and non-CJK text only.
538 ( nLstActual
== SwFontScript::CJK
|| nNxtActual
== SwFontScript::CJK
) &&
539 nLstHeight
&& rInf
.X() + nLstHeight
<= rInf
.Width() &&
542 SwKernPortion
* pKrn
=
543 new SwKernPortion( *rInf
.GetLast(), nLstHeight
,
544 pLast
->InFieldGrp() && pPor
->InFieldGrp() );
546 // ofz#58550 Direct-leak, pKrn adds itself as the NextPortion
547 // of rInf.GetLast(), but may use CopyLinePortion to add a copy
548 // of itself, which will then be left dangling with the following
549 // SetNextPortion(nullptr)
550 SwLinePortion
*pNext
= rInf
.GetLast()->GetNextPortion();
554 rInf
.GetLast()->SetNextPortion( nullptr );
555 InsertPortion( rInf
, pKrn
);
559 else if ( bHasGrid
&& ! pGridKernPortion
&& ! m_pMulti
&& ! pPor
->InTabGrp() )
561 // insert a grid kerning portion
562 pGridKernPortion
= pPor
->IsKernPortion() ?
563 static_cast<SwKernPortion
*>(pPor
) :
564 new SwKernPortion( *m_pCurr
);
566 // if we have a new GridKernPortion, we initially calculate
567 // its size so that its ends on the grid
568 const SwPageFrame
* pPageFrame
= m_pFrame
->FindPageFrame();
569 const SwLayoutFrame
* pBody
= pPageFrame
->FindBodyCont();
570 SwRectFnSet
aRectFnSet(pPageFrame
);
572 const tools::Long nGridOrigin
= pBody
?
573 aRectFnSet
.GetPrtLeft(*pBody
) :
574 aRectFnSet
.GetPrtLeft(*pPageFrame
);
576 SwTwips nStartX
= rInf
.X() + GetLeftMargin();
577 if ( aRectFnSet
.IsVert() )
579 Point
aPoint( nStartX
, 0 );
580 m_pFrame
->SwitchHorizontalToVertical( aPoint
);
581 nStartX
= aPoint
.Y();
584 const SwTwips nOfst
= nStartX
- nGridOrigin
;
587 const sal_uLong i
= ( nOfst
> 0 ) ?
588 ( ( nOfst
- 1 ) / nGridWidth
+ 1 ) :
590 const SwTwips nKernWidth
= i
* nGridWidth
- nOfst
;
591 const SwTwips nRestWidth
= rInf
.Width() - rInf
.X();
593 if ( nKernWidth
<= nRestWidth
)
594 pGridKernPortion
->Width( nKernWidth
);
597 if ( pGridKernPortion
!= pPor
)
598 InsertPortion( rInf
, pGridKernPortion
);
601 if( pPor
->IsDropPortion() )
602 MergeCharacterBorder(*static_cast<SwDropPortion
*>(pPor
));
604 // the multi-portion has its own format function
605 if( pPor
->IsMultiPortion() && ( !m_pMulti
|| m_pMulti
->IsBidi() ) )
606 bFull
= BuildMultiPortion( rInf
, *static_cast<SwMultiPortion
*>(pPor
) );
608 bFull
= pPor
->Format( rInf
);
610 if( rInf
.IsRuby() && !rInf
.GetRest() )
613 // if we are underlined, we store the beginning of this underlined
614 // segment for repaint optimization
615 if ( LINESTYLE_NONE
!= m_pFont
->GetUnderline() && ! nUnderLineStart
)
616 nUnderLineStart
= GetLeftMargin() + rInf
.X();
618 if ( pPor
->IsFlyPortion() )
619 m_pCurr
->SetFly( true );
620 // some special cases, where we have to take care for the repaint
622 // 1. Underlined portions due to special underline feature
625 // 4. other Multiportions
628 else if ( ( ! rInf
.GetPaintOfst() || nUnderLineStart
< rInf
.GetPaintOfst() ) &&
629 // 1. Underlined portions
631 // reformat is at end of an underlined portion and next portion
633 ( ( rInf
.GetReformatStart() == rInf
.GetIdx() &&
634 LINESTYLE_NONE
== m_pFont
->GetUnderline()
636 // reformat is inside portion and portion is underlined
637 ( rInf
.GetReformatStart() >= rInf
.GetIdx() &&
638 rInf
.GetReformatStart() <= rInf
.GetIdx() + pPor
->GetLen() &&
639 LINESTYLE_NONE
!= m_pFont
->GetUnderline() ) ) )
640 rInf
.SetPaintOfst( nUnderLineStart
);
641 else if ( ! rInf
.GetPaintOfst() &&
643 ( ( pPor
->InTabGrp() && !pPor
->IsTabLeftPortion() ) ||
645 ( pPor
->IsMultiPortion() && static_cast<SwMultiPortion
*>(pPor
)->IsBidi() ) ||
646 // 4. Multi Portion and 5. Drop Caps
647 ( ( pPor
->IsDropPortion() || pPor
->IsMultiPortion() ) &&
648 rInf
.GetReformatStart() >= rInf
.GetIdx() &&
649 rInf
.GetReformatStart() <= rInf
.GetIdx() + pPor
->GetLen() )
651 || ( bHasGrid
&& SwFontScript::CJK
!= m_pFont
->GetActual() )
654 // we store the beginning of the critical portion as our
656 rInf
.SetPaintOfst( GetLeftMargin() + rInf
.X() );
658 // under one of these conditions we are allowed to delete the
659 // start of the underline portion
660 if ( IsUnderlineBreak( *pPor
, *m_pFont
) )
663 if( pPor
->IsFlyCntPortion() || ( pPor
->IsMultiPortion() &&
664 static_cast<SwMultiPortion
*>(pPor
)->HasFlyInContent() ) )
666 // bUnderflow needs to be reset or we wrap again at the next softhyphen
670 if( ! bHasGrid
&& rInf
.HasScriptSpace() && pPor
->InTextGrp() &&
671 pPor
->GetLen() && !pPor
->InFieldGrp() )
673 // The distance between two different scripts is set
674 // to 20% of the fontheight.
675 TextFrameIndex
const nTmp
= rInf
.GetIdx() + pPor
->GetLen();
676 if (nTmp
== m_pScriptInfo
->NextScriptChg(nTmp
- TextFrameIndex(1)) &&
677 nTmp
!= TextFrameIndex(rInf
.GetText().getLength()) &&
678 (m_pScriptInfo
->ScriptType(nTmp
- TextFrameIndex(1)) == css::i18n::ScriptType::ASIAN
||
679 m_pScriptInfo
->ScriptType(nTmp
) == css::i18n::ScriptType::ASIAN
) )
681 const SwTwips nDist
= rInf
.GetFont()->GetHeight()/5;
685 // we do not want a kerning portion if any end
686 // would be a punctuation character
687 const CharClass
& rCC
= GetAppCharClass();
688 if (rCC
.isLetterNumeric(rInf
.GetText(), sal_Int32(nTmp
) - 1)
689 && rCC
.isLetterNumeric(rInf
.GetText(), sal_Int32(nTmp
)))
691 // does the kerning portion still fit into the line?
692 if ( rInf
.X() + pPor
->Width() + nDist
<= rInf
.Width() )
693 new SwKernPortion( *pPor
, nDist
);
702 if ( bHasGrid
&& pPor
!= pGridKernPortion
&& ! m_pMulti
&& ! pPor
->InTabGrp() )
704 TextFrameIndex
const nTmp
= rInf
.GetIdx() + pPor
->GetLen();
705 const SwTwips nRestWidth
= rInf
.Width() - rInf
.X() - pPor
->Width();
707 const SwFontScript nCurrScript
= m_pFont
->GetActual(); // pScriptInfo->ScriptType( rInf.GetIdx() );
708 const SwFontScript nNextScript
=
709 nTmp
>= TextFrameIndex(rInf
.GetText().getLength())
711 : m_pScriptInfo
->WhichFont(nTmp
);
713 // snap non-asian text to grid if next portion is ASIAN or
714 // there are no more portions in this line
715 // be careful when handling an underflow event: the gridkernportion
716 // could have been deleted
717 if ( nRestWidth
> 0 && SwFontScript::CJK
!= nCurrScript
&&
718 ! rInf
.IsUnderflow() && ( bFull
|| SwFontScript::CJK
== nNextScript
) )
720 OSL_ENSURE( pGridKernPortion
, "No GridKernPortion available" );
723 SwLinePortion
* pTmpPor
= pGridKernPortion
->GetNextPortion();
724 sal_uInt16 nSumWidth
= pPor
->Width();
727 nSumWidth
= nSumWidth
+ pTmpPor
->Width();
728 pTmpPor
= pTmpPor
->GetNextPortion();
731 const SwTwips i
= nSumWidth
?
732 ( nSumWidth
- 1 ) / nGridWidth
+ 1 :
734 const SwTwips nTmpWidth
= i
* nGridWidth
;
735 const SwTwips nKernWidth
= std::min(nTmpWidth
- nSumWidth
, nRestWidth
);
736 const SwTwips nKernWidth_1
= pGrid
->IsSnapToChars() ?
739 OSL_ENSURE( nKernWidth
<= nRestWidth
,
740 "Not enough space left for adjusting non-asian text in grid mode" );
743 pGridKernPortion
->Width( pGridKernPortion
->Width() + nKernWidth_1
);
744 rInf
.X( rInf
.X() + nKernWidth_1
);
747 if ( ! bFull
&& nKernWidth
- nKernWidth_1
> 0 )
748 new SwKernPortion( *pPor
, static_cast<short>(nKernWidth
- nKernWidth_1
),
751 pGridKernPortion
= nullptr;
753 else if ( pPor
->IsMultiPortion() || pPor
->InFixMargGrp() ||
754 pPor
->IsFlyCntPortion() || pPor
->InNumberGrp() ||
755 pPor
->InFieldGrp() || nCurrScript
!= nNextScript
)
756 // next portion should snap to grid
757 pGridKernPortion
= nullptr;
760 rInf
.SetFull( bFull
);
762 // Restportions from fields with multiple lines don't yet have the right ascent
763 if ( !pPor
->GetLen() && !pPor
->IsFlyPortion()
764 && !pPor
->IsGrfNumPortion() && ! pPor
->InNumberGrp()
765 && !pPor
->IsMultiPortion() )
766 CalcAscent( rInf
, pPor
);
768 InsertPortion( rInf
, pPor
);
769 if (pPor
->IsMultiPortion() && (!m_pMulti
|| m_pMulti
->IsBidi()))
771 (void) rInf
.CheckCurrentPosBookmark(); // bookmark was already created inside MultiPortion!
773 pPor
= NewPortion(rInf
, oMovedFlyIndex
);
778 // The last right centered, decimal tab
779 SwTabPortion
*pLastTab
= rInf
.GetLastTab();
781 pLastTab
->FormatEOL( rInf
);
782 else if( rInf
.GetLast() && rInf
.LastKernPortion() )
783 rInf
.GetLast()->FormatEOL( rInf
);
785 if( m_pCurr
->GetNextPortion() && m_pCurr
->GetNextPortion()->InNumberGrp()
786 && static_cast<SwNumberPortion
*>(m_pCurr
->GetNextPortion())->IsHide() )
787 rInf
.SetNumDone( false );
789 // Delete fly in any case
792 // Reinit the tab overflow flag after the line
793 rInf
.SetTabOverflow( false );
796 void SwTextFormatter::CalcAdjustLine( SwLineLayout
*pCurrent
)
798 if( SvxAdjust::Left
!= GetAdjust() && !m_pMulti
)
800 pCurrent
->SetFormatAdj(true);
801 if( IsFlyInCntBase() )
803 CalcAdjLine( pCurrent
);
804 // For e.g. centered fly we need to switch the RefPoint
805 // That's why bAlways = true
806 UpdatePos( pCurrent
, GetTopLeft(), GetStart(), true );
811 void SwTextFormatter::CalcAscent( SwTextFormatInfo
&rInf
, SwLinePortion
*pPor
)
814 if ( pPor
->InFieldGrp() && static_cast<SwFieldPortion
*>(pPor
)->GetFont() )
816 // Numbering + InterNetFields can keep an own font, then their size is
817 // independent from hard attribute values
818 SwFont
* pFieldFnt
= static_cast<SwFieldPortion
*>(pPor
)->m_pFont
.get();
819 SwFontSave
aSave( rInf
, pFieldFnt
);
820 pPor
->Height( rInf
.GetTextHeight() );
821 pPor
->SetAscent( rInf
.GetAscent() );
825 // tab portion representing the list tab of a list label gets the
826 // same height and ascent as the corresponding number portion
827 else if ( pPor
->InTabGrp() && pPor
->GetLen() == TextFrameIndex(0) &&
828 rInf
.GetLast() && rInf
.GetLast()->InNumberGrp() &&
829 static_cast<const SwNumberPortion
*>(rInf
.GetLast())->HasFont() )
831 const SwLinePortion
* pLast
= rInf
.GetLast();
832 pPor
->Height( pLast
->Height() );
833 pPor
->SetAscent( pLast
->GetAscent() );
835 else if (pPor
->GetWhichPor() == PortionType::Bookmark
836 && rInf
.GetIdx() == TextFrameIndex(rInf
.GetText().getLength()))
838 // bookmark at end of paragraph: *don't* advance iterator, use the
839 // current font instead; it's possible that there's a font size on the
840 // paragraph and it's overridden on the last line of the paragraph and
841 // we don't want to apply it via SwBookmarkPortion and grow the line
842 // height (example: n758883.docx)
843 SwLinePortion
const*const pLast
= rInf
.GetLast();
845 pPor
->Height( pLast
->Height(), false );
846 pPor
->SetAscent( pLast
->GetAscent() );
850 const SwLinePortion
*pLast
= rInf
.GetLast();
853 // In empty lines the attributes are switched on via SeekStart
854 const bool bFirstPor
= rInf
.GetLineStart() == rInf
.GetIdx();
855 if ( pPor
->IsQuoVadisPortion() )
856 bChg
= SeekStartAndChg( rInf
, true );
861 if( !rInf
.GetText().isEmpty() )
863 if ( pPor
->GetLen() || !rInf
.GetIdx()
864 || ( m_pCurr
!= pLast
&& !pLast
->IsFlyPortion() )
865 || !m_pCurr
->IsRest() ) // instead of !rInf.GetRest()
866 bChg
= SeekAndChg( rInf
);
868 bChg
= SeekAndChgBefore( rInf
);
871 // do not open attributes starting at 0 in empty multi
872 // portions (rotated numbering followed by a footnote
873 // can cause trouble, because the footnote attribute
874 // starts at 0, but if we open it, the attribute handler
878 bChg
= SeekStartAndChg( rInf
);
881 bChg
= SeekAndChg( rInf
);
883 if( bChg
|| bFirstPor
|| !pPor
->GetAscent()
884 || !rInf
.GetLast()->InTextGrp() )
886 pPor
->SetHangingBaseline( rInf
.GetHangingBaseline() );
887 pPor
->SetAscent( rInf
.GetAscent() );
888 pPor
->Height( rInf
.GetTextHeight() );
893 pPor
->Height( pLast
->Height() );
894 pPor
->SetAscent( pLast
->GetAscent() );
898 if( pPor
->InTextGrp() && bCalc
)
900 pPor
->SetAscent(pPor
->GetAscent() +
901 rInf
.GetFont()->GetTopBorderSpace());
902 pPor
->Height(pPor
->Height() +
903 rInf
.GetFont()->GetTopBorderSpace() +
904 rInf
.GetFont()->GetBottomBorderSpace() );
910 class SwMetaPortion
: public SwTextPortion
912 Color m_aShadowColor
;
914 SwMetaPortion() { SetWhichPor( PortionType::Meta
); }
915 virtual void Paint( const SwTextPaintInfo
&rInf
) const override
;
916 void SetShadowColor(const Color
& rCol
) { m_aShadowColor
= rCol
; }
919 /// A content control portion is a text portion that is inside RES_TXTATR_CONTENTCONTROL.
920 class SwContentControlPortion
: public SwTextPortion
922 SwTextContentControl
* m_pTextContentControl
;
924 SwContentControlPortion(SwTextContentControl
* pTextContentControl
);
925 virtual void Paint(const SwTextPaintInfo
& rInf
) const override
;
927 /// Emits a PDF form widget for this portion on success, does nothing on failure.
928 bool DescribePDFControl(const SwTextPaintInfo
& rInf
) const;
932 void SwMetaPortion::Paint( const SwTextPaintInfo
&rInf
) const
936 rInf
.DrawViewOpt( *this, PortionType::Meta
,
937 // custom shading (RDF metadata)
938 COL_BLACK
== m_aShadowColor
942 SwTextPortion::Paint( rInf
);
946 SwContentControlPortion::SwContentControlPortion(SwTextContentControl
* pTextContentControl
)
947 : m_pTextContentControl(pTextContentControl
)
949 SetWhichPor(PortionType::ContentControl
);
952 bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo
& rInf
) const
954 auto pPDFExtOutDevData
= dynamic_cast<vcl::PDFExtOutDevData
*>(rInf
.GetOut()->GetExtOutDevData());
955 if (!pPDFExtOutDevData
)
960 if (!pPDFExtOutDevData
->GetIsExportFormFields())
965 if (!m_pTextContentControl
)
970 const SwFormatContentControl
& rFormatContentControl
= m_pTextContentControl
->GetContentControl();
971 const std::shared_ptr
<SwContentControl
>& pContentControl
= rFormatContentControl
.GetContentControl();
972 if (!pContentControl
)
977 SwTextNode
* pTextNode
= pContentControl
->GetTextNode();
978 SwDoc
& rDoc
= pTextNode
->GetDoc();
979 if (rDoc
.IsInHeaderFooter(*pTextNode
))
981 // Form control in header/footer makes no sense, would allow multiple values for the same
986 // Check if this is the first content control portion of this content control.
987 sal_Int32 nStart
= m_pTextContentControl
->GetStart();
988 sal_Int32 nEnd
= *m_pTextContentControl
->GetEnd();
989 TextFrameIndex nViewStart
= rInf
.GetTextFrame()->MapModelToView(pTextNode
, nStart
);
990 TextFrameIndex nViewEnd
= rInf
.GetTextFrame()->MapModelToView(pTextNode
, nEnd
);
991 // The content control portion starts 1 char after the starting dummy character.
992 if (rInf
.GetIdx() != nViewStart
+ TextFrameIndex(1))
994 // Ignore: don't process and also don't emit plain text fallback.
998 const SwPaM
aPam(*pTextNode
, nEnd
, *pTextNode
, nStart
);
999 static sal_Unicode
const aForbidden
[] = {
1000 CH_TXTATR_BREAKWORD
,
1003 const OUString aText
= comphelper::string::removeAny(aPam
.GetText(), aForbidden
);
1005 std::unique_ptr
<vcl::PDFWriter::AnyWidget
> pDescriptor
;
1006 switch (pContentControl
->GetType())
1008 case SwContentControlType::RICH_TEXT
:
1009 case SwContentControlType::PLAIN_TEXT
:
1011 pDescriptor
= std::make_unique
<vcl::PDFWriter::EditWidget
>();
1014 case SwContentControlType::CHECKBOX
:
1016 pDescriptor
= std::make_unique
<vcl::PDFWriter::CheckBoxWidget
>();
1017 auto pCheckBoxWidget
= static_cast<vcl::PDFWriter::CheckBoxWidget
*>(pDescriptor
.get());
1018 pCheckBoxWidget
->Checked
= pContentControl
->GetChecked();
1019 pCheckBoxWidget
->OnValue
= pContentControl
->GetCheckedState();
1020 pCheckBoxWidget
->OffValue
= pContentControl
->GetUncheckedState();
1023 case SwContentControlType::DROP_DOWN_LIST
:
1025 pDescriptor
= std::make_unique
<vcl::PDFWriter::ListBoxWidget
>();
1026 auto pListWidget
= static_cast<vcl::PDFWriter::ListBoxWidget
*>(pDescriptor
.get());
1027 pListWidget
->DropDown
= true;
1028 sal_Int32 nIndex
= 0;
1029 for (const auto& rItem
: pContentControl
->GetListItems())
1031 pListWidget
->Entries
.push_back(rItem
.m_aDisplayText
);
1032 if (rItem
.m_aDisplayText
== aText
)
1033 pListWidget
->SelectedEntries
.push_back(nIndex
);
1038 case SwContentControlType::COMBO_BOX
:
1040 pDescriptor
= std::make_unique
<vcl::PDFWriter::ComboBoxWidget
>();
1041 auto pComboWidget
= static_cast<vcl::PDFWriter::ComboBoxWidget
*>(pDescriptor
.get());
1042 for (const auto& rItem
: pContentControl
->GetListItems())
1044 pComboWidget
->Entries
.push_back(rItem
.m_aDisplayText
);
1048 case SwContentControlType::DATE
:
1050 pDescriptor
= std::make_unique
<vcl::PDFWriter::EditWidget
>();
1051 auto pEditWidget
= static_cast<vcl::PDFWriter::EditWidget
*>(pDescriptor
.get());
1052 pEditWidget
->Format
= vcl::PDFWriter::Date
;
1053 // GetDateFormat() uses a syntax that works with SvNumberFormatter::PutEntry(), PDF's
1054 // AFDate_FormatEx() uses a similar syntax, but uses lowercase characters in case of
1055 // "Y", "M" and "D" at least.
1056 pEditWidget
->DateFormat
= pContentControl
->GetDateFormat().toAsciiLowerCase();
1068 const SwFont
* pFont
= rInf
.GetFont();
1071 pDescriptor
->TextFont
= pFont
->GetActualFont();
1074 // Description for accessibility purposes.
1075 if (!pContentControl
->GetAlias().isEmpty())
1077 pDescriptor
->Description
= pContentControl
->GetAlias();
1080 // Map the text of the content control to the descriptor's text.
1081 pDescriptor
->Text
= aText
;
1083 // Calculate the bounding rectangle of this content control, which can be one or more layout
1084 // portions in one or more lines.
1086 auto pTextFrame
= const_cast<SwTextFrame
*>(rInf
.GetTextFrame());
1087 SwTextSizeInfo
aInf(pTextFrame
);
1088 SwTextCursor
aLine(pTextFrame
, &aInf
);
1089 SwRect aStartRect
, aEndRect
;
1090 aLine
.GetCharRect(&aStartRect
, nViewStart
);
1091 aLine
.GetCharRect(&aEndRect
, nViewEnd
);
1093 // Handling RTL text direction
1094 if(rInf
.GetTextFrame()->IsRightToLeft())
1096 rInf
.GetTextFrame()->SwitchLTRtoRTL( aStartRect
);
1097 rInf
.GetTextFrame()->SwitchLTRtoRTL( aEndRect
);
1099 // TODO: handle rInf.GetTextFrame()->IsVertical()
1101 aLocation
= aStartRect
;
1102 aLocation
.Union(aEndRect
);
1103 pDescriptor
->Location
= aLocation
.SVRect();
1105 pPDFExtOutDevData
->WrapBeginStructureElement(vcl::PDFWriter::Form
);
1106 pPDFExtOutDevData
->CreateControl(*pDescriptor
);
1107 pPDFExtOutDevData
->EndStructureElement();
1112 void SwContentControlPortion::Paint(const SwTextPaintInfo
& rInf
) const
1116 rInf
.DrawViewOpt(*this, PortionType::ContentControl
);
1118 if (DescribePDFControl(rInf
))
1123 SwTextPortion::Paint(rInf
);
1127 namespace sw::mark
{
1128 OUString
ExpandFieldmark(IFieldmark
* pBM
)
1130 if (pBM
->GetFieldname() == ODF_FORMCHECKBOX
)
1132 ::sw::mark::ICheckboxFieldmark
const*const pCheckboxFm(
1133 dynamic_cast<ICheckboxFieldmark
const*>(pBM
));
1134 assert(pCheckboxFm
);
1135 return pCheckboxFm
->IsChecked()
1136 ? OUString(u
"\u2612")
1137 : OUString(u
"\u2610");
1139 assert(pBM
->GetFieldname() == ODF_FORMDROPDOWN
);
1140 const IFieldmark::parameter_map_t
* const pParameters
= pBM
->GetParameters();
1141 sal_Int32 nCurrentIdx
= 0;
1142 const IFieldmark::parameter_map_t::const_iterator pResult
= pParameters
->find(ODF_FORMDROPDOWN_RESULT
);
1143 if(pResult
!= pParameters
->end())
1144 pResult
->second
>>= nCurrentIdx
;
1146 const IFieldmark::parameter_map_t::const_iterator pListEntries
= pParameters
->find(OUString(ODF_FORMDROPDOWN_LISTENTRY
));
1147 if (pListEntries
!= pParameters
->end())
1149 uno::Sequence
< OUString
> vListEntries
;
1150 pListEntries
->second
>>= vListEntries
;
1151 if (nCurrentIdx
< vListEntries
.getLength())
1152 return vListEntries
[nCurrentIdx
];
1155 static constexpr OUStringLiteral vEnSpaces
= u
"\u2002\u2002\u2002\u2002\u2002";
1160 SwTextPortion
*SwTextFormatter::WhichTextPor( SwTextFormatInfo
&rInf
) const
1162 SwTextPortion
*pPor
= nullptr;
1163 if( GetFnt()->IsTox() )
1165 pPor
= new SwToxPortion
;
1167 else if ( GetFnt()->IsInputField() )
1169 if (rInf
.GetOpt().IsFieldName())
1171 OUString aFieldName
= SwFieldType::GetTypeStr(SwFieldTypesEnum::Input
);
1172 // assume this is only the *first* portion and follows will be created elsewhere => input field must start at Idx
1173 assert(rInf
.GetText()[sal_Int32(rInf
.GetIdx())] == CH_TXT_ATR_INPUTFIELDSTART
);
1174 TextFrameIndex
nFieldLen(-1);
1175 for (TextFrameIndex i
= rInf
.GetIdx() + TextFrameIndex(1); ; ++i
)
1177 assert(rInf
.GetText()[sal_Int32(i
)] != CH_TXT_ATR_INPUTFIELDSTART
); // can't nest
1178 if (rInf
.GetText()[sal_Int32(i
)] == CH_TXT_ATR_INPUTFIELDEND
)
1180 nFieldLen
= i
+ TextFrameIndex(1) - rInf
.GetIdx();
1184 assert(2 <= sal_Int32(nFieldLen
));
1185 pPor
= new SwFieldPortion(aFieldName
, nullptr, nFieldLen
);
1189 pPor
= new SwTextInputFieldPortion();
1194 if( GetFnt()->IsRef() )
1195 pPor
= new SwRefPortion
;
1196 else if (GetFnt()->IsMeta())
1198 auto pMetaPor
= new SwMetaPortion
;
1200 // set custom LO_EXT_SHADING color, if it exists
1201 SwTextFrame
const*const pFrame(rInf
.GetTextFrame());
1202 SwPosition
aPosition(pFrame
->MapViewToModelPos(rInf
.GetIdx()));
1203 SwPaM
aPam(aPosition
);
1204 uno::Reference
<text::XTextContent
> const xRet(
1205 SwUnoCursorHelper::GetNestedTextContent(
1206 *aPam
.GetPointNode().GetTextNode(), aPosition
.GetContentIndex(), false) );
1209 const SwDoc
& rDoc
= rInf
.GetTextFrame()->GetDoc();
1210 static uno::Reference
< uno::XComponentContext
> xContext(
1211 ::comphelper::getProcessComponentContext());
1213 static uno::Reference
< rdf::XURI
> xODF_SHADING(
1214 rdf::URI::createKnown(xContext
, rdf::URIs::LO_EXT_SHADING
), uno::UNO_SET_THROW
);
1216 uno::Reference
<rdf::XDocumentMetadataAccess
> xDocumentMetadataAccess(
1217 rDoc
.GetDocShell()->GetBaseModel(), uno::UNO_QUERY
);
1219 const css::uno::Reference
<css::rdf::XResource
> xSubject(xRet
, uno::UNO_QUERY
);
1220 const uno::Reference
<rdf::XRepository
>& xRepository
=
1221 xDocumentMetadataAccess
->getRDFRepository();
1222 const uno::Reference
<container::XEnumeration
> xEnum(
1223 xRepository
->getStatements(xSubject
, xODF_SHADING
, nullptr), uno::UNO_SET_THROW
);
1225 while (xEnum
->hasMoreElements())
1227 rdf::Statement stmt
;
1228 if (!(xEnum
->nextElement() >>= stmt
)) {
1229 throw uno::RuntimeException();
1231 const uno::Reference
<rdf::XLiteral
> xObject(stmt
.Object
, uno::UNO_QUERY
);
1232 if (!xObject
.is()) continue;
1233 if (xEnum
->hasMoreElements()) {
1234 SAL_INFO("sw.uno", "ignoring other odf:shading statements");
1236 Color rColor
= Color::STRtoRGB(xObject
->getValue());
1237 pMetaPor
->SetShadowColor(rColor
);
1243 else if (GetFnt()->IsContentControl())
1245 SwTextFrame
const*const pFrame(rInf
.GetTextFrame());
1246 SwPosition
aPosition(pFrame
->MapViewToModelPos(rInf
.GetIdx()));
1247 SwTextNode
* pTextNode
= aPosition
.GetNode().GetTextNode();
1248 SwTextContentControl
* pTextContentControl
= nullptr;
1251 sal_Int32 nIndex
= aPosition
.GetContentIndex();
1252 if (SwTextAttr
* pAttr
= pTextNode
->GetTextAttrAt(nIndex
, RES_TXTATR_CONTENTCONTROL
, ::sw::GetTextAttrMode::Parent
))
1254 pTextContentControl
= static_txtattr_cast
<SwTextContentControl
*>(pAttr
);
1257 pPor
= new SwContentControlPortion(pTextContentControl
);
1262 // If pCurr does not have a width, it can however already have content.
1263 // E.g. for non-displayable characters
1265 auto const ch(rInf
.GetText()[sal_Int32(rInf
.GetIdx())]);
1266 SwTextFrame
const*const pFrame(rInf
.GetTextFrame());
1267 SwPosition
aPosition(pFrame
->MapViewToModelPos(rInf
.GetIdx()));
1268 sw::mark::IFieldmark
*pBM
= pFrame
->GetDoc().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPosition
);
1269 if(pBM
!= nullptr && pBM
->GetFieldname( ) == ODF_FORMDATE
)
1271 if (ch
== CH_TXT_ATR_FIELDSTART
)
1272 pPor
= new SwFieldFormDatePortion(pBM
, true);
1273 else if (ch
== CH_TXT_ATR_FIELDSEP
)
1274 pPor
= new SwFieldMarkPortion(); // it's added in DateFieldmark?
1275 else if (ch
== CH_TXT_ATR_FIELDEND
)
1276 pPor
= new SwFieldFormDatePortion(pBM
, false);
1278 else if (ch
== CH_TXT_ATR_FIELDSTART
)
1279 pPor
= new SwFieldMarkPortion();
1280 else if (ch
== CH_TXT_ATR_FIELDSEP
)
1281 pPor
= new SwFieldMarkPortion();
1282 else if (ch
== CH_TXT_ATR_FIELDEND
)
1283 pPor
= new SwFieldMarkPortion();
1284 else if (ch
== CH_TXT_ATR_FORMELEMENT
)
1286 OSL_ENSURE(pBM
!= nullptr, "Where is my form field bookmark???");
1289 if (pBM
->GetFieldname( ) == ODF_FORMCHECKBOX
)
1291 pPor
= new SwFieldFormCheckboxPortion();
1293 else if (pBM
->GetFieldname( ) == ODF_FORMDROPDOWN
)
1295 pPor
= new SwFieldFormDropDownPortion(pBM
, sw::mark::ExpandFieldmark(pBM
));
1297 /* we need to check for ODF_FORMTEXT for scenario having FormFields inside FORMTEXT.
1298 * Otherwise file will crash on open.
1300 else if (pBM
->GetFieldname( ) == ODF_FORMTEXT
)
1302 pPor
= new SwFieldMarkPortion();
1308 if( !rInf
.X() && !m_pCurr
->GetNextPortion() && !m_pCurr
->GetLen() )
1311 pPor
= new SwTextPortion
;
1318 // We calculate the length, the following portion limits are defined:
1321 // 3) CH_TXTATR_BREAKWORD / CH_TXTATR_INWORD
1322 // 4) next attribute change
1324 SwTextPortion
*SwTextFormatter::NewTextPortion( SwTextFormatInfo
&rInf
)
1326 // If we're at the line's beginning, we take pCurr
1327 // If pCurr is not derived from SwTextPortion, we need to duplicate
1328 Seek( rInf
.GetIdx() );
1329 SwTextPortion
*pPor
= WhichTextPor( rInf
);
1331 // until next attribute change:
1332 const TextFrameIndex nNextAttr
= GetNextAttr();
1333 TextFrameIndex nNextChg
= std::min(nNextAttr
, TextFrameIndex(rInf
.GetText().getLength()));
1335 // end of script type:
1336 const TextFrameIndex nNextScript
= m_pScriptInfo
->NextScriptChg(rInf
.GetIdx());
1337 nNextChg
= std::min( nNextChg
, nNextScript
);
1339 // end of direction:
1340 const TextFrameIndex nNextDir
= m_pScriptInfo
->NextDirChg(rInf
.GetIdx());
1341 nNextChg
= std::min( nNextChg
, nNextDir
);
1343 // hidden change (potentially via bookmark):
1344 const TextFrameIndex nNextHidden
= m_pScriptInfo
->NextHiddenChg(rInf
.GetIdx());
1345 nNextChg
= std::min( nNextChg
, nNextHidden
);
1348 const TextFrameIndex nNextBookmark
= m_pScriptInfo
->NextBookmark(rInf
.GetIdx());
1349 nNextChg
= std::min(nNextChg
, nNextBookmark
);
1352 // We assume that font characters are not larger than twice
1353 // as wide as height.
1354 // Very crazy: we need to take the ascent into account.
1356 // Mind the trap! GetSize() contains the wished-for height, the real height
1357 // is only known in CalcAscent!
1359 // The ratio is even crazier: a blank in Times New Roman has an ascent of
1360 // 182, a height of 200 and a width of 53!
1361 // It follows that a line with a lot of blanks is processed incorrectly.
1362 // Therefore we increase from factor 2 to 8 (due to negative kerning).
1364 pPor
->SetLen(TextFrameIndex(1));
1365 CalcAscent( rInf
, pPor
);
1367 const SwFont
* pTmpFnt
= rInf
.GetFont();
1368 sal_Int32 nExpect
= std::min( sal_Int32( pTmpFnt
->GetHeight() ),
1369 sal_Int32( pPor
->GetAscent() ) ) / 8;
1372 nExpect
= sal_Int32(rInf
.GetIdx()) + (rInf
.GetLineWidth() / nExpect
);
1373 if (TextFrameIndex(nExpect
) > rInf
.GetIdx() && nNextChg
> TextFrameIndex(nExpect
))
1374 nNextChg
= TextFrameIndex(std::min(nExpect
, rInf
.GetText().getLength()));
1376 // we keep an invariant during method calls:
1377 // there are no portion ending characters like hard spaces
1378 // or tabs in [ nLeftScanIdx, nRightScanIdx ]
1379 if ( m_nLeftScanIdx
<= rInf
.GetIdx() && rInf
.GetIdx() <= m_nRightScanIdx
)
1381 if ( nNextChg
> m_nRightScanIdx
)
1382 nNextChg
= m_nRightScanIdx
=
1383 rInf
.ScanPortionEnd( m_nRightScanIdx
, nNextChg
);
1387 m_nLeftScanIdx
= rInf
.GetIdx();
1388 nNextChg
= m_nRightScanIdx
=
1389 rInf
.ScanPortionEnd( rInf
.GetIdx(), nNextChg
);
1392 pPor
->SetLen( nNextChg
- rInf
.GetIdx() );
1393 rInf
.SetLen( pPor
->GetLen() );
1397 // first portions have no length
1398 SwLinePortion
*SwTextFormatter::WhichFirstPortion(SwTextFormatInfo
&rInf
)
1400 SwLinePortion
*pPor
= nullptr;
1402 if( rInf
.GetRest() )
1405 if( '\0' != rInf
.GetHookChar() )
1408 pPor
= rInf
.GetRest();
1409 if( pPor
->IsErgoSumPortion() )
1410 rInf
.SetErgoDone(true);
1412 if( pPor
->IsFootnoteNumPortion() )
1413 rInf
.SetFootnoteDone(true);
1415 if( pPor
->InNumberGrp() )
1416 rInf
.SetNumDone(true);
1418 rInf
.SetRest(nullptr);
1419 m_pCurr
->SetRest( true );
1423 // We can stand in the follow, it's crucial that
1424 // pFrame->GetOffset() == 0!
1427 // We now too can elongate FootnotePortions and ErgoSumPortions
1429 // 1. The ErgoSumTexts
1430 if( !rInf
.IsErgoDone() )
1432 if( m_pFrame
->IsInFootnote() && !m_pFrame
->GetIndPrev() )
1433 pPor
= NewErgoSumPortion( rInf
);
1434 rInf
.SetErgoDone( true );
1437 // 2. Arrow portions
1438 if( !pPor
&& !rInf
.IsArrowDone() )
1440 if( m_pFrame
->GetOffset() && !m_pFrame
->IsFollow() &&
1441 rInf
.GetIdx() == m_pFrame
->GetOffset() )
1442 pPor
= new SwArrowPortion( *m_pCurr
);
1443 rInf
.SetArrowDone( true );
1446 // 3. Kerning portions at beginning of line in grid mode
1447 if ( ! pPor
&& ! m_pCurr
->GetNextPortion() )
1449 SwTextGridItem
const*const pGrid(
1450 GetGridItem(GetTextFrame()->FindPageFrame()));
1452 pPor
= new SwKernPortion( *m_pCurr
);
1455 // 4. The line rests (multiline fields)
1458 pPor
= rInf
.GetRest();
1459 // Only for pPor of course
1462 m_pCurr
->SetRest( true );
1463 rInf
.SetRest(nullptr);
1469 // 5. The foot note count
1470 if( !rInf
.IsFootnoteDone() )
1472 OSL_ENSURE( ( ! rInf
.IsMulti() && ! m_pMulti
) || m_pMulti
->HasRotation(),
1473 "Rotated number portion trouble" );
1475 const bool bFootnoteNum
= m_pFrame
->IsFootnoteNumFrame();
1476 rInf
.GetParaPortion()->SetFootnoteNum( bFootnoteNum
);
1478 pPor
= NewFootnoteNumPortion( rInf
);
1479 rInf
.SetFootnoteDone( true );
1482 // 6. The ErgoSumTexts of course also exist in the TextMaster,
1483 // it's crucial whether the SwFootnoteFrame is aFollow
1484 if( !rInf
.IsErgoDone() && !pPor
&& ! rInf
.IsMulti() )
1486 if( m_pFrame
->IsInFootnote() && !m_pFrame
->GetIndPrev() )
1487 pPor
= NewErgoSumPortion( rInf
);
1488 rInf
.SetErgoDone( true );
1492 if( !rInf
.IsNumDone() && !pPor
)
1494 OSL_ENSURE( ( ! rInf
.IsMulti() && ! m_pMulti
) || m_pMulti
->HasRotation(),
1495 "Rotated number portion trouble" );
1497 // If we're in the follow, then of course not
1498 if (GetTextFrame()->GetTextNodeForParaProps()->GetNumRule())
1499 pPor
= NewNumberPortion( rInf
);
1500 rInf
.SetNumDone( true );
1503 if( !pPor
&& GetDropFormat() && ! rInf
.IsMulti() )
1504 pPor
= NewDropPortion( rInf
);
1506 // 9. Kerning portions at beginning of line in grid mode
1507 if ( !pPor
&& !m_pCurr
->GetNextPortion() )
1509 SwTextGridItem
const*const pGrid(
1510 GetGridItem(GetTextFrame()->FindPageFrame()));
1512 pPor
= new SwKernPortion( *m_pCurr
);
1516 // 10. Decimal tab portion at the beginning of each line in table cells
1517 if ( !pPor
&& !m_pCurr
->GetNextPortion() &&
1518 GetTextFrame()->IsInTab() &&
1519 GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::TAB_COMPAT
))
1521 pPor
= NewTabPortion( rInf
, true );
1524 // 11. suffix of meta-field
1527 pPor
= TryNewNoLengthPortion(rInf
);
1531 // check this *last* so that BuildMultiPortion() can find it!
1532 if (!pPor
&& rInf
.CheckCurrentPosBookmark())
1534 const auto& bookmark
= m_pScriptInfo
->GetBookmarks(rInf
.GetIdx());
1535 if (!bookmark
.empty())
1537 // only for character width, maybe replaced with ] later
1538 sal_Unicode mark
= '[';
1540 pPor
= new SwBookmarkPortion(mark
, bookmark
);
1547 static bool lcl_OldFieldRest( const SwLineLayout
* pCurr
)
1549 if( !pCurr
->GetNext() )
1551 const SwLinePortion
*pPor
= pCurr
->GetNext()->GetNextPortion();
1553 while( pPor
&& !bRet
)
1555 bRet
= (pPor
->InFieldGrp() && static_cast<const SwFieldPortion
*>(pPor
)->IsFollow()) ||
1556 (pPor
->IsMultiPortion() && static_cast<const SwMultiPortion
*>(pPor
)->IsFollowField());
1557 if( !pPor
->GetLen() )
1559 pPor
= pPor
->GetNextPortion();
1564 /* NewPortion sets rInf.nLen
1565 * A SwTextPortion is limited by a tab, break, txtatr or attr change
1566 * We can have three cases:
1567 * 1) The line is full and the wrap was not emulated
1569 * 2) The line is full and a wrap was emulated
1570 * -> Reset width and return new FlyPortion
1571 * 3) We need to construct a new portion
1572 * -> CalcFlyWidth emulates the width and return portion, if needed
1575 SwLinePortion
*SwTextFormatter::NewPortion(SwTextFormatInfo
&rInf
,
1576 ::std::optional
<TextFrameIndex
> const oMovedFlyIndex
)
1578 if (oMovedFlyIndex
&& *oMovedFlyIndex
<= rInf
.GetIdx())
1580 SAL_WARN_IF(*oMovedFlyIndex
!= rInf
.GetIdx(), "sw.core", "stopping too late, no portion break at fly anchor?");
1585 // Underflow takes precedence
1586 rInf
.SetStopUnderflow( false );
1587 if( rInf
.GetUnderflow() )
1589 OSL_ENSURE( rInf
.IsFull(), "SwTextFormatter::NewPortion: underflow but not full" );
1590 return Underflow( rInf
);
1593 // If the line is full, flys and Underflow portions could be waiting ...
1596 // LineBreaks and Flys (bug05.sdw)
1598 if( rInf
.IsNewLine() && (!rInf
.GetFly() || !m_pCurr
->IsDummy()) )
1601 // When the text bumps into the Fly, or when the Fly comes first because
1602 // it juts out over the left edge, GetFly() is returned.
1603 // When IsFull() and no GetFly() is available, naturally zero is returned.
1606 if( rInf
.GetLast()->IsBreakPortion() )
1608 delete rInf
.GetFly();
1609 rInf
.SetFly( nullptr );
1612 return rInf
.GetFly();
1615 // A nasty special case: A frame without wrap overlaps the Footnote area.
1616 // We must declare the Footnote portion as rest of line, so that
1617 // SwTextFrame::Format doesn't abort (the text mass already was formatted).
1618 if( rInf
.GetRest() )
1619 rInf
.SetNewLine( true );
1622 // When the next line begins with a rest of a field, but now no
1623 // rest remains, the line must definitely be formatted anew!
1624 if( lcl_OldFieldRest( GetCurr() ) )
1625 rInf
.SetNewLine( true );
1628 SwLinePortion
*pFirst
= WhichFirstPortion( rInf
);
1631 rInf
.SetNewLine( true );
1632 if( pFirst
->InNumberGrp() )
1633 rInf
.SetNumDone( false) ;
1642 SwLinePortion
*pPor
= WhichFirstPortion( rInf
);
1644 // Check for Hidden Portion:
1647 TextFrameIndex nEnd
= rInf
.GetIdx();
1648 if ( ::lcl_BuildHiddenPortion( rInf
, nEnd
) )
1649 pPor
= new SwHiddenTextPortion( nEnd
- rInf
.GetIdx() );
1654 if( ( !m_pMulti
|| m_pMulti
->IsBidi() ) &&
1656 // No multi portion if there is a hook character waiting:
1657 ( !rInf
.GetRest() || '\0' == rInf
.GetHookChar() ) )
1659 // We open a multiportion part, if we enter a multi-line part
1660 // of the paragraph.
1661 TextFrameIndex nEnd
= rInf
.GetIdx();
1662 std::optional
<SwMultiCreator
> pCreate
= rInf
.GetMultiCreator( nEnd
, m_pMulti
);
1665 SwMultiPortion
* pTmp
= nullptr;
1667 if ( SwMultiCreatorId::Bidi
== pCreate
->nId
)
1668 pTmp
= new SwBidiPortion( nEnd
, pCreate
->nLevel
);
1669 else if ( SwMultiCreatorId::Ruby
== pCreate
->nId
)
1671 pTmp
= new SwRubyPortion( *pCreate
, *rInf
.GetFont(),
1672 GetTextFrame()->GetDoc().getIDocumentSettingAccess(),
1673 nEnd
, TextFrameIndex(0), rInf
);
1675 else if( SwMultiCreatorId::Rotate
== pCreate
->nId
)
1677 pTmp
= new SwRotatedPortion( *pCreate
, nEnd
,
1678 GetTextFrame()->IsRightToLeft() );
1679 GetTextFrame()->SetHasRotatedPortions(true);
1682 pTmp
= new SwDoubleLinePortion( *pCreate
, nEnd
);
1685 CalcFlyWidth( rInf
);
1691 sal_Unicode cChar
= rInf
.GetHookChar();
1695 /* We fetch cChar again to be sure that the tab is pending now and
1696 * didn't move to the next line (as happens behind frames).
1697 * However, when a FieldPortion is in the rest, we must naturally fetch
1698 * the cChar from the field content, e.g. DecimalTabs and fields (22615)
1700 if( !rInf
.GetRest() || !rInf
.GetRest()->InFieldGrp() )
1701 cChar
= rInf
.GetChar( rInf
.GetIdx() );
1702 rInf
.ClearHookChar();
1706 if (rInf
.GetIdx() >= TextFrameIndex(rInf
.GetText().getLength()))
1709 CalcFlyWidth( rInf
);
1712 cChar
= rInf
.GetChar( rInf
.GetIdx() );
1718 pPor
= NewTabPortion( rInf
, false ); break;
1722 SwTextAttr
* pHint
= GetAttr(rInf
.GetIdx());
1723 pPor
= new SwBreakPortion(*rInf
.GetLast(), pHint
);
1727 case CHAR_SOFTHYPHEN
: // soft hyphen
1728 pPor
= new SwSoftHyphPortion
; break;
1730 case CHAR_HARDBLANK
: // no-break space
1731 // Please check tdf#115067 if you want to edit the char
1732 pPor
= new SwBlankPortion( cChar
); break;
1734 case CHAR_HARDHYPHEN
: // non-breaking hyphen
1735 pPor
= new SwBlankPortion( '-' ); break;
1737 case CHAR_ZWSP
: // zero width space
1738 case CHAR_WJ
: // word joiner
1739 pPor
= new SwControlCharPortion( cChar
); break;
1741 case CH_TXTATR_BREAKWORD
:
1742 case CH_TXTATR_INWORD
:
1743 if( rInf
.HasHint( rInf
.GetIdx() ) )
1745 pPor
= NewExtraPortion( rInf
);
1751 SwTabPortion
* pLastTabPortion
= rInf
.GetLastTab();
1752 if ( pLastTabPortion
&& cChar
== rInf
.GetTabDecimal() )
1754 // Abandon dec. tab position if line is full
1755 // We have a decimal tab portion in the line and the next character has to be
1756 // aligned at the tab stop position. We store the width from the beginning of
1757 // the tab stop portion up to the portion containing the decimal separator:
1758 if (GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::TAB_COMPAT
) /*rInf.GetVsh()->IsTabCompat();*/ &&
1759 PortionType::TabDecimal
== pLastTabPortion
->GetWhichPor() )
1761 OSL_ENSURE( rInf
.X() >= pLastTabPortion
->GetFix(), "Decimal tab stop position cannot be calculated" );
1762 const sal_uInt16 nWidthOfPortionsUpToDecimalPosition
= o3tl::narrowing
<sal_uInt16
>(rInf
.X() - pLastTabPortion
->GetFix() );
1763 static_cast<SwTabDecimalPortion
*>(pLastTabPortion
)->SetWidthOfPortionsUpToDecimalPosition( nWidthOfPortionsUpToDecimalPosition
);
1764 rInf
.SetTabDecimal( 0 );
1767 rInf
.SetFull( rInf
.GetLastTab()->Format( rInf
) );
1770 if( rInf
.GetRest() )
1774 rInf
.SetNewLine(true);
1777 pPor
= rInf
.GetRest();
1778 rInf
.SetRest(nullptr);
1784 pPor
= NewTextPortion( rInf
);
1790 // if a portion is created despite there being a pending RestPortion,
1791 // then it is a field which has been split (e.g. because it contains a Tab)
1792 if( pPor
&& rInf
.GetRest() )
1793 pPor
->SetLen(TextFrameIndex(0));
1796 if( !pPor
|| rInf
.IsStop() )
1803 assert(pPor
&& "can only reach here with pPor existing");
1805 // Special portions containing numbers (footnote anchor, footnote number,
1806 // numbering) can be contained in a rotated portion, if the user
1807 // choose a rotated character attribute.
1810 if ( pPor
->IsFootnotePortion() )
1812 const SwTextFootnote
* pTextFootnote
= static_cast<SwFootnotePortion
*>(pPor
)->GetTextFootnote();
1814 if ( pTextFootnote
)
1816 SwFormatFootnote
& rFootnote
= const_cast<SwFormatFootnote
&>(pTextFootnote
->GetFootnote());
1817 const SwDoc
*const pDoc
= &rInf
.GetTextFrame()->GetDoc();
1818 const SwEndNoteInfo
* pInfo
;
1819 if( rFootnote
.IsEndNote() )
1820 pInfo
= &pDoc
->GetEndNoteInfo();
1822 pInfo
= &pDoc
->GetFootnoteInfo();
1823 const SwAttrSet
& rSet
= pInfo
->GetAnchorCharFormat(const_cast<SwDoc
&>(*pDoc
))->GetAttrSet();
1826 if( const SvxCharRotateItem
* pItem
= rSet
.GetItemIfSet( RES_CHRATR_ROTATE
) )
1827 nDir
= pItem
->GetValue();
1832 pPor
= new SwRotatedPortion(rInf
.GetIdx() + TextFrameIndex(1),
1839 else if ( pPor
->InNumberGrp() )
1841 const SwFont
* pNumFnt
= static_cast<SwFieldPortion
*>(pPor
)->GetFont();
1845 Degree10 nDir
= pNumFnt
->GetOrientation( rInf
.GetTextFrame()->IsVertical() );
1849 pPor
= new SwRotatedPortion(TextFrameIndex(0), 900_deg10
== nDir
1853 rInf
.SetNumDone( false );
1854 rInf
.SetFootnoteDone( false );
1860 // The font is set in output device,
1861 // the ascent and the height will be calculated.
1862 if( !pPor
->GetAscent() && !pPor
->Height() )
1863 CalcAscent( rInf
, pPor
);
1864 rInf
.SetLen( pPor
->GetLen() );
1866 // In CalcFlyWidth Width() will be shortened if a FlyPortion is present.
1867 CalcFlyWidth( rInf
);
1869 // One must not forget that pCurr as GetLast() must provide reasonable values:
1870 if( !m_pCurr
->Height() )
1872 OSL_ENSURE( m_pCurr
->Height(), "SwTextFormatter::NewPortion: limbo dance" );
1873 m_pCurr
->Height( pPor
->Height(), false );
1874 m_pCurr
->SetAscent( pPor
->GetAscent() );
1877 OSL_ENSURE(pPor
->Height(), "SwTextFormatter::NewPortion: something went wrong");
1878 if( pPor
->IsPostItsPortion() && rInf
.X() >= rInf
.Width() && rInf
.GetFly() )
1881 pPor
= rInf
.GetFly();
1886 TextFrameIndex
SwTextFormatter::FormatLine(TextFrameIndex
const nStartPos
)
1888 OSL_ENSURE( ! m_pFrame
->IsVertical() || m_pFrame
->IsSwapped(),
1889 "SwTextFormatter::FormatLine( nStartPos ) with unswapped frame" );
1891 // For the formatting routines, we set pOut to the reference device.
1892 SwHookOut
aHook( GetInfo() );
1893 if (GetInfo().GetLen() < TextFrameIndex(GetInfo().GetText().getLength()))
1894 GetInfo().SetLen(TextFrameIndex(GetInfo().GetText().getLength()));
1897 SetFlyInCntBase( false );
1898 GetInfo().SetLineHeight( 0 );
1899 GetInfo().SetLineNetHeight( 0 );
1901 // Recycling must be suppressed by changed line height and also
1902 // by changed ascent (lowering of baseline).
1903 const SwTwips nOldHeight
= m_pCurr
->Height();
1904 const SwTwips nOldAscent
= m_pCurr
->GetAscent();
1906 m_pCurr
->SetEndHyph( false );
1907 m_pCurr
->SetMidHyph( false );
1909 // fly positioning can make it necessary format a line several times
1910 // for this, we have to keep a copy of our rest portion
1911 SwLinePortion
* pField
= GetInfo().GetRest();
1912 std::unique_ptr
<SwFieldPortion
> xSaveField
;
1914 if ( pField
&& pField
->InFieldGrp() && !pField
->IsFootnotePortion() )
1915 xSaveField
.reset(new SwFieldPortion( *static_cast<SwFieldPortion
*>(pField
) ));
1917 // for an optimal repaint rectangle, we want to compare fly portions
1918 // before and after the BuildPortions call
1919 const bool bOptimizeRepaint
= AllowRepaintOpt();
1920 TextFrameIndex
const nOldLineEnd
= nStartPos
+ m_pCurr
->GetLen();
1921 std::vector
<tools::Long
> flyStarts
;
1923 // these are the conditions for a fly position comparison
1924 if ( bOptimizeRepaint
&& m_pCurr
->IsFly() )
1926 SwLinePortion
* pPor
= m_pCurr
->GetFirstPortion();
1927 tools::Long nPOfst
= 0;
1930 if ( pPor
->IsFlyPortion() )
1931 // insert start value of fly portion
1932 flyStarts
.push_back( nPOfst
);
1934 nPOfst
+= pPor
->Width();
1935 pPor
= pPor
->GetNextPortion();
1939 // Here soon the underflow check follows.
1942 GetInfo().SetFootnoteInside( false );
1943 GetInfo().SetOtherThanFootnoteInside( false );
1945 // These values must not be reset by FormatReset();
1946 const bool bOldNumDone
= GetInfo().IsNumDone();
1947 const bool bOldFootnoteDone
= GetInfo().IsFootnoteDone();
1948 const bool bOldArrowDone
= GetInfo().IsArrowDone();
1949 const bool bOldErgoDone
= GetInfo().IsErgoDone();
1951 // besides other things, this sets the repaint offset to 0
1952 FormatReset( GetInfo() );
1954 GetInfo().SetNumDone( bOldNumDone
);
1955 GetInfo().SetFootnoteDone(bOldFootnoteDone
);
1956 GetInfo().SetArrowDone( bOldArrowDone
);
1957 GetInfo().SetErgoDone( bOldErgoDone
);
1959 // build new portions for this line
1960 BuildPortions( GetInfo() );
1962 if( GetInfo().IsStop() )
1964 m_pCurr
->SetLen(TextFrameIndex(0));
1965 m_pCurr
->Height( GetFrameRstHeight() + 1, false );
1966 m_pCurr
->SetRealHeight( GetFrameRstHeight() + 1 );
1968 // Don't oversize the line in case of split flys, so we don't try to move the anchor
1969 // of a precede fly forward, next to its follow.
1970 if (m_pFrame
->HasNonLastSplitFlyDrawObj())
1972 m_pCurr
->SetRealHeight(GetFrameRstHeight());
1976 m_pCurr
->Truncate();
1979 else if( GetInfo().IsDropInit() )
1982 GetInfo().SetDropInit( false );
1985 m_pCurr
->CalcLine( *this, GetInfo() );
1986 CalcRealHeight( GetInfo().IsNewLine() );
1988 //i#120864 For Special case that at the first calculation couldn't get
1989 //correct height. And need to recalculate for the right height.
1990 SwLinePortion
* pPorTmp
= m_pCurr
->GetNextPortion();
1991 if ( IsFlyInCntBase() && (!IsQuick() || (pPorTmp
&& pPorTmp
->IsFlyCntPortion() && !pPorTmp
->GetNextPortion() &&
1992 m_pCurr
->Height() > pPorTmp
->Height())))
1994 SwTwips nTmpAscent
, nTmpHeight
;
1995 CalcAscentAndHeight( nTmpAscent
, nTmpHeight
);
1996 AlignFlyInCntBase( Y() + tools::Long( nTmpAscent
) );
1997 m_pCurr
->CalcLine( *this, GetInfo() );
2001 // bBuild decides if another lap of honor is done
2002 if ( m_pCurr
->GetRealHeight() <= GetInfo().GetLineHeight() )
2004 m_pCurr
->SetRealHeight( GetInfo().GetLineHeight() );
2009 bBuild
= ( GetInfo().GetTextFly().IsOn() && ChkFlyUnderflow(GetInfo()) )
2010 || GetInfo().CheckFootnotePortion(m_pCurr
);
2013 // fdo44018-2.doc: only restore m_bNumDone if a SwNumberPortion will be truncated
2014 for (SwLinePortion
* pPor
= m_pCurr
->GetNextPortion(); pPor
; pPor
= pPor
->GetNextPortion())
2016 if (pPor
->InNumberGrp())
2018 GetInfo().SetNumDone( bOldNumDone
);
2022 GetInfo().ResetMaxWidthDiff();
2025 if ( GetInfo().GetRest() )
2027 delete GetInfo().GetRest();
2028 GetInfo().SetRest( nullptr );
2031 // set original rest portion
2033 GetInfo().SetRest( new SwFieldPortion( *xSaveField
) );
2035 m_pCurr
->SetLen(TextFrameIndex(0));
2037 m_pCurr
->Truncate();
2042 // In case of compat mode, it's possible that a tab portion is wider after
2043 // formatting than before. If this is the case, we also have to make sure
2044 // the SwLineLayout is wider as well.
2045 if (GetInfo().GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::TAB_OVER_MARGIN
))
2047 sal_uInt16 nSum
= 0;
2048 SwLinePortion
* pPor
= m_pCurr
->GetFirstPortion();
2052 nSum
+= pPor
->Width();
2053 pPor
= pPor
->GetNextPortion();
2056 if (nSum
> m_pCurr
->Width())
2057 m_pCurr
->Width(nSum
);
2060 // calculate optimal repaint rectangle
2061 if ( bOptimizeRepaint
)
2063 GetInfo().SetPaintOfst( ::lcl_CalcOptRepaint( *this, *m_pCurr
, nOldLineEnd
, flyStarts
) );
2067 // Special case: we do not allow an optimization of the repaint
2068 // area, but during formatting the repaint offset is set to indicate
2069 // a maximum value for the offset. This value has to be reset:
2070 GetInfo().SetPaintOfst( 0 );
2072 // This corrects the start of the reformat range if something has
2073 // moved to the next line. Otherwise IsFirstReformat in AllowRepaintOpt
2074 // will give us a wrong result if we have to reformat another line
2075 GetInfo().GetParaPortion()->GetReformat().LeftMove( GetInfo().GetIdx() );
2077 // delete master copy of rest portion
2080 TextFrameIndex
const nNewStart
= nStartPos
+ m_pCurr
->GetLen();
2082 // adjust text if kana compression is enabled
2083 if ( GetInfo().CompressLine() )
2085 SwTwips nRepaintOfst
= CalcKanaAdj( m_pCurr
);
2087 // adjust repaint offset
2088 if ( nRepaintOfst
< GetInfo().GetPaintOfst() )
2089 GetInfo().SetPaintOfst( nRepaintOfst
);
2092 CalcAdjustLine( m_pCurr
);
2094 if( nOldHeight
!= m_pCurr
->Height() || nOldAscent
!= m_pCurr
->GetAscent() )
2097 GetInfo().SetPaintOfst( 0 ); // changed line height => no recycling
2098 // all following line must be painted and when Flys are around,
2100 GetInfo().SetShift( true );
2103 if ( IsFlyInCntBase() && !IsQuick() )
2104 UpdatePos( m_pCurr
, GetTopLeft(), GetStart() );
2109 void SwTextFormatter::RecalcRealHeight()
2117 void SwTextFormatter::CalcRealHeight( bool bNewLine
)
2119 SwTwips nLineHeight
= m_pCurr
->Height();
2120 m_pCurr
->SetClipping( false );
2122 SwTextGridItem
const*const pGrid(GetGridItem(m_pFrame
->FindPageFrame()));
2123 if ( pGrid
&& GetInfo().SnapToGrid() )
2125 const sal_uInt16 nGridWidth
= pGrid
->GetBaseHeight();
2126 const sal_uInt16 nRubyHeight
= pGrid
->GetRubyHeight();
2127 const bool bRubyTop
= ! pGrid
->GetRubyTextBelow();
2129 nLineHeight
= nGridWidth
+ nRubyHeight
;
2130 const sal_uInt16 nAmpRatio
= (m_pCurr
->Height() + nLineHeight
- 1)/nLineHeight
;
2131 nLineHeight
*= nAmpRatio
;
2133 const sal_uInt16 nAsc
= m_pCurr
->GetAscent() +
2135 ( nLineHeight
- m_pCurr
->Height() + nRubyHeight
) / 2 :
2136 ( nLineHeight
- m_pCurr
->Height() - nRubyHeight
) / 2 );
2138 m_pCurr
->Height( nLineHeight
, false );
2139 m_pCurr
->SetAscent( nAsc
);
2140 m_pInf
->GetParaPortion()->SetFixLineHeight();
2142 // we ignore any line spacing options except from ...
2143 const SvxLineSpacingItem
* pSpace
= m_aLineInf
.GetLineSpacing();
2144 if ( ! IsParaLine() && pSpace
&&
2145 SvxInterLineSpaceRule::Prop
== pSpace
->GetInterLineSpaceRule() )
2147 sal_uLong nTmp
= pSpace
->GetPropLineSpace();
2152 nTmp
*= nLineHeight
;
2153 nLineHeight
= nTmp
/ 100;
2156 m_pCurr
->SetRealHeight( nLineHeight
);
2160 // The dummy flag is set on lines that only contain flyportions, these shouldn't
2161 // consider register-true and so on. Unfortunately an empty line can be at
2162 // the end of a paragraph (empty paragraphs or behind a Shift-Return),
2163 // which should consider the register.
2164 if (!m_pCurr
->IsDummy() || (!m_pCurr
->GetNext()
2165 && GetStart() >= TextFrameIndex(GetTextFrame()->GetText().getLength())
2168 const SvxLineSpacingItem
*pSpace
= m_aLineInf
.GetLineSpacing();
2171 switch( pSpace
->GetLineSpaceRule() )
2173 case SvxLineSpaceRule::Auto
:
2174 // shrink first line of paragraph too on spacing < 100%
2176 pSpace
->GetInterLineSpaceRule() == SvxInterLineSpaceRule::Prop
2177 && GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::PROP_LINE_SPACING_SHRINKS_FIRST_LINE
))
2179 tools::Long nTmp
= pSpace
->GetPropLineSpace();
2180 // Word will render < 50% too but it's just not readable
2182 nTmp
= nTmp
? 50 : 100;
2183 if (nTmp
<100) { // code adapted from fixed line height
2184 nTmp
*= nLineHeight
;
2189 sal_uInt16 nAsc
= ( 4 * nLineHeight
) / 5; // 80%
2191 // could do clipping here (like Word does)
2192 // but at 0.5 its unreadable either way...
2193 if( nAsc
< pCurr
->GetAscent() ||
2194 nLineHeight
- nAsc
< pCurr
->Height() -
2195 pCurr
->GetAscent() )
2196 pCurr
->SetClipping( true );
2198 m_pCurr
->SetAscent( nAsc
);
2199 m_pCurr
->Height( nLineHeight
, false );
2200 m_pInf
->GetParaPortion()->SetFixLineHeight();
2204 case SvxLineSpaceRule::Min
:
2206 if( nLineHeight
< pSpace
->GetLineHeight() )
2207 nLineHeight
= pSpace
->GetLineHeight();
2210 case SvxLineSpaceRule::Fix
:
2212 nLineHeight
= pSpace
->GetLineHeight();
2213 const sal_uInt16 nAsc
= ( 4 * nLineHeight
) / 5; // 80%
2214 if( nAsc
< m_pCurr
->GetAscent() ||
2215 nLineHeight
- nAsc
< m_pCurr
->Height() - m_pCurr
->GetAscent() )
2216 m_pCurr
->SetClipping( true );
2217 m_pCurr
->Height( nLineHeight
, false );
2218 m_pCurr
->SetAscent( nAsc
);
2219 m_pInf
->GetParaPortion()->SetFixLineHeight();
2222 default: OSL_FAIL( ": unknown LineSpaceRule" );
2224 // Note: for the _first_ line the line spacing of the previous
2225 // paragraph is applied in SwFlowFrame::CalcUpperSpace()
2227 switch( pSpace
->GetInterLineSpaceRule() )
2229 case SvxInterLineSpaceRule::Off
:
2231 case SvxInterLineSpaceRule::Prop
:
2233 tools::Long nTmp
= pSpace
->GetPropLineSpace();
2234 // 50% is the minimum, if 0% we switch to the
2235 // default value 100% ...
2237 nTmp
= nTmp
? 50 : 100;
2239 // extend line height by (nPropLineSpace - 100) percent of the font height
2241 nTmp
*= m_pCurr
->GetTextHeight();
2243 nTmp
+= nLineHeight
;
2249 case SvxInterLineSpaceRule::Fix
:
2251 nLineHeight
= nLineHeight
+ pSpace
->GetInterLineSpace();
2254 default: OSL_FAIL( ": unknown InterLineSpaceRule" );
2258 if( IsRegisterOn() )
2260 SwTwips nTmpY
= Y() + m_pCurr
->GetAscent() + nLineHeight
- m_pCurr
->Height();
2261 SwRectFnSet
aRectFnSet(m_pFrame
);
2262 if ( aRectFnSet
.IsVert() )
2263 nTmpY
= m_pFrame
->SwitchHorizontalToVertical( nTmpY
);
2264 nTmpY
= aRectFnSet
.YDiff( nTmpY
, RegStart() );
2265 const sal_uInt16 nDiff
= sal_uInt16( nTmpY
% RegDiff() );
2267 nLineHeight
+= RegDiff() - nDiff
;
2270 m_pCurr
->SetRealHeight( nLineHeight
);
2273 void SwTextFormatter::FeedInf( SwTextFormatInfo
&rInf
) const
2275 // delete Fly in any case!
2279 rInf
.ChkNoHyph( CntEndHyph(), CntMidHyph() );
2280 rInf
.SetRoot( m_pCurr
);
2281 rInf
.SetLineStart( m_nStart
);
2282 rInf
.SetIdx( m_nStart
);
2283 rInf
.Left( Left() );
2284 rInf
.Right( Right() );
2285 rInf
.First( FirstLeft() );
2286 rInf
.LeftMargin(GetLeftMargin());
2288 rInf
.RealWidth( sal_uInt16(rInf
.Right() - GetLeftMargin()) );
2289 rInf
.Width( rInf
.RealWidth() );
2290 if( const_cast<SwTextFormatter
*>(this)->GetRedln() )
2292 const_cast<SwTextFormatter
*>(this)->GetRedln()->Clear( const_cast<SwTextFormatter
*>(this)->GetFnt() );
2293 const_cast<SwTextFormatter
*>(this)->GetRedln()->Reset();
2297 void SwTextFormatter::FormatReset( SwTextFormatInfo
&rInf
)
2299 m_pFirstOfBorderMerge
= nullptr;
2300 m_pCurr
->Truncate();
2303 // delete pSpaceAdd and pKanaComp
2304 m_pCurr
->FinishSpaceAdd();
2305 m_pCurr
->FinishKanaComp();
2306 m_pCurr
->ResetFlags();
2310 bool SwTextFormatter::CalcOnceMore()
2314 const sal_uInt16 nOldDrop
= GetDropHeight();
2315 CalcDropHeight( m_pDropFormat
->GetLines() );
2316 m_bOnceMore
= nOldDrop
!= GetDropHeight();
2319 m_bOnceMore
= false;
2323 SwTwips
SwTextFormatter::CalcBottomLine() const
2325 SwTwips nRet
= Y() + GetLineHeight();
2326 SwTwips nMin
= GetInfo().GetTextFly().GetMinBottom();
2327 if( nMin
&& ++nMin
> nRet
)
2329 SwTwips nDist
= m_pFrame
->getFrameArea().Height() - m_pFrame
->getFramePrintArea().Height()
2330 - m_pFrame
->getFramePrintArea().Top();
2331 if( nRet
+ nDist
< nMin
)
2333 const bool bRepaint
= HasTruncLines() &&
2334 GetInfo().GetParaPortion()->GetRepaint().Bottom() == nRet
-1;
2335 nRet
= nMin
- nDist
;
2338 const_cast<SwRepaint
&>(GetInfo().GetParaPortion()
2339 ->GetRepaint()).Bottom( nRet
-1 );
2340 const_cast<SwTextFormatInfo
&>(GetInfo()).SetPaintOfst( 0 );
2347 // FME/OD: This routine does a limited text formatting.
2348 SwTwips
SwTextFormatter::CalcFitToContent_()
2350 FormatReset( GetInfo() );
2351 BuildPortions( GetInfo() );
2352 m_pCurr
->CalcLine( *this, GetInfo() );
2353 return m_pCurr
->Width();
2356 // determines if the calculation of a repaint offset is allowed
2357 // otherwise each line is painted from 0 (this is a copy of the beginning
2358 // of the former SwTextFormatter::Recycle() function
2359 bool SwTextFormatter::AllowRepaintOpt() const
2361 // reformat position in front of current line? Only in this case
2362 // we want to set the repaint offset
2363 bool bOptimizeRepaint
= m_nStart
< GetInfo().GetReformatStart() &&
2366 // a special case is the last line of a block adjusted paragraph:
2367 if ( bOptimizeRepaint
)
2369 switch( GetAdjust() )
2371 case SvxAdjust::Block
:
2373 if( IsLastBlock() || IsLastCenter() )
2374 bOptimizeRepaint
= false;
2377 // ????: blank in the last master line (blocksat.sdw)
2378 bOptimizeRepaint
= nullptr == m_pCurr
->GetNext() && !m_pFrame
->GetFollow();
2379 if ( bOptimizeRepaint
)
2381 SwLinePortion
*pPos
= m_pCurr
->GetFirstPortion();
2382 while ( pPos
&& !pPos
->IsFlyPortion() )
2383 pPos
= pPos
->GetNextPortion();
2384 bOptimizeRepaint
= !pPos
;
2389 case SvxAdjust::Center
:
2390 case SvxAdjust::Right
:
2391 bOptimizeRepaint
= false;
2397 // Again another special case: invisible SoftHyphs
2398 const TextFrameIndex nReformat
= GetInfo().GetReformatStart();
2399 if (bOptimizeRepaint
&& TextFrameIndex(COMPLETE_STRING
) != nReformat
)
2401 const sal_Unicode cCh
= nReformat
>= TextFrameIndex(GetInfo().GetText().getLength())
2403 : GetInfo().GetText()[ sal_Int32(nReformat
) ];
2404 bOptimizeRepaint
= ( CH_TXTATR_BREAKWORD
!= cCh
&& CH_TXTATR_INWORD
!= cCh
)
2405 || ! GetInfo().HasHint( nReformat
);
2408 return bOptimizeRepaint
;
2411 void SwTextFormatter::CalcUnclipped( SwTwips
& rTop
, SwTwips
& rBottom
)
2413 OSL_ENSURE( ! m_pFrame
->IsVertical() || m_pFrame
->IsSwapped(),
2414 "SwTextFormatter::CalcUnclipped with unswapped frame" );
2416 SwTwips nFlyAsc
, nFlyDesc
;
2417 m_pCurr
->MaxAscentDescent( rTop
, rBottom
, nFlyAsc
, nFlyDesc
);
2418 rTop
= Y() + GetCurr()->GetAscent();
2419 rBottom
= rTop
+ nFlyDesc
;
2423 void SwTextFormatter::UpdatePos( SwLineLayout
*pCurrent
, Point aStart
,
2424 TextFrameIndex
const nStartIdx
, bool bAlways
) const
2426 OSL_ENSURE( ! m_pFrame
->IsVertical() || m_pFrame
->IsSwapped(),
2427 "SwTextFormatter::UpdatePos with unswapped frame" );
2429 if( GetInfo().IsTest() )
2431 SwLinePortion
*pFirst
= pCurrent
->GetFirstPortion();
2432 SwLinePortion
*pPos
= pFirst
;
2433 SwTextPaintInfo
aTmpInf( GetInfo() );
2434 aTmpInf
.SetpSpaceAdd( pCurrent
->GetpLLSpaceAdd() );
2435 aTmpInf
.ResetSpaceIdx();
2436 aTmpInf
.SetKanaComp( pCurrent
->GetpKanaComp() );
2437 aTmpInf
.ResetKanaIdx();
2440 aTmpInf
.SetIdx( nStartIdx
);
2441 aTmpInf
.SetPos( aStart
);
2443 SwTwips nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
;
2444 pCurrent
->MaxAscentDescent( nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
);
2446 const SwTwips nTmpHeight
= pCurrent
->GetRealHeight();
2447 SwTwips nAscent
= pCurrent
->GetAscent() + nTmpHeight
- pCurrent
->Height();
2448 AsCharFlags nFlags
= AsCharFlags::UlSpace
;
2451 aTmpInf
.SetDirection( GetMulti()->GetDirection() );
2452 if( GetMulti()->HasRotation() )
2454 nFlags
|= AsCharFlags::Rotate
;
2455 if( GetMulti()->IsRevers() )
2457 nFlags
|= AsCharFlags::Reverse
;
2458 aTmpInf
.X( aTmpInf
.X() - nAscent
);
2461 aTmpInf
.X( aTmpInf
.X() + nAscent
);
2465 if ( GetMulti()->IsBidi() )
2466 nFlags
|= AsCharFlags::Bidi
;
2467 aTmpInf
.Y( aTmpInf
.Y() + nAscent
);
2471 aTmpInf
.Y( aTmpInf
.Y() + nAscent
);
2475 // We only know one case where changing the position (caused by the
2476 // adjustment) could be relevant for a portion: We need to SetRefPoint
2477 // for FlyCntPortions.
2478 if( ( pPos
->IsFlyCntPortion() || pPos
->IsGrfNumPortion() )
2479 && ( bAlways
|| !IsQuick() ) )
2481 pCurrent
->MaxAscentDescent( nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
, pPos
);
2483 if( pPos
->IsGrfNumPortion() )
2485 if( !nFlyAsc
&& !nFlyDesc
)
2487 nTmpAscent
= nAscent
;
2489 nTmpDescent
= nTmpHeight
- nAscent
;
2490 nFlyDesc
= nTmpDescent
;
2492 static_cast<SwGrfNumPortion
*>(pPos
)->SetBase( nTmpAscent
, nTmpDescent
,
2493 nFlyAsc
, nFlyDesc
);
2497 Point
aBase( aTmpInf
.GetPos() );
2498 if ( GetInfo().GetTextFrame()->IsVertical() )
2499 GetInfo().GetTextFrame()->SwitchHorizontalToVertical( aBase
);
2501 static_cast<SwFlyCntPortion
*>(pPos
)->SetBase( *aTmpInf
.GetTextFrame(),
2502 aBase
, nTmpAscent
, nTmpDescent
, nFlyAsc
,
2506 if( pPos
->IsMultiPortion() && static_cast<SwMultiPortion
*>(pPos
)->HasFlyInContent() )
2508 OSL_ENSURE( !GetMulti(), "Too much multi" );
2509 const_cast<SwTextFormatter
*>(this)->m_pMulti
= static_cast<SwMultiPortion
*>(pPos
);
2510 SwLineLayout
*pLay
= &GetMulti()->GetRoot();
2511 Point
aSt( aTmpInf
.X(), aStart
.Y() );
2513 if ( GetMulti()->HasBrackets() )
2515 OSL_ENSURE( GetMulti()->IsDouble(), "Brackets only for doubles");
2516 aSt
.AdjustX(static_cast<SwDoubleLinePortion
*>(GetMulti())->PreWidth() );
2518 else if( GetMulti()->HasRotation() )
2520 aSt
.AdjustY(pCurrent
->GetAscent() - GetMulti()->GetAscent() );
2521 if( GetMulti()->IsRevers() )
2522 aSt
.AdjustX(GetMulti()->Width() );
2524 aSt
.AdjustY(GetMulti()->Height() );
2526 else if ( GetMulti()->IsBidi() )
2527 // jump to end of the bidi portion
2528 aSt
.AdjustX(pLay
->Width() );
2530 TextFrameIndex nStIdx
= aTmpInf
.GetIdx();
2533 UpdatePos( pLay
, aSt
, nStIdx
, bAlways
);
2534 nStIdx
= nStIdx
+ pLay
->GetLen();
2535 aSt
.AdjustY(pLay
->Height() );
2536 pLay
= pLay
->GetNext();
2538 const_cast<SwTextFormatter
*>(this)->m_pMulti
= nullptr;
2540 pPos
->Move( aTmpInf
);
2541 pPos
= pPos
->GetNextPortion();
2545 void SwTextFormatter::AlignFlyInCntBase( tools::Long nBaseLine
) const
2547 OSL_ENSURE( ! m_pFrame
->IsVertical() || m_pFrame
->IsSwapped(),
2548 "SwTextFormatter::AlignFlyInCntBase with unswapped frame" );
2550 if( GetInfo().IsTest() )
2552 SwLinePortion
*pFirst
= m_pCurr
->GetFirstPortion();
2553 SwLinePortion
*pPos
= pFirst
;
2554 AsCharFlags nFlags
= AsCharFlags::None
;
2555 if( GetMulti() && GetMulti()->HasRotation() )
2557 nFlags
|= AsCharFlags::Rotate
;
2558 if( GetMulti()->IsRevers() )
2559 nFlags
|= AsCharFlags::Reverse
;
2562 SwTwips nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
;
2566 if( pPos
->IsFlyCntPortion() || pPos
->IsGrfNumPortion() )
2568 m_pCurr
->MaxAscentDescent( nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
, pPos
);
2570 if( pPos
->IsGrfNumPortion() )
2571 static_cast<SwGrfNumPortion
*>(pPos
)->SetBase( nTmpAscent
, nTmpDescent
,
2572 nFlyAsc
, nFlyDesc
);
2576 if ( GetInfo().GetTextFrame()->IsVertical() )
2578 nBaseLine
= GetInfo().GetTextFrame()->SwitchHorizontalToVertical( nBaseLine
);
2579 aBase
= Point( nBaseLine
, static_cast<SwFlyCntPortion
*>(pPos
)->GetRefPoint().Y() );
2582 aBase
= Point( static_cast<SwFlyCntPortion
*>(pPos
)->GetRefPoint().X(), nBaseLine
);
2584 static_cast<SwFlyCntPortion
*>(pPos
)->SetBase( *GetInfo().GetTextFrame(), aBase
, nTmpAscent
, nTmpDescent
,
2585 nFlyAsc
, nFlyDesc
, nFlags
);
2588 pPos
= pPos
->GetNextPortion();
2592 bool SwTextFormatter::ChkFlyUnderflow( SwTextFormatInfo
&rInf
) const
2594 OSL_ENSURE( rInf
.GetTextFly().IsOn(), "SwTextFormatter::ChkFlyUnderflow: why?" );
2597 // First we check, whether a fly overlaps with the line.
2598 // = GetLineHeight()
2599 const sal_uInt16 nHeight
= GetCurr()->GetRealHeight();
2600 SwRect
aLine( GetLeftMargin(), Y(), rInf
.RealWidth(), nHeight
);
2602 SwRect
aLineVert( aLine
);
2603 if ( m_pFrame
->IsVertical() )
2604 m_pFrame
->SwitchHorizontalToVertical( aLineVert
);
2605 SwRect
aInter( rInf
.GetTextFly().GetFrame( aLineVert
) );
2606 if ( m_pFrame
->IsVertical() )
2607 m_pFrame
->SwitchVerticalToHorizontal( aInter
);
2609 if( !aInter
.HasArea() )
2612 // We now check every portion that could have lowered for overlapping
2614 const SwLinePortion
*pPos
= GetCurr()->GetFirstPortion();
2615 aLine
.Pos().setY( Y() + GetCurr()->GetRealHeight() - GetCurr()->Height() );
2616 aLine
.Height( GetCurr()->Height() );
2620 aLine
.Width( pPos
->Width() );
2623 if ( m_pFrame
->IsVertical() )
2624 m_pFrame
->SwitchHorizontalToVertical( aLineVert
);
2625 aInter
= rInf
.GetTextFly().GetFrame( aLineVert
);
2626 if ( m_pFrame
->IsVertical() )
2627 m_pFrame
->SwitchVerticalToHorizontal( aInter
);
2629 // New flys from below?
2630 if( !pPos
->IsFlyPortion() )
2632 if( aInter
.Overlaps( aLine
) )
2634 aInter
.Intersection_( aLine
);
2635 if( aInter
.HasArea() )
2637 // To be evaluated during reformat of this line:
2638 // RealHeight including spacing
2639 rInf
.SetLineHeight( nHeight
);
2640 // Height without extra spacing
2641 rInf
.SetLineNetHeight( m_pCurr
->Height() );
2648 // The fly portion is not intersected by a fly anymore
2649 if ( ! aInter
.Overlaps( aLine
) )
2651 rInf
.SetLineHeight( nHeight
);
2652 rInf
.SetLineNetHeight( m_pCurr
->Height() );
2657 aInter
.Intersection_( aLine
);
2659 // No area means a fly has become invalid because of
2660 // lowering the line => reformat the line
2661 // we also have to reformat the line, if the fly size
2662 // differs from the intersection interval's size.
2663 if( ! aInter
.HasArea() ||
2664 static_cast<const SwFlyPortion
*>(pPos
)->GetFixWidth() != aInter
.Width() )
2666 rInf
.SetLineHeight( nHeight
);
2667 rInf
.SetLineNetHeight( m_pCurr
->Height() );
2673 aLine
.Left( aLine
.Left() + pPos
->Width() );
2674 pPos
= pPos
->GetNextPortion();
2680 void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo
&rInf
)
2682 if( GetMulti() || rInf
.GetFly() )
2685 SwTextFly
& rTextFly
= rInf
.GetTextFly();
2686 if( !rTextFly
.IsOn() || rInf
.IsIgnoreFly() )
2689 const SwLinePortion
*pLast
= rInf
.GetLast();
2691 tools::Long nAscent
;
2692 tools::Long nTop
= Y();
2693 tools::Long nHeight
;
2695 if( rInf
.GetLineHeight() )
2697 // Real line height has already been calculated, we only have to
2698 // search for intersections in the lower part of the strip
2699 nAscent
= m_pCurr
->GetAscent();
2700 nHeight
= rInf
.GetLineNetHeight();
2701 nTop
+= rInf
.GetLineHeight() - nHeight
;
2705 // We make a first guess for the lines real height
2706 if ( ! m_pCurr
->GetRealHeight() )
2709 nAscent
= pLast
->GetAscent();
2710 nHeight
= pLast
->Height();
2712 if ( m_pCurr
->GetRealHeight() > nHeight
)
2713 nTop
+= m_pCurr
->GetRealHeight() - nHeight
;
2715 // Important for fixed space between lines
2716 nHeight
= m_pCurr
->GetRealHeight();
2719 const tools::Long nLeftMar
= GetLeftMargin();
2720 const tools::Long nLeftMin
= (rInf
.X() || GetDropLeft()) ? nLeftMar
: GetLeftMin();
2722 SwRect
aLine( rInf
.X() + nLeftMin
, nTop
, rInf
.RealWidth() - rInf
.X()
2723 + nLeftMar
- nLeftMin
, nHeight
);
2725 bool bWordFlyWrap
= GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::ADD_VERTICAL_FLY_OFFSETS
);
2726 // tdf#116486: consider also the upper margin from getFramePrintArea because intersections
2727 // with this additional space should lead to repositioning of paragraphs
2728 // For compatibility we grab a related compat flag:
2729 if (bWordFlyWrap
&& IsFirstTextLine())
2731 tools::Long nUpper
= m_pFrame
->getFramePrintArea().Top();
2732 // Make sure that increase only happens in case the upper spacing comes from the upper
2733 // margin of the current text frame, not because of a lower spacing of the previous text
2735 nUpper
-= m_pFrame
->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
2736 // Increase the rectangle
2737 if( nUpper
> 0 && nTop
>= nUpper
)
2738 aLine
.SubTop( nUpper
);
2741 if (IsFirstTextLine())
2743 // Check if a compatibility mode requires considering also the lower margin of this text
2744 // frame, intersections with this additional space should lead to shifting the paragraph
2746 SwTwips nLower
= m_pFrame
->GetLowerMarginForFlyIntersect();
2749 aLine
.AddBottom(nLower
);
2753 SwRect
aLineVert( aLine
);
2754 if ( m_pFrame
->IsRightToLeft() )
2755 m_pFrame
->SwitchLTRtoRTL( aLineVert
);
2757 if ( m_pFrame
->IsVertical() )
2758 m_pFrame
->SwitchHorizontalToVertical( aLineVert
);
2760 // GetFrame(...) determines and returns the intersection rectangle
2761 SwRect
aInter( rTextFly
.GetFrame( aLineVert
) );
2763 if ( m_pFrame
->IsRightToLeft() )
2764 m_pFrame
->SwitchRTLtoLTR( aInter
);
2766 if ( m_pFrame
->IsVertical() )
2767 m_pFrame
->SwitchVerticalToHorizontal( aInter
);
2769 if (!aInter
.IsEmpty() && aInter
.Bottom() < nTop
)
2771 // Intersects with the frame area (with upper margin), but not with the print area (without
2772 // upper margin). Don't reserve space for the fly portion in this case, text is allowed to
2777 if( !aInter
.Overlaps( aLine
) )
2780 aLine
.Left( rInf
.X() + nLeftMar
);
2781 bool bForced
= false;
2782 bool bSplitFly
= false;
2783 for (const auto& pObj
: *rTextFly
.GetAnchoredObjList())
2785 auto pFlyFrame
= pObj
->DynCastFlyFrame();
2791 if (!pFlyFrame
->IsFlySplitAllowed())
2799 if( aInter
.Left() <= nLeftMin
)
2801 SwTwips nFrameLeft
= GetTextFrame()->getFrameArea().Left();
2802 SwTwips nFramePrintAreaLeft
= GetTextFrame()->getFramePrintArea().Left();
2803 if( nFramePrintAreaLeft
< 0 )
2804 nFrameLeft
+= GetTextFrame()->getFramePrintArea().Left();
2805 if( aInter
.Left() < nFrameLeft
)
2807 aInter
.Left(nFrameLeft
); // both sets left and reduces width
2808 if (bSplitFly
&& nFramePrintAreaLeft
> 0 && nFramePrintAreaLeft
< aInter
.Width())
2810 // We wrap around a split fly, the fly portion is on the
2811 // left of the paragraph and we have a positive
2812 // paragraph margin. Don't take space twice in this case
2813 // (margin, fly portion), decrease the width of the fly
2814 // portion accordingly.
2815 aInter
.Right(aInter
.Right() - nFramePrintAreaLeft
);
2819 tools::Long nAddMar
= 0;
2820 if (GetTextFrame()->IsRightToLeft())
2822 nAddMar
= GetTextFrame()->getFrameArea().Right() - Right();
2827 nAddMar
= nLeftMar
- nFrameLeft
;
2829 aInter
.Width( aInter
.Width() + nAddMar
);
2830 // For a negative first line indent, we set this flag to show
2831 // that the indentation/margin has been moved.
2832 // This needs to be respected by the DefaultTab at the zero position.
2833 if( IsFirstTextLine() && HasNegFirst() )
2836 aInter
.Intersection( aLine
);
2837 if( !aInter
.HasArea() )
2840 bool bFullLine
= aLine
.Left() == aInter
.Left() &&
2841 aLine
.Right() == aInter
.Right();
2842 if (!bFullLine
&& bWordFlyWrap
&& !GetTextFrame()->IsInTab())
2844 // Word style: if there is minimal space remaining, then handle that similar to a full line
2845 // and put the actual empty paragraph below the fly.
2846 SwTwips nLimit
= MINLAY
;
2849 // We wrap around a floating table, that has a larger minimal wrap distance.
2850 nLimit
= TEXT_MIN_SMALL
;
2853 bFullLine
= std::abs(aLine
.Left() - aInter
.Left()) < nLimit
2854 && std::abs(aLine
.Right() - aInter
.Right()) < nLimit
;
2857 // Although no text is left, we need to format another line,
2858 // because also empty lines need to avoid a Fly with no wrapping.
2859 if (bFullLine
&& rInf
.GetIdx() == TextFrameIndex(rInf
.GetText().getLength()))
2861 rInf
.SetNewLine( true );
2862 // We know that for dummies, it holds ascent == height
2863 m_pCurr
->SetDummy(true);
2866 // aInter becomes frame-local
2867 aInter
.Pos().AdjustX( -nLeftMar
);
2868 SwFlyPortion
*pFly
= new SwFlyPortion( aInter
);
2871 m_pCurr
->SetForcedLeftMargin();
2872 rInf
.ForcedLeftMargin( o3tl::narrowing
<sal_uInt16
>(aInter
.Width()) );
2877 // In order to properly flow around Flys with different
2878 // wrapping attributes, we need to increase by units of line height.
2879 // The last avoiding line should be adjusted in height, so that
2880 // we don't get a frame spacing effect.
2881 // It is important that ascent == height, because the FlyPortion
2882 // values are transferred to pCurr in CalcLine and IsDummy() relies
2883 // on this behaviour.
2884 // To my knowledge we only have two places where DummyLines can be
2885 // created: here and in MakeFlyDummies.
2886 // IsDummy() is evaluated in IsFirstTextLine(), when moving lines
2887 // and in relation with DropCaps.
2888 pFly
->Height( aInter
.Height() );
2890 // nNextTop now contains the margin's bottom edge, which we avoid
2891 // or the next margin's top edge, which we need to respect.
2892 // That means we can comfortably grow up to this value; that's how
2893 // we save a few empty lines.
2894 tools::Long nNextTop
= rTextFly
.GetNextTop();
2895 if ( m_pFrame
->IsVertical() )
2896 nNextTop
= m_pFrame
->SwitchVerticalToHorizontal( nNextTop
);
2897 if( nNextTop
> aInter
.Bottom() )
2899 SwTwips nH
= nNextTop
- aInter
.Top();
2900 if( nH
< SAL_MAX_UINT16
)
2903 if( nAscent
< pFly
->Height() )
2904 pFly
->SetAscent( nAscent
);
2906 pFly
->SetAscent( pFly
->Height() );
2910 if (rInf
.GetIdx() == TextFrameIndex(rInf
.GetText().getLength()))
2912 // Don't use nHeight, or we have a huge descent
2913 pFly
->Height( pLast
->Height() );
2914 pFly
->SetAscent( pLast
->GetAscent() );
2918 pFly
->Height( aInter
.Height() );
2919 if( nAscent
< pFly
->Height() )
2920 pFly
->SetAscent( nAscent
);
2922 pFly
->SetAscent( pFly
->Height() );
2926 rInf
.SetFly( pFly
);
2928 if( pFly
->GetFix() < rInf
.Width() )
2929 rInf
.Width( pFly
->GetFix() );
2931 SwTextGridItem
const*const pGrid(GetGridItem(m_pFrame
->FindPageFrame()));
2935 const SwPageFrame
* pPageFrame
= m_pFrame
->FindPageFrame();
2936 const SwLayoutFrame
* pBody
= pPageFrame
->FindBodyCont();
2938 SwRectFnSet
aRectFnSet(pPageFrame
);
2940 const tools::Long nGridOrigin
= pBody
?
2941 aRectFnSet
.GetPrtLeft(*pBody
) :
2942 aRectFnSet
.GetPrtLeft(*pPageFrame
);
2944 const SwDoc
& rDoc
= rInf
.GetTextFrame()->GetDoc();
2945 const sal_uInt16 nGridWidth
= GetGridWidth(*pGrid
, rDoc
);
2947 SwTwips nStartX
= GetLeftMargin();
2948 if ( aRectFnSet
.IsVert() )
2950 Point
aPoint( nStartX
, 0 );
2951 m_pFrame
->SwitchHorizontalToVertical( aPoint
);
2952 nStartX
= aPoint
.Y();
2955 const SwTwips nOfst
= nStartX
- nGridOrigin
;
2956 const SwTwips nTmpWidth
= rInf
.Width() + nOfst
;
2958 const SwTwips i
= nTmpWidth
/ nGridWidth
+ 1;
2960 const SwTwips nNewWidth
= ( i
- 1 ) * nGridWidth
- nOfst
;
2961 if ( nNewWidth
> 0 )
2962 rInf
.Width( nNewWidth
);
2969 SwFlyCntPortion
*SwTextFormatter::NewFlyCntPortion( SwTextFormatInfo
&rInf
,
2970 SwTextAttr
*pHint
) const
2972 const SwFrame
*pFrame
= m_pFrame
;
2974 SwFlyInContentFrame
*pFly
;
2975 SwFrameFormat
* pFrameFormat
= static_cast<SwTextFlyCnt
*>(pHint
)->GetFlyCnt().GetFrameFormat();
2976 if( RES_FLYFRMFMT
== pFrameFormat
->Which() )
2978 // set Lock pFrame to avoid m_pCurr getting deleted
2979 TextFrameLockGuard
aGuard(m_pFrame
);
2980 pFly
= static_cast<SwTextFlyCnt
*>(pHint
)->GetFlyFrame(pFrame
);
2984 // aBase is the document-global position, from which the new extra portion is placed
2985 // aBase.X() = Offset in the line after the current position
2986 // aBase.Y() = LineIter.Y() + Ascent of the current position
2988 SwTwips nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
;
2989 // i#11859 - use new method <SwLineLayout::MaxAscentDescent(..)>
2990 // to change line spacing behaviour at paragraph - Compatibility to MS Word
2991 //SwLinePortion *pPos = pCurr->GetFirstPortion();
2992 //lcl_MaxAscDescent( pPos, nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc );
2993 m_pCurr
->MaxAscentDescent( nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
);
2995 // If the ascent of the frame is larger than the ascent of the current position,
2996 // we use this one when calculating the base, or the frame would be positioned
2997 // too much to the top, sliding down after all causing a repaint in an area
2998 // he actually never was in.
2999 SwTwips nAscent
= 0;
3001 const bool bTextFrameVertical
= GetInfo().GetTextFrame()->IsVertical();
3003 const bool bUseFlyAscent
= pFly
&& pFly
->isFrameAreaPositionValid() &&
3004 0 != ( bTextFrameVertical
?
3005 pFly
->GetRefPoint().X() :
3006 pFly
->GetRefPoint().Y() );
3008 if ( bUseFlyAscent
)
3009 nAscent
= std::abs( int( bTextFrameVertical
?
3010 pFly
->GetRelPos().X() :
3011 pFly
->GetRelPos().Y() ) );
3013 // Check if be prefer to use the ascent of the last portion:
3016 nAscent
< rInf
.GetLast()->GetAscent() )
3018 nAscent
= rInf
.GetLast()->GetAscent();
3020 else if( nAscent
> nFlyAsc
)
3023 Point
aBase( GetLeftMargin() + rInf
.X(), Y() + nAscent
);
3024 AsCharFlags nMode
= IsQuick() ? AsCharFlags::Quick
: AsCharFlags::None
;
3025 if( GetMulti() && GetMulti()->HasRotation() )
3027 nMode
|= AsCharFlags::Rotate
;
3028 if( GetMulti()->IsRevers() )
3029 nMode
|= AsCharFlags::Reverse
;
3032 Point
aTmpBase( aBase
);
3033 if ( GetInfo().GetTextFrame()->IsVertical() )
3034 GetInfo().GetTextFrame()->SwitchHorizontalToVertical( aTmpBase
);
3036 SwFlyCntPortion
* pRet(nullptr);
3039 pRet
= sw::FlyContentPortion::Create(*GetInfo().GetTextFrame(), pFly
, aTmpBase
, nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
, nMode
);
3040 // We need to make sure that our font is set again in the OutputDevice
3041 // It could be that the FlyInCnt was added anew and GetFlyFrame() would
3042 // in turn cause, that it'd be created anew again.
3043 // This one's frames get formatted right away, which change the font.
3045 if( pRet
->GetAscent() > nAscent
)
3047 aBase
.setY( Y() + pRet
->GetAscent() );
3048 nMode
|= AsCharFlags::UlSpace
;
3049 if( !rInf
.IsTest() )
3052 if ( GetInfo().GetTextFrame()->IsVertical() )
3053 GetInfo().GetTextFrame()->SwitchHorizontalToVertical( aTmpBase
);
3055 pRet
->SetBase( *rInf
.GetTextFrame(), aTmpBase
, nTmpAscent
,
3056 nTmpDescent
, nFlyAsc
, nFlyDesc
, nMode
);
3062 pRet
= sw::DrawFlyCntPortion::Create(*rInf
.GetTextFrame(), *pFrameFormat
, aTmpBase
, nTmpAscent
, nTmpDescent
, nFlyAsc
, nFlyDesc
, nMode
);
3067 /* Drop portion is a special case, because it has parts which aren't portions
3068 but we have handle them just like portions */
3069 void SwTextFormatter::MergeCharacterBorder( SwDropPortion
const & rPortion
)
3071 if( rPortion
.GetLines() <= 1 )
3074 SwDropPortionPart
* pCurrPart
= rPortion
.GetPart();
3077 if( pCurrPart
->GetFollow() &&
3078 ::lcl_HasSameBorder(pCurrPart
->GetFont(), pCurrPart
->GetFollow()->GetFont()) )
3080 pCurrPart
->SetJoinBorderWithNext(true);
3081 pCurrPart
->GetFollow()->SetJoinBorderWithPrev(true);
3083 pCurrPart
= pCurrPart
->GetFollow();
3087 void SwTextFormatter::MergeCharacterBorder( SwLinePortion
& rPortion
, SwLinePortion
const *pPrev
, SwTextFormatInfo
& rInf
)
3089 const SwFont aCurFont
= *rInf
.GetFont();
3090 if( !aCurFont
.HasBorder() )
3093 if (pPrev
&& pPrev
->GetJoinBorderWithNext() )
3095 // In some case border merge is called twice to the portion
3096 if( !rPortion
.GetJoinBorderWithPrev() )
3098 rPortion
.SetJoinBorderWithPrev(true);
3099 if( rPortion
.InTextGrp() && rPortion
.Width() > aCurFont
.GetLeftBorderSpace() )
3100 rPortion
.Width(rPortion
.Width() - aCurFont
.GetLeftBorderSpace());
3105 rPortion
.SetJoinBorderWithPrev(false);
3106 m_pFirstOfBorderMerge
= &rPortion
;
3109 // Get next portion's font
3111 if (!rInf
.IsFull() && // Not the last portion of the line (in case of line break)
3112 rInf
.GetIdx() + rPortion
.GetLen() != TextFrameIndex(rInf
.GetText().getLength())) // Not the last portion of the paragraph
3114 bSeek
= Seek(rInf
.GetIdx() + rPortion
.GetLen());
3116 // Don't join the next portion if SwKernPortion sits between two different boxes.
3117 bool bDisconnect
= rPortion
.IsKernPortion() && !rPortion
.GetJoinBorderWithPrev();
3118 // If next portion has the same border then merge
3119 if( bSeek
&& GetFnt()->HasBorder() && ::lcl_HasSameBorder(aCurFont
, *GetFnt()) && !bDisconnect
)
3121 // In some case border merge is called twice to the portion
3122 if( !rPortion
.GetJoinBorderWithNext() )
3124 rPortion
.SetJoinBorderWithNext(true);
3125 if( rPortion
.InTextGrp() && rPortion
.Width() > aCurFont
.GetRightBorderSpace() )
3126 rPortion
.Width(rPortion
.Width() - aCurFont
.GetRightBorderSpace());
3129 // If this is the last portion of the merge group then make the real height merge
3132 rPortion
.SetJoinBorderWithNext(false);
3133 if( m_pFirstOfBorderMerge
!= &rPortion
)
3135 // Calculate maximum height and ascent
3136 SwLinePortion
* pActPor
= m_pFirstOfBorderMerge
;
3137 sal_uInt16 nMaxAscent
= 0;
3138 sal_uInt16 nMaxHeight
= 0;
3139 bool bReachCurrent
= false;
3142 if( nMaxHeight
< pActPor
->Height() )
3143 nMaxHeight
= pActPor
->Height();
3144 if( nMaxAscent
< pActPor
->GetAscent() )
3145 nMaxAscent
= pActPor
->GetAscent();
3147 pActPor
= pActPor
->GetNextPortion();
3148 if( !pActPor
&& !bReachCurrent
)
3150 pActPor
= &rPortion
;
3151 bReachCurrent
= true;
3155 // Change all portion's height and ascent
3156 pActPor
= m_pFirstOfBorderMerge
;
3157 bReachCurrent
= false;
3160 if( nMaxHeight
> pActPor
->Height() )
3161 pActPor
->Height(nMaxHeight
);
3162 if( nMaxAscent
> pActPor
->GetAscent() )
3163 pActPor
->SetAscent(nMaxAscent
);
3165 pActPor
= pActPor
->GetNextPortion();
3166 if( !pActPor
&& !bReachCurrent
)
3168 pActPor
= &rPortion
;
3169 bReachCurrent
= true;
3172 m_pFirstOfBorderMerge
= nullptr;
3175 Seek(rInf
.GetIdx());
3179 // calculates and sets optimal repaint offset for the current line
3180 tools::Long
lcl_CalcOptRepaint( SwTextFormatter
&rThis
,
3181 SwLineLayout
const &rCurr
,
3182 TextFrameIndex
const nOldLineEnd
,
3183 const std::vector
<tools::Long
> &rFlyStarts
)
3185 SwTextFormatInfo
& txtFormatInfo
= rThis
.GetInfo();
3186 if ( txtFormatInfo
.GetIdx() < txtFormatInfo
.GetReformatStart() )
3187 // the reformat position is behind our new line, that means
3188 // something of our text has moved to the next line
3191 TextFrameIndex nReformat
= std::min(txtFormatInfo
.GetReformatStart(), nOldLineEnd
);
3193 // in case we do not have any fly in our line, our repaint position
3194 // is the changed position - 1
3195 if ( rFlyStarts
.empty() && ! rCurr
.IsFly() )
3197 // this is the maximum repaint offset determined during formatting
3198 // for example: the beginning of the first right tab stop
3199 // if this value is 0, this means that we do not have an upper
3200 // limit for the repaint offset
3201 const tools::Long nFormatRepaint
= txtFormatInfo
.GetPaintOfst();
3203 if (nReformat
< txtFormatInfo
.GetLineStart() + TextFrameIndex(3))
3206 // step back two positions for smoother repaint
3207 nReformat
-= TextFrameIndex(2);
3209 // i#28795, i#34607, i#38388
3210 // step back more characters, this is required by complex scripts
3211 // e.g., for Khmer (thank you, Javier!)
3212 static const TextFrameIndex
nMaxContext(10);
3213 if (nReformat
> txtFormatInfo
.GetLineStart() + nMaxContext
)
3214 nReformat
= nReformat
- nMaxContext
;
3217 nReformat
= txtFormatInfo
.GetLineStart();
3218 //reset the margin flag - prevent loops
3219 SwTextCursor::SetRightMargin(false);
3222 // Weird situation: Our line used to end with a hole portion
3223 // and we delete some characters at the end of our line. We have
3224 // to take care for repainting the blanks which are not anymore
3225 // covered by the hole portion
3226 while ( nReformat
> txtFormatInfo
.GetLineStart() &&
3227 CH_BLANK
== txtFormatInfo
.GetChar( nReformat
) )
3230 OSL_ENSURE( nReformat
< txtFormatInfo
.GetIdx(), "Reformat too small for me!" );
3233 // Note: GetChareRect is not const. It definitely changes the
3234 // bMulti flag. We have to save and restore the old value.
3235 bool bOldMulti
= txtFormatInfo
.IsMulti();
3236 rThis
.GetCharRect( &aRect
, nReformat
);
3237 txtFormatInfo
.SetMulti( bOldMulti
);
3239 return nFormatRepaint
? std::min( aRect
.Left(), nFormatRepaint
) :
3244 // nReformat may be wrong, if something around flys has changed:
3245 // we compare the former and the new fly positions in this line
3246 // if anything has changed, we carefully have to adjust the right
3248 tools::Long nPOfst
= 0;
3251 TextFrameIndex nIdx
= rThis
.GetInfo().GetLineStart();
3252 SwLinePortion
* pPor
= rCurr
.GetFirstPortion();
3256 if ( pPor
->IsFlyPortion() )
3258 // compare start of fly with former start of fly
3259 if (nCnt
< rFlyStarts
.size() &&
3260 nX
== rFlyStarts
[ nCnt
] &&
3263 // found fix position, nothing has changed left from nX
3264 nPOfst
= nX
+ pPor
->Width();
3270 nX
= nX
+ pPor
->Width();
3271 nIdx
= nIdx
+ pPor
->GetLen();
3272 pPor
= pPor
->GetNextPortion();
3275 return nPOfst
+ rThis
.GetLeftMargin();
3279 // Determine if we need to build hidden portions
3280 bool lcl_BuildHiddenPortion(const SwTextSizeInfo
& rInf
, TextFrameIndex
& rPos
)
3282 // Only if hidden text should not be shown:
3283 // if ( rInf.GetVsh() && rInf.GetVsh()->GetWin() && rInf.GetOpt().IsShowHiddenChar() )
3284 const bool bShowInDocView
= rInf
.GetVsh() && rInf
.GetVsh()->GetWin() && rInf
.GetOpt().IsShowHiddenChar();
3285 const bool bShowForPrinting
= rInf
.GetOpt().IsShowHiddenChar( true ) && rInf
.GetOpt().IsPrinting();
3286 if (bShowInDocView
|| bShowForPrinting
)
3289 const SwScriptInfo
& rSI
= rInf
.GetParaPortion()->GetScriptInfo();
3290 TextFrameIndex nHiddenStart
;
3291 TextFrameIndex nHiddenEnd
;
3292 rSI
.GetBoundsOfHiddenRange( rPos
, nHiddenStart
, nHiddenEnd
);
3302 bool lcl_HasSameBorder(const SwFont
& rFirst
, const SwFont
& rSecond
)
3305 rFirst
.GetTopBorder() == rSecond
.GetTopBorder() &&
3306 rFirst
.GetBottomBorder() == rSecond
.GetBottomBorder() &&
3307 rFirst
.GetLeftBorder() == rSecond
.GetLeftBorder() &&
3308 rFirst
.GetRightBorder() == rSecond
.GetRightBorder() &&
3309 rFirst
.GetTopBorderDist() == rSecond
.GetTopBorderDist() &&
3310 rFirst
.GetBottomBorderDist() == rSecond
.GetBottomBorderDist() &&
3311 rFirst
.GetLeftBorderDist() == rSecond
.GetLeftBorderDist() &&
3312 rFirst
.GetRightBorderDist() == rSecond
.GetRightBorderDist() &&
3313 rFirst
.GetOrientation() == rSecond
.GetOrientation() &&
3314 rFirst
.GetShadowColor() == rSecond
.GetShadowColor() &&
3315 rFirst
.GetShadowWidth() == rSecond
.GetShadowWidth() &&
3316 rFirst
.GetShadowLocation() == rSecond
.GetShadowLocation();
3319 } //end unnamed namespace
3321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */