xref: /aoo42x/main/editeng/source/rtf/rtfitem.cxx (revision 190118d0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 
27 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
28 
29 #include <editeng/flstitem.hxx>
30 #include <editeng/fontitem.hxx>
31 #include <editeng/postitem.hxx>
32 #include <editeng/wghtitem.hxx>
33 #include <editeng/fhgtitem.hxx>
34 #include <editeng/fwdtitem.hxx>
35 #include <editeng/udlnitem.hxx>
36 #include <editeng/crsditem.hxx>
37 #include <editeng/shdditem.hxx>
38 #include <editeng/akrnitem.hxx>
39 #include <editeng/wrlmitem.hxx>
40 #include <editeng/cntritem.hxx>
41 #include <editeng/prszitem.hxx>
42 #include <editeng/colritem.hxx>
43 #include <editeng/cscoitem.hxx>
44 #include <editeng/kernitem.hxx>
45 #include <editeng/cmapitem.hxx>
46 #include <editeng/escpitem.hxx>
47 #include <editeng/langitem.hxx>
48 #include <editeng/nlbkitem.hxx>
49 #include <editeng/nhypitem.hxx>
50 #include <editeng/lcolitem.hxx>
51 #include <editeng/blnkitem.hxx>
52 #include <editeng/emphitem.hxx>
53 #include <editeng/twolinesitem.hxx>
54 #include <editeng/pbinitem.hxx>
55 #include <editeng/sizeitem.hxx>
56 #include <editeng/lrspitem.hxx>
57 #include <editeng/ulspitem.hxx>
58 #include <editeng/prntitem.hxx>
59 #include <editeng/opaqitem.hxx>
60 #include <editeng/protitem.hxx>
61 #include <editeng/shaditem.hxx>
62 #include <editeng/boxitem.hxx>
63 #include <editeng/brkitem.hxx>
64 #include <editeng/keepitem.hxx>
65 #include <editeng/bolnitem.hxx>
66 #include <editeng/brshitem.hxx>
67 #include <editeng/lspcitem.hxx>
68 #include <editeng/adjitem.hxx>
69 #include <editeng/orphitem.hxx>
70 #include <editeng/widwitem.hxx>
71 #include <editeng/tstpitem.hxx>
72 #include <editeng/pmdlitem.hxx>
73 #include <editeng/spltitem.hxx>
74 #include <editeng/hyznitem.hxx>
75 #include <editeng/charscaleitem.hxx>
76 #include <editeng/charrotateitem.hxx>
77 #include <editeng/charreliefitem.hxx>
78 #include <editeng/paravertalignitem.hxx>
79 #include <editeng/forbiddenruleitem.hxx>
80 #include <editeng/hngpnctitem.hxx>
81 #include <editeng/scriptspaceitem.hxx>
82 #include <editeng/frmdiritem.hxx>
83 #include <editeng/charhiddenitem.hxx>
84 
85 #include <svtools/rtftoken.h>
86 #include <svl/itempool.hxx>
87 #include <svl/itemiter.hxx>
88 
89 #include <editeng/svxrtf.hxx>
90 #include <editeng/editids.hrc>
91 
92 #define BRACELEFT	'{'
93 #define BRACERIGHT	'}'
94 
95 
96 // einige Hilfs-Funktionen
97 // char
GetEscapement(const SfxItemSet & rSet,sal_uInt16 nId,sal_Bool bInP=sal_True)98 inline const SvxEscapementItem& GetEscapement(const SfxItemSet& rSet,sal_uInt16 nId,sal_Bool bInP=sal_True)
99 	{ return (const SvxEscapementItem&)rSet.Get( nId,bInP); }
GetLineSpacing(const SfxItemSet & rSet,sal_uInt16 nId,sal_Bool bInP=sal_True)100 inline const SvxLineSpacingItem& GetLineSpacing(const SfxItemSet& rSet,sal_uInt16 nId,sal_Bool bInP=sal_True)
101 	{ return (const SvxLineSpacingItem&)rSet.Get( nId,bInP); }
102 // frm
GetLRSpace(const SfxItemSet & rSet,sal_uInt16 nId,sal_Bool bInP=sal_True)103 inline const SvxLRSpaceItem& GetLRSpace(const SfxItemSet& rSet,sal_uInt16 nId,sal_Bool bInP=sal_True)
104 	{ return (const SvxLRSpaceItem&)rSet.Get( nId,bInP); }
GetULSpace(const SfxItemSet & rSet,sal_uInt16 nId,sal_Bool bInP=sal_True)105 inline const SvxULSpaceItem& GetULSpace(const SfxItemSet& rSet,sal_uInt16 nId,sal_Bool bInP=sal_True)
106 	{ return (const SvxULSpaceItem&)rSet.Get( nId,bInP); }
107 
108 #define PARDID		((RTFPardAttrMapIds*)aPardMap.GetData())
109 #define PLAINID		((RTFPlainAttrMapIds*)aPlainMap.GetData())
110 
SetScriptAttr(RTF_CharTypeDef eType,SfxItemSet & rSet,SfxPoolItem & rItem)111 void SvxRTFParser::SetScriptAttr( RTF_CharTypeDef eType, SfxItemSet& rSet,
112 									SfxPoolItem& rItem )
113 {
114 	const sal_uInt16 *pNormal = 0, *pCJK = 0, *pCTL = 0;
115 	const RTFPlainAttrMapIds* pIds = (RTFPlainAttrMapIds*)aPlainMap.GetData();
116 	switch( rItem.Which() )
117 	{
118 	case SID_ATTR_CHAR_FONT:
119 		pNormal = &pIds->nFont;
120 		pCJK = &pIds->nCJKFont;
121 		pCTL = &pIds->nCTLFont;
122 		break;
123 
124 	case SID_ATTR_CHAR_FONTHEIGHT:
125 		pNormal = &pIds->nFontHeight;
126 		pCJK = &pIds->nCJKFontHeight;
127 		pCTL = &pIds->nCTLFontHeight;
128 		break;
129 
130 	case SID_ATTR_CHAR_POSTURE:
131 		pNormal = &pIds->nPosture;
132 		pCJK = &pIds->nCJKPosture;
133 		pCTL = &pIds->nCTLPosture;
134 		break;
135 
136 	case SID_ATTR_CHAR_WEIGHT:
137 		pNormal = &pIds->nWeight;
138 		pCJK = &pIds->nCJKWeight;
139 		pCTL = &pIds->nCTLWeight;
140 		break;
141 
142 	case SID_ATTR_CHAR_LANGUAGE:
143 		pNormal = &pIds->nLanguage;
144 		pCJK = &pIds->nCJKLanguage;
145 		pCTL = &pIds->nCTLLanguage;
146 		break;
147 
148 	case 0:
149 		// it exist no WhichId - don't set this item
150 		break;
151 
152 	default:
153 	   rSet.Put( rItem );
154 	   break;
155 	}
156 
157 
158 	if( DOUBLEBYTE_CHARTYPE == eType )
159 	{
160 		if( bIsLeftToRightDef && *pCJK )
161 		{
162 			rItem.SetWhich( *pCJK );
163 			rSet.Put( rItem );
164 		}
165 	}
166 	else if( !bIsLeftToRightDef )
167 	{
168 		if( *pCTL )
169 		{
170 			rItem.SetWhich( *pCTL );
171 			rSet.Put( rItem );
172 		}
173 	}
174 	else
175 	{
176 		if( LOW_CHARTYPE == eType )
177 		{
178 			if( *pNormal )
179 			{
180 				rItem.SetWhich( *pNormal );
181 				rSet.Put( rItem );
182 			}
183 		}
184 		else if( HIGH_CHARTYPE == eType )
185 		{
186 			if( *pCTL )
187 			{
188 				rItem.SetWhich( *pCTL );
189 				rSet.Put( rItem );
190 			}
191 		}
192 		else
193 		{
194 			if( *pCJK )
195 			{
196 				rItem.SetWhich( *pCJK );
197 				rSet.Put( rItem );
198 			}
199 			if( *pCTL )
200 			{
201 				rItem.SetWhich( *pCTL );
202 				rSet.Put( rItem );
203 			}
204 			if( *pNormal )
205 			{
206 				rItem.SetWhich( *pNormal );
207 				rSet.Put( rItem );
208 			}
209 		}
210 	}
211 }
212 
213 // --------------------
214 
ReadAttr(int nToken,SfxItemSet * pSet)215 void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet )
216 {
217 	DBG_ASSERT( pSet, "Es muss ein SfxItemSet uebergeben werden!" );
218 	int bFirstToken = sal_True, bWeiter = sal_True;
219 	sal_uInt16 nStyleNo = 0; 		// default
220 	FontUnderline eUnderline;
221 	FontUnderline eOverline;
222 	FontEmphasisMark eEmphasis;
223 	bPardTokenRead = sal_False;
224 	RTF_CharTypeDef eCharType = NOTDEF_CHARTYPE;
225 	sal_uInt16 nFontAlign;
226 
227 	int bChkStkPos = !bNewGroup && !aAttrStack.empty();
228 
229 	while( bWeiter && IsParserWorking() )			// solange bekannte Attribute erkannt werden
230 	{
231 		switch( nToken )
232 		{
233 		case RTF_PARD:
234 			RTFPardPlain( sal_True, &pSet );
235             ResetPard();
236 			nStyleNo = 0;
237 			bPardTokenRead = sal_True;
238 			break;
239 
240 		case RTF_PLAIN:
241 			RTFPardPlain( sal_False, &pSet );
242 			break;
243 
244 		default:
245 			do {		// middle checked loop
246 				if( !bChkStkPos )
247 					break;
248 
249 				SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
250 				if( !pAkt || (pAkt->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
251 					pAkt->nSttCnt == pInsPos->GetCntIdx() ))
252 					break;
253 
254 				int nLastToken = GetStackPtr(-1)->nTokenId;
255 				if( RTF_PARD == nLastToken || RTF_PLAIN == nLastToken )
256 					break;
257 
258 				if( pAkt->aAttrSet.Count() || pAkt->pChildList ||
259 					pAkt->nStyleNo )
260 				{
261 					// eine neue Gruppe aufmachen
262 					SvxRTFItemStackType* pNew = new SvxRTFItemStackType(
263 												*pAkt, *pInsPos, sal_True );
264 					pNew->SetRTFDefaults( GetRTFDefaults() );
265 
266 					// alle bis hierher gueltigen Attribute "setzen"
267 					AttrGroupEnd();
268 					pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();  // can be changed after AttrGroupEnd!
269 					pNew->aAttrSet.SetParent( pAkt ? &pAkt->aAttrSet : 0 );
270 
271 					aAttrStack.push_back( pNew );
272 					pAkt = pNew;
273 				}
274 				else
275 					// diesen Eintrag als neuen weiterbenutzen
276 					pAkt->SetStartPos( *pInsPos );
277 
278 				pSet = &pAkt->aAttrSet;
279 			} while( sal_False );
280 
281 			switch( nToken )
282 			{
283 			case RTF_INTBL:
284 			case RTF_PAGEBB:
285 			case RTF_SBYS:
286 			case RTF_CS:
287 			case RTF_LS:
288 			case RTF_ILVL:
289 					UnknownAttrToken( nToken, pSet );
290 					break;
291 
292 			case RTF_S:
293 				if( bIsInReadStyleTab )
294 				{
295 					if( !bFirstToken )
296 						SkipToken( -1 );
297 					bWeiter = sal_False;
298 				}
299 				else
300 				{
301 					nStyleNo = -1 == nTokenValue ? 0 : sal_uInt16(nTokenValue);
302 					// setze am akt. auf dem AttrStack stehenden Style die
303 					// StyleNummer
304 					SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
305 					if( !pAkt )
306 						break;
307 
308 					pAkt->nStyleNo = sal_uInt16( nStyleNo );
309 
310 #if 0
311 // JP 05.09.95: zuruecksetzen der Style-Attribute fuehrt nur zu Problemen.
312 //				Es muss reichen, wenn das ueber pard/plain erfolgt
313 //	ansonsten Bugdoc 15304.rtf - nach nur "\pard" falscher Font !!
314 
315 					SvxRTFStyleType* pStyle = aStyleTbl.Get( pAkt->nStyleNo );
316 					if( pStyle && pStyle->aAttrSet.Count() )
317 					{
318 						//JP 07.07.95:
319 						// alle Attribute, die in der Vorlage gesetzt werden
320 						// auf defaults setzen. In RTF werden die Attribute
321 						// der Vorlage danach ja wiederholt.
322 						// WICHTIG: Attribute die in der Vorlage definiert
323 						//			sind, werden zurueckgesetzt !!!!
324 						// pAkt->aAttrSet.Put( pStyle->aAttrSet );
325 
326 						SfxItemIter aIter( pStyle->aAttrSet );
327 						SfxItemPool* pPool = pStyle->aAttrSet.GetPool();
328 						sal_uInt16 nWh = aIter.GetCurItem()->Which();
329 						while( sal_True )
330 						{
331 							pAkt->aAttrSet.Put( pPool->GetDefaultItem( nWh ));
332 							if( aIter.IsAtEnd() )
333 								break;
334 							nWh = aIter.NextItem()->Which();
335 						}
336 					}
337 #endif
338 				}
339 				break;
340 
341 			case RTF_KEEP:
342 				if( PARDID->nSplit )
343 				{
344 					pSet->Put( SvxFmtSplitItem( sal_False, PARDID->nSplit ));
345 				}
346 				break;
347 
348 			case RTF_KEEPN:
349 				if( PARDID->nKeep )
350 				{
351 					pSet->Put( SvxFmtKeepItem( sal_True, PARDID->nKeep ));
352 				}
353 				break;
354 
355 			case RTF_LEVEL:
356 				if( PARDID->nOutlineLvl )
357 				{
358 					pSet->Put( SfxUInt16Item( PARDID->nOutlineLvl,
359 												(sal_uInt16)nTokenValue ));
360 				}
361 				break;
362 
363 			case RTF_QL:
364 				if( PARDID->nAdjust )
365 				{
366 					pSet->Put( SvxAdjustItem( SVX_ADJUST_LEFT, PARDID->nAdjust ));
367 				}
368 				break;
369 			case RTF_QR:
370 				if( PARDID->nAdjust )
371 				{
372 					pSet->Put( SvxAdjustItem( SVX_ADJUST_RIGHT, PARDID->nAdjust ));
373 				}
374 				break;
375 			case RTF_QJ:
376 				if( PARDID->nAdjust )
377 				{
378 					pSet->Put( SvxAdjustItem( SVX_ADJUST_BLOCK, PARDID->nAdjust ));
379 				}
380 				break;
381 			case RTF_QC:
382 				if( PARDID->nAdjust )
383 				{
384 					pSet->Put( SvxAdjustItem( SVX_ADJUST_CENTER, PARDID->nAdjust ));
385 				}
386 				break;
387 
388 			case RTF_FI:
389 				if( PARDID->nLRSpace )
390 				{
391 					SvxLRSpaceItem aLR( GetLRSpace(*pSet, PARDID->nLRSpace ));
392 					sal_uInt16 nSz = 0;
393 					if( -1 != nTokenValue )
394 					{
395 						if( IsCalcValue() )
396 							CalcValue();
397 						nSz = sal_uInt16(nTokenValue);
398 					}
399 					aLR.SetTxtFirstLineOfst( nSz );
400 					pSet->Put( aLR );
401 				}
402 				break;
403 
404 			case RTF_LI:
405 			case RTF_LIN:
406 				if( PARDID->nLRSpace )
407 				{
408 					SvxLRSpaceItem aLR( GetLRSpace(*pSet, PARDID->nLRSpace ));
409 					sal_uInt16 nSz = 0;
410 					if( 0 < nTokenValue )
411 					{
412 						if( IsCalcValue() )
413 							CalcValue();
414 						nSz = sal_uInt16(nTokenValue);
415 					}
416 					aLR.SetTxtLeft( nSz );
417 					pSet->Put( aLR );
418 				}
419 				break;
420 
421 			case RTF_RI:
422 			case RTF_RIN:
423 				if( PARDID->nLRSpace )
424 				{
425 					SvxLRSpaceItem aLR( GetLRSpace(*pSet, PARDID->nLRSpace ));
426 					sal_uInt16 nSz = 0;
427 					if( 0 < nTokenValue )
428 					{
429 						if( IsCalcValue() )
430 							CalcValue();
431 						nSz = sal_uInt16(nTokenValue);
432 					}
433 					aLR.SetRight( nSz );
434 					pSet->Put( aLR );
435 				}
436 				break;
437 
438 			case RTF_SB:
439 				if( PARDID->nULSpace )
440 				{
441 					SvxULSpaceItem aUL( GetULSpace(*pSet, PARDID->nULSpace ));
442 					sal_uInt16 nSz = 0;
443 					if( 0 < nTokenValue )
444 					{
445 						if( IsCalcValue() )
446 							CalcValue();
447 						nSz = sal_uInt16(nTokenValue);
448 					}
449 					aUL.SetUpper( nSz );
450 					pSet->Put( aUL );
451 				}
452 				break;
453 
454 			case RTF_SA:
455 				if( PARDID->nULSpace )
456 				{
457 					SvxULSpaceItem aUL( GetULSpace(*pSet, PARDID->nULSpace ));
458 					sal_uInt16 nSz = 0;
459 					if( 0 < nTokenValue )
460 					{
461 						if( IsCalcValue() )
462 							CalcValue();
463 						nSz = sal_uInt16(nTokenValue);
464 					}
465 					aUL.SetLower( nSz );
466 					pSet->Put( aUL );
467 				}
468 				break;
469 
470 			case RTF_SLMULT:
471 				if( PARDID->nLinespacing && 1 == nTokenValue )
472 				{
473 					// dann wird auf mehrzeilig umgeschaltet!
474 					SvxLineSpacingItem aLSpace( GetLineSpacing( *pSet,
475 												PARDID->nLinespacing, sal_False ));
476 
477 					// wieviel bekommt man aus dem LineHeight Wert heraus
478 
479 					// Proportionale-Groesse:
480 					// D.H. das Verhaeltnis ergibt sich aus ( n / 240 ) Twips
481 
482 					nTokenValue = 240;
483 					if( IsCalcValue() )
484 						CalcValue();
485 
486 					nTokenValue = short( 100L * aLSpace.GetLineHeight()
487 											/ long( nTokenValue ) );
488 
489 					if( nTokenValue > 200 )		// Datenwert fuer PropLnSp
490 						nTokenValue = 200;		// ist ein sal_uInt8 !!!
491 
492 					aLSpace.SetPropLineSpace( (const sal_uInt8)nTokenValue );
493 					aLSpace.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
494 
495 					pSet->Put( aLSpace );
496 				}
497 				break;
498 
499 			case RTF_SL:
500 				if( PARDID->nLinespacing )
501 				{
502 					// errechne das Verhaeltnis aus dem default Font zu der
503 					// Size Angabe. Der Abstand besteht aus der Zeilenhoehe
504 					// (100%) und dem Leerraum ueber der Zeile (20%).
505 					SvxLineSpacingItem aLSpace(0, PARDID->nLinespacing);
506 
507 					nTokenValue = !bTokenHasValue ? 0 : nTokenValue;
508 					if (1000 == nTokenValue )
509 						nTokenValue = 240;
510 
511 					SvxLineSpace eLnSpc;
512 					if (nTokenValue < 0)
513 					{
514 						eLnSpc = SVX_LINE_SPACE_FIX;
515 						nTokenValue = -nTokenValue;
516 					}
517 					else if (nTokenValue == 0)
518                     {
519                         //if \sl0 is used, the line spacing is automatically
520                         //determined
521                         eLnSpc = SVX_LINE_SPACE_AUTO;
522                     }
523                     else
524 						eLnSpc = SVX_LINE_SPACE_MIN;
525 
526 					if (IsCalcValue())
527 						CalcValue();
528 
529                     if (eLnSpc != SVX_LINE_SPACE_AUTO)
530 					    aLSpace.SetLineHeight( (const sal_uInt16)nTokenValue );
531 
532 					aLSpace.GetLineSpaceRule() = eLnSpc;
533 					pSet->Put(aLSpace);
534 				}
535 				break;
536 
537 			case RTF_NOCWRAP:
538 				if( PARDID->nForbRule )
539 				{
540 					pSet->Put( SvxForbiddenRuleItem( sal_False,
541 													PARDID->nForbRule ));
542 				}
543 				break;
544 			case RTF_NOOVERFLOW:
545 				if( PARDID->nHangPunct )
546 				{
547 					pSet->Put( SvxHangingPunctuationItem( sal_False,
548 													PARDID->nHangPunct ));
549 				}
550 				break;
551 
552 			case RTF_ASPALPHA:
553 				if( PARDID->nScriptSpace )
554 				{
555 					pSet->Put( SvxScriptSpaceItem( sal_True,
556 												PARDID->nScriptSpace ));
557 				}
558 				break;
559 
560 			case RTF_FAFIXED:
561 			case RTF_FAAUTO:	nFontAlign = SvxParaVertAlignItem::AUTOMATIC;
562 								goto SET_FONTALIGNMENT;
563 			case RTF_FAHANG:	nFontAlign = SvxParaVertAlignItem::TOP;
564 								goto SET_FONTALIGNMENT;
565 			case RTF_FAVAR:     nFontAlign = SvxParaVertAlignItem::BOTTOM;
566 								goto SET_FONTALIGNMENT;
567 			case RTF_FACENTER:  nFontAlign = SvxParaVertAlignItem::CENTER;
568 								goto SET_FONTALIGNMENT;
569 			case RTF_FAROMAN:   nFontAlign = SvxParaVertAlignItem::BASELINE;
570 								goto SET_FONTALIGNMENT;
571 SET_FONTALIGNMENT:
572 			if( PARDID->nFontAlign )
573 			{
574 				pSet->Put( SvxParaVertAlignItem( nFontAlign,
575 												PARDID->nFontAlign ));
576 			}
577 			break;
578 
579 /*  */
580 			case RTF_B:
581 			case RTF_AB:
582 				if( IsAttrSttPos() )	// nicht im Textfluss ?
583 				{
584 
585 					SvxWeightItem aTmpItem(
586 									nTokenValue ? WEIGHT_BOLD : WEIGHT_NORMAL,
587 									SID_ATTR_CHAR_WEIGHT );
588 					SetScriptAttr( eCharType, *pSet, aTmpItem);
589 				}
590 				break;
591 
592 			case RTF_CAPS:
593 			case RTF_SCAPS:
594 				if( PLAINID->nCaseMap &&
595 					IsAttrSttPos() )		// nicht im Textfluss ?
596 				{
597 					SvxCaseMap eCaseMap;
598 					if( !nTokenValue )
599 						eCaseMap = SVX_CASEMAP_NOT_MAPPED;
600 					else if( RTF_CAPS == nToken )
601 						eCaseMap = SVX_CASEMAP_VERSALIEN;
602 					else
603 						eCaseMap = SVX_CASEMAP_KAPITAELCHEN;
604 
605 					pSet->Put( SvxCaseMapItem( eCaseMap, PLAINID->nCaseMap ));
606 				}
607 				break;
608 
609 			case RTF_DN:
610 			case RTF_SUB:
611 				if( PLAINID->nEscapement )
612 				{
613 					const sal_uInt16 nEsc = PLAINID->nEscapement;
614 					if( -1 == nTokenValue || RTF_SUB == nToken )
615 						nTokenValue = 6;
616 					if( IsCalcValue() )
617 						CalcValue();
618 					const SvxEscapementItem& rOld = GetEscapement( *pSet, nEsc, sal_False );
619 					short nEs;
620 					sal_uInt8 nProp;
621 					if( DFLT_ESC_AUTO_SUPER == rOld.GetEsc() )
622 					{
623 						nEs = DFLT_ESC_AUTO_SUB;
624 						nProp = rOld.GetProp();
625 					}
626 					else
627 					{
628 						nEs = (short)-nTokenValue;
629 						nProp = (nToken == RTF_SUB) ? DFLT_ESC_PROP : 100;
630 					}
631 					pSet->Put( SvxEscapementItem( nEs, nProp, nEsc ));
632 				}
633 				break;
634 
635 			case RTF_NOSUPERSUB:
636 				if( PLAINID->nEscapement )
637 				{
638 					const sal_uInt16 nEsc = PLAINID->nEscapement;
639 					pSet->Put( SvxEscapementItem( nEsc ));
640 				}
641 				break;
642 
643 			case RTF_EXPND:
644 				if( PLAINID->nKering )
645 				{
646 					if( -1 == nTokenValue )
647 						nTokenValue = 0;
648 					else
649 						nTokenValue *= 5;
650 					if( IsCalcValue() )
651 						CalcValue();
652 					pSet->Put( SvxKerningItem( (short)nTokenValue, PLAINID->nKering ));
653 				}
654 				break;
655 
656 			case RTF_KERNING:
657 				if( PLAINID->nAutoKerning )
658 				{
659 					if( -1 == nTokenValue )
660 						nTokenValue = 0;
661 					else
662 						nTokenValue *= 10;
663 					if( IsCalcValue() )
664 						CalcValue();
665 					pSet->Put( SvxAutoKernItem( 0 != nTokenValue,
666 												PLAINID->nAutoKerning ));
667 				}
668 				break;
669 
670 			case RTF_EXPNDTW:
671 				if( PLAINID->nKering )
672 				{
673 					if( -1 == nTokenValue )
674 						nTokenValue = 0;
675 					if( IsCalcValue() )
676 						CalcValue();
677 					pSet->Put( SvxKerningItem( (short)nTokenValue, PLAINID->nKering ));
678 				}
679 				break;
680 
681 			case RTF_F:
682 			case RTF_AF:
683 				{
684 					const Font& rSVFont = GetFont( sal_uInt16(nTokenValue) );
685 					SvxFontItem aTmpItem( rSVFont.GetFamily(),
686 									rSVFont.GetName(), rSVFont.GetStyleName(),
687 									rSVFont.GetPitch(), rSVFont.GetCharSet(),
688 									SID_ATTR_CHAR_FONT );
689 					SetScriptAttr( eCharType, *pSet, aTmpItem );
690 					if( RTF_F == nToken )
691 					{
692 						SetEncoding( rSVFont.GetCharSet() );
693 						RereadLookahead();
694 					}
695 				}
696 				break;
697 
698 			case RTF_FS:
699 			case RTF_AFS:
700 				{
701 					if( -1 == nTokenValue )
702 						nTokenValue = 240;
703 					else
704 						nTokenValue *= 10;
705 // #i66167#
706 // for the SwRTFParser 'IsCalcValue' will be false and for the EditRTFParser
707 // the converiosn takes now place in EditRTFParser since for other reasons
708 // the wrong MapUnit might still be use there
709 //                   if( IsCalcValue() )
710 //                       CalcValue();
711 					SvxFontHeightItem aTmpItem(
712 							(const sal_uInt16)nTokenValue, 100,
713 							SID_ATTR_CHAR_FONTHEIGHT );
714 					SetScriptAttr( eCharType, *pSet, aTmpItem );
715 				}
716 				break;
717 
718 			case RTF_I:
719 			case RTF_AI:
720 				if( IsAttrSttPos() )		// nicht im Textfluss ?
721 				{
722 					SvxPostureItem aTmpItem(
723 							        nTokenValue ? ITALIC_NORMAL : ITALIC_NONE,
724 							        SID_ATTR_CHAR_POSTURE );
725 					SetScriptAttr( eCharType, *pSet, aTmpItem );
726 				}
727 				break;
728 
729 			case RTF_OUTL:
730 				if( PLAINID->nContour &&
731 					IsAttrSttPos() )		// nicht im Textfluss ?
732 				{
733 					pSet->Put( SvxContourItem( nTokenValue ? sal_True : sal_False,
734 								PLAINID->nContour ));
735 				}
736 				break;
737 
738 			case RTF_SHAD:
739 				if( PLAINID->nShadowed &&
740 					IsAttrSttPos() )		// nicht im Textfluss ?
741 				{
742 					pSet->Put( SvxShadowedItem( nTokenValue ? sal_True : sal_False,
743 								PLAINID->nShadowed ));
744 				}
745 				break;
746 
747 			case RTF_STRIKE:
748 				if( PLAINID->nCrossedOut &&
749 					IsAttrSttPos() )		// nicht im Textfluss ?
750 				{
751 					pSet->Put( SvxCrossedOutItem(
752 						nTokenValue ? STRIKEOUT_SINGLE : STRIKEOUT_NONE,
753 						PLAINID->nCrossedOut ));
754 				}
755 				break;
756 
757 			case RTF_STRIKED:
758 				if( PLAINID->nCrossedOut )		// nicht im Textfluss ?
759 				{
760 					pSet->Put( SvxCrossedOutItem(
761 						nTokenValue ? STRIKEOUT_DOUBLE : STRIKEOUT_NONE,
762 						PLAINID->nCrossedOut ));
763 				}
764 				break;
765 
766 			case RTF_UL:
767 				if( !IsAttrSttPos() )
768 					break;
769 				eUnderline = nTokenValue ? UNDERLINE_SINGLE : UNDERLINE_NONE;
770 				goto ATTR_SETUNDERLINE;
771 
772 			case RTF_ULD:
773 				eUnderline = UNDERLINE_DOTTED;
774 				goto ATTR_SETUNDERLINE;
775 			case RTF_ULDASH:
776 				eUnderline = UNDERLINE_DASH;
777 				goto ATTR_SETUNDERLINE;
778 			case RTF_ULDASHD:
779 				eUnderline = UNDERLINE_DASHDOT;
780 				goto ATTR_SETUNDERLINE;
781 			case RTF_ULDASHDD:
782 				eUnderline = UNDERLINE_DASHDOTDOT;
783 				goto ATTR_SETUNDERLINE;
784 			case RTF_ULDB:
785 				eUnderline = UNDERLINE_DOUBLE;
786 				goto ATTR_SETUNDERLINE;
787 			case RTF_ULNONE:
788 				eUnderline = UNDERLINE_NONE;
789 				goto ATTR_SETUNDERLINE;
790 			case RTF_ULTH:
791 				eUnderline = UNDERLINE_BOLD;
792 				goto ATTR_SETUNDERLINE;
793 			case RTF_ULWAVE:
794 				eUnderline = UNDERLINE_WAVE;
795 				goto ATTR_SETUNDERLINE;
796 			case RTF_ULTHD:
797 				eUnderline = UNDERLINE_BOLDDOTTED;
798 				goto ATTR_SETUNDERLINE;
799 			case RTF_ULTHDASH:
800 				eUnderline = UNDERLINE_BOLDDASH;
801 				goto ATTR_SETUNDERLINE;
802 			case RTF_ULLDASH:
803 				eUnderline = UNDERLINE_LONGDASH;
804 				goto ATTR_SETUNDERLINE;
805 			case RTF_ULTHLDASH:
806 				eUnderline = UNDERLINE_BOLDLONGDASH;
807 				goto ATTR_SETUNDERLINE;
808 			case RTF_ULTHDASHD:
809 				eUnderline = UNDERLINE_BOLDDASHDOT;
810 				goto ATTR_SETUNDERLINE;
811 			case RTF_ULTHDASHDD:
812 				eUnderline = UNDERLINE_BOLDDASHDOTDOT;
813 				goto ATTR_SETUNDERLINE;
814 			case RTF_ULHWAVE:
815 				eUnderline = UNDERLINE_BOLDWAVE;
816 				goto ATTR_SETUNDERLINE;
817 			case RTF_ULULDBWAVE:
818 				eUnderline = UNDERLINE_DOUBLEWAVE;
819 				goto ATTR_SETUNDERLINE;
820 
821 			case RTF_ULW:
822 				eUnderline = UNDERLINE_SINGLE;
823 
824 				if( PLAINID->nWordlineMode )
825 				{
826 					pSet->Put( SvxWordLineModeItem( sal_True, PLAINID->nWordlineMode ));
827 				}
828 				goto ATTR_SETUNDERLINE;
829 
830 ATTR_SETUNDERLINE:
831 				if( PLAINID->nUnderline )
832 				{
833 					pSet->Put( SvxUnderlineItem( eUnderline, PLAINID->nUnderline ));
834 				}
835 				break;
836 
837 			case RTF_ULC:
838 				if( PLAINID->nUnderline )
839 				{
840 					SvxUnderlineItem aUL( UNDERLINE_SINGLE, PLAINID->nUnderline );
841 					const SfxPoolItem* pItem;
842 					if( SFX_ITEM_SET == pSet->GetItemState(
843 						PLAINID->nUnderline, sal_False, &pItem ) )
844 					{
845 						// is switched off ?
846 						if( UNDERLINE_NONE ==
847 							((SvxUnderlineItem*)pItem)->GetLineStyle() )
848 							break;
849 						aUL = *(SvxUnderlineItem*)pItem;
850 					}
851 					else
852 						aUL = (const SvxUnderlineItem&)pSet->Get( PLAINID->nUnderline, sal_False );
853 
854 					if( UNDERLINE_NONE == aUL.GetLineStyle() )
855 						aUL.SetLineStyle( UNDERLINE_SINGLE );
856 					aUL.SetColor( GetColor( sal_uInt16(nTokenValue) ));
857 					pSet->Put( aUL );
858 				}
859 				break;
860 
861 			case RTF_OL:
862 				if( !IsAttrSttPos() )
863 					break;
864 				eOverline = nTokenValue ? UNDERLINE_SINGLE : UNDERLINE_NONE;
865 				goto ATTR_SETOVERLINE;
866 
867 			case RTF_OLD:
868 				eOverline = UNDERLINE_DOTTED;
869 				goto ATTR_SETOVERLINE;
870 			case RTF_OLDASH:
871 				eOverline = UNDERLINE_DASH;
872 				goto ATTR_SETOVERLINE;
873 			case RTF_OLDASHD:
874 				eOverline = UNDERLINE_DASHDOT;
875 				goto ATTR_SETOVERLINE;
876 			case RTF_OLDASHDD:
877 				eOverline = UNDERLINE_DASHDOTDOT;
878 				goto ATTR_SETOVERLINE;
879 			case RTF_OLDB:
880 				eOverline = UNDERLINE_DOUBLE;
881 				goto ATTR_SETOVERLINE;
882 			case RTF_OLNONE:
883 				eOverline = UNDERLINE_NONE;
884 				goto ATTR_SETOVERLINE;
885 			case RTF_OLTH:
886 				eOverline = UNDERLINE_BOLD;
887 				goto ATTR_SETOVERLINE;
888 			case RTF_OLWAVE:
889 				eOverline = UNDERLINE_WAVE;
890 				goto ATTR_SETOVERLINE;
891 			case RTF_OLTHD:
892 				eOverline = UNDERLINE_BOLDDOTTED;
893 				goto ATTR_SETOVERLINE;
894 			case RTF_OLTHDASH:
895 				eOverline = UNDERLINE_BOLDDASH;
896 				goto ATTR_SETOVERLINE;
897 			case RTF_OLLDASH:
898 				eOverline = UNDERLINE_LONGDASH;
899 				goto ATTR_SETOVERLINE;
900 			case RTF_OLTHLDASH:
901 				eOverline = UNDERLINE_BOLDLONGDASH;
902 				goto ATTR_SETOVERLINE;
903 			case RTF_OLTHDASHD:
904 				eOverline = UNDERLINE_BOLDDASHDOT;
905 				goto ATTR_SETOVERLINE;
906 			case RTF_OLTHDASHDD:
907 				eOverline = UNDERLINE_BOLDDASHDOTDOT;
908 				goto ATTR_SETOVERLINE;
909 			case RTF_OLHWAVE:
910 				eOverline = UNDERLINE_BOLDWAVE;
911 				goto ATTR_SETOVERLINE;
912 			case RTF_OLOLDBWAVE:
913 				eOverline = UNDERLINE_DOUBLEWAVE;
914 				goto ATTR_SETOVERLINE;
915 
916 			case RTF_OLW:
917 				eOverline = UNDERLINE_SINGLE;
918 
919 				if( PLAINID->nWordlineMode )
920 				{
921 					pSet->Put( SvxWordLineModeItem( sal_True, PLAINID->nWordlineMode ));
922 				}
923 				goto ATTR_SETOVERLINE;
924 
925 ATTR_SETOVERLINE:
926 				if( PLAINID->nUnderline )
927 				{
928 					pSet->Put( SvxOverlineItem( eOverline, PLAINID->nOverline ));
929 				}
930 				break;
931 
932 			case RTF_OLC:
933 				if( PLAINID->nOverline )
934 				{
935 					SvxOverlineItem aOL( UNDERLINE_SINGLE, PLAINID->nOverline );
936 					const SfxPoolItem* pItem;
937 					if( SFX_ITEM_SET == pSet->GetItemState(
938 						PLAINID->nOverline, sal_False, &pItem ) )
939 					{
940 						// is switched off ?
941 						if( UNDERLINE_NONE ==
942 							((SvxOverlineItem*)pItem)->GetLineStyle() )
943 							break;
944 						aOL = *(SvxOverlineItem*)pItem;
945 					}
946 					else
947 						aOL = (const SvxOverlineItem&)pSet->Get( PLAINID->nUnderline, sal_False );
948 
949 					if( UNDERLINE_NONE == aOL.GetLineStyle() )
950 						aOL.SetLineStyle( UNDERLINE_SINGLE );
951 					aOL.SetColor( GetColor( sal_uInt16(nTokenValue) ));
952 					pSet->Put( aOL );
953 				}
954 				break;
955 
956 			case RTF_UP:
957 			case RTF_SUPER:
958 				if( PLAINID->nEscapement )
959 				{
960 					const sal_uInt16 nEsc = PLAINID->nEscapement;
961 					if( -1 == nTokenValue || RTF_SUPER == nToken )
962 						nTokenValue = 6;
963 					if( IsCalcValue() )
964 						CalcValue();
965 					const SvxEscapementItem& rOld = GetEscapement( *pSet, nEsc, sal_False );
966 					short nEs;
967 					sal_uInt8 nProp;
968 					if( DFLT_ESC_AUTO_SUB == rOld.GetEsc() )
969 					{
970 						nEs = DFLT_ESC_AUTO_SUPER;
971 						nProp = rOld.GetProp();
972 					}
973 					else
974 					{
975 						nEs = (short)nTokenValue;
976 						nProp = (nToken == RTF_SUPER) ? DFLT_ESC_PROP : 100;
977 					}
978 					pSet->Put( SvxEscapementItem( nEs, nProp, nEsc ));
979 				}
980 				break;
981 
982 			case RTF_CF:
983 				if( PLAINID->nColor )
984 				{
985 					pSet->Put( SvxColorItem( GetColor( sal_uInt16(nTokenValue) ),
986 								PLAINID->nColor ));
987 				}
988 				break;
989 #if 0
990 			//#i12501# While cb is clearly documented in the rtf spec, word
991             //doesn't accept it at all
992 			case RTF_CB:
993 				if( PLAINID->nBgColor )
994 				{
995 					pSet->Put( SvxBrushItem( GetColor( sal_uInt16(nTokenValue) ),
996 								PLAINID->nBgColor ));
997 				}
998 				break;
999 #endif
1000 			case RTF_LANG:
1001 				if( PLAINID->nLanguage )
1002 				{
1003 					pSet->Put( SvxLanguageItem( (LanguageType)nTokenValue,
1004 								PLAINID->nLanguage ));
1005 				}
1006 				break;
1007 
1008 			case RTF_LANGFE:
1009 				if( PLAINID->nCJKLanguage )
1010 				{
1011 					pSet->Put( SvxLanguageItem( (LanguageType)nTokenValue,
1012 												PLAINID->nCJKLanguage ));
1013 				}
1014 				break;
1015 			case RTF_ALANG:
1016 				{
1017 					SvxLanguageItem aTmpItem( (LanguageType)nTokenValue,
1018 									SID_ATTR_CHAR_LANGUAGE );
1019 					SetScriptAttr( eCharType, *pSet, aTmpItem );
1020 				}
1021 				break;
1022 
1023 			case RTF_RTLCH:
1024                 bIsLeftToRightDef = sal_False;
1025                 break;
1026 			case RTF_LTRCH:
1027                 bIsLeftToRightDef = sal_True;
1028                 break;
1029             case RTF_RTLPAR:
1030                 if (PARDID->nDirection)
1031                 {
1032                     pSet->Put(SvxFrameDirectionItem(FRMDIR_HORI_RIGHT_TOP,
1033                         PARDID->nDirection));
1034                 }
1035                 break;
1036             case RTF_LTRPAR:
1037                 if (PARDID->nDirection)
1038                 {
1039                     pSet->Put(SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP,
1040                         PARDID->nDirection));
1041                 }
1042                 break;
1043 			case RTF_LOCH:  	eCharType = LOW_CHARTYPE;			break;
1044 			case RTF_HICH:  	eCharType = HIGH_CHARTYPE;			break;
1045 			case RTF_DBCH:  	eCharType = DOUBLEBYTE_CHARTYPE;	break;
1046 
1047 
1048 			case RTF_ACCNONE:
1049 				eEmphasis = EMPHASISMARK_NONE;
1050 				goto ATTR_SETEMPHASIS;
1051 			case RTF_ACCDOT:
1052 				eEmphasis = EMPHASISMARK_DOTS_ABOVE;
1053 				goto ATTR_SETEMPHASIS;
1054 
1055 			case RTF_ACCCOMMA:
1056 				eEmphasis = EMPHASISMARK_SIDE_DOTS;
1057 ATTR_SETEMPHASIS:
1058 				if( PLAINID->nEmphasis )
1059 				{
1060 					pSet->Put( SvxEmphasisMarkItem( eEmphasis,
1061 											   		PLAINID->nEmphasis ));
1062 				}
1063 				break;
1064 
1065 			case RTF_TWOINONE:
1066 				if( PLAINID->nTwoLines )
1067 				{
1068 					sal_Unicode cStt, cEnd;
1069 					switch ( nTokenValue )
1070 					{
1071 					case 1:	cStt = '(', cEnd = ')';	break;
1072 					case 2:	cStt = '[', cEnd = ']';	break;
1073 					case 3:	cStt = '<', cEnd = '>';	break;
1074 					case 4:	cStt = '{', cEnd = '}';	break;
1075 					default: cStt = 0, cEnd = 0; break;
1076 					}
1077 
1078 					pSet->Put( SvxTwoLinesItem( sal_True, cStt, cEnd,
1079 											   		PLAINID->nTwoLines ));
1080 				}
1081 				break;
1082 
1083 			case RTF_CHARSCALEX :
1084 				if (PLAINID->nCharScaleX)
1085 				{
1086                     //i21372
1087                     if (nTokenValue < 1 || nTokenValue > 600)
1088                         nTokenValue = 100;
1089 					pSet->Put( SvxCharScaleWidthItem( sal_uInt16(nTokenValue),
1090 											   		PLAINID->nCharScaleX ));
1091 				}
1092 				break;
1093 
1094 			case RTF_HORZVERT:
1095 				if( PLAINID->nHorzVert )
1096 				{
1097                     // RTF knows only 90deg
1098 					pSet->Put( SvxCharRotateItem( 900, 1 == nTokenValue,
1099 											   		PLAINID->nHorzVert ));
1100 				}
1101 				break;
1102 
1103 			case RTF_EMBO:
1104 				if (PLAINID->nRelief)
1105 				{
1106 					pSet->Put(SvxCharReliefItem(RELIEF_EMBOSSED,
1107                         PLAINID->nRelief));
1108 				}
1109 				break;
1110 			case RTF_IMPR:
1111 				if (PLAINID->nRelief)
1112 				{
1113 					pSet->Put(SvxCharReliefItem(RELIEF_ENGRAVED,
1114                         PLAINID->nRelief));
1115 				}
1116 				break;
1117 			case RTF_V:
1118 				if (PLAINID->nHidden)
1119                 {
1120 					pSet->Put(SvxCharHiddenItem(nTokenValue != 0,
1121                         PLAINID->nHidden));
1122                 }
1123 				break;
1124 			case RTF_CHBGFDIAG:
1125 			case RTF_CHBGDKVERT:
1126 			case RTF_CHBGDKHORIZ:
1127 			case RTF_CHBGVERT:
1128 			case RTF_CHBGHORIZ:
1129 			case RTF_CHBGDKFDIAG:
1130 			case RTF_CHBGDCROSS:
1131 			case RTF_CHBGCROSS:
1132 			case RTF_CHBGBDIAG:
1133 			case RTF_CHBGDKDCROSS:
1134 			case RTF_CHBGDKCROSS:
1135 			case RTF_CHBGDKBDIAG:
1136 			case RTF_CHCBPAT:
1137 			case RTF_CHCFPAT:
1138 			case RTF_CHSHDNG:
1139 				if( PLAINID->nBgColor )
1140 					ReadBackgroundAttr( nToken, *pSet );
1141 				break;
1142 
1143 
1144 /*  */
1145 
1146 			case BRACELEFT:
1147 				{
1148 					// teste auf Swg-Interne Tokens
1149                     bool bHandled = false;
1150 					short nSkip = 0;
1151 					if( RTF_IGNOREFLAG != GetNextToken())
1152 						nSkip = -1;
1153 					else if( (nToken = GetNextToken() ) & RTF_SWGDEFS )
1154 					{
1155                         bHandled = true;
1156 						switch( nToken )
1157 						{
1158 						case RTF_PGDSCNO:
1159 						case RTF_PGBRK:
1160 						case RTF_SOUTLVL:
1161 							UnknownAttrToken( nToken, pSet );
1162 							// ueberlese die schliessende Klammer
1163 							break;
1164 
1165 						case RTF_SWG_ESCPROP:
1166 							{
1167 								// prozentuale Veraenderung speichern !
1168 								sal_uInt8 nProp = sal_uInt8( nTokenValue / 100 );
1169 								short nEsc = 0;
1170 								if( 1 == ( nTokenValue % 100 ))
1171 									// Erkennung unseres AutoFlags!
1172 									nEsc = DFLT_ESC_AUTO_SUPER;
1173 
1174 								if( PLAINID->nEscapement )
1175 									pSet->Put( SvxEscapementItem( nEsc, nProp,
1176 											   		PLAINID->nEscapement ));
1177 							}
1178 							break;
1179 
1180 						case RTF_HYPHEN:
1181 							{
1182 								SvxHyphenZoneItem aHypenZone(
1183 											(nTokenValue & 1) ? sal_True : sal_False,
1184 												PARDID->nHyphenzone );
1185 								aHypenZone.SetPageEnd(
1186 											(nTokenValue & 2) ? sal_True : sal_False );
1187 
1188 								if( PARDID->nHyphenzone &&
1189 									RTF_HYPHLEAD == GetNextToken() &&
1190 									RTF_HYPHTRAIL == GetNextToken() &&
1191 									RTF_HYPHMAX == GetNextToken() )
1192 								{
1193 									aHypenZone.GetMinLead() =
1194 										sal_uInt8(GetStackPtr( -2 )->nTokenValue);
1195 									aHypenZone.GetMinTrail() =
1196 											sal_uInt8(GetStackPtr( -1 )->nTokenValue);
1197 									aHypenZone.GetMaxHyphens() =
1198 											sal_uInt8(nTokenValue);
1199 
1200 									pSet->Put( aHypenZone );
1201 								}
1202 								else
1203 									SkipGroup();		// ans Ende der Gruppe
1204 							}
1205 							break;
1206 
1207 						case RTF_SHADOW:
1208 							{
1209 								int bSkip = sal_True;
1210 								do {	// middle check loop
1211 									SvxShadowLocation eSL = SvxShadowLocation( nTokenValue );
1212 									if( RTF_SHDW_DIST != GetNextToken() )
1213 										break;
1214 									sal_uInt16 nDist = sal_uInt16( nTokenValue );
1215 
1216 									if( RTF_SHDW_STYLE != GetNextToken() )
1217 										break;
1218 									//! (pb) class Brush removed -> obsolete
1219 									//! BrushStyle eStyle = BrushStyle( nTokenValue );
1220 
1221 									if( RTF_SHDW_COL != GetNextToken() )
1222 										break;
1223 									sal_uInt16 nCol = sal_uInt16( nTokenValue );
1224 
1225 									if( RTF_SHDW_FCOL != GetNextToken() )
1226 										break;
1227 //									sal_uInt16 nFillCol = sal_uInt16( nTokenValue );
1228 
1229 									Color aColor = GetColor( nCol );
1230 
1231 									if( PARDID->nShadow )
1232 										pSet->Put( SvxShadowItem( PARDID->nShadow,
1233 																  &aColor, nDist, eSL ) );
1234 
1235 									bSkip = sal_False;
1236 								} while( sal_False );
1237 
1238 								if( bSkip )
1239 									SkipGroup();		// ans Ende der Gruppe
1240 							}
1241 							break;
1242 
1243 						default:
1244                             bHandled = false;
1245 							if( (nToken & ~(0xff | RTF_SWGDEFS)) == RTF_TABSTOPDEF )
1246 							{
1247 								nToken = SkipToken( -2 );
1248 								ReadTabAttr( nToken, *pSet );
1249 
1250                                 /*
1251                                 cmc: #i76140, he who consumed the { must consume the }
1252                                 We rewound to a state of { being the current
1253                                 token so it is our responsibility to consume the }
1254                                 token if we consumed the {. We will not have consumed
1255                                 the { if it belonged to our caller, i.e. if the { we
1256                                 are handling is the "firsttoken" passed to us then
1257                                 the *caller* must consume it, not us. Otherwise *we*
1258                                 should consume it.
1259                                 */
1260                                 if (nToken == BRACELEFT && !bFirstToken)
1261                                 {
1262                                     nToken = GetNextToken();
1263                                     DBG_ASSERT( nToken == BRACERIGHT,
1264                                         "} did not follow { as expected\n");
1265                                 }
1266 							}
1267 							else if( (nToken & ~(0xff| RTF_SWGDEFS)) == RTF_BRDRDEF)
1268 							{
1269 								nToken = SkipToken( -2 );
1270 								ReadBorderAttr( nToken, *pSet );
1271 							}
1272 							else		// also kein Attribut mehr
1273 								nSkip = -2;
1274 							break;
1275 						}
1276 
1277 #if 1
1278                         /*
1279                         cmc: #i4727# / #i12713# Who owns this closing bracket?
1280                         If we read the opening one, we must read this one, if
1281                         other is counting the brackets so as to push/pop off
1282                         the correct environment then we will have pushed a new
1283                         environment for the start { of this, but will not see
1284                         the } and so is out of sync for the rest of the
1285                         document.
1286                         */
1287                         if (bHandled && !bFirstToken)
1288                             GetNextToken();
1289 #endif
1290 					}
1291 					else
1292 						nSkip = -2;
1293 
1294 					if( nSkip )				// alles voellig unbekannt
1295 					{
1296                         if (!bFirstToken)
1297 						    --nSkip;	// BRACELEFT: ist das naechste Token
1298 						SkipToken( nSkip );
1299 						bWeiter = sal_False;
1300 					}
1301 				}
1302 				break;
1303 			default:
1304 				if( (nToken & ~0xff ) == RTF_TABSTOPDEF )
1305 					ReadTabAttr( nToken, *pSet );
1306 				else if( (nToken & ~0xff ) == RTF_BRDRDEF )
1307 					ReadBorderAttr( nToken, *pSet );
1308 				else if( (nToken & ~0xff ) == RTF_SHADINGDEF )
1309 					ReadBackgroundAttr( nToken, *pSet );
1310 				else
1311 				{
1312 					// kenne das Token nicht also das Token "in den Parser zurueck"
1313 					if( !bFirstToken )
1314 						SkipToken( -1 );
1315 					bWeiter = sal_False;
1316 				}
1317 			}
1318 		}
1319 		if( bWeiter )
1320 		{
1321 			nToken = GetNextToken();
1322 		}
1323 		bFirstToken = sal_False;
1324 	}
1325 
1326 /*
1327 	// teste Attribute gegen ihre Styles
1328 	if( IsChkStyleAttr() && pSet->Count() && !pInsPos->GetCntIdx() )
1329 	{
1330 		SvxRTFStyleType* pStyle = aStyleTbl.Get( nStyleNo );
1331 		if( pStyle && pStyle->aAttrSet.Count() )
1332 		{
1333 			// alle Attribute, die schon vom Style definiert sind, aus dem
1334 			// akt. Set entfernen
1335 			const SfxPoolItem* pItem;
1336 			SfxItemIter aIter( *pSet );
1337 			sal_uInt16 nWhich = aIter.GetCurItem()->Which();
1338 			while( sal_True )
1339 			{
1340 				if( SFX_ITEM_SET == pStyle->aAttrSet.GetItemState(
1341 					nWhich, sal_False, &pItem ) && *pItem == *aIter.GetCurItem())
1342 					pSet->ClearItem( nWhich );		// loeschen
1343 
1344 				if( aIter.IsAtEnd() )
1345 					break;
1346 				nWhich = aIter.NextItem()->Which();
1347 			}
1348 		}
1349 	}
1350 */
1351 }
1352 
ReadTabAttr(int nToken,SfxItemSet & rSet)1353 void SvxRTFParser::ReadTabAttr( int nToken, SfxItemSet& rSet )
1354 {
1355 	bool bMethodOwnsToken = false; // #i52542# patch from cmc.
1356 // dann lese doch mal alle TabStops ein
1357 	SvxTabStop aTabStop;
1358 	SvxTabStopItem aAttr( 0, 0, SVX_TAB_ADJUST_DEFAULT, PARDID->nTabStop );
1359 	int bWeiter = sal_True;
1360 	do {
1361 		switch( nToken )
1362 		{
1363 		case RTF_TB:		// BarTab ???
1364 		case RTF_TX:
1365 			{
1366 				if( IsCalcValue() )
1367 					CalcValue();
1368 				aTabStop.GetTabPos() = nTokenValue;
1369 				aAttr.Insert( aTabStop );
1370 				aTabStop = SvxTabStop();	// alle Werte default
1371 			}
1372 			break;
1373 
1374 		case RTF_TQL:
1375 			aTabStop.GetAdjustment() = SVX_TAB_ADJUST_LEFT;
1376 			break;
1377 		case RTF_TQR:
1378 			aTabStop.GetAdjustment() = SVX_TAB_ADJUST_RIGHT;
1379 			break;
1380 		case RTF_TQC:
1381 			aTabStop.GetAdjustment() = SVX_TAB_ADJUST_CENTER;
1382 			break;
1383 		case RTF_TQDEC:
1384 			aTabStop.GetAdjustment() = SVX_TAB_ADJUST_DECIMAL;
1385 			break;
1386 
1387 		case RTF_TLDOT:		aTabStop.GetFill() = '.';	break;
1388 		case RTF_TLHYPH:	aTabStop.GetFill() = ' ';	break;
1389 		case RTF_TLUL:		aTabStop.GetFill() = '_';	break;
1390 		case RTF_TLTH:		aTabStop.GetFill() = '-';	break;
1391 		case RTF_TLEQ:		aTabStop.GetFill() = '=';	break;
1392 
1393 		case BRACELEFT:
1394 			{
1395 				// Swg - Kontrol BRACELEFT RTF_IGNOREFLAG RTF_TLSWG BRACERIGHT
1396 				short nSkip = 0;
1397 				if( RTF_IGNOREFLAG != GetNextToken() )
1398 					nSkip = -1;
1399 				else if( RTF_TLSWG != ( nToken = GetNextToken() ))
1400 					nSkip = -2;
1401 				else
1402 				{
1403 					aTabStop.GetDecimal() = sal_uInt8(nTokenValue & 0xff);
1404 					aTabStop.GetFill() = sal_uInt8((nTokenValue >> 8) & 0xff);
1405 					// ueberlese noch die schliessende Klammer
1406 					if (bMethodOwnsToken)
1407 						GetNextToken();
1408 				}
1409 				if( nSkip )
1410 				{
1411 					SkipToken( nSkip );		// Ignore wieder zurueck
1412 					bWeiter = sal_False;
1413 				}
1414 			}
1415 			break;
1416 
1417 		default:
1418 			bWeiter = sal_False;
1419 		}
1420 		if( bWeiter )
1421 		{
1422 			nToken = GetNextToken();
1423 			bMethodOwnsToken = true;
1424 		}
1425 	} while( bWeiter );
1426 
1427 	// mit Defaults aufuellen fehlt noch !!!
1428 	rSet.Put( aAttr );
1429 	SkipToken( -1 );
1430 }
1431 
SetBorderLine(int nBorderTyp,SvxBoxItem & rItem,const SvxBorderLine & rBorder)1432 static void SetBorderLine( int nBorderTyp, SvxBoxItem& rItem,
1433 							const SvxBorderLine& rBorder )
1434 {
1435 	switch( nBorderTyp )
1436 	{
1437 	case RTF_BOX:			// alle Stufen durchlaufen
1438 
1439 	case RTF_BRDRT:
1440 		rItem.SetLine( &rBorder, BOX_LINE_TOP );
1441 		if( RTF_BOX != nBorderTyp )
1442 			return;
1443 
1444 	case RTF_BRDRB:
1445 		rItem.SetLine( &rBorder, BOX_LINE_BOTTOM );
1446 		if( RTF_BOX != nBorderTyp )
1447 			return;
1448 
1449 	case RTF_BRDRL:
1450 		rItem.SetLine( &rBorder, BOX_LINE_LEFT );
1451 		if( RTF_BOX != nBorderTyp )
1452 			return;
1453 
1454 	case RTF_BRDRR:
1455 		rItem.SetLine( &rBorder, BOX_LINE_RIGHT );
1456 		if( RTF_BOX != nBorderTyp )
1457 			return;
1458 	}
1459 }
1460 
ReadBorderAttr(int nToken,SfxItemSet & rSet,int bTableDef)1461 void SvxRTFParser::ReadBorderAttr( int nToken, SfxItemSet& rSet,
1462 									int bTableDef )
1463 {
1464 	// dann lese doch mal das BoderAttribut ein
1465 	SvxBoxItem aAttr( PARDID->nBox );
1466 	const SfxPoolItem* pItem;
1467 	if( SFX_ITEM_SET == rSet.GetItemState( PARDID->nBox, sal_False, &pItem ) )
1468 		aAttr = *(SvxBoxItem*)pItem;
1469 
1470 	SvxBorderLine aBrd( 0, DEF_LINE_WIDTH_0, 0, 0 );	// einfache Linien
1471 	int bWeiter = sal_True, nBorderTyp = 0;
1472 
1473 	do {
1474 		switch( nToken )
1475 		{
1476 		case RTF_BOX:
1477 		case RTF_BRDRT:
1478 		case RTF_BRDRB:
1479 		case RTF_BRDRL:
1480 		case RTF_BRDRR:
1481 			nBorderTyp = nToken;
1482 			goto SETBORDER;
1483 
1484 		case RTF_CLBRDRT:
1485 			if( !bTableDef )
1486 				break;
1487 			nBorderTyp = RTF_BRDRT;
1488 			goto SETBORDER;
1489 		case RTF_CLBRDRB:
1490 			if( !bTableDef )
1491 				break;
1492 			nBorderTyp = RTF_BRDRB;
1493 			goto SETBORDER;
1494 		case RTF_CLBRDRL:
1495 			if( !bTableDef )
1496 				break;
1497 			nBorderTyp = RTF_BRDRL;
1498 			goto SETBORDER;
1499 		case RTF_CLBRDRR:
1500 			if( !bTableDef )
1501 				break;
1502 			nBorderTyp = RTF_BRDRR;
1503 			goto SETBORDER;
1504 
1505 SETBORDER:
1506 			{
1507 				// auf defaults setzen
1508 				aBrd.SetOutWidth( DEF_LINE_WIDTH_0 );
1509 				aBrd.SetInWidth( 0 );
1510 				aBrd.SetDistance( 0 );
1511 				aBrd.SetColor( Color( COL_BLACK ) );
1512 			}
1513 			break;
1514 
1515 
1516 // werden noch nicht ausgewertet
1517 		case RTF_BRSP:
1518 			{
1519 				switch( nBorderTyp )
1520 				{
1521 				case RTF_BRDRB:
1522 					aAttr.SetDistance( (sal_uInt16)nTokenValue, BOX_LINE_BOTTOM );
1523 					break;
1524 
1525 				case RTF_BRDRT:
1526 					aAttr.SetDistance( (sal_uInt16)nTokenValue, BOX_LINE_TOP );
1527 					break;
1528 
1529 				case RTF_BRDRL:
1530 					aAttr.SetDistance( (sal_uInt16)nTokenValue, BOX_LINE_LEFT );
1531 					break;
1532 
1533 				case RTF_BRDRR:
1534 					aAttr.SetDistance( (sal_uInt16)nTokenValue, BOX_LINE_RIGHT );
1535 					break;
1536 
1537 				case RTF_BOX:
1538 					aAttr.SetDistance( (sal_uInt16)nTokenValue );
1539 					break;
1540 				}
1541 			}
1542 			break;
1543 
1544 case RTF_BRDRBTW:
1545 case RTF_BRDRBAR:			break;
1546 
1547 
1548 		case RTF_BRDRCF:
1549 			{
1550 				aBrd.SetColor( GetColor( sal_uInt16(nTokenValue) ) );
1551 				SetBorderLine( nBorderTyp, aAttr, aBrd );
1552 			}
1553 			break;
1554 
1555 		case RTF_BRDRTH:
1556 			aBrd.SetOutWidth( DEF_LINE_WIDTH_1 );
1557 			aBrd.SetInWidth( 0 );
1558 			aBrd.SetDistance( 0 );
1559 			goto SETBORDERLINE;
1560 
1561 		case RTF_BRDRDB:
1562 			aBrd.SetOutWidth( DEF_DOUBLE_LINE0_OUT );
1563 			aBrd.SetInWidth( DEF_DOUBLE_LINE0_IN );
1564 			aBrd.SetDistance( DEF_DOUBLE_LINE0_DIST );
1565 			goto SETBORDERLINE;
1566 
1567 		case RTF_BRDRSH:
1568 			// schattierte Box
1569 			{
1570 				rSet.Put( SvxShadowItem( PARDID->nShadow, (Color*) 0, 60 /*3pt*/,
1571 										SVX_SHADOW_BOTTOMRIGHT ) );
1572 			}
1573 			break;
1574 
1575 		case RTF_BRDRW:
1576 			if( -1 != nTokenValue )
1577 			{
1578 				// sollte es eine "dicke" Linie sein ?
1579 				if( DEF_LINE_WIDTH_0 != aBrd.GetOutWidth() )
1580 					nTokenValue *= 2;
1581 
1582 				// eine Doppelline?
1583 				if( aBrd.GetInWidth() )
1584 				{
1585 					// WinWord - Werte an StarOffice anpassen
1586 					if( nTokenValue < DEF_LINE_WIDTH_1 - (DEF_LINE_WIDTH_1/10))
1587 					{
1588 						aBrd.SetOutWidth( DEF_DOUBLE_LINE0_OUT );
1589 						aBrd.SetInWidth( DEF_DOUBLE_LINE0_IN );
1590 						aBrd.SetDistance( DEF_DOUBLE_LINE0_DIST );
1591 					}
1592 					else
1593 					if( nTokenValue < DEF_LINE_WIDTH_2 - (DEF_LINE_WIDTH_2/10))
1594 					{
1595 						aBrd.SetOutWidth( DEF_DOUBLE_LINE1_OUT );
1596 						aBrd.SetInWidth( DEF_DOUBLE_LINE1_IN );
1597 						aBrd.SetDistance( DEF_DOUBLE_LINE1_DIST );
1598 					}
1599 					else
1600 					{
1601 						aBrd.SetOutWidth( DEF_DOUBLE_LINE2_OUT );
1602 						aBrd.SetInWidth( DEF_DOUBLE_LINE2_IN );
1603 						aBrd.SetDistance( DEF_DOUBLE_LINE2_DIST );
1604 					}
1605 				}
1606 				else
1607 				{
1608 					// WinWord - Werte an StarOffice anpassen
1609 					if( nTokenValue < DEF_LINE_WIDTH_1 - (DEF_LINE_WIDTH_1/10))
1610 						aBrd.SetOutWidth( DEF_LINE_WIDTH_0 );
1611 					else
1612 					if( nTokenValue < DEF_LINE_WIDTH_2 - (DEF_LINE_WIDTH_2/10))
1613 						aBrd.SetOutWidth( DEF_LINE_WIDTH_1 );
1614 					else
1615 					if( nTokenValue < DEF_LINE_WIDTH_3 - (DEF_LINE_WIDTH_3/10))
1616 						aBrd.SetOutWidth( DEF_LINE_WIDTH_2 );
1617 					else
1618 					if( nTokenValue < DEF_LINE_WIDTH_4 )
1619 						aBrd.SetOutWidth( DEF_LINE_WIDTH_3 );
1620 					else
1621 						aBrd.SetOutWidth( DEF_LINE_WIDTH_4 );
1622 				}
1623 			}
1624 			goto SETBORDERLINE;
1625 
1626 		case RTF_BRDRS:
1627 		case RTF_BRDRDOT:
1628 		case RTF_BRDRHAIR:
1629 		case RTF_BRDRDASH:
1630 SETBORDERLINE:
1631 			SetBorderLine( nBorderTyp, aAttr, aBrd );
1632 			break;
1633 
1634 		case BRACELEFT:
1635 			{
1636 				short nSkip = 0;
1637 				if( RTF_IGNOREFLAG != GetNextToken() )
1638 					nSkip = -1;
1639 				else
1640 				{
1641 					int bSwgControl = sal_True, bFirstToken = sal_True;
1642 					nToken = GetNextToken();
1643 					do {
1644 						switch( nToken )
1645 						{
1646 						case RTF_BRDBOX:
1647 							aAttr.SetDistance( sal_uInt16(nTokenValue) );
1648 							break;
1649 
1650 						case RTF_BRDRT:
1651 						case RTF_BRDRB:
1652 						case RTF_BRDRR:
1653 						case RTF_BRDRL:
1654 							nBorderTyp = nToken;
1655 							bFirstToken = sal_False;
1656 							if( RTF_BRDLINE_COL != GetNextToken() )
1657 							{
1658 								bSwgControl = sal_False;
1659 								break;
1660 							}
1661 							aBrd.SetColor( GetColor( sal_uInt16(nTokenValue) ));
1662 
1663 							if( RTF_BRDLINE_IN != GetNextToken() )
1664 							{
1665 								bSwgControl = sal_False;
1666 								break;
1667 							}
1668 							aBrd.SetInWidth( sal_uInt16(nTokenValue));
1669 
1670 							if( RTF_BRDLINE_OUT != GetNextToken() )
1671 							{
1672 								bSwgControl = sal_False;
1673 								break;
1674 							}
1675 							aBrd.SetOutWidth( sal_uInt16(nTokenValue));
1676 
1677 							if( RTF_BRDLINE_DIST != GetNextToken() )
1678 							{
1679 								bSwgControl = sal_False;
1680 								break;
1681 							}
1682 							aBrd.SetDistance( sal_uInt16(nTokenValue));
1683 							SetBorderLine( nBorderTyp, aAttr, aBrd );
1684 							break;
1685 
1686 						default:
1687 							bSwgControl = sal_False;
1688 							break;
1689 						}
1690 
1691 						if( bSwgControl )
1692 						{
1693 							nToken = GetNextToken();
1694 							bFirstToken = sal_False;
1695 						}
1696 					} while( bSwgControl );
1697 
1698 					// Ende der Swg-Gruppe
1699 					// -> lese noch die schliessende Klammer
1700 					if( BRACERIGHT == nToken )
1701 						;
1702 					else if( !bFirstToken )
1703 					{
1704 						// es ist ein Parser-Fehler, springe zum
1705 						// Ende der Gruppe
1706 						SkipGroup();
1707 						// schliessende BRACERIGHT ueberspringen
1708 						GetNextToken();
1709 					}
1710 					else
1711 						nSkip = -2;
1712 				}
1713 
1714 				if( nSkip )
1715 				{
1716 					SkipToken( nSkip );		// Ignore wieder zurueck
1717 					bWeiter = sal_False;
1718 				}
1719 			}
1720 			break;
1721 
1722 		default:
1723 			bWeiter = (nToken & ~(0xff| RTF_SWGDEFS)) == RTF_BRDRDEF;
1724 		}
1725 		if( bWeiter )
1726 			nToken = GetNextToken();
1727 	} while( bWeiter );
1728 	rSet.Put( aAttr );
1729 	SkipToken( -1 );
1730 }
1731 
CalcShading(sal_uInt32 nColor,sal_uInt32 nFillColor,sal_uInt8 nShading)1732 inline sal_uInt32 CalcShading( sal_uInt32 nColor, sal_uInt32 nFillColor, sal_uInt8 nShading )
1733 {
1734 	nColor = (nColor * nShading) / 100;
1735 	nFillColor = (nFillColor * ( 100 - nShading )) / 100;
1736 	return nColor + nFillColor;
1737 }
1738 
ReadBackgroundAttr(int nToken,SfxItemSet & rSet,int bTableDef)1739 void SvxRTFParser::ReadBackgroundAttr( int nToken, SfxItemSet& rSet,
1740 										int bTableDef )
1741 {
1742 	// dann lese doch mal das BoderAttribut ein
1743 	int bWeiter = sal_True;
1744 	sal_uInt16 nColor = USHRT_MAX, nFillColor = USHRT_MAX;
1745 	sal_uInt8 nFillValue = 0;
1746 
1747 	sal_uInt16 nWh = ( nToken & ~0xff ) == RTF_CHRFMT
1748 					? PLAINID->nBgColor
1749 					: PARDID->nBrush;
1750 
1751 	do {
1752 		switch( nToken )
1753 		{
1754 		case RTF_CLCBPAT:
1755 		case RTF_CHCBPAT:
1756 		case RTF_CBPAT:
1757 			nFillColor = sal_uInt16( nTokenValue );
1758 			break;
1759 
1760 		case RTF_CLCFPAT:
1761 		case RTF_CHCFPAT:
1762 		case RTF_CFPAT:
1763 			nColor = sal_uInt16( nTokenValue );
1764 			break;
1765 
1766 		case RTF_CLSHDNG:
1767 		case RTF_CHSHDNG:
1768 		case RTF_SHADING:
1769 			nFillValue = (sal_uInt8)( nTokenValue / 100 );
1770 			break;
1771 
1772 		case RTF_CLBGDKHOR:
1773 		case RTF_CHBGDKHORIZ:
1774 		case RTF_BGDKHORIZ:
1775 		case RTF_CLBGDKVERT:
1776 		case RTF_CHBGDKVERT:
1777 		case RTF_BGDKVERT:
1778 		case RTF_CLBGDKBDIAG:
1779 		case RTF_CHBGDKBDIAG:
1780 		case RTF_BGDKBDIAG:
1781 		case RTF_CLBGDKFDIAG:
1782 		case RTF_CHBGDKFDIAG:
1783 		case RTF_BGDKFDIAG:
1784 		case RTF_CLBGDKCROSS:
1785 		case RTF_CHBGDKCROSS:
1786 		case RTF_BGDKCROSS:
1787 		case RTF_CLBGDKDCROSS:
1788 		case RTF_CHBGDKDCROSS:
1789 		case RTF_BGDKDCROSS:
1790 			// dark -> 60%
1791 			nFillValue = 60;
1792 			break;
1793 
1794 		case RTF_CLBGHORIZ:
1795 		case RTF_CHBGHORIZ:
1796 		case RTF_BGHORIZ:
1797 		case RTF_CLBGVERT:
1798 		case RTF_CHBGVERT:
1799 		case RTF_BGVERT:
1800 		case RTF_CLBGBDIAG:
1801 		case RTF_CHBGBDIAG:
1802 		case RTF_BGBDIAG:
1803 		case RTF_CLBGFDIAG:
1804 		case RTF_CHBGFDIAG:
1805 		case RTF_BGFDIAG:
1806 		case RTF_CLBGCROSS:
1807 		case RTF_CHBGCROSS:
1808 		case RTF_BGCROSS:
1809 		case RTF_CLBGDCROSS:
1810 		case RTF_CHBGDCROSS:
1811 		case RTF_BGDCROSS:
1812 			// light -> 20%
1813 			nFillValue = 20;
1814 			break;
1815 
1816 		default:
1817 			if( bTableDef )
1818 				bWeiter = (nToken & ~(0xff | RTF_TABLEDEF) ) == RTF_SHADINGDEF;
1819 			else
1820 				bWeiter = (nToken & ~0xff) == RTF_SHADINGDEF;
1821 		}
1822 		if( bWeiter )
1823 			nToken = GetNextToken();
1824 	} while( bWeiter );
1825 
1826 	Color aCol( COL_WHITE ), aFCol;
1827 	if( !nFillValue )
1828 	{
1829 		// es wurde nur eine von beiden Farben angegeben oder kein BrushTyp
1830 		if( USHRT_MAX != nFillColor )
1831 		{
1832 			nFillValue = 100;
1833 			aCol = GetColor( nFillColor );
1834 		}
1835 		else if( USHRT_MAX != nColor )
1836 			aFCol = GetColor( nColor );
1837 	}
1838 	else
1839 	{
1840 		if( USHRT_MAX != nColor )
1841 			aCol = GetColor( nColor );
1842 		else
1843 			aCol = Color( COL_BLACK );
1844 
1845 		if( USHRT_MAX != nFillColor )
1846 			aFCol = GetColor( nFillColor );
1847 		else
1848 			aFCol = Color( COL_WHITE );
1849 	}
1850 
1851 	Color aColor;
1852 	if( 0 == nFillValue || 100 == nFillValue )
1853 		aColor = aCol;
1854 	else
1855 		aColor = Color(
1856 			(sal_uInt8)CalcShading( aCol.GetRed(), aFCol.GetRed(), nFillValue ),
1857 			(sal_uInt8)CalcShading( aCol.GetGreen(), aFCol.GetGreen(), nFillValue ),
1858 			(sal_uInt8)CalcShading( aCol.GetBlue(), aFCol.GetBlue(), nFillValue ) );
1859 
1860 	rSet.Put( SvxBrushItem( aColor, nWh ) );
1861 	SkipToken( -1 );
1862 }
1863 
1864 
1865 // pard / plain abarbeiten
RTFPardPlain(int bPard,SfxItemSet ** ppSet)1866 void SvxRTFParser::RTFPardPlain( int bPard, SfxItemSet** ppSet )
1867 {
1868 	if( !bNewGroup && !aAttrStack.empty() )	// not at the beginning of a new group
1869 	{
1870         SvxRTFItemStackType* pAkt = aAttrStack.back();
1871 
1872 		int nLastToken = GetStackPtr(-1)->nTokenId;
1873 		int bNewStkEntry = sal_True;
1874 		if( RTF_PARD != nLastToken &&
1875 			RTF_PLAIN != nLastToken &&
1876 			BRACELEFT != nLastToken )
1877 		{
1878 			if( pAkt->aAttrSet.Count() || pAkt->pChildList || pAkt->nStyleNo )
1879 			{
1880 				// eine neue Gruppe aufmachen
1881 				SvxRTFItemStackType* pNew = new SvxRTFItemStackType( *pAkt, *pInsPos, sal_True );
1882 				pNew->SetRTFDefaults( GetRTFDefaults() );
1883 
1884 				// alle bis hierher gueltigen Attribute "setzen"
1885 				AttrGroupEnd();
1886 				pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();  // can be changed after AttrGroupEnd!
1887 				pNew->aAttrSet.SetParent( pAkt ? &pAkt->aAttrSet : 0 );
1888 				aAttrStack.push_back( pNew );
1889 				pAkt = pNew;
1890 			}
1891 			else
1892 			{
1893 				// diesen Eintrag als neuen weiterbenutzen
1894 				pAkt->SetStartPos( *pInsPos );
1895 				bNewStkEntry = sal_False;
1896 			}
1897 		}
1898 
1899 		// jetzt noch alle auf default zuruecksetzen
1900 		if( bNewStkEntry &&
1901 			( pAkt->aAttrSet.GetParent() || pAkt->aAttrSet.Count() ))
1902 		{
1903 			const SfxPoolItem *pItem, *pDef;
1904 			const sal_uInt16* pPtr;
1905 			sal_uInt16 nCnt;
1906 			const SfxItemSet* pDfltSet = &GetRTFDefaults();
1907 			if( bPard )
1908 			{
1909 				pAkt->nStyleNo = 0;
1910 				pPtr = aPardMap.GetData();
1911 				nCnt = aPardMap.Count();
1912 			}
1913 			else
1914 			{
1915 				pPtr = aPlainMap.GetData();
1916 				nCnt = aPlainMap.Count();
1917 			}
1918 
1919 			for( sal_uInt16 n = 0; n < nCnt; ++n, ++pPtr )
1920 			{
1921 				// Item gesetzt und unterschiedlich -> das Pooldefault setzen
1922 				//JP 06.04.98: bei Items die nur SlotItems sind, darf nicht
1923 				//				auf das Default zugefriffen werden. Diese
1924 				//				werden gecleart
1925 				if( !*pPtr )
1926 					;
1927 				else if( SFX_WHICH_MAX < *pPtr )
1928 					pAkt->aAttrSet.ClearItem( *pPtr );
1929 				else if( IsChkStyleAttr() )
1930 					pAkt->aAttrSet.Put( pDfltSet->Get( *pPtr ) );
1931 				else if( !pAkt->aAttrSet.GetParent() )
1932 				{
1933 					if( SFX_ITEM_SET ==
1934 						pDfltSet->GetItemState( *pPtr, sal_False, &pDef ))
1935 						pAkt->aAttrSet.Put( *pDef );
1936 					else
1937 						pAkt->aAttrSet.ClearItem( *pPtr );
1938 				}
1939 				else if( SFX_ITEM_SET == pAkt->aAttrSet.GetParent()->
1940 							GetItemState( *pPtr, sal_True, &pItem ) &&
1941 						*( pDef = &pDfltSet->Get( *pPtr )) != *pItem )
1942 					pAkt->aAttrSet.Put( *pDef );
1943 				else
1944 				{
1945 					if( SFX_ITEM_SET ==
1946 						pDfltSet->GetItemState( *pPtr, sal_False, &pDef ))
1947 						pAkt->aAttrSet.Put( *pDef );
1948 					else
1949 						pAkt->aAttrSet.ClearItem( *pPtr );
1950 				}
1951 			}
1952 		}
1953 		else if( bPard )
1954 			pAkt->nStyleNo = 0;		// Style-Nummer zuruecksetzen
1955 
1956 		*ppSet = &pAkt->aAttrSet;
1957 
1958 		if (!bPard)
1959         {
1960             //Once we have a default font, then any text without a font specifier is
1961             //in the default font, and thus has the default font charset, otherwise
1962             //we can fall back to the ansicpg set codeset
1963             if (nDfltFont != -1)
1964             {
1965                 const Font& rSVFont = GetFont(sal_uInt16(nDfltFont));
1966                 SetEncoding(rSVFont.GetCharSet());
1967             }
1968             else
1969 			    SetEncoding(GetCodeSet());
1970         }
1971 	}
1972 }
1973 
SetDefault(int nToken,int nValue)1974 void SvxRTFParser::SetDefault( int nToken, int nValue )
1975 {
1976 	if( !bNewDoc )
1977 		return;
1978 
1979 	SfxItemSet aTmp( *pAttrPool, aWhichMap.GetData() );
1980 	sal_Bool bOldFlag = bIsLeftToRightDef;
1981 	bIsLeftToRightDef = sal_True;
1982 	switch( nToken )
1983 	{
1984 	case RTF_ADEFF:	bIsLeftToRightDef = sal_False;  // no break!
1985 	case RTF_DEFF:
1986 		{
1987 			if( -1 == nValue )
1988 				nValue = 0;
1989 			const Font& rSVFont = GetFont( sal_uInt16(nValue) );
1990 			SvxFontItem aTmpItem(
1991 								rSVFont.GetFamily(), rSVFont.GetName(),
1992 								rSVFont.GetStyleName(),	rSVFont.GetPitch(),
1993 								rSVFont.GetCharSet(), SID_ATTR_CHAR_FONT );
1994 			SetScriptAttr( NOTDEF_CHARTYPE, aTmp, aTmpItem );
1995 		}
1996 		break;
1997 
1998 	case RTF_ADEFLANG:	bIsLeftToRightDef = sal_False;  // no break!
1999 	case RTF_DEFLANG:
2000 		// default Language merken
2001 		if( -1 != nValue )
2002 		{
2003 			SvxLanguageItem aTmpItem( (const LanguageType)nValue,
2004 									    SID_ATTR_CHAR_LANGUAGE );
2005 			SetScriptAttr( NOTDEF_CHARTYPE, aTmp, aTmpItem );
2006 		}
2007 		break;
2008 
2009 	case RTF_DEFTAB:
2010 		if( PARDID->nTabStop )
2011 		{
2012 			// RTF definiert 720 twips als default
2013 			bIsSetDfltTab = sal_True;
2014 			if( -1 == nValue || !nValue )
2015 				nValue = 720;
2016 
2017 			// wer keine Twips haben moechte ...
2018 			if( IsCalcValue() )
2019 			{
2020 				nTokenValue = nValue;
2021 				CalcValue();
2022 				nValue = nTokenValue;
2023 			}
2024 #if 1
2025             /*
2026             cmc:
2027              This stuff looks a little hairy indeed, this should be totally
2028              unnecessary where default tabstops are understood. Just make one
2029              tabstop and stick the value in there, the first one is all that
2030              matters.
2031 
2032              e.g.
2033 
2034             SvxTabStopItem aNewTab(1, sal_uInt16(nValue), SVX_TAB_ADJUST_DEFAULT,
2035                 PARDID->nTabStop);
2036             ((SvxTabStop&)aNewTab[0]).GetAdjustment() = SVX_TAB_ADJUST_DEFAULT;
2037 
2038 
2039              It must exist as a foul hack to support somebody that does not
2040              have a true concept of default tabstops by making a tabsetting
2041              result from the default tabstop, creating a lot of them all at
2042              the default locations to give the effect of the first real
2043              default tabstop being in use just in case the receiving
2044              application doesn't do that for itself.
2045              */
2046 #endif
2047 
2048 			// Verhaeltnis der def. TabWidth / Tabs errechnen und
2049 			// enstsprechend die neue Anzahl errechnen.
2050 /*-----------------14.12.94 19:32-------------------
2051  ?? wie kommt man auf die 13 ??
2052 --------------------------------------------------*/
2053 			sal_uInt16 nAnzTabs = (SVX_TAB_DEFDIST * 13 ) / sal_uInt16(nValue);
2054             /*
2055              cmc, make sure we have at least one, or all hell breaks loose in
2056              everybodies exporters, #i8247#
2057             */
2058             if (nAnzTabs < 1)
2059                 nAnzTabs = 1;
2060 
2061 			// wir wollen Defaulttabs
2062 			SvxTabStopItem aNewTab( nAnzTabs, sal_uInt16(nValue),
2063 								SVX_TAB_ADJUST_DEFAULT, PARDID->nTabStop );
2064 			while( nAnzTabs )
2065 				((SvxTabStop&)aNewTab[ --nAnzTabs ]).GetAdjustment() = SVX_TAB_ADJUST_DEFAULT;
2066 
2067 			pAttrPool->SetPoolDefaultItem( aNewTab );
2068 		}
2069 		break;
2070 	}
2071 	bIsLeftToRightDef = bOldFlag;
2072 
2073 	if( aTmp.Count() )
2074 	{
2075 		SfxItemIter aIter( aTmp );
2076 		const SfxPoolItem* pItem = aIter.GetCurItem();
2077 		while( sal_True )
2078 		{
2079 			pAttrPool->SetPoolDefaultItem( *pItem );
2080 			if( aIter.IsAtEnd() )
2081 				break;
2082 			pItem = aIter.NextItem();
2083 		}
2084 	}
2085 }
2086 
2087 // default: keine Umrechnung, alles bei Twips lassen.
CalcValue()2088 void SvxRTFParser::CalcValue()
2089 {
2090 }
2091 
2092 	// fuer Tokens, die im ReadAttr nicht ausgewertet werden
UnknownAttrToken(int,SfxItemSet *)2093 void SvxRTFParser::UnknownAttrToken( int, SfxItemSet* )
2094 {
2095 }
2096 
2097 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
2098