Revert "tdf#162268: Import - add zero width space after line break"
[LibreOffice.git] / sw / source / core / text / atrstck.cxx
blob85689a2c82a86713dfcc7cd04679b6e0fdad236a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "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>
26 #include <editeng/crossedoutitem.hxx>
27 #include <editeng/escapementitem.hxx>
28 #include <editeng/fontitem.hxx>
29 #include <editeng/fhgtitem.hxx>
30 #include <editeng/kernitem.hxx>
31 #include <editeng/charreliefitem.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>
39 #include <editeng/charrotateitem.hxx>
40 #include <editeng/emphasismarkitem.hxx>
41 #include <editeng/charscaleitem.hxx>
42 #include <editeng/twolinesitem.hxx>
43 #include <editeng/charhiddenitem.hxx>
44 #include <editeng/boxitem.hxx>
45 #include <editeng/nhypitem.hxx>
46 #include <editeng/shaditem.hxx>
47 #include <viewopt.hxx>
48 #include <charfmt.hxx>
49 #include <fchrfmt.hxx>
50 #include <fmtautofmt.hxx>
51 #include <editeng/brushitem.hxx>
52 #include <fmtinfmt.hxx>
53 #include <txtinet.hxx>
54 #include <IDocumentSettingAccess.hxx>
55 #include <viewsh.hxx>
57 /**
58 * Attribute to Stack Mapping
60 * Attributes applied to a text are pushed on different stacks. For each
61 * stack, the top most attribute on the stack is valid. Because some
62 * kinds of attributes have to be pushed to the same stacks we map their
63 * ids to stack ids
64 * Attention: The first NUM_DEFAULT_VALUES ( defined in swfntcch.hxx )
65 * are stored in the defaultitem-cache, if you add one, you have to increase
66 * NUM_DEFAULT_VALUES.
67 * Also adjust NUM_ATTRIBUTE_STACKS in atrhndl.hxx.
69 const sal_uInt8 StackPos[ RES_TXTATR_WITHEND_END - RES_CHRATR_BEGIN + 1 ] =
71 0, // // 0
72 1, // RES_CHRATR_CASEMAP = RES_CHRATR_BEGIN // 1
73 0, // RES_CHRATR_CHARSETCOLOR, // 2
74 2, // RES_CHRATR_COLOR, // 3
75 3, // RES_CHRATR_CONTOUR, // 4
76 4, // RES_CHRATR_CROSSEDOUT, // 5
77 5, // RES_CHRATR_ESCAPEMENT, // 6
78 6, // RES_CHRATR_FONT, // 7
79 7, // RES_CHRATR_FONTSIZE, // 8
80 8, // RES_CHRATR_KERNING, // 9
81 9, // RES_CHRATR_LANGUAGE, // 10
82 10, // RES_CHRATR_POSTURE, // 11
83 0, // RES_CHRATR_UNUSED1, // 12
84 11, // RES_CHRATR_SHADOWED, // 13
85 12, // RES_CHRATR_UNDERLINE, // 14
86 13, // RES_CHRATR_WEIGHT, // 15
87 14, // RES_CHRATR_WORDLINEMODE, // 16
88 15, // RES_CHRATR_AUTOKERN, // 17
89 16, // RES_CHRATR_BLINK, // 18
90 17, // RES_CHRATR_NOHYPHEN, // 19
91 0, // RES_CHRATR_UNUSED2, // 20
92 18, // RES_CHRATR_BACKGROUND, // 21
93 19, // RES_CHRATR_CJK_FONT, // 22
94 20, // RES_CHRATR_CJK_FONTSIZE, // 23
95 21, // RES_CHRATR_CJK_LANGUAGE, // 24
96 22, // RES_CHRATR_CJK_POSTURE, // 25
97 23, // RES_CHRATR_CJK_WEIGHT, // 26
98 24, // RES_CHRATR_CTL_FONT, // 27
99 25, // RES_CHRATR_CTL_FONTSIZE, // 28
100 26, // RES_CHRATR_CTL_LANGUAGE, // 29
101 27, // RES_CHRATR_CTL_POSTURE, // 30
102 28, // RES_CHRATR_CTL_WEIGHT, // 31
103 29, // RES_CHRATR_ROTATE, // 32
104 30, // RES_CHRATR_EMPHASIS_MARK, // 33
105 31, // RES_CHRATR_TWO_LINES, // 34
106 32, // RES_CHRATR_SCALEW, // 35
107 33, // RES_CHRATR_RELIEF, // 36
108 34, // RES_CHRATR_HIDDEN, // 37
109 35, // RES_CHRATR_OVERLINE, // 38
110 0, // RES_CHRATR_RSID, // 39
111 36, // RES_CHRATR_BOX, // 40
112 37, // RES_CHRATR_SHADOW, // 41
113 38, // RES_CHRATR_HIGHLIGHT, // 42
114 0, // RES_CHRATR_GRABBAG, // 43
115 0, // RES_CHRATR_BIDIRTL, // 44
116 0, // RES_CHRATR_IDCTHINT, // 45
117 39, // RES_TXTATR_REFMARK, // 46
118 40, // RES_TXTATR_TOXMARK, // 47
119 41, // RES_TXTATR_META, // 48
120 41, // RES_TXTATR_METAFIELD, // 49
121 0, // RES_TXTATR_AUTOFMT, // 50
122 0, // RES_TXTATR_INETFMT // 51
123 0, // RES_TXTATR_CHARFMT, // 52
124 42, // RES_TXTATR_CJK_RUBY, // 53
125 0, // RES_TXTATR_UNKNOWN_CONTAINER, // 54
126 43, // RES_TXTATR_INPUTFIELD // 55
127 44, // RES_TXTATR_CONTENTCONTROL // 56
130 namespace CharFormat
133 /// Returns the item set associated with a character/inet/auto style
134 const SfxItemSet* GetItemSet( const SfxPoolItem& rAttr )
136 const SfxItemSet* pSet = nullptr;
138 if ( RES_TXTATR_AUTOFMT == rAttr.Which() )
140 pSet = rAttr.StaticWhichCast(RES_TXTATR_AUTOFMT).GetStyleHandle().get();
142 else
144 // Get the attributes from the template
145 const SwCharFormat* pFormat = RES_TXTATR_INETFMT == rAttr.Which() ?
146 rAttr.StaticWhichCast(RES_TXTATR_INETFMT).GetTextINetFormat()->GetCharFormat() :
147 static_cast<const SwFormatCharFormat&>(rAttr).GetCharFormat();
148 if( pFormat )
150 pSet = &pFormat->GetAttrSet();
154 return pSet;
157 /// Extracts pool item of type nWhich from rAttr
158 const SfxPoolItem* GetItem( const SwTextAttr& rAttr, sal_uInt16 nWhich )
160 if ( RES_TXTATR_INETFMT == rAttr.Which() ||
161 RES_TXTATR_CHARFMT == rAttr.Which() ||
162 RES_TXTATR_AUTOFMT == rAttr.Which() )
164 const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
165 if ( !pSet ) return nullptr;
167 bool bInParent = RES_TXTATR_AUTOFMT != rAttr.Which();
168 const SfxPoolItem* pItem;
169 bool bRet = SfxItemState::SET == pSet->GetItemState( nWhich, bInParent, &pItem );
171 return bRet ? pItem : nullptr;
174 return ( nWhich == rAttr.Which() ) ? &rAttr.GetAttr() : nullptr;
177 /// Checks if item is included in character/inet/auto style
178 bool IsItemIncluded( const sal_uInt16 nWhich, const SwTextAttr *pAttr )
180 bool bRet = false;
182 const SfxItemSet* pItemSet = CharFormat::GetItemSet( pAttr->GetAttr() );
183 if ( pItemSet )
184 bRet = SfxItemState::SET == pItemSet->GetItemState( nWhich );
186 return bRet;
191 * The color of hyperlinks is taken from the associated character attribute,
192 * depending on its 'visited' state. There are actually two cases, which
193 * should override the colors from the character attribute:
194 * 1. We never take the 'visited' color during printing/pdf export/preview
195 * 2. The user has chosen to override these colors in the view options
197 static bool lcl_ChgHyperLinkColor( const SwTextAttr& rAttr,
198 const SfxPoolItem& rItem,
199 const SwViewShell* pShell,
200 Color* pColor )
202 if ( !pShell ||
203 RES_TXTATR_INETFMT != rAttr.Which() ||
204 RES_CHRATR_COLOR != rItem.Which() )
205 return false;
207 // #i15455#
208 // 1. case:
209 // We do not want to show visited links:
210 // (printing, pdf export, page preview)
212 SwTextINetFormat & rINetAttr(const_cast<SwTextINetFormat&>(
213 static_txtattr_cast<SwTextINetFormat const&>(rAttr)));
214 if ( pShell->GetOut()->GetOutDevType() == OUTDEV_PRINTER ||
215 pShell->GetViewOptions()->IsPDFExport() ||
216 pShell->GetViewOptions()->IsPagePreview() )
218 if (rINetAttr.IsVisited())
220 if ( pColor )
222 // take color from character format 'unvisited link'
223 rINetAttr.SetVisited(false);
224 const SwCharFormat* pTmpFormat = rINetAttr.GetCharFormat();
225 if (const SvxColorItem* pItem = pTmpFormat->GetItemIfSet(RES_CHRATR_COLOR))
226 *pColor = pItem->GetValue();
227 rINetAttr.SetVisited(true);
229 return true;
232 return false;
235 // 2. case:
236 // We do not want to apply the color set in the hyperlink
237 // attribute, instead we take the colors from the view options:
239 if ( pShell->GetWin() &&
241 (rINetAttr.IsVisited() && pShell->GetViewOptions()->IsVisitedLinks()) ||
242 (!rINetAttr.IsVisited() && pShell->GetViewOptions()->IsLinks())
246 if ( pColor )
248 if (rINetAttr.IsVisited())
250 // take color from view option 'visited link color'
251 *pColor = pShell->GetViewOptions()->GetVisitedLinksColor();
253 else
255 // take color from view option 'unvisited link color'
256 *pColor = pShell->GetViewOptions()->GetLinksColor();
259 return true;
262 return false;
265 SwAttrHandler::SwAttrHandler()
266 : m_pIDocumentSettingAccess(nullptr)
267 , m_pShell(nullptr)
268 , m_bVertLayout(false)
269 , m_bVertLayoutLRBT(false)
271 memset( m_pDefaultArray, 0, NUM_DEFAULT_VALUES * sizeof(SfxPoolItem*) );
274 SwAttrHandler::~SwAttrHandler()
278 void SwAttrHandler::Init( const SwAttrSet& rAttrSet,
279 const IDocumentSettingAccess& rIDocumentSettingAcces )
281 m_pIDocumentSettingAccess = &rIDocumentSettingAcces;
282 m_pShell = nullptr;
284 for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++ )
285 m_pDefaultArray[ StackPos[ i ] ] = &rAttrSet.Get( i );
288 void SwAttrHandler::Init( const SfxPoolItem** pPoolItem, const SwAttrSet* pAS,
289 const IDocumentSettingAccess& rIDocumentSettingAcces,
290 const SwViewShell* pSh,
291 SwFont& rFnt, bool bVL, bool bVertLayoutLRBT )
293 // initialize default array
294 memcpy( m_pDefaultArray, pPoolItem,
295 NUM_DEFAULT_VALUES * sizeof(SfxPoolItem*) );
297 m_pIDocumentSettingAccess = &rIDocumentSettingAcces;
298 m_pShell = pSh;
300 // do we have to apply additional paragraph attributes?
301 m_bVertLayout = bVL;
302 m_bVertLayoutLRBT = bVertLayoutLRBT;
304 if ( pAS && pAS->Count() )
306 SfxItemIter aIter( *pAS );
307 sal_uInt16 nWhich;
308 const SfxPoolItem* pItem = aIter.GetCurItem();
311 nWhich = pItem->Which();
312 if (isCHRATR(nWhich))
314 m_pDefaultArray[ StackPos[ nWhich ] ] = pItem;
315 FontChg( *pItem, rFnt, true );
318 pItem = aIter.NextItem();
319 } while (pItem);
322 // It is possible, that Init is called more than once, e.g., in a
323 // SwTextFrame::FormatOnceMore situation or (since sw_redlinehide)
324 // from SwAttrIter::Seek(); in the latter case SwTextSizeInfo::m_pFnt
325 // is an alias of m_pFnt so it must not be deleted!
326 if (m_oFnt)
327 *m_oFnt = rFnt;
328 else
329 m_oFnt.emplace(rFnt);
332 void SwAttrHandler::Reset( )
334 for (auto& i : m_aAttrStack)
335 i.clear();
338 void SwAttrHandler::PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
340 // these special attributes in fact represent a collection of attributes
341 // they have to be pushed to each stack they belong to
342 if ( RES_TXTATR_INETFMT == rAttr.Which() ||
343 RES_TXTATR_CHARFMT == rAttr.Which() ||
344 RES_TXTATR_AUTOFMT == rAttr.Which() )
346 const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
347 if ( !pSet ) return;
349 for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
351 const SfxPoolItem* pItem;
352 bool bRet = SfxItemState::SET == pSet->GetItemState( i, rAttr.Which() != RES_TXTATR_AUTOFMT, &pItem );
354 if ( bRet )
356 // we push rAttr onto the appropriate stack
357 if ( Push( rAttr, *pItem ) )
359 // we let pItem change rFnt
360 Color aColor;
361 if (lcl_ChgHyperLinkColor(rAttr, *pItem, m_pShell, &aColor))
363 SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
364 FontChg( aItemNext, rFnt, true );
366 else
367 FontChg( *pItem, rFnt, true );
372 if (rAttr.Which() == RES_TXTATR_INETFMT)
374 if (m_nINETFMT == 0)
375 rFnt.SetURL(true);
376 ++m_nINETFMT;
379 // this is the usual case, we have a basic attribute, push it onto the
380 // stack and change the font
381 else
383 if ( Push( rAttr, rAttr.GetAttr() ) )
384 // we let pItem change rFnt
385 FontChg( rAttr.GetAttr(), rFnt, true );
389 const SwTextAttr* SwAttrHandler::GetTop(sal_uInt16 nStack)
391 return m_aAttrStack[nStack].empty() ? nullptr : m_aAttrStack[nStack].back();
394 bool SwAttrHandler::Push( const SwTextAttr& rAttr, const SfxPoolItem& rItem )
396 OSL_ENSURE( rItem.Which() < RES_TXTATR_WITHEND_END,
397 "I do not want this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
399 // robust
400 if ( RES_TXTATR_WITHEND_END <= rItem.Which() )
401 return false;
403 const sal_uInt16 nStack = StackPos[ rItem.Which() ];
405 // attributes originating from redlining have highest priority
406 // second priority are hyperlink attributes, which have a color replacement
407 const SwTextAttr* pTopAttr = GetTop(nStack);
408 if ( !pTopAttr
409 || rAttr.IsPriorityAttr()
410 || ( !pTopAttr->IsPriorityAttr()
411 && !lcl_ChgHyperLinkColor(*pTopAttr, rItem, m_pShell, nullptr)))
413 m_aAttrStack[nStack].push_back(&rAttr);
414 return true;
417 const auto it = m_aAttrStack[nStack].end() - 1;
418 m_aAttrStack[nStack].insert(it, &rAttr);
419 return false;
422 void SwAttrHandler::RemoveFromStack(sal_uInt16 nWhich, const SwTextAttr& rAttr)
424 auto& rStack = m_aAttrStack[StackPos[nWhich]];
425 const auto it = std::find(rStack.begin(), rStack.end(), &rAttr);
426 if (it != rStack.end())
427 rStack.erase(it);
430 void SwAttrHandler::PopAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
432 if ( RES_TXTATR_WITHEND_END <= rAttr.Which() )
433 return; // robust
435 // these special attributes in fact represent a collection of attributes
436 // they have to be removed from each stack they belong to
437 if ( RES_TXTATR_INETFMT == rAttr.Which() ||
438 RES_TXTATR_CHARFMT == rAttr.Which() ||
439 RES_TXTATR_AUTOFMT == rAttr.Which() )
441 const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
442 if ( !pSet ) return;
444 if (rAttr.Which() == RES_TXTATR_INETFMT)
446 assert(m_nINETFMT > 0);
447 --m_nINETFMT;
448 if (m_nINETFMT == 0)
449 rFnt.SetURL(false);
452 for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
454 const SfxPoolItem* pItem;
455 bool bRet = SfxItemState::SET == pSet->GetItemState( i, RES_TXTATR_AUTOFMT != rAttr.Which(), &pItem );
456 if ( bRet )
458 // we remove rAttr from the appropriate stack
459 RemoveFromStack(i, rAttr);
460 // reset font according to attribute on top of stack
461 // or default value
462 ActivateTop( rFnt, i );
466 // this is the usual case, we have a basic attribute, remove it from the
467 // stack and reset the font
468 else
470 RemoveFromStack(rAttr.Which(), rAttr);
471 // reset font according to attribute on top of stack
472 // or default value
473 ActivateTop( rFnt, rAttr.Which() );
477 /// Only used during redlining
478 void SwAttrHandler::Pop( const SwTextAttr& rAttr )
480 OSL_ENSURE( rAttr.Which() < RES_TXTATR_WITHEND_END,
481 "I do not have this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
483 if ( rAttr.Which() < RES_TXTATR_WITHEND_END )
485 RemoveFromStack(rAttr.Which(), rAttr);
489 void SwAttrHandler::ActivateTop( SwFont& rFnt, const sal_uInt16 nAttr )
491 assert(nAttr < RES_TXTATR_WITHEND_END);
493 const sal_uInt16 nStackPos = StackPos[ nAttr ];
494 const SwTextAttr* pTopAt = GetTop(nStackPos);
495 if ( pTopAt )
497 const SfxPoolItem* pItemNext(nullptr);
499 // check if top attribute is collection of attributes
500 if ( RES_TXTATR_INETFMT == pTopAt->Which() ||
501 RES_TXTATR_CHARFMT == pTopAt->Which() ||
502 RES_TXTATR_AUTOFMT == pTopAt->Which() )
504 const SfxItemSet* pSet = CharFormat::GetItemSet( pTopAt->GetAttr() );
505 if (pSet)
506 pSet->GetItemState( nAttr, RES_TXTATR_AUTOFMT != pTopAt->Which(), &pItemNext );
509 if (pItemNext)
511 Color aColor;
512 if (lcl_ChgHyperLinkColor(*pTopAt, *pItemNext, m_pShell, &aColor))
514 SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
515 FontChg( aItemNext, rFnt, false );
517 else
518 FontChg( *pItemNext, rFnt, false );
520 else
521 FontChg( pTopAt->GetAttr(), rFnt, false );
524 // default value has to be set, we only have default values for char attribs
525 else if ( nStackPos < NUM_DEFAULT_VALUES )
526 FontChg( *m_pDefaultArray[ nStackPos ], rFnt, false );
527 else if ( RES_TXTATR_REFMARK == nAttr )
528 rFnt.GetRef()--;
529 else if ( RES_TXTATR_TOXMARK == nAttr )
530 rFnt.GetTox()--;
531 else if ( (RES_TXTATR_META == nAttr) || (RES_TXTATR_METAFIELD == nAttr) )
533 rFnt.GetMeta()--;
535 else if (nAttr == RES_TXTATR_CONTENTCONTROL)
537 rFnt.GetContentControl()--;
539 else if ( RES_TXTATR_CJK_RUBY == nAttr )
541 // ruby stack has no more attributes
542 // check, if a rotation attribute has to be applied
543 const sal_uInt16 nTwoLineStack = StackPos[ RES_CHRATR_TWO_LINES ];
544 bool bTwoLineAct = false;
545 const SwTextAttr* pTwoLineAttr = GetTop(nTwoLineStack);
547 if ( pTwoLineAttr )
549 const auto& rTwoLineItem = *CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES );
550 bTwoLineAct = rTwoLineItem.GetValue();
552 else
553 bTwoLineAct = m_pDefaultArray[ nTwoLineStack ]->StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue();
555 if ( bTwoLineAct )
556 return;
558 // eventually, a rotate attribute has to be activated
559 const sal_uInt16 nRotateStack = StackPos[ RES_CHRATR_ROTATE ];
560 const SwTextAttr* pRotateAttr = GetTop(nRotateStack);
562 if ( pRotateAttr )
564 const auto& rRotateItem = *CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
565 rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
567 else
568 rFnt.SetVertical( m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout );
570 else if ( RES_TXTATR_INPUTFIELD == nAttr )
571 rFnt.GetInputField()--;
575 * When popping an attribute from the stack, the top more remaining
576 * attribute in the stack becomes valid. The following function change
577 * a font depending on the stack id.
579 void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
581 switch ( rItem.Which() )
583 case RES_CHRATR_CASEMAP :
584 rFnt.SetCaseMap( rItem.StaticWhichCast(RES_CHRATR_CASEMAP).GetCaseMap() );
585 break;
586 case RES_CHRATR_COLOR :
587 rFnt.SetColor( rItem.StaticWhichCast(RES_CHRATR_COLOR).GetValue() );
588 break;
589 case RES_CHRATR_CONTOUR :
590 rFnt.SetOutline( rItem.StaticWhichCast(RES_CHRATR_CONTOUR).GetValue() );
591 break;
592 case RES_CHRATR_CROSSEDOUT :
593 rFnt.SetStrikeout( rItem.StaticWhichCast(RES_CHRATR_CROSSEDOUT).GetStrikeout() );
594 break;
595 case RES_CHRATR_ESCAPEMENT :
596 rFnt.SetEscapement( rItem.StaticWhichCast(RES_CHRATR_ESCAPEMENT).GetEsc() );
597 rFnt.SetProportion( rItem.StaticWhichCast(RES_CHRATR_ESCAPEMENT).GetProportionalHeight() );
598 break;
599 case RES_CHRATR_FONT :
601 auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_FONT);
602 rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::Latin );
603 rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::Latin );
604 rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::Latin );
605 rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::Latin );
606 rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::Latin );
607 break;
609 case RES_CHRATR_FONTSIZE :
610 rFnt.SetSize(Size(0, rItem.StaticWhichCast(RES_CHRATR_FONTSIZE).GetHeight() ), SwFontScript::Latin );
611 break;
612 case RES_CHRATR_KERNING :
613 rFnt.SetFixKerning( rItem.StaticWhichCast(RES_CHRATR_KERNING).GetValue() );
614 break;
615 case RES_CHRATR_LANGUAGE :
616 rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_LANGUAGE).GetLanguage(), SwFontScript::Latin );
617 break;
618 case RES_CHRATR_POSTURE :
619 rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_POSTURE).GetPosture(), SwFontScript::Latin );
620 break;
621 case RES_CHRATR_SHADOWED :
622 rFnt.SetShadow( rItem.StaticWhichCast(RES_CHRATR_SHADOWED).GetValue() );
623 break;
624 case RES_CHRATR_UNDERLINE :
626 const sal_uInt16 nStackPos = StackPos[ RES_CHRATR_HIDDEN ];
627 const SwTextAttr* pTopAt = GetTop(nStackPos);
629 const SfxPoolItem* pTmpItem = pTopAt ?
630 CharFormat::GetItem( *pTopAt, RES_CHRATR_HIDDEN ) :
631 m_pDefaultArray[ nStackPos ];
633 const sal_uInt16 nStackPos2 = StackPos[ RES_CHRATR_NOHYPHEN ];
634 const SwTextAttr* pTopAt2 = GetTop(nStackPos2);
636 const SfxPoolItem* pTmpItem2 = pTopAt2 ?
637 CharFormat::GetItem( *pTopAt2, RES_CHRATR_NOHYPHEN ) :
638 m_pDefaultArray[ nStackPos2 ];
640 if ((m_pShell && !m_pShell->GetWin()) ||
641 (pTmpItem && !pTmpItem->StaticWhichCast(RES_CHRATR_HIDDEN).GetValue()) ||
642 (pTmpItem2 && !pTmpItem2->StaticWhichCast(RES_CHRATR_NOHYPHEN).GetValue()) )
644 rFnt.SetUnderline( rItem.StaticWhichCast(RES_CHRATR_UNDERLINE).GetLineStyle() );
645 rFnt.SetUnderColor( rItem.StaticWhichCast(RES_CHRATR_UNDERLINE).GetColor() );
647 break;
649 case RES_CHRATR_BOX:
651 const SvxBoxItem& aBoxItem = rItem.StaticWhichCast(RES_CHRATR_BOX);
652 rFnt.SetTopBorder( aBoxItem.GetTop() );
653 rFnt.SetBottomBorder( aBoxItem.GetBottom() );
654 rFnt.SetRightBorder( aBoxItem.GetRight() );
655 rFnt.SetLeftBorder( aBoxItem.GetLeft() );
656 rFnt.SetTopBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::TOP) );
657 rFnt.SetBottomBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::BOTTOM) );
658 rFnt.SetRightBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::RIGHT) );
659 rFnt.SetLeftBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::LEFT) );
660 break;
662 case RES_CHRATR_SHADOW:
664 const SvxShadowItem& aShadowItem = rItem.StaticWhichCast(RES_CHRATR_SHADOW);
665 rFnt.SetShadowColor( aShadowItem.GetColor() );
666 rFnt.SetShadowWidth( aShadowItem.GetWidth() );
667 rFnt.SetShadowLocation( aShadowItem.GetLocation() );
668 break;
670 case RES_CHRATR_OVERLINE :
671 rFnt.SetOverline( rItem.StaticWhichCast(RES_CHRATR_OVERLINE).GetLineStyle() );
672 rFnt.SetOverColor( rItem.StaticWhichCast(RES_CHRATR_OVERLINE).GetColor() );
673 break;
674 case RES_CHRATR_WEIGHT :
675 rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_WEIGHT).GetWeight(), SwFontScript::Latin );
676 break;
677 case RES_CHRATR_WORDLINEMODE :
678 rFnt.SetWordLineMode( rItem.StaticWhichCast(RES_CHRATR_WORDLINEMODE).GetValue() );
679 break;
680 case RES_CHRATR_AUTOKERN :
681 if( rItem.StaticWhichCast(RES_CHRATR_AUTOKERN).GetValue() )
683 rFnt.SetAutoKern( (!m_pIDocumentSettingAccess ||
684 !m_pIDocumentSettingAccess->get(DocumentSettingId::KERN_ASIAN_PUNCTUATION)) ?
685 FontKerning::FontSpecific :
686 FontKerning::Asian );
688 else
689 rFnt.SetAutoKern( FontKerning::NONE );
690 break;
691 case RES_CHRATR_BACKGROUND :
692 rFnt.SetBackColor(rItem.StaticWhichCast(RES_CHRATR_BACKGROUND).GetColor());
693 break;
694 case RES_CHRATR_HIGHLIGHT :
695 rFnt.SetHighlightColor( rItem.StaticWhichCast(RES_CHRATR_HIGHLIGHT).GetColor() );
696 break;
697 case RES_CHRATR_NOHYPHEN :
698 if ( m_pShell && m_pShell->GetWin() &&
699 m_pShell->GetViewOptions()->IsViewMetaChars() )
701 if ( rItem.StaticWhichCast(RES_CHRATR_NOHYPHEN).GetValue() )
703 rFnt.SetUnderline( LINESTYLE_DOTTED );
704 rFnt.SetUnderColor( COL_LIGHTGRAY );
706 else
707 ActivateTop( rFnt, RES_CHRATR_UNDERLINE );
709 break;
710 case RES_CHRATR_CJK_FONT :
712 auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_CJK_FONT);
713 rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::CJK );
714 rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::CJK );
715 rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::CJK );
716 rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::CJK );
717 rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::CJK );
718 break;
720 case RES_CHRATR_CJK_FONTSIZE :
721 rFnt.SetSize(Size( 0, rItem.StaticWhichCast(RES_CHRATR_CJK_FONTSIZE).GetHeight()), SwFontScript::CJK);
722 break;
723 case RES_CHRATR_CJK_LANGUAGE :
724 rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_CJK_LANGUAGE).GetLanguage(), SwFontScript::CJK );
725 break;
726 case RES_CHRATR_CJK_POSTURE :
727 rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_CJK_POSTURE).GetPosture(), SwFontScript::CJK );
728 break;
729 case RES_CHRATR_CJK_WEIGHT :
730 rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_CJK_WEIGHT).GetWeight(), SwFontScript::CJK );
731 break;
732 case RES_CHRATR_CTL_FONT :
734 auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_CTL_FONT);
735 rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::CTL );
736 rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::CTL );
737 rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::CTL );
738 rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::CTL );
739 rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::CTL );
740 break;
742 case RES_CHRATR_CTL_FONTSIZE :
743 rFnt.SetSize(Size(0, rItem.StaticWhichCast(RES_CHRATR_CTL_FONTSIZE).GetHeight() ), SwFontScript::CTL);
744 break;
745 case RES_CHRATR_CTL_LANGUAGE :
746 rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_CTL_LANGUAGE).GetLanguage(), SwFontScript::CTL );
747 break;
748 case RES_CHRATR_CTL_POSTURE :
749 rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_CTL_POSTURE).GetPosture(), SwFontScript::CTL );
750 break;
751 case RES_CHRATR_CTL_WEIGHT :
752 rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_CTL_WEIGHT).GetWeight(), SwFontScript::CTL );
753 break;
754 case RES_CHRATR_EMPHASIS_MARK :
755 rFnt.SetEmphasisMark( rItem.StaticWhichCast(RES_CHRATR_EMPHASIS_MARK).GetEmphasisMark() );
756 break;
757 case RES_CHRATR_SCALEW :
758 rFnt.SetPropWidth( rItem.StaticWhichCast(RES_CHRATR_SCALEW).GetValue() );
759 break;
760 case RES_CHRATR_RELIEF :
761 rFnt.SetRelief( rItem.StaticWhichCast(RES_CHRATR_RELIEF).GetValue() );
762 break;
763 case RES_CHRATR_HIDDEN :
764 if (m_pShell && m_pShell->GetWin())
766 if ( rItem.StaticWhichCast(RES_CHRATR_HIDDEN).GetValue() )
767 rFnt.SetUnderline( LINESTYLE_DOTTED );
768 else
769 ActivateTop( rFnt, RES_CHRATR_UNDERLINE );
771 break;
772 case RES_CHRATR_ROTATE :
774 // rotate attribute is applied, when:
775 // 1. ruby stack is empty and
776 // 2. top of two line stack ( or default attribute )is an
777 // deactivated two line attribute
778 const bool bRuby =
779 0 != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].size();
781 if ( bRuby )
782 break;
784 const sal_uInt16 nTwoLineStack = StackPos[ RES_CHRATR_TWO_LINES ];
785 bool bTwoLineAct = false;
786 const SwTextAttr* pTwoLineAttr = GetTop(nTwoLineStack);
788 if ( pTwoLineAttr )
790 const auto& rTwoLineItem = *CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES );
791 bTwoLineAct = rTwoLineItem.GetValue();
793 else
794 bTwoLineAct = m_pDefaultArray[ nTwoLineStack ]->StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue();
796 if ( !bTwoLineAct )
797 rFnt.SetVertical( rItem.StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout, m_bVertLayoutLRBT );
799 break;
801 case RES_CHRATR_TWO_LINES :
803 bool bRuby = 0 !=
804 m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].size();
806 // two line is activated, if
807 // 1. no ruby attribute is set and
808 // 2. attribute is active
809 if ( !bRuby && rItem.StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue() )
811 rFnt.SetVertical( 0_deg10, m_bVertLayout );
812 break;
815 // a deactivating two line attribute is on top of stack,
816 // check if rotate attribute has to be enabled
817 if ( bRuby )
818 break;
820 const sal_uInt16 nRotateStack = StackPos[ RES_CHRATR_ROTATE ];
821 const SwTextAttr* pRotateAttr = GetTop(nRotateStack);
823 if ( pRotateAttr )
825 const auto& rRotateItem = *CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
826 rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
828 else
829 rFnt.SetVertical(m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout);
830 break;
832 case RES_TXTATR_CJK_RUBY :
833 rFnt.SetVertical( 0_deg10, m_bVertLayout );
834 break;
835 case RES_TXTATR_REFMARK :
836 if ( bPush )
837 rFnt.GetRef()++;
838 else
839 rFnt.GetRef()--;
840 break;
841 case RES_TXTATR_TOXMARK :
842 if ( bPush )
843 rFnt.GetTox()++;
844 else
845 rFnt.GetTox()--;
846 break;
847 case RES_TXTATR_META:
848 case RES_TXTATR_METAFIELD:
849 if ( bPush )
850 rFnt.GetMeta()++;
851 else
852 rFnt.GetMeta()--;
853 break;
854 case RES_TXTATR_CONTENTCONTROL:
855 if (bPush)
857 rFnt.GetContentControl()++;
859 else
861 rFnt.GetContentControl()--;
863 break;
864 case RES_TXTATR_INPUTFIELD :
865 if ( bPush )
866 rFnt.GetInputField()++;
867 else
868 rFnt.GetInputField()--;
869 break;
873 /// Takes the default font and calculated the ascent and height
874 void SwAttrHandler::GetDefaultAscentAndHeight( SwViewShell const * pShell, OutputDevice const & rOut,
875 sal_uInt16& nAscent, sal_uInt16& nHeight ) const
877 OSL_ENSURE(m_oFnt, "No font available for GetDefaultAscentAndHeight");
879 if (m_oFnt)
881 SwFont aFont( *m_oFnt );
882 nHeight = aFont.GetHeight( pShell, rOut );
883 nAscent = aFont.GetAscent( pShell, rOut );
887 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */