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