LibreOffice Module sw (master)  1
portxt.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/i18n/ScriptType.hpp>
21 #include <com/sun/star/i18n/XBreakIterator.hpp>
22 #include <i18nlangtag/mslangid.hxx>
23 #include <breakit.hxx>
24 #include <hintids.hxx>
26 #include <SwPortionHandler.hxx>
27 #include "porlay.hxx"
28 #include "inftxt.hxx"
29 #include "guess.hxx"
30 #include "porfld.hxx"
31 #include <pagefrm.hxx>
32 #include <tgrditem.hxx>
34 #include <IDocumentMarkAccess.hxx>
35 
36 #include <IMark.hxx>
37 #include <pam.hxx>
38 #include <doc.hxx>
39 #include <xmloff/odffields.hxx>
40 
41 using namespace ::sw::mark;
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::i18n::ScriptType;
44 
45 // Returns for how many characters an extra space has to be added
46 // (for justified alignment).
48  const OUString* pStr, const SwLinePortion& rPor)
49 {
50  TextFrameIndex nPos, nEnd;
51  const SwScriptInfo* pSI = nullptr;
52 
53  if ( pStr )
54  {
55  // passing a string means we are inside a field
56  nPos = TextFrameIndex(0);
57  nEnd = TextFrameIndex(pStr->getLength());
58  }
59  else
60  {
61  nPos = rInf.GetIdx();
62  nEnd = rInf.GetIdx() + rPor.GetLen();
63  pStr = &rInf.GetText();
64  pSI = &const_cast<SwParaPortion*>(rInf.GetParaPortion())->GetScriptInfo();
65  }
66 
67  TextFrameIndex nCnt(0);
68  sal_uInt8 nScript = 0;
69 
70  // If portion consists of Asian characters and language is not
71  // Korean, we add extra space to each character.
72  // first we get the script type
73  if ( pSI )
74  nScript = pSI->ScriptType( nPos );
75  else
76  nScript = static_cast<sal_uInt8>(
77  g_pBreakIt->GetBreakIter()->getScriptType(*pStr, sal_Int32(nPos)));
78 
79  // Note: rInf.GetIdx() can differ from nPos,
80  // e.g., when rPor is a field portion. nPos refers to the string passed
81  // to the function, rInf.GetIdx() refers to the original string.
82 
83  // We try to find out which justification mode is required. This is done by
84  // evaluating the script type and the language attribute set for this portion
85 
86  // Asian Justification: Each character get some extra space
87  if ( nEnd > nPos && ASIAN == nScript )
88  {
89  LanguageType aLang =
90  rInf.GetTextFrame()->GetLangOfChar(rInf.GetIdx(), nScript);
91 
92  if (!MsLangId::isKorean(aLang))
93  {
94  const SwLinePortion* pPor = rPor.GetNextPortion();
95  if ( pPor && ( pPor->IsKernPortion() ||
96  pPor->IsControlCharPortion() ||
97  pPor->IsPostItsPortion() ) )
98  pPor = pPor->GetNextPortion();
99 
100  nCnt += SwScriptInfo::CountCJKCharacters( *pStr, nPos, nEnd, aLang );
101 
102  if ( !pPor || pPor->IsHolePortion() || pPor->InFixMargGrp() ||
103  pPor->IsBreakPortion() )
104  --nCnt;
105 
106  return nCnt;
107  }
108  }
109 
110  // Kashida Justification: Insert Kashidas
111  if ( nEnd > nPos && pSI && COMPLEX == nScript )
112  {
113  if ( SwScriptInfo::IsArabicText( *pStr, nPos, nEnd - nPos ) && pSI->CountKashida() )
114  {
115  const sal_Int32 nKashRes = pSI->KashidaJustify( nullptr, nullptr, nPos, nEnd - nPos );
116  // i60591: need to check result of KashidaJustify
117  // determine if kashida justification is applicable
118  if (nKashRes != -1)
119  return TextFrameIndex(nKashRes);
120  }
121  }
122 
123  // Thai Justification: Each character cell gets some extra space
124  if ( nEnd > nPos && COMPLEX == nScript )
125  {
126  LanguageType aLang =
127  rInf.GetTextFrame()->GetLangOfChar(rInf.GetIdx(), nScript);
128 
129  if ( LANGUAGE_THAI == aLang )
130  {
131  nCnt = SwScriptInfo::ThaiJustify( *pStr, nullptr, nullptr, nPos, nEnd - nPos );
132 
133  const SwLinePortion* pPor = rPor.GetNextPortion();
134  if ( pPor && ( pPor->IsKernPortion() ||
135  pPor->IsControlCharPortion() ||
136  pPor->IsPostItsPortion() ) )
137  pPor = pPor->GetNextPortion();
138 
139  if ( nCnt && ( ! pPor || pPor->IsHolePortion() || pPor->InFixMargGrp() ) )
140  --nCnt;
141 
142  return nCnt;
143  }
144  }
145 
146  // Here starts the good old "Look for blanks and add space to them" part.
147  // Note: We do not want to add space to an isolated latin blank in front
148  // of some complex characters in RTL environment
149  const bool bDoNotAddSpace =
150  LATIN == nScript && (nEnd == nPos + TextFrameIndex(1)) && pSI &&
151  ( i18n::ScriptType::COMPLEX ==
152  pSI->ScriptType(nPos + TextFrameIndex(1))) &&
153  rInf.GetTextFrame() && rInf.GetTextFrame()->IsRightToLeft();
154 
155  if ( bDoNotAddSpace )
156  return nCnt;
157 
158  TextFrameIndex nTextEnd = std::min(nEnd, TextFrameIndex(pStr->getLength()));
159  for ( ; nPos < nTextEnd; ++nPos )
160  {
161  if (CH_BLANK == (*pStr)[ sal_Int32(nPos) ])
162  ++nCnt;
163  }
164 
165  // We still have to examine the next character:
166  // If the next character is ASIAN and not KOREAN we have
167  // to add an extra space
168  // nPos refers to the original string, even if a field string has
169  // been passed to this function
170  nPos = rInf.GetIdx() + rPor.GetLen();
171  if (nPos < TextFrameIndex(rInf.GetText().getLength()))
172  {
173  sal_uInt8 nNextScript = 0;
174  const SwLinePortion* pPor = rPor.GetNextPortion();
175  if ( pPor && pPor->IsKernPortion() )
176  pPor = pPor->GetNextPortion();
177 
178  if (!pPor || pPor->InFixMargGrp())
179  return nCnt;
180 
181  // next character is inside a field?
182  if ( CH_TXTATR_BREAKWORD == rInf.GetChar( nPos ) && pPor->InExpGrp() )
183  {
184  bool bOldOnWin = rInf.OnWin();
185  const_cast<SwTextSizeInfo &>(rInf).SetOnWin( false );
186 
187  OUString aStr;
188  pPor->GetExpText( rInf, aStr );
189  const_cast<SwTextSizeInfo &>(rInf).SetOnWin( bOldOnWin );
190 
191  nNextScript = static_cast<sal_uInt8>(g_pBreakIt->GetBreakIter()->getScriptType( aStr, 0 ));
192  }
193  else
194  nNextScript = static_cast<sal_uInt8>(
195  g_pBreakIt->GetBreakIter()->getScriptType(rInf.GetText(), sal_Int32(nPos)));
196 
197  if( ASIAN == nNextScript )
198  {
199  LanguageType aLang =
200  rInf.GetTextFrame()->GetLangOfChar(nPos, nNextScript);
201 
202  if (!MsLangId::isKorean(aLang))
203  ++nCnt;
204  }
205  }
206 
207  return nCnt;
208 }
209 
211 {
212  SwTextPortion *const pNew(new SwTextPortion);
213  static_cast<SwLinePortion&>(*pNew) = rPortion;
214  pNew->SetWhichPor( PortionType::Text ); // overwrite that!
215  return pNew;
216 }
217 
219 {
220  // The word/char is larger than the line
221  // Special case 1: The word is larger than the line
222  // We truncate ...
223  const sal_uInt16 nLineWidth = static_cast<sal_uInt16>(rInf.Width() - rInf.X());
224  TextFrameIndex nLen = rGuess.CutPos() - rInf.GetIdx();
225  if (nLen > TextFrameIndex(0))
226  {
227  // special case: guess does not always provide the correct
228  // width, only in common cases.
229  if ( !rGuess.BreakWidth() )
230  {
231  rInf.SetLen( nLen );
232  SetLen( nLen );
233  CalcTextSize( rInf );
234 
235  // changing these values requires also changing them in
236  // guess.cxx
237  sal_uInt16 nItalic = 0;
238  if( ITALIC_NONE != rInf.GetFont()->GetItalic() && !rInf.NotEOL() )
239  {
240  nItalic = Height() / 12;
241  }
242  Width( Width() + nItalic );
243  }
244  else
245  {
246  Width( rGuess.BreakWidth() );
247  SetLen( nLen );
248  }
249  }
250  // special case: first character does not fit to line
251  else if ( rGuess.CutPos() == rInf.GetLineStart() )
252  {
253  SetLen( TextFrameIndex(1) );
254  Width( nLineWidth );
255  }
256  else
257  {
258  SetLen( TextFrameIndex(0) );
259  Width( 0 );
260  }
261 }
262 
264 {
265  Truncate();
266  Height( 0 );
267  Width( 0 );
268  SetLen( TextFrameIndex(0) );
269  SetAscent( 0 );
270  rInf.SetUnderflow( this );
271 }
272 
273 static bool lcl_HasContent( const SwFieldPortion& rField, SwTextFormatInfo const &rInf )
274 {
275  OUString aText;
276  return rField.GetExpText( rInf, aText ) && !aText.isEmpty();
277 }
278 
280 {
281  // 5744: If only the hyphen does not fit anymore, we still need to wrap
282  // the word, or else return true!
283  if( rInf.IsUnderflow() && rInf.GetSoftHyphPos() )
284  {
285  // soft hyphen portion has triggered an underflow event because
286  // of an alternative spelling position
287  bool bFull = false;
288  const bool bHyph = rInf.ChgHyph( true );
289  if( rInf.IsHyphenate() )
290  {
291  SwTextGuess aGuess;
292  // check for alternative spelling left from the soft hyphen
293  // this should usually be true but
294  aGuess.AlternativeSpelling(rInf, rInf.GetSoftHyphPos() - TextFrameIndex(1));
295  bFull = CreateHyphen( rInf, aGuess );
296  OSL_ENSURE( bFull, "Problem with hyphenation!!!" );
297  }
298  rInf.ChgHyph( bHyph );
299  rInf.SetSoftHyphPos( TextFrameIndex(0) );
300  return bFull;
301  }
302 
303  SwTextGuess aGuess;
304  const bool bFull = !aGuess.Guess( *this, rInf, Height() );
305 
306  // these are the possible cases:
307  // A Portion fits to current line
308  // B Portion does not fit to current line but a possible line break
309  // within the portion has been found by the break iterator, 2 subcases
310  // B1 break is hyphen
311  // B2 break is word end
312  // C Portion does not fit to current line and no possible line break
313  // has been found by break iterator, 2 subcases:
314  // C1 break iterator found a possible line break in portion before us
315  // ==> this break is used (underflow)
316  // C2 break iterator does not found a possible line break at all:
317  // ==> line break
318 
319  // case A: line not yet full
320  if ( !bFull )
321  {
322  Width( aGuess.BreakWidth() );
323  // Caution!
324  if( !InExpGrp() || InFieldGrp() )
325  SetLen( rInf.GetLen() );
326 
327  short nKern = rInf.GetFont()->CheckKerning();
328  if( nKern > 0 && rInf.Width() < rInf.X() + Width() + nKern )
329  {
330  nKern = static_cast<short>(rInf.Width() - rInf.X() - Width() - 1);
331  if( nKern < 0 )
332  nKern = 0;
333  }
334  if( nKern )
335  new SwKernPortion( *this, nKern );
336  }
337  // special case: hanging portion
338  else if( bFull && aGuess.GetHangingPortion() )
339  {
340  Width( aGuess.BreakWidth() );
341  SetLen( aGuess.BreakPos() - rInf.GetIdx() );
342  aGuess.GetHangingPortion()->SetAscent( GetAscent() );
343  Insert( aGuess.ReleaseHangingPortion() );
344  }
345  // breakPos >= index
346  else if (aGuess.BreakPos() >= rInf.GetIdx() && aGuess.BreakPos() != TextFrameIndex(COMPLETE_STRING))
347  {
348  // case B1
349  if( aGuess.HyphWord().is() && aGuess.BreakPos() > rInf.GetLineStart()
350  && ( aGuess.BreakPos() > rInf.GetIdx() ||
351  ( rInf.GetLast() && ! rInf.GetLast()->IsFlyPortion() ) ) )
352  {
353  CreateHyphen( rInf, aGuess );
354  if ( rInf.GetFly() )
355  rInf.GetRoot()->SetMidHyph( true );
356  else
357  rInf.GetRoot()->SetEndHyph( true );
358  }
359  // case C1
360  // - Footnote portions with fake line start (i.e., not at beginning of line)
361  // should keep together with the text portion. (Note: no keep together
362  // with only footnote portions.
363  // - TabPortions not at beginning of line should keep together with the
364  // text portion, if they are not followed by a blank
365  // (work around different definition of tab stop character - breaking or
366  // non breaking character - in compatibility mode)
367  else if ( ( IsFootnotePortion() && rInf.IsFakeLineStart() &&
368 
369  rInf.IsOtherThanFootnoteInside() ) ||
370  ( rInf.GetLast() &&
372  rInf.GetLast()->InTabGrp() &&
373  rInf.GetLineStart() + rInf.GetLast()->GetLen() < rInf.GetIdx() &&
374  aGuess.BreakPos() == rInf.GetIdx() &&
375  CH_BLANK != rInf.GetChar( rInf.GetIdx() ) &&
376  CH_FULL_BLANK != rInf.GetChar( rInf.GetIdx() ) &&
377  CH_SIX_PER_EM != rInf.GetChar( rInf.GetIdx() ) ) )
378  BreakUnderflow( rInf );
379  // case B2
380  else if( rInf.GetIdx() > rInf.GetLineStart() ||
381  aGuess.BreakPos() > rInf.GetIdx() ||
382  // this is weird: during formatting the follow of a field
383  // the values rInf.GetIdx and rInf.GetLineStart are replaced
384  // IsFakeLineStart indicates GetIdx > GetLineStart
385  rInf.IsFakeLineStart() ||
386  rInf.GetFly() ||
387  rInf.IsFirstMulti() ||
388  ( rInf.GetLast() &&
389  ( rInf.GetLast()->IsFlyPortion() ||
390  ( rInf.GetLast()->InFieldGrp() &&
391  ! rInf.GetLast()->InNumberGrp() &&
392  ! rInf.GetLast()->IsErgoSumPortion() &&
393  lcl_HasContent(*static_cast<SwFieldPortion*>(rInf.GetLast()),rInf ) ) ) ) )
394  {
395  // GetLineWidth() takes care of DocumentSettingId::TAB_OVER_MARGIN.
396  if (aGuess.BreakWidth() <= rInf.GetLineWidth())
397  Width( aGuess.BreakWidth() );
398  else
399  // this actually should not happen
400  Width( sal_uInt16(rInf.Width() - rInf.X()) );
401 
402  SetLen( aGuess.BreakPos() - rInf.GetIdx() );
403 
404  OSL_ENSURE( aGuess.BreakStart() >= aGuess.FieldDiff(),
405  "Trouble with expanded field portions during line break" );
406  TextFrameIndex const nRealStart = aGuess.BreakStart() - aGuess.FieldDiff();
407  if( aGuess.BreakPos() < nRealStart && !InExpGrp() )
408  {
409  SwHolePortion *pNew = new SwHolePortion( *this );
410  pNew->SetLen( nRealStart - aGuess.BreakPos() );
411  Insert( pNew );
412  }
413  }
414  else // case C2, last exit
415  BreakCut( rInf, aGuess );
416  }
417  // breakPos < index or no breakpos at all
418  else
419  {
420  bool bFirstPor = rInf.GetLineStart() == rInf.GetIdx();
421  if (aGuess.BreakPos() != TextFrameIndex(COMPLETE_STRING) &&
422  aGuess.BreakPos() != rInf.GetLineStart() &&
423  ( !bFirstPor || rInf.GetFly() || rInf.GetLast()->IsFlyPortion() ||
424  rInf.IsFirstMulti() ) &&
425  ( !rInf.GetLast()->IsBlankPortion() ||
426  SwBlankPortion::MayUnderflow(rInf, rInf.GetIdx() - TextFrameIndex(1), true)))
427  { // case C1 (former BreakUnderflow())
428  BreakUnderflow( rInf );
429  }
430  else
431  // case C2, last exit
432  BreakCut( rInf, aGuess );
433  }
434 
435  return bFull;
436 }
437 
439 {
440  // GetLineWidth() takes care of DocumentSettingId::TAB_OVER_MARGIN.
441  if( rInf.GetLineWidth() < 0 || (!GetLen() && !InExpGrp()) )
442  {
443  Height( 0 );
444  Width( 0 );
445  SetLen( TextFrameIndex(0) );
446  SetAscent( 0 );
447  SetNextPortion( nullptr ); // ????
448  return true;
449  }
450 
451  OSL_ENSURE( rInf.RealWidth() || (rInf.X() == rInf.Width()),
452  "SwTextPortion::Format: missing real width" );
453  OSL_ENSURE( Height(), "SwTextPortion::Format: missing height" );
454 
455  return Format_( rInf );
456 }
457 
458 // Format end of line
459 // 5083: We can have awkward cases e.g.:
460 // "from {Santa}"
461 // Santa wraps, "from " turns into "from" and " " in a justified
462 // paragraph, in which the glue gets expanded instead of merged
463 // with the MarginPortion.
464 
465 // rInf.nIdx points to the next word, nIdx-1 is the portion's last char
467 {
468  if( !(
470  !GetNextPortion()->GetNextPortion() ) ) &&
471  GetLen() &&
472  rInf.GetIdx() < TextFrameIndex(rInf.GetText().getLength()) &&
473  TextFrameIndex(1) < rInf.GetIdx() &&
474  ' ' == rInf.GetChar(rInf.GetIdx() - TextFrameIndex(1)) &&
475  !rInf.GetLast()->IsHolePortion()) )
476  return;
477 
478  // calculate number of blanks
479  TextFrameIndex nX(rInf.GetIdx() - TextFrameIndex(1));
480  TextFrameIndex nHoleLen(1);
481  while( nX && nHoleLen < GetLen() && CH_BLANK == rInf.GetChar( --nX ) )
482  nHoleLen++;
483 
484  // First set ourselves and the insert, because there could be
485  // a SwLineLayout
486  sal_uInt16 nBlankSize;
487  if( nHoleLen == GetLen() )
488  nBlankSize = Width();
489  else
490  nBlankSize = sal_Int32(nHoleLen) * rInf.GetTextSize(OUString(' ')).Width();
491  Width( Width() - nBlankSize );
492  rInf.X( rInf.X() - nBlankSize );
493  SetLen( GetLen() - nHoleLen );
494  SwLinePortion *pHole = new SwHolePortion( *this );
495  static_cast<SwHolePortion *>( pHole )->SetBlankWidth( nBlankSize );
496  static_cast<SwHolePortion *>( pHole )->SetLen( nHoleLen );
497  Insert( pHole );
498 
499 }
500 
502 {
503  OSL_ENSURE( false, "SwTextPortion::GetModelPositionForViewPoint: don't use this method!" );
505 }
506 
507 // The GetTextSize() assumes that the own length is correct
509 {
510  SwPosSize aSize = rInf.GetTextSize();
511  if( !GetJoinBorderWithPrev() )
512  aSize.Width(aSize.Width() + rInf.GetFont()->GetLeftBorderSpace() );
513  if( !GetJoinBorderWithNext() )
514  aSize.Width(aSize.Width() + rInf.GetFont()->GetRightBorderSpace() );
515 
516  aSize.Height(aSize.Height() +
517  rInf.GetFont()->GetTopBorderSpace() +
518  rInf.GetFont()->GetBottomBorderSpace() );
519 
520  return aSize;
521 }
522 
523 void SwTextPortion::Paint( const SwTextPaintInfo &rInf ) const
524 {
525  if (rInf.OnWin() && TextFrameIndex(1) == rInf.GetLen()
526  && CH_TXT_ATR_FIELDEND == rInf.GetText()[sal_Int32(rInf.GetIdx())])
527  {
528  assert(false); // this is some debugging only code
529  rInf.DrawBackBrush( *this );
530  const OUString aText(CH_TXT_ATR_SUBST_FIELDEND);
531  rInf.DrawText(aText, *this, TextFrameIndex(0), TextFrameIndex(aText.getLength()));
532  }
533  else if (rInf.OnWin() && TextFrameIndex(1) == rInf.GetLen()
534  && CH_TXT_ATR_FIELDSTART == rInf.GetText()[sal_Int32(rInf.GetIdx())])
535  {
536  assert(false); // this is some debugging only code
537  rInf.DrawBackBrush( *this );
538  const OUString aText(CH_TXT_ATR_SUBST_FIELDSTART);
539  rInf.DrawText(aText, *this, TextFrameIndex(0), TextFrameIndex(aText.getLength()));
540  }
541  else if( GetLen() )
542  {
543  rInf.DrawBackBrush( *this );
544  rInf.DrawBorder( *this );
545 
546  // do we have to repaint a post it portion?
547  if( rInf.OnWin() && mpNextPortion && !mpNextPortion->Width() )
548  mpNextPortion->PrePaint( rInf, this );
549 
550  auto const* pWrongList = rInf.GetpWrongList();
551  auto const* pGrammarCheckList = rInf.GetGrammarCheckList();
552  auto const* pSmarttags = rInf.GetSmartTags();
553 
554  const bool bWrong = nullptr != pWrongList;
555  const bool bGrammarCheck = nullptr != pGrammarCheckList;
556  const bool bSmartTags = nullptr != pSmarttags;
557 
558  if ( bWrong || bSmartTags || bGrammarCheck )
559  rInf.DrawMarkedText( *this, rInf.GetLen(), bWrong, bSmartTags, bGrammarCheck );
560  else
561  rInf.DrawText( *this, rInf.GetLen() );
562  }
563 }
564 
565 bool SwTextPortion::GetExpText( const SwTextSizeInfo &, OUString & ) const
566 {
567  return false;
568 }
569 
570 // Responsible for the justified paragraph. They calculate the blank
571 // count and the resulting added space.
573  TextFrameIndex& rCharCnt) const
574 {
575  TextFrameIndex nCnt(0);
576  TextFrameIndex nPos(0);
577 
578  if ( rInf.SnapToGrid() )
579  {
580  SwTextGridItem const*const pGrid(GetGridItem(rInf.GetTextFrame()->FindPageFrame()));
581  if (pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars())
582  return TextFrameIndex(0);
583  }
584 
585  if ( InExpGrp() )
586  {
587  if( !IsBlankPortion() && !InNumberGrp() && !IsCombinedPortion() )
588  {
589  // OnWin() likes to return a blank instead of an empty string from
590  // time to time. We cannot use that here at all, however.
591  bool bOldOnWin = rInf.OnWin();
592  const_cast<SwTextSizeInfo &>(rInf).SetOnWin( false );
593 
594  OUString aStr;
595  GetExpText( rInf, aStr );
596  const_cast<SwTextSizeInfo &>(rInf).SetOnWin( bOldOnWin );
597 
598  nCnt = nCnt + lcl_AddSpace( rInf, &aStr, *this );
599  nPos = TextFrameIndex(aStr.getLength());
600  }
601  }
602  else if( !IsDropPortion() )
603  {
604  nCnt = nCnt + lcl_AddSpace( rInf, nullptr, *this );
605  nPos = GetLen();
606  }
607  rCharCnt = rCharCnt + nPos;
608  return nCnt;
609 }
610 
611 long SwTextPortion::CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const
612 {
613  TextFrameIndex nCnt(0);
614 
615  if ( rInf.SnapToGrid() )
616  {
617  SwTextGridItem const*const pGrid(GetGridItem(rInf.GetTextFrame()->FindPageFrame()));
618  if (pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars())
619  return 0;
620  }
621 
622  if ( InExpGrp() )
623  {
624  if( !IsBlankPortion() && !InNumberGrp() && !IsCombinedPortion() )
625  {
626  // OnWin() likes to return a blank instead of an empty string from
627  // time to time. We cannot use that here at all, however.
628  bool bOldOnWin = rInf.OnWin();
629  const_cast<SwTextSizeInfo &>(rInf).SetOnWin( false );
630 
631  OUString aStr;
632  GetExpText( rInf, aStr );
633  const_cast<SwTextSizeInfo &>(rInf).SetOnWin( bOldOnWin );
634  if( nSpaceAdd > 0 )
635  nCnt = nCnt + lcl_AddSpace( rInf, &aStr, *this );
636  else
637  {
638  nSpaceAdd = -nSpaceAdd;
639  nCnt = TextFrameIndex(aStr.getLength());
640  }
641  }
642  }
643  else if( !IsDropPortion() )
644  {
645  if( nSpaceAdd > 0 )
646  nCnt = nCnt + lcl_AddSpace( rInf, nullptr, *this );
647  else
648  {
649  nSpaceAdd = -nSpaceAdd;
650  nCnt = GetLen();
651  SwLinePortion* pPor = GetNextPortion();
652 
653  // we do not want an extra space in front of margin portions
654  if ( nCnt )
655  {
656  while ( pPor && !pPor->Width() && ! pPor->IsHolePortion() )
657  pPor = pPor->GetNextPortion();
658 
659  if ( !pPor || pPor->InFixMargGrp() || pPor->IsHolePortion() )
660  --nCnt;
661  }
662  }
663  }
664 
665  return sal_Int32(nCnt) * nSpaceAdd / SPACING_PRECISION_FACTOR;
666 }
667 
669 {
670  rPH.Text( GetLen(), GetWhichPor(), Height(), Width() );
671 }
672 
674  : SwTextPortion()
675 {
677 }
678 
680 {
681  return SwTextPortion::Format(rTextFormatInfo);
682 }
683 
685 {
686  if ( Width() )
687  {
688  rInf.DrawViewOpt( *this, PortionType::InputField );
689  SwTextSlot aPaintText( &rInf, this, true, true, OUString() );
690  SwTextPortion::Paint( rInf );
691  }
692 }
693 
694 bool SwTextInputFieldPortion::GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const
695 {
696  sal_Int32 nIdx(rInf.GetIdx());
697  sal_Int32 nLen(rInf.GetLen());
698  if ( rInf.GetChar( rInf.GetIdx() ) == CH_TXT_ATR_INPUTFIELDSTART )
699  {
700  ++nIdx;
701  --nLen;
702  }
703  if (rInf.GetChar(rInf.GetIdx() + rInf.GetLen() - TextFrameIndex(1)) == CH_TXT_ATR_INPUTFIELDEND)
704  {
705  --nLen;
706  }
707  rText = rInf.GetText().copy( nIdx, std::min( nLen, rInf.GetText().getLength() - nIdx ) );
708 
709  return true;
710 }
711 
713 {
714  SwTextSlot aFormatText( &rInf, this, true, false );
715  if (rInf.GetLen() == TextFrameIndex(0))
716  {
717  return SwPosSize( 0, 0 );
718  }
719 
720  return rInf.GetTextSize();
721 }
722 
724  : nBlankWidth( 0 )
725 {
726  SetLen( TextFrameIndex(1) );
727  Height( rPor.Height() );
728  SetAscent( rPor.GetAscent() );
730 }
731 
733 
734 void SwHolePortion::Paint( const SwTextPaintInfo &rInf ) const
735 {
736  if( !rInf.GetOut() )
737  return;
738 
739  // #i16816# export stuff only needed for tagged pdf support
741  return;
742 
743  // #i68503# the hole must have no decoration for a consistent visual appearance
744  const SwFont* pOrigFont = rInf.GetFont();
745  std::unique_ptr<SwFont> pHoleFont;
746  std::unique_ptr<SwFontSave> pFontSave;
747  if( pOrigFont->GetUnderline() != LINESTYLE_NONE
748  || pOrigFont->GetOverline() != LINESTYLE_NONE
749  || pOrigFont->GetStrikeout() != STRIKEOUT_NONE )
750  {
751  pHoleFont.reset(new SwFont( *pOrigFont ));
752  pHoleFont->SetUnderline( LINESTYLE_NONE );
753  pHoleFont->SetOverline( LINESTYLE_NONE );
754  pHoleFont->SetStrikeout( STRIKEOUT_NONE );
755  pFontSave.reset(new SwFontSave( rInf, pHoleFont.get() ));
756  }
757 
758  const OUString aText( ' ' );
759  rInf.DrawText(aText, *this, TextFrameIndex(0), TextFrameIndex(1));
760 
761  pFontSave.reset();
762  pHoleFont.reset();
763 }
764 
766 {
767  return rInf.IsFull() || rInf.X() >= rInf.Width();
768 }
769 
771 {
772  rPH.Text( GetLen(), GetWhichPor() );
773 }
774 
775 void SwFieldMarkPortion::Paint( const SwTextPaintInfo & /*rInf*/) const
776 {
777  // These shouldn't be painted!
778  //SwTextPortion::Paint(rInf);
779 }
780 
782 {
783  Width(0);
784  return false;
785 }
786 
788 {
789  SwPosition const aPosition(rInf.GetTextFrame()->MapViewToModelPos(rInf.GetIdx()));
790 
791  IFieldmark const*const pBM = rInf.GetTextFrame()->GetDoc().getIDocumentMarkAccess()->getFieldmarkAt(aPosition);
792 
793  OSL_ENSURE(pBM && pBM->GetFieldname( ) == ODF_FORMCHECKBOX,
794  "Where is my form field bookmark???");
795 
796  if (pBM && pBM->GetFieldname( ) == ODF_FORMCHECKBOX)
797  {
798  const ICheckboxFieldmark* pCheckboxFm = dynamic_cast<ICheckboxFieldmark const*>(pBM);
799  bool bChecked = pCheckboxFm && pCheckboxFm->IsChecked();
800  rInf.DrawCheckBox(*this, bChecked);
801  }
802 }
803 
805 {
806  SwPosition const aPosition(rInf.GetTextFrame()->MapViewToModelPos(rInf.GetIdx()));
807  IFieldmark const*const pBM = rInf.GetTextFrame()->GetDoc().getIDocumentMarkAccess()->getFieldmarkAt(aPosition);
808  OSL_ENSURE(pBM && pBM->GetFieldname( ) == ODF_FORMCHECKBOX, "Where is my form field bookmark???");
809  if (pBM && pBM->GetFieldname( ) == ODF_FORMCHECKBOX)
810  {
811  // the width of the checkbox portion is the same as its height since it's a square
812  // and that size depends on the font size.
813  // See:
814  // http://document-foundation-mail-archive.969070.n3.nabble.com/Wrong-copy-paste-in-SwFieldFormCheckboxPortion-Format-td4269112.html
815  Width( rInf.GetTextHeight( ) );
816  Height( rInf.GetTextHeight( ) );
817  SetAscent( rInf.GetAscent( ) );
818  }
819  return false;
820 }
821 
822 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsFirstMulti() const
Definition: inftxt.hxx:212
sal_uInt16 GetLeftBorderSpace() const
Definition: swfont.hxx:908
TextFrameIndex FieldDiff() const
Definition: guess.hxx:57
void DrawBackBrush(const SwLinePortion &rPor) const
Definition: inftxt.cxx:1154
virtual ::sw::mark::IFieldmark * getFieldmarkAt(const SwPosition &rPos) const =0
get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
short CheckKerning()
Definition: swfont.hxx:323
Marks a position in the document model.
Definition: pam.hxx:35
virtual void FormatEOL(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:466
sal_uInt16 BreakWidth() const
Definition: guess.hxx:53
bool IsUnderflow() const
Definition: inftxt.hxx:589
LanguageType GetLangOfChar(TextFrameIndex nIndex, sal_uInt16 nScript, bool bNoChar=false) const
Definition: txtfrm.cxx:1330
#define CH_TXT_ATR_SUBST_FIELDSTART
Definition: hintids.hxx:182
sal_uInt16 Height() const
Definition: possiz.hxx:44
SwFont * GetFont()
Definition: inftxt.hxx:238
bool InNumberGrp() const
Definition: porlin.hxx:102
SwHolePortion(const SwTextPortion &rPor)
Definition: portxt.cxx:723
bool GetJoinBorderWithPrev() const
Definition: porlin.hxx:168
void BreakCut(SwTextFormatInfo &rInf, const SwTextGuess &rGuess)
Definition: portxt.cxx:218
void CalcTextSize(const SwTextSizeInfo &rInfo)
Definition: porlin.cxx:138
sal_uInt16 GetRightBorderSpace() const
Definition: swfont.hxx:893
#define CH_TXT_ATR_SUBST_FIELDEND
Definition: hintids.hxx:183
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
#define ODF_FORMCHECKBOX
void DrawBorder(const SwLinePortion &rPor) const
Draw character border around a line portion.
Definition: inftxt.cxx:1301
sal_uInt16 GetTextHeight() const
Definition: inftxt.hxx:719
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: portxt.cxx:684
static TextFrameIndex lcl_AddSpace(const SwTextSizeInfo &rInf, const OUString *pStr, const SwLinePortion &rPor)
Definition: portxt.cxx:47
bool Guess(const SwTextPortion &rPor, SwTextFormatInfo &rInf, const sal_uInt16 nHeight)
Definition: guess.cxx:50
void SetLen(TextFrameIndex const nLen)
Definition: porlin.hxx:75
#define ASIAN
sw::WrongListIterator * GetGrammarCheckList() const
Definition: inftxt.hxx:458
void DrawText(const OUString &rText, const SwLinePortion &rPor, TextFrameIndex nIdx=TextFrameIndex(0), TextFrameIndex nLen=TextFrameIndex(COMPLETE_STRING), const bool bKern=false) const
Definition: inftxt.hxx:747
sal_uInt16 RealWidth() const
Definition: inftxt.hxx:555
FontStrikeout GetStrikeout() const
Definition: swfont.hxx:275
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1683
static bool lcl_HasContent(const SwFieldPortion &rField, SwTextFormatInfo const &rInf)
Definition: portxt.cxx:273
bool InFieldGrp() const
Definition: porlin.hxx:104
bool Format_(SwTextFormatInfo &rInf)
Definition: portxt.cxx:279
SwPosSize GetTextSize(OutputDevice *pOut, const SwScriptInfo *pSI, const OUString &rText, TextFrameIndex nIdx, TextFrameIndex nLen) const
Definition: inftxt.cxx:382
virtual void Text(TextFrameIndex nLength, PortionType nType, sal_Int32 nHeight=0, sal_Int32 nWidth=0)=0
(empty) destructor
bool AlternativeSpelling(const SwTextFormatInfo &rInf, const TextFrameIndex nPos)
Definition: guess.cxx:564
Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
Definition: porlay.hxx:229
bool ChgHyph(const bool bNew)
Definition: inftxt.cxx:1961
bool IsFull() const
Definition: inftxt.hxx:569
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: portxt.cxx:523
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: portxt.cxx:775
bool IsControlCharPortion() const
Definition: porlin.hxx:136
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:170
sw::WrongListIterator * GetSmartTags() const
Definition: inftxt.hxx:461
LINESTYLE_NONE
bool IsBreakPortion() const
Definition: porlin.hxx:114
sal_Unicode GetChar(TextFrameIndex const nPos) const
Definition: inftxt.hxx:247
#define CH_TXT_ATR_INPUTFIELDSTART
Definition: hintids.hxx:174
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:33
void DrawCheckBox(const SwFieldFormCheckboxPortion &rPor, bool bChecked) const
Definition: inftxt.cxx:1095
TextFrameIndex BreakStart() const
Definition: guess.hxx:55
static sal_uInt16 MayUnderflow(const SwTextFormatInfo &rInf, TextFrameIndex nIdx, bool bUnderflow)
If a Line is full of HardBlanks and overflows, we must not generate underflows! Causes problems with ...
Definition: porexp.cxx:104
void SetUnderline(const FontLineStyle eUnderline)
Definition: swfont.hxx:545
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:438
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porfld.cxx:441
TextFrameIndex GetLineStart() const
Definition: inftxt.hxx:596
TextFrameIndex BreakPos() const
Definition: guess.hxx:56
bool InFixMargGrp() const
Definition: porlin.hxx:108
This portion represents a part of the paragraph string.
Definition: portxt.hxx:27
static bool IsArabicText(const OUString &rText, TextFrameIndex nStt, TextFrameIndex nLen)
Checks if text is Arabic text.
Definition: porlay.cxx:2122
static SwTextPortion * CopyLinePortion(const SwLinePortion &rPortion)
Definition: portxt.cxx:210
void SetEndHyph(const bool bNew)
Definition: porlay.hxx:112
bool IsCombinedPortion() const
Definition: porlin.hxx:129
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:765
virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const
the parameter is actually SwTwips apparently?
Definition: porlin.cxx:222
SwPosSize(const sal_uInt16 nW=0, const sal_uInt16 nH=0)
Definition: possiz.hxx:31
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const
Definition: porlin.cxx:310
const sal_Unicode CH_FULL_BLANK
Definition: swfont.hxx:47
virtual SwLinePortion * Compress() override
Definition: portxt.cxx:732
SwTwips GetLineWidth()
Returns the distance between the current horizontal position and the end of the line.
Definition: inftxt.cxx:1753
vcl::RenderContext * GetOut()
Definition: inftxt.hxx:231
SwPageFrame * FindPageFrame()
Definition: frame.hxx:660
SwParaPortion * GetParaPortion()
Definition: inftxt.hxx:128
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:94
void SetUnderflow(SwLinePortion *pNew)
Definition: inftxt.hxx:607
bool IsFlyPortion() const
Definition: porlin.hxx:125
SwTextGridItem const * GetGridItem(SwPageFrame const *const)
Definition: pagechg.cxx:2515
TextFrameIndex CutPos() const
Definition: guess.hxx:54
FontLineStyle GetOverline() const
Definition: swfont.hxx:273
const sal_Unicode CH_BLANK
Definition: swfont.hxx:42
bool IsKernPortion() const
Definition: porlin.hxx:132
sal_uInt16 GetTopBorderSpace() const
Definition: swfont.hxx:863
#define CH_TXT_ATR_FIELDSTART
Definition: hintids.hxx:179
sal_uInt16 Width() const
Definition: inftxt.hxx:534
SwLineLayout * GetRoot()
Definition: inftxt.hxx:563
bool NotEOL() const
Definition: inftxt.hxx:201
static bool IsExportTaggedPDF(const OutputDevice &rOut)
TextFrameIndex GetIdx() const
Definition: inftxt.hxx:278
bool IsDropPortion() const
Definition: porlin.hxx:121
ITALIC_NONE
void PrePaint(const SwTextPaintInfo &rInf, const SwLinePortion *pLast) const
Definition: porlin.cxx:76
bool SnapToGrid() const
Definition: inftxt.hxx:222
TextFrameIndex GetLen() const
Definition: porlin.hxx:74
sw::WrongListIterator * GetpWrongList() const
Definition: inftxt.hxx:455
bool InTabGrp() const
Definition: porlin.hxx:100
SwTextFrame * GetTextFrame()
Definition: inftxt.hxx:291
sal_Int32 nLineWidth
const OUString & GetText() const
Definition: inftxt.hxx:246
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: portxt.cxx:694
virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const override
the parameter is actually SwTwips apparently?
Definition: portxt.cxx:501
#define LANGUAGE_THAI
bool IsHolePortion() const
Definition: porlin.hxx:126
void Truncate()
Definition: porlin.hxx:196
SwLinePortion * mpNextPortion
Definition: porlin.hxx:54
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
Definition: breakit.hxx:62
FontLineStyle GetUnderline() const
Definition: swfont.hxx:271
SwTwips X() const
Definition: inftxt.hxx:385
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:781
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:50
virtual long CalcSpacing(long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: portxt.cxx:611
void SetSoftHyphPos(TextFrameIndex const nNew)
Definition: inftxt.hxx:610
bool CreateHyphen(SwTextFormatInfo &rInf, SwTextGuess const &rGuess)
Definition: txthyph.cxx:252
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:679
#define CH_TXT_ATR_INPUTFIELDEND
Definition: hintids.hxx:175
sal_Int16 ScriptType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1621
bool IsHyphenate() const
If the Hyphenator returns ERROR or the language is set to NOLANGUAGE we do not hyphenate.
Definition: inftxt.cxx:1478
void SetLen(const TextFrameIndex nNew)
Definition: inftxt.hxx:281
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: portxt.cxx:565
bool InExpGrp() const
Definition: porlin.hxx:107
For the text replacement and restoration of SwTextSizeInfo.
Definition: inftxt.hxx:680
unsigned char sal_uInt8
PortionType GetWhichPor() const
Definition: porlin.hxx:95
bool IsFootnotePortion() const
Definition: porlin.hxx:120
FontItalic GetItalic() const
Definition: swfont.hxx:281
bool IsErgoSumPortion() const
Definition: porlin.hxx:115
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: portxt.cxx:734
static TextFrameIndex ThaiJustify(const OUString &rText, long *pKernArray, long *pScrArray, TextFrameIndex nIdx, TextFrameIndex nLen, TextFrameIndex nNumberOfBlanks=TextFrameIndex(0), long nSpaceAdd=0)
Performs a thai justification on the kerning array.
Definition: porlay.cxx:2296
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:175
bool OnWin() const
Definition: inftxt.hxx:199
bool IsRightToLeft() const
Definition: frame.hxx:965
SwHangingPortion * GetHangingPortion() const
Definition: guess.hxx:51
TextFrameIndex GetLen() const
Definition: inftxt.hxx:280
sal_uInt16 GetBottomBorderSpace() const
Definition: swfont.hxx:878
virtual bool Format(SwTextFormatInfo &rInf) override
Definition: portxt.cxx:804
static bool isKorean(LanguageType nLang)
sal_uInt16 Width() const
Definition: possiz.hxx:46
TextFrameIndex GetSpaceCnt(const SwTextSizeInfo &rInf, TextFrameIndex &rCnt) const
Definition: portxt.cxx:572
SwLinePortion * GetLast()
Definition: inftxt.hxx:567
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
#define CH_TXT_ATR_FIELDEND
Definition: hintids.hxx:181
void SetNextPortion(SwLinePortion *pNew)
Definition: porlin.hxx:76
bool IsSnapToChars() const
Definition: tgrditem.hxx:100
SwHangingPortion * ReleaseHangingPortion()
Definition: guess.hxx:52
size_t CountKashida() const
Definition: scriptinfo.hxx:150
bool IsFakeLineStart() const
Definition: inftxt.hxx:578
void SetAscent(const sal_uInt16 nNewAsc)
Definition: porlin.hxx:79
void BreakUnderflow(SwTextFormatInfo &rInf)
Definition: portxt.cxx:263
#define SPACING_PRECISION_FACTOR
Definition: scriptinfo.hxx:39
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: portxt.cxx:770
SwDoc & GetDoc()
Definition: txtfrm.hxx:452
bool IsOtherThanFootnoteInside() const
Definition: inftxt.hxx:208
SwTextGrid GetGridType() const
Definition: tgrditem.hxx:81
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: portxt.cxx:787
STRIKEOUT_NONE
virtual SwPosSize GetTextSize(const SwTextSizeInfo &rInfo) const override
Definition: portxt.cxx:508
SwFlyPortion * GetFly()
Definition: inftxt.hxx:615
void SetMidHyph(const bool bNew)
Definition: porlay.hxx:114
bool GetJoinBorderWithNext() const
Definition: porlin.hxx:169
SwLinePortion * GetNextPortion() const
Definition: porlin.hxx:72
static TextFrameIndex CountCJKCharacters(const OUString &rText, TextFrameIndex nPos, TextFrameIndex nEnd, LanguageType aLang)
Definition: porlay.cxx:2590
sal_Int32 KashidaJustify(long *pKernArray, long *pScrArray, TextFrameIndex nStt, TextFrameIndex nLen, long nSpaceAdd=0) const
Performs a kashida justification on the kerning array.
Definition: porlay.cxx:2037
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
virtual SwPosSize GetTextSize(const SwTextSizeInfo &rInfo) const override
Definition: portxt.cxx:712
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1235
aStr
sal_uInt16 & GetAscent()
Definition: porlin.hxx:77
#define COMPLEX
virtual SwLinePortion * Insert(SwLinePortion *pPortion)
Definition: porlin.cxx:168
void DrawMarkedText(const SwLinePortion &rPor, TextFrameIndex nLen, const bool bWrong, const bool bSmartTags, const bool bGrammarCheck) const
Definition: inftxt.hxx:761
const sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:61
TextFrameIndex GetSoftHyphPos() const
Definition: inftxt.hxx:609
void DrawViewOpt(const SwLinePortion &rPor, PortionType nWhich) const
Definition: inftxt.cxx:1313
sal_uInt16 nPos
bool IsPostItsPortion() const
Definition: porlin.hxx:128
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: portxt.cxx:668
const css::uno::Reference< css::linguistic2::XHyphenatedWord > & HyphWord() const
Definition: guess.hxx:58
sal_uInt16 GetAscent() const
Definition: inftxt.hxx:713
bool IsBlankPortion() const
Definition: porlin.hxx:113
const sal_Unicode CH_SIX_PER_EM
Definition: swfont.hxx:49