1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atrstck.cxx,v $
10 * $Revision: 1.30.210.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <errhdl.hxx> // ASSERT
36 #include <atrhndl.hxx>
37 #include <svtools/itemiter.hxx>
38 #include <vcl/outdev.hxx>
39 #include <svx/cmapitem.hxx>
40 #include <svx/colritem.hxx>
41 #include <svx/cntritem.hxx>
42 #include <svx/crsditem.hxx>
43 #include <svx/escpitem.hxx>
44 #include <svx/fontitem.hxx>
45 #include <svx/fhgtitem.hxx>
46 #include <svx/kernitem.hxx>
47 #include <svx/charreliefitem.hxx>
48 #include <svx/langitem.hxx>
49 #include <svx/postitem.hxx>
50 #include <svx/shdditem.hxx>
51 #include <svx/udlnitem.hxx>
52 #include <svx/wghtitem.hxx>
53 #include <svx/wrlmitem.hxx>
54 #include <svx/akrnitem.hxx>
55 #include <svx/blnkitem.hxx>
56 #include <svx/charrotateitem.hxx>
57 #include <svx/emphitem.hxx>
58 #include <svx/charscaleitem.hxx>
59 #include <svx/twolinesitem.hxx>
60 #include <svx/charhiddenitem.hxx>
61 #include <viewopt.hxx>
62 #include <charfmt.hxx>
63 #include <fchrfmt.hxx>
64 #include <fmtautofmt.hxx>
65 #include <svx/brshitem.hxx>
66 #include <fmtinfmt.hxx>
67 #include <txtinet.hxx>
68 #include <IDocumentSettingAccess.hxx>
69 #include <viewsh.hxx> // ViewShell
70 #include <viewopt.hxx> // SwViewOptions
72 #define STACK_INCREMENT 4
74 /*************************************************************************
75 * Attribute to Stack Mapping
77 * Attributes applied to a text are pushed on different stacks. For each
78 * stack, the top most attribute on the stack is valid. Because some
79 * kinds of attributes have to be pushed to the same stacks we map their
81 * Attention: The first NUM_DEFAULT_VALUES ( defined in swfntcch.hxx == 35 )
82 * are stored in the defaultitem-cache, if you add one, you have to increase
84 * Also adjust NUM_ATTRIBUTE_STACKS in atrhndl.hxx.
85 *************************************************************************/
87 const BYTE StackPos
[ static_cast<USHORT
>(RES_TXTATR_WITHEND_END
) -
88 static_cast<USHORT
>(RES_CHRATR_BEGIN
) + 1 ] =
91 1, // RES_CHRATR_CASEMAP = RES_CHRATR_BEGIN // 1
92 0, // RES_CHRATR_CHARSETCOLOR, // 2
93 2, // RES_CHRATR_COLOR, // 3
94 3, // RES_CHRATR_CONTOUR, // 4
95 4, // RES_CHRATR_CROSSEDOUT, // 5
96 5, // RES_CHRATR_ESCAPEMENT, // 6
97 6, // RES_CHRATR_FONT, // 7
98 7, // RES_CHRATR_FONTSIZE, // 8
99 8, // RES_CHRATR_KERNING, // 9
100 9, // RES_CHRATR_LANGUAGE, // 10
101 10, // RES_CHRATR_POSTURE, // 11
102 0, // RES_CHRATR_PROPORTIONALFONTSIZE, // 12
103 11, // RES_CHRATR_SHADOWED, // 13
104 12, // RES_CHRATR_UNDERLINE, // 14
105 13, // RES_CHRATR_WEIGHT, // 15
106 14, // RES_CHRATR_WORDLINEMODE, // 16
107 15, // RES_CHRATR_AUTOKERN, // 17
108 16, // RES_CHRATR_BLINK, // 18
109 17, // RES_CHRATR_NOHYPHEN, // 19
110 0, // RES_CHRATR_NOLINEBREAK, // 20
111 18, // RES_CHRATR_BACKGROUND, // 21
112 19, // RES_CHRATR_CJK_FONT, // 22
113 20, // RES_CHRATR_CJK_FONTSIZE, // 23
114 21, // RES_CHRATR_CJK_LANGUAGE, // 24
115 22, // RES_CHRATR_CJK_POSTURE, // 25
116 23, // RES_CHRATR_CJK_WEIGHT, // 26
117 24, // RES_CHRATR_CTL_FONT, // 27
118 25, // RES_CHRATR_CTL_FONTSIZE, // 28
119 26, // RES_CHRATR_CTL_LANGUAGE, // 29
120 27, // RES_CHRATR_CTL_POSTURE, // 30
121 28, // RES_CHRATR_CTL_WEIGHT, // 31
122 29, // RES_CHRATR_ROTATE, // 32
123 30, // RES_CHRATR_EMPHASIS_MARK, // 33
124 31, // RES_CHRATR_TWO_LINES, // 34
125 32, // RES_CHRATR_SCALEW, // 35
126 33, // RES_CHRATR_RELIEF, // 36
127 34, // RES_CHRATR_HIDDEN, // 37
128 35, // RES_CHRATR_OVERLINE, // 38
129 0, // RES_CHRATR_DUMMY1, // 39
130 0, // RES_CHRATR_DUMMY2, // 40
131 0, // RES_TXTATR_AUTOFMT, // 41
132 0, // RES_TXTATR_INETFMT // 42
133 36, // RES_TXTATR_REFMARK, // 43
134 37, // RES_TXTATR_TOXMARK, // 44
135 0, // RES_TXTATR_CHARFMT, // 45
136 0, // RES_TXTATR_DUMMY5 // 46
137 38, // RES_TXTATR_CJK_RUBY, // 47
138 0, // RES_TXTATR_UNKNOWN_CONTAINER, // 48
139 0, // RES_TXTATR_DUMMY6, // 49
140 0 // RES_TXTATR_DUMMY7, // 50
143 /*************************************************************************
145 * returns the item set associated with an character/inet/auto style
146 *************************************************************************/
151 const SfxItemSet
* GetItemSet( const SfxPoolItem
& rAttr
)
153 const SfxItemSet
* pSet
= 0;
155 if ( RES_TXTATR_AUTOFMT
== rAttr
.Which() )
157 pSet
= static_cast<const SwFmtAutoFmt
&>(rAttr
).GetStyleHandle().get();
161 // aus der Vorlage die Attribute holen:
162 SwCharFmt
* pFmt
= RES_TXTATR_INETFMT
== rAttr
.Which() ?
163 ((SwFmtINetFmt
&)rAttr
).GetTxtINetFmt()->GetCharFmt() :
164 ((SwFmtCharFmt
&)rAttr
).GetCharFmt();
167 pSet
= &pFmt
->GetAttrSet();
174 /*************************************************************************
176 * extracts pool item of type nWhich from rAttr
177 *************************************************************************/
179 const SfxPoolItem
* GetItem( const SwTxtAttr
& rAttr
, USHORT nWhich
)
181 if ( RES_TXTATR_INETFMT
== rAttr
.Which() ||
182 RES_TXTATR_CHARFMT
== rAttr
.Which() ||
183 RES_TXTATR_AUTOFMT
== rAttr
.Which() )
185 const SfxItemSet
* pSet
= CharFmt::GetItemSet( rAttr
.GetAttr() );
186 if ( !pSet
) return 0;
188 bool bInParent
= RES_TXTATR_AUTOFMT
!= rAttr
.Which();
189 const SfxPoolItem
* pItem
;
190 BOOL bRet
= SFX_ITEM_SET
== pSet
->GetItemState( nWhich
, bInParent
, &pItem
);
192 return bRet
? pItem
: 0;
195 return ( nWhich
== rAttr
.Which() ) ? &rAttr
.GetAttr() : 0;
198 /*************************************************************************
199 * CharFmt::IsItemIncluded
200 * checks if item is included in character/inet/auto style
201 *************************************************************************/
203 BOOL
IsItemIncluded( const USHORT nWhich
, const SwTxtAttr
*pAttr
)
207 const SfxItemSet
* pItemSet
= CharFmt::GetItemSet( pAttr
->GetAttr() );
209 bRet
= SFX_ITEM_SET
== pItemSet
->GetItemState( nWhich
, TRUE
);
216 /*************************************************************************
217 * lcl_ChgHyperLinkColor
218 * The color of hyperlinks is taken from the associated character attribute,
219 * depending on its 'visited' state. There are actually two cases, which
220 * should override the colors from the character attribute:
221 * 1. We never take the 'visited' color during printing/pdf export/preview
222 * 2. The user has choosen to override these colors in the view options
223 *************************************************************************/
225 bool lcl_ChgHyperLinkColor( const SwTxtAttr
& rAttr
,
226 const SfxPoolItem
& rItem
,
227 const ViewShell
* pShell
,
231 RES_TXTATR_INETFMT
!= rAttr
.Which() ||
232 RES_CHRATR_COLOR
!= rItem
.Which() )
235 // --> FME 2004-09-13 #i15455#
237 // We do not want to show visited links:
238 // (printing, pdf export, page preview)
240 if ( pShell
->GetOut()->GetOutDevType() == OUTDEV_PRINTER
||
241 pShell
->GetViewOptions()->IsPDFExport() ||
242 pShell
->GetViewOptions()->IsPagePreview() )
244 if ( ((SwTxtINetFmt
&)rAttr
).IsVisited() )
248 // take color from character format 'unvisited link'
249 SwTxtINetFmt
& rInetAttr( const_cast<SwTxtINetFmt
&>(
250 static_cast<const SwTxtINetFmt
&>(rAttr
)) );
251 rInetAttr
.SetVisited( false );
252 const SwCharFmt
* pTmpFmt
= ((SwTxtINetFmt
&)rAttr
).GetCharFmt();
253 const SfxPoolItem
* pItem
;
254 pTmpFmt
->GetItemState( RES_CHRATR_COLOR
, TRUE
, &pItem
);
255 *pColor
= ((SvxColorItem
*)pItem
)->GetValue();
256 rInetAttr
.SetVisited( true );
267 // We do not want to apply the color set in the hyperlink
268 // attribute, instead we take the colors from the view options:
270 if ( pShell
->GetWin() &&
272 (((SwTxtINetFmt
&)rAttr
).IsVisited() && SwViewOption::IsVisitedLinks()) ||
273 (!((SwTxtINetFmt
&)rAttr
).IsVisited() && SwViewOption::IsLinks())
279 if ( ((SwTxtINetFmt
&)rAttr
).IsVisited() )
281 // take color from view option 'visited link color'
282 *pColor
= SwViewOption::GetVisitedLinksColor();
286 // take color from view option 'unvisited link color'
287 *pColor
= SwViewOption::GetLinksColor();
296 /*************************************************************************
297 * SwAttrHandler::SwAttrStack::SwAttrStack()
298 *************************************************************************/
300 inline SwAttrHandler::SwAttrStack::SwAttrStack()
301 : nCount( 0 ), nSize( INITIAL_NUM_ATTR
)
303 pArray
= pInitialArray
;
306 /*************************************************************************
307 * SwAttrHandler::SwAttrStack::Insert()
308 *************************************************************************/
310 void SwAttrHandler::SwAttrStack::Insert( const SwTxtAttr
& rAttr
, const USHORT nPos
)
312 // do we still have enough space?
313 if ( nCount
>= nSize
)
315 // we are still in our initial array
316 if ( INITIAL_NUM_ATTR
== nSize
)
318 nSize
+= STACK_INCREMENT
;
319 pArray
= new SwTxtAttr
*[ nSize
];
320 // copy from pInitArray to new Array
321 memcpy( pArray
, pInitialArray
,
322 INITIAL_NUM_ATTR
* sizeof(SwTxtAttr
*)
325 // we are in new memory
328 nSize
+= STACK_INCREMENT
;
329 SwTxtAttr
** pTmpArray
= new SwTxtAttr
*[ nSize
];
330 // copy from pArray to new Array
331 memcpy( pTmpArray
, pArray
, nCount
* sizeof(SwTxtAttr
*) );
338 ASSERT( nPos
<= nCount
, "wrong position for insert operation");
341 memmove( pArray
+ nPos
+ 1, pArray
+ nPos
,
342 ( nCount
- nPos
) * sizeof(SwTxtAttr
*)
344 pArray
[ nPos
] = (SwTxtAttr
*)&rAttr
;
349 /*************************************************************************
350 * SwAttrHandler::SwAttrStack::Remove()
351 *************************************************************************/
353 void SwAttrHandler::SwAttrStack::Remove( const SwTxtAttr
& rAttr
)
355 USHORT nPos
= Pos( rAttr
);
358 memmove( pArray
+ nPos
, pArray
+ nPos
+ 1,
359 ( nCount
- 1 - nPos
) * sizeof(SwTxtAttr
*)
365 /*************************************************************************
366 * SwAttrHandler::SwAttrStack::Top()
367 *************************************************************************/
369 const SwTxtAttr
* SwAttrHandler::SwAttrStack::Top() const
371 return nCount
? pArray
[ nCount
- 1 ] : 0;
374 /*************************************************************************
375 * SwAttrHandler::SwAttrStack::Pos()
376 *************************************************************************/
378 USHORT
SwAttrHandler::SwAttrStack::Pos( const SwTxtAttr
& rAttr
) const
384 for ( USHORT nIdx
= nCount
; nIdx
> 0; )
386 if ( &rAttr
== pArray
[ --nIdx
] )
394 /*************************************************************************
395 * SwAttrHandler::SwAttrHandler()
396 *************************************************************************/
398 SwAttrHandler::SwAttrHandler() : mpShell( 0 ), pFnt( 0 ), bVertLayout( sal_False
)
401 memset( pDefaultArray
, 0, NUM_DEFAULT_VALUES
* sizeof(SfxPoolItem
*) );
404 SwAttrHandler::~SwAttrHandler()
409 /*************************************************************************
410 * SwAttrHandler::Init()
411 *************************************************************************/
413 void SwAttrHandler::Init( const SwAttrSet
& rAttrSet
,
414 const IDocumentSettingAccess
& rIDocumentSettingAcces
,
415 const ViewShell
* pSh
)
417 mpIDocumentSettingAccess
= &rIDocumentSettingAcces
;
420 for ( USHORT i
= RES_CHRATR_BEGIN
; i
< RES_CHRATR_END
; i
++ )
421 pDefaultArray
[ StackPos
[ i
] ] = &rAttrSet
.Get( i
, TRUE
);
424 void SwAttrHandler::Init( const SfxPoolItem
** pPoolItem
, const SwAttrSet
* pAS
,
425 const IDocumentSettingAccess
& rIDocumentSettingAcces
,
426 const ViewShell
* pSh
,
427 SwFont
& rFnt
, sal_Bool bVL
)
429 // initialize default array
430 memcpy( pDefaultArray
, pPoolItem
,
431 NUM_DEFAULT_VALUES
* sizeof(SfxPoolItem
*) );
433 mpIDocumentSettingAccess
= &rIDocumentSettingAcces
;
436 // do we have to apply additional paragraph attributes?
439 if ( pAS
&& pAS
->Count() )
441 SfxItemIter
aIter( *pAS
);
443 const SfxPoolItem
* pItem
= aIter
.GetCurItem();
446 nWhich
= pItem
->Which();
447 if (isCHRATR(nWhich
))
449 pDefaultArray
[ StackPos
[ nWhich
] ] = pItem
;
450 FontChg( *pItem
, rFnt
, sal_True
);
453 if( aIter
.IsAtEnd() )
456 pItem
= aIter
.NextItem();
460 // It is possible, that Init is called more than once, e.g., in a
461 // SwTxtFrm::FormatOnceMore situation.
463 pFnt
= new SwFont( rFnt
);
466 void SwAttrHandler::Reset( )
468 for ( USHORT i
= 0; i
< NUM_ATTRIBUTE_STACKS
; i
++ )
469 aAttrStack
[ i
].Reset();
472 /*************************************************************************
473 * SwAttrHandler::PushAndChg()
474 *************************************************************************/
476 void SwAttrHandler::PushAndChg( const SwTxtAttr
& rAttr
, SwFont
& rFnt
)
478 // these special attributes in fact represent a collection of attributes
479 // they have to be pushed to each stack they belong to
480 if ( RES_TXTATR_INETFMT
== rAttr
.Which() ||
481 RES_TXTATR_CHARFMT
== rAttr
.Which() ||
482 RES_TXTATR_AUTOFMT
== rAttr
.Which() )
484 const SfxItemSet
* pSet
= CharFmt::GetItemSet( rAttr
.GetAttr() );
487 for ( USHORT i
= RES_CHRATR_BEGIN
; i
< RES_CHRATR_END
; i
++)
489 const SfxPoolItem
* pItem
;
490 BOOL bRet
= SFX_ITEM_SET
== pSet
->GetItemState( i
, rAttr
.Which() != RES_TXTATR_AUTOFMT
, &pItem
);
494 // we push rAttr onto the appropriate stack
495 if ( Push( rAttr
, *pItem
) )
497 // we let pItem change rFnt
499 if ( lcl_ChgHyperLinkColor( rAttr
, *pItem
, mpShell
, &aColor
) )
501 SvxColorItem
aItemNext( aColor
, RES_CHRATR_COLOR
);
502 FontChg( aItemNext
, rFnt
, sal_True
);
505 FontChg( *pItem
, rFnt
, sal_True
);
510 // this is the usual case, we have a basic attribute, push it onto the
511 // stack and change the font
514 if ( Push( rAttr
, rAttr
.GetAttr() ) )
515 // we let pItem change rFnt
516 FontChg( rAttr
.GetAttr(), rFnt
, sal_True
);
520 /*************************************************************************
521 * SwAttrHandler::Push()
522 *************************************************************************/
524 sal_Bool
SwAttrHandler::Push( const SwTxtAttr
& rAttr
, const SfxPoolItem
& rItem
)
526 ASSERT( rItem
.Which() < RES_TXTATR_WITHEND_END
||
527 RES_UNKNOWNATR_CONTAINER
== rItem
.Which() ,
528 "I do not want this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
531 if ( RES_TXTATR_WITHEND_END
<= rItem
.Which() ||
532 RES_UNKNOWNATR_CONTAINER
== rItem
.Which() )
535 USHORT nStack
= StackPos
[ rItem
.Which() ];
537 // attributes originating from redlining have highest priority
538 // second priority are hyperlink attributes, which have a color replacement
539 const SwTxtAttr
* pTopAttr
= aAttrStack
[ nStack
].Top();
540 if ( !pTopAttr
|| rAttr
.IsPriorityAttr() ||
541 ( !pTopAttr
->IsPriorityAttr() &&
542 !lcl_ChgHyperLinkColor( *pTopAttr
, rItem
, mpShell
, 0 ) ) )
544 aAttrStack
[ nStack
].Push( rAttr
);
548 USHORT nPos
= aAttrStack
[ nStack
].Count();
549 ASSERT( nPos
, "empty stack?" );
550 aAttrStack
[ nStack
].Insert( rAttr
, nPos
- 1 );
554 /*************************************************************************
555 * SwAttrHandler::PopAndChg()
556 *************************************************************************/
558 void SwAttrHandler::PopAndChg( const SwTxtAttr
& rAttr
, SwFont
& rFnt
)
560 // these special attributes in fact represent a collection of attributes
561 // they have to be removed from each stack they belong to
562 if ( RES_TXTATR_INETFMT
== rAttr
.Which() ||
563 RES_TXTATR_CHARFMT
== rAttr
.Which() ||
564 RES_TXTATR_AUTOFMT
== rAttr
.Which() )
566 const SfxItemSet
* pSet
= CharFmt::GetItemSet( rAttr
.GetAttr() );
569 for ( USHORT i
= RES_CHRATR_BEGIN
; i
< RES_CHRATR_END
; i
++)
571 const SfxPoolItem
* pItem
;
572 BOOL bRet
= SFX_ITEM_SET
== pSet
->GetItemState( i
, RES_TXTATR_AUTOFMT
!= rAttr
.Which(), &pItem
);
575 // we remove rAttr from the appropriate stack
576 USHORT nStackPos
= StackPos
[ i
];
577 aAttrStack
[ nStackPos
].Remove( rAttr
);
578 // reset font according to attribute on top of stack
580 ActivateTop( rFnt
, i
);
584 // this is the usual case, we have a basic attribute, remove it from the
585 // stack and reset the font
586 else if ( RES_UNKNOWNATR_CONTAINER
!= rAttr
.Which() )
588 aAttrStack
[ StackPos
[ rAttr
.Which() ] ].Remove( rAttr
);
589 // reset font according to attribute on top of stack
591 ActivateTop( rFnt
, rAttr
.Which() );
595 /*************************************************************************
596 * SwAttrHandler::Pop()
598 * only used during redlining
599 *************************************************************************/
601 void SwAttrHandler::Pop( const SwTxtAttr
& rAttr
)
603 ASSERT( rAttr
.Which() < RES_TXTATR_WITHEND_END
||
604 RES_UNKNOWNATR_CONTAINER
== rAttr
.Which() ,
605 "I do not have this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
607 if ( RES_UNKNOWNATR_CONTAINER
!= rAttr
.Which() &&
608 rAttr
.Which() < RES_TXTATR_WITHEND_END
)
609 aAttrStack
[ StackPos
[ rAttr
.Which() ] ].Remove( rAttr
);
612 /*************************************************************************
613 * SwAttrHandler::ActivateTop()
614 *************************************************************************/
615 void SwAttrHandler::ActivateTop( SwFont
& rFnt
, const USHORT nAttr
)
617 ASSERT( nAttr
< RES_TXTATR_WITHEND_END
,
618 "I cannot activate this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
620 const USHORT nStackPos
= StackPos
[ nAttr
];
621 const SwTxtAttr
* pTopAt
= aAttrStack
[ nStackPos
].Top();
624 // check if top attribute is collection of attributes
625 if ( RES_TXTATR_INETFMT
== pTopAt
->Which() ||
626 RES_TXTATR_CHARFMT
== pTopAt
->Which() ||
627 RES_TXTATR_AUTOFMT
== pTopAt
->Which() )
629 const SfxItemSet
* pSet
= CharFmt::GetItemSet( pTopAt
->GetAttr() );
630 const SfxPoolItem
* pItemNext
;
631 pSet
->GetItemState( nAttr
, RES_TXTATR_AUTOFMT
!= pTopAt
->Which(), &pItemNext
);
634 if ( lcl_ChgHyperLinkColor( *pTopAt
, *pItemNext
, mpShell
, &aColor
) )
636 SvxColorItem
aItemNext( aColor
, RES_CHRATR_COLOR
);
637 FontChg( aItemNext
, rFnt
, sal_False
);
640 FontChg( *pItemNext
, rFnt
, sal_False
);
643 FontChg( pTopAt
->GetAttr(), rFnt
, sal_False
);
646 // default value has to be set, we only have default values for char attribs
647 else if ( nStackPos
< NUM_DEFAULT_VALUES
)
648 FontChg( *pDefaultArray
[ nStackPos
], rFnt
, sal_False
);
649 else if ( RES_TXTATR_REFMARK
== nAttr
)
651 else if ( RES_TXTATR_TOXMARK
== nAttr
)
653 else if ( RES_TXTATR_CJK_RUBY
== nAttr
)
655 // ruby stack has no more attributes
656 // check, if an rotation attribute has to be applied
657 USHORT nTwoLineStack
= StackPos
[ RES_CHRATR_TWO_LINES
];
658 sal_Bool bTwoLineAct
= sal_False
;
659 const SfxPoolItem
* pTwoLineItem
= 0;
660 const SwTxtAttr
* pTwoLineAttr
= aAttrStack
[ nTwoLineStack
].Top();
664 pTwoLineItem
= CharFmt::GetItem( *pTwoLineAttr
, RES_CHRATR_TWO_LINES
);
665 bTwoLineAct
= ((SvxTwoLinesItem
*)pTwoLineItem
)->GetValue();
669 ((SvxTwoLinesItem
*)pDefaultArray
[ nTwoLineStack
])->GetValue();
674 // eventually, an rotate attribute has to be activated
675 USHORT nRotateStack
= StackPos
[ RES_CHRATR_ROTATE
];
676 const SfxPoolItem
* pRotateItem
= 0;
677 const SwTxtAttr
* pRotateAttr
= aAttrStack
[ nRotateStack
].Top();
681 pRotateItem
= CharFmt::GetItem( *pRotateAttr
, RES_CHRATR_ROTATE
);
682 rFnt
.SetVertical( ((SvxCharRotateItem
*)pRotateItem
)->GetValue(),
687 ((SvxCharRotateItem
*)pDefaultArray
[ nRotateStack
])->GetValue(),
693 /*************************************************************************
694 * Font Changing Function
696 * When popping an attribute from the stack, the top mose remaining
697 * attribute in the stack becomes valid. The following function change
698 * a font depending on the stack id.
699 *************************************************************************/
701 void SwAttrHandler::FontChg(const SfxPoolItem
& rItem
, SwFont
& rFnt
, sal_Bool bPush
)
703 switch ( rItem
.Which() )
705 case RES_CHRATR_CASEMAP
:
706 rFnt
.SetCaseMap( ((SvxCaseMapItem
&)rItem
).GetCaseMap() );
708 case RES_CHRATR_COLOR
:
709 rFnt
.SetColor( ((SvxColorItem
&)rItem
).GetValue() );
711 case RES_CHRATR_CONTOUR
:
712 rFnt
.SetOutline( ((SvxContourItem
&)rItem
).GetValue() );
714 case RES_CHRATR_CROSSEDOUT
:
715 rFnt
.SetStrikeout( ((SvxCrossedOutItem
&)rItem
).GetStrikeout() );
717 case RES_CHRATR_ESCAPEMENT
:
718 rFnt
.SetEscapement( ((SvxEscapementItem
&)rItem
).GetEsc() );
719 rFnt
.SetProportion( ((SvxEscapementItem
&)rItem
).GetProp() );
721 case RES_CHRATR_FONT
:
722 rFnt
.SetName( ((SvxFontItem
&)rItem
).GetFamilyName(), SW_LATIN
);
723 rFnt
.SetStyleName( ((SvxFontItem
&)rItem
).GetStyleName(), SW_LATIN
);
724 rFnt
.SetFamily( ((SvxFontItem
&)rItem
).GetFamily(), SW_LATIN
);
725 rFnt
.SetPitch( ((SvxFontItem
&)rItem
).GetPitch(), SW_LATIN
);
726 rFnt
.SetCharSet( ((SvxFontItem
&)rItem
).GetCharSet(), SW_LATIN
);
728 case RES_CHRATR_FONTSIZE
:
729 rFnt
.SetSize(Size(0,((SvxFontHeightItem
&)rItem
).GetHeight() ), SW_LATIN
);
731 case RES_CHRATR_KERNING
:
732 rFnt
.SetFixKerning( ((SvxKerningItem
&)rItem
).GetValue() );
734 case RES_CHRATR_LANGUAGE
:
735 rFnt
.SetLanguage( ((SvxLanguageItem
&)rItem
).GetLanguage(), SW_LATIN
);
737 case RES_CHRATR_POSTURE
:
738 rFnt
.SetItalic( ((SvxPostureItem
&)rItem
).GetPosture(), SW_LATIN
);
740 case RES_CHRATR_SHADOWED
:
741 rFnt
.SetShadow( ((SvxShadowedItem
&)rItem
).GetValue() );
743 case RES_CHRATR_UNDERLINE
:
745 const USHORT nStackPos
= StackPos
[ RES_CHRATR_HIDDEN
];
746 const SwTxtAttr
* pTopAt
= aAttrStack
[ nStackPos
].Top();
748 const SfxPoolItem
* pTmpItem
= pTopAt
?
749 CharFmt::GetItem( *pTopAt
, RES_CHRATR_HIDDEN
) :
750 pDefaultArray
[ nStackPos
];
752 if( (mpShell
&& !mpShell
->GetWin()) ||
753 (pTmpItem
&& !static_cast<const SvxCharHiddenItem
*>(pTmpItem
)->GetValue()) )
755 rFnt
.SetUnderline( ((SvxUnderlineItem
&)rItem
).GetLineStyle() );
756 rFnt
.SetUnderColor( ((SvxUnderlineItem
&)rItem
).GetColor() );
760 case RES_CHRATR_OVERLINE
:
761 rFnt
.SetOverline( ((SvxOverlineItem
&)rItem
).GetLineStyle() );
762 rFnt
.SetOverColor( ((SvxOverlineItem
&)rItem
).GetColor() );
764 case RES_CHRATR_WEIGHT
:
765 rFnt
.SetWeight( ((SvxWeightItem
&)rItem
).GetWeight(), SW_LATIN
);
767 case RES_CHRATR_WORDLINEMODE
:
768 rFnt
.SetWordLineMode( ((SvxWordLineModeItem
&)rItem
).GetValue() );
770 case RES_CHRATR_AUTOKERN
:
771 if( ((SvxAutoKernItem
&)rItem
).GetValue() )
773 rFnt
.SetAutoKern( ( !mpIDocumentSettingAccess
||
774 !mpIDocumentSettingAccess
->get(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION
) ) ?
775 KERNING_FONTSPECIFIC
:
779 rFnt
.SetAutoKern( 0 );
781 case RES_CHRATR_BLINK
:
782 rFnt
.SetBlink( ((SvxBlinkItem
&)rItem
).GetValue() );
784 case RES_CHRATR_BACKGROUND
:
785 rFnt
.SetBackColor(new Color( ((SvxBrushItem
&)rItem
).GetColor() ) );
787 case RES_CHRATR_CJK_FONT
:
788 rFnt
.SetName( ((SvxFontItem
&)rItem
).GetFamilyName(), SW_CJK
);
789 rFnt
.SetStyleName( ((SvxFontItem
&)rItem
).GetStyleName(), SW_CJK
);
790 rFnt
.SetFamily( ((SvxFontItem
&)rItem
).GetFamily(), SW_CJK
);
791 rFnt
.SetPitch( ((SvxFontItem
&)rItem
).GetPitch(), SW_CJK
);
792 rFnt
.SetCharSet( ((SvxFontItem
&)rItem
).GetCharSet(), SW_CJK
);
794 case RES_CHRATR_CJK_FONTSIZE
:
795 rFnt
.SetSize(Size( 0, ((SvxFontHeightItem
&)rItem
).GetHeight()), SW_CJK
);
797 case RES_CHRATR_CJK_LANGUAGE
:
798 rFnt
.SetLanguage( ((SvxLanguageItem
&)rItem
).GetLanguage(), SW_CJK
);
800 case RES_CHRATR_CJK_POSTURE
:
801 rFnt
.SetItalic( ((SvxPostureItem
&)rItem
).GetPosture(), SW_CJK
);
803 case RES_CHRATR_CJK_WEIGHT
:
804 rFnt
.SetWeight( ((SvxWeightItem
&)rItem
).GetWeight(), SW_CJK
);
806 case RES_CHRATR_CTL_FONT
:
807 rFnt
.SetName( ((SvxFontItem
&)rItem
).GetFamilyName(), SW_CTL
);
808 rFnt
.SetStyleName( ((SvxFontItem
&)rItem
).GetStyleName(), SW_CTL
);
809 rFnt
.SetFamily( ((SvxFontItem
&)rItem
).GetFamily(), SW_CTL
);
810 rFnt
.SetPitch( ((SvxFontItem
&)rItem
).GetPitch(), SW_CTL
);
811 rFnt
.SetCharSet( ((SvxFontItem
&)rItem
).GetCharSet(), SW_CTL
);
813 case RES_CHRATR_CTL_FONTSIZE
:
814 rFnt
.SetSize(Size(0, ((SvxFontHeightItem
&)rItem
).GetHeight() ), SW_CTL
);
816 case RES_CHRATR_CTL_LANGUAGE
:
817 rFnt
.SetLanguage( ((SvxLanguageItem
&)rItem
).GetLanguage(), SW_CTL
);
819 case RES_CHRATR_CTL_POSTURE
:
820 rFnt
.SetItalic( ((SvxPostureItem
&)rItem
).GetPosture(), SW_CTL
);
822 case RES_CHRATR_CTL_WEIGHT
:
823 rFnt
.SetWeight( ((SvxWeightItem
&)rItem
).GetWeight(), SW_CTL
);
825 case RES_CHRATR_EMPHASIS_MARK
:
826 rFnt
.SetEmphasisMark(
827 ((SvxEmphasisMarkItem
&)rItem
).GetEmphasisMark()
830 case RES_CHRATR_SCALEW
:
831 rFnt
.SetPropWidth( ((SvxCharScaleWidthItem
&)rItem
).GetValue() );
833 case RES_CHRATR_RELIEF
:
834 rFnt
.SetRelief( (FontRelief
)((SvxCharReliefItem
&)rItem
).GetValue() );
836 case RES_CHRATR_HIDDEN
:
837 if( mpShell
&& mpShell
->GetWin())
839 if ( ((SvxCharHiddenItem
&)rItem
).GetValue() )
840 rFnt
.SetUnderline( UNDERLINE_DOTTED
);
842 ActivateTop( rFnt
, RES_CHRATR_UNDERLINE
);
845 case RES_CHRATR_ROTATE
:
847 // rotate attribute is applied, when:
848 // 1. ruby stack is empty and
849 // 2. top of two line stack ( or default attribute )is an
850 // deactivated two line attribute
852 0 != aAttrStack
[ StackPos
[ RES_TXTATR_CJK_RUBY
] ].Count();
857 USHORT nTwoLineStack
= StackPos
[ RES_CHRATR_TWO_LINES
];
858 sal_Bool bTwoLineAct
= sal_False
;
859 const SfxPoolItem
* pTwoLineItem
= 0;
860 const SwTxtAttr
* pTwoLineAttr
= aAttrStack
[ nTwoLineStack
].Top();
864 pTwoLineItem
= CharFmt::GetItem( *pTwoLineAttr
, RES_CHRATR_TWO_LINES
);
865 bTwoLineAct
= ((SvxTwoLinesItem
*)pTwoLineItem
)->GetValue();
869 ((SvxTwoLinesItem
*)pDefaultArray
[ nTwoLineStack
])->GetValue();
872 rFnt
.SetVertical( ((SvxCharRotateItem
&)rItem
).GetValue(),
877 case RES_CHRATR_TWO_LINES
:
879 sal_Bool bRuby
= 0 !=
880 aAttrStack
[ StackPos
[ RES_TXTATR_CJK_RUBY
] ].Count();
881 sal_Bool bTwoLineAct
= sal_False
;
883 // two line is activated, if
884 // 1. no ruby attribute is set and
885 // 2. attribute is active
886 bTwoLineAct
= ((SvxTwoLinesItem
&)rItem
).GetValue();
888 if ( !bRuby
&& bTwoLineAct
)
890 rFnt
.SetVertical( 0, bVertLayout
);
894 // a deactivating two line attribute is on top of stack,
895 // check if rotate attribute has to be enabled
899 USHORT nRotateStack
= StackPos
[ RES_CHRATR_ROTATE
];
900 const SfxPoolItem
* pRotateItem
= 0;
901 const SwTxtAttr
* pRotateAttr
= aAttrStack
[ nRotateStack
].Top();
905 pRotateItem
= CharFmt::GetItem( *pRotateAttr
, RES_CHRATR_ROTATE
);
906 rFnt
.SetVertical( ((SvxCharRotateItem
*)pRotateItem
)->GetValue(),
911 ((SvxCharRotateItem
*)pDefaultArray
[ nRotateStack
])->GetValue(),
916 case RES_TXTATR_CJK_RUBY
:
917 rFnt
.SetVertical( 0, bVertLayout
);
919 case RES_TXTATR_REFMARK
:
925 case RES_TXTATR_TOXMARK
:
934 // Takes the default font and calculated the ascent and height
935 void SwAttrHandler::GetDefaultAscentAndHeight( ViewShell
* pShell
, OutputDevice
& rOut
,
936 USHORT
& nAscent
, USHORT
& nHeight
) const
938 ASSERT( pFnt
, "No font available for GetDefaultAscentAndHeight" )
942 SwFont
aFont( *pFnt
);
943 nHeight
= aFont
.GetHeight( pShell
, rOut
);
944 nAscent
= aFont
.GetAscent( pShell
, rOut
);