1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
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
66 * Also adjust NUM_ATTRIBUTE_STACKS in atrhndl.hxx.
68 const sal_uInt8 StackPos
[ RES_TXTATR_WITHEND_END
- RES_CHRATR_BEGIN
+ 1 ] =
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
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();
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();
149 pSet
= &pFormat
->GetAttrSet();
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
)
181 const SfxItemSet
* pItemSet
= CharFormat::GetItemSet( pAttr
->GetAttr() );
183 bRet
= SfxItemState::SET
== pItemSet
->GetItemState( nWhich
);
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
,
202 RES_TXTATR_INETFMT
!= rAttr
.Which() ||
203 RES_CHRATR_COLOR
!= rItem
.Which() )
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())
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);
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())
247 if (rINetAttr
.IsVisited())
249 // take color from view option 'visited link color'
250 *pColor
= pShell
->GetViewOptions()->GetVisitedLinksColor();
254 // take color from view option 'unvisited link color'
255 *pColor
= pShell
->GetViewOptions()->GetLinksColor();
264 SwAttrHandler::SwAttrHandler()
265 : m_pIDocumentSettingAccess(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
;
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
;
299 // do we have to apply additional paragraph attributes?
301 m_bVertLayoutLRBT
= bVertLayoutLRBT
;
303 if ( pAS
&& pAS
->Count() )
305 SfxItemIter
aIter( *pAS
);
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();
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!
328 m_oFnt
.emplace(rFnt
);
331 void SwAttrHandler::Reset( )
333 for (auto& i
: m_aAttrStack
)
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() );
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
);
355 // we push rAttr onto the appropriate stack
356 if ( Push( rAttr
, *pItem
) )
358 // we let pItem change rFnt
360 if (lcl_ChgHyperLinkColor(rAttr
, *pItem
, m_pShell
, &aColor
))
362 SvxColorItem
aItemNext( aColor
, RES_CHRATR_COLOR
);
363 FontChg( aItemNext
, rFnt
, true );
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
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" );
392 if ( RES_TXTATR_WITHEND_END
<= rItem
.Which() )
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
);
401 || rAttr
.IsPriorityAttr()
402 || ( !pTopAttr
->IsPriorityAttr()
403 && !lcl_ChgHyperLinkColor(*pTopAttr
, rItem
, m_pShell
, nullptr)))
405 m_aAttrStack
[nStack
].push_back(&rAttr
);
409 const auto it
= m_aAttrStack
[nStack
].end() - 1;
410 m_aAttrStack
[nStack
].insert(it
, &rAttr
);
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())
422 void SwAttrHandler::PopAndChg( const SwTextAttr
& rAttr
, SwFont
& rFnt
)
424 if ( RES_TXTATR_WITHEND_END
<= rAttr
.Which() )
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() );
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
);
442 // we remove rAttr from the appropriate stack
443 RemoveFromStack(i
, rAttr
);
444 // reset font according to attribute on top of stack
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
454 RemoveFromStack(rAttr
.Which(), rAttr
);
455 // reset font according to attribute on top of stack
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
);
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() );
491 pSet
->GetItemState( nAttr
, RES_TXTATR_AUTOFMT
!= pTopAt
->Which(), &pItemNext
);
497 if (lcl_ChgHyperLinkColor(*pTopAt
, *pItemNext
, m_pShell
, &aColor
))
499 SvxColorItem
aItemNext( aColor
, RES_CHRATR_COLOR
);
500 FontChg( aItemNext
, rFnt
, false );
503 FontChg( *pItemNext
, rFnt
, false );
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
)
514 else if ( RES_TXTATR_TOXMARK
== nAttr
)
516 else if ( (RES_TXTATR_META
== nAttr
) || (RES_TXTATR_METAFIELD
== nAttr
) )
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
);
534 const auto& rTwoLineItem
= *CharFormat::GetItem( *pTwoLineAttr
, RES_CHRATR_TWO_LINES
);
535 bTwoLineAct
= rTwoLineItem
.GetValue();
538 bTwoLineAct
= m_pDefaultArray
[ nTwoLineStack
]->StaticWhichCast(RES_CHRATR_TWO_LINES
).GetValue();
543 // eventually, a rotate attribute has to be activated
544 const sal_uInt16 nRotateStack
= StackPos
[ RES_CHRATR_ROTATE
];
545 const SwTextAttr
* pRotateAttr
= GetTop(nRotateStack
);
549 const auto& rRotateItem
= *CharFormat::GetItem( *pRotateAttr
, RES_CHRATR_ROTATE
);
550 rFnt
.SetVertical( rRotateItem
.GetValue(), m_bVertLayout
);
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() );
571 case RES_CHRATR_COLOR
:
572 rFnt
.SetColor( rItem
.StaticWhichCast(RES_CHRATR_COLOR
).GetValue() );
574 case RES_CHRATR_CONTOUR
:
575 rFnt
.SetOutline( rItem
.StaticWhichCast(RES_CHRATR_CONTOUR
).GetValue() );
577 case RES_CHRATR_CROSSEDOUT
:
578 rFnt
.SetStrikeout( rItem
.StaticWhichCast(RES_CHRATR_CROSSEDOUT
).GetStrikeout() );
580 case RES_CHRATR_ESCAPEMENT
:
581 rFnt
.SetEscapement( rItem
.StaticWhichCast(RES_CHRATR_ESCAPEMENT
).GetEsc() );
582 rFnt
.SetProportion( rItem
.StaticWhichCast(RES_CHRATR_ESCAPEMENT
).GetProportionalHeight() );
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
);
594 case RES_CHRATR_FONTSIZE
:
595 rFnt
.SetSize(Size(0, rItem
.StaticWhichCast(RES_CHRATR_FONTSIZE
).GetHeight() ), SwFontScript::Latin
);
597 case RES_CHRATR_KERNING
:
598 rFnt
.SetFixKerning( rItem
.StaticWhichCast(RES_CHRATR_KERNING
).GetValue() );
600 case RES_CHRATR_LANGUAGE
:
601 rFnt
.SetLanguage( rItem
.StaticWhichCast(RES_CHRATR_LANGUAGE
).GetLanguage(), SwFontScript::Latin
);
603 case RES_CHRATR_POSTURE
:
604 rFnt
.SetItalic( rItem
.StaticWhichCast(RES_CHRATR_POSTURE
).GetPosture(), SwFontScript::Latin
);
606 case RES_CHRATR_SHADOWED
:
607 rFnt
.SetShadow( rItem
.StaticWhichCast(RES_CHRATR_SHADOWED
).GetValue() );
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() );
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
) );
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() );
647 case RES_CHRATR_OVERLINE
:
648 rFnt
.SetOverline( rItem
.StaticWhichCast(RES_CHRATR_OVERLINE
).GetLineStyle() );
649 rFnt
.SetOverColor( rItem
.StaticWhichCast(RES_CHRATR_OVERLINE
).GetColor() );
651 case RES_CHRATR_WEIGHT
:
652 rFnt
.SetWeight( rItem
.StaticWhichCast(RES_CHRATR_WEIGHT
).GetWeight(), SwFontScript::Latin
);
654 case RES_CHRATR_WORDLINEMODE
:
655 rFnt
.SetWordLineMode( rItem
.StaticWhichCast(RES_CHRATR_WORDLINEMODE
).GetValue() );
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
);
666 rFnt
.SetAutoKern( FontKerning::NONE
);
668 case RES_CHRATR_BACKGROUND
:
669 rFnt
.SetBackColor(rItem
.StaticWhichCast(RES_CHRATR_BACKGROUND
).GetColor());
671 case RES_CHRATR_HIGHLIGHT
:
672 rFnt
.SetHighlightColor( rItem
.StaticWhichCast(RES_CHRATR_HIGHLIGHT
).GetColor() );
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
);
684 case RES_CHRATR_CJK_FONTSIZE
:
685 rFnt
.SetSize(Size( 0, rItem
.StaticWhichCast(RES_CHRATR_CJK_FONTSIZE
).GetHeight()), SwFontScript::CJK
);
687 case RES_CHRATR_CJK_LANGUAGE
:
688 rFnt
.SetLanguage( rItem
.StaticWhichCast(RES_CHRATR_CJK_LANGUAGE
).GetLanguage(), SwFontScript::CJK
);
690 case RES_CHRATR_CJK_POSTURE
:
691 rFnt
.SetItalic( rItem
.StaticWhichCast(RES_CHRATR_CJK_POSTURE
).GetPosture(), SwFontScript::CJK
);
693 case RES_CHRATR_CJK_WEIGHT
:
694 rFnt
.SetWeight( rItem
.StaticWhichCast(RES_CHRATR_CJK_WEIGHT
).GetWeight(), SwFontScript::CJK
);
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
);
706 case RES_CHRATR_CTL_FONTSIZE
:
707 rFnt
.SetSize(Size(0, rItem
.StaticWhichCast(RES_CHRATR_CTL_FONTSIZE
).GetHeight() ), SwFontScript::CTL
);
709 case RES_CHRATR_CTL_LANGUAGE
:
710 rFnt
.SetLanguage( rItem
.StaticWhichCast(RES_CHRATR_CTL_LANGUAGE
).GetLanguage(), SwFontScript::CTL
);
712 case RES_CHRATR_CTL_POSTURE
:
713 rFnt
.SetItalic( rItem
.StaticWhichCast(RES_CHRATR_CTL_POSTURE
).GetPosture(), SwFontScript::CTL
);
715 case RES_CHRATR_CTL_WEIGHT
:
716 rFnt
.SetWeight( rItem
.StaticWhichCast(RES_CHRATR_CTL_WEIGHT
).GetWeight(), SwFontScript::CTL
);
718 case RES_CHRATR_EMPHASIS_MARK
:
719 rFnt
.SetEmphasisMark( rItem
.StaticWhichCast(RES_CHRATR_EMPHASIS_MARK
).GetEmphasisMark() );
721 case RES_CHRATR_SCALEW
:
722 rFnt
.SetPropWidth( rItem
.StaticWhichCast(RES_CHRATR_SCALEW
).GetValue() );
724 case RES_CHRATR_RELIEF
:
725 rFnt
.SetRelief( rItem
.StaticWhichCast(RES_CHRATR_RELIEF
).GetValue() );
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
);
733 ActivateTop( rFnt
, RES_CHRATR_UNDERLINE
);
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
743 0 != m_aAttrStack
[ StackPos
[ RES_TXTATR_CJK_RUBY
] ].size();
748 const sal_uInt16 nTwoLineStack
= StackPos
[ RES_CHRATR_TWO_LINES
];
749 bool bTwoLineAct
= false;
750 const SwTextAttr
* pTwoLineAttr
= GetTop(nTwoLineStack
);
754 const auto& rTwoLineItem
= *CharFormat::GetItem( *pTwoLineAttr
, RES_CHRATR_TWO_LINES
);
755 bTwoLineAct
= rTwoLineItem
.GetValue();
758 bTwoLineAct
= m_pDefaultArray
[ nTwoLineStack
]->StaticWhichCast(RES_CHRATR_TWO_LINES
).GetValue();
761 rFnt
.SetVertical( rItem
.StaticWhichCast(RES_CHRATR_ROTATE
).GetValue(), m_bVertLayout
, m_bVertLayoutLRBT
);
765 case RES_CHRATR_TWO_LINES
:
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
);
779 // a deactivating two line attribute is on top of stack,
780 // check if rotate attribute has to be enabled
784 const sal_uInt16 nRotateStack
= StackPos
[ RES_CHRATR_ROTATE
];
785 const SwTextAttr
* pRotateAttr
= GetTop(nRotateStack
);
789 const auto& rRotateItem
= *CharFormat::GetItem( *pRotateAttr
, RES_CHRATR_ROTATE
);
790 rFnt
.SetVertical( rRotateItem
.GetValue(), m_bVertLayout
);
793 rFnt
.SetVertical(m_pDefaultArray
[ nRotateStack
]->StaticWhichCast(RES_CHRATR_ROTATE
).GetValue(), m_bVertLayout
);
796 case RES_TXTATR_CJK_RUBY
:
797 rFnt
.SetVertical( 0_deg10
, m_bVertLayout
);
799 case RES_TXTATR_REFMARK
:
805 case RES_TXTATR_TOXMARK
:
811 case RES_TXTATR_META
:
812 case RES_TXTATR_METAFIELD
:
818 case RES_TXTATR_CONTENTCONTROL
:
821 rFnt
.GetContentControl()++;
825 rFnt
.GetContentControl()--;
828 case RES_TXTATR_INPUTFIELD
:
830 rFnt
.GetInputField()++;
832 rFnt
.GetInputField()--;
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");
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: */