Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <atrhndl.hxx>
21 : #include <svl/itemiter.hxx>
22 : #include <vcl/outdev.hxx>
23 : #include <editeng/cmapitem.hxx>
24 : #include <editeng/colritem.hxx>
25 : #include <editeng/cntritem.hxx>
26 : #include <editeng/crsditem.hxx>
27 : #include <editeng/escpitem.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/akrnitem.hxx>
39 : #include <editeng/blnkitem.hxx>
40 : #include <editeng/charrotateitem.hxx>
41 : #include <editeng/emphitem.hxx>
42 : #include <editeng/charscaleitem.hxx>
43 : #include <editeng/twolinesitem.hxx>
44 : #include <editeng/charhiddenitem.hxx>
45 : #include <viewopt.hxx>
46 : #include <charfmt.hxx>
47 : #include <fchrfmt.hxx>
48 : #include <fmtautofmt.hxx>
49 : #include <editeng/brshitem.hxx>
50 : #include <fmtinfmt.hxx>
51 : #include <txtinet.hxx>
52 : #include <IDocumentSettingAccess.hxx>
53 : #include <viewsh.hxx> // ViewShell
54 : #include <viewopt.hxx> // SwViewOptions
55 :
56 : #define STACK_INCREMENT 4
57 :
58 : /*************************************************************************
59 : * Attribute to Stack Mapping
60 : *
61 : * Attributes applied to a text are pushed on different stacks. For each
62 : * stack, the top most attribute on the stack is valid. Because some
63 : * kinds of attributes have to be pushed to the same stacks we map their
64 : * ids to stack ids
65 : * Attention: The first NUM_DEFAULT_VALUES ( defined in swfntcch.hxx == 35 )
66 : * are stored in the defaultitem-cache, if you add one, you have to increase
67 : * NUM_DEFAULT_VALUES.
68 : * Also adjust NUM_ATTRIBUTE_STACKS in atrhndl.hxx.
69 : *************************************************************************/
70 :
71 : const sal_uInt8 StackPos[ static_cast<sal_uInt16>(RES_TXTATR_WITHEND_END) -
72 : static_cast<sal_uInt16>(RES_CHRATR_BEGIN) + 1 ] =
73 : {
74 : 0, // // 0
75 : 1, // RES_CHRATR_CASEMAP = RES_CHRATR_BEGIN // 1
76 : 0, // RES_CHRATR_CHARSETCOLOR, // 2
77 : 2, // RES_CHRATR_COLOR, // 3
78 : 3, // RES_CHRATR_CONTOUR, // 4
79 : 4, // RES_CHRATR_CROSSEDOUT, // 5
80 : 5, // RES_CHRATR_ESCAPEMENT, // 6
81 : 6, // RES_CHRATR_FONT, // 7
82 : 7, // RES_CHRATR_FONTSIZE, // 8
83 : 8, // RES_CHRATR_KERNING, // 9
84 : 9, // RES_CHRATR_LANGUAGE, // 10
85 : 10, // RES_CHRATR_POSTURE, // 11
86 : 0, // RES_CHRATR_PROPORTIONALFONTSIZE, // 12
87 : 11, // RES_CHRATR_SHADOWED, // 13
88 : 12, // RES_CHRATR_UNDERLINE, // 14
89 : 13, // RES_CHRATR_WEIGHT, // 15
90 : 14, // RES_CHRATR_WORDLINEMODE, // 16
91 : 15, // RES_CHRATR_AUTOKERN, // 17
92 : 16, // RES_CHRATR_BLINK, // 18
93 : 17, // RES_CHRATR_NOHYPHEN, // 19
94 : 0, // RES_CHRATR_NOLINEBREAK, // 20
95 : 18, // RES_CHRATR_BACKGROUND, // 21
96 : 19, // RES_CHRATR_CJK_FONT, // 22
97 : 20, // RES_CHRATR_CJK_FONTSIZE, // 23
98 : 21, // RES_CHRATR_CJK_LANGUAGE, // 24
99 : 22, // RES_CHRATR_CJK_POSTURE, // 25
100 : 23, // RES_CHRATR_CJK_WEIGHT, // 26
101 : 24, // RES_CHRATR_CTL_FONT, // 27
102 : 25, // RES_CHRATR_CTL_FONTSIZE, // 28
103 : 26, // RES_CHRATR_CTL_LANGUAGE, // 29
104 : 27, // RES_CHRATR_CTL_POSTURE, // 30
105 : 28, // RES_CHRATR_CTL_WEIGHT, // 31
106 : 29, // RES_CHRATR_ROTATE, // 32
107 : 30, // RES_CHRATR_EMPHASIS_MARK, // 33
108 : 31, // RES_CHRATR_TWO_LINES, // 34
109 : 32, // RES_CHRATR_SCALEW, // 35
110 : 33, // RES_CHRATR_RELIEF, // 36
111 : 34, // RES_CHRATR_HIDDEN, // 37
112 : 35, // RES_CHRATR_OVERLINE, // 38
113 : 0, // RES_CHRATR_RSID, // 39
114 : 0, // RES_DUMMY1, // 40
115 : 36, // RES_TXTATR_REFMARK, // 41
116 : 37, // RES_TXTATR_TOXMARK, // 42
117 : 38, // RES_TXTATR_META, // 43
118 : 38, // RES_TXTATR_METAFIELD, // 44
119 : 0, // RES_TXTATR_AUTOFMT, // 45
120 : 0, // RES_TXTATR_INETFMT // 46
121 : 0, // RES_TXTATR_CHARFMT, // 47
122 : 39, // RES_TXTATR_CJK_RUBY, // 48
123 : 0, // RES_TXTATR_UNKNOWN_CONTAINER, // 49
124 : 0, // RES_TXTATR_DUMMY5 // 50
125 : };
126 :
127 : /*************************************************************************
128 : * CharFmt::GetItem
129 : * returns the item set associated with an character/inet/auto style
130 : *************************************************************************/
131 :
132 : namespace CharFmt
133 : {
134 :
135 19641 : const SfxItemSet* GetItemSet( const SfxPoolItem& rAttr )
136 : {
137 19641 : const SfxItemSet* pSet = 0;
138 :
139 19641 : if ( RES_TXTATR_AUTOFMT == rAttr.Which() )
140 : {
141 19350 : pSet = static_cast<const SwFmtAutoFmt&>(rAttr).GetStyleHandle().get();
142 : }
143 : else
144 : {
145 : // Get the attributes from the template
146 291 : SwCharFmt* pFmt = RES_TXTATR_INETFMT == rAttr.Which() ?
147 104 : ((SwFmtINetFmt&)rAttr).GetTxtINetFmt()->GetCharFmt() :
148 395 : ((SwFmtCharFmt&)rAttr).GetCharFmt();
149 291 : if( pFmt )
150 : {
151 291 : pSet = &pFmt->GetAttrSet();
152 : }
153 : }
154 :
155 19641 : return pSet;
156 : }
157 :
158 : /*************************************************************************
159 : * CharFmt::GetItem
160 : * extracts pool item of type nWhich from rAttr
161 : *************************************************************************/
162 :
163 12879 : const SfxPoolItem* GetItem( const SwTxtAttr& rAttr, sal_uInt16 nWhich )
164 : {
165 38489 : if ( RES_TXTATR_INETFMT == rAttr.Which() ||
166 12833 : RES_TXTATR_CHARFMT == rAttr.Which() ||
167 12777 : RES_TXTATR_AUTOFMT == rAttr.Which() )
168 : {
169 12323 : const SfxItemSet* pSet = CharFmt::GetItemSet( rAttr.GetAttr() );
170 12323 : if ( !pSet ) return 0;
171 :
172 12323 : bool bInParent = RES_TXTATR_AUTOFMT != rAttr.Which();
173 : const SfxPoolItem* pItem;
174 12323 : bool bRet = SFX_ITEM_SET == pSet->GetItemState( nWhich, bInParent, &pItem );
175 :
176 12323 : return bRet ? pItem : 0;
177 : }
178 :
179 556 : return ( nWhich == rAttr.Which() ) ? &rAttr.GetAttr() : 0;
180 : }
181 :
182 : /*************************************************************************
183 : * CharFmt::IsItemIncluded
184 : * checks if item is included in character/inet/auto style
185 : *************************************************************************/
186 :
187 2865 : bool IsItemIncluded( const sal_uInt16 nWhich, const SwTxtAttr *pAttr )
188 : {
189 2865 : bool bRet = false;
190 :
191 2865 : const SfxItemSet* pItemSet = CharFmt::GetItemSet( pAttr->GetAttr() );
192 2865 : if ( pItemSet )
193 2865 : bRet = SFX_ITEM_SET == pItemSet->GetItemState( nWhich, sal_True );
194 :
195 2865 : return bRet;
196 : }
197 :
198 : }
199 :
200 : /*************************************************************************
201 : * lcl_ChgHyperLinkColor
202 : * The color of hyperlinks is taken from the associated character attribute,
203 : * depending on its 'visited' state. There are actually two cases, which
204 : * should override the colors from the character attribute:
205 : * 1. We never take the 'visited' color during printing/pdf export/preview
206 : * 2. The user has choosen to override these colors in the view options
207 : *************************************************************************/
208 :
209 2375 : static bool lcl_ChgHyperLinkColor( const SwTxtAttr& rAttr,
210 : const SfxPoolItem& rItem,
211 : const ViewShell* pShell,
212 : Color* pColor )
213 : {
214 4825 : if ( !pShell ||
215 2375 : RES_TXTATR_INETFMT != rAttr.Which() ||
216 75 : RES_CHRATR_COLOR != rItem.Which() )
217 2360 : return false;
218 :
219 : // #i15455#
220 : // 1. case:
221 : // We do not want to show visited links:
222 : // (printing, pdf export, page preview)
223 : //
224 45 : if ( pShell->GetOut()->GetOutDevType() == OUTDEV_PRINTER ||
225 15 : pShell->GetViewOptions()->IsPDFExport() ||
226 15 : pShell->GetViewOptions()->IsPagePreview() )
227 : {
228 0 : if ( ((SwTxtINetFmt&)rAttr).IsVisited() )
229 : {
230 0 : if ( pColor )
231 : {
232 : // take color from character format 'unvisited link'
233 : SwTxtINetFmt& rInetAttr( const_cast<SwTxtINetFmt&>(
234 0 : static_cast<const SwTxtINetFmt&>(rAttr)) );
235 0 : rInetAttr.SetVisited( false );
236 0 : const SwCharFmt* pTmpFmt = ((SwTxtINetFmt&)rAttr).GetCharFmt();
237 : const SfxPoolItem* pItem;
238 0 : pTmpFmt->GetItemState( RES_CHRATR_COLOR, sal_True, &pItem );
239 0 : *pColor = ((SvxColorItem*)pItem)->GetValue();
240 0 : rInetAttr.SetVisited( true );
241 : }
242 0 : return true;
243 : }
244 :
245 0 : return false;
246 : }
247 :
248 : //
249 : // 2. case:
250 : // We do not want to apply the color set in the hyperlink
251 : // attribute, instead we take the colors from the view options:
252 : //
253 60 : if ( pShell->GetWin() &&
254 : (
255 15 : (((SwTxtINetFmt&)rAttr).IsVisited() && SwViewOption::IsVisitedLinks()) ||
256 30 : (!((SwTxtINetFmt&)rAttr).IsVisited() && SwViewOption::IsLinks())
257 : )
258 : )
259 : {
260 0 : if ( pColor )
261 : {
262 0 : if ( ((SwTxtINetFmt&)rAttr).IsVisited() )
263 : {
264 : // take color from view option 'visited link color'
265 0 : *pColor = SwViewOption::GetVisitedLinksColor();
266 : }
267 : else
268 : {
269 : // take color from view option 'unvisited link color'
270 0 : *pColor = SwViewOption::GetLinksColor();
271 : }
272 : }
273 0 : return true;
274 : }
275 :
276 15 : return false;
277 : }
278 :
279 : /*************************************************************************
280 : * SwAttrHandler::SwAttrStack::SwAttrStack()
281 : *************************************************************************/
282 :
283 166360 : inline SwAttrHandler::SwAttrStack::SwAttrStack()
284 166360 : : nCount( 0 ), nSize( INITIAL_NUM_ATTR )
285 : {
286 166360 : pArray = pInitialArray;
287 166360 : }
288 :
289 : /*************************************************************************
290 : * SwAttrHandler::SwAttrStack::Insert()
291 : *************************************************************************/
292 :
293 2288 : void SwAttrHandler::SwAttrStack::Insert( const SwTxtAttr& rAttr, const sal_uInt16 nPos )
294 : {
295 : // do we still have enough space?
296 2288 : if ( nCount >= nSize )
297 : {
298 : // we are still in our initial array
299 0 : if ( INITIAL_NUM_ATTR == nSize )
300 : {
301 0 : nSize += STACK_INCREMENT;
302 0 : pArray = new SwTxtAttr*[ nSize ];
303 : // copy from pInitArray to new Array
304 : memcpy( pArray, pInitialArray,
305 : INITIAL_NUM_ATTR * sizeof(SwTxtAttr*)
306 0 : );
307 : }
308 : // we are in new memory
309 : else
310 : {
311 0 : nSize += STACK_INCREMENT;
312 0 : SwTxtAttr** pTmpArray = new SwTxtAttr*[ nSize ];
313 : // copy from pArray to new Array
314 0 : memcpy( pTmpArray, pArray, nCount * sizeof(SwTxtAttr*) );
315 : // free old array
316 0 : delete [] pArray;
317 0 : pArray = pTmpArray;
318 : }
319 : }
320 :
321 : OSL_ENSURE( nPos <= nCount, "wrong position for insert operation");
322 :
323 2288 : if ( nPos < nCount )
324 0 : memmove( pArray + nPos + 1, pArray + nPos,
325 : ( nCount - nPos ) * sizeof(SwTxtAttr*)
326 0 : );
327 2288 : pArray[ nPos ] = (SwTxtAttr*)&rAttr;
328 :
329 2288 : nCount++;
330 2288 : }
331 :
332 : /*************************************************************************
333 : * SwAttrHandler::SwAttrStack::Remove()
334 : *************************************************************************/
335 :
336 129 : void SwAttrHandler::SwAttrStack::Remove( const SwTxtAttr& rAttr )
337 : {
338 129 : sal_uInt16 nPos = Pos( rAttr );
339 129 : if ( nPos < nCount )
340 : {
341 387 : memmove( pArray + nPos, pArray + nPos + 1,
342 : ( nCount - 1 - nPos ) * sizeof(SwTxtAttr*)
343 516 : );
344 129 : nCount--;
345 : }
346 129 : }
347 :
348 : /*************************************************************************
349 : * SwAttrHandler::SwAttrStack::Top()
350 : *************************************************************************/
351 :
352 2489 : const SwTxtAttr* SwAttrHandler::SwAttrStack::Top() const
353 : {
354 2489 : return nCount ? pArray[ nCount - 1 ] : 0;
355 : }
356 :
357 : /*************************************************************************
358 : * SwAttrHandler::SwAttrStack::Pos()
359 : *************************************************************************/
360 :
361 129 : sal_uInt16 SwAttrHandler::SwAttrStack::Pos( const SwTxtAttr& rAttr ) const
362 : {
363 129 : if ( ! nCount )
364 : // empty stack
365 0 : return USHRT_MAX;
366 :
367 265 : for ( sal_uInt16 nIdx = nCount; nIdx > 0; )
368 : {
369 136 : if ( &rAttr == pArray[ --nIdx ] )
370 129 : return nIdx;
371 : }
372 :
373 : // element not found
374 0 : return USHRT_MAX;
375 : }
376 :
377 : /*************************************************************************
378 : * SwAttrHandler::SwAttrHandler()
379 : *************************************************************************/
380 :
381 4159 : SwAttrHandler::SwAttrHandler() : mpShell( 0 ), pFnt( 0 ), bVertLayout( sal_False )
382 :
383 : {
384 4159 : memset( pDefaultArray, 0, NUM_DEFAULT_VALUES * sizeof(SfxPoolItem*) );
385 4159 : }
386 :
387 174678 : SwAttrHandler::~SwAttrHandler()
388 : {
389 4159 : delete pFnt;
390 170519 : }
391 :
392 : /*************************************************************************
393 : * SwAttrHandler::Init()
394 : *************************************************************************/
395 :
396 0 : void SwAttrHandler::Init( const SwAttrSet& rAttrSet,
397 : const IDocumentSettingAccess& rIDocumentSettingAcces,
398 : const ViewShell* pSh )
399 : {
400 0 : mpIDocumentSettingAccess = &rIDocumentSettingAcces;
401 0 : mpShell = pSh;
402 :
403 0 : for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++ )
404 0 : pDefaultArray[ StackPos[ i ] ] = &rAttrSet.Get( i, sal_True );
405 0 : }
406 :
407 4159 : void SwAttrHandler::Init( const SfxPoolItem** pPoolItem, const SwAttrSet* pAS,
408 : const IDocumentSettingAccess& rIDocumentSettingAcces,
409 : const ViewShell* pSh,
410 : SwFont& rFnt, sal_Bool bVL )
411 : {
412 : // initialize default array
413 : memcpy( pDefaultArray, pPoolItem,
414 4159 : NUM_DEFAULT_VALUES * sizeof(SfxPoolItem*) );
415 :
416 4159 : mpIDocumentSettingAccess = &rIDocumentSettingAcces;
417 4159 : mpShell = pSh;
418 :
419 : // do we have to apply additional paragraph attributes?
420 4159 : bVertLayout = bVL;
421 :
422 4159 : if ( pAS && pAS->Count() )
423 : {
424 3184 : SfxItemIter aIter( *pAS );
425 : sal_uInt16 nWhich;
426 3184 : const SfxPoolItem* pItem = aIter.GetCurItem();
427 8714 : while( true )
428 : {
429 11898 : nWhich = pItem->Which();
430 11898 : if (isCHRATR(nWhich))
431 : {
432 350 : pDefaultArray[ StackPos[ nWhich ] ] = pItem;
433 350 : FontChg( *pItem, rFnt, sal_True );
434 : }
435 :
436 11898 : if( aIter.IsAtEnd() )
437 3184 : break;
438 :
439 8714 : pItem = aIter.NextItem();
440 3184 : }
441 : }
442 :
443 : // It is possible, that Init is called more than once, e.g., in a
444 : // SwTxtFrm::FormatOnceMore situation.
445 4159 : delete pFnt;
446 4159 : pFnt = new SwFont( rFnt );
447 4159 : }
448 :
449 738 : void SwAttrHandler::Reset( )
450 : {
451 30258 : for ( sal_uInt16 i = 0; i < NUM_ATTRIBUTE_STACKS; i++ )
452 29520 : aAttrStack[ i ].Reset();
453 738 : }
454 :
455 : /*************************************************************************
456 : * SwAttrHandler::PushAndChg()
457 : *************************************************************************/
458 :
459 485 : void SwAttrHandler::PushAndChg( const SwTxtAttr& rAttr, SwFont& rFnt )
460 : {
461 : // these special attributes in fact represent a collection of attributes
462 : // they have to be pushed to each stack they belong to
463 1402 : if ( RES_TXTATR_INETFMT == rAttr.Which() ||
464 470 : RES_TXTATR_CHARFMT == rAttr.Which() ||
465 447 : RES_TXTATR_AUTOFMT == rAttr.Which() )
466 : {
467 475 : const SfxItemSet* pSet = CharFmt::GetItemSet( rAttr.GetAttr() );
468 960 : if ( !pSet ) return;
469 :
470 19475 : for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
471 : {
472 : const SfxPoolItem* pItem;
473 19000 : bool bRet = SFX_ITEM_SET == pSet->GetItemState( i, rAttr.Which() != RES_TXTATR_AUTOFMT, &pItem );
474 :
475 19000 : if ( bRet )
476 : {
477 : // we push rAttr onto the appropriate stack
478 2278 : if ( Push( rAttr, *pItem ) )
479 : {
480 : // we let pItem change rFnt
481 2278 : Color aColor;
482 2278 : if ( lcl_ChgHyperLinkColor( rAttr, *pItem, mpShell, &aColor ) )
483 : {
484 0 : SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
485 0 : FontChg( aItemNext, rFnt, sal_True );
486 : }
487 : else
488 2278 : FontChg( *pItem, rFnt, sal_True );
489 : }
490 : }
491 : }
492 : }
493 : // this is the usual case, we have a basic attribute, push it onto the
494 : // stack and change the font
495 : else
496 : {
497 10 : if ( Push( rAttr, rAttr.GetAttr() ) )
498 : // we let pItem change rFnt
499 10 : FontChg( rAttr.GetAttr(), rFnt, sal_True );
500 : }
501 : }
502 :
503 : /*************************************************************************
504 : * SwAttrHandler::Push()
505 : *************************************************************************/
506 :
507 2288 : sal_Bool SwAttrHandler::Push( const SwTxtAttr& rAttr, const SfxPoolItem& rItem )
508 : {
509 : OSL_ENSURE( rItem.Which() < RES_TXTATR_WITHEND_END,
510 : "I do not want this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
511 :
512 : // robust
513 2288 : if ( RES_TXTATR_WITHEND_END <= rItem.Which() )
514 0 : return sal_False;
515 :
516 2288 : sal_uInt16 nStack = StackPos[ rItem.Which() ];
517 :
518 : // attributes originating from redlining have highest priority
519 : // second priority are hyperlink attributes, which have a color replacement
520 2288 : const SwTxtAttr* pTopAttr = aAttrStack[ nStack ].Top();
521 2408 : if ( !pTopAttr || rAttr.IsPriorityAttr() ||
522 60 : ( !pTopAttr->IsPriorityAttr() &&
523 60 : !lcl_ChgHyperLinkColor( *pTopAttr, rItem, mpShell, 0 ) ) )
524 : {
525 2288 : aAttrStack[ nStack ].Push( rAttr );
526 2288 : return sal_True;
527 : }
528 :
529 0 : sal_uInt16 nPos = aAttrStack[ nStack ].Count();
530 : OSL_ENSURE( nPos, "empty stack?" );
531 0 : aAttrStack[ nStack ].Insert( rAttr, nPos - 1 );
532 0 : return sal_False;
533 : }
534 :
535 : /*************************************************************************
536 : * SwAttrHandler::PopAndChg()
537 : *************************************************************************/
538 :
539 65 : void SwAttrHandler::PopAndChg( const SwTxtAttr& rAttr, SwFont& rFnt )
540 : {
541 65 : if ( RES_TXTATR_WITHEND_END <= rAttr.Which() )
542 0 : return; // robust
543 :
544 : // these special attributes in fact represent a collection of attributes
545 : // they have to be removed from each stack they belong to
546 159 : if ( RES_TXTATR_INETFMT == rAttr.Which() ||
547 56 : RES_TXTATR_CHARFMT == rAttr.Which() ||
548 38 : RES_TXTATR_AUTOFMT == rAttr.Which() )
549 : {
550 55 : const SfxItemSet* pSet = CharFmt::GetItemSet( rAttr.GetAttr() );
551 55 : if ( !pSet ) return;
552 :
553 2255 : for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
554 : {
555 : const SfxPoolItem* pItem;
556 2200 : bool bRet = SFX_ITEM_SET == pSet->GetItemState( i, RES_TXTATR_AUTOFMT != rAttr.Which(), &pItem );
557 2200 : if ( bRet )
558 : {
559 : // we remove rAttr from the appropriate stack
560 119 : sal_uInt16 nStackPos = StackPos[ i ];
561 119 : aAttrStack[ nStackPos ].Remove( rAttr );
562 : // reset font according to attribute on top of stack
563 : // or default value
564 119 : ActivateTop( rFnt, i );
565 : }
566 : }
567 : }
568 : // this is the usual case, we have a basic attribute, remove it from the
569 : // stack and reset the font
570 : else
571 : {
572 10 : aAttrStack[ StackPos[ rAttr.Which() ] ].Remove( rAttr );
573 : // reset font according to attribute on top of stack
574 : // or default value
575 10 : ActivateTop( rFnt, rAttr.Which() );
576 : }
577 : }
578 :
579 : /*************************************************************************
580 : * SwAttrHandler::Pop()
581 : *
582 : * only used during redlining
583 : *************************************************************************/
584 :
585 0 : void SwAttrHandler::Pop( const SwTxtAttr& rAttr )
586 : {
587 : OSL_ENSURE( rAttr.Which() < RES_TXTATR_WITHEND_END,
588 : "I do not have this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
589 :
590 0 : if ( rAttr.Which() < RES_TXTATR_WITHEND_END )
591 : {
592 0 : aAttrStack[ StackPos[ rAttr.Which() ] ].Remove( rAttr );
593 : }
594 0 : }
595 :
596 : /*************************************************************************
597 : * SwAttrHandler::ActivateTop()
598 : *************************************************************************/
599 129 : void SwAttrHandler::ActivateTop( SwFont& rFnt, const sal_uInt16 nAttr )
600 : {
601 : OSL_ENSURE( nAttr < RES_TXTATR_WITHEND_END,
602 : "I cannot activate this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
603 :
604 129 : const sal_uInt16 nStackPos = StackPos[ nAttr ];
605 129 : const SwTxtAttr* pTopAt = aAttrStack[ nStackPos ].Top();
606 129 : if ( pTopAt )
607 : {
608 : // check if top attribute is collection of attributes
609 95 : if ( RES_TXTATR_INETFMT == pTopAt->Which() ||
610 44 : RES_TXTATR_CHARFMT == pTopAt->Which() ||
611 7 : RES_TXTATR_AUTOFMT == pTopAt->Which() )
612 : {
613 37 : const SfxItemSet* pSet = CharFmt::GetItemSet( pTopAt->GetAttr() );
614 : const SfxPoolItem* pItemNext;
615 37 : pSet->GetItemState( nAttr, RES_TXTATR_AUTOFMT != pTopAt->Which(), &pItemNext );
616 :
617 37 : Color aColor;
618 37 : if ( lcl_ChgHyperLinkColor( *pTopAt, *pItemNext, mpShell, &aColor ) )
619 : {
620 0 : SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
621 0 : FontChg( aItemNext, rFnt, sal_False );
622 : }
623 : else
624 37 : FontChg( *pItemNext, rFnt, sal_False );
625 : }
626 : else
627 7 : FontChg( pTopAt->GetAttr(), rFnt, sal_False );
628 : }
629 :
630 : // default value has to be set, we only have default values for char attribs
631 85 : else if ( nStackPos < NUM_DEFAULT_VALUES )
632 85 : FontChg( *pDefaultArray[ nStackPos ], rFnt, sal_False );
633 0 : else if ( RES_TXTATR_REFMARK == nAttr )
634 0 : rFnt.GetRef()--;
635 0 : else if ( RES_TXTATR_TOXMARK == nAttr )
636 0 : rFnt.GetTox()--;
637 0 : else if ( (RES_TXTATR_META == nAttr) || (RES_TXTATR_METAFIELD == nAttr) )
638 : {
639 0 : rFnt.GetMeta()--;
640 : }
641 0 : else if ( RES_TXTATR_CJK_RUBY == nAttr )
642 : {
643 : // ruby stack has no more attributes
644 : // check, if an rotation attribute has to be applied
645 0 : sal_uInt16 nTwoLineStack = StackPos[ RES_CHRATR_TWO_LINES ];
646 0 : sal_Bool bTwoLineAct = sal_False;
647 0 : const SfxPoolItem* pTwoLineItem = 0;
648 0 : const SwTxtAttr* pTwoLineAttr = aAttrStack[ nTwoLineStack ].Top();
649 :
650 0 : if ( pTwoLineAttr )
651 : {
652 0 : pTwoLineItem = CharFmt::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES );
653 0 : bTwoLineAct = ((SvxTwoLinesItem*)pTwoLineItem)->GetValue();
654 : }
655 : else
656 : bTwoLineAct =
657 0 : ((SvxTwoLinesItem*)pDefaultArray[ nTwoLineStack ])->GetValue();
658 :
659 0 : if ( bTwoLineAct )
660 129 : return;
661 :
662 : // eventually, an rotate attribute has to be activated
663 0 : sal_uInt16 nRotateStack = StackPos[ RES_CHRATR_ROTATE ];
664 0 : const SfxPoolItem* pRotateItem = 0;
665 0 : const SwTxtAttr* pRotateAttr = aAttrStack[ nRotateStack ].Top();
666 :
667 0 : if ( pRotateAttr )
668 : {
669 0 : pRotateItem = CharFmt::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
670 0 : rFnt.SetVertical( ((SvxCharRotateItem*)pRotateItem)->GetValue(),
671 0 : bVertLayout );
672 : }
673 : else
674 : rFnt.SetVertical(
675 0 : ((SvxCharRotateItem*)pDefaultArray[ nRotateStack ])->GetValue(),
676 : bVertLayout
677 0 : );
678 : }
679 : }
680 :
681 : /*************************************************************************
682 : * Font Changing Function
683 : *
684 : * When popping an attribute from the stack, the top mose remaining
685 : * attribute in the stack becomes valid. The following function change
686 : * a font depending on the stack id.
687 : *************************************************************************/
688 :
689 2767 : void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, sal_Bool bPush )
690 : {
691 2767 : switch ( rItem.Which() )
692 : {
693 : case RES_CHRATR_CASEMAP :
694 4 : rFnt.SetCaseMap( ((SvxCaseMapItem&)rItem).GetCaseMap() );
695 4 : break;
696 : case RES_CHRATR_COLOR :
697 111 : rFnt.SetColor( ((SvxColorItem&)rItem).GetValue() );
698 111 : break;
699 : case RES_CHRATR_CONTOUR :
700 0 : rFnt.SetOutline( ((SvxContourItem&)rItem).GetValue() );
701 0 : break;
702 : case RES_CHRATR_CROSSEDOUT :
703 24 : rFnt.SetStrikeout( ((SvxCrossedOutItem&)rItem).GetStrikeout() );
704 24 : break;
705 : case RES_CHRATR_ESCAPEMENT :
706 27 : rFnt.SetEscapement( ((SvxEscapementItem&)rItem).GetEsc() );
707 27 : rFnt.SetProportion( ((SvxEscapementItem&)rItem).GetProp() );
708 27 : break;
709 : case RES_CHRATR_FONT :
710 270 : rFnt.SetName( ((SvxFontItem&)rItem).GetFamilyName(), SW_LATIN );
711 270 : rFnt.SetStyleName( ((SvxFontItem&)rItem).GetStyleName(), SW_LATIN );
712 270 : rFnt.SetFamily( ((SvxFontItem&)rItem).GetFamily(), SW_LATIN );
713 270 : rFnt.SetPitch( ((SvxFontItem&)rItem).GetPitch(), SW_LATIN );
714 270 : rFnt.SetCharSet( ((SvxFontItem&)rItem).GetCharSet(), SW_LATIN );
715 270 : break;
716 : case RES_CHRATR_FONTSIZE :
717 324 : rFnt.SetSize(Size(0,((SvxFontHeightItem&)rItem).GetHeight() ), SW_LATIN );
718 324 : break;
719 : case RES_CHRATR_KERNING :
720 2 : rFnt.SetFixKerning( ((SvxKerningItem&)rItem).GetValue() );
721 2 : break;
722 : case RES_CHRATR_LANGUAGE :
723 371 : rFnt.SetLanguage( ((SvxLanguageItem&)rItem).GetLanguage(), SW_LATIN );
724 371 : break;
725 : case RES_CHRATR_POSTURE :
726 30 : rFnt.SetItalic( ((SvxPostureItem&)rItem).GetPosture(), SW_LATIN );
727 30 : break;
728 : case RES_CHRATR_SHADOWED :
729 0 : rFnt.SetShadow( ((SvxShadowedItem&)rItem).GetValue() );
730 0 : break;
731 : case RES_CHRATR_UNDERLINE :
732 : {
733 72 : const sal_uInt16 nStackPos = StackPos[ RES_CHRATR_HIDDEN ];
734 72 : const SwTxtAttr* pTopAt = aAttrStack[ nStackPos ].Top();
735 :
736 : const SfxPoolItem* pTmpItem = pTopAt ?
737 : CharFmt::GetItem( *pTopAt, RES_CHRATR_HIDDEN ) :
738 72 : pDefaultArray[ nStackPos ];
739 :
740 144 : if( (mpShell && !mpShell->GetWin()) ||
741 72 : (pTmpItem && !static_cast<const SvxCharHiddenItem*>(pTmpItem)->GetValue()) )
742 : {
743 72 : rFnt.SetUnderline( ((SvxUnderlineItem&)rItem).GetLineStyle() );
744 72 : rFnt.SetUnderColor( ((SvxUnderlineItem&)rItem).GetColor() );
745 : }
746 72 : break;
747 : }
748 : case RES_CHRATR_OVERLINE :
749 0 : rFnt.SetOverline( ((SvxOverlineItem&)rItem).GetLineStyle() );
750 0 : rFnt.SetOverColor( ((SvxOverlineItem&)rItem).GetColor() );
751 0 : break;
752 : case RES_CHRATR_WEIGHT :
753 31 : rFnt.SetWeight( ((SvxWeightItem&)rItem).GetWeight(), SW_LATIN );
754 31 : break;
755 : case RES_CHRATR_WORDLINEMODE :
756 0 : rFnt.SetWordLineMode( ((SvxWordLineModeItem&)rItem).GetValue() );
757 0 : break;
758 : case RES_CHRATR_AUTOKERN :
759 0 : if( ((SvxAutoKernItem&)rItem).GetValue() )
760 : {
761 0 : rFnt.SetAutoKern( ( !mpIDocumentSettingAccess ||
762 0 : !mpIDocumentSettingAccess->get(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION) ) ?
763 : KERNING_FONTSPECIFIC :
764 0 : KERNING_ASIAN );
765 : }
766 : else
767 0 : rFnt.SetAutoKern( 0 );
768 0 : break;
769 : case RES_CHRATR_BLINK :
770 0 : rFnt.SetBlink( ((SvxBlinkItem&)rItem).GetValue() );
771 0 : break;
772 : case RES_CHRATR_BACKGROUND :
773 13 : rFnt.SetBackColor(new Color( ((SvxBrushItem&)rItem).GetColor() ) );
774 13 : break;
775 : case RES_CHRATR_CJK_FONT :
776 149 : rFnt.SetName( ((SvxFontItem&)rItem).GetFamilyName(), SW_CJK );
777 149 : rFnt.SetStyleName( ((SvxFontItem&)rItem).GetStyleName(), SW_CJK );
778 149 : rFnt.SetFamily( ((SvxFontItem&)rItem).GetFamily(), SW_CJK );
779 149 : rFnt.SetPitch( ((SvxFontItem&)rItem).GetPitch(), SW_CJK );
780 149 : rFnt.SetCharSet( ((SvxFontItem&)rItem).GetCharSet(), SW_CJK );
781 149 : break;
782 : case RES_CHRATR_CJK_FONTSIZE :
783 322 : rFnt.SetSize(Size( 0, ((SvxFontHeightItem&)rItem).GetHeight()), SW_CJK);
784 322 : break;
785 : case RES_CHRATR_CJK_LANGUAGE :
786 247 : rFnt.SetLanguage( ((SvxLanguageItem&)rItem).GetLanguage(), SW_CJK );
787 247 : break;
788 : case RES_CHRATR_CJK_POSTURE :
789 30 : rFnt.SetItalic( ((SvxPostureItem&)rItem).GetPosture(), SW_CJK );
790 30 : break;
791 : case RES_CHRATR_CJK_WEIGHT :
792 31 : rFnt.SetWeight( ((SvxWeightItem&)rItem).GetWeight(), SW_CJK );
793 31 : break;
794 : case RES_CHRATR_CTL_FONT :
795 202 : rFnt.SetName( ((SvxFontItem&)rItem).GetFamilyName(), SW_CTL );
796 202 : rFnt.SetStyleName( ((SvxFontItem&)rItem).GetStyleName(), SW_CTL );
797 202 : rFnt.SetFamily( ((SvxFontItem&)rItem).GetFamily(), SW_CTL );
798 202 : rFnt.SetPitch( ((SvxFontItem&)rItem).GetPitch(), SW_CTL );
799 202 : rFnt.SetCharSet( ((SvxFontItem&)rItem).GetCharSet(), SW_CTL );
800 202 : break;
801 : case RES_CHRATR_CTL_FONTSIZE :
802 205 : rFnt.SetSize(Size(0, ((SvxFontHeightItem&)rItem).GetHeight() ), SW_CTL);
803 205 : break;
804 : case RES_CHRATR_CTL_LANGUAGE :
805 240 : rFnt.SetLanguage( ((SvxLanguageItem&)rItem).GetLanguage(), SW_CTL );
806 240 : break;
807 : case RES_CHRATR_CTL_POSTURE :
808 0 : rFnt.SetItalic( ((SvxPostureItem&)rItem).GetPosture(), SW_CTL );
809 0 : break;
810 : case RES_CHRATR_CTL_WEIGHT :
811 10 : rFnt.SetWeight( ((SvxWeightItem&)rItem).GetWeight(), SW_CTL );
812 10 : break;
813 : case RES_CHRATR_EMPHASIS_MARK :
814 : rFnt.SetEmphasisMark(
815 0 : ((SvxEmphasisMarkItem&)rItem).GetEmphasisMark()
816 0 : );
817 0 : break;
818 : case RES_CHRATR_SCALEW :
819 2 : rFnt.SetPropWidth( ((SvxCharScaleWidthItem&)rItem).GetValue() );
820 2 : break;
821 : case RES_CHRATR_RELIEF :
822 0 : rFnt.SetRelief( (FontRelief)((SvxCharReliefItem&)rItem).GetValue() );
823 0 : break;
824 : case RES_CHRATR_HIDDEN :
825 0 : if( mpShell && mpShell->GetWin())
826 : {
827 0 : if ( ((SvxCharHiddenItem&)rItem).GetValue() )
828 0 : rFnt.SetUnderline( UNDERLINE_DOTTED );
829 : else
830 0 : ActivateTop( rFnt, RES_CHRATR_UNDERLINE );
831 : }
832 0 : break;
833 : case RES_CHRATR_ROTATE :
834 : {
835 : // rotate attribute is applied, when:
836 : // 1. ruby stack is empty and
837 : // 2. top of two line stack ( or default attribute )is an
838 : // deactivated two line attribute
839 : const bool bRuby =
840 0 : 0 != aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].Count();
841 :
842 0 : if ( bRuby )
843 0 : break;
844 :
845 0 : sal_uInt16 nTwoLineStack = StackPos[ RES_CHRATR_TWO_LINES ];
846 0 : sal_Bool bTwoLineAct = sal_False;
847 0 : const SfxPoolItem* pTwoLineItem = 0;
848 0 : const SwTxtAttr* pTwoLineAttr = aAttrStack[ nTwoLineStack ].Top();
849 :
850 0 : if ( pTwoLineAttr )
851 : {
852 0 : pTwoLineItem = CharFmt::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES );
853 0 : bTwoLineAct = ((SvxTwoLinesItem*)pTwoLineItem)->GetValue();
854 : }
855 : else
856 : bTwoLineAct =
857 0 : ((SvxTwoLinesItem*)pDefaultArray[ nTwoLineStack ])->GetValue();
858 :
859 0 : if ( !bTwoLineAct )
860 0 : rFnt.SetVertical( ((SvxCharRotateItem&)rItem).GetValue(),
861 0 : bVertLayout );
862 :
863 0 : break;
864 : }
865 : case RES_CHRATR_TWO_LINES :
866 : {
867 : bool bRuby = 0 !=
868 0 : aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].Count();
869 :
870 : // two line is activated, if
871 : // 1. no ruby attribute is set and
872 : // 2. attribute is active
873 0 : sal_Bool bTwoLineAct = ((SvxTwoLinesItem&)rItem).GetValue();
874 :
875 0 : if ( !bRuby && bTwoLineAct )
876 : {
877 0 : rFnt.SetVertical( 0, bVertLayout );
878 0 : break;
879 : }
880 :
881 : // a deactivating two line attribute is on top of stack,
882 : // check if rotate attribute has to be enabled
883 0 : if ( bRuby )
884 0 : break;
885 :
886 0 : sal_uInt16 nRotateStack = StackPos[ RES_CHRATR_ROTATE ];
887 0 : const SfxPoolItem* pRotateItem = 0;
888 0 : const SwTxtAttr* pRotateAttr = aAttrStack[ nRotateStack ].Top();
889 :
890 0 : if ( pRotateAttr )
891 : {
892 0 : pRotateItem = CharFmt::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
893 0 : rFnt.SetVertical( ((SvxCharRotateItem*)pRotateItem)->GetValue(),
894 0 : bVertLayout );
895 : }
896 : else
897 : rFnt.SetVertical(
898 0 : ((SvxCharRotateItem*)pDefaultArray[ nRotateStack ])->GetValue(),
899 : bVertLayout
900 0 : );
901 0 : break;
902 : }
903 : case RES_TXTATR_CJK_RUBY :
904 0 : rFnt.SetVertical( 0, bVertLayout );
905 0 : break;
906 : case RES_TXTATR_REFMARK :
907 0 : if ( bPush )
908 0 : rFnt.GetRef()++;
909 : else
910 0 : rFnt.GetRef()--;
911 0 : break;
912 : case RES_TXTATR_TOXMARK :
913 0 : if ( bPush )
914 0 : rFnt.GetTox()++;
915 : else
916 0 : rFnt.GetTox()--;
917 0 : break;
918 : case RES_TXTATR_META:
919 : case RES_TXTATR_METAFIELD:
920 0 : if ( bPush )
921 0 : rFnt.GetMeta()++;
922 : else
923 0 : rFnt.GetMeta()--;
924 0 : break;
925 : }
926 2767 : }
927 :
928 : // Takes the default font and calculated the ascent and height
929 25 : void SwAttrHandler::GetDefaultAscentAndHeight( ViewShell* pShell, OutputDevice& rOut,
930 : sal_uInt16& nAscent, sal_uInt16& nHeight ) const
931 : {
932 : OSL_ENSURE( pFnt, "No font available for GetDefaultAscentAndHeight" );
933 :
934 25 : if ( pFnt )
935 : {
936 25 : SwFont aFont( *pFnt );
937 25 : nHeight = aFont.GetHeight( pShell, rOut );
938 25 : nAscent = aFont.GetAscent( pShell, rOut );
939 : }
940 25 : }
941 :
942 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|