4 * Portions Copyright 2004 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Derived from RTF Tools by Paul DuBois (dubois@primate.wisc.edu)
23 * Homepage: http://www.snake.net/software/RTF/
24 * Original license follows:
28 * reader.c - RTF file reader. Release 1.10.
32 * Author: Paul DuBois dubois@primate.wisc.edu
34 * This software may be redistributed without restriction and used for
35 * any purpose whatsoever.
47 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
54 extern HANDLE me_heap
;
56 static int _RTFGetChar(RTF_Info
*);
57 static void _RTFGetToken (RTF_Info
*);
58 static void _RTFGetToken2 (RTF_Info
*);
59 static int GetChar (RTF_Info
*);
60 static void ReadFontTbl (RTF_Info
*);
61 static void ReadColorTbl (RTF_Info
*);
62 static void ReadStyleSheet (RTF_Info
*);
63 static void ReadInfoGroup (RTF_Info
*);
64 static void ReadPictGroup (RTF_Info
*);
65 static void ReadObjGroup (RTF_Info
*);
66 static void LookupInit (void);
67 static void Lookup (RTF_Info
*, char *);
68 static int Hash (char*);
70 static void RTFOutputUnicodeString( RTF_Info
*info
, WCHAR
*str
, int len
);
72 static void CharAttr(RTF_Info
*info
);
73 static void CharSet(RTF_Info
*info
);
74 static void DocAttr(RTF_Info
*info
);
77 int _RTFGetChar(RTF_Info
*info
)
83 /* if the last buffer wasn't full, it's EOF */
84 if (info
->dwInputSize
> 0 &&
85 info
->dwInputSize
== info
->dwInputUsed
&& info
->dwInputSize
< sizeof(info
->InputBuffer
))
87 if (info
->dwInputSize
<= info
->dwInputUsed
)
90 info
->editstream
.dwError
= info
->editstream
.pfnCallback(info
->editstream
.dwCookie
,
91 info
->InputBuffer
, sizeof(info
->InputBuffer
), &count
);
92 /* if error, it's EOF */
93 if (info
->editstream
.dwError
)
95 /* if no bytes read, it's EOF */
98 info
->dwInputSize
= count
;
99 info
->dwInputUsed
= 0;
101 ch
= info
->InputBuffer
[info
->dwInputUsed
++];
107 void RTFSetEditStream(RTF_Info
*info
, EDITSTREAM
*es
)
111 info
->editstream
.dwCookie
= es
->dwCookie
;
112 info
->editstream
.dwError
= es
->dwError
;
113 info
->editstream
.pfnCallback
= es
->pfnCallback
;
117 * Initialize the reader. This may be called multiple times,
118 * to read multiple files. The only thing not reset is the input
119 * stream; that must be done with RTFSetStream().
122 void RTFInit(RTF_Info
*info
)
128 RTFStyleElt
*eltList
, *ep
;
132 if (info
->rtfTextBuf
== (char *) NULL
) /* initialize the text buffers */
134 info
->rtfTextBuf
= RTFAlloc (rtfBufSiz
);
135 info
->pushedTextBuf
= RTFAlloc (rtfBufSiz
);
136 if (info
->rtfTextBuf
== (char *) NULL
137 || info
->pushedTextBuf
== (char *) NULL
)
138 RTFPanic (info
,"Cannot allocate text buffers.");
139 info
->rtfTextBuf
[0] = info
->pushedTextBuf
[0] = '\0';
142 RTFFree (info
->inputName
);
143 RTFFree (info
->outputName
);
144 info
->inputName
= info
->outputName
= (char *) NULL
;
146 /* initialize lookup table */
149 for (i
= 0; i
< rtfMaxClass
; i
++)
150 RTFSetClassCallback (info
, i
, (RTFFuncPtr
) NULL
);
151 for (i
= 0; i
< rtfMaxDestination
; i
++)
152 RTFSetDestinationCallback (info
, i
, (RTFFuncPtr
) NULL
);
154 /* install built-in destination readers */
155 RTFSetDestinationCallback (info
, rtfFontTbl
, ReadFontTbl
);
156 RTFSetDestinationCallback (info
, rtfColorTbl
, ReadColorTbl
);
157 RTFSetDestinationCallback (info
, rtfStyleSheet
, ReadStyleSheet
);
158 RTFSetDestinationCallback (info
, rtfInfo
, ReadInfoGroup
);
159 RTFSetDestinationCallback (info
, rtfPict
, ReadPictGroup
);
160 RTFSetDestinationCallback (info
, rtfObject
, ReadObjGroup
);
163 RTFSetReadHook (info
, (RTFFuncPtr
) NULL
);
165 /* dump old lists if necessary */
167 while (info
->fontList
!= (RTFFont
*) NULL
)
169 fp
= info
->fontList
->rtfNextFont
;
170 RTFFree (info
->fontList
->rtfFName
);
171 RTFFree ((char *) info
->fontList
);
174 while (info
->colorList
!= (RTFColor
*) NULL
)
176 cp
= info
->colorList
->rtfNextColor
;
177 RTFFree ((char *) info
->colorList
);
178 info
->colorList
= cp
;
180 while (info
->styleList
!= (RTFStyle
*) NULL
)
182 sp
= info
->styleList
->rtfNextStyle
;
183 eltList
= info
->styleList
->rtfSSEList
;
184 while (eltList
!= (RTFStyleElt
*) NULL
)
186 ep
= eltList
->rtfNextSE
;
187 RTFFree (eltList
->rtfSEText
);
188 RTFFree ((char *) eltList
);
191 RTFFree (info
->styleList
->rtfSName
);
192 RTFFree ((char *) info
->styleList
);
193 info
->styleList
= sp
;
196 info
->ansiCodePage
= 1252; /* Latin-1 */
197 info
->unicodeLength
= 1; /* \uc1 is the default */
198 info
->codePage
= info
->ansiCodePage
;
201 info
->pushedClass
= -1;
202 info
->pushedChar
= EOF
;
204 info
->rtfLineNum
= 0;
205 info
->rtfLinePos
= 0;
206 info
->prevChar
= EOF
;
211 * Set or get the input or output file name. These are never guaranteed
212 * to be accurate, only insofar as the calling program makes them so.
215 void RTFSetInputName(RTF_Info
*info
, char *name
)
219 if ((info
->inputName
= RTFStrSave (name
)) == (char *) NULL
)
220 RTFPanic (info
,"RTFSetInputName: out of memory");
224 char *RTFGetInputName(RTF_Info
*info
)
226 return (info
->inputName
);
230 void RTFSetOutputName(RTF_Info
*info
, char *name
)
234 if ((info
->outputName
= RTFStrSave (name
)) == (char *) NULL
)
235 RTFPanic (info
, "RTFSetOutputName: out of memory");
239 char *RTFGetOutputName(RTF_Info
*info
)
241 return (info
->outputName
);
246 /* ---------------------------------------------------------------------- */
249 * Callback table manipulation routines
254 * Install or return a writer callback for a token class
257 void RTFSetClassCallback(RTF_Info
*info
, int class, RTFFuncPtr callback
)
259 if (class >= 0 && class < rtfMaxClass
)
260 info
->ccb
[class] = callback
;
264 RTFFuncPtr
RTFGetClassCallback(RTF_Info
*info
, int class)
266 if (class >= 0 && class < rtfMaxClass
)
267 return (info
->ccb
[class]);
268 return ((RTFFuncPtr
) NULL
);
273 * Install or return a writer callback for a destination type
276 void RTFSetDestinationCallback(RTF_Info
*info
, int dest
, RTFFuncPtr callback
)
278 if (dest
>= 0 && dest
< rtfMaxDestination
)
279 info
->dcb
[dest
] = callback
;
283 RTFFuncPtr
RTFGetDestinationCallback(RTF_Info
*info
, int dest
)
285 if (dest
>= 0 && dest
< rtfMaxDestination
)
286 return (info
->dcb
[dest
]);
287 return ((RTFFuncPtr
) NULL
);
291 /* ---------------------------------------------------------------------- */
294 * Token reading routines
299 * Read the input stream, invoking the writer's callbacks
303 void RTFRead(RTF_Info
*info
)
305 while (RTFGetToken (info
) != rtfEOF
)
306 RTFRouteToken (info
);
311 * Route a token. If it's a destination for which a reader is
312 * installed, process the destination internally, otherwise
313 * pass the token to the writer's class callback.
316 void RTFRouteToken(RTF_Info
*info
)
322 if (info
->rtfClass
< 0 || info
->rtfClass
>= rtfMaxClass
) /* watchdog */
324 RTFPanic (info
,"Unknown class %d: %s (reader malfunction)",
325 info
->rtfClass
, info
->rtfTextBuf
);
327 if (RTFCheckCM (info
, rtfControl
, rtfDestination
))
329 /* invoke destination-specific callback if there is one */
330 if ((p
= RTFGetDestinationCallback (info
, info
->rtfMinor
))
331 != (RTFFuncPtr
) NULL
)
337 /* invoke class callback if there is one */
338 if ((p
= RTFGetClassCallback (info
, info
->rtfClass
)) != (RTFFuncPtr
) NULL
)
344 * Skip to the end of the current group. When this returns,
345 * writers that maintain a state stack may want to call their
346 * state unstacker; global vars will still be set to the group's
350 void RTFSkipGroup(RTF_Info
*info
)
356 while (RTFGetToken (info
) != rtfEOF
)
358 if (info
->rtfClass
== rtfGroup
)
360 if (info
->rtfMajor
== rtfBeginGroup
)
362 else if (info
->rtfMajor
== rtfEndGroup
)
365 break; /* end of initial group */
373 * Read one token. Call the read hook if there is one. The
374 * token class is the return value. Returns rtfEOF when there
375 * are no more tokens.
378 int RTFGetToken(RTF_Info
*info
)
387 if ((p
= RTFGetReadHook (info
)) != (RTFFuncPtr
) NULL
)
388 (*p
) (info
); /* give read hook a look at token */
390 /* Silently discard newlines, carriage returns, nulls. */
391 if (!(info
->rtfClass
== rtfText
&& info
->rtfFormat
!= SF_TEXT
392 && (info
->rtfMajor
== '\r' || info
->rtfMajor
== '\n' || info
->rtfMajor
== '\0')))
395 return (info
->rtfClass
);
400 * Install or return a token reader hook.
403 void RTFSetReadHook(RTF_Info
*info
, RTFFuncPtr f
)
409 RTFFuncPtr
RTFGetReadHook(RTF_Info
*info
)
411 return (info
->readHook
);
415 void RTFUngetToken(RTF_Info
*info
)
419 if (info
->pushedClass
>= 0) /* there's already an ungotten token */
420 RTFPanic (info
,"cannot unget two tokens");
421 if (info
->rtfClass
< 0)
422 RTFPanic (info
,"no token to unget");
423 info
->pushedClass
= info
->rtfClass
;
424 info
->pushedMajor
= info
->rtfMajor
;
425 info
->pushedMinor
= info
->rtfMinor
;
426 info
->pushedParam
= info
->rtfParam
;
427 (void) strcpy (info
->pushedTextBuf
, info
->rtfTextBuf
);
431 int RTFPeekToken(RTF_Info
*info
)
434 RTFUngetToken (info
);
435 return (info
->rtfClass
);
439 static void _RTFGetToken(RTF_Info
*info
)
443 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 (void) strcpy (info
->rtfTextBuf
, info
->pushedTextBuf
);
464 info
->rtfTextLen
= strlen (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 RTFANSIToUnicode(RTF_Info
*info
, char c
)
481 WCHAR buffer
[2] = { 0, 0 };
483 /* TODO: Probably caching codepage conversion tables would be faster... */
484 MultiByteToWideChar(info
->codePage
, 0, &c
, 1, buffer
, 2);
490 RTFCharSetToCodePage(RTF_Info
*info
, int charset
)
495 case DEFAULT_CHARSET
:
501 case SHIFTJIS_CHARSET
:
503 case HANGEUL_CHARSET
:
509 case CHINESEBIG5_CHARSET
:
513 case TURKISH_CHARSET
:
515 case VIETNAMESE_CHARSET
:
523 case RUSSIAN_CHARSET
:
527 case EASTEUROPE_CHARSET
:
534 DWORD n
= (DWORD
)charset
;
536 /* FIXME: TranslateCharsetInfo does not work as good as it
537 * should, so let's use it only when all else fails */
538 if (!TranslateCharsetInfo(&n
, &csi
, TCI_SRCCHARSET
))
539 RTFMsg(info
,"%s: unknown charset %u\n", __FUNCTION__
, charset
);
548 /* this shouldn't be called anywhere but from _RTFGetToken() */
550 static void _RTFGetToken2(RTF_Info
*info
)
557 /* initialize token vars */
559 info
->rtfClass
= rtfUnknown
;
560 info
->rtfParam
= rtfNoParam
;
561 info
->rtfTextBuf
[info
->rtfTextLen
= 0] = '\0';
563 /* get first character, which may be a pushback from previous token */
565 if (info
->pushedChar
!= EOF
)
567 c
= info
->pushedChar
;
568 info
->rtfTextBuf
[info
->rtfTextLen
++] = c
;
569 info
->rtfTextBuf
[info
->rtfTextLen
] = '\0';
570 info
->pushedChar
= EOF
;
572 else if ((c
= GetChar (info
)) == EOF
)
574 info
->rtfClass
= rtfEOF
;
580 info
->rtfClass
= rtfGroup
;
581 info
->rtfMajor
= rtfBeginGroup
;
586 info
->rtfClass
= rtfGroup
;
587 info
->rtfMajor
= rtfEndGroup
;
593 * Two possibilities here:
594 * 1) ASCII 9, effectively like \tab control symbol
595 * 2) literal text char
597 if (c
== '\t') /* ASCII 9 */
599 info
->rtfClass
= rtfControl
;
600 info
->rtfMajor
= rtfSpecialChar
;
601 info
->rtfMinor
= rtfTab
;
605 info
->rtfClass
= rtfText
;
608 info
->rtfMajor
= RTFANSIToUnicode(info
, c
);
614 if ((c
= GetChar (info
)) == EOF
)
616 /* early eof, whoops (class is rtfUnknown) */
622 * Three possibilities here:
623 * 1) hex encoded text char, e.g., \'d5, \'d3
624 * 2) special escaped text char, e.g., \{, \}
625 * 3) control symbol, e.g., \_, \-, \|, \<10>
627 if (c
== '\'') /* hex char */
631 if ((c
= GetChar (info
)) != EOF
&& (c2
= GetChar (info
)) != EOF
)
633 /* should do isxdigit check! */
634 info
->rtfClass
= rtfText
;
635 info
->rtfMajor
= RTFANSIToUnicode(info
, RTFCharToHex (c
) * 16 + RTFCharToHex (c2
));
638 /* early eof, whoops (class is rtfUnknown) */
643 /*if (index (":{}\\", c) != (char *) NULL)*/ /* escaped char */
644 if (c
== ':' || c
== '{' || c
== '}' || c
== '\\')
646 info
->rtfClass
= rtfText
;
652 Lookup (info
, info
->rtfTextBuf
); /* sets class, major, minor */
658 if ((c
= GetChar (info
)) == EOF
)
663 * At this point, the control word is all collected, so the
664 * major/minor numbers are determined before the parameter
665 * (if any) is scanned. There will be one too many characters
666 * in the buffer, though, so fix up before and restore after
671 info
->rtfTextBuf
[info
->rtfTextLen
-1] = '\0';
672 Lookup (info
, info
->rtfTextBuf
); /* sets class, major, minor */
674 info
->rtfTextBuf
[info
->rtfTextLen
-1] = c
;
677 * Should be looking at first digit of parameter if there
678 * is one, unless it's negative. In that case, next char
679 * is '-', so need to gobble next char, and remember sign.
688 if (c
!= EOF
&& isdigit (c
))
691 while (isdigit (c
)) /* gobble parameter */
693 info
->rtfParam
= info
->rtfParam
* 10 + c
- '0';
694 if ((c
= GetChar (info
)) == EOF
)
697 info
->rtfParam
*= sign
;
700 * If control symbol delimiter was a blank, gobble it.
701 * Otherwise the character is first char of next token, so
702 * push it back for next call. In either case, delete the
703 * delimiter from the token buffer.
708 info
->pushedChar
= c
;
709 info
->rtfTextBuf
[--info
->rtfTextLen
] = '\0';
715 * Read the next character from the input. This handles setting the
716 * current line and position-within-line variables. Those variable are
717 * set correctly whether lines end with CR, LF, or CRLF (the last being
720 * bumpLine indicates whether the line number should be incremented on
721 * the *next* input character.
725 static int GetChar(RTF_Info
*info
)
732 if ((c
= _RTFGetChar(info
)) != EOF
)
734 info
->rtfTextBuf
[info
->rtfTextLen
++] = c
;
735 info
->rtfTextBuf
[info
->rtfTextLen
] = '\0';
737 if (info
->prevChar
== EOF
)
739 oldBumpLine
= info
->bumpLine
; /* non-zero if prev char was line ending */
746 if (info
->prevChar
== '\r') /* oops, previous \r wasn't */
747 oldBumpLine
= 0; /* really a line ending */
750 if (oldBumpLine
) /* were we supposed to increment the */
751 { /* line count on this char? */
753 info
->rtfLinePos
= 1;
761 * Synthesize a token by setting the global variables to the
762 * values supplied. Typically this is followed with a call
763 * to RTFRouteToken().
765 * If a param value other than rtfNoParam is passed, it becomes
766 * part of the token text.
769 void RTFSetToken(RTF_Info
*info
, int class, int major
, int minor
, int param
, const char *text
)
773 info
->rtfClass
= class;
774 info
->rtfMajor
= major
;
775 info
->rtfMinor
= minor
;
776 info
->rtfParam
= param
;
777 if (param
== rtfNoParam
)
778 (void) strcpy (info
->rtfTextBuf
, text
);
780 sprintf (info
->rtfTextBuf
, "%s%d", text
, param
);
781 info
->rtfTextLen
= strlen (info
->rtfTextBuf
);
785 /* ---------------------------------------------------------------------- */
788 * Special destination readers. They gobble the destination so the
789 * writer doesn't have to deal with them. That's wrong for any
790 * translator that wants to process any of these itself. In that
791 * case, these readers should be overridden by installing a different
792 * destination callback.
794 * NOTE: The last token read by each of these reader will be the
795 * destination's terminating '}', which will then be the current token.
796 * That '}' token is passed to RTFRouteToken() - the writer has already
797 * seen the '{' that began the destination group, and may have pushed a
798 * state; it also needs to know at the end of the group that a state
801 * It's important that rtf.h and the control token lookup table list
802 * as many symbols as possible, because these destination readers
803 * unfortunately make strict assumptions about the input they expect,
804 * and a token of class rtfUnknown will throw them off easily.
809 * Read { \fonttbl ... } destination. Old font tables don't have
810 * braces around each table entry; try to adjust for that.
813 static void ReadFontTbl(RTF_Info
*info
)
816 char buf
[rtfBufSiz
], *bp
;
818 const char *fn
= "ReadFontTbl";
824 (void) RTFGetToken (info
);
825 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
827 if (old
< 0) /* first entry - determine tbl type */
829 if (RTFCheckCMM (info
, rtfControl
, rtfCharAttr
, rtfFontNum
))
830 old
= 1; /* no brace */
831 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
833 else /* can't tell! */
834 RTFPanic (info
, "%s: Cannot determine format", fn
);
836 if (old
== 0) /* need to find "{" here */
838 if (!RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
839 RTFPanic (info
, "%s: missing \"{\"", fn
);
840 (void) RTFGetToken (info
); /* yes, skip to next token */
842 if ((fp
= New (RTFFont
)) == (RTFFont
*) NULL
)
843 RTFPanic (info
, "%s: cannot allocate font entry", fn
);
845 fp
->rtfNextFont
= info
->fontList
;
848 fp
->rtfFName
= (char *) NULL
;
849 fp
->rtfFAltName
= (char *) NULL
;
855 fp
->rtfFCodePage
= 0;
857 while (info
->rtfClass
!= rtfEOF
858 && !RTFCheckCM (info
, rtfText
, ';')
859 && !RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
861 if (info
->rtfClass
== rtfControl
)
863 switch (info
->rtfMajor
)
866 /* ignore token but announce it */
867 RTFMsg (info
,"%s: unknown token \"%s\"\n",
868 fn
, info
->rtfTextBuf
);
871 fp
->rtfFFamily
= info
->rtfMinor
;
874 switch (info
->rtfMinor
)
877 break; /* ignore unknown? */
879 fp
->rtfFNum
= info
->rtfParam
;
884 switch (info
->rtfMinor
)
887 break; /* ignore unknown? */
889 fp
->rtfFCharSet
= info
->rtfParam
;
890 if (!fp
->rtfFCodePage
)
891 fp
->rtfFCodePage
= RTFCharSetToCodePage(info
, info
->rtfParam
);
894 fp
->rtfFPitch
= info
->rtfParam
;
896 case rtfFontCodePage
:
897 fp
->rtfFCodePage
= info
->rtfParam
;
900 case rtfFTypeTrueType
:
901 fp
->rtfFType
= info
->rtfParam
;
907 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
)) /* dest */
909 RTFSkipGroup (info
); /* ignore for now */
911 else if (info
->rtfClass
== rtfText
) /* font name */
914 while (info
->rtfClass
== rtfText
915 && !RTFCheckCM (info
, rtfText
, ';'))
917 *bp
++ = info
->rtfMajor
;
918 (void) RTFGetToken (info
);
921 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
922 if(RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
924 RTFUngetToken (info
);
927 fp
->rtfFName
= RTFStrSave (buf
);
928 if (fp
->rtfFName
== (char *) NULL
)
929 RTFPanic (info
, "%s: cannot allocate font name", fn
);
930 /* already have next token; don't read one */
931 /* at bottom of loop */
936 /* ignore token but announce it */
937 RTFMsg (info
, "%s: unknown token \"%s\"\n",
938 fn
,info
->rtfTextBuf
);
940 (void) RTFGetToken (info
);
942 if (old
== 0) /* need to see "}" here */
944 (void) RTFGetToken (info
);
945 if (!RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
946 RTFPanic (info
, "%s: missing \"}\"", fn
);
949 if (fp
->rtfFNum
== -1)
950 RTFPanic (info
,"%s: missing font number", fn
);
952 * Could check other pieces of structure here, too, I suppose.
954 RTFRouteToken (info
); /* feed "}" back to router */
959 * The color table entries have color values of -1 if
960 * the default color should be used for the entry (only
961 * a semi-colon is given in the definition, no color values).
962 * There will be a problem if a partial entry (1 or 2 but
963 * not 3 color values) is given. The possibility is ignored
967 static void ReadColorTbl(RTF_Info
*info
)
971 const char *fn
= "ReadColorTbl";
977 (void) RTFGetToken (info
);
978 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
980 if ((cp
= New (RTFColor
)) == (RTFColor
*) NULL
)
981 RTFPanic (info
,"%s: cannot allocate color entry", fn
);
982 cp
->rtfCNum
= cnum
++;
983 cp
->rtfCRed
= cp
->rtfCGreen
= cp
->rtfCBlue
= -1;
984 cp
->rtfNextColor
= info
->colorList
;
985 info
->colorList
= cp
;
986 while (RTFCheckCM (info
, rtfControl
, rtfColorName
))
988 switch (info
->rtfMinor
)
990 case rtfRed
: cp
->rtfCRed
= info
->rtfParam
; break;
991 case rtfGreen
: cp
->rtfCGreen
= info
->rtfParam
; break;
992 case rtfBlue
: cp
->rtfCBlue
= info
->rtfParam
; break;
996 if (!RTFCheckCM (info
, rtfText
, (int) ';'))
997 RTFPanic (info
,"%s: malformed entry", fn
);
999 RTFRouteToken (info
); /* feed "}" back to router */
1004 * The "Normal" style definition doesn't contain any style number,
1005 * all others do. Normal style is given style rtfNormalStyleNum.
1008 static void ReadStyleSheet(RTF_Info
*info
)
1011 RTFStyleElt
*sep
, *sepLast
;
1012 char buf
[rtfBufSiz
], *bp
;
1013 const char *fn
= "ReadStyleSheet";
1019 (void) RTFGetToken (info
);
1020 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
1022 if ((sp
= New (RTFStyle
)) == (RTFStyle
*) NULL
)
1023 RTFPanic (info
,"%s: cannot allocate stylesheet entry", fn
);
1024 sp
->rtfSName
= (char *) NULL
;
1026 sp
->rtfSType
= rtfParStyle
;
1027 sp
->rtfSAdditive
= 0;
1028 sp
->rtfSBasedOn
= rtfNoStyleNum
;
1029 sp
->rtfSNextPar
= -1;
1030 sp
->rtfSSEList
= sepLast
= (RTFStyleElt
*) NULL
;
1031 sp
->rtfNextStyle
= info
->styleList
;
1032 sp
->rtfExpanding
= 0;
1033 info
->styleList
= sp
;
1034 if (!RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
1035 RTFPanic (info
,"%s: missing \"{\"", fn
);
1038 (void) RTFGetToken (info
);
1039 if (info
->rtfClass
== rtfEOF
1040 || RTFCheckCM (info
, rtfText
, ';'))
1042 if (info
->rtfClass
== rtfControl
)
1044 if (RTFCheckMM (info
, rtfSpecialChar
, rtfOptDest
))
1045 continue; /* ignore "\*" */
1046 if (RTFCheckMM (info
, rtfParAttr
, rtfStyleNum
))
1048 sp
->rtfSNum
= info
->rtfParam
;
1049 sp
->rtfSType
= rtfParStyle
;
1052 if (RTFCheckMM (info
, rtfCharAttr
, rtfCharStyleNum
))
1054 sp
->rtfSNum
= info
->rtfParam
;
1055 sp
->rtfSType
= rtfCharStyle
;
1058 if (RTFCheckMM (info
, rtfSectAttr
, rtfSectStyleNum
))
1060 sp
->rtfSNum
= info
->rtfParam
;
1061 sp
->rtfSType
= rtfSectStyle
;
1064 if (RTFCheckMM (info
, rtfStyleAttr
, rtfBasedOn
))
1066 sp
->rtfSBasedOn
= info
->rtfParam
;
1069 if (RTFCheckMM (info
, rtfStyleAttr
, rtfAdditive
))
1071 sp
->rtfSAdditive
= 1;
1074 if (RTFCheckMM (info
, rtfStyleAttr
, rtfNext
))
1076 sp
->rtfSNextPar
= info
->rtfParam
;
1079 if ((sep
= New (RTFStyleElt
)) == (RTFStyleElt
*) NULL
)
1080 RTFPanic (info
,"%s: cannot allocate style element", fn
);
1081 sep
->rtfSEClass
= info
->rtfClass
;
1082 sep
->rtfSEMajor
= info
->rtfMajor
;
1083 sep
->rtfSEMinor
= info
->rtfMinor
;
1084 sep
->rtfSEParam
= info
->rtfParam
;
1085 if ((sep
->rtfSEText
= RTFStrSave (info
->rtfTextBuf
))
1087 RTFPanic (info
,"%s: cannot allocate style element text", fn
);
1088 if (sepLast
== (RTFStyleElt
*) NULL
)
1089 sp
->rtfSSEList
= sep
; /* first element */
1090 else /* add to end */
1091 sepLast
->rtfNextSE
= sep
;
1092 sep
->rtfNextSE
= (RTFStyleElt
*) NULL
;
1095 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
1098 * This passes over "{\*\keycode ... }, among
1099 * other things. A temporary (perhaps) hack.
1101 RTFSkipGroup (info
);
1104 else if (info
->rtfClass
== rtfText
) /* style name */
1107 while (info
->rtfClass
== rtfText
)
1109 if (info
->rtfMajor
== ';')
1111 /* put back for "for" loop */
1112 (void) RTFUngetToken (info
);
1115 *bp
++ = info
->rtfMajor
;
1116 (void) RTFGetToken (info
);
1119 if ((sp
->rtfSName
= RTFStrSave (buf
)) == (char *) NULL
)
1120 RTFPanic (info
, "%s: cannot allocate style name", fn
);
1122 else /* unrecognized */
1124 /* ignore token but announce it */
1125 RTFMsg (info
, "%s: unknown token \"%s\"\n",
1126 fn
, info
->rtfTextBuf
);
1129 (void) RTFGetToken (info
);
1130 if (!RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
1131 RTFPanic (info
, "%s: missing \"}\"", fn
);
1134 * Check over the style structure. A name is a must.
1135 * If no style number was specified, check whether it's the
1136 * Normal style (in which case it's given style number
1137 * rtfNormalStyleNum). Note that some "normal" style names
1138 * just begin with "Normal" and can have other stuff following,
1139 * e.g., "Normal,Times 10 point". Ugh.
1141 * Some German RTF writers use "Standard" instead of "Normal".
1143 if (sp
->rtfSName
== (char *) NULL
)
1144 RTFPanic (info
,"%s: missing style name", fn
);
1145 if (sp
->rtfSNum
< 0)
1147 if (strncmp (buf
, "Normal", 6) != 0
1148 && strncmp (buf
, "Standard", 8) != 0)
1149 RTFPanic (info
,"%s: missing style number", fn
);
1150 sp
->rtfSNum
= rtfNormalStyleNum
;
1152 if (sp
->rtfSNextPar
== -1) /* if \snext not given, */
1153 sp
->rtfSNextPar
= sp
->rtfSNum
; /* next is itself */
1155 RTFRouteToken (info
); /* feed "}" back to router */
1159 static void ReadInfoGroup(RTF_Info
*info
)
1161 RTFSkipGroup (info
);
1162 RTFRouteToken (info
); /* feed "}" back to router */
1166 static void ReadPictGroup(RTF_Info
*info
)
1168 RTFSkipGroup (info
);
1169 RTFRouteToken (info
); /* feed "}" back to router */
1173 static void ReadObjGroup(RTF_Info
*info
)
1175 RTFSkipGroup (info
);
1176 RTFRouteToken (info
); /* feed "}" back to router */
1180 /* ---------------------------------------------------------------------- */
1183 * Routines to return pieces of stylesheet, or font or color tables.
1184 * References to style 0 are mapped onto the Normal style.
1188 RTFStyle
*RTFGetStyle(RTF_Info
*info
, int num
)
1193 return (info
->styleList
);
1194 for (s
= info
->styleList
; s
!= (RTFStyle
*) NULL
; s
= s
->rtfNextStyle
)
1196 if (s
->rtfSNum
== num
)
1199 return (s
); /* NULL if not found */
1203 RTFFont
*RTFGetFont(RTF_Info
*info
, int num
)
1208 return (info
->fontList
);
1209 for (f
= info
->fontList
; f
!= (RTFFont
*) NULL
; f
= f
->rtfNextFont
)
1211 if (f
->rtfFNum
== num
)
1214 return (f
); /* NULL if not found */
1218 RTFColor
*RTFGetColor(RTF_Info
*info
, int num
)
1223 return (info
->colorList
);
1224 for (c
= info
->colorList
; c
!= (RTFColor
*) NULL
; c
= c
->rtfNextColor
)
1226 if (c
->rtfCNum
== num
)
1229 return (c
); /* NULL if not found */
1233 /* ---------------------------------------------------------------------- */
1237 * Expand style n, if there is such a style.
1240 void RTFExpandStyle(RTF_Info
*info
, int n
)
1247 if (n
== -1 || (s
= RTFGetStyle (info
, n
)) == (RTFStyle
*) NULL
)
1249 if (s
->rtfExpanding
!= 0)
1250 RTFPanic (info
,"Style expansion loop, style %d", n
);
1251 s
->rtfExpanding
= 1; /* set expansion flag for loop detection */
1253 * Expand "based-on" style (unless it's the same as the current
1254 * style -- Normal style usually gives itself as its own based-on
1255 * style). Based-on style expansion is done by synthesizing
1256 * the token that the writer needs to see in order to trigger
1257 * another style expansion, and feeding to token back through
1258 * the router so the writer sees it.
1260 if (n
!= s
->rtfSBasedOn
)
1262 RTFSetToken (info
, rtfControl
, rtfParAttr
, rtfStyleNum
,
1263 s
->rtfSBasedOn
, "\\s");
1264 RTFRouteToken (info
);
1267 * Now route the tokens unique to this style. RTFSetToken()
1268 * isn't used because it would add the param value to the end
1269 * of the token text, which already has it in.
1271 for (se
= s
->rtfSSEList
; se
!= (RTFStyleElt
*) NULL
; se
= se
->rtfNextSE
)
1273 info
->rtfClass
= se
->rtfSEClass
;
1274 info
->rtfMajor
= se
->rtfSEMajor
;
1275 info
->rtfMinor
= se
->rtfSEMinor
;
1276 info
->rtfParam
= se
->rtfSEParam
;
1277 (void) strcpy (info
->rtfTextBuf
, se
->rtfSEText
);
1278 info
->rtfTextLen
= strlen (info
->rtfTextBuf
);
1279 RTFRouteToken (info
);
1281 s
->rtfExpanding
= 0; /* done - clear expansion flag */
1285 /* ---------------------------------------------------------------------- */
1288 * Control symbol lookup routines
1292 typedef struct RTFKey RTFKey
;
1296 int rtfKMajor
; /* major number */
1297 int rtfKMinor
; /* minor number */
1298 const char *rtfKStr
; /* symbol name */
1299 int rtfKHash
; /* symbol name hash value */
1303 * A minor number of -1 means the token has no minor number
1304 * (all valid minor numbers are >= 0).
1307 static RTFKey rtfKey
[] =
1310 * Special characters
1313 { rtfSpecialChar
, rtfIIntVersion
, "vern", 0 },
1314 { rtfSpecialChar
, rtfICreateTime
, "creatim", 0 },
1315 { rtfSpecialChar
, rtfIRevisionTime
, "revtim", 0 },
1316 { rtfSpecialChar
, rtfIPrintTime
, "printim", 0 },
1317 { rtfSpecialChar
, rtfIBackupTime
, "buptim", 0 },
1318 { rtfSpecialChar
, rtfIEditTime
, "edmins", 0 },
1319 { rtfSpecialChar
, rtfIYear
, "yr", 0 },
1320 { rtfSpecialChar
, rtfIMonth
, "mo", 0 },
1321 { rtfSpecialChar
, rtfIDay
, "dy", 0 },
1322 { rtfSpecialChar
, rtfIHour
, "hr", 0 },
1323 { rtfSpecialChar
, rtfIMinute
, "min", 0 },
1324 { rtfSpecialChar
, rtfISecond
, "sec", 0 },
1325 { rtfSpecialChar
, rtfINPages
, "nofpages", 0 },
1326 { rtfSpecialChar
, rtfINWords
, "nofwords", 0 },
1327 { rtfSpecialChar
, rtfINChars
, "nofchars", 0 },
1328 { rtfSpecialChar
, rtfIIntID
, "id", 0 },
1330 { rtfSpecialChar
, rtfCurHeadDate
, "chdate", 0 },
1331 { rtfSpecialChar
, rtfCurHeadDateLong
, "chdpl", 0 },
1332 { rtfSpecialChar
, rtfCurHeadDateAbbrev
, "chdpa", 0 },
1333 { rtfSpecialChar
, rtfCurHeadTime
, "chtime", 0 },
1334 { rtfSpecialChar
, rtfCurHeadPage
, "chpgn", 0 },
1335 { rtfSpecialChar
, rtfSectNum
, "sectnum", 0 },
1336 { rtfSpecialChar
, rtfCurFNote
, "chftn", 0 },
1337 { rtfSpecialChar
, rtfCurAnnotRef
, "chatn", 0 },
1338 { rtfSpecialChar
, rtfFNoteSep
, "chftnsep", 0 },
1339 { rtfSpecialChar
, rtfFNoteCont
, "chftnsepc", 0 },
1340 { rtfSpecialChar
, rtfCell
, "cell", 0 },
1341 { rtfSpecialChar
, rtfRow
, "row", 0 },
1342 { rtfSpecialChar
, rtfPar
, "par", 0 },
1343 /* newline and carriage return are synonyms for */
1344 /* \par when they are preceded by a \ character */
1345 { rtfSpecialChar
, rtfPar
, "\n", 0 },
1346 { rtfSpecialChar
, rtfPar
, "\r", 0 },
1347 { rtfSpecialChar
, rtfSect
, "sect", 0 },
1348 { rtfSpecialChar
, rtfPage
, "page", 0 },
1349 { rtfSpecialChar
, rtfColumn
, "column", 0 },
1350 { rtfSpecialChar
, rtfLine
, "line", 0 },
1351 { rtfSpecialChar
, rtfSoftPage
, "softpage", 0 },
1352 { rtfSpecialChar
, rtfSoftColumn
, "softcol", 0 },
1353 { rtfSpecialChar
, rtfSoftLine
, "softline", 0 },
1354 { rtfSpecialChar
, rtfSoftLineHt
, "softlheight", 0 },
1355 { rtfSpecialChar
, rtfTab
, "tab", 0 },
1356 { rtfSpecialChar
, rtfEmDash
, "emdash", 0 },
1357 { rtfSpecialChar
, rtfEnDash
, "endash", 0 },
1358 { rtfSpecialChar
, rtfEmSpace
, "emspace", 0 },
1359 { rtfSpecialChar
, rtfEnSpace
, "enspace", 0 },
1360 { rtfSpecialChar
, rtfBullet
, "bullet", 0 },
1361 { rtfSpecialChar
, rtfLQuote
, "lquote", 0 },
1362 { rtfSpecialChar
, rtfRQuote
, "rquote", 0 },
1363 { rtfSpecialChar
, rtfLDblQuote
, "ldblquote", 0 },
1364 { rtfSpecialChar
, rtfRDblQuote
, "rdblquote", 0 },
1365 { rtfSpecialChar
, rtfFormula
, "|", 0 },
1366 { rtfSpecialChar
, rtfNoBrkSpace
, "~", 0 },
1367 { rtfSpecialChar
, rtfNoReqHyphen
, "-", 0 },
1368 { rtfSpecialChar
, rtfNoBrkHyphen
, "_", 0 },
1369 { rtfSpecialChar
, rtfOptDest
, "*", 0 },
1370 { rtfSpecialChar
, rtfLTRMark
, "ltrmark", 0 },
1371 { rtfSpecialChar
, rtfRTLMark
, "rtlmark", 0 },
1372 { rtfSpecialChar
, rtfNoWidthJoiner
, "zwj", 0 },
1373 { rtfSpecialChar
, rtfNoWidthNonJoiner
, "zwnj", 0 },
1374 /* is this valid? */
1375 { rtfSpecialChar
, rtfCurHeadPict
, "chpict", 0 },
1376 { rtfSpecialChar
, rtfUnicode
, "u", 0 },
1379 * Character formatting attributes
1382 { rtfCharAttr
, rtfPlain
, "plain", 0 },
1383 { rtfCharAttr
, rtfBold
, "b", 0 },
1384 { rtfCharAttr
, rtfAllCaps
, "caps", 0 },
1385 { rtfCharAttr
, rtfDeleted
, "deleted", 0 },
1386 { rtfCharAttr
, rtfSubScript
, "dn", 0 },
1387 { rtfCharAttr
, rtfSubScrShrink
, "sub", 0 },
1388 { rtfCharAttr
, rtfNoSuperSub
, "nosupersub", 0 },
1389 { rtfCharAttr
, rtfExpand
, "expnd", 0 },
1390 { rtfCharAttr
, rtfExpandTwips
, "expndtw", 0 },
1391 { rtfCharAttr
, rtfKerning
, "kerning", 0 },
1392 { rtfCharAttr
, rtfFontNum
, "f", 0 },
1393 { rtfCharAttr
, rtfFontSize
, "fs", 0 },
1394 { rtfCharAttr
, rtfItalic
, "i", 0 },
1395 { rtfCharAttr
, rtfOutline
, "outl", 0 },
1396 { rtfCharAttr
, rtfRevised
, "revised", 0 },
1397 { rtfCharAttr
, rtfRevAuthor
, "revauth", 0 },
1398 { rtfCharAttr
, rtfRevDTTM
, "revdttm", 0 },
1399 { rtfCharAttr
, rtfSmallCaps
, "scaps", 0 },
1400 { rtfCharAttr
, rtfShadow
, "shad", 0 },
1401 { rtfCharAttr
, rtfStrikeThru
, "strike", 0 },
1402 { rtfCharAttr
, rtfUnderline
, "ul", 0 },
1403 { rtfCharAttr
, rtfDotUnderline
, "uld", 0 },
1404 { rtfCharAttr
, rtfDbUnderline
, "uldb", 0 },
1405 { rtfCharAttr
, rtfNoUnderline
, "ulnone", 0 },
1406 { rtfCharAttr
, rtfWordUnderline
, "ulw", 0 },
1407 { rtfCharAttr
, rtfSuperScript
, "up", 0 },
1408 { rtfCharAttr
, rtfSuperScrShrink
, "super", 0 },
1409 { rtfCharAttr
, rtfInvisible
, "v", 0 },
1410 { rtfCharAttr
, rtfForeColor
, "cf", 0 },
1411 { rtfCharAttr
, rtfBackColor
, "cb", 0 },
1412 { rtfCharAttr
, rtfRTLChar
, "rtlch", 0 },
1413 { rtfCharAttr
, rtfLTRChar
, "ltrch", 0 },
1414 { rtfCharAttr
, rtfCharStyleNum
, "cs", 0 },
1415 { rtfCharAttr
, rtfCharCharSet
, "cchs", 0 },
1416 { rtfCharAttr
, rtfLanguage
, "lang", 0 },
1417 /* this has disappeared from spec 1.2 */
1418 { rtfCharAttr
, rtfGray
, "gray", 0 },
1421 * Paragraph formatting attributes
1424 { rtfParAttr
, rtfParDef
, "pard", 0 },
1425 { rtfParAttr
, rtfStyleNum
, "s", 0 },
1426 { rtfParAttr
, rtfHyphenate
, "hyphpar", 0 },
1427 { rtfParAttr
, rtfInTable
, "intbl", 0 },
1428 { rtfParAttr
, rtfKeep
, "keep", 0 },
1429 { rtfParAttr
, rtfNoWidowControl
, "nowidctlpar", 0 },
1430 { rtfParAttr
, rtfKeepNext
, "keepn", 0 },
1431 { rtfParAttr
, rtfOutlineLevel
, "level", 0 },
1432 { rtfParAttr
, rtfNoLineNum
, "noline", 0 },
1433 { rtfParAttr
, rtfPBBefore
, "pagebb", 0 },
1434 { rtfParAttr
, rtfSideBySide
, "sbys", 0 },
1435 { rtfParAttr
, rtfQuadLeft
, "ql", 0 },
1436 { rtfParAttr
, rtfQuadRight
, "qr", 0 },
1437 { rtfParAttr
, rtfQuadJust
, "qj", 0 },
1438 { rtfParAttr
, rtfQuadCenter
, "qc", 0 },
1439 { rtfParAttr
, rtfFirstIndent
, "fi", 0 },
1440 { rtfParAttr
, rtfLeftIndent
, "li", 0 },
1441 { rtfParAttr
, rtfRightIndent
, "ri", 0 },
1442 { rtfParAttr
, rtfSpaceBefore
, "sb", 0 },
1443 { rtfParAttr
, rtfSpaceAfter
, "sa", 0 },
1444 { rtfParAttr
, rtfSpaceBetween
, "sl", 0 },
1445 { rtfParAttr
, rtfSpaceMultiply
, "slmult", 0 },
1447 { rtfParAttr
, rtfSubDocument
, "subdocument", 0 },
1449 { rtfParAttr
, rtfRTLPar
, "rtlpar", 0 },
1450 { rtfParAttr
, rtfLTRPar
, "ltrpar", 0 },
1452 { rtfParAttr
, rtfTabPos
, "tx", 0 },
1454 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1455 * although it's not in the spec. It's also redundant, since lj
1456 * tabs are the default.
1458 { rtfParAttr
, rtfTabLeft
, "tql", 0 },
1459 { rtfParAttr
, rtfTabRight
, "tqr", 0 },
1460 { rtfParAttr
, rtfTabCenter
, "tqc", 0 },
1461 { rtfParAttr
, rtfTabDecimal
, "tqdec", 0 },
1462 { rtfParAttr
, rtfTabBar
, "tb", 0 },
1463 { rtfParAttr
, rtfLeaderDot
, "tldot", 0 },
1464 { rtfParAttr
, rtfLeaderHyphen
, "tlhyph", 0 },
1465 { rtfParAttr
, rtfLeaderUnder
, "tlul", 0 },
1466 { rtfParAttr
, rtfLeaderThick
, "tlth", 0 },
1467 { rtfParAttr
, rtfLeaderEqual
, "tleq", 0 },
1469 { rtfParAttr
, rtfParLevel
, "pnlvl", 0 },
1470 { rtfParAttr
, rtfParBullet
, "pnlvlblt", 0 },
1471 { rtfParAttr
, rtfParSimple
, "pnlvlbody", 0 },
1472 { rtfParAttr
, rtfParNumCont
, "pnlvlcont", 0 },
1473 { rtfParAttr
, rtfParNumOnce
, "pnnumonce", 0 },
1474 { rtfParAttr
, rtfParNumAcross
, "pnacross", 0 },
1475 { rtfParAttr
, rtfParHangIndent
, "pnhang", 0 },
1476 { rtfParAttr
, rtfParNumRestart
, "pnrestart", 0 },
1477 { rtfParAttr
, rtfParNumCardinal
, "pncard", 0 },
1478 { rtfParAttr
, rtfParNumDecimal
, "pndec", 0 },
1479 { rtfParAttr
, rtfParNumULetter
, "pnucltr", 0 },
1480 { rtfParAttr
, rtfParNumURoman
, "pnucrm", 0 },
1481 { rtfParAttr
, rtfParNumLLetter
, "pnlcltr", 0 },
1482 { rtfParAttr
, rtfParNumLRoman
, "pnlcrm", 0 },
1483 { rtfParAttr
, rtfParNumOrdinal
, "pnord", 0 },
1484 { rtfParAttr
, rtfParNumOrdinalText
, "pnordt", 0 },
1485 { rtfParAttr
, rtfParNumBold
, "pnb", 0 },
1486 { rtfParAttr
, rtfParNumItalic
, "pni", 0 },
1487 { rtfParAttr
, rtfParNumAllCaps
, "pncaps", 0 },
1488 { rtfParAttr
, rtfParNumSmallCaps
, "pnscaps", 0 },
1489 { rtfParAttr
, rtfParNumUnder
, "pnul", 0 },
1490 { rtfParAttr
, rtfParNumDotUnder
, "pnuld", 0 },
1491 { rtfParAttr
, rtfParNumDbUnder
, "pnuldb", 0 },
1492 { rtfParAttr
, rtfParNumNoUnder
, "pnulnone", 0 },
1493 { rtfParAttr
, rtfParNumWordUnder
, "pnulw", 0 },
1494 { rtfParAttr
, rtfParNumStrikethru
, "pnstrike", 0 },
1495 { rtfParAttr
, rtfParNumForeColor
, "pncf", 0 },
1496 { rtfParAttr
, rtfParNumFont
, "pnf", 0 },
1497 { rtfParAttr
, rtfParNumFontSize
, "pnfs", 0 },
1498 { rtfParAttr
, rtfParNumIndent
, "pnindent", 0 },
1499 { rtfParAttr
, rtfParNumSpacing
, "pnsp", 0 },
1500 { rtfParAttr
, rtfParNumInclPrev
, "pnprev", 0 },
1501 { rtfParAttr
, rtfParNumCenter
, "pnqc", 0 },
1502 { rtfParAttr
, rtfParNumLeft
, "pnql", 0 },
1503 { rtfParAttr
, rtfParNumRight
, "pnqr", 0 },
1504 { rtfParAttr
, rtfParNumStartAt
, "pnstart", 0 },
1506 { rtfParAttr
, rtfBorderTop
, "brdrt", 0 },
1507 { rtfParAttr
, rtfBorderBottom
, "brdrb", 0 },
1508 { rtfParAttr
, rtfBorderLeft
, "brdrl", 0 },
1509 { rtfParAttr
, rtfBorderRight
, "brdrr", 0 },
1510 { rtfParAttr
, rtfBorderBetween
, "brdrbtw", 0 },
1511 { rtfParAttr
, rtfBorderBar
, "brdrbar", 0 },
1512 { rtfParAttr
, rtfBorderBox
, "box", 0 },
1513 { rtfParAttr
, rtfBorderSingle
, "brdrs", 0 },
1514 { rtfParAttr
, rtfBorderThick
, "brdrth", 0 },
1515 { rtfParAttr
, rtfBorderShadow
, "brdrsh", 0 },
1516 { rtfParAttr
, rtfBorderDouble
, "brdrdb", 0 },
1517 { rtfParAttr
, rtfBorderDot
, "brdrdot", 0 },
1518 { rtfParAttr
, rtfBorderDot
, "brdrdash", 0 },
1519 { rtfParAttr
, rtfBorderHair
, "brdrhair", 0 },
1520 { rtfParAttr
, rtfBorderWidth
, "brdrw", 0 },
1521 { rtfParAttr
, rtfBorderColor
, "brdrcf", 0 },
1522 { rtfParAttr
, rtfBorderSpace
, "brsp", 0 },
1524 { rtfParAttr
, rtfShading
, "shading", 0 },
1525 { rtfParAttr
, rtfBgPatH
, "bghoriz", 0 },
1526 { rtfParAttr
, rtfBgPatV
, "bgvert", 0 },
1527 { rtfParAttr
, rtfFwdDiagBgPat
, "bgfdiag", 0 },
1528 { rtfParAttr
, rtfBwdDiagBgPat
, "bgbdiag", 0 },
1529 { rtfParAttr
, rtfHatchBgPat
, "bgcross", 0 },
1530 { rtfParAttr
, rtfDiagHatchBgPat
, "bgdcross", 0 },
1531 { rtfParAttr
, rtfDarkBgPatH
, "bgdkhoriz", 0 },
1532 { rtfParAttr
, rtfDarkBgPatV
, "bgdkvert", 0 },
1533 { rtfParAttr
, rtfFwdDarkBgPat
, "bgdkfdiag", 0 },
1534 { rtfParAttr
, rtfBwdDarkBgPat
, "bgdkbdiag", 0 },
1535 { rtfParAttr
, rtfDarkHatchBgPat
, "bgdkcross", 0 },
1536 { rtfParAttr
, rtfDarkDiagHatchBgPat
, "bgdkdcross", 0 },
1537 { rtfParAttr
, rtfBgPatLineColor
, "cfpat", 0 },
1538 { rtfParAttr
, rtfBgPatColor
, "cbpat", 0 },
1541 * Section formatting attributes
1544 { rtfSectAttr
, rtfSectDef
, "sectd", 0 },
1545 { rtfSectAttr
, rtfENoteHere
, "endnhere", 0 },
1546 { rtfSectAttr
, rtfPrtBinFirst
, "binfsxn", 0 },
1547 { rtfSectAttr
, rtfPrtBin
, "binsxn", 0 },
1548 { rtfSectAttr
, rtfSectStyleNum
, "ds", 0 },
1550 { rtfSectAttr
, rtfNoBreak
, "sbknone", 0 },
1551 { rtfSectAttr
, rtfColBreak
, "sbkcol", 0 },
1552 { rtfSectAttr
, rtfPageBreak
, "sbkpage", 0 },
1553 { rtfSectAttr
, rtfEvenBreak
, "sbkeven", 0 },
1554 { rtfSectAttr
, rtfOddBreak
, "sbkodd", 0 },
1556 { rtfSectAttr
, rtfColumns
, "cols", 0 },
1557 { rtfSectAttr
, rtfColumnSpace
, "colsx", 0 },
1558 { rtfSectAttr
, rtfColumnNumber
, "colno", 0 },
1559 { rtfSectAttr
, rtfColumnSpRight
, "colsr", 0 },
1560 { rtfSectAttr
, rtfColumnWidth
, "colw", 0 },
1561 { rtfSectAttr
, rtfColumnLine
, "linebetcol", 0 },
1563 { rtfSectAttr
, rtfLineModulus
, "linemod", 0 },
1564 { rtfSectAttr
, rtfLineDist
, "linex", 0 },
1565 { rtfSectAttr
, rtfLineStarts
, "linestarts", 0 },
1566 { rtfSectAttr
, rtfLineRestart
, "linerestart", 0 },
1567 { rtfSectAttr
, rtfLineRestartPg
, "lineppage", 0 },
1568 { rtfSectAttr
, rtfLineCont
, "linecont", 0 },
1570 { rtfSectAttr
, rtfSectPageWid
, "pgwsxn", 0 },
1571 { rtfSectAttr
, rtfSectPageHt
, "pghsxn", 0 },
1572 { rtfSectAttr
, rtfSectMarginLeft
, "marglsxn", 0 },
1573 { rtfSectAttr
, rtfSectMarginRight
, "margrsxn", 0 },
1574 { rtfSectAttr
, rtfSectMarginTop
, "margtsxn", 0 },
1575 { rtfSectAttr
, rtfSectMarginBottom
, "margbsxn", 0 },
1576 { rtfSectAttr
, rtfSectMarginGutter
, "guttersxn", 0 },
1577 { rtfSectAttr
, rtfSectLandscape
, "lndscpsxn", 0 },
1578 { rtfSectAttr
, rtfTitleSpecial
, "titlepg", 0 },
1579 { rtfSectAttr
, rtfHeaderY
, "headery", 0 },
1580 { rtfSectAttr
, rtfFooterY
, "footery", 0 },
1582 { rtfSectAttr
, rtfPageStarts
, "pgnstarts", 0 },
1583 { rtfSectAttr
, rtfPageCont
, "pgncont", 0 },
1584 { rtfSectAttr
, rtfPageRestart
, "pgnrestart", 0 },
1585 { rtfSectAttr
, rtfPageNumRight
, "pgnx", 0 },
1586 { rtfSectAttr
, rtfPageNumTop
, "pgny", 0 },
1587 { rtfSectAttr
, rtfPageDecimal
, "pgndec", 0 },
1588 { rtfSectAttr
, rtfPageURoman
, "pgnucrm", 0 },
1589 { rtfSectAttr
, rtfPageLRoman
, "pgnlcrm", 0 },
1590 { rtfSectAttr
, rtfPageULetter
, "pgnucltr", 0 },
1591 { rtfSectAttr
, rtfPageLLetter
, "pgnlcltr", 0 },
1592 { rtfSectAttr
, rtfPageNumHyphSep
, "pgnhnsh", 0 },
1593 { rtfSectAttr
, rtfPageNumSpaceSep
, "pgnhnsp", 0 },
1594 { rtfSectAttr
, rtfPageNumColonSep
, "pgnhnsc", 0 },
1595 { rtfSectAttr
, rtfPageNumEmdashSep
, "pgnhnsm", 0 },
1596 { rtfSectAttr
, rtfPageNumEndashSep
, "pgnhnsn", 0 },
1598 { rtfSectAttr
, rtfTopVAlign
, "vertalt", 0 },
1599 /* misspelled as "vertal" in specification 1.0 */
1600 { rtfSectAttr
, rtfBottomVAlign
, "vertalb", 0 },
1601 { rtfSectAttr
, rtfCenterVAlign
, "vertalc", 0 },
1602 { rtfSectAttr
, rtfJustVAlign
, "vertalj", 0 },
1604 { rtfSectAttr
, rtfRTLSect
, "rtlsect", 0 },
1605 { rtfSectAttr
, rtfLTRSect
, "ltrsect", 0 },
1607 /* I've seen these in an old spec, but not in real files... */
1608 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1609 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1610 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1611 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1612 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1615 * Document formatting attributes
1618 { rtfDocAttr
, rtfDefTab
, "deftab", 0 },
1619 { rtfDocAttr
, rtfHyphHotZone
, "hyphhotz", 0 },
1620 { rtfDocAttr
, rtfHyphConsecLines
, "hyphconsec", 0 },
1621 { rtfDocAttr
, rtfHyphCaps
, "hyphcaps", 0 },
1622 { rtfDocAttr
, rtfHyphAuto
, "hyphauto", 0 },
1623 { rtfDocAttr
, rtfLineStart
, "linestart", 0 },
1624 { rtfDocAttr
, rtfFracWidth
, "fracwidth", 0 },
1625 /* \makeback was given in old version of spec, it's now */
1626 /* listed as \makebackup */
1627 { rtfDocAttr
, rtfMakeBackup
, "makeback", 0 },
1628 { rtfDocAttr
, rtfMakeBackup
, "makebackup", 0 },
1629 { rtfDocAttr
, rtfRTFDefault
, "defformat", 0 },
1630 { rtfDocAttr
, rtfPSOverlay
, "psover", 0 },
1631 { rtfDocAttr
, rtfDocTemplate
, "doctemp", 0 },
1632 { rtfDocAttr
, rtfDefLanguage
, "deflang", 0 },
1634 { rtfDocAttr
, rtfFENoteType
, "fet", 0 },
1635 { rtfDocAttr
, rtfFNoteEndSect
, "endnotes", 0 },
1636 { rtfDocAttr
, rtfFNoteEndDoc
, "enddoc", 0 },
1637 { rtfDocAttr
, rtfFNoteText
, "ftntj", 0 },
1638 { rtfDocAttr
, rtfFNoteBottom
, "ftnbj", 0 },
1639 { rtfDocAttr
, rtfENoteEndSect
, "aendnotes", 0 },
1640 { rtfDocAttr
, rtfENoteEndDoc
, "aenddoc", 0 },
1641 { rtfDocAttr
, rtfENoteText
, "aftntj", 0 },
1642 { rtfDocAttr
, rtfENoteBottom
, "aftnbj", 0 },
1643 { rtfDocAttr
, rtfFNoteStart
, "ftnstart", 0 },
1644 { rtfDocAttr
, rtfENoteStart
, "aftnstart", 0 },
1645 { rtfDocAttr
, rtfFNoteRestartPage
, "ftnrstpg", 0 },
1646 { rtfDocAttr
, rtfFNoteRestart
, "ftnrestart", 0 },
1647 { rtfDocAttr
, rtfFNoteRestartCont
, "ftnrstcont", 0 },
1648 { rtfDocAttr
, rtfENoteRestart
, "aftnrestart", 0 },
1649 { rtfDocAttr
, rtfENoteRestartCont
, "aftnrstcont", 0 },
1650 { rtfDocAttr
, rtfFNoteNumArabic
, "ftnnar", 0 },
1651 { rtfDocAttr
, rtfFNoteNumLLetter
, "ftnnalc", 0 },
1652 { rtfDocAttr
, rtfFNoteNumULetter
, "ftnnauc", 0 },
1653 { rtfDocAttr
, rtfFNoteNumLRoman
, "ftnnrlc", 0 },
1654 { rtfDocAttr
, rtfFNoteNumURoman
, "ftnnruc", 0 },
1655 { rtfDocAttr
, rtfFNoteNumChicago
, "ftnnchi", 0 },
1656 { rtfDocAttr
, rtfENoteNumArabic
, "aftnnar", 0 },
1657 { rtfDocAttr
, rtfENoteNumLLetter
, "aftnnalc", 0 },
1658 { rtfDocAttr
, rtfENoteNumULetter
, "aftnnauc", 0 },
1659 { rtfDocAttr
, rtfENoteNumLRoman
, "aftnnrlc", 0 },
1660 { rtfDocAttr
, rtfENoteNumURoman
, "aftnnruc", 0 },
1661 { rtfDocAttr
, rtfENoteNumChicago
, "aftnnchi", 0 },
1663 { rtfDocAttr
, rtfPaperWidth
, "paperw", 0 },
1664 { rtfDocAttr
, rtfPaperHeight
, "paperh", 0 },
1665 { rtfDocAttr
, rtfPaperSize
, "psz", 0 },
1666 { rtfDocAttr
, rtfLeftMargin
, "margl", 0 },
1667 { rtfDocAttr
, rtfRightMargin
, "margr", 0 },
1668 { rtfDocAttr
, rtfTopMargin
, "margt", 0 },
1669 { rtfDocAttr
, rtfBottomMargin
, "margb", 0 },
1670 { rtfDocAttr
, rtfFacingPage
, "facingp", 0 },
1671 { rtfDocAttr
, rtfGutterWid
, "gutter", 0 },
1672 { rtfDocAttr
, rtfMirrorMargin
, "margmirror", 0 },
1673 { rtfDocAttr
, rtfLandscape
, "landscape", 0 },
1674 { rtfDocAttr
, rtfPageStart
, "pgnstart", 0 },
1675 { rtfDocAttr
, rtfWidowCtrl
, "widowctrl", 0 },
1677 { rtfDocAttr
, rtfLinkStyles
, "linkstyles", 0 },
1679 { rtfDocAttr
, rtfNoAutoTabIndent
, "notabind", 0 },
1680 { rtfDocAttr
, rtfWrapSpaces
, "wraptrsp", 0 },
1681 { rtfDocAttr
, rtfPrintColorsBlack
, "prcolbl", 0 },
1682 { rtfDocAttr
, rtfNoExtraSpaceRL
, "noextrasprl", 0 },
1683 { rtfDocAttr
, rtfNoColumnBalance
, "nocolbal", 0 },
1684 { rtfDocAttr
, rtfCvtMailMergeQuote
, "cvmme", 0 },
1685 { rtfDocAttr
, rtfSuppressTopSpace
, "sprstsp", 0 },
1686 { rtfDocAttr
, rtfSuppressPreParSpace
, "sprsspbf", 0 },
1687 { rtfDocAttr
, rtfCombineTblBorders
, "otblrul", 0 },
1688 { rtfDocAttr
, rtfTranspMetafiles
, "transmf", 0 },
1689 { rtfDocAttr
, rtfSwapBorders
, "swpbdr", 0 },
1690 { rtfDocAttr
, rtfShowHardBreaks
, "brkfrm", 0 },
1692 { rtfDocAttr
, rtfFormProtected
, "formprot", 0 },
1693 { rtfDocAttr
, rtfAllProtected
, "allprot", 0 },
1694 { rtfDocAttr
, rtfFormShading
, "formshade", 0 },
1695 { rtfDocAttr
, rtfFormDisplay
, "formdisp", 0 },
1696 { rtfDocAttr
, rtfPrintData
, "printdata", 0 },
1698 { rtfDocAttr
, rtfRevProtected
, "revprot", 0 },
1699 { rtfDocAttr
, rtfRevisions
, "revisions", 0 },
1700 { rtfDocAttr
, rtfRevDisplay
, "revprop", 0 },
1701 { rtfDocAttr
, rtfRevBar
, "revbar", 0 },
1703 { rtfDocAttr
, rtfAnnotProtected
, "annotprot", 0 },
1705 { rtfDocAttr
, rtfRTLDoc
, "rtldoc", 0 },
1706 { rtfDocAttr
, rtfLTRDoc
, "ltrdoc", 0 },
1708 { rtfDocAttr
, rtfAnsiCodePage
, "ansicpg", 0 },
1709 { rtfDocAttr
, rtfUnicodeLength
, "uc", 0 },
1715 { rtfStyleAttr
, rtfAdditive
, "additive", 0 },
1716 { rtfStyleAttr
, rtfBasedOn
, "sbasedon", 0 },
1717 { rtfStyleAttr
, rtfNext
, "snext", 0 },
1720 * Picture attributes
1723 { rtfPictAttr
, rtfMacQD
, "macpict", 0 },
1724 { rtfPictAttr
, rtfPMMetafile
, "pmmetafile", 0 },
1725 { rtfPictAttr
, rtfWinMetafile
, "wmetafile", 0 },
1726 { rtfPictAttr
, rtfDevIndBitmap
, "dibitmap", 0 },
1727 { rtfPictAttr
, rtfWinBitmap
, "wbitmap", 0 },
1728 { rtfPictAttr
, rtfPixelBits
, "wbmbitspixel", 0 },
1729 { rtfPictAttr
, rtfBitmapPlanes
, "wbmplanes", 0 },
1730 { rtfPictAttr
, rtfBitmapWid
, "wbmwidthbytes", 0 },
1732 { rtfPictAttr
, rtfPicWid
, "picw", 0 },
1733 { rtfPictAttr
, rtfPicHt
, "pich", 0 },
1734 { rtfPictAttr
, rtfPicGoalWid
, "picwgoal", 0 },
1735 { rtfPictAttr
, rtfPicGoalHt
, "pichgoal", 0 },
1736 /* these two aren't in the spec, but some writers emit them */
1737 { rtfPictAttr
, rtfPicGoalWid
, "picwGoal", 0 },
1738 { rtfPictAttr
, rtfPicGoalHt
, "pichGoal", 0 },
1739 { rtfPictAttr
, rtfPicScaleX
, "picscalex", 0 },
1740 { rtfPictAttr
, rtfPicScaleY
, "picscaley", 0 },
1741 { rtfPictAttr
, rtfPicScaled
, "picscaled", 0 },
1742 { rtfPictAttr
, rtfPicCropTop
, "piccropt", 0 },
1743 { rtfPictAttr
, rtfPicCropBottom
, "piccropb", 0 },
1744 { rtfPictAttr
, rtfPicCropLeft
, "piccropl", 0 },
1745 { rtfPictAttr
, rtfPicCropRight
, "piccropr", 0 },
1747 { rtfPictAttr
, rtfPicMFHasBitmap
, "picbmp", 0 },
1748 { rtfPictAttr
, rtfPicMFBitsPerPixel
, "picbpp", 0 },
1750 { rtfPictAttr
, rtfPicBinary
, "bin", 0 },
1753 * NeXT graphic attributes
1756 { rtfNeXTGrAttr
, rtfNeXTGWidth
, "width", 0 },
1757 { rtfNeXTGrAttr
, rtfNeXTGHeight
, "height", 0 },
1763 { rtfDestination
, rtfFontTbl
, "fonttbl", 0 },
1764 { rtfDestination
, rtfFontAltName
, "falt", 0 },
1765 { rtfDestination
, rtfEmbeddedFont
, "fonteb", 0 },
1766 { rtfDestination
, rtfFontFile
, "fontfile", 0 },
1767 { rtfDestination
, rtfFileTbl
, "filetbl", 0 },
1768 { rtfDestination
, rtfFileInfo
, "file", 0 },
1769 { rtfDestination
, rtfColorTbl
, "colortbl", 0 },
1770 { rtfDestination
, rtfStyleSheet
, "stylesheet", 0 },
1771 { rtfDestination
, rtfKeyCode
, "keycode", 0 },
1772 { rtfDestination
, rtfRevisionTbl
, "revtbl", 0 },
1773 { rtfDestination
, rtfGenerator
, "generator", 0 },
1774 { rtfDestination
, rtfInfo
, "info", 0 },
1775 { rtfDestination
, rtfITitle
, "title", 0 },
1776 { rtfDestination
, rtfISubject
, "subject", 0 },
1777 { rtfDestination
, rtfIAuthor
, "author", 0 },
1778 { rtfDestination
, rtfIOperator
, "operator", 0 },
1779 { rtfDestination
, rtfIKeywords
, "keywords", 0 },
1780 { rtfDestination
, rtfIComment
, "comment", 0 },
1781 { rtfDestination
, rtfIVersion
, "version", 0 },
1782 { rtfDestination
, rtfIDoccomm
, "doccomm", 0 },
1783 /* \verscomm may not exist -- was seen in earlier spec version */
1784 { rtfDestination
, rtfIVerscomm
, "verscomm", 0 },
1785 { rtfDestination
, rtfNextFile
, "nextfile", 0 },
1786 { rtfDestination
, rtfTemplate
, "template", 0 },
1787 { rtfDestination
, rtfFNSep
, "ftnsep", 0 },
1788 { rtfDestination
, rtfFNContSep
, "ftnsepc", 0 },
1789 { rtfDestination
, rtfFNContNotice
, "ftncn", 0 },
1790 { rtfDestination
, rtfENSep
, "aftnsep", 0 },
1791 { rtfDestination
, rtfENContSep
, "aftnsepc", 0 },
1792 { rtfDestination
, rtfENContNotice
, "aftncn", 0 },
1793 { rtfDestination
, rtfPageNumLevel
, "pgnhn", 0 },
1794 { rtfDestination
, rtfParNumLevelStyle
, "pnseclvl", 0 },
1795 { rtfDestination
, rtfHeader
, "header", 0 },
1796 { rtfDestination
, rtfFooter
, "footer", 0 },
1797 { rtfDestination
, rtfHeaderLeft
, "headerl", 0 },
1798 { rtfDestination
, rtfHeaderRight
, "headerr", 0 },
1799 { rtfDestination
, rtfHeaderFirst
, "headerf", 0 },
1800 { rtfDestination
, rtfFooterLeft
, "footerl", 0 },
1801 { rtfDestination
, rtfFooterRight
, "footerr", 0 },
1802 { rtfDestination
, rtfFooterFirst
, "footerf", 0 },
1803 { rtfDestination
, rtfParNumText
, "pntext", 0 },
1804 { rtfDestination
, rtfParNumbering
, "pn", 0 },
1805 { rtfDestination
, rtfParNumTextAfter
, "pntexta", 0 },
1806 { rtfDestination
, rtfParNumTextBefore
, "pntextb", 0 },
1807 { rtfDestination
, rtfBookmarkStart
, "bkmkstart", 0 },
1808 { rtfDestination
, rtfBookmarkEnd
, "bkmkend", 0 },
1809 { rtfDestination
, rtfPict
, "pict", 0 },
1810 { rtfDestination
, rtfObject
, "object", 0 },
1811 { rtfDestination
, rtfObjClass
, "objclass", 0 },
1812 { rtfDestination
, rtfObjName
, "objname", 0 },
1813 { rtfObjAttr
, rtfObjTime
, "objtime", 0 },
1814 { rtfDestination
, rtfObjData
, "objdata", 0 },
1815 { rtfDestination
, rtfObjAlias
, "objalias", 0 },
1816 { rtfDestination
, rtfObjSection
, "objsect", 0 },
1817 /* objitem and objtopic aren't documented in the spec! */
1818 { rtfDestination
, rtfObjItem
, "objitem", 0 },
1819 { rtfDestination
, rtfObjTopic
, "objtopic", 0 },
1820 { rtfDestination
, rtfObjResult
, "result", 0 },
1821 { rtfDestination
, rtfDrawObject
, "do", 0 },
1822 { rtfDestination
, rtfFootnote
, "footnote", 0 },
1823 { rtfDestination
, rtfAnnotRefStart
, "atrfstart", 0 },
1824 { rtfDestination
, rtfAnnotRefEnd
, "atrfend", 0 },
1825 { rtfDestination
, rtfAnnotID
, "atnid", 0 },
1826 { rtfDestination
, rtfAnnotAuthor
, "atnauthor", 0 },
1827 { rtfDestination
, rtfAnnotation
, "annotation", 0 },
1828 { rtfDestination
, rtfAnnotRef
, "atnref", 0 },
1829 { rtfDestination
, rtfAnnotTime
, "atntime", 0 },
1830 { rtfDestination
, rtfAnnotIcon
, "atnicn", 0 },
1831 { rtfDestination
, rtfField
, "field", 0 },
1832 { rtfDestination
, rtfFieldInst
, "fldinst", 0 },
1833 { rtfDestination
, rtfFieldResult
, "fldrslt", 0 },
1834 { rtfDestination
, rtfDataField
, "datafield", 0 },
1835 { rtfDestination
, rtfIndex
, "xe", 0 },
1836 { rtfDestination
, rtfIndexText
, "txe", 0 },
1837 { rtfDestination
, rtfIndexRange
, "rxe", 0 },
1838 { rtfDestination
, rtfTOC
, "tc", 0 },
1839 { rtfDestination
, rtfNeXTGraphic
, "NeXTGraphic", 0 },
1845 { rtfFontFamily
, rtfFFNil
, "fnil", 0 },
1846 { rtfFontFamily
, rtfFFRoman
, "froman", 0 },
1847 { rtfFontFamily
, rtfFFSwiss
, "fswiss", 0 },
1848 { rtfFontFamily
, rtfFFModern
, "fmodern", 0 },
1849 { rtfFontFamily
, rtfFFScript
, "fscript", 0 },
1850 { rtfFontFamily
, rtfFFDecor
, "fdecor", 0 },
1851 { rtfFontFamily
, rtfFFTech
, "ftech", 0 },
1852 { rtfFontFamily
, rtfFFBidirectional
, "fbidi", 0 },
1858 { rtfFontAttr
, rtfFontCharSet
, "fcharset", 0 },
1859 { rtfFontAttr
, rtfFontPitch
, "fprq", 0 },
1860 { rtfFontAttr
, rtfFontCodePage
, "cpg", 0 },
1861 { rtfFontAttr
, rtfFTypeNil
, "ftnil", 0 },
1862 { rtfFontAttr
, rtfFTypeTrueType
, "fttruetype", 0 },
1865 * File table attributes
1868 { rtfFileAttr
, rtfFileNum
, "fid", 0 },
1869 { rtfFileAttr
, rtfFileRelPath
, "frelative", 0 },
1870 { rtfFileAttr
, rtfFileOSNum
, "fosnum", 0 },
1876 { rtfFileSource
, rtfSrcMacintosh
, "fvalidmac", 0 },
1877 { rtfFileSource
, rtfSrcDOS
, "fvaliddos", 0 },
1878 { rtfFileSource
, rtfSrcNTFS
, "fvalidntfs", 0 },
1879 { rtfFileSource
, rtfSrcHPFS
, "fvalidhpfs", 0 },
1880 { rtfFileSource
, rtfSrcNetwork
, "fnetwork", 0 },
1886 { rtfColorName
, rtfRed
, "red", 0 },
1887 { rtfColorName
, rtfGreen
, "green", 0 },
1888 { rtfColorName
, rtfBlue
, "blue", 0 },
1894 { rtfCharSet
, rtfMacCharSet
, "mac", 0 },
1895 { rtfCharSet
, rtfAnsiCharSet
, "ansi", 0 },
1896 { rtfCharSet
, rtfPcCharSet
, "pc", 0 },
1897 { rtfCharSet
, rtfPcaCharSet
, "pca", 0 },
1903 { rtfTblAttr
, rtfRowDef
, "trowd", 0 },
1904 { rtfTblAttr
, rtfRowGapH
, "trgaph", 0 },
1905 { rtfTblAttr
, rtfCellPos
, "cellx", 0 },
1906 { rtfTblAttr
, rtfMergeRngFirst
, "clmgf", 0 },
1907 { rtfTblAttr
, rtfMergePrevious
, "clmrg", 0 },
1909 { rtfTblAttr
, rtfRowLeft
, "trql", 0 },
1910 { rtfTblAttr
, rtfRowRight
, "trqr", 0 },
1911 { rtfTblAttr
, rtfRowCenter
, "trqc", 0 },
1912 { rtfTblAttr
, rtfRowLeftEdge
, "trleft", 0 },
1913 { rtfTblAttr
, rtfRowHt
, "trrh", 0 },
1914 { rtfTblAttr
, rtfRowHeader
, "trhdr", 0 },
1915 { rtfTblAttr
, rtfRowKeep
, "trkeep", 0 },
1917 { rtfTblAttr
, rtfRTLRow
, "rtlrow", 0 },
1918 { rtfTblAttr
, rtfLTRRow
, "ltrrow", 0 },
1920 { rtfTblAttr
, rtfRowBordTop
, "trbrdrt", 0 },
1921 { rtfTblAttr
, rtfRowBordLeft
, "trbrdrl", 0 },
1922 { rtfTblAttr
, rtfRowBordBottom
, "trbrdrb", 0 },
1923 { rtfTblAttr
, rtfRowBordRight
, "trbrdrr", 0 },
1924 { rtfTblAttr
, rtfRowBordHoriz
, "trbrdrh", 0 },
1925 { rtfTblAttr
, rtfRowBordVert
, "trbrdrv", 0 },
1927 { rtfTblAttr
, rtfCellBordBottom
, "clbrdrb", 0 },
1928 { rtfTblAttr
, rtfCellBordTop
, "clbrdrt", 0 },
1929 { rtfTblAttr
, rtfCellBordLeft
, "clbrdrl", 0 },
1930 { rtfTblAttr
, rtfCellBordRight
, "clbrdrr", 0 },
1932 { rtfTblAttr
, rtfCellShading
, "clshdng", 0 },
1933 { rtfTblAttr
, rtfCellBgPatH
, "clbghoriz", 0 },
1934 { rtfTblAttr
, rtfCellBgPatV
, "clbgvert", 0 },
1935 { rtfTblAttr
, rtfCellFwdDiagBgPat
, "clbgfdiag", 0 },
1936 { rtfTblAttr
, rtfCellBwdDiagBgPat
, "clbgbdiag", 0 },
1937 { rtfTblAttr
, rtfCellHatchBgPat
, "clbgcross", 0 },
1938 { rtfTblAttr
, rtfCellDiagHatchBgPat
, "clbgdcross", 0 },
1940 * The spec lists "clbgdkhor", but the corresponding non-cell
1941 * control is "bgdkhoriz". At any rate Macintosh Word seems
1942 * to accept both "clbgdkhor" and "clbgdkhoriz".
1944 { rtfTblAttr
, rtfCellDarkBgPatH
, "clbgdkhoriz", 0 },
1945 { rtfTblAttr
, rtfCellDarkBgPatH
, "clbgdkhor", 0 },
1946 { rtfTblAttr
, rtfCellDarkBgPatV
, "clbgdkvert", 0 },
1947 { rtfTblAttr
, rtfCellFwdDarkBgPat
, "clbgdkfdiag", 0 },
1948 { rtfTblAttr
, rtfCellBwdDarkBgPat
, "clbgdkbdiag", 0 },
1949 { rtfTblAttr
, rtfCellDarkHatchBgPat
, "clbgdkcross", 0 },
1950 { rtfTblAttr
, rtfCellDarkDiagHatchBgPat
, "clbgdkdcross", 0 },
1951 { rtfTblAttr
, rtfCellBgPatLineColor
, "clcfpat", 0 },
1952 { rtfTblAttr
, rtfCellBgPatColor
, "clcbpat", 0 },
1958 { rtfFieldAttr
, rtfFieldDirty
, "flddirty", 0 },
1959 { rtfFieldAttr
, rtfFieldEdited
, "fldedit", 0 },
1960 { rtfFieldAttr
, rtfFieldLocked
, "fldlock", 0 },
1961 { rtfFieldAttr
, rtfFieldPrivate
, "fldpriv", 0 },
1962 { rtfFieldAttr
, rtfFieldAlt
, "fldalt", 0 },
1965 * Positioning attributes
1968 { rtfPosAttr
, rtfAbsWid
, "absw", 0 },
1969 { rtfPosAttr
, rtfAbsHt
, "absh", 0 },
1971 { rtfPosAttr
, rtfRPosMargH
, "phmrg", 0 },
1972 { rtfPosAttr
, rtfRPosPageH
, "phpg", 0 },
1973 { rtfPosAttr
, rtfRPosColH
, "phcol", 0 },
1974 { rtfPosAttr
, rtfPosX
, "posx", 0 },
1975 { rtfPosAttr
, rtfPosNegX
, "posnegx", 0 },
1976 { rtfPosAttr
, rtfPosXCenter
, "posxc", 0 },
1977 { rtfPosAttr
, rtfPosXInside
, "posxi", 0 },
1978 { rtfPosAttr
, rtfPosXOutSide
, "posxo", 0 },
1979 { rtfPosAttr
, rtfPosXRight
, "posxr", 0 },
1980 { rtfPosAttr
, rtfPosXLeft
, "posxl", 0 },
1982 { rtfPosAttr
, rtfRPosMargV
, "pvmrg", 0 },
1983 { rtfPosAttr
, rtfRPosPageV
, "pvpg", 0 },
1984 { rtfPosAttr
, rtfRPosParaV
, "pvpara", 0 },
1985 { rtfPosAttr
, rtfPosY
, "posy", 0 },
1986 { rtfPosAttr
, rtfPosNegY
, "posnegy", 0 },
1987 { rtfPosAttr
, rtfPosYInline
, "posyil", 0 },
1988 { rtfPosAttr
, rtfPosYTop
, "posyt", 0 },
1989 { rtfPosAttr
, rtfPosYCenter
, "posyc", 0 },
1990 { rtfPosAttr
, rtfPosYBottom
, "posyb", 0 },
1992 { rtfPosAttr
, rtfNoWrap
, "nowrap", 0 },
1993 { rtfPosAttr
, rtfDistFromTextAll
, "dxfrtext", 0 },
1994 { rtfPosAttr
, rtfDistFromTextX
, "dfrmtxtx", 0 },
1995 { rtfPosAttr
, rtfDistFromTextY
, "dfrmtxty", 0 },
1996 /* \dyfrtext no longer exists in spec 1.2, apparently */
1997 /* replaced by \dfrmtextx and \dfrmtexty. */
1998 { rtfPosAttr
, rtfTextDistY
, "dyfrtext", 0 },
2000 { rtfPosAttr
, rtfDropCapLines
, "dropcapli", 0 },
2001 { rtfPosAttr
, rtfDropCapType
, "dropcapt", 0 },
2007 { rtfObjAttr
, rtfObjEmb
, "objemb", 0 },
2008 { rtfObjAttr
, rtfObjLink
, "objlink", 0 },
2009 { rtfObjAttr
, rtfObjAutoLink
, "objautlink", 0 },
2010 { rtfObjAttr
, rtfObjSubscriber
, "objsub", 0 },
2011 { rtfObjAttr
, rtfObjPublisher
, "objpub", 0 },
2012 { rtfObjAttr
, rtfObjICEmb
, "objicemb", 0 },
2014 { rtfObjAttr
, rtfObjLinkSelf
, "linkself", 0 },
2015 { rtfObjAttr
, rtfObjLock
, "objupdate", 0 },
2016 { rtfObjAttr
, rtfObjUpdate
, "objlock", 0 },
2018 { rtfObjAttr
, rtfObjHt
, "objh", 0 },
2019 { rtfObjAttr
, rtfObjWid
, "objw", 0 },
2020 { rtfObjAttr
, rtfObjSetSize
, "objsetsize", 0 },
2021 { rtfObjAttr
, rtfObjAlign
, "objalign", 0 },
2022 { rtfObjAttr
, rtfObjTransposeY
, "objtransy", 0 },
2023 { rtfObjAttr
, rtfObjCropTop
, "objcropt", 0 },
2024 { rtfObjAttr
, rtfObjCropBottom
, "objcropb", 0 },
2025 { rtfObjAttr
, rtfObjCropLeft
, "objcropl", 0 },
2026 { rtfObjAttr
, rtfObjCropRight
, "objcropr", 0 },
2027 { rtfObjAttr
, rtfObjScaleX
, "objscalex", 0 },
2028 { rtfObjAttr
, rtfObjScaleY
, "objscaley", 0 },
2030 { rtfObjAttr
, rtfObjResRTF
, "rsltrtf", 0 },
2031 { rtfObjAttr
, rtfObjResPict
, "rsltpict", 0 },
2032 { rtfObjAttr
, rtfObjResBitmap
, "rsltbmp", 0 },
2033 { rtfObjAttr
, rtfObjResText
, "rslttxt", 0 },
2034 { rtfObjAttr
, rtfObjResMerge
, "rsltmerge", 0 },
2036 { rtfObjAttr
, rtfObjBookmarkPubObj
, "bkmkpub", 0 },
2037 { rtfObjAttr
, rtfObjPubAutoUpdate
, "pubauto", 0 },
2040 * Associated character formatting attributes
2043 { rtfACharAttr
, rtfACBold
, "ab", 0 },
2044 { rtfACharAttr
, rtfACAllCaps
, "caps", 0 },
2045 { rtfACharAttr
, rtfACForeColor
, "acf", 0 },
2046 { rtfACharAttr
, rtfACSubScript
, "adn", 0 },
2047 { rtfACharAttr
, rtfACExpand
, "aexpnd", 0 },
2048 { rtfACharAttr
, rtfACFontNum
, "af", 0 },
2049 { rtfACharAttr
, rtfACFontSize
, "afs", 0 },
2050 { rtfACharAttr
, rtfACItalic
, "ai", 0 },
2051 { rtfACharAttr
, rtfACLanguage
, "alang", 0 },
2052 { rtfACharAttr
, rtfACOutline
, "aoutl", 0 },
2053 { rtfACharAttr
, rtfACSmallCaps
, "ascaps", 0 },
2054 { rtfACharAttr
, rtfACShadow
, "ashad", 0 },
2055 { rtfACharAttr
, rtfACStrikeThru
, "astrike", 0 },
2056 { rtfACharAttr
, rtfACUnderline
, "aul", 0 },
2057 { rtfACharAttr
, rtfACDotUnderline
, "auld", 0 },
2058 { rtfACharAttr
, rtfACDbUnderline
, "auldb", 0 },
2059 { rtfACharAttr
, rtfACNoUnderline
, "aulnone", 0 },
2060 { rtfACharAttr
, rtfACWordUnderline
, "aulw", 0 },
2061 { rtfACharAttr
, rtfACSuperScript
, "aup", 0 },
2064 * Footnote attributes
2067 { rtfFNoteAttr
, rtfFNAlt
, "ftnalt", 0 },
2070 * Key code attributes
2073 { rtfKeyCodeAttr
, rtfAltKey
, "alt", 0 },
2074 { rtfKeyCodeAttr
, rtfShiftKey
, "shift", 0 },
2075 { rtfKeyCodeAttr
, rtfControlKey
, "ctrl", 0 },
2076 { rtfKeyCodeAttr
, rtfFunctionKey
, "fn", 0 },
2079 * Bookmark attributes
2082 { rtfBookmarkAttr
, rtfBookmarkFirstCol
, "bkmkcolf", 0 },
2083 { rtfBookmarkAttr
, rtfBookmarkLastCol
, "bkmkcoll", 0 },
2086 * Index entry attributes
2089 { rtfIndexAttr
, rtfIndexNumber
, "xef", 0 },
2090 { rtfIndexAttr
, rtfIndexBold
, "bxe", 0 },
2091 { rtfIndexAttr
, rtfIndexItalic
, "ixe", 0 },
2094 * Table of contents attributes
2097 { rtfTOCAttr
, rtfTOCType
, "tcf", 0 },
2098 { rtfTOCAttr
, rtfTOCLevel
, "tcl", 0 },
2101 * Drawing object attributes
2104 { rtfDrawAttr
, rtfDrawLock
, "dolock", 0 },
2105 { rtfDrawAttr
, rtfDrawPageRelX
, "doxpage", 0 },
2106 { rtfDrawAttr
, rtfDrawColumnRelX
, "dobxcolumn", 0 },
2107 { rtfDrawAttr
, rtfDrawMarginRelX
, "dobxmargin", 0 },
2108 { rtfDrawAttr
, rtfDrawPageRelY
, "dobypage", 0 },
2109 { rtfDrawAttr
, rtfDrawColumnRelY
, "dobycolumn", 0 },
2110 { rtfDrawAttr
, rtfDrawMarginRelY
, "dobymargin", 0 },
2111 { rtfDrawAttr
, rtfDrawHeight
, "dobhgt", 0 },
2113 { rtfDrawAttr
, rtfDrawBeginGroup
, "dpgroup", 0 },
2114 { rtfDrawAttr
, rtfDrawGroupCount
, "dpcount", 0 },
2115 { rtfDrawAttr
, rtfDrawEndGroup
, "dpendgroup", 0 },
2116 { rtfDrawAttr
, rtfDrawArc
, "dparc", 0 },
2117 { rtfDrawAttr
, rtfDrawCallout
, "dpcallout", 0 },
2118 { rtfDrawAttr
, rtfDrawEllipse
, "dpellipse", 0 },
2119 { rtfDrawAttr
, rtfDrawLine
, "dpline", 0 },
2120 { rtfDrawAttr
, rtfDrawPolygon
, "dppolygon", 0 },
2121 { rtfDrawAttr
, rtfDrawPolyLine
, "dppolyline", 0 },
2122 { rtfDrawAttr
, rtfDrawRect
, "dprect", 0 },
2123 { rtfDrawAttr
, rtfDrawTextBox
, "dptxbx", 0 },
2125 { rtfDrawAttr
, rtfDrawOffsetX
, "dpx", 0 },
2126 { rtfDrawAttr
, rtfDrawSizeX
, "dpxsize", 0 },
2127 { rtfDrawAttr
, rtfDrawOffsetY
, "dpy", 0 },
2128 { rtfDrawAttr
, rtfDrawSizeY
, "dpysize", 0 },
2130 { rtfDrawAttr
, rtfCOAngle
, "dpcoa", 0 },
2131 { rtfDrawAttr
, rtfCOAccentBar
, "dpcoaccent", 0 },
2132 { rtfDrawAttr
, rtfCOBestFit
, "dpcobestfit", 0 },
2133 { rtfDrawAttr
, rtfCOBorder
, "dpcoborder", 0 },
2134 { rtfDrawAttr
, rtfCOAttachAbsDist
, "dpcodabs", 0 },
2135 { rtfDrawAttr
, rtfCOAttachBottom
, "dpcodbottom", 0 },
2136 { rtfDrawAttr
, rtfCOAttachCenter
, "dpcodcenter", 0 },
2137 { rtfDrawAttr
, rtfCOAttachTop
, "dpcodtop", 0 },
2138 { rtfDrawAttr
, rtfCOLength
, "dpcolength", 0 },
2139 { rtfDrawAttr
, rtfCONegXQuadrant
, "dpcominusx", 0 },
2140 { rtfDrawAttr
, rtfCONegYQuadrant
, "dpcominusy", 0 },
2141 { rtfDrawAttr
, rtfCOOffset
, "dpcooffset", 0 },
2142 { rtfDrawAttr
, rtfCOAttachSmart
, "dpcosmarta", 0 },
2143 { rtfDrawAttr
, rtfCODoubleLine
, "dpcotdouble", 0 },
2144 { rtfDrawAttr
, rtfCORightAngle
, "dpcotright", 0 },
2145 { rtfDrawAttr
, rtfCOSingleLine
, "dpcotsingle", 0 },
2146 { rtfDrawAttr
, rtfCOTripleLine
, "dpcottriple", 0 },
2148 { rtfDrawAttr
, rtfDrawTextBoxMargin
, "dptxbxmar", 0 },
2149 { rtfDrawAttr
, rtfDrawTextBoxText
, "dptxbxtext", 0 },
2150 { rtfDrawAttr
, rtfDrawRoundRect
, "dproundr", 0 },
2152 { rtfDrawAttr
, rtfDrawPointX
, "dpptx", 0 },
2153 { rtfDrawAttr
, rtfDrawPointY
, "dppty", 0 },
2154 { rtfDrawAttr
, rtfDrawPolyCount
, "dppolycount", 0 },
2156 { rtfDrawAttr
, rtfDrawArcFlipX
, "dparcflipx", 0 },
2157 { rtfDrawAttr
, rtfDrawArcFlipY
, "dparcflipy", 0 },
2159 { rtfDrawAttr
, rtfDrawLineBlue
, "dplinecob", 0 },
2160 { rtfDrawAttr
, rtfDrawLineGreen
, "dplinecog", 0 },
2161 { rtfDrawAttr
, rtfDrawLineRed
, "dplinecor", 0 },
2162 { rtfDrawAttr
, rtfDrawLinePalette
, "dplinepal", 0 },
2163 { rtfDrawAttr
, rtfDrawLineDashDot
, "dplinedado", 0 },
2164 { rtfDrawAttr
, rtfDrawLineDashDotDot
, "dplinedadodo", 0 },
2165 { rtfDrawAttr
, rtfDrawLineDash
, "dplinedash", 0 },
2166 { rtfDrawAttr
, rtfDrawLineDot
, "dplinedot", 0 },
2167 { rtfDrawAttr
, rtfDrawLineGray
, "dplinegray", 0 },
2168 { rtfDrawAttr
, rtfDrawLineHollow
, "dplinehollow", 0 },
2169 { rtfDrawAttr
, rtfDrawLineSolid
, "dplinesolid", 0 },
2170 { rtfDrawAttr
, rtfDrawLineWidth
, "dplinew", 0 },
2172 { rtfDrawAttr
, rtfDrawHollowEndArrow
, "dpaendhol", 0 },
2173 { rtfDrawAttr
, rtfDrawEndArrowLength
, "dpaendl", 0 },
2174 { rtfDrawAttr
, rtfDrawSolidEndArrow
, "dpaendsol", 0 },
2175 { rtfDrawAttr
, rtfDrawEndArrowWidth
, "dpaendw", 0 },
2176 { rtfDrawAttr
, rtfDrawHollowStartArrow
,"dpastarthol", 0 },
2177 { rtfDrawAttr
, rtfDrawStartArrowLength
,"dpastartl", 0 },
2178 { rtfDrawAttr
, rtfDrawSolidStartArrow
, "dpastartsol", 0 },
2179 { rtfDrawAttr
, rtfDrawStartArrowWidth
, "dpastartw", 0 },
2181 { rtfDrawAttr
, rtfDrawBgFillBlue
, "dpfillbgcb", 0 },
2182 { rtfDrawAttr
, rtfDrawBgFillGreen
, "dpfillbgcg", 0 },
2183 { rtfDrawAttr
, rtfDrawBgFillRed
, "dpfillbgcr", 0 },
2184 { rtfDrawAttr
, rtfDrawBgFillPalette
, "dpfillbgpal", 0 },
2185 { rtfDrawAttr
, rtfDrawBgFillGray
, "dpfillbggray", 0 },
2186 { rtfDrawAttr
, rtfDrawFgFillBlue
, "dpfillfgcb", 0 },
2187 { rtfDrawAttr
, rtfDrawFgFillGreen
, "dpfillfgcg", 0 },
2188 { rtfDrawAttr
, rtfDrawFgFillRed
, "dpfillfgcr", 0 },
2189 { rtfDrawAttr
, rtfDrawFgFillPalette
, "dpfillfgpal", 0 },
2190 { rtfDrawAttr
, rtfDrawFgFillGray
, "dpfillfggray", 0 },
2191 { rtfDrawAttr
, rtfDrawFillPatIndex
, "dpfillpat", 0 },
2193 { rtfDrawAttr
, rtfDrawShadow
, "dpshadow", 0 },
2194 { rtfDrawAttr
, rtfDrawShadowXOffset
, "dpshadx", 0 },
2195 { rtfDrawAttr
, rtfDrawShadowYOffset
, "dpshady", 0 },
2197 { rtfVersion
, -1, "rtf", 0 },
2198 { rtfDefFont
, -1, "deff", 0 },
2200 { 0, -1, (char *) NULL
, 0 }
2202 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2204 typedef struct tagRTFHashTableEntry
{
2207 } RTFHashTableEntry
;
2209 static RTFHashTableEntry rtfHashTable
[RTF_KEY_COUNT
* 2];
2213 * Initialize lookup table hash values. Only need to do this once.
2216 static void LookupInit(void)
2218 static int inited
= 0;
2223 memset(rtfHashTable
, 0, RTF_KEY_COUNT
* 2 * sizeof(*rtfHashTable
));
2224 for (rp
= rtfKey
; rp
->rtfKStr
!= (char *) NULL
; rp
++) {
2227 rp
->rtfKHash
= Hash ((char*)rp
->rtfKStr
);
2228 index
= rp
->rtfKHash
% (RTF_KEY_COUNT
* 2);
2229 if (!rtfHashTable
[index
].count
)
2230 rtfHashTable
[index
].value
= (void *)RTFAlloc(sizeof(RTFKey
*));
2232 rtfHashTable
[index
].value
= (void *)RTFReAlloc((void *)rtfHashTable
[index
].value
, sizeof(RTFKey
*) * (rtfHashTable
[index
].count
+ 1));
2233 rtfHashTable
[index
].value
[rtfHashTable
[index
].count
++] = rp
;
2241 * Determine major and minor number of control token. If it's
2242 * not found, the class turns into rtfUnknown.
2245 static void Lookup(RTF_Info
*info
, char *s
)
2249 RTFHashTableEntry
*entry
;
2253 ++s
; /* skip over the leading \ character */
2255 entry
= &rtfHashTable
[hash
% (RTF_KEY_COUNT
* 2)];
2256 for (i
= 0; i
< entry
->count
; i
++)
2258 rp
= entry
->value
[i
];
2259 if (hash
== rp
->rtfKHash
&& strcmp (s
, rp
->rtfKStr
) == 0)
2261 info
->rtfClass
= rtfControl
;
2262 info
->rtfMajor
= rp
->rtfKMajor
;
2263 info
->rtfMinor
= rp
->rtfKMinor
;
2267 info
->rtfClass
= rtfUnknown
;
2272 * Compute hash value of symbol
2275 static int Hash(char *s
)
2280 while ((c
= *s
++) != '\0')
2286 /* ---------------------------------------------------------------------- */
2289 * Memory allocation routines
2294 * Return pointer to block of size bytes, or NULL if there's
2295 * not enough memory available.
2297 * This is called through RTFAlloc(), a define which coerces the
2298 * argument to int. This avoids the persistent problem of allocation
2299 * failing under THINK C when a long is passed.
2302 char *_RTFAlloc(int size
)
2304 return HeapAlloc(me_heap
, 0, size
);
2309 RTFReAlloc(char *ptr
, int size
)
2311 return HeapReAlloc(me_heap
, 0, ptr
, size
);
2316 * Saves a string on the heap and returns a pointer to it.
2320 char *RTFStrSave(char *s
)
2324 if ((p
= RTFAlloc ((int) (strlen (s
) + 1))) == (char *) NULL
)
2325 return ((char *) NULL
);
2326 return (strcpy (p
, s
));
2330 void RTFFree(char *p
)
2332 HeapFree(me_heap
, 0, p
);
2336 /* ---------------------------------------------------------------------- */
2340 * Token comparison routines
2343 int RTFCheckCM(RTF_Info
*info
, int class, int major
)
2345 return (info
->rtfClass
== class && info
->rtfMajor
== major
);
2349 int RTFCheckCMM(RTF_Info
*info
, int class, int major
, int minor
)
2351 return (info
->rtfClass
== class && info
->rtfMajor
== major
&& info
->rtfMinor
== minor
);
2355 int RTFCheckMM(RTF_Info
*info
, int major
, int minor
)
2357 return (info
->rtfMajor
== major
&& info
->rtfMinor
== minor
);
2361 /* ---------------------------------------------------------------------- */
2364 int RTFCharToHex(char c
)
2369 return (c
- '0'); /* '0'..'9' */
2370 return (c
- 'a' + 10); /* 'a'..'f' */
2374 int RTFHexToChar(int i
)
2378 return (i
- 10 + 'a');
2382 /* ---------------------------------------------------------------------- */
2385 * Open a library file.
2389 void RTFSetOpenLibFileProc(RTF_Info
*info
, FILE *(*proc
)())
2391 info
->libFileOpen
= proc
;
2395 FILE *RTFOpenLibFile (RTF_Info
*info
, char *file
, char *mode
)
2397 if (info
->libFileOpen
== NULL
)
2398 return ((FILE *) NULL
);
2399 return ((*info
->libFileOpen
) (file
, mode
));
2403 /* ---------------------------------------------------------------------- */
2406 * Print message. Default is to send message to stderr
2407 * but this may be overridden with RTFSetMsgProc().
2409 * Message should include linefeeds as necessary. If the default
2410 * function is overridden, the overriding function may want to
2411 * map linefeeds to another line ending character or sequence if
2412 * the host system doesn't use linefeeds.
2416 void RTFMsg (RTF_Info
*info
, const char *fmt
, ...)
2418 char buf
[rtfBufSiz
];
2421 va_start (args
,fmt
);
2422 vsprintf (buf
, fmt
, args
);
2424 MESSAGE( "%s", buf
);
2428 /* ---------------------------------------------------------------------- */
2432 * Process termination. Print error message and exit. Also prints
2433 * current token, and current input line number and position within
2434 * line if any input has been read from the current file. (No input
2435 * has been read if prevChar is EOF).
2438 static void DefaultPanicProc(RTF_Info
*info
, char *s
)
2446 void RTFPanic(RTF_Info
*info
, const char *fmt
, ...)
2448 char buf
[rtfBufSiz
];
2451 va_start (args
,fmt
);
2452 vsprintf (buf
, fmt
, args
);
2454 (void) strcat (buf
, "\n");
2455 if (info
->prevChar
!= EOF
&& info
->rtfTextBuf
!= (char *) NULL
)
2457 sprintf (buf
+ strlen (buf
),
2458 "Last token read was \"%s\" near line %ld, position %d.\n",
2459 info
->rtfTextBuf
, info
->rtfLineNum
, info
->rtfLinePos
);
2461 DefaultPanicProc(info
, buf
);
2464 /* ---------------------------------------------------------------------- */
2467 * originally from RTF tools' text-writer.c
2469 * text-writer -- RTF-to-text translation writer code.
2471 * Read RTF input, write text of document (text extraction).
2474 static void TextClass (RTF_Info
*info
);
2475 static void ControlClass (RTF_Info
*info
);
2476 static void Destination (RTF_Info
*info
);
2477 static void SpecialChar (RTF_Info
*info
);
2478 static void PutLitChar (RTF_Info
*info
, int c
);
2481 * Initialize the writer.
2485 WriterInit (RTF_Info
*info
)
2491 BeginFile (RTF_Info
*info
)
2493 /* install class callbacks */
2495 RTFSetClassCallback (info
, rtfText
, TextClass
);
2496 RTFSetClassCallback (info
, rtfControl
, ControlClass
);
2502 * Write out a character. Seems to work for the default ANSI codepage,
2503 * contrary to TextClass_orig.
2507 TextClass (RTF_Info
*info
)
2509 PutLitChar (info
, info
->rtfMajor
);
2514 ControlClass (RTF_Info
*info
)
2518 switch (info
->rtfMajor
)
2526 case rtfDestination
:
2532 case rtfSpecialChar
:
2540 CharAttr(RTF_Info
*info
)
2542 switch (info
->rtfMinor
)
2545 info
->codePage
= RTFGetFont(info
, info
->rtfParam
)->rtfFCodePage
;
2552 CharSet(RTF_Info
*info
)
2554 switch (info
->rtfMinor
)
2556 case rtfAnsiCharSet
:
2557 info
->ansiCodePage
= 1252; /* Latin-1 */
2560 info
->ansiCodePage
= 10000; /* MacRoman */
2563 info
->ansiCodePage
= 437;
2566 info
->ansiCodePage
= 850;
2572 * This function notices destinations that aren't explicitly handled
2573 * and skips to their ends. This keeps, for instance, picture
2574 * data from being considered as plain text.
2578 Destination (RTF_Info
*info
)
2581 if (!RTFGetDestinationCallback(info
, info
->rtfMinor
))
2582 RTFSkipGroup (info
);
2587 DocAttr(RTF_Info
*info
)
2589 switch (info
->rtfMinor
)
2591 case rtfAnsiCodePage
:
2592 info
->ansiCodePage
= info
->rtfParam
;
2594 case rtfUnicodeLength
:
2595 info
->unicodeLength
= info
->rtfParam
;
2601 static void SpecialChar (RTF_Info
*info
)
2606 switch (info
->rtfMinor
)
2609 /* the next token determines destination, if it's unknown, skip the group */
2610 /* this way we filter out the garbage coming from unknown destinations */
2612 if (info
->rtfClass
!= rtfDestination
)
2615 RTFRouteToken(info
); /* "\*" is ignored with known destinations */
2622 buf
[0] = info
->rtfParam
;
2624 RTFFlushOutputBuffer(info
);
2625 RTFOutputUnicodeString(info
, buf
, 1);
2627 /* After \u we must skip number of character tokens set by \ucN */
2628 for (i
= 0; i
< info
->unicodeLength
; i
++)
2631 if (info
->rtfClass
!= rtfText
)
2633 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2634 info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
2635 RTFUngetToken(info
);
2645 PutLitChar (info
, '\n');
2648 PutLitChar (info
, ' '); /* make sure cells are separated */
2651 PutLitChar (info
, 0x00A0);
2654 PutLitChar (info
, '\t');
2656 case rtfNoBrkHyphen
:
2657 PutLitChar (info
, 0x2011);
2660 PutLitChar (info
, 0x2022);
2663 PutLitChar (info
, 0x2014);
2666 PutLitChar (info
, 0x2013);
2669 PutLitChar (info
, 0x2018);
2672 PutLitChar (info
, 0x2019);
2675 PutLitChar (info
, 0x201C);
2678 PutLitChar (info
, 0x201D);
2684 static void PutLitChar (RTF_Info
*info
, int c
)
2686 if( info
->dwOutputCount
>= ( sizeof info
->OutputBuffer
- 1 ) )
2687 RTFFlushOutputBuffer( info
);
2688 info
->OutputBuffer
[info
->dwOutputCount
++] = c
;
2691 static void RTFOutputUnicodeString( RTF_Info
*info
, WCHAR
*str
, int len
)
2693 assert(str
[len
] == '\0');
2695 ME_InsertTextFromCursor( info
->editor
, 0, str
, len
, info
->style
);
2700 void RTFFlushOutputBuffer( RTF_Info
*info
)
2702 info
->OutputBuffer
[info
->dwOutputCount
] = 0;
2703 RTFOutputUnicodeString(info
, info
->OutputBuffer
, info
->dwOutputCount
);
2704 info
->dwOutputCount
= 0;