4 * Portions Copyright 2004 Mike McCormack for CodeWeavers
5 * Portions Copyright 2006 by Phil Krylov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Derived from RTF Tools by Paul DuBois (dubois@primate.wisc.edu)
24 * Homepage: http://www.snake.net/software/RTF/
25 * Original license follows:
29 * reader.c - RTF file reader. Release 1.10.
33 * Author: Paul DuBois dubois@primate.wisc.edu
35 * This software may be redistributed without restriction and used for
36 * any purpose whatsoever.
42 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
44 static int _RTFGetChar(RTF_Info
*);
45 static void _RTFGetToken (RTF_Info
*);
46 static void _RTFGetToken2 (RTF_Info
*);
47 static int GetChar (RTF_Info
*);
48 static void ReadFontTbl (RTF_Info
*);
49 static void ReadColorTbl (RTF_Info
*);
50 static void ReadStyleSheet (RTF_Info
*);
51 static void ReadInfoGroup (RTF_Info
*);
52 static void ReadPictGroup (RTF_Info
*);
53 static void ReadObjGroup (RTF_Info
*);
54 static void Lookup (RTF_Info
*, char *);
55 static int Hash (const char *);
57 static void CharAttr(RTF_Info
*info
);
58 static void CharSet(RTF_Info
*info
);
59 static void DocAttr(RTF_Info
*info
);
61 static void RTFFlushCPOutputBuffer(RTF_Info
*info
);
62 static void RTFPutCodePageChar(RTF_Info
*info
, int c
);
64 /* ---------------------------------------------------------------------- */
68 * Saves a string on the heap and returns a pointer to it.
70 static inline char *RTFStrSave(const char *s
)
74 p
= heap_alloc (lstrlenA(s
) + 1);
77 return lstrcpyA (p
, s
);
81 /* ---------------------------------------------------------------------- */
84 int _RTFGetChar(RTF_Info
*info
)
87 ME_InStream
*stream
= info
->stream
;
89 if (stream
->dwSize
<= stream
->dwUsed
)
91 ME_StreamInFill(stream
);
92 /* if error, it's EOF */
93 if (stream
->editstream
->dwError
)
95 /* if no bytes read, it's EOF */
96 if (stream
->dwSize
== 0)
99 ch
= (unsigned char)stream
->buffer
[stream
->dwUsed
++];
105 void RTFSetEditStream(RTF_Info
*info
, ME_InStream
*stream
)
107 info
->stream
= stream
;
111 RTFDestroyAttrs(RTF_Info
*info
)
116 RTFStyleElt
*eltList
, *ep
;
118 while (info
->fontList
)
120 fp
= info
->fontList
->rtfNextFont
;
121 heap_free (info
->fontList
->rtfFName
);
122 heap_free (info
->fontList
);
125 while (info
->colorList
)
127 cp
= info
->colorList
->rtfNextColor
;
128 heap_free (info
->colorList
);
129 info
->colorList
= cp
;
131 while (info
->styleList
)
133 sp
= info
->styleList
->rtfNextStyle
;
134 eltList
= info
->styleList
->rtfSSEList
;
137 ep
= eltList
->rtfNextSE
;
138 heap_free (eltList
->rtfSEText
);
142 heap_free (info
->styleList
->rtfSName
);
143 heap_free (info
->styleList
);
144 info
->styleList
= sp
;
150 RTFDestroy(RTF_Info
*info
)
152 if (info
->rtfTextBuf
)
154 heap_free(info
->rtfTextBuf
);
155 heap_free(info
->pushedTextBuf
);
157 RTFDestroyAttrs(info
);
158 heap_free(info
->cpOutputBuffer
);
159 while (info
->tableDef
)
161 RTFTable
*tableDef
= info
->tableDef
;
162 info
->tableDef
= tableDef
->parent
;
169 /* ---------------------------------------------------------------------- */
172 * Callback table manipulation routines
177 * Install or return a writer callback for a token class
180 static void RTFSetClassCallback(RTF_Info
*info
, int class, RTFFuncPtr callback
)
182 if (class >= 0 && class < rtfMaxClass
)
183 info
->ccb
[class] = callback
;
187 static RTFFuncPtr
RTFGetClassCallback(const RTF_Info
*info
, int class)
189 if (class >= 0 && class < rtfMaxClass
)
190 return info
->ccb
[class];
196 * Initialize the reader. This may be called multiple times,
197 * to read multiple files. The only thing not reset is the input
198 * stream; that must be done with RTFSetStream().
201 void RTFInit(RTF_Info
*info
)
205 if (info
->rtfTextBuf
== NULL
) /* initialize the text buffers */
207 info
->rtfTextBuf
= heap_alloc (rtfBufSiz
);
208 info
->pushedTextBuf
= heap_alloc (rtfBufSiz
);
209 if (info
->rtfTextBuf
== NULL
|| info
->pushedTextBuf
== NULL
) {
210 ERR ("Cannot allocate text buffers.\n");
213 info
->rtfTextBuf
[0] = info
->pushedTextBuf
[0] = '\0';
216 for (i
= 0; i
< rtfMaxClass
; i
++)
217 RTFSetClassCallback (info
, i
, NULL
);
218 for (i
= 0; i
< rtfMaxDestination
; i
++)
219 RTFSetDestinationCallback (info
, i
, NULL
);
221 /* install built-in destination readers */
222 RTFSetDestinationCallback (info
, rtfFontTbl
, ReadFontTbl
);
223 RTFSetDestinationCallback (info
, rtfColorTbl
, ReadColorTbl
);
224 RTFSetDestinationCallback (info
, rtfStyleSheet
, ReadStyleSheet
);
225 RTFSetDestinationCallback (info
, rtfInfo
, ReadInfoGroup
);
226 RTFSetDestinationCallback (info
, rtfPict
, ReadPictGroup
);
227 RTFSetDestinationCallback (info
, rtfObject
, ReadObjGroup
);
230 RTFSetReadHook (info
, NULL
);
232 /* dump old lists if necessary */
234 RTFDestroyAttrs(info
);
236 info
->ansiCodePage
= 1252; /* Latin-1; actually unused */
237 info
->unicodeLength
= 1; /* \uc1 is the default */
238 info
->codePage
= info
->ansiCodePage
;
242 info
->pushedClass
= -1;
243 info
->pushedChar
= EOF
;
245 info
->rtfLineNum
= 0;
246 info
->rtfLinePos
= 0;
247 info
->prevChar
= EOF
;
248 info
->bumpLine
= FALSE
;
250 info
->dwCPOutputCount
= 0;
251 if (!info
->cpOutputBuffer
)
253 info
->dwMaxCPOutputCount
= 0x1000;
254 info
->cpOutputBuffer
= heap_alloc(info
->dwMaxCPOutputCount
);
257 info
->tableDef
= NULL
;
258 info
->nestingLevel
= 0;
259 info
->canInheritInTbl
= FALSE
;
260 info
->borderType
= 0;
264 * Install or return a writer callback for a destination type
267 void RTFSetDestinationCallback(RTF_Info
*info
, int dest
, RTFFuncPtr callback
)
269 if (dest
>= 0 && dest
< rtfMaxDestination
)
270 info
->dcb
[dest
] = callback
;
274 static RTFFuncPtr
RTFGetDestinationCallback(const RTF_Info
*info
, int dest
)
276 if (dest
>= 0 && dest
< rtfMaxDestination
)
277 return info
->dcb
[dest
];
282 /* ---------------------------------------------------------------------- */
285 * Token reading routines
290 * Read the input stream, invoking the writer's callbacks
294 void RTFRead(RTF_Info
*info
)
296 while (RTFGetToken (info
) != rtfEOF
)
297 RTFRouteToken (info
);
302 * Route a token. If it's a destination for which a reader is
303 * installed, process the destination internally, otherwise
304 * pass the token to the writer's class callback.
307 void RTFRouteToken(RTF_Info
*info
)
311 if (info
->rtfClass
< 0 || info
->rtfClass
>= rtfMaxClass
) /* watchdog */
313 ERR( "Unknown class %d: %s (reader malfunction)\n",
314 info
->rtfClass
, info
->rtfTextBuf
);
316 if (RTFCheckCM (info
, rtfControl
, rtfDestination
))
318 /* invoke destination-specific callback if there is one */
319 p
= RTFGetDestinationCallback (info
, info
->rtfMinor
);
326 /* invoke class callback if there is one */
327 p
= RTFGetClassCallback (info
, info
->rtfClass
);
334 * Skip to the end of the current group. When this returns,
335 * writers that maintain a state stack may want to call their
336 * state unstacker; global vars will still be set to the group's
340 void RTFSkipGroup(RTF_Info
*info
)
344 while (RTFGetToken (info
) != rtfEOF
)
346 if (info
->rtfClass
== rtfGroup
)
348 if (info
->rtfMajor
== rtfBeginGroup
)
350 else if (info
->rtfMajor
== rtfEndGroup
)
353 break; /* end of initial group */
360 * Do no special processing on the group.
362 * This acts as a placeholder for a callback in order to indicate that it
363 * shouldn't be ignored. Instead it will fallback on the loop in RTFRead.
365 void RTFReadGroup (RTF_Info
*info
)
371 * Install or return a token reader hook.
374 void RTFSetReadHook(RTF_Info
*info
, RTFFuncPtr f
)
380 static RTFFuncPtr
RTFGetReadHook(const RTF_Info
*info
)
382 return (info
->readHook
);
387 * Read one token. Call the read hook if there is one. The
388 * token class is the return value. Returns rtfEOF when there
389 * are no more tokens.
392 int RTFGetToken(RTF_Info
*info
)
396 /* don't try to return anything once EOF is reached */
397 if (info
->rtfClass
== rtfEOF
) {
404 p
= RTFGetReadHook (info
);
406 (*p
) (info
); /* give read hook a look at token */
408 /* Silently discard newlines, carriage returns, nulls. */
409 if (!(info
->rtfClass
== rtfText
&& info
->rtfFormat
!= SF_TEXT
410 && (info
->rtfMajor
== '\r' || info
->rtfMajor
== '\n' || info
->rtfMajor
== '\0')))
413 return (info
->rtfClass
);
417 static void RTFUngetToken(RTF_Info
*info
)
419 if (info
->pushedClass
>= 0) /* there's already an ungotten token */
420 ERR ("cannot unget two tokens\n");
421 if (info
->rtfClass
< 0)
422 ERR ("no token to unget\n");
423 info
->pushedClass
= info
->rtfClass
;
424 info
->pushedMajor
= info
->rtfMajor
;
425 info
->pushedMinor
= info
->rtfMinor
;
426 info
->pushedParam
= info
->rtfParam
;
427 lstrcpyA (info
->pushedTextBuf
, info
->rtfTextBuf
);
428 /* The read hook decrements stackTop on rtfEndGroup, so
429 * increment the value to compensate for it being decremented
430 * twice due to the RTFUngetToken. */
431 if(RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
433 info
->stack
[info
->stackTop
].style
= info
->style
;
434 ME_AddRefStyle(info
->style
);
440 static void _RTFGetToken(RTF_Info
*info
)
442 if (info
->rtfFormat
== SF_TEXT
)
444 info
->rtfMajor
= GetChar (info
);
446 info
->rtfParam
= rtfNoParam
;
447 info
->rtfTextBuf
[info
->rtfTextLen
= 0] = '\0';
448 if (info
->rtfMajor
== EOF
)
449 info
->rtfClass
= rtfEOF
;
451 info
->rtfClass
= rtfText
;
455 /* first check for pushed token from RTFUngetToken() */
457 if (info
->pushedClass
>= 0)
459 info
->rtfClass
= info
->pushedClass
;
460 info
->rtfMajor
= info
->pushedMajor
;
461 info
->rtfMinor
= info
->pushedMinor
;
462 info
->rtfParam
= info
->pushedParam
;
463 lstrcpyA (info
->rtfTextBuf
, info
->pushedTextBuf
);
464 info
->rtfTextLen
= lstrlenA(info
->rtfTextBuf
);
465 info
->pushedClass
= -1;
470 * Beyond this point, no token is ever seen twice, which is
471 * important, e.g., for making sure no "}" pops the font stack twice.
474 _RTFGetToken2 (info
);
479 RTFCharSetToCodePage(RTF_Info
*info
, int charset
)
485 case DEFAULT_CHARSET
:
491 case SHIFTJIS_CHARSET
:
493 case HANGEUL_CHARSET
:
499 case CHINESEBIG5_CHARSET
:
503 case TURKISH_CHARSET
:
505 case VIETNAMESE_CHARSET
:
513 case RUSSIAN_CHARSET
:
517 case EASTEUROPE_CHARSET
:
526 /* FIXME: TranslateCharsetInfo does not work as good as it
527 * should, so let's use it only when all else fails */
528 if (!TranslateCharsetInfo(&n
, &csi
, TCI_SRCCHARSET
))
529 ERR("unknown charset %d\n", charset
);
538 /* this shouldn't be called anywhere but from _RTFGetToken() */
540 static void _RTFGetToken2(RTF_Info
*info
)
545 /* initialize token vars */
547 info
->rtfClass
= rtfUnknown
;
548 info
->rtfParam
= rtfNoParam
;
549 info
->rtfTextBuf
[info
->rtfTextLen
= 0] = '\0';
551 /* get first character, which may be a pushback from previous token */
553 if (info
->pushedChar
!= EOF
)
555 c
= info
->pushedChar
;
556 info
->rtfTextBuf
[info
->rtfTextLen
++] = c
;
557 info
->rtfTextBuf
[info
->rtfTextLen
] = '\0';
558 info
->pushedChar
= EOF
;
560 else if ((c
= GetChar (info
)) == EOF
)
562 info
->rtfClass
= rtfEOF
;
568 info
->rtfClass
= rtfGroup
;
569 info
->rtfMajor
= rtfBeginGroup
;
574 info
->rtfClass
= rtfGroup
;
575 info
->rtfMajor
= rtfEndGroup
;
581 * Two possibilities here:
582 * 1) ASCII 9, effectively like \tab control symbol
583 * 2) literal text char
585 if (c
== '\t') /* ASCII 9 */
587 info
->rtfClass
= rtfControl
;
588 info
->rtfMajor
= rtfSpecialChar
;
589 info
->rtfMinor
= rtfTab
;
593 info
->rtfClass
= rtfText
;
598 if ((c
= GetChar (info
)) == EOF
)
600 /* early eof, whoops (class is rtfUnknown) */
606 * Three possibilities here:
607 * 1) hex encoded text char, e.g., \'d5, \'d3
608 * 2) special escaped text char, e.g., \{, \}
609 * 3) control symbol, e.g., \_, \-, \|, \<10>
611 if (c
== '\'') /* hex char */
615 if ((c
= GetChar (info
)) != EOF
&& (c2
= GetChar (info
)) != EOF
616 && isxdigit(c
) && isxdigit(c2
))
618 info
->rtfClass
= rtfText
;
619 info
->rtfMajor
= RTFCharToHex (c
) * 16 + RTFCharToHex (c2
);
622 /* early eof, whoops */
623 info
->rtfClass
= rtfEOF
;
624 info
->stream
->editstream
->dwError
= -14;
629 /*if (index (":{}\\", c) != NULL)*/ /* escaped char */
630 if (c
== ':' || c
== '{' || c
== '}' || c
== '\\')
632 info
->rtfClass
= rtfText
;
638 Lookup (info
, info
->rtfTextBuf
); /* sets class, major, minor */
644 if ((c
= GetChar (info
)) == EOF
)
649 * At this point, the control word is all collected, so the
650 * major/minor numbers are determined before the parameter
651 * (if any) is scanned. There will be one too many characters
652 * in the buffer, though, so fix up before and restore after
657 info
->rtfTextBuf
[info
->rtfTextLen
-1] = '\0';
658 Lookup (info
, info
->rtfTextBuf
); /* sets class, major, minor */
660 info
->rtfTextBuf
[info
->rtfTextLen
-1] = c
;
663 * Should be looking at first digit of parameter if there
664 * is one, unless it's negative. In that case, next char
665 * is '-', so need to gobble next char, and remember sign.
674 if (c
!= EOF
&& isdigit (c
))
677 while (isdigit (c
)) /* gobble parameter */
679 info
->rtfParam
= info
->rtfParam
* 10 + c
- '0';
680 if ((c
= GetChar (info
)) == EOF
)
683 info
->rtfParam
*= sign
;
686 * If control symbol delimiter was a blank, gobble it.
687 * Otherwise the character is first char of next token, so
688 * push it back for next call. In either case, delete the
689 * delimiter from the token buffer.
694 info
->pushedChar
= c
;
695 info
->rtfTextBuf
[--info
->rtfTextLen
] = '\0';
701 * Read the next character from the input. This handles setting the
702 * current line and position-within-line variables. Those variables are
703 * set correctly whether lines end with CR, LF, or CRLF (the last being
706 * bumpLine indicates whether the line number should be incremented on
707 * the *next* input character.
711 static int GetChar(RTF_Info
*info
)
716 if ((c
= _RTFGetChar(info
)) != EOF
)
718 info
->rtfTextBuf
[info
->rtfTextLen
++] = c
;
719 info
->rtfTextBuf
[info
->rtfTextLen
] = '\0';
721 if (info
->prevChar
== EOF
)
722 info
->bumpLine
= TRUE
;
723 oldBumpLine
= info
->bumpLine
; /* TRUE if prev char was line ending */
724 info
->bumpLine
= FALSE
;
726 info
->bumpLine
= TRUE
;
729 info
->bumpLine
= TRUE
;
730 if (info
->prevChar
== '\r') /* oops, previous \r wasn't */
731 oldBumpLine
= FALSE
; /* really a line ending */
734 if (oldBumpLine
) /* were we supposed to increment the */
735 { /* line count on this char? */
737 info
->rtfLinePos
= 1;
744 /* ---------------------------------------------------------------------- */
747 * Special destination readers. They gobble the destination so the
748 * writer doesn't have to deal with them. That's wrong for any
749 * translator that wants to process any of these itself. In that
750 * case, these readers should be overridden by installing a different
751 * destination callback.
753 * NOTE: The last token read by each of these reader will be the
754 * destination's terminating '}', which will then be the current token.
755 * That '}' token is passed to RTFRouteToken() - the writer has already
756 * seen the '{' that began the destination group, and may have pushed a
757 * state; it also needs to know at the end of the group that a state
760 * It's important that rtf.h and the control token lookup table list
761 * as many symbols as possible, because these destination readers
762 * unfortunately make strict assumptions about the input they expect,
763 * and a token of class rtfUnknown will throw them off easily.
768 * Read { \fonttbl ... } destination. Old font tables don't have
769 * braces around each table entry; try to adjust for that.
772 static void ReadFontTbl(RTF_Info
*info
)
775 char buf
[rtfBufSiz
], *bp
;
781 if (info
->rtfClass
== rtfEOF
)
783 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
785 if (old
< 0) /* first entry - determine tbl type */
787 if (RTFCheckCMM (info
, rtfControl
, rtfCharAttr
, rtfFontNum
))
788 old
= 1; /* no brace */
789 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
791 else /* can't tell! */
792 ERR ("cannot determine format\n");
794 if (old
== 0) /* need to find "{" here */
796 if (!RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
797 ERR ("missing \"{\"\n");
798 RTFGetToken (info
); /* yes, skip to next token */
799 if (info
->rtfClass
== rtfEOF
)
804 ERR ("cannot allocate font entry\n");
808 fp
->rtfNextFont
= info
->fontList
;
812 fp
->rtfFAltName
= NULL
;
814 fp
->rtfFFamily
= FF_DONTCARE
;
815 fp
->rtfFCharSet
= DEFAULT_CHARSET
; /* 1 */
816 fp
->rtfFPitch
= DEFAULT_PITCH
;
818 fp
->rtfFCodePage
= CP_ACP
;
820 while (info
->rtfClass
!= rtfEOF
821 && !RTFCheckCM (info
, rtfText
, ';')
822 && !RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
824 if (info
->rtfClass
== rtfControl
)
826 switch (info
->rtfMajor
)
829 /* ignore token but announce it */
830 WARN ("unknown token \"%s\"\n",
834 fp
->rtfFFamily
= info
->rtfMinor
;
837 switch (info
->rtfMinor
)
840 break; /* ignore unknown? */
842 fp
->rtfFNum
= info
->rtfParam
;
847 switch (info
->rtfMinor
)
850 break; /* ignore unknown? */
852 fp
->rtfFCharSet
= info
->rtfParam
;
853 if (!fp
->rtfFCodePage
)
854 fp
->rtfFCodePage
= RTFCharSetToCodePage(info
, info
->rtfParam
);
857 fp
->rtfFPitch
= info
->rtfParam
;
859 case rtfFontCodePage
:
860 fp
->rtfFCodePage
= info
->rtfParam
;
863 case rtfFTypeTrueType
:
864 fp
->rtfFType
= info
->rtfParam
;
870 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
)) /* dest */
872 RTFSkipGroup (info
); /* ignore for now */
874 else if (info
->rtfClass
== rtfText
) /* font name */
877 while (info
->rtfClass
== rtfText
878 && !RTFCheckCM (info
, rtfText
, ';'))
880 *bp
++ = info
->rtfMajor
;
884 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
885 if(RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
887 RTFUngetToken (info
);
890 fp
->rtfFName
= RTFStrSave (buf
);
891 if (fp
->rtfFName
== NULL
)
892 ERR ("cannot allocate font name\n");
893 /* already have next token; don't read one */
894 /* at bottom of loop */
899 /* ignore token but announce it */
900 WARN ("unknown token \"%s\"\n", info
->rtfTextBuf
);
903 if (info
->rtfClass
== rtfEOF
)
906 if (info
->rtfClass
== rtfEOF
)
908 if (old
== 0) /* need to see "}" here */
911 if (!RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
912 ERR ("missing \"}\"\n");
913 if (info
->rtfClass
== rtfEOF
)
917 /* Apply the real properties of the default font */
918 if (fp
->rtfFNum
== info
->defFont
)
920 if (info
->ansiCodePage
!= CP_UTF8
)
921 info
->codePage
= fp
->rtfFCodePage
;
922 TRACE("default font codepage %d\n", info
->codePage
);
925 if (!fp
|| (fp
->rtfFNum
== -1))
926 ERR("missing font number\n");
928 * Could check other pieces of structure here, too, I suppose.
930 RTFRouteToken (info
); /* feed "}" back to router */
932 /* Set default font */
933 info
->rtfClass
= rtfControl
;
934 info
->rtfMajor
= rtfCharAttr
;
935 info
->rtfMinor
= rtfFontNum
;
936 info
->rtfParam
= info
->defFont
;
937 lstrcpyA(info
->rtfTextBuf
, "f");
943 * The color table entries have color values of -1 if
944 * the default color should be used for the entry (only
945 * a semi-colon is given in the definition, no color values).
946 * There will be a problem if a partial entry (1 or 2 but
947 * not 3 color values) is given. The possibility is ignored
951 static void ReadColorTbl(RTF_Info
*info
)
960 if (info
->rtfClass
== rtfEOF
)
962 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
969 else if (RTFCheckCM(info
, rtfGroup
, rtfBeginGroup
))
977 ERR ("cannot allocate color entry\n");
980 cp
->rtfCNum
= cnum
++;
981 cp
->rtfNextColor
= info
->colorList
;
982 info
->colorList
= cp
;
983 if (!RTFCheckCM (info
, rtfControl
, rtfColorName
))
984 cp
->rtfCRed
= cp
->rtfCGreen
= cp
->rtfCBlue
= -1;
986 cp
->rtfCRed
= cp
->rtfCGreen
= cp
->rtfCBlue
= 0;
988 switch (info
->rtfMinor
)
990 case rtfRed
: cp
->rtfCRed
= info
->rtfParam
& 0xFF; break;
991 case rtfGreen
: cp
->rtfCGreen
= info
->rtfParam
& 0xFF; break;
992 case rtfBlue
: cp
->rtfCBlue
= info
->rtfParam
& 0xFF; break;
995 } while (RTFCheckCM (info
, rtfControl
, rtfColorName
));
997 if (info
->rtfClass
== rtfEOF
)
999 if (!RTFCheckCM (info
, rtfText
, ';'))
1000 ERR ("malformed entry\n");
1002 RTFRouteToken (info
); /* feed "}" back to router */
1007 * The "Normal" style definition doesn't contain any style number,
1008 * all others do. Normal style is given style rtfNormalStyleNum.
1011 static void ReadStyleSheet(RTF_Info
*info
)
1014 RTFStyleElt
*sep
, *sepLast
;
1015 char buf
[rtfBufSiz
], *bp
;
1021 if (info
->rtfClass
== rtfEOF
)
1023 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
1025 sp
= New (RTFStyle
);
1027 ERR ("cannot allocate stylesheet entry\n");
1030 sp
->rtfSName
= NULL
;
1032 sp
->rtfSType
= rtfParStyle
;
1033 sp
->rtfSAdditive
= 0;
1034 sp
->rtfSBasedOn
= rtfNoStyleNum
;
1035 sp
->rtfSNextPar
= -1;
1036 sp
->rtfSSEList
= sepLast
= NULL
;
1037 sp
->rtfNextStyle
= info
->styleList
;
1038 sp
->rtfExpanding
= 0;
1039 info
->styleList
= sp
;
1040 if (!RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
1041 ERR ("missing \"{\"\n");
1046 if (info
->rtfClass
== rtfEOF
1047 || RTFCheckCM (info
, rtfText
, ';'))
1049 if (info
->rtfClass
== rtfControl
)
1051 if (RTFCheckMM (info
, rtfSpecialChar
, rtfOptDest
)) {
1053 ERR("skipping optional destination\n");
1055 info
->rtfClass
= rtfGroup
;
1056 info
->rtfMajor
= rtfEndGroup
;
1058 break; /* ignore "\*" */
1060 if (RTFCheckMM (info
, rtfParAttr
, rtfStyleNum
))
1062 sp
->rtfSNum
= info
->rtfParam
;
1063 sp
->rtfSType
= rtfParStyle
;
1066 if (RTFCheckMM (info
, rtfCharAttr
, rtfCharStyleNum
))
1068 sp
->rtfSNum
= info
->rtfParam
;
1069 sp
->rtfSType
= rtfCharStyle
;
1072 if (RTFCheckMM (info
, rtfSectAttr
, rtfSectStyleNum
))
1074 sp
->rtfSNum
= info
->rtfParam
;
1075 sp
->rtfSType
= rtfSectStyle
;
1078 if (RTFCheckMM (info
, rtfStyleAttr
, rtfBasedOn
))
1080 sp
->rtfSBasedOn
= info
->rtfParam
;
1083 if (RTFCheckMM (info
, rtfStyleAttr
, rtfAdditive
))
1085 sp
->rtfSAdditive
= 1;
1088 if (RTFCheckMM (info
, rtfStyleAttr
, rtfNext
))
1090 sp
->rtfSNextPar
= info
->rtfParam
;
1093 sep
= New (RTFStyleElt
);
1096 ERR ("cannot allocate style element\n");
1099 sep
->rtfSEClass
= info
->rtfClass
;
1100 sep
->rtfSEMajor
= info
->rtfMajor
;
1101 sep
->rtfSEMinor
= info
->rtfMinor
;
1102 sep
->rtfSEParam
= info
->rtfParam
;
1103 sep
->rtfSEText
= RTFStrSave (info
->rtfTextBuf
);
1104 if (sep
->rtfSEText
== NULL
)
1105 ERR ("cannot allocate style element text\n");
1106 if (sepLast
== NULL
)
1107 sp
->rtfSSEList
= sep
; /* first element */
1108 else /* add to end */
1109 sepLast
->rtfNextSE
= sep
;
1110 sep
->rtfNextSE
= NULL
;
1113 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
1116 * This passes over "{\*\keycode ... }, among
1117 * other things. A temporary (perhaps) hack.
1119 ERR("skipping begin\n");
1120 RTFSkipGroup (info
);
1123 else if (info
->rtfClass
== rtfText
) /* style name */
1126 while (info
->rtfClass
== rtfText
)
1128 if (info
->rtfMajor
== ';')
1130 /* put back for "for" loop */
1131 RTFUngetToken (info
);
1134 *bp
++ = info
->rtfMajor
;
1138 sp
->rtfSName
= RTFStrSave (buf
);
1139 if (sp
->rtfSName
== NULL
)
1140 ERR ("cannot allocate style name\n");
1142 else /* unrecognized */
1144 /* ignore token but announce it */
1145 WARN ("unknown token \"%s\"\n", info
->rtfTextBuf
);
1150 if (!RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
1151 ERR ("missing \"}\"\n");
1153 * Check over the style structure. A name is a must.
1154 * If no style number was specified, check whether it's the
1155 * Normal style (in which case it's given style number
1156 * rtfNormalStyleNum). Note that some "normal" style names
1157 * just begin with "Normal" and can have other stuff following,
1158 * e.g., "Normal,Times 10 point". Ugh.
1160 * Some German RTF writers use "Standard" instead of "Normal".
1162 if (sp
->rtfSName
== NULL
)
1163 ERR ("missing style name\n");
1164 if (sp
->rtfSNum
< 0)
1166 if (strncmp (buf
, "Normal", 6) != 0
1167 && strncmp (buf
, "Standard", 8) != 0)
1168 ERR ("missing style number\n");
1169 sp
->rtfSNum
= rtfNormalStyleNum
;
1171 if (sp
->rtfSNextPar
== -1) /* if \snext not given, */
1172 sp
->rtfSNextPar
= sp
->rtfSNum
; /* next is itself */
1174 /* otherwise we're just dealing with fake end group from skipped group */
1176 RTFRouteToken (info
); /* feed "}" back to router */
1180 static void ReadInfoGroup(RTF_Info
*info
)
1182 RTFSkipGroup (info
);
1183 RTFRouteToken (info
); /* feed "}" back to router */
1187 static void ReadPictGroup(RTF_Info
*info
)
1189 RTFSkipGroup (info
);
1190 RTFRouteToken (info
); /* feed "}" back to router */
1194 static void ReadObjGroup(RTF_Info
*info
)
1196 RTFSkipGroup (info
);
1197 RTFRouteToken (info
); /* feed "}" back to router */
1201 /* ---------------------------------------------------------------------- */
1204 * Routines to return pieces of stylesheet, or font or color tables.
1205 * References to style 0 are mapped onto the Normal style.
1208 RTFFont
*RTFGetFont(const RTF_Info
*info
, int num
)
1213 return (info
->fontList
);
1214 for (f
= info
->fontList
; f
!= NULL
; f
= f
->rtfNextFont
)
1216 if (f
->rtfFNum
== num
)
1219 return (f
); /* NULL if not found */
1223 RTFColor
*RTFGetColor(const RTF_Info
*info
, int num
)
1228 return (info
->colorList
);
1229 for (c
= info
->colorList
; c
!= NULL
; c
= c
->rtfNextColor
)
1231 if (c
->rtfCNum
== num
)
1234 return (c
); /* NULL if not found */
1238 /* ---------------------------------------------------------------------- */
1241 * Control symbol lookup routines
1245 typedef struct RTFKey RTFKey
;
1249 int rtfKMajor
; /* major number */
1250 int rtfKMinor
; /* minor number */
1251 const char *rtfKStr
; /* symbol name */
1252 int rtfKHash
; /* symbol name hash value */
1256 * A minor number of -1 means the token has no minor number
1257 * (all valid minor numbers are >= 0).
1260 static RTFKey rtfKey
[] =
1263 * Special characters
1266 { rtfSpecialChar
, rtfIIntVersion
, "vern", 0 },
1267 { rtfSpecialChar
, rtfICreateTime
, "creatim", 0 },
1268 { rtfSpecialChar
, rtfIRevisionTime
, "revtim", 0 },
1269 { rtfSpecialChar
, rtfIPrintTime
, "printim", 0 },
1270 { rtfSpecialChar
, rtfIBackupTime
, "buptim", 0 },
1271 { rtfSpecialChar
, rtfIEditTime
, "edmins", 0 },
1272 { rtfSpecialChar
, rtfIYear
, "yr", 0 },
1273 { rtfSpecialChar
, rtfIMonth
, "mo", 0 },
1274 { rtfSpecialChar
, rtfIDay
, "dy", 0 },
1275 { rtfSpecialChar
, rtfIHour
, "hr", 0 },
1276 { rtfSpecialChar
, rtfIMinute
, "min", 0 },
1277 { rtfSpecialChar
, rtfISecond
, "sec", 0 },
1278 { rtfSpecialChar
, rtfINPages
, "nofpages", 0 },
1279 { rtfSpecialChar
, rtfINWords
, "nofwords", 0 },
1280 { rtfSpecialChar
, rtfINChars
, "nofchars", 0 },
1281 { rtfSpecialChar
, rtfIIntID
, "id", 0 },
1283 { rtfSpecialChar
, rtfCurHeadDate
, "chdate", 0 },
1284 { rtfSpecialChar
, rtfCurHeadDateLong
, "chdpl", 0 },
1285 { rtfSpecialChar
, rtfCurHeadDateAbbrev
, "chdpa", 0 },
1286 { rtfSpecialChar
, rtfCurHeadTime
, "chtime", 0 },
1287 { rtfSpecialChar
, rtfCurHeadPage
, "chpgn", 0 },
1288 { rtfSpecialChar
, rtfSectNum
, "sectnum", 0 },
1289 { rtfSpecialChar
, rtfCurFNote
, "chftn", 0 },
1290 { rtfSpecialChar
, rtfCurAnnotRef
, "chatn", 0 },
1291 { rtfSpecialChar
, rtfFNoteSep
, "chftnsep", 0 },
1292 { rtfSpecialChar
, rtfFNoteCont
, "chftnsepc", 0 },
1293 { rtfSpecialChar
, rtfCell
, "cell", 0 },
1294 { rtfSpecialChar
, rtfRow
, "row", 0 },
1295 { rtfSpecialChar
, rtfPar
, "par", 0 },
1296 /* newline and carriage return are synonyms for */
1297 /* \par when they are preceded by a \ character */
1298 { rtfSpecialChar
, rtfPar
, "\n", 0 },
1299 { rtfSpecialChar
, rtfPar
, "\r", 0 },
1300 { rtfSpecialChar
, rtfSect
, "sect", 0 },
1301 { rtfSpecialChar
, rtfPage
, "page", 0 },
1302 { rtfSpecialChar
, rtfColumn
, "column", 0 },
1303 { rtfSpecialChar
, rtfLine
, "line", 0 },
1304 { rtfSpecialChar
, rtfSoftPage
, "softpage", 0 },
1305 { rtfSpecialChar
, rtfSoftColumn
, "softcol", 0 },
1306 { rtfSpecialChar
, rtfSoftLine
, "softline", 0 },
1307 { rtfSpecialChar
, rtfSoftLineHt
, "softlheight", 0 },
1308 { rtfSpecialChar
, rtfTab
, "tab", 0 },
1309 { rtfSpecialChar
, rtfEmDash
, "emdash", 0 },
1310 { rtfSpecialChar
, rtfEnDash
, "endash", 0 },
1311 { rtfSpecialChar
, rtfEmSpace
, "emspace", 0 },
1312 { rtfSpecialChar
, rtfEnSpace
, "enspace", 0 },
1313 { rtfSpecialChar
, rtfBullet
, "bullet", 0 },
1314 { rtfSpecialChar
, rtfLQuote
, "lquote", 0 },
1315 { rtfSpecialChar
, rtfRQuote
, "rquote", 0 },
1316 { rtfSpecialChar
, rtfLDblQuote
, "ldblquote", 0 },
1317 { rtfSpecialChar
, rtfRDblQuote
, "rdblquote", 0 },
1318 { rtfSpecialChar
, rtfFormula
, "|", 0 },
1319 { rtfSpecialChar
, rtfNoBrkSpace
, "~", 0 },
1320 { rtfSpecialChar
, rtfNoReqHyphen
, "-", 0 },
1321 { rtfSpecialChar
, rtfNoBrkHyphen
, "_", 0 },
1322 { rtfSpecialChar
, rtfOptDest
, "*", 0 },
1323 { rtfSpecialChar
, rtfLTRMark
, "ltrmark", 0 },
1324 { rtfSpecialChar
, rtfRTLMark
, "rtlmark", 0 },
1325 { rtfSpecialChar
, rtfNoWidthJoiner
, "zwj", 0 },
1326 { rtfSpecialChar
, rtfNoWidthNonJoiner
, "zwnj", 0 },
1327 /* is this valid? */
1328 { rtfSpecialChar
, rtfCurHeadPict
, "chpict", 0 },
1329 { rtfSpecialChar
, rtfUnicode
, "u", 0 },
1330 { rtfSpecialChar
, rtfNestCell
, "nestcell", 0 },
1331 { rtfSpecialChar
, rtfNestRow
, "nestrow", 0 },
1334 * Character formatting attributes
1337 { rtfCharAttr
, rtfPlain
, "plain", 0 },
1338 { rtfCharAttr
, rtfBold
, "b", 0 },
1339 { rtfCharAttr
, rtfAllCaps
, "caps", 0 },
1340 { rtfCharAttr
, rtfDeleted
, "deleted", 0 },
1341 { rtfCharAttr
, rtfSubScript
, "dn", 0 },
1342 { rtfCharAttr
, rtfSubScrShrink
, "sub", 0 },
1343 { rtfCharAttr
, rtfNoSuperSub
, "nosupersub", 0 },
1344 { rtfCharAttr
, rtfExpand
, "expnd", 0 },
1345 { rtfCharAttr
, rtfExpandTwips
, "expndtw", 0 },
1346 { rtfCharAttr
, rtfKerning
, "kerning", 0 },
1347 { rtfCharAttr
, rtfFontNum
, "f", 0 },
1348 { rtfCharAttr
, rtfFontSize
, "fs", 0 },
1349 { rtfCharAttr
, rtfItalic
, "i", 0 },
1350 { rtfCharAttr
, rtfOutline
, "outl", 0 },
1351 { rtfCharAttr
, rtfRevised
, "revised", 0 },
1352 { rtfCharAttr
, rtfRevAuthor
, "revauth", 0 },
1353 { rtfCharAttr
, rtfRevDTTM
, "revdttm", 0 },
1354 { rtfCharAttr
, rtfSmallCaps
, "scaps", 0 },
1355 { rtfCharAttr
, rtfShadow
, "shad", 0 },
1356 { rtfCharAttr
, rtfStrikeThru
, "strike", 0 },
1357 { rtfCharAttr
, rtfUnderline
, "ul", 0 },
1358 { rtfCharAttr
, rtfDotUnderline
, "uld", 0 },
1359 { rtfCharAttr
, rtfDbUnderline
, "uldb", 0 },
1360 { rtfCharAttr
, rtfNoUnderline
, "ulnone", 0 },
1361 { rtfCharAttr
, rtfWordUnderline
, "ulw", 0 },
1362 { rtfCharAttr
, rtfSuperScript
, "up", 0 },
1363 { rtfCharAttr
, rtfSuperScrShrink
, "super", 0 },
1364 { rtfCharAttr
, rtfInvisible
, "v", 0 },
1365 { rtfCharAttr
, rtfForeColor
, "cf", 0 },
1366 { rtfCharAttr
, rtfBackColor
, "cb", 0 },
1367 { rtfCharAttr
, rtfRTLChar
, "rtlch", 0 },
1368 { rtfCharAttr
, rtfLTRChar
, "ltrch", 0 },
1369 { rtfCharAttr
, rtfCharStyleNum
, "cs", 0 },
1370 { rtfCharAttr
, rtfCharCharSet
, "cchs", 0 },
1371 { rtfCharAttr
, rtfLanguage
, "lang", 0 },
1372 /* this has disappeared from spec 1.2 */
1373 { rtfCharAttr
, rtfGray
, "gray", 0 },
1374 { rtfCharAttr
, rtfUnicodeLength
, "uc", 0 },
1377 * Paragraph formatting attributes
1380 { rtfParAttr
, rtfParDef
, "pard", 0 },
1381 { rtfParAttr
, rtfStyleNum
, "s", 0 },
1382 { rtfParAttr
, rtfHyphenate
, "hyphpar", 0 },
1383 { rtfParAttr
, rtfInTable
, "intbl", 0 },
1384 { rtfParAttr
, rtfKeep
, "keep", 0 },
1385 { rtfParAttr
, rtfNoWidowControl
, "nowidctlpar", 0 },
1386 { rtfParAttr
, rtfKeepNext
, "keepn", 0 },
1387 { rtfParAttr
, rtfOutlineLevel
, "level", 0 },
1388 { rtfParAttr
, rtfNoLineNum
, "noline", 0 },
1389 { rtfParAttr
, rtfPBBefore
, "pagebb", 0 },
1390 { rtfParAttr
, rtfSideBySide
, "sbys", 0 },
1391 { rtfParAttr
, rtfQuadLeft
, "ql", 0 },
1392 { rtfParAttr
, rtfQuadRight
, "qr", 0 },
1393 { rtfParAttr
, rtfQuadJust
, "qj", 0 },
1394 { rtfParAttr
, rtfQuadCenter
, "qc", 0 },
1395 { rtfParAttr
, rtfFirstIndent
, "fi", 0 },
1396 { rtfParAttr
, rtfLeftIndent
, "li", 0 },
1397 { rtfParAttr
, rtfRightIndent
, "ri", 0 },
1398 { rtfParAttr
, rtfSpaceBefore
, "sb", 0 },
1399 { rtfParAttr
, rtfSpaceAfter
, "sa", 0 },
1400 { rtfParAttr
, rtfSpaceBetween
, "sl", 0 },
1401 { rtfParAttr
, rtfSpaceMultiply
, "slmult", 0 },
1403 { rtfParAttr
, rtfSubDocument
, "subdocument", 0 },
1405 { rtfParAttr
, rtfRTLPar
, "rtlpar", 0 },
1406 { rtfParAttr
, rtfLTRPar
, "ltrpar", 0 },
1408 { rtfParAttr
, rtfTabPos
, "tx", 0 },
1410 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1411 * although it's not in the spec. It's also redundant, since lj
1412 * tabs are the default.
1414 { rtfParAttr
, rtfTabLeft
, "tql", 0 },
1415 { rtfParAttr
, rtfTabRight
, "tqr", 0 },
1416 { rtfParAttr
, rtfTabCenter
, "tqc", 0 },
1417 { rtfParAttr
, rtfTabDecimal
, "tqdec", 0 },
1418 { rtfParAttr
, rtfTabBar
, "tb", 0 },
1419 { rtfParAttr
, rtfLeaderDot
, "tldot", 0 },
1420 { rtfParAttr
, rtfLeaderHyphen
, "tlhyph", 0 },
1421 { rtfParAttr
, rtfLeaderUnder
, "tlul", 0 },
1422 { rtfParAttr
, rtfLeaderThick
, "tlth", 0 },
1423 { rtfParAttr
, rtfLeaderEqual
, "tleq", 0 },
1425 { rtfParAttr
, rtfParLevel
, "pnlvl", 0 },
1426 { rtfParAttr
, rtfParBullet
, "pnlvlblt", 0 },
1427 { rtfParAttr
, rtfParSimple
, "pnlvlbody", 0 },
1428 { rtfParAttr
, rtfParNumCont
, "pnlvlcont", 0 },
1429 { rtfParAttr
, rtfParNumOnce
, "pnnumonce", 0 },
1430 { rtfParAttr
, rtfParNumAcross
, "pnacross", 0 },
1431 { rtfParAttr
, rtfParHangIndent
, "pnhang", 0 },
1432 { rtfParAttr
, rtfParNumRestart
, "pnrestart", 0 },
1433 { rtfParAttr
, rtfParNumCardinal
, "pncard", 0 },
1434 { rtfParAttr
, rtfParNumDecimal
, "pndec", 0 },
1435 { rtfParAttr
, rtfParNumULetter
, "pnucltr", 0 },
1436 { rtfParAttr
, rtfParNumURoman
, "pnucrm", 0 },
1437 { rtfParAttr
, rtfParNumLLetter
, "pnlcltr", 0 },
1438 { rtfParAttr
, rtfParNumLRoman
, "pnlcrm", 0 },
1439 { rtfParAttr
, rtfParNumOrdinal
, "pnord", 0 },
1440 { rtfParAttr
, rtfParNumOrdinalText
, "pnordt", 0 },
1441 { rtfParAttr
, rtfParNumBold
, "pnb", 0 },
1442 { rtfParAttr
, rtfParNumItalic
, "pni", 0 },
1443 { rtfParAttr
, rtfParNumAllCaps
, "pncaps", 0 },
1444 { rtfParAttr
, rtfParNumSmallCaps
, "pnscaps", 0 },
1445 { rtfParAttr
, rtfParNumUnder
, "pnul", 0 },
1446 { rtfParAttr
, rtfParNumDotUnder
, "pnuld", 0 },
1447 { rtfParAttr
, rtfParNumDbUnder
, "pnuldb", 0 },
1448 { rtfParAttr
, rtfParNumNoUnder
, "pnulnone", 0 },
1449 { rtfParAttr
, rtfParNumWordUnder
, "pnulw", 0 },
1450 { rtfParAttr
, rtfParNumStrikethru
, "pnstrike", 0 },
1451 { rtfParAttr
, rtfParNumForeColor
, "pncf", 0 },
1452 { rtfParAttr
, rtfParNumFont
, "pnf", 0 },
1453 { rtfParAttr
, rtfParNumFontSize
, "pnfs", 0 },
1454 { rtfParAttr
, rtfParNumIndent
, "pnindent", 0 },
1455 { rtfParAttr
, rtfParNumSpacing
, "pnsp", 0 },
1456 { rtfParAttr
, rtfParNumInclPrev
, "pnprev", 0 },
1457 { rtfParAttr
, rtfParNumCenter
, "pnqc", 0 },
1458 { rtfParAttr
, rtfParNumLeft
, "pnql", 0 },
1459 { rtfParAttr
, rtfParNumRight
, "pnqr", 0 },
1460 { rtfParAttr
, rtfParNumStartAt
, "pnstart", 0 },
1462 { rtfParAttr
, rtfBorderTop
, "brdrt", 0 },
1463 { rtfParAttr
, rtfBorderBottom
, "brdrb", 0 },
1464 { rtfParAttr
, rtfBorderLeft
, "brdrl", 0 },
1465 { rtfParAttr
, rtfBorderRight
, "brdrr", 0 },
1466 { rtfParAttr
, rtfBorderBetween
, "brdrbtw", 0 },
1467 { rtfParAttr
, rtfBorderBar
, "brdrbar", 0 },
1468 { rtfParAttr
, rtfBorderBox
, "box", 0 },
1469 { rtfParAttr
, rtfBorderSingle
, "brdrs", 0 },
1470 { rtfParAttr
, rtfBorderThick
, "brdrth", 0 },
1471 { rtfParAttr
, rtfBorderShadow
, "brdrsh", 0 },
1472 { rtfParAttr
, rtfBorderDouble
, "brdrdb", 0 },
1473 { rtfParAttr
, rtfBorderDot
, "brdrdot", 0 },
1474 { rtfParAttr
, rtfBorderDot
, "brdrdash", 0 },
1475 { rtfParAttr
, rtfBorderHair
, "brdrhair", 0 },
1476 { rtfParAttr
, rtfBorderWidth
, "brdrw", 0 },
1477 { rtfParAttr
, rtfBorderColor
, "brdrcf", 0 },
1478 { rtfParAttr
, rtfBorderSpace
, "brsp", 0 },
1480 { rtfParAttr
, rtfShading
, "shading", 0 },
1481 { rtfParAttr
, rtfBgPatH
, "bghoriz", 0 },
1482 { rtfParAttr
, rtfBgPatV
, "bgvert", 0 },
1483 { rtfParAttr
, rtfFwdDiagBgPat
, "bgfdiag", 0 },
1484 { rtfParAttr
, rtfBwdDiagBgPat
, "bgbdiag", 0 },
1485 { rtfParAttr
, rtfHatchBgPat
, "bgcross", 0 },
1486 { rtfParAttr
, rtfDiagHatchBgPat
, "bgdcross", 0 },
1487 { rtfParAttr
, rtfDarkBgPatH
, "bgdkhoriz", 0 },
1488 { rtfParAttr
, rtfDarkBgPatV
, "bgdkvert", 0 },
1489 { rtfParAttr
, rtfFwdDarkBgPat
, "bgdkfdiag", 0 },
1490 { rtfParAttr
, rtfBwdDarkBgPat
, "bgdkbdiag", 0 },
1491 { rtfParAttr
, rtfDarkHatchBgPat
, "bgdkcross", 0 },
1492 { rtfParAttr
, rtfDarkDiagHatchBgPat
, "bgdkdcross", 0 },
1493 { rtfParAttr
, rtfBgPatLineColor
, "cfpat", 0 },
1494 { rtfParAttr
, rtfBgPatColor
, "cbpat", 0 },
1495 { rtfParAttr
, rtfNestLevel
, "itap", 0 },
1498 * Section formatting attributes
1501 { rtfSectAttr
, rtfSectDef
, "sectd", 0 },
1502 { rtfSectAttr
, rtfENoteHere
, "endnhere", 0 },
1503 { rtfSectAttr
, rtfPrtBinFirst
, "binfsxn", 0 },
1504 { rtfSectAttr
, rtfPrtBin
, "binsxn", 0 },
1505 { rtfSectAttr
, rtfSectStyleNum
, "ds", 0 },
1507 { rtfSectAttr
, rtfNoBreak
, "sbknone", 0 },
1508 { rtfSectAttr
, rtfColBreak
, "sbkcol", 0 },
1509 { rtfSectAttr
, rtfPageBreak
, "sbkpage", 0 },
1510 { rtfSectAttr
, rtfEvenBreak
, "sbkeven", 0 },
1511 { rtfSectAttr
, rtfOddBreak
, "sbkodd", 0 },
1513 { rtfSectAttr
, rtfColumns
, "cols", 0 },
1514 { rtfSectAttr
, rtfColumnSpace
, "colsx", 0 },
1515 { rtfSectAttr
, rtfColumnNumber
, "colno", 0 },
1516 { rtfSectAttr
, rtfColumnSpRight
, "colsr", 0 },
1517 { rtfSectAttr
, rtfColumnWidth
, "colw", 0 },
1518 { rtfSectAttr
, rtfColumnLine
, "linebetcol", 0 },
1520 { rtfSectAttr
, rtfLineModulus
, "linemod", 0 },
1521 { rtfSectAttr
, rtfLineDist
, "linex", 0 },
1522 { rtfSectAttr
, rtfLineStarts
, "linestarts", 0 },
1523 { rtfSectAttr
, rtfLineRestart
, "linerestart", 0 },
1524 { rtfSectAttr
, rtfLineRestartPg
, "lineppage", 0 },
1525 { rtfSectAttr
, rtfLineCont
, "linecont", 0 },
1527 { rtfSectAttr
, rtfSectPageWid
, "pgwsxn", 0 },
1528 { rtfSectAttr
, rtfSectPageHt
, "pghsxn", 0 },
1529 { rtfSectAttr
, rtfSectMarginLeft
, "marglsxn", 0 },
1530 { rtfSectAttr
, rtfSectMarginRight
, "margrsxn", 0 },
1531 { rtfSectAttr
, rtfSectMarginTop
, "margtsxn", 0 },
1532 { rtfSectAttr
, rtfSectMarginBottom
, "margbsxn", 0 },
1533 { rtfSectAttr
, rtfSectMarginGutter
, "guttersxn", 0 },
1534 { rtfSectAttr
, rtfSectLandscape
, "lndscpsxn", 0 },
1535 { rtfSectAttr
, rtfTitleSpecial
, "titlepg", 0 },
1536 { rtfSectAttr
, rtfHeaderY
, "headery", 0 },
1537 { rtfSectAttr
, rtfFooterY
, "footery", 0 },
1539 { rtfSectAttr
, rtfPageStarts
, "pgnstarts", 0 },
1540 { rtfSectAttr
, rtfPageCont
, "pgncont", 0 },
1541 { rtfSectAttr
, rtfPageRestart
, "pgnrestart", 0 },
1542 { rtfSectAttr
, rtfPageNumRight
, "pgnx", 0 },
1543 { rtfSectAttr
, rtfPageNumTop
, "pgny", 0 },
1544 { rtfSectAttr
, rtfPageDecimal
, "pgndec", 0 },
1545 { rtfSectAttr
, rtfPageURoman
, "pgnucrm", 0 },
1546 { rtfSectAttr
, rtfPageLRoman
, "pgnlcrm", 0 },
1547 { rtfSectAttr
, rtfPageULetter
, "pgnucltr", 0 },
1548 { rtfSectAttr
, rtfPageLLetter
, "pgnlcltr", 0 },
1549 { rtfSectAttr
, rtfPageNumHyphSep
, "pgnhnsh", 0 },
1550 { rtfSectAttr
, rtfPageNumSpaceSep
, "pgnhnsp", 0 },
1551 { rtfSectAttr
, rtfPageNumColonSep
, "pgnhnsc", 0 },
1552 { rtfSectAttr
, rtfPageNumEmdashSep
, "pgnhnsm", 0 },
1553 { rtfSectAttr
, rtfPageNumEndashSep
, "pgnhnsn", 0 },
1555 { rtfSectAttr
, rtfTopVAlign
, "vertalt", 0 },
1556 /* misspelled as "vertal" in specification 1.0 */
1557 { rtfSectAttr
, rtfBottomVAlign
, "vertalb", 0 },
1558 { rtfSectAttr
, rtfCenterVAlign
, "vertalc", 0 },
1559 { rtfSectAttr
, rtfJustVAlign
, "vertalj", 0 },
1561 { rtfSectAttr
, rtfRTLSect
, "rtlsect", 0 },
1562 { rtfSectAttr
, rtfLTRSect
, "ltrsect", 0 },
1564 /* I've seen these in an old spec, but not in real files... */
1565 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1566 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1567 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1568 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1569 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1572 * Document formatting attributes
1575 { rtfDocAttr
, rtfDefTab
, "deftab", 0 },
1576 { rtfDocAttr
, rtfHyphHotZone
, "hyphhotz", 0 },
1577 { rtfDocAttr
, rtfHyphConsecLines
, "hyphconsec", 0 },
1578 { rtfDocAttr
, rtfHyphCaps
, "hyphcaps", 0 },
1579 { rtfDocAttr
, rtfHyphAuto
, "hyphauto", 0 },
1580 { rtfDocAttr
, rtfLineStart
, "linestart", 0 },
1581 { rtfDocAttr
, rtfFracWidth
, "fracwidth", 0 },
1582 /* \makeback was given in old version of spec, it's now */
1583 /* listed as \makebackup */
1584 { rtfDocAttr
, rtfMakeBackup
, "makeback", 0 },
1585 { rtfDocAttr
, rtfMakeBackup
, "makebackup", 0 },
1586 { rtfDocAttr
, rtfRTFDefault
, "defformat", 0 },
1587 { rtfDocAttr
, rtfPSOverlay
, "psover", 0 },
1588 { rtfDocAttr
, rtfDocTemplate
, "doctemp", 0 },
1589 { rtfDocAttr
, rtfDefLanguage
, "deflang", 0 },
1591 { rtfDocAttr
, rtfFENoteType
, "fet", 0 },
1592 { rtfDocAttr
, rtfFNoteEndSect
, "endnotes", 0 },
1593 { rtfDocAttr
, rtfFNoteEndDoc
, "enddoc", 0 },
1594 { rtfDocAttr
, rtfFNoteText
, "ftntj", 0 },
1595 { rtfDocAttr
, rtfFNoteBottom
, "ftnbj", 0 },
1596 { rtfDocAttr
, rtfENoteEndSect
, "aendnotes", 0 },
1597 { rtfDocAttr
, rtfENoteEndDoc
, "aenddoc", 0 },
1598 { rtfDocAttr
, rtfENoteText
, "aftntj", 0 },
1599 { rtfDocAttr
, rtfENoteBottom
, "aftnbj", 0 },
1600 { rtfDocAttr
, rtfFNoteStart
, "ftnstart", 0 },
1601 { rtfDocAttr
, rtfENoteStart
, "aftnstart", 0 },
1602 { rtfDocAttr
, rtfFNoteRestartPage
, "ftnrstpg", 0 },
1603 { rtfDocAttr
, rtfFNoteRestart
, "ftnrestart", 0 },
1604 { rtfDocAttr
, rtfFNoteRestartCont
, "ftnrstcont", 0 },
1605 { rtfDocAttr
, rtfENoteRestart
, "aftnrestart", 0 },
1606 { rtfDocAttr
, rtfENoteRestartCont
, "aftnrstcont", 0 },
1607 { rtfDocAttr
, rtfFNoteNumArabic
, "ftnnar", 0 },
1608 { rtfDocAttr
, rtfFNoteNumLLetter
, "ftnnalc", 0 },
1609 { rtfDocAttr
, rtfFNoteNumULetter
, "ftnnauc", 0 },
1610 { rtfDocAttr
, rtfFNoteNumLRoman
, "ftnnrlc", 0 },
1611 { rtfDocAttr
, rtfFNoteNumURoman
, "ftnnruc", 0 },
1612 { rtfDocAttr
, rtfFNoteNumChicago
, "ftnnchi", 0 },
1613 { rtfDocAttr
, rtfENoteNumArabic
, "aftnnar", 0 },
1614 { rtfDocAttr
, rtfENoteNumLLetter
, "aftnnalc", 0 },
1615 { rtfDocAttr
, rtfENoteNumULetter
, "aftnnauc", 0 },
1616 { rtfDocAttr
, rtfENoteNumLRoman
, "aftnnrlc", 0 },
1617 { rtfDocAttr
, rtfENoteNumURoman
, "aftnnruc", 0 },
1618 { rtfDocAttr
, rtfENoteNumChicago
, "aftnnchi", 0 },
1620 { rtfDocAttr
, rtfPaperWidth
, "paperw", 0 },
1621 { rtfDocAttr
, rtfPaperHeight
, "paperh", 0 },
1622 { rtfDocAttr
, rtfPaperSize
, "psz", 0 },
1623 { rtfDocAttr
, rtfLeftMargin
, "margl", 0 },
1624 { rtfDocAttr
, rtfRightMargin
, "margr", 0 },
1625 { rtfDocAttr
, rtfTopMargin
, "margt", 0 },
1626 { rtfDocAttr
, rtfBottomMargin
, "margb", 0 },
1627 { rtfDocAttr
, rtfFacingPage
, "facingp", 0 },
1628 { rtfDocAttr
, rtfGutterWid
, "gutter", 0 },
1629 { rtfDocAttr
, rtfMirrorMargin
, "margmirror", 0 },
1630 { rtfDocAttr
, rtfLandscape
, "landscape", 0 },
1631 { rtfDocAttr
, rtfPageStart
, "pgnstart", 0 },
1632 { rtfDocAttr
, rtfWidowCtrl
, "widowctrl", 0 },
1634 { rtfDocAttr
, rtfLinkStyles
, "linkstyles", 0 },
1636 { rtfDocAttr
, rtfNoAutoTabIndent
, "notabind", 0 },
1637 { rtfDocAttr
, rtfWrapSpaces
, "wraptrsp", 0 },
1638 { rtfDocAttr
, rtfPrintColorsBlack
, "prcolbl", 0 },
1639 { rtfDocAttr
, rtfNoExtraSpaceRL
, "noextrasprl", 0 },
1640 { rtfDocAttr
, rtfNoColumnBalance
, "nocolbal", 0 },
1641 { rtfDocAttr
, rtfCvtMailMergeQuote
, "cvmme", 0 },
1642 { rtfDocAttr
, rtfSuppressTopSpace
, "sprstsp", 0 },
1643 { rtfDocAttr
, rtfSuppressPreParSpace
, "sprsspbf", 0 },
1644 { rtfDocAttr
, rtfCombineTblBorders
, "otblrul", 0 },
1645 { rtfDocAttr
, rtfTranspMetafiles
, "transmf", 0 },
1646 { rtfDocAttr
, rtfSwapBorders
, "swpbdr", 0 },
1647 { rtfDocAttr
, rtfShowHardBreaks
, "brkfrm", 0 },
1649 { rtfDocAttr
, rtfFormProtected
, "formprot", 0 },
1650 { rtfDocAttr
, rtfAllProtected
, "allprot", 0 },
1651 { rtfDocAttr
, rtfFormShading
, "formshade", 0 },
1652 { rtfDocAttr
, rtfFormDisplay
, "formdisp", 0 },
1653 { rtfDocAttr
, rtfPrintData
, "printdata", 0 },
1655 { rtfDocAttr
, rtfRevProtected
, "revprot", 0 },
1656 { rtfDocAttr
, rtfRevisions
, "revisions", 0 },
1657 { rtfDocAttr
, rtfRevDisplay
, "revprop", 0 },
1658 { rtfDocAttr
, rtfRevBar
, "revbar", 0 },
1660 { rtfDocAttr
, rtfAnnotProtected
, "annotprot", 0 },
1662 { rtfDocAttr
, rtfRTLDoc
, "rtldoc", 0 },
1663 { rtfDocAttr
, rtfLTRDoc
, "ltrdoc", 0 },
1665 { rtfDocAttr
, rtfAnsiCodePage
, "ansicpg", 0 },
1666 { rtfDocAttr
, rtfUTF8RTF
, "urtf", 0 },
1672 { rtfStyleAttr
, rtfAdditive
, "additive", 0 },
1673 { rtfStyleAttr
, rtfBasedOn
, "sbasedon", 0 },
1674 { rtfStyleAttr
, rtfNext
, "snext", 0 },
1677 * Picture attributes
1680 { rtfPictAttr
, rtfMacQD
, "macpict", 0 },
1681 { rtfPictAttr
, rtfPMMetafile
, "pmmetafile", 0 },
1682 { rtfPictAttr
, rtfWinMetafile
, "wmetafile", 0 },
1683 { rtfPictAttr
, rtfDevIndBitmap
, "dibitmap", 0 },
1684 { rtfPictAttr
, rtfWinBitmap
, "wbitmap", 0 },
1685 { rtfPictAttr
, rtfEmfBlip
, "emfblip", 0 },
1686 { rtfPictAttr
, rtfPixelBits
, "wbmbitspixel", 0 },
1687 { rtfPictAttr
, rtfBitmapPlanes
, "wbmplanes", 0 },
1688 { rtfPictAttr
, rtfBitmapWid
, "wbmwidthbytes", 0 },
1690 { rtfPictAttr
, rtfPicWid
, "picw", 0 },
1691 { rtfPictAttr
, rtfPicHt
, "pich", 0 },
1692 { rtfPictAttr
, rtfPicGoalWid
, "picwgoal", 0 },
1693 { rtfPictAttr
, rtfPicGoalHt
, "pichgoal", 0 },
1694 /* these two aren't in the spec, but some writers emit them */
1695 { rtfPictAttr
, rtfPicGoalWid
, "picwGoal", 0 },
1696 { rtfPictAttr
, rtfPicGoalHt
, "pichGoal", 0 },
1697 { rtfPictAttr
, rtfPicScaleX
, "picscalex", 0 },
1698 { rtfPictAttr
, rtfPicScaleY
, "picscaley", 0 },
1699 { rtfPictAttr
, rtfPicScaled
, "picscaled", 0 },
1700 { rtfPictAttr
, rtfPicCropTop
, "piccropt", 0 },
1701 { rtfPictAttr
, rtfPicCropBottom
, "piccropb", 0 },
1702 { rtfPictAttr
, rtfPicCropLeft
, "piccropl", 0 },
1703 { rtfPictAttr
, rtfPicCropRight
, "piccropr", 0 },
1705 { rtfPictAttr
, rtfPicMFHasBitmap
, "picbmp", 0 },
1706 { rtfPictAttr
, rtfPicMFBitsPerPixel
, "picbpp", 0 },
1708 { rtfPictAttr
, rtfPicBinary
, "bin", 0 },
1711 * NeXT graphic attributes
1714 { rtfNeXTGrAttr
, rtfNeXTGWidth
, "width", 0 },
1715 { rtfNeXTGrAttr
, rtfNeXTGHeight
, "height", 0 },
1721 { rtfDestination
, rtfFontTbl
, "fonttbl", 0 },
1722 { rtfDestination
, rtfFontAltName
, "falt", 0 },
1723 { rtfDestination
, rtfEmbeddedFont
, "fonteb", 0 },
1724 { rtfDestination
, rtfFontFile
, "fontfile", 0 },
1725 { rtfDestination
, rtfFileTbl
, "filetbl", 0 },
1726 { rtfDestination
, rtfFileInfo
, "file", 0 },
1727 { rtfDestination
, rtfColorTbl
, "colortbl", 0 },
1728 { rtfDestination
, rtfStyleSheet
, "stylesheet", 0 },
1729 { rtfDestination
, rtfKeyCode
, "keycode", 0 },
1730 { rtfDestination
, rtfRevisionTbl
, "revtbl", 0 },
1731 { rtfDestination
, rtfGenerator
, "generator", 0 },
1732 { rtfDestination
, rtfInfo
, "info", 0 },
1733 { rtfDestination
, rtfITitle
, "title", 0 },
1734 { rtfDestination
, rtfISubject
, "subject", 0 },
1735 { rtfDestination
, rtfIAuthor
, "author", 0 },
1736 { rtfDestination
, rtfIOperator
, "operator", 0 },
1737 { rtfDestination
, rtfIKeywords
, "keywords", 0 },
1738 { rtfDestination
, rtfIComment
, "comment", 0 },
1739 { rtfDestination
, rtfIVersion
, "version", 0 },
1740 { rtfDestination
, rtfIDoccomm
, "doccomm", 0 },
1741 /* \verscomm may not exist -- was seen in earlier spec version */
1742 { rtfDestination
, rtfIVerscomm
, "verscomm", 0 },
1743 { rtfDestination
, rtfNextFile
, "nextfile", 0 },
1744 { rtfDestination
, rtfTemplate
, "template", 0 },
1745 { rtfDestination
, rtfFNSep
, "ftnsep", 0 },
1746 { rtfDestination
, rtfFNContSep
, "ftnsepc", 0 },
1747 { rtfDestination
, rtfFNContNotice
, "ftncn", 0 },
1748 { rtfDestination
, rtfENSep
, "aftnsep", 0 },
1749 { rtfDestination
, rtfENContSep
, "aftnsepc", 0 },
1750 { rtfDestination
, rtfENContNotice
, "aftncn", 0 },
1751 { rtfDestination
, rtfPageNumLevel
, "pgnhn", 0 },
1752 { rtfDestination
, rtfParNumLevelStyle
, "pnseclvl", 0 },
1753 { rtfDestination
, rtfHeader
, "header", 0 },
1754 { rtfDestination
, rtfFooter
, "footer", 0 },
1755 { rtfDestination
, rtfHeaderLeft
, "headerl", 0 },
1756 { rtfDestination
, rtfHeaderRight
, "headerr", 0 },
1757 { rtfDestination
, rtfHeaderFirst
, "headerf", 0 },
1758 { rtfDestination
, rtfFooterLeft
, "footerl", 0 },
1759 { rtfDestination
, rtfFooterRight
, "footerr", 0 },
1760 { rtfDestination
, rtfFooterFirst
, "footerf", 0 },
1761 { rtfDestination
, rtfParNumText
, "pntext", 0 },
1762 { rtfDestination
, rtfParNumbering
, "pn", 0 },
1763 { rtfDestination
, rtfParNumTextAfter
, "pntexta", 0 },
1764 { rtfDestination
, rtfParNumTextBefore
, "pntextb", 0 },
1765 { rtfDestination
, rtfBookmarkStart
, "bkmkstart", 0 },
1766 { rtfDestination
, rtfBookmarkEnd
, "bkmkend", 0 },
1767 { rtfDestination
, rtfPict
, "pict", 0 },
1768 { rtfDestination
, rtfObject
, "object", 0 },
1769 { rtfDestination
, rtfObjClass
, "objclass", 0 },
1770 { rtfDestination
, rtfObjName
, "objname", 0 },
1771 { rtfObjAttr
, rtfObjTime
, "objtime", 0 },
1772 { rtfDestination
, rtfObjData
, "objdata", 0 },
1773 { rtfDestination
, rtfObjAlias
, "objalias", 0 },
1774 { rtfDestination
, rtfObjSection
, "objsect", 0 },
1775 /* objitem and objtopic aren't documented in the spec! */
1776 { rtfDestination
, rtfObjItem
, "objitem", 0 },
1777 { rtfDestination
, rtfObjTopic
, "objtopic", 0 },
1778 { rtfDestination
, rtfObjResult
, "result", 0 },
1779 { rtfDestination
, rtfDrawObject
, "do", 0 },
1780 { rtfDestination
, rtfFootnote
, "footnote", 0 },
1781 { rtfDestination
, rtfAnnotRefStart
, "atrfstart", 0 },
1782 { rtfDestination
, rtfAnnotRefEnd
, "atrfend", 0 },
1783 { rtfDestination
, rtfAnnotID
, "atnid", 0 },
1784 { rtfDestination
, rtfAnnotAuthor
, "atnauthor", 0 },
1785 { rtfDestination
, rtfAnnotation
, "annotation", 0 },
1786 { rtfDestination
, rtfAnnotRef
, "atnref", 0 },
1787 { rtfDestination
, rtfAnnotTime
, "atntime", 0 },
1788 { rtfDestination
, rtfAnnotIcon
, "atnicn", 0 },
1789 { rtfDestination
, rtfField
, "field", 0 },
1790 { rtfDestination
, rtfFieldInst
, "fldinst", 0 },
1791 { rtfDestination
, rtfFieldResult
, "fldrslt", 0 },
1792 { rtfDestination
, rtfDataField
, "datafield", 0 },
1793 { rtfDestination
, rtfIndex
, "xe", 0 },
1794 { rtfDestination
, rtfIndexText
, "txe", 0 },
1795 { rtfDestination
, rtfIndexRange
, "rxe", 0 },
1796 { rtfDestination
, rtfTOC
, "tc", 0 },
1797 { rtfDestination
, rtfNeXTGraphic
, "NeXTGraphic", 0 },
1798 { rtfDestination
, rtfNestTableProps
, "nesttableprops", 0 },
1799 { rtfDestination
, rtfNoNestTables
, "nonesttables", 0 },
1800 { rtfDestination
, rtfShpPict
, "shppict", 0 },
1801 { rtfDestination
, rtfNonShpPict
, "nonshppict", 0 },
1807 { rtfFontFamily
, rtfFFNil
, "fnil", 0 },
1808 { rtfFontFamily
, rtfFFRoman
, "froman", 0 },
1809 { rtfFontFamily
, rtfFFSwiss
, "fswiss", 0 },
1810 { rtfFontFamily
, rtfFFModern
, "fmodern", 0 },
1811 { rtfFontFamily
, rtfFFScript
, "fscript", 0 },
1812 { rtfFontFamily
, rtfFFDecor
, "fdecor", 0 },
1813 { rtfFontFamily
, rtfFFTech
, "ftech", 0 },
1814 { rtfFontFamily
, rtfFFBidirectional
, "fbidi", 0 },
1820 { rtfFontAttr
, rtfFontCharSet
, "fcharset", 0 },
1821 { rtfFontAttr
, rtfFontPitch
, "fprq", 0 },
1822 { rtfFontAttr
, rtfFontCodePage
, "cpg", 0 },
1823 { rtfFontAttr
, rtfFTypeNil
, "ftnil", 0 },
1824 { rtfFontAttr
, rtfFTypeTrueType
, "fttruetype", 0 },
1827 * File table attributes
1830 { rtfFileAttr
, rtfFileNum
, "fid", 0 },
1831 { rtfFileAttr
, rtfFileRelPath
, "frelative", 0 },
1832 { rtfFileAttr
, rtfFileOSNum
, "fosnum", 0 },
1838 { rtfFileSource
, rtfSrcMacintosh
, "fvalidmac", 0 },
1839 { rtfFileSource
, rtfSrcDOS
, "fvaliddos", 0 },
1840 { rtfFileSource
, rtfSrcNTFS
, "fvalidntfs", 0 },
1841 { rtfFileSource
, rtfSrcHPFS
, "fvalidhpfs", 0 },
1842 { rtfFileSource
, rtfSrcNetwork
, "fnetwork", 0 },
1848 { rtfColorName
, rtfRed
, "red", 0 },
1849 { rtfColorName
, rtfGreen
, "green", 0 },
1850 { rtfColorName
, rtfBlue
, "blue", 0 },
1856 { rtfCharSet
, rtfMacCharSet
, "mac", 0 },
1857 { rtfCharSet
, rtfAnsiCharSet
, "ansi", 0 },
1858 { rtfCharSet
, rtfPcCharSet
, "pc", 0 },
1859 { rtfCharSet
, rtfPcaCharSet
, "pca", 0 },
1865 { rtfTblAttr
, rtfRowDef
, "trowd", 0 },
1866 { rtfTblAttr
, rtfRowGapH
, "trgaph", 0 },
1867 { rtfTblAttr
, rtfCellPos
, "cellx", 0 },
1868 { rtfTblAttr
, rtfMergeRngFirst
, "clmgf", 0 },
1869 { rtfTblAttr
, rtfMergePrevious
, "clmrg", 0 },
1871 { rtfTblAttr
, rtfRowLeft
, "trql", 0 },
1872 { rtfTblAttr
, rtfRowRight
, "trqr", 0 },
1873 { rtfTblAttr
, rtfRowCenter
, "trqc", 0 },
1874 { rtfTblAttr
, rtfRowLeftEdge
, "trleft", 0 },
1875 { rtfTblAttr
, rtfRowHt
, "trrh", 0 },
1876 { rtfTblAttr
, rtfRowHeader
, "trhdr", 0 },
1877 { rtfTblAttr
, rtfRowKeep
, "trkeep", 0 },
1879 { rtfTblAttr
, rtfRTLRow
, "rtlrow", 0 },
1880 { rtfTblAttr
, rtfLTRRow
, "ltrrow", 0 },
1882 { rtfTblAttr
, rtfRowBordTop
, "trbrdrt", 0 },
1883 { rtfTblAttr
, rtfRowBordLeft
, "trbrdrl", 0 },
1884 { rtfTblAttr
, rtfRowBordBottom
, "trbrdrb", 0 },
1885 { rtfTblAttr
, rtfRowBordRight
, "trbrdrr", 0 },
1886 { rtfTblAttr
, rtfRowBordHoriz
, "trbrdrh", 0 },
1887 { rtfTblAttr
, rtfRowBordVert
, "trbrdrv", 0 },
1889 { rtfTblAttr
, rtfCellBordBottom
, "clbrdrb", 0 },
1890 { rtfTblAttr
, rtfCellBordTop
, "clbrdrt", 0 },
1891 { rtfTblAttr
, rtfCellBordLeft
, "clbrdrl", 0 },
1892 { rtfTblAttr
, rtfCellBordRight
, "clbrdrr", 0 },
1894 { rtfTblAttr
, rtfCellShading
, "clshdng", 0 },
1895 { rtfTblAttr
, rtfCellBgPatH
, "clbghoriz", 0 },
1896 { rtfTblAttr
, rtfCellBgPatV
, "clbgvert", 0 },
1897 { rtfTblAttr
, rtfCellFwdDiagBgPat
, "clbgfdiag", 0 },
1898 { rtfTblAttr
, rtfCellBwdDiagBgPat
, "clbgbdiag", 0 },
1899 { rtfTblAttr
, rtfCellHatchBgPat
, "clbgcross", 0 },
1900 { rtfTblAttr
, rtfCellDiagHatchBgPat
, "clbgdcross", 0 },
1902 * The spec lists "clbgdkhor", but the corresponding non-cell
1903 * control is "bgdkhoriz". At any rate Macintosh Word seems
1904 * to accept both "clbgdkhor" and "clbgdkhoriz".
1906 { rtfTblAttr
, rtfCellDarkBgPatH
, "clbgdkhoriz", 0 },
1907 { rtfTblAttr
, rtfCellDarkBgPatH
, "clbgdkhor", 0 },
1908 { rtfTblAttr
, rtfCellDarkBgPatV
, "clbgdkvert", 0 },
1909 { rtfTblAttr
, rtfCellFwdDarkBgPat
, "clbgdkfdiag", 0 },
1910 { rtfTblAttr
, rtfCellBwdDarkBgPat
, "clbgdkbdiag", 0 },
1911 { rtfTblAttr
, rtfCellDarkHatchBgPat
, "clbgdkcross", 0 },
1912 { rtfTblAttr
, rtfCellDarkDiagHatchBgPat
, "clbgdkdcross", 0 },
1913 { rtfTblAttr
, rtfCellBgPatLineColor
, "clcfpat", 0 },
1914 { rtfTblAttr
, rtfCellBgPatColor
, "clcbpat", 0 },
1920 { rtfFieldAttr
, rtfFieldDirty
, "flddirty", 0 },
1921 { rtfFieldAttr
, rtfFieldEdited
, "fldedit", 0 },
1922 { rtfFieldAttr
, rtfFieldLocked
, "fldlock", 0 },
1923 { rtfFieldAttr
, rtfFieldPrivate
, "fldpriv", 0 },
1924 { rtfFieldAttr
, rtfFieldAlt
, "fldalt", 0 },
1927 * Positioning attributes
1930 { rtfPosAttr
, rtfAbsWid
, "absw", 0 },
1931 { rtfPosAttr
, rtfAbsHt
, "absh", 0 },
1933 { rtfPosAttr
, rtfRPosMargH
, "phmrg", 0 },
1934 { rtfPosAttr
, rtfRPosPageH
, "phpg", 0 },
1935 { rtfPosAttr
, rtfRPosColH
, "phcol", 0 },
1936 { rtfPosAttr
, rtfPosX
, "posx", 0 },
1937 { rtfPosAttr
, rtfPosNegX
, "posnegx", 0 },
1938 { rtfPosAttr
, rtfPosXCenter
, "posxc", 0 },
1939 { rtfPosAttr
, rtfPosXInside
, "posxi", 0 },
1940 { rtfPosAttr
, rtfPosXOutSide
, "posxo", 0 },
1941 { rtfPosAttr
, rtfPosXRight
, "posxr", 0 },
1942 { rtfPosAttr
, rtfPosXLeft
, "posxl", 0 },
1944 { rtfPosAttr
, rtfRPosMargV
, "pvmrg", 0 },
1945 { rtfPosAttr
, rtfRPosPageV
, "pvpg", 0 },
1946 { rtfPosAttr
, rtfRPosParaV
, "pvpara", 0 },
1947 { rtfPosAttr
, rtfPosY
, "posy", 0 },
1948 { rtfPosAttr
, rtfPosNegY
, "posnegy", 0 },
1949 { rtfPosAttr
, rtfPosYInline
, "posyil", 0 },
1950 { rtfPosAttr
, rtfPosYTop
, "posyt", 0 },
1951 { rtfPosAttr
, rtfPosYCenter
, "posyc", 0 },
1952 { rtfPosAttr
, rtfPosYBottom
, "posyb", 0 },
1954 { rtfPosAttr
, rtfNoWrap
, "nowrap", 0 },
1955 { rtfPosAttr
, rtfDistFromTextAll
, "dxfrtext", 0 },
1956 { rtfPosAttr
, rtfDistFromTextX
, "dfrmtxtx", 0 },
1957 { rtfPosAttr
, rtfDistFromTextY
, "dfrmtxty", 0 },
1958 /* \dyfrtext no longer exists in spec 1.2, apparently */
1959 /* replaced by \dfrmtextx and \dfrmtexty. */
1960 { rtfPosAttr
, rtfTextDistY
, "dyfrtext", 0 },
1962 { rtfPosAttr
, rtfDropCapLines
, "dropcapli", 0 },
1963 { rtfPosAttr
, rtfDropCapType
, "dropcapt", 0 },
1969 { rtfObjAttr
, rtfObjEmb
, "objemb", 0 },
1970 { rtfObjAttr
, rtfObjLink
, "objlink", 0 },
1971 { rtfObjAttr
, rtfObjAutoLink
, "objautlink", 0 },
1972 { rtfObjAttr
, rtfObjSubscriber
, "objsub", 0 },
1973 { rtfObjAttr
, rtfObjPublisher
, "objpub", 0 },
1974 { rtfObjAttr
, rtfObjICEmb
, "objicemb", 0 },
1976 { rtfObjAttr
, rtfObjLinkSelf
, "linkself", 0 },
1977 { rtfObjAttr
, rtfObjLock
, "objupdate", 0 },
1978 { rtfObjAttr
, rtfObjUpdate
, "objlock", 0 },
1980 { rtfObjAttr
, rtfObjHt
, "objh", 0 },
1981 { rtfObjAttr
, rtfObjWid
, "objw", 0 },
1982 { rtfObjAttr
, rtfObjSetSize
, "objsetsize", 0 },
1983 { rtfObjAttr
, rtfObjAlign
, "objalign", 0 },
1984 { rtfObjAttr
, rtfObjTransposeY
, "objtransy", 0 },
1985 { rtfObjAttr
, rtfObjCropTop
, "objcropt", 0 },
1986 { rtfObjAttr
, rtfObjCropBottom
, "objcropb", 0 },
1987 { rtfObjAttr
, rtfObjCropLeft
, "objcropl", 0 },
1988 { rtfObjAttr
, rtfObjCropRight
, "objcropr", 0 },
1989 { rtfObjAttr
, rtfObjScaleX
, "objscalex", 0 },
1990 { rtfObjAttr
, rtfObjScaleY
, "objscaley", 0 },
1992 { rtfObjAttr
, rtfObjResRTF
, "rsltrtf", 0 },
1993 { rtfObjAttr
, rtfObjResPict
, "rsltpict", 0 },
1994 { rtfObjAttr
, rtfObjResBitmap
, "rsltbmp", 0 },
1995 { rtfObjAttr
, rtfObjResText
, "rslttxt", 0 },
1996 { rtfObjAttr
, rtfObjResMerge
, "rsltmerge", 0 },
1998 { rtfObjAttr
, rtfObjBookmarkPubObj
, "bkmkpub", 0 },
1999 { rtfObjAttr
, rtfObjPubAutoUpdate
, "pubauto", 0 },
2002 * Associated character formatting attributes
2005 { rtfACharAttr
, rtfACBold
, "ab", 0 },
2006 { rtfACharAttr
, rtfACAllCaps
, "caps", 0 },
2007 { rtfACharAttr
, rtfACForeColor
, "acf", 0 },
2008 { rtfACharAttr
, rtfACSubScript
, "adn", 0 },
2009 { rtfACharAttr
, rtfACExpand
, "aexpnd", 0 },
2010 { rtfACharAttr
, rtfACFontNum
, "af", 0 },
2011 { rtfACharAttr
, rtfACFontSize
, "afs", 0 },
2012 { rtfACharAttr
, rtfACItalic
, "ai", 0 },
2013 { rtfACharAttr
, rtfACLanguage
, "alang", 0 },
2014 { rtfACharAttr
, rtfACOutline
, "aoutl", 0 },
2015 { rtfACharAttr
, rtfACSmallCaps
, "ascaps", 0 },
2016 { rtfACharAttr
, rtfACShadow
, "ashad", 0 },
2017 { rtfACharAttr
, rtfACStrikeThru
, "astrike", 0 },
2018 { rtfACharAttr
, rtfACUnderline
, "aul", 0 },
2019 { rtfACharAttr
, rtfACDotUnderline
, "auld", 0 },
2020 { rtfACharAttr
, rtfACDbUnderline
, "auldb", 0 },
2021 { rtfACharAttr
, rtfACNoUnderline
, "aulnone", 0 },
2022 { rtfACharAttr
, rtfACWordUnderline
, "aulw", 0 },
2023 { rtfACharAttr
, rtfACSuperScript
, "aup", 0 },
2026 * Footnote attributes
2029 { rtfFNoteAttr
, rtfFNAlt
, "ftnalt", 0 },
2032 * Key code attributes
2035 { rtfKeyCodeAttr
, rtfAltKey
, "alt", 0 },
2036 { rtfKeyCodeAttr
, rtfShiftKey
, "shift", 0 },
2037 { rtfKeyCodeAttr
, rtfControlKey
, "ctrl", 0 },
2038 { rtfKeyCodeAttr
, rtfFunctionKey
, "fn", 0 },
2041 * Bookmark attributes
2044 { rtfBookmarkAttr
, rtfBookmarkFirstCol
, "bkmkcolf", 0 },
2045 { rtfBookmarkAttr
, rtfBookmarkLastCol
, "bkmkcoll", 0 },
2048 * Index entry attributes
2051 { rtfIndexAttr
, rtfIndexNumber
, "xef", 0 },
2052 { rtfIndexAttr
, rtfIndexBold
, "bxe", 0 },
2053 { rtfIndexAttr
, rtfIndexItalic
, "ixe", 0 },
2056 * Table of contents attributes
2059 { rtfTOCAttr
, rtfTOCType
, "tcf", 0 },
2060 { rtfTOCAttr
, rtfTOCLevel
, "tcl", 0 },
2063 * Drawing object attributes
2066 { rtfDrawAttr
, rtfDrawLock
, "dolock", 0 },
2067 { rtfDrawAttr
, rtfDrawPageRelX
, "doxpage", 0 },
2068 { rtfDrawAttr
, rtfDrawColumnRelX
, "dobxcolumn", 0 },
2069 { rtfDrawAttr
, rtfDrawMarginRelX
, "dobxmargin", 0 },
2070 { rtfDrawAttr
, rtfDrawPageRelY
, "dobypage", 0 },
2071 { rtfDrawAttr
, rtfDrawColumnRelY
, "dobycolumn", 0 },
2072 { rtfDrawAttr
, rtfDrawMarginRelY
, "dobymargin", 0 },
2073 { rtfDrawAttr
, rtfDrawHeight
, "dobhgt", 0 },
2075 { rtfDrawAttr
, rtfDrawBeginGroup
, "dpgroup", 0 },
2076 { rtfDrawAttr
, rtfDrawGroupCount
, "dpcount", 0 },
2077 { rtfDrawAttr
, rtfDrawEndGroup
, "dpendgroup", 0 },
2078 { rtfDrawAttr
, rtfDrawArc
, "dparc", 0 },
2079 { rtfDrawAttr
, rtfDrawCallout
, "dpcallout", 0 },
2080 { rtfDrawAttr
, rtfDrawEllipse
, "dpellipse", 0 },
2081 { rtfDrawAttr
, rtfDrawLine
, "dpline", 0 },
2082 { rtfDrawAttr
, rtfDrawPolygon
, "dppolygon", 0 },
2083 { rtfDrawAttr
, rtfDrawPolyLine
, "dppolyline", 0 },
2084 { rtfDrawAttr
, rtfDrawRect
, "dprect", 0 },
2085 { rtfDrawAttr
, rtfDrawTextBox
, "dptxbx", 0 },
2087 { rtfDrawAttr
, rtfDrawOffsetX
, "dpx", 0 },
2088 { rtfDrawAttr
, rtfDrawSizeX
, "dpxsize", 0 },
2089 { rtfDrawAttr
, rtfDrawOffsetY
, "dpy", 0 },
2090 { rtfDrawAttr
, rtfDrawSizeY
, "dpysize", 0 },
2092 { rtfDrawAttr
, rtfCOAngle
, "dpcoa", 0 },
2093 { rtfDrawAttr
, rtfCOAccentBar
, "dpcoaccent", 0 },
2094 { rtfDrawAttr
, rtfCOBestFit
, "dpcobestfit", 0 },
2095 { rtfDrawAttr
, rtfCOBorder
, "dpcoborder", 0 },
2096 { rtfDrawAttr
, rtfCOAttachAbsDist
, "dpcodabs", 0 },
2097 { rtfDrawAttr
, rtfCOAttachBottom
, "dpcodbottom", 0 },
2098 { rtfDrawAttr
, rtfCOAttachCenter
, "dpcodcenter", 0 },
2099 { rtfDrawAttr
, rtfCOAttachTop
, "dpcodtop", 0 },
2100 { rtfDrawAttr
, rtfCOLength
, "dpcolength", 0 },
2101 { rtfDrawAttr
, rtfCONegXQuadrant
, "dpcominusx", 0 },
2102 { rtfDrawAttr
, rtfCONegYQuadrant
, "dpcominusy", 0 },
2103 { rtfDrawAttr
, rtfCOOffset
, "dpcooffset", 0 },
2104 { rtfDrawAttr
, rtfCOAttachSmart
, "dpcosmarta", 0 },
2105 { rtfDrawAttr
, rtfCODoubleLine
, "dpcotdouble", 0 },
2106 { rtfDrawAttr
, rtfCORightAngle
, "dpcotright", 0 },
2107 { rtfDrawAttr
, rtfCOSingleLine
, "dpcotsingle", 0 },
2108 { rtfDrawAttr
, rtfCOTripleLine
, "dpcottriple", 0 },
2110 { rtfDrawAttr
, rtfDrawTextBoxMargin
, "dptxbxmar", 0 },
2111 { rtfDrawAttr
, rtfDrawTextBoxText
, "dptxbxtext", 0 },
2112 { rtfDrawAttr
, rtfDrawRoundRect
, "dproundr", 0 },
2114 { rtfDrawAttr
, rtfDrawPointX
, "dpptx", 0 },
2115 { rtfDrawAttr
, rtfDrawPointY
, "dppty", 0 },
2116 { rtfDrawAttr
, rtfDrawPolyCount
, "dppolycount", 0 },
2118 { rtfDrawAttr
, rtfDrawArcFlipX
, "dparcflipx", 0 },
2119 { rtfDrawAttr
, rtfDrawArcFlipY
, "dparcflipy", 0 },
2121 { rtfDrawAttr
, rtfDrawLineBlue
, "dplinecob", 0 },
2122 { rtfDrawAttr
, rtfDrawLineGreen
, "dplinecog", 0 },
2123 { rtfDrawAttr
, rtfDrawLineRed
, "dplinecor", 0 },
2124 { rtfDrawAttr
, rtfDrawLinePalette
, "dplinepal", 0 },
2125 { rtfDrawAttr
, rtfDrawLineDashDot
, "dplinedado", 0 },
2126 { rtfDrawAttr
, rtfDrawLineDashDotDot
, "dplinedadodo", 0 },
2127 { rtfDrawAttr
, rtfDrawLineDash
, "dplinedash", 0 },
2128 { rtfDrawAttr
, rtfDrawLineDot
, "dplinedot", 0 },
2129 { rtfDrawAttr
, rtfDrawLineGray
, "dplinegray", 0 },
2130 { rtfDrawAttr
, rtfDrawLineHollow
, "dplinehollow", 0 },
2131 { rtfDrawAttr
, rtfDrawLineSolid
, "dplinesolid", 0 },
2132 { rtfDrawAttr
, rtfDrawLineWidth
, "dplinew", 0 },
2134 { rtfDrawAttr
, rtfDrawHollowEndArrow
, "dpaendhol", 0 },
2135 { rtfDrawAttr
, rtfDrawEndArrowLength
, "dpaendl", 0 },
2136 { rtfDrawAttr
, rtfDrawSolidEndArrow
, "dpaendsol", 0 },
2137 { rtfDrawAttr
, rtfDrawEndArrowWidth
, "dpaendw", 0 },
2138 { rtfDrawAttr
, rtfDrawHollowStartArrow
,"dpastarthol", 0 },
2139 { rtfDrawAttr
, rtfDrawStartArrowLength
,"dpastartl", 0 },
2140 { rtfDrawAttr
, rtfDrawSolidStartArrow
, "dpastartsol", 0 },
2141 { rtfDrawAttr
, rtfDrawStartArrowWidth
, "dpastartw", 0 },
2143 { rtfDrawAttr
, rtfDrawBgFillBlue
, "dpfillbgcb", 0 },
2144 { rtfDrawAttr
, rtfDrawBgFillGreen
, "dpfillbgcg", 0 },
2145 { rtfDrawAttr
, rtfDrawBgFillRed
, "dpfillbgcr", 0 },
2146 { rtfDrawAttr
, rtfDrawBgFillPalette
, "dpfillbgpal", 0 },
2147 { rtfDrawAttr
, rtfDrawBgFillGray
, "dpfillbggray", 0 },
2148 { rtfDrawAttr
, rtfDrawFgFillBlue
, "dpfillfgcb", 0 },
2149 { rtfDrawAttr
, rtfDrawFgFillGreen
, "dpfillfgcg", 0 },
2150 { rtfDrawAttr
, rtfDrawFgFillRed
, "dpfillfgcr", 0 },
2151 { rtfDrawAttr
, rtfDrawFgFillPalette
, "dpfillfgpal", 0 },
2152 { rtfDrawAttr
, rtfDrawFgFillGray
, "dpfillfggray", 0 },
2153 { rtfDrawAttr
, rtfDrawFillPatIndex
, "dpfillpat", 0 },
2155 { rtfDrawAttr
, rtfDrawShadow
, "dpshadow", 0 },
2156 { rtfDrawAttr
, rtfDrawShadowXOffset
, "dpshadx", 0 },
2157 { rtfDrawAttr
, rtfDrawShadowYOffset
, "dpshady", 0 },
2159 { rtfVersion
, -1, "rtf", 0 },
2160 { rtfDefFont
, -1, "deff", 0 },
2164 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2166 typedef struct tagRTFHashTableEntry
{
2169 } RTFHashTableEntry
;
2171 static RTFHashTableEntry rtfHashTable
[RTF_KEY_COUNT
* 2];
2175 * Initialize lookup table hash values. Only need to do this once.
2178 void LookupInit(void)
2182 memset(rtfHashTable
, 0, sizeof rtfHashTable
);
2183 for (rp
= rtfKey
; rp
->rtfKStr
!= NULL
; rp
++)
2187 rp
->rtfKHash
= Hash (rp
->rtfKStr
);
2188 index
= rp
->rtfKHash
% (RTF_KEY_COUNT
* 2);
2189 if (!rtfHashTable
[index
].count
)
2190 rtfHashTable
[index
].value
= heap_alloc(sizeof(RTFKey
*));
2192 rtfHashTable
[index
].value
= heap_realloc(rtfHashTable
[index
].value
, sizeof(RTFKey
*) * (rtfHashTable
[index
].count
+ 1));
2193 rtfHashTable
[index
].value
[rtfHashTable
[index
].count
++] = rp
;
2197 void LookupCleanup(void)
2201 for (i
=0; i
<RTF_KEY_COUNT
*2; i
++)
2203 heap_free( rtfHashTable
[i
].value
);
2204 rtfHashTable
[i
].value
= NULL
;
2205 rtfHashTable
[i
].count
= 0;
2211 * Determine major and minor number of control token. If it's
2212 * not found, the class turns into rtfUnknown.
2215 static void Lookup(RTF_Info
*info
, char *s
)
2219 RTFHashTableEntry
*entry
;
2222 ++s
; /* skip over the leading \ character */
2224 entry
= &rtfHashTable
[hash
% (RTF_KEY_COUNT
* 2)];
2225 for (i
= 0; i
< entry
->count
; i
++)
2227 rp
= entry
->value
[i
];
2228 if (hash
== rp
->rtfKHash
&& strcmp (s
, rp
->rtfKStr
) == 0)
2230 info
->rtfClass
= rtfControl
;
2231 info
->rtfMajor
= rp
->rtfKMajor
;
2232 info
->rtfMinor
= rp
->rtfKMinor
;
2236 info
->rtfClass
= rtfUnknown
;
2241 * Compute hash value of symbol
2244 static int Hash(const char *s
)
2249 while ((c
= *s
++) != '\0')
2256 /* ---------------------------------------------------------------------- */
2260 * Token comparison routines
2263 int RTFCheckCM(const RTF_Info
*info
, int class, int major
)
2265 return (info
->rtfClass
== class && info
->rtfMajor
== major
);
2269 int RTFCheckCMM(const RTF_Info
*info
, int class, int major
, int minor
)
2271 return (info
->rtfClass
== class && info
->rtfMajor
== major
&& info
->rtfMinor
== minor
);
2275 int RTFCheckMM(const RTF_Info
*info
, int major
, int minor
)
2277 return (info
->rtfMajor
== major
&& info
->rtfMinor
== minor
);
2281 /* ---------------------------------------------------------------------- */
2284 int RTFCharToHex(char c
)
2289 return (c
- '0'); /* '0'..'9' */
2290 return (c
- 'a' + 10); /* 'a'..'f' */
2294 /* ---------------------------------------------------------------------- */
2297 * originally from RTF tools' text-writer.c
2299 * text-writer -- RTF-to-text translation writer code.
2301 * Read RTF input, write text of document (text extraction).
2304 static void TextClass (RTF_Info
*info
);
2305 static void ControlClass (RTF_Info
*info
);
2306 static void DefFont(RTF_Info
*info
);
2307 static void Destination (RTF_Info
*info
);
2308 static void SpecialChar (RTF_Info
*info
);
2309 static void RTFPutUnicodeChar (RTF_Info
*info
, int c
);
2312 * Initialize the writer.
2316 WriterInit (RTF_Info
*info
)
2322 BeginFile (RTF_Info
*info
)
2324 /* install class callbacks */
2326 RTFSetClassCallback (info
, rtfText
, TextClass
);
2327 RTFSetClassCallback (info
, rtfControl
, ControlClass
);
2333 * Write out a character.
2337 TextClass (RTF_Info
*info
)
2339 RTFPutCodePageChar(info
, info
->rtfMajor
);
2344 ControlClass (RTF_Info
*info
)
2346 switch (info
->rtfMajor
)
2350 ME_RTFCharAttrHook(info
);
2353 ME_RTFParAttrHook(info
);
2356 ME_RTFTblAttrHook(info
);
2364 case rtfDestination
:
2370 case rtfSpecialChar
:
2372 ME_RTFSpecialCharHook(info
);
2379 CharAttr(RTF_Info
*info
)
2383 switch (info
->rtfMinor
)
2386 font
= RTFGetFont(info
, info
->rtfParam
);
2389 if (info
->ansiCodePage
!= CP_UTF8
&& info
->codePage
!= font
->rtfFCodePage
)
2391 RTFFlushOutputBuffer(info
);
2392 info
->codePage
= font
->rtfFCodePage
;
2394 TRACE("font %d codepage %d\n", info
->rtfParam
, info
->codePage
);
2397 ERR( "unknown font %d\n", info
->rtfParam
);
2399 case rtfUnicodeLength
:
2400 info
->unicodeLength
= info
->rtfParam
;
2407 CharSet(RTF_Info
*info
)
2409 if (info
->ansiCodePage
== CP_UTF8
)
2412 switch (info
->rtfMinor
)
2414 case rtfAnsiCharSet
:
2415 info
->ansiCodePage
= 1252; /* Latin-1 */
2418 info
->ansiCodePage
= 10000; /* MacRoman */
2421 info
->ansiCodePage
= 437;
2424 info
->ansiCodePage
= 850;
2430 * This function notices destinations that aren't explicitly handled
2431 * and skips to their ends. This keeps, for instance, picture
2432 * data from being considered as plain text.
2436 Destination (RTF_Info
*info
)
2438 if (!RTFGetDestinationCallback(info
, info
->rtfMinor
))
2439 RTFSkipGroup (info
);
2444 DefFont(RTF_Info
*info
)
2446 TRACE("%d\n", info
->rtfParam
);
2447 info
->defFont
= info
->rtfParam
;
2452 DocAttr(RTF_Info
*info
)
2454 TRACE("minor %d, param %d\n", info
->rtfMinor
, info
->rtfParam
);
2456 switch (info
->rtfMinor
)
2458 case rtfAnsiCodePage
:
2459 info
->codePage
= info
->ansiCodePage
= info
->rtfParam
;
2462 info
->codePage
= info
->ansiCodePage
= CP_UTF8
;
2468 static void SpecialChar (RTF_Info
*info
)
2470 switch (info
->rtfMinor
)
2473 /* the next token determines destination, if it's unknown, skip the group */
2474 /* this way we filter out the garbage coming from unknown destinations */
2476 if (info
->rtfClass
!= rtfDestination
)
2479 RTFRouteToken(info
); /* "\*" is ignored with known destinations */
2485 RTFPutUnicodeChar(info
, info
->rtfParam
);
2487 /* After \u we must skip number of character tokens set by \ucN */
2488 for (i
= 0; i
< info
->unicodeLength
; i
++)
2491 if (info
->rtfClass
!= rtfText
)
2493 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2494 info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
2495 RTFUngetToken(info
);
2502 RTFFlushOutputBuffer(info
);
2503 ME_InsertEndRowFromCursor(info
->editor
, 0);
2508 RTFPutUnicodeChar (info
, '\r');
2509 if (info
->editor
->bEmulateVersion10
) RTFPutUnicodeChar (info
, '\n');
2512 RTFPutUnicodeChar (info
, 0x00A0);
2515 RTFPutUnicodeChar (info
, '\t');
2517 case rtfNoBrkHyphen
:
2518 RTFPutUnicodeChar (info
, 0x2011);
2521 RTFPutUnicodeChar (info
, 0x2022);
2524 RTFPutUnicodeChar (info
, 0x2014);
2527 RTFPutUnicodeChar (info
, 0x2013);
2530 RTFPutUnicodeChar (info
, 0x2018);
2533 RTFPutUnicodeChar (info
, 0x2019);
2536 RTFPutUnicodeChar (info
, 0x201C);
2539 RTFPutUnicodeChar (info
, 0x201D);
2546 RTFFlushUnicodeOutputBuffer(RTF_Info
*info
)
2548 if (info
->dwOutputCount
)
2550 ME_InsertTextFromCursor(info
->editor
, 0, info
->OutputBuffer
,
2551 info
->dwOutputCount
, info
->style
);
2552 info
->dwOutputCount
= 0;
2558 RTFPutUnicodeString(RTF_Info
*info
, const WCHAR
*string
, int length
)
2560 if (info
->dwCPOutputCount
)
2561 RTFFlushCPOutputBuffer(info
);
2564 int fit
= min(length
, sizeof(info
->OutputBuffer
) / sizeof(WCHAR
) - info
->dwOutputCount
);
2566 memmove(info
->OutputBuffer
+ info
->dwOutputCount
, string
, fit
* sizeof(WCHAR
));
2567 info
->dwOutputCount
+= fit
;
2570 if (sizeof(info
->OutputBuffer
) / sizeof(WCHAR
) == info
->dwOutputCount
)
2571 RTFFlushUnicodeOutputBuffer(info
);
2576 RTFFlushCPOutputBuffer(RTF_Info
*info
)
2578 int bufferMax
= info
->dwCPOutputCount
* 2 * sizeof(WCHAR
);
2579 WCHAR
*buffer
= heap_alloc(bufferMax
);
2582 length
= MultiByteToWideChar(info
->codePage
, 0, info
->cpOutputBuffer
,
2583 info
->dwCPOutputCount
, buffer
, bufferMax
/sizeof(WCHAR
));
2584 info
->dwCPOutputCount
= 0;
2586 RTFPutUnicodeString(info
, buffer
, length
);
2591 RTFFlushOutputBuffer(RTF_Info
*info
)
2593 if (info
->dwCPOutputCount
)
2594 RTFFlushCPOutputBuffer(info
);
2595 RTFFlushUnicodeOutputBuffer(info
);
2599 RTFPutUnicodeChar(RTF_Info
*info
, int c
)
2601 if (info
->dwCPOutputCount
)
2602 RTFFlushCPOutputBuffer(info
);
2603 if (info
->dwOutputCount
* sizeof(WCHAR
) >= ( sizeof info
->OutputBuffer
- 1 ) )
2604 RTFFlushUnicodeOutputBuffer( info
);
2605 info
->OutputBuffer
[info
->dwOutputCount
++] = c
;
2609 RTFPutCodePageChar(RTF_Info
*info
, int c
)
2611 /* Use dynamic buffer here because it's the best way to handle
2612 * MBCS codepages without having to worry about partial chars */
2613 if (info
->dwCPOutputCount
>= info
->dwMaxCPOutputCount
)
2615 info
->dwMaxCPOutputCount
*= 2;
2616 info
->cpOutputBuffer
= heap_realloc(info
->cpOutputBuffer
, info
->dwMaxCPOutputCount
);
2618 info
->cpOutputBuffer
[info
->dwCPOutputCount
++] = c
;