android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / text / atrstck.cxx
blob048878292fc0920bebf5e0edcf9cd496128db4ac
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/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>
53 #include <IDocumentSettingAccess.hxx>
54 #include <viewsh.hxx>
56 /**
57 * Attribute to Stack Mapping
59 * Attributes applied to a text are pushed on different stacks. For each
60 * stack, the top most attribute on the stack is valid. Because some
61 * kinds of attributes have to be pushed to the same stacks we map their
62 * ids to stack ids
63 * Attention: The first NUM_DEFAULT_VALUES ( defined in swfntcch.hxx )
64 * are stored in the defaultitem-cache, if you add one, you have to increase
65 * NUM_DEFAULT_VALUES.
66 * Also adjust NUM_ATTRIBUTE_STACKS in atrhndl.hxx.
68 const sal_uInt8 StackPos[ RES_TXTATR_WITHEND_END - RES_CHRATR_BEGIN + 1 ] =
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 44, // RES_TXTATR_CONTENTCONTROL // 56
129 namespace CharFormat
132 /// Returns the item set associated with a character/inet/auto style
133 const SfxItemSet* GetItemSet( const SfxPoolItem& rAttr )
135 const SfxItemSet* pSet = nullptr;
137 if ( RES_TXTATR_AUTOFMT == rAttr.Which() )
139 pSet = rAttr.StaticWhichCast(RES_TXTATR_AUTOFMT).GetStyleHandle().get();
141 else
143 // Get the attributes from the template
144 const SwCharFormat* pFormat = RES_TXTATR_INETFMT == rAttr.Which() ?
145 rAttr.StaticWhichCast(RES_TXTATR_INETFMT).GetTextINetFormat()->GetCharFormat() :
146 static_cast<const SwFormatCharFormat&>(rAttr).GetCharFormat();
147 if( pFormat )
149 pSet = &pFormat->GetAttrSet();
153 return pSet;
156 /// Extracts pool item of type nWhich from rAttr
157 const SfxPoolItem* GetItem( const SwTextAttr& rAttr, sal_uInt16 nWhich )
159 if ( RES_TXTATR_INETFMT == rAttr.Which() ||
160 RES_TXTATR_CHARFMT == rAttr.Which() ||
161 RES_TXTATR_AUTOFMT == rAttr.Which() )
163 const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
164 if ( !pSet ) return nullptr;
166 bool bInParent = RES_TXTATR_AUTOFMT != rAttr.Which();
167 const SfxPoolItem* pItem;
168 bool bRet = SfxItemState::SET == pSet->GetItemState( nWhich, bInParent, &pItem );
170 return bRet ? pItem : nullptr;
173 return ( nWhich == rAttr.Which() ) ? &rAttr.GetAttr() : nullptr;
176 /// Checks if item is included in character/inet/auto style
177 bool IsItemIncluded( const sal_uInt16 nWhich, const SwTextAttr *pAttr )
179 bool bRet = false;
181 const SfxItemSet* pItemSet = CharFormat::GetItemSet( pAttr->GetAttr() );
182 if ( pItemSet )
183 bRet = SfxItemState::SET == pItemSet->GetItemState( nWhich );
185 return bRet;
190 * The color of hyperlinks is taken from the associated character attribute,
191 * depending on its 'visited' state. There are actually two cases, which
192 * should override the colors from the character attribute:
193 * 1. We never take the 'visited' color during printing/pdf export/preview
194 * 2. The user has chosen to override these colors in the view options
196 static bool lcl_ChgHyperLinkColor( const SwTextAttr& rAttr,
197 const SfxPoolItem& rItem,
198 const SwViewShell* pShell,
199 Color* pColor )
201 if ( !pShell ||
202 RES_TXTATR_INETFMT != rAttr.Which() ||
203 RES_CHRATR_COLOR != rItem.Which() )
204 return false;
206 // #i15455#
207 // 1. case:
208 // We do not want to show visited links:
209 // (printing, pdf export, page preview)
211 SwTextINetFormat & rINetAttr(const_cast<SwTextINetFormat&>(
212 static_txtattr_cast<SwTextINetFormat const&>(rAttr)));
213 if ( pShell->GetOut()->GetOutDevType() == OUTDEV_PRINTER ||
214 pShell->GetViewOptions()->IsPDFExport() ||
215 pShell->GetViewOptions()->IsPagePreview() )
217 if (rINetAttr.IsVisited())
219 if ( pColor )
221 // take color from character format 'unvisited link'
222 rINetAttr.SetVisited(false);
223 const SwCharFormat* pTmpFormat = rINetAttr.GetCharFormat();
224 if (const SvxColorItem* pItem = pTmpFormat->GetItemIfSet(RES_CHRATR_COLOR))
225 *pColor = pItem->GetValue();
226 rINetAttr.SetVisited(true);
228 return true;
231 return false;
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:
238 if ( pShell->GetWin() &&
240 (rINetAttr.IsVisited() && pShell->GetViewOptions()->IsVisitedLinks()) ||
241 (!rINetAttr.IsVisited() && pShell->GetViewOptions()->IsLinks())
245 if ( pColor )
247 if (rINetAttr.IsVisited())
249 // take color from view option 'visited link color'
250 *pColor = pShell->GetViewOptions()->GetVisitedLinksColor();
252 else
254 // take color from view option 'unvisited link color'
255 *pColor = pShell->GetViewOptions()->GetLinksColor();
258 return true;
261 return false;
264 SwAttrHandler::SwAttrHandler()
265 : m_pIDocumentSettingAccess(nullptr)
266 , m_pShell(nullptr)
267 , m_bVertLayout(false)
268 , m_bVertLayoutLRBT(false)
270 memset( m_pDefaultArray, 0, NUM_DEFAULT_VALUES * sizeof(SfxPoolItem*) );
273 SwAttrHandler::~SwAttrHandler()
277 void SwAttrHandler::Init( const SwAttrSet& rAttrSet,
278 const IDocumentSettingAccess& rIDocumentSettingAcces )
280 m_pIDocumentSettingAccess = &rIDocumentSettingAcces;
281 m_pShell = nullptr;
283 for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++ )
284 m_pDefaultArray[ StackPos[ i ] ] = &rAttrSet.Get( i );
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 )
292 // initialize default array
293 memcpy( m_pDefaultArray, pPoolItem,
294 NUM_DEFAULT_VALUES * sizeof(SfxPoolItem*) );
296 m_pIDocumentSettingAccess = &rIDocumentSettingAcces;
297 m_pShell = pSh;
299 // do we have to apply additional paragraph attributes?
300 m_bVertLayout = bVL;
301 m_bVertLayoutLRBT = bVertLayoutLRBT;
303 if ( pAS && pAS->Count() )
305 SfxItemIter aIter( *pAS );
306 sal_uInt16 nWhich;
307 const SfxPoolItem* pItem = aIter.GetCurItem();
310 nWhich = pItem->Which();
311 if (isCHRATR(nWhich))
313 m_pDefaultArray[ StackPos[ nWhich ] ] = pItem;
314 FontChg( *pItem, rFnt, true );
317 pItem = aIter.NextItem();
318 } while (pItem);
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);
331 void SwAttrHandler::Reset( )
333 for (auto& i : m_aAttrStack)
334 i.clear();
337 void SwAttrHandler::PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
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() )
345 const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
346 if ( !pSet ) return;
348 for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
350 const SfxPoolItem* pItem;
351 bool bRet = SfxItemState::SET == pSet->GetItemState( i, rAttr.Which() != RES_TXTATR_AUTOFMT, &pItem );
353 if ( bRet )
355 // we push rAttr onto the appropriate stack
356 if ( Push( rAttr, *pItem ) )
358 // we let pItem change rFnt
359 Color aColor;
360 if (lcl_ChgHyperLinkColor(rAttr, *pItem, m_pShell, &aColor))
362 SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
363 FontChg( aItemNext, rFnt, true );
365 else
366 FontChg( *pItem, rFnt, true );
371 // this is the usual case, we have a basic attribute, push it onto the
372 // stack and change the font
373 else
375 if ( Push( rAttr, rAttr.GetAttr() ) )
376 // we let pItem change rFnt
377 FontChg( rAttr.GetAttr(), rFnt, true );
381 const SwTextAttr* SwAttrHandler::GetTop(sal_uInt16 nStack)
383 return m_aAttrStack[nStack].empty() ? nullptr : m_aAttrStack[nStack].back();
386 bool SwAttrHandler::Push( const SwTextAttr& rAttr, const SfxPoolItem& rItem )
388 OSL_ENSURE( rItem.Which() < RES_TXTATR_WITHEND_END,
389 "I do not want this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
391 // robust
392 if ( RES_TXTATR_WITHEND_END <= rItem.Which() )
393 return false;
395 const sal_uInt16 nStack = StackPos[ rItem.Which() ];
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)))
405 m_aAttrStack[nStack].push_back(&rAttr);
406 return true;
409 const auto it = m_aAttrStack[nStack].end() - 1;
410 m_aAttrStack[nStack].insert(it, &rAttr);
411 return false;
414 void SwAttrHandler::RemoveFromStack(sal_uInt16 nWhich, const SwTextAttr& rAttr)
416 auto& rStack = m_aAttrStack[StackPos[nWhich]];
417 const auto it = std::find(rStack.begin(), rStack.end(), &rAttr);
418 if (it != rStack.end())
419 rStack.erase(it);
422 void SwAttrHandler::PopAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
424 if ( RES_TXTATR_WITHEND_END <= rAttr.Which() )
425 return; // robust
427 // these special attributes in fact represent a collection of attributes
428 // they have to be removed from each stack they belong to
429 if ( RES_TXTATR_INETFMT == rAttr.Which() ||
430 RES_TXTATR_CHARFMT == rAttr.Which() ||
431 RES_TXTATR_AUTOFMT == rAttr.Which() )
433 const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
434 if ( !pSet ) return;
436 for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
438 const SfxPoolItem* pItem;
439 bool bRet = SfxItemState::SET == pSet->GetItemState( i, RES_TXTATR_AUTOFMT != rAttr.Which(), &pItem );
440 if ( bRet )
442 // we remove rAttr from the appropriate stack
443 RemoveFromStack(i, rAttr);
444 // reset font according to attribute on top of stack
445 // or default value
446 ActivateTop( rFnt, i );
450 // this is the usual case, we have a basic attribute, remove it from the
451 // stack and reset the font
452 else
454 RemoveFromStack(rAttr.Which(), rAttr);
455 // reset font according to attribute on top of stack
456 // or default value
457 ActivateTop( rFnt, rAttr.Which() );
461 /// Only used during redlining
462 void SwAttrHandler::Pop( const SwTextAttr& rAttr )
464 OSL_ENSURE( rAttr.Which() < RES_TXTATR_WITHEND_END,
465 "I do not have this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
467 if ( rAttr.Which() < RES_TXTATR_WITHEND_END )
469 RemoveFromStack(rAttr.Which(), rAttr);
473 void SwAttrHandler::ActivateTop( SwFont& rFnt, const sal_uInt16 nAttr )
475 OSL_ENSURE( nAttr < RES_TXTATR_WITHEND_END,
476 "I cannot activate this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
478 const sal_uInt16 nStackPos = StackPos[ nAttr ];
479 const SwTextAttr* pTopAt = GetTop(nStackPos);
480 if ( pTopAt )
482 const SfxPoolItem* pItemNext(nullptr);
484 // check if top attribute is collection of attributes
485 if ( RES_TXTATR_INETFMT == pTopAt->Which() ||
486 RES_TXTATR_CHARFMT == pTopAt->Which() ||
487 RES_TXTATR_AUTOFMT == pTopAt->Which() )
489 const SfxItemSet* pSet = CharFormat::GetItemSet( pTopAt->GetAttr() );
490 if (pSet)
491 pSet->GetItemState( nAttr, RES_TXTATR_AUTOFMT != pTopAt->Which(), &pItemNext );
494 if (pItemNext)
496 Color aColor;
497 if (lcl_ChgHyperLinkColor(*pTopAt, *pItemNext, m_pShell, &aColor))
499 SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
500 FontChg( aItemNext, rFnt, false );
502 else
503 FontChg( *pItemNext, rFnt, false );
505 else
506 FontChg( pTopAt->GetAttr(), rFnt, false );
509 // default value has to be set, we only have default values for char attribs
510 else if ( nStackPos < NUM_DEFAULT_VALUES )
511 FontChg( *m_pDefaultArray[ nStackPos ], rFnt, false );
512 else if ( RES_TXTATR_REFMARK == nAttr )
513 rFnt.GetRef()--;
514 else if ( RES_TXTATR_TOXMARK == nAttr )
515 rFnt.GetTox()--;
516 else if ( (RES_TXTATR_META == nAttr) || (RES_TXTATR_METAFIELD == nAttr) )
518 rFnt.GetMeta()--;
520 else if (nAttr == RES_TXTATR_CONTENTCONTROL)
522 rFnt.GetContentControl()--;
524 else if ( RES_TXTATR_CJK_RUBY == nAttr )
526 // ruby stack has no more attributes
527 // check, if a rotation attribute has to be applied
528 const sal_uInt16 nTwoLineStack = StackPos[ RES_CHRATR_TWO_LINES ];
529 bool bTwoLineAct = false;
530 const SwTextAttr* pTwoLineAttr = GetTop(nTwoLineStack);
532 if ( pTwoLineAttr )
534 const auto& rTwoLineItem = *CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES );
535 bTwoLineAct = rTwoLineItem.GetValue();
537 else
538 bTwoLineAct = m_pDefaultArray[ nTwoLineStack ]->StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue();
540 if ( bTwoLineAct )
541 return;
543 // eventually, a rotate attribute has to be activated
544 const sal_uInt16 nRotateStack = StackPos[ RES_CHRATR_ROTATE ];
545 const SwTextAttr* pRotateAttr = GetTop(nRotateStack);
547 if ( pRotateAttr )
549 const auto& rRotateItem = *CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
550 rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
552 else
553 rFnt.SetVertical( m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout );
555 else if ( RES_TXTATR_INPUTFIELD == nAttr )
556 rFnt.GetInputField()--;
560 * When popping an attribute from the stack, the top more remaining
561 * attribute in the stack becomes valid. The following function change
562 * a font depending on the stack id.
564 void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
566 switch ( rItem.Which() )
568 case RES_CHRATR_CASEMAP :
569 rFnt.SetCaseMap( rItem.StaticWhichCast(RES_CHRATR_CASEMAP).GetCaseMap() );
570 break;
571 case RES_CHRATR_COLOR :
572 rFnt.SetColor( rItem.StaticWhichCast(RES_CHRATR_COLOR).GetValue() );
573 break;
574 case RES_CHRATR_CONTOUR :
575 rFnt.SetOutline( rItem.StaticWhichCast(RES_CHRATR_CONTOUR).GetValue() );
576 break;
577 case RES_CHRATR_CROSSEDOUT :
578 rFnt.SetStrikeout( rItem.StaticWhichCast(RES_CHRATR_CROSSEDOUT).GetStrikeout() );
579 break;
580 case RES_CHRATR_ESCAPEMENT :
581 rFnt.SetEscapement( rItem.StaticWhichCast(RES_CHRATR_ESCAPEMENT).GetEsc() );
582 rFnt.SetProportion( rItem.StaticWhichCast(RES_CHRATR_ESCAPEMENT).GetProportionalHeight() );
583 break;
584 case RES_CHRATR_FONT :
586 auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_FONT);
587 rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::Latin );
588 rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::Latin );
589 rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::Latin );
590 rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::Latin );
591 rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::Latin );
592 break;
594 case RES_CHRATR_FONTSIZE :
595 rFnt.SetSize(Size(0, rItem.StaticWhichCast(RES_CHRATR_FONTSIZE).GetHeight() ), SwFontScript::Latin );
596 break;
597 case RES_CHRATR_KERNING :
598 rFnt.SetFixKerning( rItem.StaticWhichCast(RES_CHRATR_KERNING).GetValue() );
599 break;
600 case RES_CHRATR_LANGUAGE :
601 rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_LANGUAGE).GetLanguage(), SwFontScript::Latin );
602 break;
603 case RES_CHRATR_POSTURE :
604 rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_POSTURE).GetPosture(), SwFontScript::Latin );
605 break;
606 case RES_CHRATR_SHADOWED :
607 rFnt.SetShadow( rItem.StaticWhichCast(RES_CHRATR_SHADOWED).GetValue() );
608 break;
609 case RES_CHRATR_UNDERLINE :
611 const sal_uInt16 nStackPos = StackPos[ RES_CHRATR_HIDDEN ];
612 const SwTextAttr* pTopAt = GetTop(nStackPos);
614 const SfxPoolItem* pTmpItem = pTopAt ?
615 CharFormat::GetItem( *pTopAt, RES_CHRATR_HIDDEN ) :
616 m_pDefaultArray[ nStackPos ];
618 if ((m_pShell && !m_pShell->GetWin()) ||
619 (pTmpItem && !pTmpItem->StaticWhichCast(RES_CHRATR_HIDDEN).GetValue()) )
621 rFnt.SetUnderline( rItem.StaticWhichCast(RES_CHRATR_UNDERLINE).GetLineStyle() );
622 rFnt.SetUnderColor( rItem.StaticWhichCast(RES_CHRATR_UNDERLINE).GetColor() );
624 break;
626 case RES_CHRATR_BOX:
628 const SvxBoxItem& aBoxItem = rItem.StaticWhichCast(RES_CHRATR_BOX);
629 rFnt.SetTopBorder( aBoxItem.GetTop() );
630 rFnt.SetBottomBorder( aBoxItem.GetBottom() );
631 rFnt.SetRightBorder( aBoxItem.GetRight() );
632 rFnt.SetLeftBorder( aBoxItem.GetLeft() );
633 rFnt.SetTopBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::TOP) );
634 rFnt.SetBottomBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::BOTTOM) );
635 rFnt.SetRightBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::RIGHT) );
636 rFnt.SetLeftBorderDist( aBoxItem.GetDistance(SvxBoxItemLine::LEFT) );
637 break;
639 case RES_CHRATR_SHADOW:
641 const SvxShadowItem& aShadowItem = rItem.StaticWhichCast(RES_CHRATR_SHADOW);
642 rFnt.SetShadowColor( aShadowItem.GetColor() );
643 rFnt.SetShadowWidth( aShadowItem.GetWidth() );
644 rFnt.SetShadowLocation( aShadowItem.GetLocation() );
645 break;
647 case RES_CHRATR_OVERLINE :
648 rFnt.SetOverline( rItem.StaticWhichCast(RES_CHRATR_OVERLINE).GetLineStyle() );
649 rFnt.SetOverColor( rItem.StaticWhichCast(RES_CHRATR_OVERLINE).GetColor() );
650 break;
651 case RES_CHRATR_WEIGHT :
652 rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_WEIGHT).GetWeight(), SwFontScript::Latin );
653 break;
654 case RES_CHRATR_WORDLINEMODE :
655 rFnt.SetWordLineMode( rItem.StaticWhichCast(RES_CHRATR_WORDLINEMODE).GetValue() );
656 break;
657 case RES_CHRATR_AUTOKERN :
658 if( rItem.StaticWhichCast(RES_CHRATR_AUTOKERN).GetValue() )
660 rFnt.SetAutoKern( (!m_pIDocumentSettingAccess ||
661 !m_pIDocumentSettingAccess->get(DocumentSettingId::KERN_ASIAN_PUNCTUATION)) ?
662 FontKerning::FontSpecific :
663 FontKerning::Asian );
665 else
666 rFnt.SetAutoKern( FontKerning::NONE );
667 break;
668 case RES_CHRATR_BACKGROUND :
669 rFnt.SetBackColor(rItem.StaticWhichCast(RES_CHRATR_BACKGROUND).GetColor());
670 break;
671 case RES_CHRATR_HIGHLIGHT :
672 rFnt.SetHighlightColor( rItem.StaticWhichCast(RES_CHRATR_HIGHLIGHT).GetColor() );
673 break;
674 case RES_CHRATR_CJK_FONT :
676 auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_CJK_FONT);
677 rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::CJK );
678 rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::CJK );
679 rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::CJK );
680 rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::CJK );
681 rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::CJK );
682 break;
684 case RES_CHRATR_CJK_FONTSIZE :
685 rFnt.SetSize(Size( 0, rItem.StaticWhichCast(RES_CHRATR_CJK_FONTSIZE).GetHeight()), SwFontScript::CJK);
686 break;
687 case RES_CHRATR_CJK_LANGUAGE :
688 rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_CJK_LANGUAGE).GetLanguage(), SwFontScript::CJK );
689 break;
690 case RES_CHRATR_CJK_POSTURE :
691 rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_CJK_POSTURE).GetPosture(), SwFontScript::CJK );
692 break;
693 case RES_CHRATR_CJK_WEIGHT :
694 rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_CJK_WEIGHT).GetWeight(), SwFontScript::CJK );
695 break;
696 case RES_CHRATR_CTL_FONT :
698 auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_CTL_FONT);
699 rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::CTL );
700 rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::CTL );
701 rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::CTL );
702 rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::CTL );
703 rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::CTL );
704 break;
706 case RES_CHRATR_CTL_FONTSIZE :
707 rFnt.SetSize(Size(0, rItem.StaticWhichCast(RES_CHRATR_CTL_FONTSIZE).GetHeight() ), SwFontScript::CTL);
708 break;
709 case RES_CHRATR_CTL_LANGUAGE :
710 rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_CTL_LANGUAGE).GetLanguage(), SwFontScript::CTL );
711 break;
712 case RES_CHRATR_CTL_POSTURE :
713 rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_CTL_POSTURE).GetPosture(), SwFontScript::CTL );
714 break;
715 case RES_CHRATR_CTL_WEIGHT :
716 rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_CTL_WEIGHT).GetWeight(), SwFontScript::CTL );
717 break;
718 case RES_CHRATR_EMPHASIS_MARK :
719 rFnt.SetEmphasisMark( rItem.StaticWhichCast(RES_CHRATR_EMPHASIS_MARK).GetEmphasisMark() );
720 break;
721 case RES_CHRATR_SCALEW :
722 rFnt.SetPropWidth( rItem.StaticWhichCast(RES_CHRATR_SCALEW).GetValue() );
723 break;
724 case RES_CHRATR_RELIEF :
725 rFnt.SetRelief( rItem.StaticWhichCast(RES_CHRATR_RELIEF).GetValue() );
726 break;
727 case RES_CHRATR_HIDDEN :
728 if (m_pShell && m_pShell->GetWin())
730 if ( rItem.StaticWhichCast(RES_CHRATR_HIDDEN).GetValue() )
731 rFnt.SetUnderline( LINESTYLE_DOTTED );
732 else
733 ActivateTop( rFnt, RES_CHRATR_UNDERLINE );
735 break;
736 case RES_CHRATR_ROTATE :
738 // rotate attribute is applied, when:
739 // 1. ruby stack is empty and
740 // 2. top of two line stack ( or default attribute )is an
741 // deactivated two line attribute
742 const bool bRuby =
743 0 != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].size();
745 if ( bRuby )
746 break;
748 const sal_uInt16 nTwoLineStack = StackPos[ RES_CHRATR_TWO_LINES ];
749 bool bTwoLineAct = false;
750 const SwTextAttr* pTwoLineAttr = GetTop(nTwoLineStack);
752 if ( pTwoLineAttr )
754 const auto& rTwoLineItem = *CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES );
755 bTwoLineAct = rTwoLineItem.GetValue();
757 else
758 bTwoLineAct = m_pDefaultArray[ nTwoLineStack ]->StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue();
760 if ( !bTwoLineAct )
761 rFnt.SetVertical( rItem.StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout, m_bVertLayoutLRBT );
763 break;
765 case RES_CHRATR_TWO_LINES :
767 bool bRuby = 0 !=
768 m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].size();
770 // two line is activated, if
771 // 1. no ruby attribute is set and
772 // 2. attribute is active
773 if ( !bRuby && rItem.StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue() )
775 rFnt.SetVertical( 0_deg10, m_bVertLayout );
776 break;
779 // a deactivating two line attribute is on top of stack,
780 // check if rotate attribute has to be enabled
781 if ( bRuby )
782 break;
784 const sal_uInt16 nRotateStack = StackPos[ RES_CHRATR_ROTATE ];
785 const SwTextAttr* pRotateAttr = GetTop(nRotateStack);
787 if ( pRotateAttr )
789 const auto& rRotateItem = *CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
790 rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
792 else
793 rFnt.SetVertical(m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout);
794 break;
796 case RES_TXTATR_CJK_RUBY :
797 rFnt.SetVertical( 0_deg10, m_bVertLayout );
798 break;
799 case RES_TXTATR_REFMARK :
800 if ( bPush )
801 rFnt.GetRef()++;
802 else
803 rFnt.GetRef()--;
804 break;
805 case RES_TXTATR_TOXMARK :
806 if ( bPush )
807 rFnt.GetTox()++;
808 else
809 rFnt.GetTox()--;
810 break;
811 case RES_TXTATR_META:
812 case RES_TXTATR_METAFIELD:
813 if ( bPush )
814 rFnt.GetMeta()++;
815 else
816 rFnt.GetMeta()--;
817 break;
818 case RES_TXTATR_CONTENTCONTROL:
819 if (bPush)
821 rFnt.GetContentControl()++;
823 else
825 rFnt.GetContentControl()--;
827 break;
828 case RES_TXTATR_INPUTFIELD :
829 if ( bPush )
830 rFnt.GetInputField()++;
831 else
832 rFnt.GetInputField()--;
833 break;
837 /// Takes the default font and calculated the ascent and height
838 void SwAttrHandler::GetDefaultAscentAndHeight( SwViewShell const * pShell, OutputDevice const & rOut,
839 sal_uInt16& nAscent, sal_uInt16& nHeight ) const
841 OSL_ENSURE(m_oFnt, "No font available for GetDefaultAscentAndHeight");
843 if (m_oFnt)
845 SwFont aFont( *m_oFnt );
846 nHeight = aFont.GetHeight( pShell, rOut );
847 nAscent = aFont.GetAscent( pShell, rOut );
851 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */