LibreOffice Module sw (master)  1
atrstck.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 "atrhndl.hxx"
21 #include <svl/itemiter.hxx>
22 #include <vcl/outdev.hxx>
23 #include <editeng/cmapitem.hxx>
24 #include <editeng/colritem.hxx>
25 #include <editeng/contouritem.hxx>
28 #include <editeng/fontitem.hxx>
29 #include <editeng/fhgtitem.hxx>
30 #include <editeng/kernitem.hxx>
32 #include <editeng/langitem.hxx>
33 #include <editeng/postitem.hxx>
34 #include <editeng/shdditem.hxx>
35 #include <editeng/udlnitem.hxx>
36 #include <editeng/wghtitem.hxx>
37 #include <editeng/wrlmitem.hxx>
38 #include <editeng/autokernitem.hxx>
42 #include <editeng/twolinesitem.hxx>
44 #include <editeng/boxitem.hxx>
45 #include <editeng/shaditem.hxx>
46 #include <viewopt.hxx>
47 #include <charfmt.hxx>
48 #include <fchrfmt.hxx>
49 #include <fmtautofmt.hxx>
50 #include <editeng/brushitem.hxx>
51 #include <fmtinfmt.hxx>
52 #include <txtinet.hxx>
54 #include <viewsh.hxx>
55 
69 {
70  0, // // 0
71  1, // RES_CHRATR_CASEMAP = RES_CHRATR_BEGIN // 1
72  0, // RES_CHRATR_CHARSETCOLOR, // 2
73  2, // RES_CHRATR_COLOR, // 3
74  3, // RES_CHRATR_CONTOUR, // 4
75  4, // RES_CHRATR_CROSSEDOUT, // 5
76  5, // RES_CHRATR_ESCAPEMENT, // 6
77  6, // RES_CHRATR_FONT, // 7
78  7, // RES_CHRATR_FONTSIZE, // 8
79  8, // RES_CHRATR_KERNING, // 9
80  9, // RES_CHRATR_LANGUAGE, // 10
81  10, // RES_CHRATR_POSTURE, // 11
82  0, // RES_CHRATR_UNUSED1, // 12
83  11, // RES_CHRATR_SHADOWED, // 13
84  12, // RES_CHRATR_UNDERLINE, // 14
85  13, // RES_CHRATR_WEIGHT, // 15
86  14, // RES_CHRATR_WORDLINEMODE, // 16
87  15, // RES_CHRATR_AUTOKERN, // 17
88  16, // RES_CHRATR_BLINK, // 18
89  17, // RES_CHRATR_NOHYPHEN, // 19
90  0, // RES_CHRATR_UNUSED2, // 20
91  18, // RES_CHRATR_BACKGROUND, // 21
92  19, // RES_CHRATR_CJK_FONT, // 22
93  20, // RES_CHRATR_CJK_FONTSIZE, // 23
94  21, // RES_CHRATR_CJK_LANGUAGE, // 24
95  22, // RES_CHRATR_CJK_POSTURE, // 25
96  23, // RES_CHRATR_CJK_WEIGHT, // 26
97  24, // RES_CHRATR_CTL_FONT, // 27
98  25, // RES_CHRATR_CTL_FONTSIZE, // 28
99  26, // RES_CHRATR_CTL_LANGUAGE, // 29
100  27, // RES_CHRATR_CTL_POSTURE, // 30
101  28, // RES_CHRATR_CTL_WEIGHT, // 31
102  29, // RES_CHRATR_ROTATE, // 32
103  30, // RES_CHRATR_EMPHASIS_MARK, // 33
104  31, // RES_CHRATR_TWO_LINES, // 34
105  32, // RES_CHRATR_SCALEW, // 35
106  33, // RES_CHRATR_RELIEF, // 36
107  34, // RES_CHRATR_HIDDEN, // 37
108  35, // RES_CHRATR_OVERLINE, // 38
109  0, // RES_CHRATR_RSID, // 39
110  36, // RES_CHRATR_BOX, // 40
111  37, // RES_CHRATR_SHADOW, // 41
112  38, // RES_CHRATR_HIGHLIGHT, // 42
113  0, // RES_CHRATR_GRABBAG, // 43
114  0, // RES_CHRATR_BIDIRTL, // 44
115  0, // RES_CHRATR_IDCTHINT, // 45
116  39, // RES_TXTATR_REFMARK, // 46
117  40, // RES_TXTATR_TOXMARK, // 47
118  41, // RES_TXTATR_META, // 48
119  41, // RES_TXTATR_METAFIELD, // 49
120  0, // RES_TXTATR_AUTOFMT, // 50
121  0, // RES_TXTATR_INETFMT // 51
122  0, // RES_TXTATR_CHARFMT, // 52
123  42, // RES_TXTATR_CJK_RUBY, // 53
124  0, // RES_TXTATR_UNKNOWN_CONTAINER, // 54
125  43, // RES_TXTATR_INPUTFIELD // 55
126 };
127 
128 namespace CharFormat
129 {
130 
132 const SfxItemSet* GetItemSet( const SfxPoolItem& rAttr )
133 {
134  const SfxItemSet* pSet = nullptr;
135 
136  if ( RES_TXTATR_AUTOFMT == rAttr.Which() )
137  {
138  pSet = rAttr.StaticWhichCast(RES_TXTATR_AUTOFMT).GetStyleHandle().get();
139  }
140  else
141  {
142  // Get the attributes from the template
143  const SwCharFormat* pFormat = RES_TXTATR_INETFMT == rAttr.Which() ?
144  rAttr.StaticWhichCast(RES_TXTATR_INETFMT).GetTextINetFormat()->GetCharFormat() :
145  static_cast<const SwFormatCharFormat&>(rAttr).GetCharFormat();
146  if( pFormat )
147  {
148  pSet = &pFormat->GetAttrSet();
149  }
150  }
151 
152  return pSet;
153 }
154 
156 const SfxPoolItem* GetItem( const SwTextAttr& rAttr, sal_uInt16 nWhich )
157 {
158  if ( RES_TXTATR_INETFMT == rAttr.Which() ||
159  RES_TXTATR_CHARFMT == rAttr.Which() ||
160  RES_TXTATR_AUTOFMT == rAttr.Which() )
161  {
162  const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
163  if ( !pSet ) return nullptr;
164 
165  bool bInParent = RES_TXTATR_AUTOFMT != rAttr.Which();
166  const SfxPoolItem* pItem;
167  bool bRet = SfxItemState::SET == pSet->GetItemState( nWhich, bInParent, &pItem );
168 
169  return bRet ? pItem : nullptr;
170  }
171 
172  return ( nWhich == rAttr.Which() ) ? &rAttr.GetAttr() : nullptr;
173 }
174 
176 bool IsItemIncluded( const sal_uInt16 nWhich, const SwTextAttr *pAttr )
177 {
178  bool bRet = false;
179 
180  const SfxItemSet* pItemSet = CharFormat::GetItemSet( pAttr->GetAttr() );
181  if ( pItemSet )
182  bRet = SfxItemState::SET == pItemSet->GetItemState( nWhich );
183 
184  return bRet;
185 }
186 }
187 
195 static bool lcl_ChgHyperLinkColor( const SwTextAttr& rAttr,
196  const SfxPoolItem& rItem,
197  const SwViewShell* pShell,
198  Color* pColor )
199 {
200  if ( !pShell ||
201  RES_TXTATR_INETFMT != rAttr.Which() ||
202  RES_CHRATR_COLOR != rItem.Which() )
203  return false;
204 
205  // #i15455#
206  // 1. case:
207  // We do not want to show visited links:
208  // (printing, pdf export, page preview)
209 
210  SwTextINetFormat & rINetAttr(const_cast<SwTextINetFormat&>(
211  static_txtattr_cast<SwTextINetFormat const&>(rAttr)));
212  if ( pShell->GetOut()->GetOutDevType() == OUTDEV_PRINTER ||
213  pShell->GetViewOptions()->IsPDFExport() ||
214  pShell->GetViewOptions()->IsPagePreview() )
215  {
216  if (rINetAttr.IsVisited())
217  {
218  if ( pColor )
219  {
220  // take color from character format 'unvisited link'
221  rINetAttr.SetVisited(false);
222  const SwCharFormat* pTmpFormat = rINetAttr.GetCharFormat();
223  const SfxPoolItem* pItem;
224  if (SfxItemState::SET == pTmpFormat->GetItemState(RES_CHRATR_COLOR, true, &pItem))
225  *pColor = pItem->StaticWhichCast(RES_CHRATR_COLOR).GetValue();
226  rINetAttr.SetVisited(true);
227  }
228  return true;
229  }
230 
231  return false;
232  }
233 
234  // 2. case:
235  // We do not want to apply the color set in the hyperlink
236  // attribute, instead we take the colors from the view options:
237 
238  if ( pShell->GetWin() &&
239  (
240  (rINetAttr.IsVisited() && SwViewOption::IsVisitedLinks()) ||
241  (!rINetAttr.IsVisited() && SwViewOption::IsLinks())
242  )
243  )
244  {
245  if ( pColor )
246  {
247  if (rINetAttr.IsVisited())
248  {
249  // take color from view option 'visited link color'
251  }
252  else
253  {
254  // take color from view option 'unvisited link color'
255  *pColor = SwViewOption::GetLinksColor();
256  }
257  }
258  return true;
259  }
260 
261  return false;
262 }
263 
265  : m_pIDocumentSettingAccess(nullptr)
266  , m_pShell(nullptr)
267  , m_bVertLayout(false)
268  , m_bVertLayoutLRBT(false)
269 {
270  memset( m_pDefaultArray, 0, NUM_DEFAULT_VALUES * sizeof(SfxPoolItem*) );
271 }
272 
274 {
275 }
276 
277 void SwAttrHandler::Init( const SwAttrSet& rAttrSet,
278  const IDocumentSettingAccess& rIDocumentSettingAcces )
279 {
280  m_pIDocumentSettingAccess = &rIDocumentSettingAcces;
281  m_pShell = nullptr;
282 
283  for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++ )
284  m_pDefaultArray[ StackPos[ i ] ] = &rAttrSet.Get( i );
285 }
286 
287 void SwAttrHandler::Init( const SfxPoolItem** pPoolItem, const SwAttrSet* pAS,
288  const IDocumentSettingAccess& rIDocumentSettingAcces,
289  const SwViewShell* pSh,
290  SwFont& rFnt, bool bVL, bool bVertLayoutLRBT )
291 {
292  // initialize default array
293  memcpy( m_pDefaultArray, pPoolItem,
294  NUM_DEFAULT_VALUES * sizeof(SfxPoolItem*) );
295 
296  m_pIDocumentSettingAccess = &rIDocumentSettingAcces;
297  m_pShell = pSh;
298 
299  // do we have to apply additional paragraph attributes?
300  m_bVertLayout = bVL;
301  m_bVertLayoutLRBT = bVertLayoutLRBT;
302 
303  if ( pAS && pAS->Count() )
304  {
305  SfxItemIter aIter( *pAS );
306  sal_uInt16 nWhich;
307  const SfxPoolItem* pItem = aIter.GetCurItem();
308  do
309  {
310  nWhich = pItem->Which();
311  if (isCHRATR(nWhich))
312  {
313  m_pDefaultArray[ StackPos[ nWhich ] ] = pItem;
314  FontChg( *pItem, rFnt, true );
315  }
316 
317  pItem = aIter.NextItem();
318  } while (pItem);
319  }
320 
321  // It is possible, that Init is called more than once, e.g., in a
322  // SwTextFrame::FormatOnceMore situation or (since sw_redlinehide)
323  // from SwAttrIter::Seek(); in the latter case SwTextSizeInfo::m_pFnt
324  // is an alias of m_pFnt so it must not be deleted!
325  if (m_oFnt)
326  *m_oFnt = rFnt;
327  else
328  m_oFnt.emplace(rFnt);
329 }
330 
332 {
333  for (auto& i : m_aAttrStack)
334  i = nullptr;
335 }
336 
337 void SwAttrHandler::PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
338 {
339  // these special attributes in fact represent a collection of attributes
340  // they have to be pushed to each stack they belong to
341  if ( RES_TXTATR_INETFMT == rAttr.Which() ||
342  RES_TXTATR_CHARFMT == rAttr.Which() ||
343  RES_TXTATR_AUTOFMT == rAttr.Which() )
344  {
345  const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
346  if ( !pSet ) return;
347 
348  for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
349  {
350  const SfxPoolItem* pItem;
351  bool bRet = SfxItemState::SET == pSet->GetItemState( i, rAttr.Which() != RES_TXTATR_AUTOFMT, &pItem );
352 
353  if ( bRet )
354  {
355  // we push rAttr onto the appropriate stack
356  if ( Push( rAttr, *pItem ) )
357  {
358  // we let pItem change rFnt
359  Color aColor;
360  if (lcl_ChgHyperLinkColor(rAttr, *pItem, m_pShell, &aColor))
361  {
362  SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
363  FontChg( aItemNext, rFnt, true );
364  }
365  else
366  FontChg( *pItem, rFnt, true );
367  }
368  }
369  }
370  }
371  // this is the usual case, we have a basic attribute, push it onto the
372  // stack and change the font
373  else
374  {
375  if ( Push( rAttr, rAttr.GetAttr() ) )
376  // we let pItem change rFnt
377  FontChg( rAttr.GetAttr(), rFnt, true );
378  }
379 }
380 
381 const SwTextAttr* SwAttrHandler::GetTop(sal_uInt16 nStack)
382 {
383  return m_aAttrStack[nStack];
384 }
385 
386 bool SwAttrHandler::Push( const SwTextAttr& rAttr, const SfxPoolItem& rItem )
387 {
388  OSL_ENSURE( rItem.Which() < RES_TXTATR_WITHEND_END,
389  "I do not want this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
390 
391  // robust
392  if ( RES_TXTATR_WITHEND_END <= rItem.Which() )
393  return false;
394 
395  const sal_uInt16 nStack = StackPos[ rItem.Which() ];
396 
397  // attributes originating from redlining have highest priority
398  // second priority are hyperlink attributes, which have a color replacement
399  const SwTextAttr* pTopAttr = GetTop(nStack);
400  if ( !pTopAttr
401  || rAttr.IsPriorityAttr()
402  || ( !pTopAttr->IsPriorityAttr()
403  && !lcl_ChgHyperLinkColor(*pTopAttr, rItem, m_pShell, nullptr)))
404  {
405  m_aAttrStack[nStack] = &rAttr;
406  return true;
407  }
408 
409  return false;
410 }
411 
412 void SwAttrHandler::RemoveFromStack(sal_uInt16 nWhich, const SwTextAttr& rAttr)
413 {
414  auto& rStack = m_aAttrStack[StackPos[nWhich]];
415  if (rStack == &rAttr)
416  rStack = nullptr;
417 }
418 
419 void SwAttrHandler::PopAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
420 {
421  if ( RES_TXTATR_WITHEND_END <= rAttr.Which() )
422  return; // robust
423 
424  // these special attributes in fact represent a collection of attributes
425  // they have to be removed from each stack they belong to
426  if ( RES_TXTATR_INETFMT == rAttr.Which() ||
427  RES_TXTATR_CHARFMT == rAttr.Which() ||
428  RES_TXTATR_AUTOFMT == rAttr.Which() )
429  {
430  const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
431  if ( !pSet ) return;
432 
433  for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
434  {
435  const SfxPoolItem* pItem;
436  bool bRet = SfxItemState::SET == pSet->GetItemState( i, RES_TXTATR_AUTOFMT != rAttr.Which(), &pItem );
437  if ( bRet )
438  {
439  // we remove rAttr from the appropriate stack
440  RemoveFromStack(i, rAttr);
441  // reset font according to attribute on top of stack
442  // or default value
443  ActivateTop( rFnt, i );
444  }
445  }
446  }
447  // this is the usual case, we have a basic attribute, remove it from the
448  // stack and reset the font
449  else
450  {
451  RemoveFromStack(rAttr.Which(), rAttr);
452  // reset font according to attribute on top of stack
453  // or default value
454  ActivateTop( rFnt, rAttr.Which() );
455  }
456 }
457 
459 void SwAttrHandler::Pop( const SwTextAttr& rAttr )
460 {
461  OSL_ENSURE( rAttr.Which() < RES_TXTATR_WITHEND_END,
462  "I do not have this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
463 
464  if ( rAttr.Which() < RES_TXTATR_WITHEND_END )
465  {
466  RemoveFromStack(rAttr.Which(), rAttr);
467  }
468 }
469 
470 void SwAttrHandler::ActivateTop( SwFont& rFnt, const sal_uInt16 nAttr )
471 {
472  OSL_ENSURE( nAttr < RES_TXTATR_WITHEND_END,
473  "I cannot activate this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
474 
475  const sal_uInt16 nStackPos = StackPos[ nAttr ];
476  const SwTextAttr* pTopAt = GetTop(nStackPos);
477  if ( pTopAt )
478  {
479  const SfxPoolItem* pItemNext(nullptr);
480 
481  // check if top attribute is collection of attributes
482  if ( RES_TXTATR_INETFMT == pTopAt->Which() ||
483  RES_TXTATR_CHARFMT == pTopAt->Which() ||
484  RES_TXTATR_AUTOFMT == pTopAt->Which() )
485  {
486  const SfxItemSet* pSet = CharFormat::GetItemSet( pTopAt->GetAttr() );
487  if (pSet)
488  pSet->GetItemState( nAttr, RES_TXTATR_AUTOFMT != pTopAt->Which(), &pItemNext );
489  }
490 
491  if (pItemNext)
492  {
493  Color aColor;
494  if (lcl_ChgHyperLinkColor(*pTopAt, *pItemNext, m_pShell, &aColor))
495  {
496  SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
497  FontChg( aItemNext, rFnt, false );
498  }
499  else
500  FontChg( *pItemNext, rFnt, false );
501  }
502  else
503  FontChg( pTopAt->GetAttr(), rFnt, false );
504  }
505 
506  // default value has to be set, we only have default values for char attribs
507  else if ( nStackPos < NUM_DEFAULT_VALUES )
508  FontChg( *m_pDefaultArray[ nStackPos ], rFnt, false );
509  else if ( RES_TXTATR_REFMARK == nAttr )
510  rFnt.GetRef()--;
511  else if ( RES_TXTATR_TOXMARK == nAttr )
512  rFnt.GetTox()--;
513  else if ( (RES_TXTATR_META == nAttr) || (RES_TXTATR_METAFIELD == nAttr) )
514  {
515  rFnt.GetMeta()--;
516  }
517  else if ( RES_TXTATR_CJK_RUBY == nAttr )
518  {
519  // ruby stack has no more attributes
520  // check, if a rotation attribute has to be applied
521  const sal_uInt16 nTwoLineStack = StackPos[ RES_CHRATR_TWO_LINES ];
522  bool bTwoLineAct = false;
523  const SwTextAttr* pTwoLineAttr = GetTop(nTwoLineStack);
524 
525  if ( pTwoLineAttr )
526  {
527  const auto& rTwoLineItem = CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES )->StaticWhichCast(RES_CHRATR_TWO_LINES);
528  bTwoLineAct = rTwoLineItem.GetValue();
529  }
530  else
531  bTwoLineAct = m_pDefaultArray[ nTwoLineStack ]->StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue();
532 
533  if ( bTwoLineAct )
534  return;
535 
536  // eventually, a rotate attribute has to be activated
537  const sal_uInt16 nRotateStack = StackPos[ RES_CHRATR_ROTATE ];
538  const SwTextAttr* pRotateAttr = GetTop(nRotateStack);
539 
540  if ( pRotateAttr )
541  {
542  const auto& rRotateItem = CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE )->StaticWhichCast(RES_CHRATR_ROTATE);
543  rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
544  }
545  else
546  rFnt.SetVertical( m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout );
547  }
548  else if ( RES_TXTATR_INPUTFIELD == nAttr )
549  rFnt.GetInputField()--;
550 }
551 
557 void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
558 {
559  switch ( rItem.Which() )
560  {
561  case RES_CHRATR_CASEMAP :
562  rFnt.SetCaseMap( rItem.StaticWhichCast(RES_CHRATR_CASEMAP).GetCaseMap() );
563  break;
564  case RES_CHRATR_COLOR :
565  rFnt.SetColor( rItem.StaticWhichCast(RES_CHRATR_COLOR).GetValue() );
566  break;
567  case RES_CHRATR_CONTOUR :
568  rFnt.SetOutline( rItem.StaticWhichCast(RES_CHRATR_CONTOUR).GetValue() );
569  break;
570  case RES_CHRATR_CROSSEDOUT :
571  rFnt.SetStrikeout( rItem.StaticWhichCast(RES_CHRATR_CROSSEDOUT).GetStrikeout() );
572  break;
573  case RES_CHRATR_ESCAPEMENT :
574  rFnt.SetEscapement( rItem.StaticWhichCast(RES_CHRATR_ESCAPEMENT).GetEsc() );
575  rFnt.SetProportion( rItem.StaticWhichCast(RES_CHRATR_ESCAPEMENT).GetProportionalHeight() );
576  break;
577  case RES_CHRATR_FONT :
578  {
579  auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_FONT);
580  rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::Latin );
581  rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::Latin );
582  rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::Latin );
583  rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::Latin );
584  rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::Latin );
585  break;
586  }
587  case RES_CHRATR_FONTSIZE :
588  rFnt.SetSize(Size(0, rItem.StaticWhichCast(RES_CHRATR_FONTSIZE).GetHeight() ), SwFontScript::Latin );
589  break;
590  case RES_CHRATR_KERNING :
591  rFnt.SetFixKerning( rItem.StaticWhichCast(RES_CHRATR_KERNING).GetValue() );
592  break;
593  case RES_CHRATR_LANGUAGE :
595  break;
596  case RES_CHRATR_POSTURE :
598  break;
599  case RES_CHRATR_SHADOWED :
600  rFnt.SetShadow( rItem.StaticWhichCast(RES_CHRATR_SHADOWED).GetValue() );
601  break;
602  case RES_CHRATR_UNDERLINE :
603  {
604  const sal_uInt16 nStackPos = StackPos[ RES_CHRATR_HIDDEN ];
605  const SwTextAttr* pTopAt = GetTop(nStackPos);
606 
607  const SfxPoolItem* pTmpItem = pTopAt ?
609  m_pDefaultArray[ nStackPos ];
610 
611  if ((m_pShell && !m_pShell->GetWin()) ||
612  (pTmpItem && !pTmpItem->StaticWhichCast(RES_CHRATR_HIDDEN).GetValue()) )
613  {
614  rFnt.SetUnderline( rItem.StaticWhichCast(RES_CHRATR_UNDERLINE).GetLineStyle() );
615  rFnt.SetUnderColor( rItem.StaticWhichCast(RES_CHRATR_UNDERLINE).GetColor() );
616  }
617  break;
618  }
619  case RES_CHRATR_BOX:
620  {
621  const SvxBoxItem& aBoxItem = rItem.StaticWhichCast(RES_CHRATR_BOX);
622  rFnt.SetTopBorder( aBoxItem.GetTop() );
623  rFnt.SetBottomBorder( aBoxItem.GetBottom() );
624  rFnt.SetRightBorder( aBoxItem.GetRight() );
625  rFnt.SetLeftBorder( aBoxItem.GetLeft() );
626  rFnt.SetTopBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::TOP) );
627  rFnt.SetBottomBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::BOTTOM) );
628  rFnt.SetRightBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::RIGHT) );
629  rFnt.SetLeftBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::LEFT) );
630  break;
631  }
632  case RES_CHRATR_SHADOW:
633  {
634  const SvxShadowItem& aShadowItem = rItem.StaticWhichCast(RES_CHRATR_SHADOW);
635  rFnt.SetShadowColor( aShadowItem.GetColor() );
636  rFnt.SetShadowWidth( aShadowItem.GetWidth() );
637  rFnt.SetShadowLocation( aShadowItem.GetLocation() );
638  break;
639  }
640  case RES_CHRATR_OVERLINE :
641  rFnt.SetOverline( rItem.StaticWhichCast(RES_CHRATR_OVERLINE).GetLineStyle() );
642  rFnt.SetOverColor( rItem.StaticWhichCast(RES_CHRATR_OVERLINE).GetColor() );
643  break;
644  case RES_CHRATR_WEIGHT :
646  break;
648  rFnt.SetWordLineMode( rItem.StaticWhichCast(RES_CHRATR_WORDLINEMODE).GetValue() );
649  break;
650  case RES_CHRATR_AUTOKERN :
651  if( rItem.StaticWhichCast(RES_CHRATR_AUTOKERN).GetValue() )
652  {
655  FontKerning::FontSpecific :
656  FontKerning::Asian );
657  }
658  else
659  rFnt.SetAutoKern( FontKerning::NONE );
660  break;
661  case RES_CHRATR_BACKGROUND :
662  rFnt.SetBackColor(rItem.StaticWhichCast(RES_CHRATR_BACKGROUND).GetColor());
663  break;
664  case RES_CHRATR_HIGHLIGHT :
665  rFnt.SetHighlightColor( rItem.StaticWhichCast(RES_CHRATR_HIGHLIGHT).GetColor() );
666  break;
667  case RES_CHRATR_CJK_FONT :
668  {
669  auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_CJK_FONT);
670  rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::CJK );
671  rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::CJK );
672  rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::CJK );
673  rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::CJK );
674  rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::CJK );
675  break;
676  }
679  break;
682  break;
685  break;
686  case RES_CHRATR_CJK_WEIGHT :
688  break;
689  case RES_CHRATR_CTL_FONT :
690  {
691  auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_CTL_FONT);
692  rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::CTL );
693  rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::CTL );
694  rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::CTL );
695  rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::CTL );
696  rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::CTL );
697  break;
698  }
701  break;
704  break;
707  break;
708  case RES_CHRATR_CTL_WEIGHT :
710  break;
712  rFnt.SetEmphasisMark( rItem.StaticWhichCast(RES_CHRATR_EMPHASIS_MARK).GetEmphasisMark() );
713  break;
714  case RES_CHRATR_SCALEW :
715  rFnt.SetPropWidth( rItem.StaticWhichCast(RES_CHRATR_SCALEW).GetValue() );
716  break;
717  case RES_CHRATR_RELIEF :
718  rFnt.SetRelief( rItem.StaticWhichCast(RES_CHRATR_RELIEF).GetValue() );
719  break;
720  case RES_CHRATR_HIDDEN :
721  if (m_pShell && m_pShell->GetWin())
722  {
723  if ( rItem.StaticWhichCast(RES_CHRATR_HIDDEN).GetValue() )
725  else
727  }
728  break;
729  case RES_CHRATR_ROTATE :
730  {
731  // rotate attribute is applied, when:
732  // 1. ruby stack is empty and
733  // 2. top of two line stack ( or default attribute )is an
734  // deactivated two line attribute
735  const bool bRuby =
736  nullptr != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ];
737 
738  if ( bRuby )
739  break;
740 
741  const sal_uInt16 nTwoLineStack = StackPos[ RES_CHRATR_TWO_LINES ];
742  bool bTwoLineAct = false;
743  const SwTextAttr* pTwoLineAttr = GetTop(nTwoLineStack);
744 
745  if ( pTwoLineAttr )
746  {
747  const auto& rTwoLineItem = CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES )->StaticWhichCast(RES_CHRATR_TWO_LINES);
748  bTwoLineAct = rTwoLineItem.GetValue();
749  }
750  else
751  bTwoLineAct = m_pDefaultArray[ nTwoLineStack ]->StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue();
752 
753  if ( !bTwoLineAct )
755 
756  break;
757  }
758  case RES_CHRATR_TWO_LINES :
759  {
760  bool bRuby = nullptr != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ];
761 
762  // two line is activated, if
763  // 1. no ruby attribute is set and
764  // 2. attribute is active
765  if ( !bRuby && rItem.StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue() )
766  {
767  rFnt.SetVertical( 0_deg10, m_bVertLayout );
768  break;
769  }
770 
771  // a deactivating two line attribute is on top of stack,
772  // check if rotate attribute has to be enabled
773  if ( bRuby )
774  break;
775 
776  const sal_uInt16 nRotateStack = StackPos[ RES_CHRATR_ROTATE ];
777  const SwTextAttr* pRotateAttr = GetTop(nRotateStack);
778 
779  if ( pRotateAttr )
780  {
781  const auto& rRotateItem = CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE )->StaticWhichCast(RES_CHRATR_ROTATE);
782  rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
783  }
784  else
785  rFnt.SetVertical(m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout);
786  break;
787  }
788  case RES_TXTATR_CJK_RUBY :
789  rFnt.SetVertical( 0_deg10, m_bVertLayout );
790  break;
791  case RES_TXTATR_REFMARK :
792  if ( bPush )
793  rFnt.GetRef()++;
794  else
795  rFnt.GetRef()--;
796  break;
797  case RES_TXTATR_TOXMARK :
798  if ( bPush )
799  rFnt.GetTox()++;
800  else
801  rFnt.GetTox()--;
802  break;
803  case RES_TXTATR_META:
805  if ( bPush )
806  rFnt.GetMeta()++;
807  else
808  rFnt.GetMeta()--;
809  break;
810  case RES_TXTATR_INPUTFIELD :
811  if ( bPush )
812  rFnt.GetInputField()++;
813  else
814  rFnt.GetInputField()--;
815  break;
816  }
817 }
818 
821  sal_uInt16& nAscent, sal_uInt16& nHeight ) const
822 {
823  OSL_ENSURE(m_oFnt, "No font available for GetDefaultAscentAndHeight");
824 
825  if (m_oFnt)
826  {
827  SwFont aFont( *m_oFnt );
828  nHeight = aFont.GetHeight( pShell, rOut );
829  nAscent = aFont.GetAscent( pShell, rOut );
830  }
831 }
832 
833 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetLeftBorderDist(const sal_uInt16 nLeftDist)
Definition: swfont.hxx:848
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:339
OutDevType GetOutDevType() const
constexpr TypedWhichId< SvxCrossedOutItem > RES_CHRATR_CROSSEDOUT(5)
SwCharFormat * GetCharFormat()
Definition: txtatr2.cxx:111
bool IsPagePreview() const
Definition: viewopt.hxx:635
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CTL_FONT(27)
constexpr TypedWhichId< SvxEscapementItem > RES_CHRATR_ESCAPEMENT(6)
void Pop(const SwTextAttr &rAttr)
Only used during redlining.
Definition: atrstck.cxx:459
static bool IsVisitedLinks()
Definition: viewopt.hxx:670
bool IsPriorityAttr() const
Definition: txatbase.hxx:101
void SetWordLineMode(const bool bWordLineMode)
Definition: swfont.hxx:668
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:476
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_METAFIELD(49)
void PopAndChg(const SwTextAttr &rAttr, SwFont &rFnt)
Definition: atrstck.cxx:419
std::string GetValue
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_META(48)
void FontChg(const SfxPoolItem &rItem, SwFont &rFnt, bool bPush)
When popping an attribute from the stack, the top more remaining attribute in the stack becomes valid...
Definition: atrstck.cxx:557
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
Extracts pool item of type nWhich from rAttr.
Definition: atrstck.cxx:156
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_LANGUAGE(10)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
static Color & GetLinksColor()
Definition: viewopt.cxx:421
void SetEmphasisMark(const FontEmphasisMark eValue)
Definition: swfont.hxx:682
sal_uInt16 GetDistance(SvxBoxItemLine nLine) const
constexpr TypedWhichId< SvxUnderlineItem > RES_CHRATR_UNDERLINE(14)
constexpr TypedWhichId< SvxAutoKernItem > RES_CHRATR_AUTOKERN(17)
bool IsVisited() const
Definition: txtinet.hxx:54
const SfxPoolItem * m_pDefaultArray[NUM_DEFAULT_VALUES]
Definition: atrhndl.hxx:42
constexpr TypedWhichId< SvxBoxItem > RES_CHRATR_BOX(40)
sal_uInt16 Which() const
Definition: txatbase.hxx:114
void SetOutline(const bool bOutline)
Definition: swfont.hxx:600
const editeng::SvxBorderLine * GetRight() const
void SetPropWidth(const sal_uInt16 nNew)
Definition: swfont.hxx:690
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CJK_POSTURE(25)
sal_uInt8 & GetRef()
Definition: swfont.hxx:249
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_FONT(7)
void SetBottomBorderDist(const sal_uInt16 nBottomDist)
Definition: swfont.hxx:834
void SetPitch(const FontPitch ePitch, const SwFontScript nWhich)
Definition: swfont.hxx:501
constexpr TypedWhichId< SvxTwoLinesItem > RES_CHRATR_TWO_LINES(34)
#define NUM_DEFAULT_VALUES
Definition: swfntcch.hxx:22
void SetColor(const Color &rColor)
Definition: swfont.hxx:411
constexpr TypedWhichId< SvxCaseMapItem > RES_CHRATR_CASEMAP(RES_CHRATR_BEGIN)
void SetShadow(const bool bShadow)
Definition: swfont.hxx:615
bool m_bVertLayoutLRBT
Definition: atrhndl.hxx:51
const SfxPoolItem * NextItem()
SvxShadowLocation GetLocation() const
bool m_bVertLayout
Definition: atrhndl.hxx:50
constexpr TypedWhichId< SvxShadowItem > RES_CHRATR_SHADOW(41)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CTL_LANGUAGE(29)
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
sal_uInt16 GetAscent(SwViewShell const *pSh, const OutputDevice &rOut)
Definition: swfont.hxx:323
static Color & GetVisitedLinksColor()
Definition: viewopt.cxx:426
constexpr TypedWhichId< SwFormatRuby > RES_TXTATR_CJK_RUBY(53)
void SetShadowColor(const Color &rColor)
Definition: swfont.hxx:920
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
void SetUnderline(const FontLineStyle eUnderline)
Definition: swfont.hxx:542
constexpr TypedWhichId< SvxCharReliefItem > RES_CHRATR_RELIEF(36)
void SetShadowLocation(const SvxShadowLocation aLocation)
Definition: swfont.hxx:934
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
void SetStrikeout(const FontStrikeout eStrikeout)
Definition: swfont.hxx:572
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
void SetLeftBorder(const editeng::SvxBorderLine *pLeftBorder)
Definition: swfont.cxx:110
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_WEIGHT(15)
OUTDEV_PRINTER
const Color & GetColor() const
void SetStyleName(const OUString &rStyleName, const SwFontScript nWhich)
Definition: swfont.hxx:474
const editeng::SvxBorderLine * GetTop() const
void SetLanguage(LanguageType eNewLang, const SwFontScript nWhich)
Definition: swfont.hxx:804
void Reset()
Definition: atrstck.cxx:331
void Init(const SwAttrSet &rAttrSet, const IDocumentSettingAccess &rIDocumentSettingAccess)
Definition: atrstck.cxx:277
void SetRightBorder(const editeng::SvxBorderLine *pRightBorder)
Definition: swfont.cxx:97
const editeng::SvxBorderLine * GetLeft() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void SetVisited(bool bNew)
Definition: txtinet.hxx:55
int i
T & StaticWhichCast(TypedWhichId< T > nId)
void SetUnderColor(const Color &rColor)
Definition: swfont.hxx:214
void SetRightBorderDist(const sal_uInt16 nRightDist)
Definition: swfont.hxx:841
void SetShadowWidth(const sal_uInt16 nWidth)
Definition: swfont.hxx:927
void SetCaseMap(const SvxCaseMap eNew)
Definition: swfont.hxx:654
constexpr sal_uInt16 RES_TXTATR_WITHEND_END(56)
const SwTextAttr * m_aAttrStack[NUM_ATTRIBUTE_STACKS]
Definition: atrhndl.hxx:41
void SetVertical(Degree10 nDir, const bool bVertLayout=false, const bool bVertLayoutLRBT=false)
Definition: swfont.cxx:417
sal_uInt16 Count() const
constexpr TypedWhichId< SvxShadowedItem > RES_CHRATR_SHADOWED(13)
void SetRelief(const FontRelief eNew)
Definition: swfont.hxx:708
const IDocumentSettingAccess * m_pIDocumentSettingAccess
Definition: atrhndl.hxx:43
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
Returns the item set associated with a character/inet/auto style.
Definition: atrstck.cxx:132
void SetEscapement(const short nNewEsc)
Definition: swfont.hxx:781
Provides access to settings of a document.
void RemoveFromStack(sal_uInt16 nWhich, const SwTextAttr &rAttr)
Definition: atrstck.cxx:412
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:388
void SetWeight(const FontWeight eWeight, const SwFontScript nWhich)
Definition: swfont.hxx:529
void GetDefaultAscentAndHeight(SwViewShell const *pShell, OutputDevice const &rOut, sal_uInt16 &nAscent, sal_uInt16 &nHeight) const
Takes the default font and calculated the ascent and height.
Definition: atrstck.cxx:820
bool IsPDFExport() const
Definition: viewopt.hxx:417
Shell * m_pShell
bool Push(const SwTextAttr &rAttr, const SfxPoolItem &rItem)
Definition: atrstck.cxx:386
constexpr TypedWhichId< SvxOverlineItem > RES_CHRATR_OVERLINE(38)
constexpr TypedWhichId< SvxEmphasisMarkItem > RES_CHRATR_EMPHASIS_MARK(33)
sal_uInt8 & GetMeta()
Definition: swfont.hxx:251
Represents the style of a text portion.
Definition: charfmt.hxx:26
void SetOverColor(const Color &rColor)
Definition: swfont.hxx:216
const SwTextAttr * GetTop(sal_uInt16 nStack)
Definition: atrstck.cxx:381
void SetFixKerning(const short nNewKern)
Definition: swfont.hxx:647
constexpr TypedWhichId< SvxCharScaleWidthItem > RES_CHRATR_SCALEW(35)
constexpr TypedWhichId< SvxCharHiddenItem > RES_CHRATR_HIDDEN(37)
std::optional< SwFont > m_oFnt
Definition: atrhndl.hxx:48
void SetBottomBorder(const editeng::SvxBorderLine *pBottomBorder)
Definition: swfont.cxx:84
constexpr TypedWhichId< SvxColorItem > RES_CHRATR_COLOR(3)
constexpr TypedWhichId< SvxBrushItem > RES_CHRATR_BACKGROUND(21)
static bool IsLinks()
Definition: viewopt.hxx:669
const sal_uInt8 StackPos[RES_TXTATR_WITHEND_END-RES_CHRATR_BEGIN+1]
Attribute to Stack Mapping.
Definition: atrstck.cxx:68
const SwViewShell * m_pShell
Definition: atrhndl.hxx:44
constexpr sal_uInt16 RES_CHRATR_BEGIN(HINT_BEGIN)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
sal_uInt8 & GetInputField()
Definition: swfont.hxx:253
sal_uInt8 & GetTox()
Definition: swfont.hxx:247
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void SetBackColor(std::optional< Color > xNewColor)
Definition: swfont.cxx:64
void SetSize(const Size &rSize, const SwFontScript nWhich)
Definition: swfont.hxx:734
unsigned char sal_uInt8
constexpr TypedWhichId< SvxWordLineModeItem > RES_CHRATR_WORDLINEMODE(16)
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:424
vcl::Window * GetWin() const
Definition: viewsh.hxx:338
LINESTYLE_DOTTED
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CTL_WEIGHT(31)
void SetTopBorder(const editeng::SvxBorderLine *pTopBorder)
Definition: swfont.cxx:71
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CTL_POSTURE(30)
void SetFamily(const FontFamily eFamily, const SwFontScript nWhich)
Definition: swfont.hxx:448
void SetCharSet(const rtl_TextEncoding eCharSet, const SwFontScript nWhich)
Definition: swfont.hxx:487
constexpr TypedWhichId< SwTOXMark > RES_TXTATR_TOXMARK(47)
void ActivateTop(SwFont &rFnt, sal_uInt16 nStackPos)
Definition: atrstck.cxx:470
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
constexpr sal_uInt16 RES_CHRATR_END(46)
void SetName(const OUString &rName, const SwFontScript nWhich)
Definition: swfont.hxx:461
void PushAndChg(const SwTextAttr &rAttr, SwFont &rFnt)
Definition: atrstck.cxx:337
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:163
bool IsItemIncluded(const sal_uInt16 nWhich, const SwTextAttr *pAttr)
Checks if item is included in character/inet/auto style.
Definition: atrstck.cxx:176
void SetAutoKern(FontKerning nAutoKern)
Definition: swfont.hxx:630
constexpr TypedWhichId< SvxCharRotateItem > RES_CHRATR_ROTATE(32)
void SetItalic(const FontItalic eItalic, const SwFontScript nWhich)
Definition: swfont.hxx:587
constexpr TypedWhichId< SwFormatRefMark > RES_TXTATR_REFMARK(RES_TXTATR_WITHEND_BEGIN)
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:120
void SetProportion(const sal_uInt8 nNewPropr)
Definition: swfont.hxx:762
void SetHighlightColor(const Color &aNewColor)
Definition: swfont.hxx:941
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CTL_FONTSIZE(28)
static bool lcl_ChgHyperLinkColor(const SwTextAttr &rAttr, const SfxPoolItem &rItem, const SwViewShell *pShell, Color *pColor)
The color of hyperlinks is taken from the associated character attribute, depending on its 'visited' ...
Definition: atrstck.cxx:195
constexpr TypedWhichId< SvxBrushItem > RES_CHRATR_HIGHLIGHT(42)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
constexpr TypedWhichId< SvxKerningItem > RES_CHRATR_KERNING(9)
void SetOverline(const FontLineStyle eOverline)
Definition: swfont.hxx:557
const editeng::SvxBorderLine * GetBottom() const
tools::Long GetHeight() const
Definition: swfont.hxx:280
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
sal_uInt16 Which() const
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CJK_LANGUAGE(24)
void SetTopBorderDist(const sal_uInt16 nTopDist)
Definition: swfont.hxx:827
const SfxPoolItem * GetCurItem() const
sal_uInt16 GetWidth() const
constexpr TypedWhichId< SvxContourItem > RES_CHRATR_CONTOUR(4)