- support DirectInput 8 interfaces.
[wine/multimedia.git] / dlls / richedit / reader.c
blobe2a64a396235b458f2b3e156d86fd422c84c5bd5
1 /*
2 * - Need to document error code meanings.
3 * - Need to do something with \* on destinations.
4 * - Make the parameter a long?
6 * reader.c - RTF file reader. Release 1.10.
8 * ASCII 10 (\n) and 13 (\r) are ignored and silently discarded.
9 * Nulls are also discarded.
10 * (although the read hook will still get a look at them.)
12 * "\:" is not a ":", it's a control symbol. But some versions of
13 * Word seem to write "\:" for ":". This reader treats "\:" as a
14 * plain text ":"
16 * 19 Mar 93
17 * - Add hack to skip "{\*\keycode ... }" group in stylesheet.
18 * This is probably the wrong thing to do, but it's simple.
19 * 13 Jul 93
20 * - Add THINK C awareness to malloc() declaration. Necessary so
21 * compiler knows the malloc argument is 4 bytes. Ugh.
22 * 07 Sep 93
23 * - Text characters are mapped onto standard codes, which are placed
24 * in rtfMinor.
25 * - Eliminated use of index() function.
26 * 05 Mar 94
27 * - Added zillions of new symbols (those defined in RTF spec 1.2).
28 * 14 Mar 94
29 * - Public functions RTFMsg() and RTFPanic() now take variable arguments.
30 * This means RTFPanic() now is used in place of what was formerly the
31 * internal function Error().
32 * - 8-bit characters are now legal, so they're not converted to \'xx
33 * hex char representation now.
34 * 01 Apr 94
35 * - Added public variables rtfLineNum and rtfLinePos.
36 * - #include string.h or strings.h, avoiding strncmp() problem where
37 * last argument is treated as zero when prototype isn't available.
38 * 04 Apr 94
39 * - Treat style numbers 222 and 0 properly as "no style" and "normal".
41 * Author: Paul DuBois dubois@primate.wisc.edu
43 * This software may be redistributed without restriction and used for
44 * any purpose whatsoever.
47 # ifndef STRING_H
48 # define STRING_H <string.h>
49 # endif
51 # include <stdio.h>
52 # include <ctype.h>
53 # include STRING_H
54 # ifdef STDARG
55 # include <stdarg.h>
56 # else
57 # ifdef VARARGS
58 # include <varargs.h>
59 # endif /* VARARGS */
60 # endif /* STDARG */
62 # define rtfInternal
63 # include "rtf.h"
64 # undef rtfInternal
67 * include hard coded charsets
70 #include "ansi_gen.h"
71 #include "ansi_sym.h"
72 #include "text_map.h"
74 #include <stdlib.h>
76 #include "charlist.h"
77 #include "windef.h"
78 #include "winbase.h"
79 #include "wine/debug.h"
81 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
83 extern HANDLE RICHED32_hHeap;
86 * Return pointer to new element of type t, or NULL
87 * if no memory available.
90 # define New(t) ((t *) RTFAlloc ((int) sizeof (t)))
92 /* maximum number of character values representable in a byte */
94 # define charSetSize 256
96 /* charset stack size */
98 # define maxCSStack 10
100 static int _RTFGetChar();
101 static void _RTFGetToken ();
102 static void _RTFGetToken2 ();
103 static int GetChar ();
104 static void ReadFontTbl ();
105 static void ReadColorTbl ();
106 static void ReadStyleSheet ();
107 static void ReadInfoGroup ();
108 static void ReadPictGroup ();
109 static void ReadObjGroup ();
110 static void LookupInit ();
111 static void Lookup ();
112 static int Hash ();
114 static void CharSetInit ();
115 static void ReadCharSetMaps ();
119 * Public variables (listed in rtf.h)
122 int rtfClass;
123 int rtfMajor;
124 int rtfMinor;
125 int rtfParam;
126 char *rtfTextBuf = (char *) NULL;
127 int rtfTextLen;
129 long rtfLineNum;
130 int rtfLinePos;
134 * Private stuff
137 static int pushedChar; /* pushback char if read too far */
139 static int pushedClass; /* pushed token info for RTFUngetToken() */
140 static int pushedMajor;
141 static int pushedMinor;
142 static int pushedParam;
143 static char *pushedTextBuf = (char *) NULL;
145 static int prevChar;
146 static int bumpLine;
148 static RTFFont *fontList = (RTFFont *) NULL; /* these lists MUST be */
149 static RTFColor *colorList = (RTFColor *) NULL; /* initialized to NULL */
150 static RTFStyle *styleList = (RTFStyle *) NULL;
152 static char *inputName = (char *) NULL;
153 static char *outputName = (char *) NULL;
155 static EDITSTREAM editstream;
156 static CHARLIST inputCharList = {0, NULL, NULL};
159 * This array is used to map standard character names onto their numeric codes.
160 * The position of the name within the array is the code.
161 * stdcharnames.h is generated in the ../h directory.
164 static char *stdCharName[] =
166 # include "stdcharnames.h"
167 (char *) NULL
172 * These arrays are used to map RTF input character values onto the standard
173 * character names represented by the values. Input character values are
174 * used as indices into the arrays to produce standard character codes.
178 static char *genCharSetFile = (char *) NULL;
179 static int genCharCode[charSetSize]; /* general */
180 static int haveGenCharSet = 0;
182 static char *symCharSetFile = (char *) NULL;
183 static int symCharCode[charSetSize]; /* symbol */
184 static int haveSymCharSet = 0;
186 static int curCharSet = rtfCSGeneral;
187 static int *curCharCode = genCharCode;
190 * By default, the reader is configured to handle charset mapping invisibly,
191 * including reading the charset files and switching charset maps as necessary
192 * for Symbol font.
195 static int autoCharSetFlags;
198 * Stack for keeping track of charset map on group begin/end. This is
199 * necessary because group termination reverts the font to the previous
200 * value, which may implicitly change it.
203 static int csStack[maxCSStack];
204 static int csTop = 0;
207 * Get a char from the charlist. The charlist is used to store characters
208 * from the editstream.
213 _RTFGetChar()
215 char myChar;
217 TRACE("\n");
219 if(CHARLIST_GetNbItems(&inputCharList) == 0)
221 char buff[10];
222 long pcb;
223 editstream.pfnCallback(editstream.dwCookie, buff, 1, &pcb);
224 if(pcb == 0)
225 return EOF;
226 else
227 CHARLIST_Enqueue(&inputCharList, buff[0]);
229 myChar = CHARLIST_Dequeue(&inputCharList);
230 return (int) myChar;
233 void
234 RTFSetEditStream(EDITSTREAM *es)
236 TRACE("\n");
238 editstream.dwCookie = es->dwCookie;
239 editstream.dwError = es->dwError;
240 editstream.pfnCallback = es->pfnCallback;
244 * Initialize the reader. This may be called multiple times,
245 * to read multiple files. The only thing not reset is the input
246 * stream; that must be done with RTFSetStream().
249 void
250 RTFInit ()
252 int i;
253 RTFColor *cp;
254 RTFFont *fp;
255 RTFStyle *sp;
256 RTFStyleElt *eltList, *ep;
258 TRACE("\n");
260 if (rtfTextBuf == (char *) NULL) /* initialize the text buffers */
262 rtfTextBuf = RTFAlloc (rtfBufSiz);
263 pushedTextBuf = RTFAlloc (rtfBufSiz);
264 if (rtfTextBuf == (char *) NULL
265 || pushedTextBuf == (char *) NULL)
266 RTFPanic ("Cannot allocate text buffers.");
267 rtfTextBuf[0] = pushedTextBuf[0] = '\0';
270 RTFFree (inputName);
271 RTFFree (outputName);
272 inputName = outputName = (char *) NULL;
274 /* initialize lookup table */
275 LookupInit ();
277 for (i = 0; i < rtfMaxClass; i++)
278 RTFSetClassCallback (i, (RTFFuncPtr) NULL);
279 for (i = 0; i < rtfMaxDestination; i++)
280 RTFSetDestinationCallback (i, (RTFFuncPtr) NULL);
282 /* install built-in destination readers */
283 RTFSetDestinationCallback (rtfFontTbl, ReadFontTbl);
284 RTFSetDestinationCallback (rtfColorTbl, ReadColorTbl);
285 RTFSetDestinationCallback (rtfStyleSheet, ReadStyleSheet);
286 RTFSetDestinationCallback (rtfInfo, ReadInfoGroup);
287 RTFSetDestinationCallback (rtfPict, ReadPictGroup);
288 RTFSetDestinationCallback (rtfObject, ReadObjGroup);
291 RTFSetReadHook ((RTFFuncPtr) NULL);
293 /* dump old lists if necessary */
295 while (fontList != (RTFFont *) NULL)
297 fp = fontList->rtfNextFont;
298 RTFFree (fontList->rtfFName);
299 RTFFree ((char *) fontList);
300 fontList = fp;
302 while (colorList != (RTFColor *) NULL)
304 cp = colorList->rtfNextColor;
305 RTFFree ((char *) colorList);
306 colorList = cp;
308 while (styleList != (RTFStyle *) NULL)
310 sp = styleList->rtfNextStyle;
311 eltList = styleList->rtfSSEList;
312 while (eltList != (RTFStyleElt *) NULL)
314 ep = eltList->rtfNextSE;
315 RTFFree (eltList->rtfSEText);
316 RTFFree ((char *) eltList);
317 eltList = ep;
319 RTFFree (styleList->rtfSName);
320 RTFFree ((char *) styleList);
321 styleList = sp;
324 rtfClass = -1;
325 pushedClass = -1;
326 pushedChar = EOF;
328 rtfLineNum = 0;
329 rtfLinePos = 0;
330 prevChar = EOF;
331 bumpLine = 0;
333 CharSetInit ();
334 csTop = 0;
338 * Set or get the input or output file name. These are never guaranteed
339 * to be accurate, only insofar as the calling program makes them so.
342 void
343 RTFSetInputName (name)
344 char *name;
346 TRACE("\n");
348 if ((inputName = RTFStrSave (name)) == (char *) NULL)
349 RTFPanic ("RTFSetInputName: out of memory");
353 char *
354 RTFGetInputName ()
356 return (inputName);
360 void
361 RTFSetOutputName (name)
362 char *name;
364 TRACE("\n");
366 if ((outputName = RTFStrSave (name)) == (char *) NULL)
367 RTFPanic ("RTFSetOutputName: out of memory");
371 char *
372 RTFGetOutputName ()
374 return (outputName);
379 /* ---------------------------------------------------------------------- */
382 * Callback table manipulation routines
387 * Install or return a writer callback for a token class
391 static RTFFuncPtr ccb[rtfMaxClass]; /* class callbacks */
394 void
395 RTFSetClassCallback (class, callback)
396 int class;
397 RTFFuncPtr callback;
399 if (class >= 0 && class < rtfMaxClass)
400 ccb[class] = callback;
404 RTFFuncPtr
405 RTFGetClassCallback (class)
406 int class;
408 if (class >= 0 && class < rtfMaxClass)
409 return (ccb[class]);
410 return ((RTFFuncPtr) NULL);
415 * Install or return a writer callback for a destination type
418 static RTFFuncPtr dcb[rtfMaxDestination]; /* destination callbacks */
421 void
422 RTFSetDestinationCallback (dest, callback)
423 int dest;
424 RTFFuncPtr callback;
426 if (dest >= 0 && dest < rtfMaxDestination)
427 dcb[dest] = callback;
431 RTFFuncPtr
432 RTFGetDestinationCallback (dest)
433 int dest;
435 if (dest >= 0 && dest < rtfMaxDestination)
436 return (dcb[dest]);
437 return ((RTFFuncPtr) NULL);
441 /* ---------------------------------------------------------------------- */
444 * Token reading routines
449 * Read the input stream, invoking the writer's callbacks
450 * where appropriate.
453 void
454 RTFRead ()
456 while (RTFGetToken () != rtfEOF)
457 RTFRouteToken ();
462 * Route a token. If it's a destination for which a reader is
463 * installed, process the destination internally, otherwise
464 * pass the token to the writer's class callback.
467 void
468 RTFRouteToken ()
470 RTFFuncPtr p;
472 TRACE("\n");
474 if (rtfClass < 0 || rtfClass >= rtfMaxClass) /* watchdog */
476 RTFPanic ("Unknown class %d: %s (reader malfunction)",
477 rtfClass, rtfTextBuf);
479 if (RTFCheckCM (rtfControl, rtfDestination))
481 /* invoke destination-specific callback if there is one */
482 if ((p = RTFGetDestinationCallback (rtfMinor))
483 != (RTFFuncPtr) NULL)
485 (*p) ();
486 return;
489 /* invoke class callback if there is one */
490 if ((p = RTFGetClassCallback (rtfClass)) != (RTFFuncPtr) NULL)
491 (*p) ();
496 * Skip to the end of the current group. When this returns,
497 * writers that maintain a state stack may want to call their
498 * state unstacker; global vars will still be set to the group's
499 * closing brace.
502 void
503 RTFSkipGroup ()
505 int level = 1;
506 TRACE("\n");
508 while (RTFGetToken () != rtfEOF)
510 if (rtfClass == rtfGroup)
512 if (rtfMajor == rtfBeginGroup)
513 ++level;
514 else if (rtfMajor == rtfEndGroup)
516 if (--level < 1)
517 break; /* end of initial group */
525 * Read one token. Call the read hook if there is one. The
526 * token class is the return value. Returns rtfEOF when there
527 * are no more tokens.
531 RTFGetToken ()
533 RTFFuncPtr p;
534 TRACE("\n");
536 for (;;)
538 _RTFGetToken ();
539 if ((p = RTFGetReadHook ()) != (RTFFuncPtr) NULL)
540 (*p) (); /* give read hook a look at token */
542 /* Silently discard newlines, carriage returns, nulls. */
543 if (!(rtfClass == rtfText
544 && (rtfMajor == '\n' || rtfMajor == '\r'
545 || rtfMajor == '\0')))
546 break;
548 return (rtfClass);
553 * Install or return a token reader hook.
556 static RTFFuncPtr readHook;
559 void
560 RTFSetReadHook (f)
561 RTFFuncPtr f;
563 readHook = f;
567 RTFFuncPtr
568 RTFGetReadHook ()
570 return (readHook);
574 void
575 RTFUngetToken ()
577 TRACE("\n");
579 if (pushedClass >= 0) /* there's already an ungotten token */
580 RTFPanic ("cannot unget two tokens");
581 if (rtfClass < 0)
582 RTFPanic ("no token to unget");
583 pushedClass = rtfClass;
584 pushedMajor = rtfMajor;
585 pushedMinor = rtfMinor;
586 pushedParam = rtfParam;
587 (void) strcpy (pushedTextBuf, rtfTextBuf);
592 RTFPeekToken ()
594 _RTFGetToken ();
595 RTFUngetToken ();
596 return (rtfClass);
600 static void
601 _RTFGetToken ()
603 RTFFont *fp;
605 TRACE("\n");
607 /* first check for pushed token from RTFUngetToken() */
609 if (pushedClass >= 0)
611 rtfClass = pushedClass;
612 rtfMajor = pushedMajor;
613 rtfMinor = pushedMinor;
614 rtfParam = pushedParam;
615 (void) strcpy (rtfTextBuf, pushedTextBuf);
616 rtfTextLen = strlen (rtfTextBuf);
617 pushedClass = -1;
618 return;
622 * Beyond this point, no token is ever seen twice, which is
623 * important, e.g., for making sure no "}" pops the font stack twice.
626 _RTFGetToken2 ();
627 if (rtfClass == rtfText) /* map RTF char to standard code */
628 rtfMinor = RTFMapChar (rtfMajor);
631 * If auto-charset stuff is activated, see if anything needs doing,
632 * like reading the charset maps or switching between them.
635 if (autoCharSetFlags == 0)
636 return;
638 if ((autoCharSetFlags & rtfReadCharSet)
639 && RTFCheckCM (rtfControl, rtfCharSet))
641 ReadCharSetMaps ();
643 else if ((autoCharSetFlags & rtfSwitchCharSet)
644 && RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum))
646 if ((fp = RTFGetFont (rtfParam)) != (RTFFont *) NULL)
648 if (strncmp (fp->rtfFName, "Symbol", 6) == 0)
649 curCharSet = rtfCSSymbol;
650 else
651 curCharSet = rtfCSGeneral;
652 RTFSetCharSet (curCharSet);
655 else if ((autoCharSetFlags & rtfSwitchCharSet) && rtfClass == rtfGroup)
657 switch (rtfMajor)
659 case rtfBeginGroup:
660 if (csTop >= maxCSStack)
661 RTFPanic ("_RTFGetToken: stack overflow");
662 csStack[csTop++] = curCharSet;
663 break;
664 case rtfEndGroup:
665 if (csTop <= 0)
666 RTFPanic ("_RTFGetToken: stack underflow");
667 curCharSet = csStack[--csTop];
668 RTFSetCharSet (curCharSet);
669 break;
675 /* this shouldn't be called anywhere but from _RTFGetToken() */
677 static void
678 _RTFGetToken2 ()
680 int sign;
681 int c;
683 TRACE("\n");
685 /* initialize token vars */
687 rtfClass = rtfUnknown;
688 rtfParam = rtfNoParam;
689 rtfTextBuf[rtfTextLen = 0] = '\0';
691 /* get first character, which may be a pushback from previous token */
693 if (pushedChar != EOF)
695 c = pushedChar;
696 rtfTextBuf[rtfTextLen++] = c;
697 rtfTextBuf[rtfTextLen] = '\0';
698 pushedChar = EOF;
700 else if ((c = GetChar ()) == EOF)
702 rtfClass = rtfEOF;
703 return;
706 if (c == '{')
708 rtfClass = rtfGroup;
709 rtfMajor = rtfBeginGroup;
710 return;
712 if (c == '}')
714 rtfClass = rtfGroup;
715 rtfMajor = rtfEndGroup;
716 return;
718 if (c != '\\')
721 * Two possibilities here:
722 * 1) ASCII 9, effectively like \tab control symbol
723 * 2) literal text char
725 if (c == '\t') /* ASCII 9 */
727 rtfClass = rtfControl;
728 rtfMajor = rtfSpecialChar;
729 rtfMinor = rtfTab;
731 else
733 rtfClass = rtfText;
734 rtfMajor = c;
736 return;
738 if ((c = GetChar ()) == EOF)
740 /* early eof, whoops (class is rtfUnknown) */
741 return;
743 if (!isalpha (c))
746 * Three possibilities here:
747 * 1) hex encoded text char, e.g., \'d5, \'d3
748 * 2) special escaped text char, e.g., \{, \}
749 * 3) control symbol, e.g., \_, \-, \|, \<10>
751 if (c == '\'') /* hex char */
753 int c2;
755 if ((c = GetChar ()) != EOF && (c2 = GetChar ()) != EOF)
757 /* should do isxdigit check! */
758 rtfClass = rtfText;
759 rtfMajor = RTFCharToHex (c) * 16
760 + RTFCharToHex (c2);
761 return;
763 /* early eof, whoops (class is rtfUnknown) */
764 return;
767 /* escaped char */
768 /*if (index (":{}\\", c) != (char *) NULL)*/ /* escaped char */
769 if (c == ':' || c == '{' || c == '}' || c == '\\')
771 rtfClass = rtfText;
772 rtfMajor = c;
773 return;
776 /* control symbol */
777 Lookup (rtfTextBuf); /* sets class, major, minor */
778 return;
780 /* control word */
781 while (isalpha (c))
783 if ((c = GetChar ()) == EOF)
784 break;
788 * At this point, the control word is all collected, so the
789 * major/minor numbers are determined before the parameter
790 * (if any) is scanned. There will be one too many characters
791 * in the buffer, though, so fix up before and restore after
792 * looking up.
795 if (c != EOF)
796 rtfTextBuf[rtfTextLen-1] = '\0';
797 Lookup (rtfTextBuf); /* sets class, major, minor */
798 if (c != EOF)
799 rtfTextBuf[rtfTextLen-1] = c;
802 * Should be looking at first digit of parameter if there
803 * is one, unless it's negative. In that case, next char
804 * is '-', so need to gobble next char, and remember sign.
807 sign = 1;
808 if (c == '-')
810 sign = -1;
811 c = GetChar ();
813 if (c != EOF && isdigit (c))
815 rtfParam = 0;
816 while (isdigit (c)) /* gobble parameter */
818 rtfParam = rtfParam * 10 + c - '0';
819 if ((c = GetChar ()) == EOF)
820 break;
822 rtfParam *= sign;
825 * If control symbol delimiter was a blank, gobble it.
826 * Otherwise the character is first char of next token, so
827 * push it back for next call. In either case, delete the
828 * delimiter from the token buffer.
830 if (c != EOF)
832 if (c != ' ')
833 pushedChar = c;
834 rtfTextBuf[--rtfTextLen] = '\0';
840 * Read the next character from the input. This handles setting the
841 * current line and position-within-line variables. Those variable are
842 * set correctly whether lines end with CR, LF, or CRLF (the last being
843 * the tricky case).
845 * bumpLine indicates whether the line number should be incremented on
846 * the *next* input character.
850 static int
851 GetChar ()
853 int c;
854 int oldBumpLine;
856 TRACE("\n");
858 if ((c = _RTFGetChar()) != EOF)
860 rtfTextBuf[rtfTextLen++] = c;
861 rtfTextBuf[rtfTextLen] = '\0';
863 if (prevChar == EOF)
864 bumpLine = 1;
865 oldBumpLine = bumpLine; /* non-zero if prev char was line ending */
866 bumpLine = 0;
867 if (c == '\r')
868 bumpLine = 1;
869 else if (c == '\n')
871 bumpLine = 1;
872 if (prevChar == '\r') /* oops, previous \r wasn't */
873 oldBumpLine = 0; /* really a line ending */
875 ++rtfLinePos;
876 if (oldBumpLine) /* were we supposed to increment the */
877 { /* line count on this char? */
878 ++rtfLineNum;
879 rtfLinePos = 1;
881 prevChar = c;
882 return (c);
887 * Synthesize a token by setting the global variables to the
888 * values supplied. Typically this is followed with a call
889 * to RTFRouteToken().
891 * If a param value other than rtfNoParam is passed, it becomes
892 * part of the token text.
895 void
896 RTFSetToken (class, major, minor, param, text)
897 int class, major, minor, param;
898 char *text;
900 TRACE("\n");
902 rtfClass = class;
903 rtfMajor = major;
904 rtfMinor = minor;
905 rtfParam = param;
906 if (param == rtfNoParam)
907 (void) strcpy (rtfTextBuf, text);
908 else
909 sprintf (rtfTextBuf, "%s%d", text, param);
910 rtfTextLen = strlen (rtfTextBuf);
914 /* ---------------------------------------------------------------------- */
917 * Routines to handle mapping of RTF character sets
918 * onto standard characters.
920 * RTFStdCharCode(name) given char name, produce numeric code
921 * RTFStdCharName(code) given char code, return name
922 * RTFMapChar(c) map input (RTF) char code to std code
923 * RTFSetCharSet(id) select given charset map
924 * RTFGetCharSet() get current charset map
926 * See ../h/README for more information about charset names and codes.
931 * Initialize charset stuff.
934 static void
935 CharSetInit ()
937 TRACE("\n");
939 autoCharSetFlags = (rtfReadCharSet | rtfSwitchCharSet);
940 RTFFree (genCharSetFile);
941 genCharSetFile = (char *) NULL;
942 haveGenCharSet = 0;
943 RTFFree (symCharSetFile);
944 symCharSetFile = (char *) NULL;
945 haveSymCharSet = 0;
946 curCharSet = rtfCSGeneral;
947 curCharCode = genCharCode;
952 * Specify the name of a file to be read when auto-charset-file reading is
953 * done.
956 void
957 RTFSetCharSetMap (name, csId)
958 char *name;
959 int csId;
961 TRACE("\n");
963 if ((name = RTFStrSave (name)) == (char *) NULL) /* make copy */
964 RTFPanic ("RTFSetCharSetMap: out of memory");
965 switch (csId)
967 case rtfCSGeneral:
968 RTFFree (genCharSetFile); /* free any previous value */
969 genCharSetFile = name;
970 break;
971 case rtfCSSymbol:
972 RTFFree (symCharSetFile); /* free any previous value */
973 symCharSetFile = name;
974 break;
980 * Do auto-charset-file reading.
981 * will always use the ansi charset no mater what the value
982 * of the rtfTextBuf is.
984 * TODO: add support for other charset in the future.
988 static void
989 ReadCharSetMaps ()
991 char buf[rtfBufSiz];
993 TRACE("\n");
995 if (genCharSetFile != (char *) NULL)
996 (void) strcpy (buf, genCharSetFile);
997 else
998 sprintf (buf, "%s-gen", &rtfTextBuf[1]);
999 if (RTFReadCharSetMap (rtfCSGeneral) == 0)
1000 RTFPanic ("ReadCharSetMaps: Cannot read charset map %s", buf);
1001 if (symCharSetFile != (char *) NULL)
1002 (void) strcpy (buf, symCharSetFile);
1003 else
1004 sprintf (buf, "%s-sym", &rtfTextBuf[1]);
1005 if (RTFReadCharSetMap (rtfCSSymbol) == 0)
1006 RTFPanic ("ReadCharSetMaps: Cannot read charset map %s", buf);
1012 * Convert a CaracterSetMap (caracter_name, caracter) into
1013 * this form : array[caracter_ident] = caracter;
1017 RTFReadCharSetMap (csId)
1018 int csId;
1020 int *stdCodeArray;
1021 int i;
1023 TRACE("\n");
1025 switch (csId)
1027 default:
1028 return (0); /* illegal charset id */
1029 case rtfCSGeneral:
1031 haveGenCharSet = 1;
1032 stdCodeArray = genCharCode;
1033 for (i = 0; i < charSetSize; i++)
1035 stdCodeArray[i] = rtfSC_nothing;
1038 for ( i = 0 ; i< sizeof(ansi_gen)/(sizeof(int));i+=2)
1040 stdCodeArray[ ansi_gen[i+1] ] = ansi_gen[i];
1042 break;
1044 case rtfCSSymbol:
1046 haveSymCharSet = 1;
1047 stdCodeArray = symCharCode;
1048 for (i = 0; i < charSetSize; i++)
1050 stdCodeArray[i] = rtfSC_nothing;
1053 for ( i = 0 ; i< sizeof(ansi_sym)/(sizeof(int));i+=2)
1055 stdCodeArray[ ansi_sym[i+1] ] = ansi_sym[i];
1057 break;
1060 return (1);
1065 * Given a standard character name (a string), find its code (a number).
1066 * Return -1 if name is unknown.
1070 RTFStdCharCode (name)
1071 char *name;
1073 int i;
1075 TRACE("\n");
1077 for (i = 0; i < rtfSC_MaxChar; i++)
1079 if (strcmp (name, stdCharName[i]) == 0)
1080 return (i);
1082 return (-1);
1087 * Given a standard character code (a number), find its name (a string).
1088 * Return NULL if code is unknown.
1091 char *
1092 RTFStdCharName (code)
1093 int code;
1095 if (code < 0 || code >= rtfSC_MaxChar)
1096 return ((char *) NULL);
1097 return (stdCharName[code]);
1102 * Given an RTF input character code, find standard character code.
1103 * The translator should read the appropriate charset maps when it finds a
1104 * charset control. However, the file might not contain one. In this
1105 * case, no map will be available. When the first attempt is made to
1106 * map a character under these circumstances, RTFMapChar() assumes ANSI
1107 * and reads the map as necessary.
1111 RTFMapChar (c)
1112 int c;
1114 TRACE("\n");
1116 switch (curCharSet)
1118 case rtfCSGeneral:
1119 if (!haveGenCharSet)
1121 if (RTFReadCharSetMap (rtfCSGeneral) == 0)
1122 RTFPanic ("RTFMapChar: cannot read ansi-gen");
1124 break;
1125 case rtfCSSymbol:
1126 if (!haveSymCharSet)
1128 if (RTFReadCharSetMap (rtfCSSymbol) == 0)
1129 RTFPanic ("RTFMapChar: cannot read ansi-sym");
1131 break;
1133 if (c < 0 || c >= charSetSize)
1134 return (rtfSC_nothing);
1135 return (curCharCode[c]);
1140 * Set the current character set. If csId is illegal, uses general charset.
1143 void
1144 RTFSetCharSet (csId)
1145 int csId;
1147 TRACE("\n");
1149 switch (csId)
1151 default: /* use general if csId unknown */
1152 case rtfCSGeneral:
1153 curCharCode = genCharCode;
1154 curCharSet = csId;
1155 break;
1156 case rtfCSSymbol:
1157 curCharCode = symCharCode;
1158 curCharSet = csId;
1159 break;
1165 RTFGetCharSet ()
1167 return (curCharSet);
1171 /* ---------------------------------------------------------------------- */
1174 * Special destination readers. They gobble the destination so the
1175 * writer doesn't have to deal with them. That's wrong for any
1176 * translator that wants to process any of these itself. In that
1177 * case, these readers should be overridden by installing a different
1178 * destination callback.
1180 * NOTE: The last token read by each of these reader will be the
1181 * destination's terminating '}', which will then be the current token.
1182 * That '}' token is passed to RTFRouteToken() - the writer has already
1183 * seen the '{' that began the destination group, and may have pushed a
1184 * state; it also needs to know at the end of the group that a state
1185 * should be popped.
1187 * It's important that rtf.h and the control token lookup table list
1188 * as many symbols as possible, because these destination readers
1189 * unfortunately make strict assumptions about the input they expect,
1190 * and a token of class rtfUnknown will throw them off easily.
1195 * Read { \fonttbl ... } destination. Old font tables don't have
1196 * braces around each table entry; try to adjust for that.
1199 static void
1200 ReadFontTbl ()
1202 RTFFont *fp = NULL;
1203 char buf[rtfBufSiz], *bp;
1204 int old = -1;
1205 char *fn = "ReadFontTbl";
1207 TRACE("\n");
1209 for (;;)
1211 (void) RTFGetToken ();
1212 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1213 break;
1214 if (old < 0) /* first entry - determine tbl type */
1216 if (RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum))
1217 old = 1; /* no brace */
1218 else if (RTFCheckCM (rtfGroup, rtfBeginGroup))
1219 old = 0; /* brace */
1220 else /* can't tell! */
1221 RTFPanic ("%s: Cannot determine format", fn);
1223 if (old == 0) /* need to find "{" here */
1225 if (!RTFCheckCM (rtfGroup, rtfBeginGroup))
1226 RTFPanic ("%s: missing \"{\"", fn);
1227 (void) RTFGetToken (); /* yes, skip to next token */
1229 if ((fp = New (RTFFont)) == (RTFFont *) NULL)
1230 RTFPanic ("%s: cannot allocate font entry", fn);
1232 fp->rtfNextFont = fontList;
1233 fontList = fp;
1235 fp->rtfFName = (char *) NULL;
1236 fp->rtfFAltName = (char *) NULL;
1237 fp->rtfFNum = -1;
1238 fp->rtfFFamily = 0;
1239 fp->rtfFCharSet = 0;
1240 fp->rtfFPitch = 0;
1241 fp->rtfFType = 0;
1242 fp->rtfFCodePage = 0;
1244 while (rtfClass != rtfEOF
1245 && !RTFCheckCM (rtfText, ';')
1246 && !RTFCheckCM (rtfGroup, rtfEndGroup))
1248 if (rtfClass == rtfControl)
1250 switch (rtfMajor)
1252 default:
1253 /* ignore token but announce it */
1254 RTFMsg ("%s: unknown token \"%s\"\n",
1255 fn, rtfTextBuf);
1256 case rtfFontFamily:
1257 fp->rtfFFamily = rtfMinor;
1258 break;
1259 case rtfCharAttr:
1260 switch (rtfMinor)
1262 default:
1263 break; /* ignore unknown? */
1264 case rtfFontNum:
1265 fp->rtfFNum = rtfParam;
1266 break;
1268 break;
1269 case rtfFontAttr:
1270 switch (rtfMinor)
1272 default:
1273 break; /* ignore unknown? */
1274 case rtfFontCharSet:
1275 fp->rtfFCharSet = rtfParam;
1276 break;
1277 case rtfFontPitch:
1278 fp->rtfFPitch = rtfParam;
1279 break;
1280 case rtfFontCodePage:
1281 fp->rtfFCodePage = rtfParam;
1282 break;
1283 case rtfFTypeNil:
1284 case rtfFTypeTrueType:
1285 fp->rtfFType = rtfParam;
1286 break;
1288 break;
1291 else if (RTFCheckCM (rtfGroup, rtfBeginGroup)) /* dest */
1293 RTFSkipGroup (); /* ignore for now */
1295 else if (rtfClass == rtfText) /* font name */
1297 bp = buf;
1298 while (rtfClass != rtfEOF
1299 && !RTFCheckCM (rtfText, ';')
1300 && !RTFCheckCM (rtfGroup, rtfEndGroup))
1302 *bp++ = rtfMajor;
1303 (void) RTFGetToken ();
1306 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
1307 if(RTFCheckCM (rtfGroup, rtfEndGroup))
1309 RTFUngetToken ();
1311 *bp = '\0';
1312 fp->rtfFName = RTFStrSave (buf);
1313 if (fp->rtfFName == (char *) NULL)
1314 RTFPanic ("%s: cannot allocate font name", fn);
1315 /* already have next token; don't read one */
1316 /* at bottom of loop */
1317 continue;
1319 else
1321 /* ignore token but announce it */
1322 RTFMsg ("%s: unknown token \"%s\"\n",
1323 fn, rtfTextBuf);
1325 (void) RTFGetToken ();
1327 if (old == 0) /* need to see "}" here */
1329 (void) RTFGetToken ();
1330 if (!RTFCheckCM (rtfGroup, rtfEndGroup))
1331 RTFPanic ("%s: missing \"}\"", fn);
1334 if (fp->rtfFNum == -1)
1335 RTFPanic ("%s: missing font number", fn);
1337 * Could check other pieces of structure here, too, I suppose.
1339 RTFRouteToken (); /* feed "}" back to router */
1344 * The color table entries have color values of -1 if
1345 * the default color should be used for the entry (only
1346 * a semi-colon is given in the definition, no color values).
1347 * There will be a problem if a partial entry (1 or 2 but
1348 * not 3 color values) is given. The possibility is ignored
1349 * here.
1352 static void
1353 ReadColorTbl ()
1355 RTFColor *cp;
1356 int cnum = 0;
1357 char *fn = "ReadColorTbl";
1359 TRACE("\n");
1361 for (;;)
1363 (void) RTFGetToken ();
1364 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1365 break;
1366 if ((cp = New (RTFColor)) == (RTFColor *) NULL)
1367 RTFPanic ("%s: cannot allocate color entry", fn);
1368 cp->rtfCNum = cnum++;
1369 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
1370 cp->rtfNextColor = colorList;
1371 colorList = cp;
1372 while (RTFCheckCM (rtfControl, rtfColorName))
1374 switch (rtfMinor)
1376 case rtfRed: cp->rtfCRed = rtfParam; break;
1377 case rtfGreen: cp->rtfCGreen = rtfParam; break;
1378 case rtfBlue: cp->rtfCBlue = rtfParam; break;
1380 RTFGetToken ();
1382 if (!RTFCheckCM (rtfText, (int) ';'))
1383 RTFPanic ("%s: malformed entry", fn);
1385 RTFRouteToken (); /* feed "}" back to router */
1390 * The "Normal" style definition doesn't contain any style number,
1391 * all others do. Normal style is given style rtfNormalStyleNum.
1394 static void
1395 ReadStyleSheet ()
1397 RTFStyle *sp;
1398 RTFStyleElt *sep, *sepLast;
1399 char buf[rtfBufSiz], *bp;
1400 char *fn = "ReadStyleSheet";
1402 TRACE("\n");
1404 for (;;)
1406 (void) RTFGetToken ();
1407 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1408 break;
1409 if ((sp = New (RTFStyle)) == (RTFStyle *) NULL)
1410 RTFPanic ("%s: cannot allocate stylesheet entry", fn);
1411 sp->rtfSName = (char *) NULL;
1412 sp->rtfSNum = -1;
1413 sp->rtfSType = rtfParStyle;
1414 sp->rtfSAdditive = 0;
1415 sp->rtfSBasedOn = rtfNoStyleNum;
1416 sp->rtfSNextPar = -1;
1417 sp->rtfSSEList = sepLast = (RTFStyleElt *) NULL;
1418 sp->rtfNextStyle = styleList;
1419 sp->rtfExpanding = 0;
1420 styleList = sp;
1421 if (!RTFCheckCM (rtfGroup, rtfBeginGroup))
1422 RTFPanic ("%s: missing \"{\"", fn);
1423 for (;;)
1425 (void) RTFGetToken ();
1426 if (rtfClass == rtfEOF
1427 || RTFCheckCM (rtfText, ';'))
1428 break;
1429 if (rtfClass == rtfControl)
1431 if (RTFCheckMM (rtfSpecialChar, rtfOptDest))
1432 continue; /* ignore "\*" */
1433 if (RTFCheckMM (rtfParAttr, rtfStyleNum))
1435 sp->rtfSNum = rtfParam;
1436 sp->rtfSType = rtfParStyle;
1437 continue;
1439 if (RTFCheckMM (rtfCharAttr, rtfCharStyleNum))
1441 sp->rtfSNum = rtfParam;
1442 sp->rtfSType = rtfCharStyle;
1443 continue;
1445 if (RTFCheckMM (rtfSectAttr, rtfSectStyleNum))
1447 sp->rtfSNum = rtfParam;
1448 sp->rtfSType = rtfSectStyle;
1449 continue;
1451 if (RTFCheckMM (rtfStyleAttr, rtfBasedOn))
1453 sp->rtfSBasedOn = rtfParam;
1454 continue;
1456 if (RTFCheckMM (rtfStyleAttr, rtfAdditive))
1458 sp->rtfSAdditive = 1;
1459 continue;
1461 if (RTFCheckMM (rtfStyleAttr, rtfNext))
1463 sp->rtfSNextPar = rtfParam;
1464 continue;
1466 if ((sep = New (RTFStyleElt)) == (RTFStyleElt *) NULL)
1467 RTFPanic ("%s: cannot allocate style element", fn);
1468 sep->rtfSEClass = rtfClass;
1469 sep->rtfSEMajor = rtfMajor;
1470 sep->rtfSEMinor = rtfMinor;
1471 sep->rtfSEParam = rtfParam;
1472 if ((sep->rtfSEText = RTFStrSave (rtfTextBuf))
1473 == (char *) NULL)
1474 RTFPanic ("%s: cannot allocate style element text", fn);
1475 if (sepLast == (RTFStyleElt *) NULL)
1476 sp->rtfSSEList = sep; /* first element */
1477 else /* add to end */
1478 sepLast->rtfNextSE = sep;
1479 sep->rtfNextSE = (RTFStyleElt *) NULL;
1480 sepLast = sep;
1482 else if (RTFCheckCM (rtfGroup, rtfBeginGroup))
1485 * This passes over "{\*\keycode ... }, among
1486 * other things. A temporary (perhaps) hack.
1488 RTFSkipGroup ();
1489 continue;
1491 else if (rtfClass == rtfText) /* style name */
1493 bp = buf;
1494 while (rtfClass == rtfText)
1496 if (rtfMajor == ';')
1498 /* put back for "for" loop */
1499 (void) RTFUngetToken ();
1500 break;
1502 *bp++ = rtfMajor;
1503 (void) RTFGetToken ();
1505 *bp = '\0';
1506 if ((sp->rtfSName = RTFStrSave (buf)) == (char *) NULL)
1507 RTFPanic ("%s: cannot allocate style name", fn);
1509 else /* unrecognized */
1511 /* ignore token but announce it */
1512 RTFMsg ("%s: unknown token \"%s\"\n",
1513 fn, rtfTextBuf);
1516 (void) RTFGetToken ();
1517 if (!RTFCheckCM (rtfGroup, rtfEndGroup))
1518 RTFPanic ("%s: missing \"}\"", fn);
1521 * Check over the style structure. A name is a must.
1522 * If no style number was specified, check whether it's the
1523 * Normal style (in which case it's given style number
1524 * rtfNormalStyleNum). Note that some "normal" style names
1525 * just begin with "Normal" and can have other stuff following,
1526 * e.g., "Normal,Times 10 point". Ugh.
1528 * Some German RTF writers use "Standard" instead of "Normal".
1530 if (sp->rtfSName == (char *) NULL)
1531 RTFPanic ("%s: missing style name", fn);
1532 if (sp->rtfSNum < 0)
1534 if (strncmp (buf, "Normal", 6) != 0
1535 && strncmp (buf, "Standard", 8) != 0)
1536 RTFPanic ("%s: missing style number", fn);
1537 sp->rtfSNum = rtfNormalStyleNum;
1539 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1540 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1542 RTFRouteToken (); /* feed "}" back to router */
1546 static void
1547 ReadInfoGroup ()
1549 RTFSkipGroup ();
1550 RTFRouteToken (); /* feed "}" back to router */
1554 static void
1555 ReadPictGroup ()
1557 RTFSkipGroup ();
1558 RTFRouteToken (); /* feed "}" back to router */
1562 static void
1563 ReadObjGroup ()
1565 RTFSkipGroup ();
1566 RTFRouteToken (); /* feed "}" back to router */
1570 /* ---------------------------------------------------------------------- */
1573 * Routines to return pieces of stylesheet, or font or color tables.
1574 * References to style 0 are mapped onto the Normal style.
1578 RTFStyle *
1579 RTFGetStyle (num)
1580 int num;
1582 RTFStyle *s;
1584 if (num == -1)
1585 return (styleList);
1586 for (s = styleList; s != (RTFStyle *) NULL; s = s->rtfNextStyle)
1588 if (s->rtfSNum == num)
1589 break;
1591 return (s); /* NULL if not found */
1595 RTFFont *
1596 RTFGetFont (num)
1597 int num;
1599 RTFFont *f;
1601 if (num == -1)
1602 return (fontList);
1603 for (f = fontList; f != (RTFFont *) NULL; f = f->rtfNextFont)
1605 if (f->rtfFNum == num)
1606 break;
1608 return (f); /* NULL if not found */
1612 RTFColor *
1613 RTFGetColor (num)
1614 int num;
1616 RTFColor *c;
1618 if (num == -1)
1619 return (colorList);
1620 for (c = colorList; c != (RTFColor *) NULL; c = c->rtfNextColor)
1622 if (c->rtfCNum == num)
1623 break;
1625 return (c); /* NULL if not found */
1629 /* ---------------------------------------------------------------------- */
1633 * Expand style n, if there is such a style.
1636 void
1637 RTFExpandStyle (n)
1638 int n;
1640 RTFStyle *s;
1641 RTFStyleElt *se;
1643 TRACE("\n");
1645 if (n == -1 || (s = RTFGetStyle (n)) == (RTFStyle *) NULL)
1646 return;
1647 if (s->rtfExpanding != 0)
1648 RTFPanic ("Style expansion loop, style %d", n);
1649 s->rtfExpanding = 1; /* set expansion flag for loop detection */
1651 * Expand "based-on" style (unless it's the same as the current
1652 * style -- Normal style usually gives itself as its own based-on
1653 * style). Based-on style expansion is done by synthesizing
1654 * the token that the writer needs to see in order to trigger
1655 * another style expansion, and feeding to token back through
1656 * the router so the writer sees it.
1658 if (n != s->rtfSBasedOn)
1660 RTFSetToken (rtfControl, rtfParAttr, rtfStyleNum,
1661 s->rtfSBasedOn, "\\s");
1662 RTFRouteToken ();
1665 * Now route the tokens unique to this style. RTFSetToken()
1666 * isn't used because it would add the param value to the end
1667 * of the token text, which already has it in.
1669 for (se = s->rtfSSEList; se != (RTFStyleElt *) NULL; se = se->rtfNextSE)
1671 rtfClass = se->rtfSEClass;
1672 rtfMajor = se->rtfSEMajor;
1673 rtfMinor = se->rtfSEMinor;
1674 rtfParam = se->rtfSEParam;
1675 (void) strcpy (rtfTextBuf, se->rtfSEText);
1676 rtfTextLen = strlen (rtfTextBuf);
1677 RTFRouteToken ();
1679 s->rtfExpanding = 0; /* done - clear expansion flag */
1683 /* ---------------------------------------------------------------------- */
1686 * Control symbol lookup routines
1690 typedef struct RTFKey RTFKey;
1692 struct RTFKey
1694 int rtfKMajor; /* major number */
1695 int rtfKMinor; /* minor number */
1696 char *rtfKStr; /* symbol name */
1697 int rtfKHash; /* symbol name hash value */
1701 * A minor number of -1 means the token has no minor number
1702 * (all valid minor numbers are >= 0).
1705 static RTFKey rtfKey[] =
1708 * Special characters
1711 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1712 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1713 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1714 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1715 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1716 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1717 { rtfSpecialChar, rtfIYear, "yr", 0 },
1718 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1719 { rtfSpecialChar, rtfIDay, "dy", 0 },
1720 { rtfSpecialChar, rtfIHour, "hr", 0 },
1721 { rtfSpecialChar, rtfIMinute, "min", 0 },
1722 { rtfSpecialChar, rtfISecond, "sec", 0 },
1723 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1724 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1725 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1726 { rtfSpecialChar, rtfIIntID, "id", 0 },
1728 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1729 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1730 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1731 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1732 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1733 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1734 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1735 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1736 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1737 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1738 { rtfSpecialChar, rtfCell, "cell", 0 },
1739 { rtfSpecialChar, rtfRow, "row", 0 },
1740 { rtfSpecialChar, rtfPar, "par", 0 },
1741 /* newline and carriage return are synonyms for */
1742 /* \par when they are preceded by a \ character */
1743 { rtfSpecialChar, rtfPar, "\n", 0 },
1744 { rtfSpecialChar, rtfPar, "\r", 0 },
1745 { rtfSpecialChar, rtfSect, "sect", 0 },
1746 { rtfSpecialChar, rtfPage, "page", 0 },
1747 { rtfSpecialChar, rtfColumn, "column", 0 },
1748 { rtfSpecialChar, rtfLine, "line", 0 },
1749 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1750 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1751 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1752 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1753 { rtfSpecialChar, rtfTab, "tab", 0 },
1754 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1755 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1756 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1757 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1758 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1759 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1760 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1761 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1762 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1763 { rtfSpecialChar, rtfFormula, "|", 0 },
1764 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1765 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1766 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1767 { rtfSpecialChar, rtfOptDest, "*", 0 },
1768 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1769 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1770 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1771 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1772 /* is this valid? */
1773 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1776 * Character formatting attributes
1779 { rtfCharAttr, rtfPlain, "plain", 0 },
1780 { rtfCharAttr, rtfBold, "b", 0 },
1781 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1782 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1783 { rtfCharAttr, rtfSubScript, "dn", 0 },
1784 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1785 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1786 { rtfCharAttr, rtfExpand, "expnd", 0 },
1787 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1788 { rtfCharAttr, rtfKerning, "kerning", 0 },
1789 { rtfCharAttr, rtfFontNum, "f", 0 },
1790 { rtfCharAttr, rtfFontSize, "fs", 0 },
1791 { rtfCharAttr, rtfItalic, "i", 0 },
1792 { rtfCharAttr, rtfOutline, "outl", 0 },
1793 { rtfCharAttr, rtfRevised, "revised", 0 },
1794 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1795 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1796 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1797 { rtfCharAttr, rtfShadow, "shad", 0 },
1798 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1799 { rtfCharAttr, rtfUnderline, "ul", 0 },
1800 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1801 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1802 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1803 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1804 { rtfCharAttr, rtfSuperScript, "up", 0 },
1805 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1806 { rtfCharAttr, rtfInvisible, "v", 0 },
1807 { rtfCharAttr, rtfForeColor, "cf", 0 },
1808 { rtfCharAttr, rtfBackColor, "cb", 0 },
1809 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1810 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1811 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1812 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1813 { rtfCharAttr, rtfLanguage, "lang", 0 },
1814 /* this has disappeared from spec 1.2 */
1815 { rtfCharAttr, rtfGray, "gray", 0 },
1818 * Paragraph formatting attributes
1821 { rtfParAttr, rtfParDef, "pard", 0 },
1822 { rtfParAttr, rtfStyleNum, "s", 0 },
1823 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1824 { rtfParAttr, rtfInTable, "intbl", 0 },
1825 { rtfParAttr, rtfKeep, "keep", 0 },
1826 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1827 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1828 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1829 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1830 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1831 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1832 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1833 { rtfParAttr, rtfQuadRight, "qr", 0 },
1834 { rtfParAttr, rtfQuadJust, "qj", 0 },
1835 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1836 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1837 { rtfParAttr, rtfLeftIndent, "li", 0 },
1838 { rtfParAttr, rtfRightIndent, "ri", 0 },
1839 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1840 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1841 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1842 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1844 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1846 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1847 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1849 { rtfParAttr, rtfTabPos, "tx", 0 },
1851 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1852 * although it's not in the spec. It's also redundant, since lj
1853 * tabs are the default.
1855 { rtfParAttr, rtfTabLeft, "tql", 0 },
1856 { rtfParAttr, rtfTabRight, "tqr", 0 },
1857 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1858 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1859 { rtfParAttr, rtfTabBar, "tb", 0 },
1860 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1861 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1862 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1863 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1864 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1866 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1867 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1868 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1869 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1870 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1871 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1872 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1873 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1874 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1875 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1876 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1877 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1878 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1879 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1880 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1881 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1882 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1883 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1884 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1885 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1886 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1887 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1888 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1889 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1890 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1891 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1892 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1893 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1894 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1895 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1896 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1897 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1898 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1899 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1900 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1901 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1903 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1904 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1905 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1906 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1907 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1908 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1909 { rtfParAttr, rtfBorderBox, "box", 0 },
1910 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1911 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1912 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1913 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1914 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1915 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1916 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1917 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1918 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1919 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1921 { rtfParAttr, rtfShading, "shading", 0 },
1922 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1923 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1924 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1925 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1926 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1927 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1928 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1929 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1930 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1931 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1932 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1933 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1934 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1935 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1938 * Section formatting attributes
1941 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1942 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1943 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1944 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1945 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1947 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1948 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1949 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1950 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1951 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1953 { rtfSectAttr, rtfColumns, "cols", 0 },
1954 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1955 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1956 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1957 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1958 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1960 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1961 { rtfSectAttr, rtfLineDist, "linex", 0 },
1962 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1963 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1964 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1965 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1967 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1968 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1969 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1970 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1971 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1972 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1973 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1974 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1975 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1976 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1977 { rtfSectAttr, rtfFooterY, "footery", 0 },
1979 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1980 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1981 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1982 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1983 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1984 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1985 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1986 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1987 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1988 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1989 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1990 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1991 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1992 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1993 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1995 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1996 /* misspelled as "vertal" in specification 1.0 */
1997 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1998 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1999 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
2001 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
2002 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
2004 /* I've seen these in an old spec, but not in real files... */
2005 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
2006 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
2007 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
2008 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
2009 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
2012 * Document formatting attributes
2015 { rtfDocAttr, rtfDefTab, "deftab", 0 },
2016 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
2017 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
2018 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
2019 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
2020 { rtfDocAttr, rtfLineStart, "linestart", 0 },
2021 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
2022 /* \makeback was given in old version of spec, it's now */
2023 /* listed as \makebackup */
2024 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
2025 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
2026 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
2027 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
2028 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
2029 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
2031 { rtfDocAttr, rtfFENoteType, "fet", 0 },
2032 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
2033 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
2034 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
2035 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
2036 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
2037 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
2038 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
2039 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
2040 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
2041 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
2042 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
2043 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
2044 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
2045 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
2046 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
2047 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
2048 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
2049 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
2050 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
2051 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
2052 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
2053 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
2054 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
2055 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
2056 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
2057 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
2058 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
2060 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
2061 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
2062 { rtfDocAttr, rtfPaperSize, "psz", 0 },
2063 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
2064 { rtfDocAttr, rtfRightMargin, "margr", 0 },
2065 { rtfDocAttr, rtfTopMargin, "margt", 0 },
2066 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
2067 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
2068 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
2069 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
2070 { rtfDocAttr, rtfLandscape, "landscape", 0 },
2071 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
2072 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
2074 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
2076 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
2077 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
2078 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
2079 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
2080 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
2081 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
2082 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
2083 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
2084 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
2085 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
2086 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
2087 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
2089 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
2090 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
2091 { rtfDocAttr, rtfFormShading, "formshade", 0 },
2092 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
2093 { rtfDocAttr, rtfPrintData, "printdata", 0 },
2095 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
2096 { rtfDocAttr, rtfRevisions, "revisions", 0 },
2097 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
2098 { rtfDocAttr, rtfRevBar, "revbar", 0 },
2100 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
2102 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
2103 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
2106 * Style attributes
2109 { rtfStyleAttr, rtfAdditive, "additive", 0 },
2110 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
2111 { rtfStyleAttr, rtfNext, "snext", 0 },
2114 * Picture attributes
2117 { rtfPictAttr, rtfMacQD, "macpict", 0 },
2118 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
2119 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
2120 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
2121 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
2122 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
2123 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
2124 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
2126 { rtfPictAttr, rtfPicWid, "picw", 0 },
2127 { rtfPictAttr, rtfPicHt, "pich", 0 },
2128 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
2129 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
2130 /* these two aren't in the spec, but some writers emit them */
2131 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
2132 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
2133 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
2134 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
2135 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
2136 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
2137 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
2138 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
2139 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
2141 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
2142 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
2144 { rtfPictAttr, rtfPicBinary, "bin", 0 },
2147 * NeXT graphic attributes
2150 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
2151 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
2154 * Destinations
2157 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
2158 { rtfDestination, rtfFontAltName, "falt", 0 },
2159 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
2160 { rtfDestination, rtfFontFile, "fontfile", 0 },
2161 { rtfDestination, rtfFileTbl, "filetbl", 0 },
2162 { rtfDestination, rtfFileInfo, "file", 0 },
2163 { rtfDestination, rtfColorTbl, "colortbl", 0 },
2164 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
2165 { rtfDestination, rtfKeyCode, "keycode", 0 },
2166 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
2167 { rtfDestination, rtfInfo, "info", 0 },
2168 { rtfDestination, rtfITitle, "title", 0 },
2169 { rtfDestination, rtfISubject, "subject", 0 },
2170 { rtfDestination, rtfIAuthor, "author", 0 },
2171 { rtfDestination, rtfIOperator, "operator", 0 },
2172 { rtfDestination, rtfIKeywords, "keywords", 0 },
2173 { rtfDestination, rtfIComment, "comment", 0 },
2174 { rtfDestination, rtfIVersion, "version", 0 },
2175 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
2176 /* \verscomm may not exist -- was seen in earlier spec version */
2177 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
2178 { rtfDestination, rtfNextFile, "nextfile", 0 },
2179 { rtfDestination, rtfTemplate, "template", 0 },
2180 { rtfDestination, rtfFNSep, "ftnsep", 0 },
2181 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
2182 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
2183 { rtfDestination, rtfENSep, "aftnsep", 0 },
2184 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
2185 { rtfDestination, rtfENContNotice, "aftncn", 0 },
2186 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
2187 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
2188 { rtfDestination, rtfHeader, "header", 0 },
2189 { rtfDestination, rtfFooter, "footer", 0 },
2190 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
2191 { rtfDestination, rtfHeaderRight, "headerr", 0 },
2192 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
2193 { rtfDestination, rtfFooterLeft, "footerl", 0 },
2194 { rtfDestination, rtfFooterRight, "footerr", 0 },
2195 { rtfDestination, rtfFooterFirst, "footerf", 0 },
2196 { rtfDestination, rtfParNumText, "pntext", 0 },
2197 { rtfDestination, rtfParNumbering, "pn", 0 },
2198 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
2199 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
2200 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
2201 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
2202 { rtfDestination, rtfPict, "pict", 0 },
2203 { rtfDestination, rtfObject, "object", 0 },
2204 { rtfDestination, rtfObjClass, "objclass", 0 },
2205 { rtfDestination, rtfObjName, "objname", 0 },
2206 { rtfObjAttr, rtfObjTime, "objtime", 0 },
2207 { rtfDestination, rtfObjData, "objdata", 0 },
2208 { rtfDestination, rtfObjAlias, "objalias", 0 },
2209 { rtfDestination, rtfObjSection, "objsect", 0 },
2210 /* objitem and objtopic aren't documented in the spec! */
2211 { rtfDestination, rtfObjItem, "objitem", 0 },
2212 { rtfDestination, rtfObjTopic, "objtopic", 0 },
2213 { rtfDestination, rtfObjResult, "result", 0 },
2214 { rtfDestination, rtfDrawObject, "do", 0 },
2215 { rtfDestination, rtfFootnote, "footnote", 0 },
2216 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
2217 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
2218 { rtfDestination, rtfAnnotID, "atnid", 0 },
2219 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
2220 { rtfDestination, rtfAnnotation, "annotation", 0 },
2221 { rtfDestination, rtfAnnotRef, "atnref", 0 },
2222 { rtfDestination, rtfAnnotTime, "atntime", 0 },
2223 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
2224 { rtfDestination, rtfField, "field", 0 },
2225 { rtfDestination, rtfFieldInst, "fldinst", 0 },
2226 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
2227 { rtfDestination, rtfDataField, "datafield", 0 },
2228 { rtfDestination, rtfIndex, "xe", 0 },
2229 { rtfDestination, rtfIndexText, "txe", 0 },
2230 { rtfDestination, rtfIndexRange, "rxe", 0 },
2231 { rtfDestination, rtfTOC, "tc", 0 },
2232 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
2235 * Font families
2238 { rtfFontFamily, rtfFFNil, "fnil", 0 },
2239 { rtfFontFamily, rtfFFRoman, "froman", 0 },
2240 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
2241 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
2242 { rtfFontFamily, rtfFFScript, "fscript", 0 },
2243 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
2244 { rtfFontFamily, rtfFFTech, "ftech", 0 },
2245 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
2248 * Font attributes
2251 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
2252 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
2253 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
2254 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
2255 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
2258 * File table attributes
2261 { rtfFileAttr, rtfFileNum, "fid", 0 },
2262 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
2263 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
2266 * File sources
2269 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
2270 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
2271 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
2272 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
2273 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
2276 * Color names
2279 { rtfColorName, rtfRed, "red", 0 },
2280 { rtfColorName, rtfGreen, "green", 0 },
2281 { rtfColorName, rtfBlue, "blue", 0 },
2284 * Charset names
2287 { rtfCharSet, rtfMacCharSet, "mac", 0 },
2288 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
2289 { rtfCharSet, rtfPcCharSet, "pc", 0 },
2290 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
2293 * Table attributes
2296 { rtfTblAttr, rtfRowDef, "trowd", 0 },
2297 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
2298 { rtfTblAttr, rtfCellPos, "cellx", 0 },
2299 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
2300 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
2302 { rtfTblAttr, rtfRowLeft, "trql", 0 },
2303 { rtfTblAttr, rtfRowRight, "trqr", 0 },
2304 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
2305 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
2306 { rtfTblAttr, rtfRowHt, "trrh", 0 },
2307 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
2308 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
2310 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
2311 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
2313 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
2314 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
2315 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
2316 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
2317 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
2318 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
2320 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
2321 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
2322 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
2323 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
2325 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
2326 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
2327 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
2328 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
2329 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
2330 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
2331 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
2333 * The spec lists "clbgdkhor", but the corresponding non-cell
2334 * control is "bgdkhoriz". At any rate Macintosh Word seems
2335 * to accept both "clbgdkhor" and "clbgdkhoriz".
2337 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
2338 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
2339 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
2340 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
2341 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
2342 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
2343 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
2344 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
2345 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
2348 * Field attributes
2351 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
2352 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
2353 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
2354 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
2355 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
2358 * Positioning attributes
2361 { rtfPosAttr, rtfAbsWid, "absw", 0 },
2362 { rtfPosAttr, rtfAbsHt, "absh", 0 },
2364 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
2365 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
2366 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
2367 { rtfPosAttr, rtfPosX, "posx", 0 },
2368 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
2369 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
2370 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
2371 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
2372 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
2373 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
2375 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
2376 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
2377 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
2378 { rtfPosAttr, rtfPosY, "posy", 0 },
2379 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
2380 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
2381 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
2382 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
2383 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
2385 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
2386 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
2387 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
2388 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
2389 /* \dyfrtext no longer exists in spec 1.2, apparently */
2390 /* replaced by \dfrmtextx and \dfrmtexty. */
2391 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
2393 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
2394 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
2397 * Object controls
2400 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
2401 { rtfObjAttr, rtfObjLink, "objlink", 0 },
2402 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
2403 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
2404 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
2405 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
2407 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
2408 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
2409 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
2411 { rtfObjAttr, rtfObjHt, "objh", 0 },
2412 { rtfObjAttr, rtfObjWid, "objw", 0 },
2413 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
2414 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
2415 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
2416 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
2417 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
2418 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
2419 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
2420 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
2421 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2423 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2424 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2425 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2426 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2427 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2429 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2430 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2433 * Associated character formatting attributes
2436 { rtfACharAttr, rtfACBold, "ab", 0 },
2437 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2438 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2439 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2440 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2441 { rtfACharAttr, rtfACFontNum, "af", 0 },
2442 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2443 { rtfACharAttr, rtfACItalic, "ai", 0 },
2444 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2445 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2446 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2447 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2448 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2449 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2450 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2451 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2452 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2453 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2454 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2457 * Footnote attributes
2460 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2463 * Key code attributes
2466 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2467 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2468 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2469 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2472 * Bookmark attributes
2475 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2476 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2479 * Index entry attributes
2482 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2483 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2484 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2487 * Table of contents attributes
2490 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2491 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2494 * Drawing object attributes
2497 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2498 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2499 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2500 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2501 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2502 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2503 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2504 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2506 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2507 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2508 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2509 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2510 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2511 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2512 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2513 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2514 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2515 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2516 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2518 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2519 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2520 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2521 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2523 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2524 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2525 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2526 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2527 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2528 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2529 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2530 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2531 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2532 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2533 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2534 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2535 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2536 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2537 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2538 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2539 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2541 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2542 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2543 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2545 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2546 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2547 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2549 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2550 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2552 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2553 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2554 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2555 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2556 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2557 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2558 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2559 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2560 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2561 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2562 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2563 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2565 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2566 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2567 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2568 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2569 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2570 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2571 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2572 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2574 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2575 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2576 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2577 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2578 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2579 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2580 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2581 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2582 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2583 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2584 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2586 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2587 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2588 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2590 { rtfVersion, -1, "rtf", 0 },
2591 { rtfDefFont, -1, "deff", 0 },
2593 { 0, -1, (char *) NULL, 0 }
2598 * Initialize lookup table hash values. Only need to do this once.
2601 static void
2602 LookupInit ()
2604 static int inited = 0;
2605 RTFKey *rp;
2607 if (inited == 0)
2609 for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
2610 rp->rtfKHash = Hash (rp->rtfKStr);
2611 ++inited;
2617 * Determine major and minor number of control token. If it's
2618 * not found, the class turns into rtfUnknown.
2621 static void
2622 Lookup (s)
2623 char *s;
2625 RTFKey *rp;
2626 int hash;
2628 TRACE("\n");
2629 ++s; /* skip over the leading \ character */
2630 hash = Hash (s);
2631 for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
2633 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2635 rtfClass = rtfControl;
2636 rtfMajor = rp->rtfKMajor;
2637 rtfMinor = rp->rtfKMinor;
2638 return;
2641 rtfClass = rtfUnknown;
2646 * Compute hash value of symbol
2649 static int
2650 Hash (s)
2651 char *s;
2653 char c;
2654 int val = 0;
2656 while ((c = *s++) != '\0')
2657 val += (int) c;
2658 return (val);
2662 /* ---------------------------------------------------------------------- */
2665 * Memory allocation routines
2670 * Return pointer to block of size bytes, or NULL if there's
2671 * not enough memory available.
2673 * This is called through RTFAlloc(), a define which coerces the
2674 * argument to int. This avoids the persistent problem of allocation
2675 * failing under THINK C when a long is passed.
2678 char *
2679 _RTFAlloc (size)
2680 int size;
2682 return HeapAlloc(RICHED32_hHeap, 0, size);
2687 * Saves a string on the heap and returns a pointer to it.
2691 char *
2692 RTFStrSave (s)
2693 char *s;
2695 char *p;
2697 if ((p = RTFAlloc ((int) (strlen (s) + 1))) == (char *) NULL)
2698 return ((char *) NULL);
2699 return (strcpy (p, s));
2703 void
2704 RTFFree (p)
2705 char *p;
2707 if (p != (char *) NULL)
2708 HeapFree(RICHED32_hHeap, 0, p);
2712 /* ---------------------------------------------------------------------- */
2716 * Token comparison routines
2720 RTFCheckCM (class, major)
2721 int class, major;
2723 return (rtfClass == class && rtfMajor == major);
2728 RTFCheckCMM (class, major, minor)
2729 int class, major, minor;
2731 return (rtfClass == class && rtfMajor == major && rtfMinor == minor);
2736 RTFCheckMM (major, minor)
2737 int major, minor;
2739 return (rtfMajor == major && rtfMinor == minor);
2743 /* ---------------------------------------------------------------------- */
2747 RTFCharToHex (c)
2748 char c;
2750 if (isupper (c))
2751 c = tolower (c);
2752 if (isdigit (c))
2753 return (c - '0'); /* '0'..'9' */
2754 return (c - 'a' + 10); /* 'a'..'f' */
2759 RTFHexToChar (i)
2760 int i;
2762 if (i < 10)
2763 return (i + '0');
2764 return (i - 10 + 'a');
2768 /* ---------------------------------------------------------------------- */
2771 * RTFReadOutputMap() -- Read output translation map
2775 * Read in an array describing the relation between the standard character set
2776 * and an RTF translator's corresponding output sequences. Each line consists
2777 * of a standard character name and the output sequence for that character.
2779 * outMap is an array of strings into which the sequences should be placed.
2780 * It should be declared like this in the calling program:
2782 * char *outMap[rtfSC_MaxChar];
2784 * reinit should be non-zero if outMap should be initialized
2785 * zero otherwise.
2790 RTFReadOutputMap (outMap, reinit)
2791 char *outMap[];
2792 int reinit;
2794 int i;
2795 int stdCode;
2796 char *name, *seq;
2798 if (reinit)
2800 for (i = 0; i < rtfSC_MaxChar; i++)
2802 outMap[i] = (char *) NULL;
2806 for (i=0 ;i< sizeof(text_map)/sizeof(char*); i+=2)
2808 name = text_map[i];
2809 seq = text_map[i+1];
2810 stdCode = RTFStdCharCode( name );
2811 outMap[stdCode] = seq;
2814 return (1);
2817 /* ---------------------------------------------------------------------- */
2820 * Open a library file.
2824 static FILE *(*libFileOpen) () = NULL;
2828 void
2829 RTFSetOpenLibFileProc (proc)
2830 FILE *(*proc) ();
2832 libFileOpen = proc;
2836 FILE *
2837 RTFOpenLibFile (file, mode)
2838 char *file;
2839 char *mode;
2841 if (libFileOpen == NULL)
2842 return ((FILE *) NULL);
2843 return ((*libFileOpen) (file, mode));
2847 /* ---------------------------------------------------------------------- */
2850 * Print message. Default is to send message to stderr
2851 * but this may be overridden with RTFSetMsgProc().
2853 * Message should include linefeeds as necessary. If the default
2854 * function is overridden, the overriding function may want to
2855 * map linefeeds to another line ending character or sequence if
2856 * the host system doesn't use linefeeds.
2860 static void
2861 DefaultMsgProc (s)
2862 char *s;
2864 MESSAGE( "%s", s);
2868 static RTFFuncPtr msgProc = DefaultMsgProc;
2871 void
2872 RTFSetMsgProc (proc)
2873 RTFFuncPtr proc;
2875 msgProc = proc;
2879 # ifdef STDARG
2882 * This version is for systems with stdarg
2885 void
2886 RTFMsg (char *fmt, ...)
2888 char buf[rtfBufSiz];
2890 va_list args;
2891 va_start (args,fmt);
2892 vsprintf (buf, fmt, args);
2893 va_end (args);
2894 (*msgProc) (buf);
2897 # else /* !STDARG */
2899 # ifdef VARARGS
2903 * This version is for systems that have varargs.
2906 void
2907 RTFMsg (va_alist)
2908 va_dcl
2910 va_list args;
2911 char *fmt;
2912 char buf[rtfBufSiz];
2914 va_start (args);
2915 fmt = va_arg (args, char *);
2916 vsprintf (buf, fmt, args);
2917 va_end (args);
2918 (*msgProc) (buf);
2921 # else /* !VARARGS */
2924 * This version is for systems that don't have varargs.
2927 void
2928 RTFMsg (fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9)
2929 char *fmt;
2930 char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8, *a9;
2932 char buf[rtfBufSiz];
2934 sprintf (buf, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9);
2935 (*msgProc) (buf);
2938 # endif /* !VARARGS */
2939 # endif /* !STDARG */
2942 /* ---------------------------------------------------------------------- */
2946 * Process termination. Print error message and exit. Also prints
2947 * current token, and current input line number and position within
2948 * line if any input has been read from the current file. (No input
2949 * has been read if prevChar is EOF).
2952 static void
2953 DefaultPanicProc (s)
2954 char *s;
2956 MESSAGE( "%s", s);
2957 /*exit (1);*/
2961 static RTFFuncPtr panicProc = DefaultPanicProc;
2964 void
2965 RTFSetPanicProc (proc)
2966 RTFFuncPtr proc;
2968 panicProc = proc;
2972 # ifdef STDARG
2975 * This version is for systems with stdarg
2978 void
2979 RTFPanic (char *fmt, ...)
2981 char buf[rtfBufSiz];
2983 va_list args;
2984 va_start (args,fmt);
2985 vsprintf (buf, fmt, args);
2986 va_end (args);
2987 (void) strcat (buf, "\n");
2988 if (prevChar != EOF && rtfTextBuf != (char *) NULL)
2990 sprintf (buf + strlen (buf),
2991 "Last token read was \"%s\" near line %ld, position %d.\n",
2992 rtfTextBuf, rtfLineNum, rtfLinePos);
2994 (*panicProc) (buf);
2997 # else /* !STDARG */
2999 # ifdef VARARGS
3003 * This version is for systems that have varargs.
3006 void
3007 RTFPanic (va_alist)
3008 va_dcl
3010 va_list args;
3011 char *fmt;
3012 char buf[rtfBufSiz];
3014 va_start (args);
3015 fmt = va_arg (args, char *);
3016 vsprintf (buf, fmt, args);
3017 va_end (args);
3018 (void) strcat (buf, "\n");
3019 if (prevChar != EOF && rtfTextBuf != (char *) NULL)
3021 sprintf (buf + strlen (buf),
3022 "Last token read was \"%s\" near line %ld, position %d.\n",
3023 rtfTextBuf, rtfLineNum, rtfLinePos);
3025 (*panicProc) (buf);
3028 # else /* !VARARGS */
3031 * This version is for systems that don't have varargs.
3034 void
3035 RTFPanic (fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9)
3036 char *fmt;
3037 char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8, *a9;
3039 char buf[rtfBufSiz];
3041 sprintf (buf, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9);
3042 (void) strcat (buf, "\n");
3043 if (prevChar != EOF && rtfTextBuf != (char *) NULL)
3045 sprintf (buf + strlen (buf),
3046 "Last token read was \"%s\" near line %ld, position %d.\n",
3047 rtfTextBuf, rtfLineNum, rtfLinePos);
3049 (*panicProc) (buf);
3052 # endif /* !VARARGS */
3053 # endif /* !STDARG */