bump product version to 5.0.4.1
[LibreOffice.git] / editeng / source / rtf / rtfitem.cxx
blob67a574bac6e2af88260a07fe2e7d81f7f22052e0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <editeng/flstitem.hxx>
22 #include <editeng/fontitem.hxx>
23 #include <editeng/postitem.hxx>
24 #include <editeng/wghtitem.hxx>
25 #include <editeng/fhgtitem.hxx>
26 #include <editeng/fwdtitem.hxx>
27 #include <editeng/udlnitem.hxx>
28 #include <editeng/crossedoutitem.hxx>
29 #include <editeng/shdditem.hxx>
30 #include <editeng/autokernitem.hxx>
31 #include <editeng/wrlmitem.hxx>
32 #include <editeng/contouritem.hxx>
33 #include <editeng/prszitem.hxx>
34 #include <editeng/colritem.hxx>
35 #include <editeng/charsetcoloritem.hxx>
36 #include <editeng/kernitem.hxx>
37 #include <editeng/cmapitem.hxx>
38 #include <editeng/escapementitem.hxx>
39 #include <editeng/langitem.hxx>
40 #include <editeng/nlbkitem.hxx>
41 #include <editeng/nhypitem.hxx>
42 #include <editeng/lcolitem.hxx>
43 #include <editeng/blinkitem.hxx>
44 #include <editeng/emphasismarkitem.hxx>
45 #include <editeng/twolinesitem.hxx>
46 #include <editeng/pbinitem.hxx>
47 #include <editeng/sizeitem.hxx>
48 #include <editeng/lrspitem.hxx>
49 #include <editeng/ulspitem.hxx>
50 #include <editeng/prntitem.hxx>
51 #include <editeng/opaqitem.hxx>
52 #include <editeng/protitem.hxx>
53 #include <editeng/shaditem.hxx>
54 #include <editeng/boxitem.hxx>
55 #include <editeng/formatbreakitem.hxx>
56 #include <editeng/keepitem.hxx>
57 #include <editeng/lineitem.hxx>
58 #include <editeng/brushitem.hxx>
59 #include <editeng/lspcitem.hxx>
60 #include <editeng/adjustitem.hxx>
61 #include <editeng/orphitem.hxx>
62 #include <editeng/widwitem.hxx>
63 #include <editeng/tstpitem.hxx>
64 #include <editeng/pmdlitem.hxx>
65 #include <editeng/spltitem.hxx>
66 #include <editeng/hyphenzoneitem.hxx>
67 #include <editeng/charscaleitem.hxx>
68 #include <editeng/charrotateitem.hxx>
69 #include <editeng/charreliefitem.hxx>
70 #include <editeng/paravertalignitem.hxx>
71 #include <editeng/forbiddenruleitem.hxx>
72 #include <editeng/hngpnctitem.hxx>
73 #include <editeng/scriptspaceitem.hxx>
74 #include <editeng/frmdiritem.hxx>
75 #include <editeng/charhiddenitem.hxx>
77 #include <svtools/rtftoken.h>
78 #include <svl/itempool.hxx>
79 #include <svl/itemiter.hxx>
81 #include <editeng/svxrtf.hxx>
82 #include <editeng/editids.hrc>
84 #define BRACELEFT '{'
85 #define BRACERIGHT '}'
87 using namespace ::com::sun::star;
88 using namespace editeng;
90 // Some helper functions
91 // char
92 inline const SvxEscapementItem& GetEscapement(const SfxItemSet& rSet,sal_uInt16 nId,bool bInP=true)
93 { return static_cast<const SvxEscapementItem&>(rSet.Get( nId,bInP)); }
94 inline const SvxLineSpacingItem& GetLineSpacing(const SfxItemSet& rSet,sal_uInt16 nId,bool bInP=true)
95 { return static_cast<const SvxLineSpacingItem&>(rSet.Get( nId,bInP)); }
96 // frm
97 inline const SvxLRSpaceItem& GetLRSpace(const SfxItemSet& rSet,sal_uInt16 nId,bool bInP=true)
98 { return static_cast<const SvxLRSpaceItem&>(rSet.Get( nId,bInP)); }
99 inline const SvxULSpaceItem& GetULSpace(const SfxItemSet& rSet,sal_uInt16 nId,bool bInP=true)
100 { return static_cast<const SvxULSpaceItem&>(rSet.Get( nId,bInP)); }
102 void SvxRTFParser::SetScriptAttr( RTF_CharTypeDef eType, SfxItemSet& rSet,
103 SfxPoolItem& rItem )
105 const sal_uInt16 *pNormal = 0, *pCJK = 0, *pCTL = 0;
106 switch( rItem.Which() )
108 case SID_ATTR_CHAR_FONT:
109 pNormal = &aPlainMap.nFont;
110 pCJK = &aPlainMap.nCJKFont;
111 pCTL = &aPlainMap.nCTLFont;
112 break;
114 case SID_ATTR_CHAR_FONTHEIGHT:
115 pNormal = &aPlainMap.nFontHeight;
116 pCJK = &aPlainMap.nCJKFontHeight;
117 pCTL = &aPlainMap.nCTLFontHeight;
118 break;
120 case SID_ATTR_CHAR_POSTURE:
121 pNormal = &aPlainMap.nPosture;
122 pCJK = &aPlainMap.nCJKPosture;
123 pCTL = &aPlainMap.nCTLPosture;
124 break;
126 case SID_ATTR_CHAR_WEIGHT:
127 pNormal = &aPlainMap.nWeight;
128 pCJK = &aPlainMap.nCJKWeight;
129 pCTL = &aPlainMap.nCTLWeight;
130 break;
132 case SID_ATTR_CHAR_LANGUAGE:
133 pNormal = &aPlainMap.nLanguage;
134 pCJK = &aPlainMap.nCJKLanguage;
135 pCTL = &aPlainMap.nCTLLanguage;
136 break;
138 case 0:
139 // it exist no WhichId - don't set this item
140 break;
142 default:
143 rSet.Put( rItem );
144 break;
147 if( DOUBLEBYTE_CHARTYPE == eType )
149 if( bIsLeftToRightDef && pCJK )
151 rItem.SetWhich( *pCJK );
152 rSet.Put( rItem );
155 else if( !bIsLeftToRightDef )
157 if( pCTL )
159 rItem.SetWhich( *pCTL );
160 rSet.Put( rItem );
163 else
165 if( LOW_CHARTYPE == eType )
167 if( pNormal )
169 rItem.SetWhich( *pNormal );
170 rSet.Put( rItem );
173 else if( HIGH_CHARTYPE == eType )
175 if( pCTL )
177 rItem.SetWhich( *pCTL );
178 rSet.Put( rItem );
181 else
183 if( pCJK )
185 rItem.SetWhich( *pCJK );
186 rSet.Put( rItem );
188 if( pCTL )
190 rItem.SetWhich( *pCTL );
191 rSet.Put( rItem );
193 if( pNormal )
195 rItem.SetWhich( *pNormal );
196 rSet.Put( rItem );
204 void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet )
206 DBG_ASSERT( pSet, "A SfxItemSet has to be provided as argument!" );
207 bool bFirstToken = true;
208 bool bContinue = true;
209 sal_uInt16 nStyleNo = 0; // default
210 FontUnderline eUnderline;
211 FontUnderline eOverline;
212 FontEmphasisMark eEmphasis;
213 bPardTokenRead = false;
214 RTF_CharTypeDef eCharType = NOTDEF_CHARTYPE;
215 sal_uInt16 nFontAlign;
217 bool bChkStkPos = !bNewGroup && !aAttrStack.empty();
219 while( bContinue && IsParserWorking() ) // as long as known Attribute are recognized
221 switch( nToken )
223 case RTF_PARD:
224 RTFPardPlain( true, &pSet );
225 nStyleNo = 0;
226 bPardTokenRead = true;
227 break;
229 case RTF_PLAIN:
230 RTFPardPlain( false, &pSet );
231 break;
233 default:
234 do { // middle checked loop
235 if( !bChkStkPos )
236 break;
238 SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
239 if( !pAkt || (pAkt->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
240 pAkt->nSttCnt == pInsPos->GetCntIdx() ))
241 break;
243 int nLastToken = GetStackPtr(-1)->nTokenId;
244 if( RTF_PARD == nLastToken || RTF_PLAIN == nLastToken )
245 break;
247 if( pAkt->aAttrSet.Count() || pAkt->pChildList ||
248 pAkt->nStyleNo )
250 // Open a new Group
251 SvxRTFItemStackType* pNew = new SvxRTFItemStackType(
252 *pAkt, *pInsPos, true );
253 pNew->SetRTFDefaults( GetRTFDefaults() );
255 // "Set" all valid attributes up until this point
256 AttrGroupEnd();
257 pAkt = aAttrStack.empty() ? 0 : aAttrStack.back(); // can be changed after AttrGroupEnd!
258 pNew->aAttrSet.SetParent( pAkt ? &pAkt->aAttrSet : 0 );
260 aAttrStack.push_back( pNew );
261 pAkt = pNew;
263 else
264 // continue to use this entry as a new one
265 pAkt->SetStartPos( *pInsPos );
267 pSet = &pAkt->aAttrSet;
268 } while( false );
270 switch( nToken )
272 case RTF_INTBL:
273 case RTF_PAGEBB:
274 case RTF_SBYS:
275 case RTF_CS:
276 case RTF_LS:
277 case RTF_ILVL:
278 UnknownAttrToken( nToken, pSet );
279 break;
281 case RTF_S:
282 if( bIsInReadStyleTab )
284 if( !bFirstToken )
285 SkipToken( -1 );
286 bContinue = false;
288 else
290 nStyleNo = -1 == nTokenValue ? 0 : sal_uInt16(nTokenValue);
291 /* setze am akt. auf dem AttrStack stehenden Style die
292 I sit on akt. which is on the immediate style AttrStack */
293 // StyleNummer
294 SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
295 if( !pAkt )
296 break;
298 pAkt->nStyleNo = sal_uInt16( nStyleNo );
301 break;
303 case RTF_KEEP:
304 if( aPardMap.nSplit )
306 pSet->Put( SvxFormatSplitItem( false, aPardMap.nSplit ));
308 break;
310 case RTF_KEEPN:
311 if( aPardMap.nKeep )
313 pSet->Put( SvxFormatKeepItem( true, aPardMap.nKeep ));
315 break;
317 case RTF_LEVEL:
318 if( aPardMap.nOutlineLvl )
320 pSet->Put( SfxUInt16Item( aPardMap.nOutlineLvl,
321 (sal_uInt16)nTokenValue ));
323 break;
325 case RTF_QL:
326 if( aPardMap.nAdjust )
328 pSet->Put( SvxAdjustItem( SVX_ADJUST_LEFT, aPardMap.nAdjust ));
330 break;
331 case RTF_QR:
332 if( aPardMap.nAdjust )
334 pSet->Put( SvxAdjustItem( SVX_ADJUST_RIGHT, aPardMap.nAdjust ));
336 break;
337 case RTF_QJ:
338 if( aPardMap.nAdjust )
340 pSet->Put( SvxAdjustItem( SVX_ADJUST_BLOCK, aPardMap.nAdjust ));
342 break;
343 case RTF_QC:
344 if( aPardMap.nAdjust )
346 pSet->Put( SvxAdjustItem( SVX_ADJUST_CENTER, aPardMap.nAdjust ));
348 break;
350 case RTF_FI:
351 if( aPardMap.nLRSpace )
353 SvxLRSpaceItem aLR( GetLRSpace(*pSet, aPardMap.nLRSpace ));
354 sal_uInt16 nSz = 0;
355 if( -1 != nTokenValue )
357 if( IsCalcValue() )
358 CalcValue();
359 nSz = sal_uInt16(nTokenValue);
361 aLR.SetTextFirstLineOfst( nSz );
362 pSet->Put( aLR );
364 break;
366 case RTF_LI:
367 case RTF_LIN:
368 if( aPardMap.nLRSpace )
370 SvxLRSpaceItem aLR( GetLRSpace(*pSet, aPardMap.nLRSpace ));
371 sal_uInt16 nSz = 0;
372 if( 0 < nTokenValue )
374 if( IsCalcValue() )
375 CalcValue();
376 nSz = sal_uInt16(nTokenValue);
378 aLR.SetTextLeft( nSz );
379 pSet->Put( aLR );
381 break;
383 case RTF_RI:
384 case RTF_RIN:
385 if( aPardMap.nLRSpace )
387 SvxLRSpaceItem aLR( GetLRSpace(*pSet, aPardMap.nLRSpace ));
388 sal_uInt16 nSz = 0;
389 if( 0 < nTokenValue )
391 if( IsCalcValue() )
392 CalcValue();
393 nSz = sal_uInt16(nTokenValue);
395 aLR.SetRight( nSz );
396 pSet->Put( aLR );
398 break;
400 case RTF_SB:
401 if( aPardMap.nULSpace )
403 SvxULSpaceItem aUL( GetULSpace(*pSet, aPardMap.nULSpace ));
404 sal_uInt16 nSz = 0;
405 if( 0 < nTokenValue )
407 if( IsCalcValue() )
408 CalcValue();
409 nSz = sal_uInt16(nTokenValue);
411 aUL.SetUpper( nSz );
412 pSet->Put( aUL );
414 break;
416 case RTF_SA:
417 if( aPardMap.nULSpace )
419 SvxULSpaceItem aUL( GetULSpace(*pSet, aPardMap.nULSpace ));
420 sal_uInt16 nSz = 0;
421 if( 0 < nTokenValue )
423 if( IsCalcValue() )
424 CalcValue();
425 nSz = sal_uInt16(nTokenValue);
427 aUL.SetLower( nSz );
428 pSet->Put( aUL );
430 break;
432 case RTF_SLMULT:
433 if( aPardMap.nLinespacing && 1 == nTokenValue )
435 // then switches to multi-line!
436 SvxLineSpacingItem aLSpace( GetLineSpacing( *pSet,
437 aPardMap.nLinespacing, false ));
439 // how much do you get from the line height value?
441 // Proportional-Size:
442 // Ie, the ratio is (n / 240) twips
444 nTokenValue = 240;
445 if( IsCalcValue() )
446 CalcValue();
448 nTokenValue = short( 100L * aLSpace.GetLineHeight()
449 / long( nTokenValue ) );
451 if( nTokenValue > 200 ) // Data value for PropLnSp
452 nTokenValue = 200; // is one BYTE !!!
454 aLSpace.SetPropLineSpace( (const sal_uInt8)nTokenValue );
455 aLSpace.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
457 pSet->Put( aLSpace );
459 break;
461 case RTF_SL:
462 if( aPardMap.nLinespacing )
464 // Calculate the ratio between the default font and the
465 // specified size. The distance consists of the line height
466 // (100%) and the space above the line (20%).
467 SvxLineSpacingItem aLSpace(0, aPardMap.nLinespacing);
469 nTokenValue = !bTokenHasValue ? 0 : nTokenValue;
470 if (1000 == nTokenValue )
471 nTokenValue = 240;
473 SvxLineSpace eLnSpc;
474 if (nTokenValue < 0)
476 eLnSpc = SVX_LINE_SPACE_FIX;
477 nTokenValue = -nTokenValue;
479 else if (nTokenValue == 0)
481 //if \sl0 is used, the line spacing is automatically
482 //determined
483 eLnSpc = SVX_LINE_SPACE_AUTO;
485 else
486 eLnSpc = SVX_LINE_SPACE_MIN;
488 if (IsCalcValue())
489 CalcValue();
491 if (eLnSpc != SVX_LINE_SPACE_AUTO)
492 aLSpace.SetLineHeight( (const sal_uInt16)nTokenValue );
494 aLSpace.GetLineSpaceRule() = eLnSpc;
495 pSet->Put(aLSpace);
497 break;
499 case RTF_NOCWRAP:
500 if( aPardMap.nForbRule )
502 pSet->Put( SvxForbiddenRuleItem( false,
503 aPardMap.nForbRule ));
505 break;
506 case RTF_NOOVERFLOW:
507 if( aPardMap.nHangPunct )
509 pSet->Put( SvxHangingPunctuationItem( false,
510 aPardMap.nHangPunct ));
512 break;
514 case RTF_ASPALPHA:
515 if( aPardMap.nScriptSpace )
517 pSet->Put( SvxScriptSpaceItem( true,
518 aPardMap.nScriptSpace ));
520 break;
522 case RTF_FAFIXED:
523 case RTF_FAAUTO: nFontAlign = SvxParaVertAlignItem::AUTOMATIC;
524 goto SET_FONTALIGNMENT;
525 case RTF_FAHANG: nFontAlign = SvxParaVertAlignItem::TOP;
526 goto SET_FONTALIGNMENT;
527 case RTF_FAVAR: nFontAlign = SvxParaVertAlignItem::BOTTOM;
528 goto SET_FONTALIGNMENT;
529 case RTF_FACENTER: nFontAlign = SvxParaVertAlignItem::CENTER;
530 goto SET_FONTALIGNMENT;
531 case RTF_FAROMAN: nFontAlign = SvxParaVertAlignItem::BASELINE;
532 goto SET_FONTALIGNMENT;
533 SET_FONTALIGNMENT:
534 if( aPardMap.nFontAlign )
536 pSet->Put( SvxParaVertAlignItem( nFontAlign,
537 aPardMap.nFontAlign ));
539 break;
541 case RTF_B:
542 case RTF_AB:
543 if( IsAttrSttPos() ) // not in the text flow?
546 SvxWeightItem aTmpItem(
547 nTokenValue ? WEIGHT_BOLD : WEIGHT_NORMAL,
548 SID_ATTR_CHAR_WEIGHT );
549 SetScriptAttr( eCharType, *pSet, aTmpItem);
551 break;
553 case RTF_CAPS:
554 case RTF_SCAPS:
555 if( aPlainMap.nCaseMap &&
556 IsAttrSttPos() ) // not in the text flow?
558 SvxCaseMap eCaseMap;
559 if( !nTokenValue )
560 eCaseMap = SVX_CASEMAP_NOT_MAPPED;
561 else if( RTF_CAPS == nToken )
562 eCaseMap = SVX_CASEMAP_VERSALIEN;
563 else
564 eCaseMap = SVX_CASEMAP_KAPITAELCHEN;
566 pSet->Put( SvxCaseMapItem( eCaseMap, aPlainMap.nCaseMap ));
568 break;
570 case RTF_DN:
571 case RTF_SUB:
572 if( aPlainMap.nEscapement )
574 const sal_uInt16 nEsc = aPlainMap.nEscapement;
575 if( -1 == nTokenValue || RTF_SUB == nToken )
576 nTokenValue = 6;
577 if( IsCalcValue() )
578 CalcValue();
579 const SvxEscapementItem& rOld = GetEscapement( *pSet, nEsc, false );
580 short nEs;
581 sal_uInt8 nProp;
582 if( DFLT_ESC_AUTO_SUPER == rOld.GetEsc() )
584 nEs = DFLT_ESC_AUTO_SUB;
585 nProp = rOld.GetProp();
587 else
589 nEs = (short)-nTokenValue;
590 nProp = (nToken == RTF_SUB) ? DFLT_ESC_PROP : 100;
592 pSet->Put( SvxEscapementItem( nEs, nProp, nEsc ));
594 break;
596 case RTF_NOSUPERSUB:
597 if( aPlainMap.nEscapement )
599 const sal_uInt16 nEsc = aPlainMap.nEscapement;
600 pSet->Put( SvxEscapementItem( nEsc ));
602 break;
604 case RTF_EXPND:
605 if( aPlainMap.nKering )
607 if( -1 == nTokenValue )
608 nTokenValue = 0;
609 else
610 nTokenValue *= 5;
611 if( IsCalcValue() )
612 CalcValue();
613 pSet->Put( SvxKerningItem( (short)nTokenValue, aPlainMap.nKering ));
615 break;
617 case RTF_KERNING:
618 if( aPlainMap.nAutoKerning )
620 if( -1 == nTokenValue )
621 nTokenValue = 0;
622 else
623 nTokenValue *= 10;
624 if( IsCalcValue() )
625 CalcValue();
626 pSet->Put( SvxAutoKernItem( 0 != nTokenValue,
627 aPlainMap.nAutoKerning ));
629 break;
631 case RTF_EXPNDTW:
632 if( aPlainMap.nKering )
634 if( -1 == nTokenValue )
635 nTokenValue = 0;
636 if( IsCalcValue() )
637 CalcValue();
638 pSet->Put( SvxKerningItem( (short)nTokenValue, aPlainMap.nKering ));
640 break;
642 case RTF_F:
643 case RTF_AF:
645 const vcl::Font& rSVFont = GetFont( sal_uInt16(nTokenValue) );
646 SvxFontItem aTmpItem( rSVFont.GetFamily(),
647 rSVFont.GetName(), rSVFont.GetStyleName(),
648 rSVFont.GetPitch(), rSVFont.GetCharSet(),
649 SID_ATTR_CHAR_FONT );
650 SetScriptAttr( eCharType, *pSet, aTmpItem );
651 if( RTF_F == nToken )
653 SetEncoding( rSVFont.GetCharSet() );
654 RereadLookahead();
657 break;
659 case RTF_FS:
660 case RTF_AFS:
662 if( -1 == nTokenValue )
663 nTokenValue = 240;
664 else
665 nTokenValue *= 10;
666 // #i66167#
667 // for the SwRTFParser 'IsCalcValue' will be false and for the EditRTFParser
668 // the converiosn takes now place in EditRTFParser since for other reasons
669 // the wrong MapUnit might still be use there
670 // if( IsCalcValue() )
671 // CalcValue();
672 SvxFontHeightItem aTmpItem(
673 (const sal_uInt16)nTokenValue, 100,
674 SID_ATTR_CHAR_FONTHEIGHT );
675 SetScriptAttr( eCharType, *pSet, aTmpItem );
677 break;
679 case RTF_I:
680 case RTF_AI:
681 if( IsAttrSttPos() ) // not in the text flow?
683 SvxPostureItem aTmpItem(
684 nTokenValue ? ITALIC_NORMAL : ITALIC_NONE,
685 SID_ATTR_CHAR_POSTURE );
686 SetScriptAttr( eCharType, *pSet, aTmpItem );
688 break;
690 case RTF_OUTL:
691 if( aPlainMap.nContour &&
692 IsAttrSttPos() ) // not in the text flow?
694 pSet->Put( SvxContourItem(nTokenValue != 0,
695 aPlainMap.nContour ));
697 break;
699 case RTF_SHAD:
700 if( aPlainMap.nShadowed &&
701 IsAttrSttPos() ) // not in the text flow?
703 pSet->Put( SvxShadowedItem(nTokenValue != 0,
704 aPlainMap.nShadowed ));
706 break;
708 case RTF_STRIKE:
709 if( aPlainMap.nCrossedOut &&
710 IsAttrSttPos() ) // not in the text flow?
712 pSet->Put( SvxCrossedOutItem(
713 nTokenValue ? STRIKEOUT_SINGLE : STRIKEOUT_NONE,
714 aPlainMap.nCrossedOut ));
716 break;
718 case RTF_STRIKED:
719 if( aPlainMap.nCrossedOut ) // not in the text flow?
721 pSet->Put( SvxCrossedOutItem(
722 nTokenValue ? STRIKEOUT_DOUBLE : STRIKEOUT_NONE,
723 aPlainMap.nCrossedOut ));
725 break;
727 case RTF_UL:
728 if( !IsAttrSttPos() )
729 break;
730 eUnderline = nTokenValue ? UNDERLINE_SINGLE : UNDERLINE_NONE;
731 goto ATTR_SETUNDERLINE;
733 case RTF_ULD:
734 eUnderline = UNDERLINE_DOTTED;
735 goto ATTR_SETUNDERLINE;
736 case RTF_ULDASH:
737 eUnderline = UNDERLINE_DASH;
738 goto ATTR_SETUNDERLINE;
739 case RTF_ULDASHD:
740 eUnderline = UNDERLINE_DASHDOT;
741 goto ATTR_SETUNDERLINE;
742 case RTF_ULDASHDD:
743 eUnderline = UNDERLINE_DASHDOTDOT;
744 goto ATTR_SETUNDERLINE;
745 case RTF_ULDB:
746 eUnderline = UNDERLINE_DOUBLE;
747 goto ATTR_SETUNDERLINE;
748 case RTF_ULNONE:
749 eUnderline = UNDERLINE_NONE;
750 goto ATTR_SETUNDERLINE;
751 case RTF_ULTH:
752 eUnderline = UNDERLINE_BOLD;
753 goto ATTR_SETUNDERLINE;
754 case RTF_ULWAVE:
755 eUnderline = UNDERLINE_WAVE;
756 goto ATTR_SETUNDERLINE;
757 case RTF_ULTHD:
758 eUnderline = UNDERLINE_BOLDDOTTED;
759 goto ATTR_SETUNDERLINE;
760 case RTF_ULTHDASH:
761 eUnderline = UNDERLINE_BOLDDASH;
762 goto ATTR_SETUNDERLINE;
763 case RTF_ULLDASH:
764 eUnderline = UNDERLINE_LONGDASH;
765 goto ATTR_SETUNDERLINE;
766 case RTF_ULTHLDASH:
767 eUnderline = UNDERLINE_BOLDLONGDASH;
768 goto ATTR_SETUNDERLINE;
769 case RTF_ULTHDASHD:
770 eUnderline = UNDERLINE_BOLDDASHDOT;
771 goto ATTR_SETUNDERLINE;
772 case RTF_ULTHDASHDD:
773 eUnderline = UNDERLINE_BOLDDASHDOTDOT;
774 goto ATTR_SETUNDERLINE;
775 case RTF_ULHWAVE:
776 eUnderline = UNDERLINE_BOLDWAVE;
777 goto ATTR_SETUNDERLINE;
778 case RTF_ULULDBWAVE:
779 eUnderline = UNDERLINE_DOUBLEWAVE;
780 goto ATTR_SETUNDERLINE;
782 case RTF_ULW:
783 eUnderline = UNDERLINE_SINGLE;
785 if( aPlainMap.nWordlineMode )
787 pSet->Put( SvxWordLineModeItem( true, aPlainMap.nWordlineMode ));
789 goto ATTR_SETUNDERLINE;
791 ATTR_SETUNDERLINE:
792 if( aPlainMap.nUnderline )
794 pSet->Put( SvxUnderlineItem( eUnderline, aPlainMap.nUnderline ));
796 break;
798 case RTF_ULC:
799 if( aPlainMap.nUnderline )
801 SvxUnderlineItem aUL( UNDERLINE_SINGLE, aPlainMap.nUnderline );
802 const SfxPoolItem* pItem;
803 if( SfxItemState::SET == pSet->GetItemState(
804 aPlainMap.nUnderline, false, &pItem ) )
806 // is switched off ?
807 if( UNDERLINE_NONE ==
808 static_cast<const SvxUnderlineItem*>(pItem)->GetLineStyle() )
809 break;
810 aUL = *static_cast<const SvxUnderlineItem*>(pItem);
812 else
813 aUL = static_cast<const SvxUnderlineItem&>(pSet->Get( aPlainMap.nUnderline, false ));
815 if( UNDERLINE_NONE == aUL.GetLineStyle() )
816 aUL.SetLineStyle( UNDERLINE_SINGLE );
817 aUL.SetColor( GetColor( sal_uInt16(nTokenValue) ));
818 pSet->Put( aUL );
820 break;
822 case RTF_OL:
823 if( !IsAttrSttPos() )
824 break;
825 eOverline = nTokenValue ? UNDERLINE_SINGLE : UNDERLINE_NONE;
826 goto ATTR_SETOVERLINE;
828 case RTF_OLD:
829 eOverline = UNDERLINE_DOTTED;
830 goto ATTR_SETOVERLINE;
831 case RTF_OLDASH:
832 eOverline = UNDERLINE_DASH;
833 goto ATTR_SETOVERLINE;
834 case RTF_OLDASHD:
835 eOverline = UNDERLINE_DASHDOT;
836 goto ATTR_SETOVERLINE;
837 case RTF_OLDASHDD:
838 eOverline = UNDERLINE_DASHDOTDOT;
839 goto ATTR_SETOVERLINE;
840 case RTF_OLDB:
841 eOverline = UNDERLINE_DOUBLE;
842 goto ATTR_SETOVERLINE;
843 case RTF_OLNONE:
844 eOverline = UNDERLINE_NONE;
845 goto ATTR_SETOVERLINE;
846 case RTF_OLTH:
847 eOverline = UNDERLINE_BOLD;
848 goto ATTR_SETOVERLINE;
849 case RTF_OLWAVE:
850 eOverline = UNDERLINE_WAVE;
851 goto ATTR_SETOVERLINE;
852 case RTF_OLTHD:
853 eOverline = UNDERLINE_BOLDDOTTED;
854 goto ATTR_SETOVERLINE;
855 case RTF_OLTHDASH:
856 eOverline = UNDERLINE_BOLDDASH;
857 goto ATTR_SETOVERLINE;
858 case RTF_OLLDASH:
859 eOverline = UNDERLINE_LONGDASH;
860 goto ATTR_SETOVERLINE;
861 case RTF_OLTHLDASH:
862 eOverline = UNDERLINE_BOLDLONGDASH;
863 goto ATTR_SETOVERLINE;
864 case RTF_OLTHDASHD:
865 eOverline = UNDERLINE_BOLDDASHDOT;
866 goto ATTR_SETOVERLINE;
867 case RTF_OLTHDASHDD:
868 eOverline = UNDERLINE_BOLDDASHDOTDOT;
869 goto ATTR_SETOVERLINE;
870 case RTF_OLHWAVE:
871 eOverline = UNDERLINE_BOLDWAVE;
872 goto ATTR_SETOVERLINE;
873 case RTF_OLOLDBWAVE:
874 eOverline = UNDERLINE_DOUBLEWAVE;
875 goto ATTR_SETOVERLINE;
877 case RTF_OLW:
878 eOverline = UNDERLINE_SINGLE;
880 if( aPlainMap.nWordlineMode )
882 pSet->Put( SvxWordLineModeItem( true, aPlainMap.nWordlineMode ));
884 goto ATTR_SETOVERLINE;
886 ATTR_SETOVERLINE:
887 if( aPlainMap.nUnderline )
889 pSet->Put( SvxOverlineItem( eOverline, aPlainMap.nOverline ));
891 break;
893 case RTF_OLC:
894 if( aPlainMap.nOverline )
896 SvxOverlineItem aOL( UNDERLINE_SINGLE, aPlainMap.nOverline );
897 const SfxPoolItem* pItem;
898 if( SfxItemState::SET == pSet->GetItemState(
899 aPlainMap.nOverline, false, &pItem ) )
901 // is switched off ?
902 if( UNDERLINE_NONE ==
903 static_cast<const SvxOverlineItem*>(pItem)->GetLineStyle() )
904 break;
905 aOL = *static_cast<const SvxOverlineItem*>(pItem);
907 else
908 aOL = static_cast<const SvxOverlineItem&>(pSet->Get( aPlainMap.nOverline, false ));
910 if( UNDERLINE_NONE == aOL.GetLineStyle() )
911 aOL.SetLineStyle( UNDERLINE_SINGLE );
912 aOL.SetColor( GetColor( sal_uInt16(nTokenValue) ));
913 pSet->Put( aOL );
915 break;
917 case RTF_UP:
918 case RTF_SUPER:
919 if( aPlainMap.nEscapement )
921 const sal_uInt16 nEsc = aPlainMap.nEscapement;
922 if( -1 == nTokenValue || RTF_SUPER == nToken )
923 nTokenValue = 6;
924 if( IsCalcValue() )
925 CalcValue();
926 const SvxEscapementItem& rOld = GetEscapement( *pSet, nEsc, false );
927 short nEs;
928 sal_uInt8 nProp;
929 if( DFLT_ESC_AUTO_SUB == rOld.GetEsc() )
931 nEs = DFLT_ESC_AUTO_SUPER;
932 nProp = rOld.GetProp();
934 else
936 nEs = (short)nTokenValue;
937 nProp = (nToken == RTF_SUPER) ? DFLT_ESC_PROP : 100;
939 pSet->Put( SvxEscapementItem( nEs, nProp, nEsc ));
941 break;
943 case RTF_CF:
944 if( aPlainMap.nColor )
946 pSet->Put( SvxColorItem( GetColor( sal_uInt16(nTokenValue) ),
947 aPlainMap.nColor ));
949 break;
950 //#i12501# While cb is clearly documented in the rtf spec, word
951 //doesn't accept it at all
952 #if 0
953 case RTF_CB:
954 if( aPlainMap.nBgColor )
956 pSet->Put( SvxBrushItem( GetColor( sal_uInt16(nTokenValue) ),
957 aPlainMap.nBgColor ));
959 break;
960 #endif
962 case RTF_LANG:
963 if( aPlainMap.nLanguage )
965 pSet->Put( SvxLanguageItem( (LanguageType)nTokenValue,
966 aPlainMap.nLanguage ));
968 break;
970 case RTF_LANGFE:
971 if( aPlainMap.nCJKLanguage )
973 pSet->Put( SvxLanguageItem( (LanguageType)nTokenValue,
974 aPlainMap.nCJKLanguage ));
976 break;
977 case RTF_ALANG:
979 SvxLanguageItem aTmpItem( (LanguageType)nTokenValue,
980 SID_ATTR_CHAR_LANGUAGE );
981 SetScriptAttr( eCharType, *pSet, aTmpItem );
983 break;
985 case RTF_RTLCH:
986 bIsLeftToRightDef = false;
987 break;
988 case RTF_LTRCH:
989 bIsLeftToRightDef = true;
990 break;
991 case RTF_RTLPAR:
992 if (aPardMap.nDirection)
994 pSet->Put(SvxFrameDirectionItem(FRMDIR_HORI_RIGHT_TOP,
995 aPardMap.nDirection));
997 break;
998 case RTF_LTRPAR:
999 if (aPardMap.nDirection)
1001 pSet->Put(SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP,
1002 aPardMap.nDirection));
1004 break;
1005 case RTF_LOCH: eCharType = LOW_CHARTYPE; break;
1006 case RTF_HICH: eCharType = HIGH_CHARTYPE; break;
1007 case RTF_DBCH: eCharType = DOUBLEBYTE_CHARTYPE; break;
1010 case RTF_ACCNONE:
1011 eEmphasis = EMPHASISMARK_NONE;
1012 goto ATTR_SETEMPHASIS;
1013 case RTF_ACCDOT:
1014 eEmphasis = EMPHASISMARK_DOTS_ABOVE;
1015 goto ATTR_SETEMPHASIS;
1017 case RTF_ACCCOMMA:
1018 eEmphasis = EMPHASISMARK_SIDE_DOTS;
1019 ATTR_SETEMPHASIS:
1020 if( aPlainMap.nEmphasis )
1022 pSet->Put( SvxEmphasisMarkItem( eEmphasis,
1023 aPlainMap.nEmphasis ));
1025 break;
1027 case RTF_TWOINONE:
1028 if( aPlainMap.nTwoLines )
1030 sal_Unicode cStt, cEnd;
1031 switch ( nTokenValue )
1033 case 1: cStt = '(', cEnd = ')'; break;
1034 case 2: cStt = '[', cEnd = ']'; break;
1035 case 3: cStt = '<', cEnd = '>'; break;
1036 case 4: cStt = '{', cEnd = '}'; break;
1037 default: cStt = 0, cEnd = 0; break;
1040 pSet->Put( SvxTwoLinesItem( true, cStt, cEnd,
1041 aPlainMap.nTwoLines ));
1043 break;
1045 case RTF_CHARSCALEX :
1046 if (aPlainMap.nCharScaleX)
1048 //i21372
1049 if (nTokenValue < 1 || nTokenValue > 600)
1050 nTokenValue = 100;
1051 pSet->Put( SvxCharScaleWidthItem( sal_uInt16(nTokenValue),
1052 aPlainMap.nCharScaleX ));
1054 break;
1056 case RTF_HORZVERT:
1057 if( aPlainMap.nHorzVert )
1059 // RTF knows only 90deg
1060 pSet->Put( SvxCharRotateItem( 900, 1 == nTokenValue,
1061 aPlainMap.nHorzVert ));
1063 break;
1065 case RTF_EMBO:
1066 if (aPlainMap.nRelief)
1068 pSet->Put(SvxCharReliefItem(RELIEF_EMBOSSED,
1069 aPlainMap.nRelief));
1071 break;
1072 case RTF_IMPR:
1073 if (aPlainMap.nRelief)
1075 pSet->Put(SvxCharReliefItem(RELIEF_ENGRAVED,
1076 aPlainMap.nRelief));
1078 break;
1079 case RTF_V:
1080 if (aPlainMap.nHidden)
1082 pSet->Put(SvxCharHiddenItem(nTokenValue != 0,
1083 aPlainMap.nHidden));
1085 break;
1086 case RTF_CHBGFDIAG:
1087 case RTF_CHBGDKVERT:
1088 case RTF_CHBGDKHORIZ:
1089 case RTF_CHBGVERT:
1090 case RTF_CHBGHORIZ:
1091 case RTF_CHBGDKFDIAG:
1092 case RTF_CHBGDCROSS:
1093 case RTF_CHBGCROSS:
1094 case RTF_CHBGBDIAG:
1095 case RTF_CHBGDKDCROSS:
1096 case RTF_CHBGDKCROSS:
1097 case RTF_CHBGDKBDIAG:
1098 case RTF_CHCBPAT:
1099 case RTF_CHCFPAT:
1100 case RTF_CHSHDNG:
1101 if( aPlainMap.nBgColor )
1102 ReadBackgroundAttr( nToken, *pSet );
1103 break;
1105 case BRACELEFT:
1107 // tests on Swg internal tokens
1108 bool bHandled = false;
1109 short nSkip = 0;
1110 if( RTF_IGNOREFLAG != GetNextToken())
1111 nSkip = -1;
1112 else if( (nToken = GetNextToken() ) & RTF_SWGDEFS )
1114 bHandled = true;
1115 switch( nToken )
1117 case RTF_PGDSCNO:
1118 case RTF_PGBRK:
1119 case RTF_SOUTLVL:
1120 UnknownAttrToken( nToken, pSet );
1121 // overwrite the closing parenthesis
1122 break;
1124 case RTF_SWG_ESCPROP:
1126 // Store percentage change!
1127 sal_uInt8 nProp = sal_uInt8( nTokenValue / 100 );
1128 short nEsc = 0;
1129 if( 1 == ( nTokenValue % 100 ))
1130 // Recognize own auto-flags!
1131 nEsc = DFLT_ESC_AUTO_SUPER;
1133 if( aPlainMap.nEscapement )
1134 pSet->Put( SvxEscapementItem( nEsc, nProp,
1135 aPlainMap.nEscapement ));
1137 break;
1139 case RTF_HYPHEN:
1141 SvxHyphenZoneItem aHypenZone(
1142 (nTokenValue & 1) != 0,
1143 aPardMap.nHyphenzone );
1144 aHypenZone.SetPageEnd((nTokenValue & 2) != 0);
1146 if( aPardMap.nHyphenzone &&
1147 RTF_HYPHLEAD == GetNextToken() &&
1148 RTF_HYPHTRAIL == GetNextToken() &&
1149 RTF_HYPHMAX == GetNextToken() )
1151 aHypenZone.GetMinLead() =
1152 sal_uInt8(GetStackPtr( -2 )->nTokenValue);
1153 aHypenZone.GetMinTrail() =
1154 sal_uInt8(GetStackPtr( -1 )->nTokenValue);
1155 aHypenZone.GetMaxHyphens() =
1156 sal_uInt8(nTokenValue);
1158 pSet->Put( aHypenZone );
1160 else
1161 SkipGroup(); // at the end of the group
1163 break;
1165 case RTF_SHADOW:
1167 bool bSkip = true;
1168 do { // middle check loop
1169 SvxShadowLocation eSL = SvxShadowLocation( nTokenValue );
1170 if( RTF_SHDW_DIST != GetNextToken() )
1171 break;
1172 sal_uInt16 nDist = sal_uInt16( nTokenValue );
1174 if( RTF_SHDW_STYLE != GetNextToken() )
1175 break;
1177 if( RTF_SHDW_COL != GetNextToken() )
1178 break;
1179 sal_uInt16 nCol = sal_uInt16( nTokenValue );
1181 if( RTF_SHDW_FCOL != GetNextToken() )
1182 break;
1184 Color aColor = GetColor( nCol );
1186 if( aPardMap.nShadow )
1187 pSet->Put( SvxShadowItem( aPardMap.nShadow,
1188 &aColor, nDist, eSL ) );
1190 bSkip = false;
1191 } while( false );
1193 if( bSkip )
1194 SkipGroup(); // at the end of the group
1196 break;
1198 default:
1199 bHandled = false;
1200 if( (nToken & ~(0xff | RTF_SWGDEFS)) == RTF_TABSTOPDEF )
1202 nToken = SkipToken( -2 );
1203 ReadTabAttr( nToken, *pSet );
1206 cmc: #i76140, he who consumed the { must consume the }
1207 We rewound to a state of { being the current
1208 token so it is our responsibility to consume the }
1209 token if we consumed the {. We will not have consumed
1210 the { if it belonged to our caller, i.e. if the { we
1211 are handling is the "firsttoken" passed to us then
1212 the *caller* must consume it, not us. Otherwise *we*
1213 should consume it.
1215 if (nToken == BRACELEFT && !bFirstToken)
1217 nToken = GetNextToken();
1218 SAL_WARN_IF( nToken != BRACERIGHT,
1219 "editeng",
1220 "} did not follow { as expected");
1223 else if( (nToken & ~(0xff| RTF_SWGDEFS)) == RTF_BRDRDEF)
1225 nToken = SkipToken( -2 );
1226 ReadBorderAttr( nToken, *pSet );
1228 else // so no more attribute
1229 nSkip = -2;
1230 break;
1233 #if 1
1235 cmc: #i4727# / #i12713# Who owns this closing bracket?
1236 If we read the opening one, we must read this one, if
1237 other is counting the brackets so as to push/pop off
1238 the correct environment then we will have pushed a new
1239 environment for the start { of this, but will not see
1240 the } and so is out of sync for the rest of the
1241 document.
1243 if (bHandled && !bFirstToken)
1244 GetNextToken();
1245 #endif
1247 else
1248 nSkip = -2;
1250 if( nSkip ) // all completely unknown
1252 if (!bFirstToken)
1253 --nSkip; // BRACELEFT: is the next token
1254 SkipToken( nSkip );
1255 bContinue = false;
1258 break;
1259 default:
1260 if( (nToken & ~0xff ) == RTF_TABSTOPDEF )
1261 ReadTabAttr( nToken, *pSet );
1262 else if( (nToken & ~0xff ) == RTF_BRDRDEF )
1263 ReadBorderAttr( nToken, *pSet );
1264 else if( (nToken & ~0xff ) == RTF_SHADINGDEF )
1265 ReadBackgroundAttr( nToken, *pSet );
1266 else
1268 // unknown token, so token "returned in Parser"
1269 if( !bFirstToken )
1270 SkipToken( -1 );
1271 bContinue = false;
1275 if( bContinue )
1277 nToken = GetNextToken();
1279 bFirstToken = false;
1283 void SvxRTFParser::ReadTabAttr( int nToken, SfxItemSet& rSet )
1285 bool bMethodOwnsToken = false; // #i52542# patch from cmc.
1286 // then read all the TabStops
1287 SvxTabStop aTabStop;
1288 SvxTabStopItem aAttr( 0, 0, SVX_TAB_ADJUST_DEFAULT, aPardMap.nTabStop );
1289 bool bContinue = true;
1290 do {
1291 switch( nToken )
1293 case RTF_TB: // BarTab ???
1294 case RTF_TX:
1296 if( IsCalcValue() )
1297 CalcValue();
1298 aTabStop.GetTabPos() = nTokenValue;
1299 aAttr.Insert( aTabStop );
1300 aTabStop = SvxTabStop(); // all values default
1302 break;
1304 case RTF_TQL:
1305 aTabStop.GetAdjustment() = SVX_TAB_ADJUST_LEFT;
1306 break;
1307 case RTF_TQR:
1308 aTabStop.GetAdjustment() = SVX_TAB_ADJUST_RIGHT;
1309 break;
1310 case RTF_TQC:
1311 aTabStop.GetAdjustment() = SVX_TAB_ADJUST_CENTER;
1312 break;
1313 case RTF_TQDEC:
1314 aTabStop.GetAdjustment() = SVX_TAB_ADJUST_DECIMAL;
1315 break;
1317 case RTF_TLDOT: aTabStop.GetFill() = '.'; break;
1318 case RTF_TLHYPH: aTabStop.GetFill() = ' '; break;
1319 case RTF_TLUL: aTabStop.GetFill() = '_'; break;
1320 case RTF_TLTH: aTabStop.GetFill() = '-'; break;
1321 case RTF_TLEQ: aTabStop.GetFill() = '='; break;
1323 case BRACELEFT:
1325 // Swg - control BRACELEFT RTF_IGNOREFLAG RTF_TLSWG BRACERIGHT
1326 short nSkip = 0;
1327 if( RTF_IGNOREFLAG != GetNextToken() )
1328 nSkip = -1;
1329 else if( RTF_TLSWG != ( nToken = GetNextToken() ))
1330 nSkip = -2;
1331 else
1333 aTabStop.GetDecimal() = sal_uInt8(nTokenValue & 0xff);
1334 aTabStop.GetFill() = sal_uInt8((nTokenValue >> 8) & 0xff);
1335 // overwrite the closing parenthesis
1336 if (bMethodOwnsToken)
1337 GetNextToken();
1339 if( nSkip )
1341 SkipToken( nSkip ); // Ignore back again
1342 bContinue = false;
1345 break;
1347 default:
1348 bContinue = false;
1350 if( bContinue )
1352 nToken = GetNextToken();
1353 bMethodOwnsToken = true;
1355 } while( bContinue );
1357 // Fill with defaults is still missing!
1358 rSet.Put( aAttr );
1359 SkipToken( -1 );
1362 static void SetBorderLine( int nBorderTyp, SvxBoxItem& rItem,
1363 const SvxBorderLine& rBorder )
1365 switch( nBorderTyp )
1367 case RTF_BOX: // run through all levels
1368 case RTF_BRDRT:
1369 rItem.SetLine( &rBorder, SvxBoxItemLine::TOP );
1370 if( RTF_BOX != nBorderTyp )
1371 return;
1372 // fall-through
1373 case RTF_BRDRB:
1374 rItem.SetLine( &rBorder, SvxBoxItemLine::BOTTOM );
1375 if( RTF_BOX != nBorderTyp )
1376 return;
1377 // fall-through
1378 case RTF_BRDRL:
1379 rItem.SetLine( &rBorder, SvxBoxItemLine::LEFT );
1380 if( RTF_BOX != nBorderTyp )
1381 return;
1382 // fall-through
1383 case RTF_BRDRR:
1384 rItem.SetLine( &rBorder, SvxBoxItemLine::RIGHT );
1385 if( RTF_BOX != nBorderTyp )
1386 return;
1390 void SvxRTFParser::ReadBorderAttr( int nToken, SfxItemSet& rSet,
1391 bool bTableDef )
1393 // then read the border attribute
1394 SvxBoxItem aAttr( aPardMap.nBox );
1395 const SfxPoolItem* pItem;
1396 if( SfxItemState::SET == rSet.GetItemState( aPardMap.nBox, false, &pItem ) )
1397 aAttr = *static_cast<const SvxBoxItem*>(pItem);
1399 SvxBorderLine aBrd( 0, DEF_LINE_WIDTH_0 ); // Simple plain line
1400 bool bContinue = true;
1401 int nBorderTyp = 0;
1403 long nWidth = 1;
1404 bool bDoubleWidth = false;
1406 do {
1407 switch( nToken )
1409 case RTF_BOX:
1410 case RTF_BRDRT:
1411 case RTF_BRDRB:
1412 case RTF_BRDRL:
1413 case RTF_BRDRR:
1414 nBorderTyp = nToken;
1415 break;
1417 case RTF_CLBRDRT: // Cell top border
1419 if( bTableDef )
1421 if (nBorderTyp != 0)
1422 SetBorderLine( nBorderTyp, aAttr, aBrd );
1423 nBorderTyp = RTF_BRDRT;
1425 break;
1427 case RTF_CLBRDRB: // Cell bottom border
1429 if( bTableDef )
1431 if (nBorderTyp != 0)
1432 SetBorderLine( nBorderTyp, aAttr, aBrd );
1433 nBorderTyp = RTF_BRDRB;
1435 break;
1437 case RTF_CLBRDRL: // Cell left border
1439 if( bTableDef )
1441 if (nBorderTyp != 0)
1442 SetBorderLine( nBorderTyp, aAttr, aBrd );
1443 nBorderTyp = RTF_BRDRL;
1445 break;
1447 case RTF_CLBRDRR: // Cell right border
1449 if( bTableDef )
1451 if (nBorderTyp != 0)
1452 SetBorderLine( nBorderTyp, aAttr, aBrd );
1453 nBorderTyp = RTF_BRDRR;
1455 break;
1458 case RTF_BRDRDOT: // dotted border
1459 aBrd.SetBorderLineStyle(table::BorderLineStyle::DOTTED);
1460 break;
1461 case RTF_BRDRDASH: // dashed border
1462 aBrd.SetBorderLineStyle(table::BorderLineStyle::DASHED);
1463 break;
1464 case RTF_BRDRHAIR: // hairline border
1466 aBrd.SetBorderLineStyle( table::BorderLineStyle::SOLID);
1467 aBrd.SetWidth( DEF_LINE_WIDTH_0 );
1469 break;
1470 case RTF_BRDRDB: // Double border
1471 aBrd.SetBorderLineStyle(table::BorderLineStyle::DOUBLE);
1472 break;
1473 case RTF_BRDRINSET: // inset border
1474 aBrd.SetBorderLineStyle(table::BorderLineStyle::INSET);
1475 break;
1476 case RTF_BRDROUTSET: // outset border
1477 aBrd.SetBorderLineStyle(table::BorderLineStyle::OUTSET);
1478 break;
1479 case RTF_BRDRTNTHSG: // ThinThick Small gap
1480 aBrd.SetBorderLineStyle(table::BorderLineStyle::THINTHICK_SMALLGAP);
1481 break;
1482 case RTF_BRDRTNTHMG: // ThinThick Medium gap
1483 aBrd.SetBorderLineStyle(table::BorderLineStyle::THINTHICK_MEDIUMGAP);
1484 break;
1485 case RTF_BRDRTNTHLG: // ThinThick Large gap
1486 aBrd.SetBorderLineStyle(table::BorderLineStyle::THINTHICK_LARGEGAP);
1487 break;
1488 case RTF_BRDRTHTNSG: // ThickThin Small gap
1489 aBrd.SetBorderLineStyle(table::BorderLineStyle::THICKTHIN_SMALLGAP);
1490 break;
1491 case RTF_BRDRTHTNMG: // ThickThin Medium gap
1492 aBrd.SetBorderLineStyle(table::BorderLineStyle::THICKTHIN_MEDIUMGAP);
1493 break;
1494 case RTF_BRDRTHTNLG: // ThickThin Large gap
1495 aBrd.SetBorderLineStyle(table::BorderLineStyle::THICKTHIN_LARGEGAP);
1496 break;
1497 case RTF_BRDREMBOSS: // Embossed border
1498 aBrd.SetBorderLineStyle(table::BorderLineStyle::EMBOSSED);
1499 break;
1500 case RTF_BRDRENGRAVE: // Engraved border
1501 aBrd.SetBorderLineStyle(table::BorderLineStyle::ENGRAVED);
1502 break;
1504 case RTF_BRDRS: // single thickness border
1505 bDoubleWidth = false;
1506 break;
1507 case RTF_BRDRTH: // double thickness border width*2
1508 bDoubleWidth = true;
1509 break;
1510 case RTF_BRDRW: // border width <255
1511 nWidth = nTokenValue;
1512 break;
1514 case RTF_BRDRCF: // Border color
1515 aBrd.SetColor( GetColor( sal_uInt16(nTokenValue) ) );
1516 break;
1518 case RTF_BRDRSH: // Shadowed border
1519 rSet.Put( SvxShadowItem( aPardMap.nShadow, (Color*) 0, 60 /*3pt*/,
1520 SVX_SHADOW_BOTTOMRIGHT ) );
1521 break;
1523 case RTF_BRSP: // Spacing to content in twip
1525 switch( nBorderTyp )
1527 case RTF_BRDRB:
1528 aAttr.SetDistance( (sal_uInt16)nTokenValue, SvxBoxItemLine::BOTTOM );
1529 break;
1531 case RTF_BRDRT:
1532 aAttr.SetDistance( (sal_uInt16)nTokenValue, SvxBoxItemLine::TOP );
1533 break;
1535 case RTF_BRDRL:
1536 aAttr.SetDistance( (sal_uInt16)nTokenValue, SvxBoxItemLine::LEFT );
1537 break;
1539 case RTF_BRDRR:
1540 aAttr.SetDistance( (sal_uInt16)nTokenValue, SvxBoxItemLine::RIGHT );
1541 break;
1543 case RTF_BOX:
1544 aAttr.SetDistance( (sal_uInt16)nTokenValue );
1545 break;
1548 break;
1550 case RTF_BRDRBTW: // Border formatting group
1551 case RTF_BRDRBAR: // Border outside
1552 // TODO unhandled ATM
1553 break;
1555 default:
1556 bContinue = (nToken & ~(0xff| RTF_SWGDEFS)) == RTF_BRDRDEF;
1558 if( bContinue )
1559 nToken = GetNextToken();
1560 } while( bContinue );
1562 // Finally compute the border width
1563 if ( bDoubleWidth ) nWidth *= 2;
1564 aBrd.SetWidth( nWidth );
1566 SetBorderLine( nBorderTyp, aAttr, aBrd );
1568 rSet.Put( aAttr );
1569 SkipToken( -1 );
1572 inline sal_uInt32 CalcShading( sal_uInt32 nColor, sal_uInt32 nFillColor, sal_uInt8 nShading )
1574 nColor = (nColor * nShading) / 100;
1575 nFillColor = (nFillColor * ( 100 - nShading )) / 100;
1576 return nColor + nFillColor;
1579 void SvxRTFParser::ReadBackgroundAttr( int nToken, SfxItemSet& rSet,
1580 bool bTableDef )
1582 // then read the border attribute
1583 bool bContinue = true;
1584 sal_uInt16 nColor = USHRT_MAX, nFillColor = USHRT_MAX;
1585 sal_uInt8 nFillValue = 0;
1587 sal_uInt16 nWh = ( nToken & ~0xff ) == RTF_CHRFMT
1588 ? aPlainMap.nBgColor
1589 : aPardMap.nBrush;
1591 do {
1592 switch( nToken )
1594 case RTF_CLCBPAT:
1595 case RTF_CHCBPAT:
1596 case RTF_CBPAT:
1597 nFillColor = sal_uInt16( nTokenValue );
1598 break;
1600 case RTF_CLCFPAT:
1601 case RTF_CHCFPAT:
1602 case RTF_CFPAT:
1603 nColor = sal_uInt16( nTokenValue );
1604 break;
1606 case RTF_CLSHDNG:
1607 case RTF_CHSHDNG:
1608 case RTF_SHADING:
1609 nFillValue = (sal_uInt8)( nTokenValue / 100 );
1610 break;
1612 case RTF_CLBGDKHOR:
1613 case RTF_CHBGDKHORIZ:
1614 case RTF_BGDKHORIZ:
1615 case RTF_CLBGDKVERT:
1616 case RTF_CHBGDKVERT:
1617 case RTF_BGDKVERT:
1618 case RTF_CLBGDKBDIAG:
1619 case RTF_CHBGDKBDIAG:
1620 case RTF_BGDKBDIAG:
1621 case RTF_CLBGDKFDIAG:
1622 case RTF_CHBGDKFDIAG:
1623 case RTF_BGDKFDIAG:
1624 case RTF_CLBGDKCROSS:
1625 case RTF_CHBGDKCROSS:
1626 case RTF_BGDKCROSS:
1627 case RTF_CLBGDKDCROSS:
1628 case RTF_CHBGDKDCROSS:
1629 case RTF_BGDKDCROSS:
1630 // dark -> 60%
1631 nFillValue = 60;
1632 break;
1634 case RTF_CLBGHORIZ:
1635 case RTF_CHBGHORIZ:
1636 case RTF_BGHORIZ:
1637 case RTF_CLBGVERT:
1638 case RTF_CHBGVERT:
1639 case RTF_BGVERT:
1640 case RTF_CLBGBDIAG:
1641 case RTF_CHBGBDIAG:
1642 case RTF_BGBDIAG:
1643 case RTF_CLBGFDIAG:
1644 case RTF_CHBGFDIAG:
1645 case RTF_BGFDIAG:
1646 case RTF_CLBGCROSS:
1647 case RTF_CHBGCROSS:
1648 case RTF_BGCROSS:
1649 case RTF_CLBGDCROSS:
1650 case RTF_CHBGDCROSS:
1651 case RTF_BGDCROSS:
1652 // light -> 20%
1653 nFillValue = 20;
1654 break;
1656 default:
1657 if( bTableDef )
1658 bContinue = (nToken & ~(0xff | RTF_TABLEDEF) ) == RTF_SHADINGDEF;
1659 else
1660 bContinue = (nToken & ~0xff) == RTF_SHADINGDEF;
1662 if( bContinue )
1663 nToken = GetNextToken();
1664 } while( bContinue );
1666 Color aCol( COL_WHITE ), aFCol;
1667 if( !nFillValue )
1669 // there was only one of two colors specified or no BrushTyp
1670 if( USHRT_MAX != nFillColor )
1672 nFillValue = 100;
1673 aCol = GetColor( nFillColor );
1675 else if( USHRT_MAX != nColor )
1676 aFCol = GetColor( nColor );
1678 else
1680 if( USHRT_MAX != nColor )
1681 aCol = GetColor( nColor );
1682 else
1683 aCol = Color( COL_BLACK );
1685 if( USHRT_MAX != nFillColor )
1686 aFCol = GetColor( nFillColor );
1687 else
1688 aFCol = Color( COL_WHITE );
1691 Color aColor;
1692 if( 0 == nFillValue || 100 == nFillValue )
1693 aColor = aCol;
1694 else
1695 aColor = Color(
1696 (sal_uInt8)CalcShading( aCol.GetRed(), aFCol.GetRed(), nFillValue ),
1697 (sal_uInt8)CalcShading( aCol.GetGreen(), aFCol.GetGreen(), nFillValue ),
1698 (sal_uInt8)CalcShading( aCol.GetBlue(), aFCol.GetBlue(), nFillValue ) );
1700 rSet.Put( SvxBrushItem( aColor, nWh ) );
1701 SkipToken( -1 );
1705 // pard / plain handling
1706 void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet )
1708 if( !bNewGroup && !aAttrStack.empty() ) // not at the beginning of a new group
1710 SvxRTFItemStackType* pAkt = aAttrStack.back();
1712 int nLastToken = GetStackPtr(-1)->nTokenId;
1713 bool bNewStkEntry = true;
1714 if( RTF_PARD != nLastToken &&
1715 RTF_PLAIN != nLastToken &&
1716 BRACELEFT != nLastToken )
1718 if( pAkt->aAttrSet.Count() || pAkt->pChildList || pAkt->nStyleNo )
1720 // open a new group
1721 SvxRTFItemStackType* pNew = new SvxRTFItemStackType( *pAkt, *pInsPos, true );
1722 pNew->SetRTFDefaults( GetRTFDefaults() );
1724 // Set all until here valid attributes
1725 AttrGroupEnd();
1726 pAkt = aAttrStack.empty() ? 0 : aAttrStack.back(); // can be changed after AttrGroupEnd!
1727 pNew->aAttrSet.SetParent( pAkt ? &pAkt->aAttrSet : 0 );
1728 aAttrStack.push_back( pNew );
1729 pAkt = pNew;
1731 else
1733 // continue to use this entry as new
1734 pAkt->SetStartPos( *pInsPos );
1735 bNewStkEntry = false;
1739 // now reset all to default
1740 if( bNewStkEntry &&
1741 ( pAkt->aAttrSet.GetParent() || pAkt->aAttrSet.Count() ))
1743 const SfxPoolItem *pItem, *pDef;
1744 const sal_uInt16* pPtr;
1745 sal_uInt16 nCnt;
1746 const SfxItemSet* pDfltSet = &GetRTFDefaults();
1747 if( bPard )
1749 pAkt->nStyleNo = 0;
1750 pPtr = reinterpret_cast<sal_uInt16*>(&aPardMap);
1751 nCnt = sizeof(aPardMap) / sizeof(sal_uInt16);
1753 else
1755 pPtr = reinterpret_cast<sal_uInt16*>(&aPlainMap);
1756 nCnt = sizeof(aPlainMap) / sizeof(sal_uInt16);
1759 for( sal_uInt16 n = 0; n < nCnt; ++n, ++pPtr )
1761 // Item set and different -> Set the Default Pool
1762 if( !*pPtr )
1764 else if( SFX_WHICH_MAX < *pPtr )
1765 pAkt->aAttrSet.ClearItem( *pPtr );
1766 else if( IsChkStyleAttr() )
1767 pAkt->aAttrSet.Put( pDfltSet->Get( *pPtr ) );
1768 else if( !pAkt->aAttrSet.GetParent() )
1770 if( SfxItemState::SET ==
1771 pDfltSet->GetItemState( *pPtr, false, &pDef ))
1772 pAkt->aAttrSet.Put( *pDef );
1773 else
1774 pAkt->aAttrSet.ClearItem( *pPtr );
1776 else if( SfxItemState::SET == pAkt->aAttrSet.GetParent()->
1777 GetItemState( *pPtr, true, &pItem ) &&
1778 *( pDef = &pDfltSet->Get( *pPtr )) != *pItem )
1779 pAkt->aAttrSet.Put( *pDef );
1780 else
1782 if( SfxItemState::SET ==
1783 pDfltSet->GetItemState( *pPtr, false, &pDef ))
1784 pAkt->aAttrSet.Put( *pDef );
1785 else
1786 pAkt->aAttrSet.ClearItem( *pPtr );
1790 else if( bPard )
1791 pAkt->nStyleNo = 0; // reset Style number
1793 *ppSet = &pAkt->aAttrSet;
1795 if (!bPard)
1797 //Once we have a default font, then any text without a font specifier is
1798 //in the default font, and thus has the default font charset, otherwise
1799 //we can fall back to the ansicpg set codeset
1800 if (nDfltFont != -1)
1802 const vcl::Font& rSVFont = GetFont(sal_uInt16(nDfltFont));
1803 SetEncoding(rSVFont.GetCharSet());
1805 else
1806 SetEncoding(GetCodeSet());
1811 void SvxRTFParser::SetDefault( int nToken, int nValue )
1813 if( !bNewDoc )
1814 return;
1816 SfxItemSet aTmp( *pAttrPool, &aWhichMap[0] );
1817 bool bOldFlag = bIsLeftToRightDef;
1818 bIsLeftToRightDef = true;
1819 switch( nToken )
1821 case RTF_ADEFF: bIsLeftToRightDef = false; // no break!
1822 case RTF_DEFF:
1824 if( -1 == nValue )
1825 nValue = 0;
1826 const vcl::Font& rSVFont = GetFont( sal_uInt16(nValue) );
1827 SvxFontItem aTmpItem(
1828 rSVFont.GetFamily(), rSVFont.GetName(),
1829 rSVFont.GetStyleName(), rSVFont.GetPitch(),
1830 rSVFont.GetCharSet(), SID_ATTR_CHAR_FONT );
1831 SetScriptAttr( NOTDEF_CHARTYPE, aTmp, aTmpItem );
1833 break;
1835 case RTF_ADEFLANG: bIsLeftToRightDef = false; // no break!
1836 case RTF_DEFLANG:
1837 // store default Language
1838 if( -1 != nValue )
1840 SvxLanguageItem aTmpItem( (const LanguageType)nValue,
1841 SID_ATTR_CHAR_LANGUAGE );
1842 SetScriptAttr( NOTDEF_CHARTYPE, aTmp, aTmpItem );
1844 break;
1846 case RTF_DEFTAB:
1847 if( aPardMap.nTabStop )
1849 // RTF defines 720 twips as default
1850 bIsSetDfltTab = true;
1851 if( -1 == nValue || !nValue )
1852 nValue = 720;
1854 // who would like to have no twips ...
1855 if( IsCalcValue() )
1857 nTokenValue = nValue;
1858 CalcValue();
1859 nValue = nTokenValue;
1862 // Calculate the ratio of default TabWidth / Tabs and
1863 // calculate the corresponding new number.
1864 // ?? how did one come up with 13 ??
1865 sal_uInt16 nTabCount = (SVX_TAB_DEFDIST * 13 ) / sal_uInt16(nValue);
1867 cmc, make sure we have at least one, or all hell breaks loose in
1868 everybodies exporters, #i8247#
1870 if (nTabCount < 1)
1871 nTabCount = 1;
1873 // we want Defaulttabs
1874 SvxTabStopItem aNewTab( nTabCount, sal_uInt16(nValue),
1875 SVX_TAB_ADJUST_DEFAULT, aPardMap.nTabStop );
1876 while( nTabCount )
1877 ((SvxTabStop&)aNewTab[ --nTabCount ]).GetAdjustment() = SVX_TAB_ADJUST_DEFAULT;
1879 pAttrPool->SetPoolDefaultItem( aNewTab );
1881 break;
1883 bIsLeftToRightDef = bOldFlag;
1885 if( aTmp.Count() )
1887 SfxItemIter aIter( aTmp );
1888 const SfxPoolItem* pItem = aIter.GetCurItem();
1889 while( true )
1891 pAttrPool->SetPoolDefaultItem( *pItem );
1892 if( aIter.IsAtEnd() )
1893 break;
1894 pItem = aIter.NextItem();
1899 // default: no conversion, leaving everything in twips.
1900 void SvxRTFParser::CalcValue()
1904 // for tokens that are not evaluated in ReadAttr
1905 void SvxRTFParser::UnknownAttrToken( int, SfxItemSet* )
1909 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */