Porting fixes.
[wine/wine64.git] / dlls / richedit / reader.c
blob13e98c83e22ffc52d1f93ea0c347e8642b80d77c
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 # include <stdio.h>
48 # include <ctype.h>
49 # include <string.h>
50 # include <stdarg.h>
52 # include "rtf.h"
55 * include hard coded charsets
58 #include "ansi_gen.h"
59 #include "ansi_sym.h"
60 #include "text_map.h"
62 #include <stdlib.h>
64 #include "charlist.h"
65 #include "windef.h"
66 #include "winbase.h"
67 #include "wine/debug.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
71 extern HANDLE RICHED32_hHeap;
74 * Return pointer to new element of type t, or NULL
75 * if no memory available.
78 # define New(t) ((t *) RTFAlloc ((int) sizeof (t)))
80 /* maximum number of character values representable in a byte */
82 # define charSetSize 256
84 /* charset stack size */
86 # define maxCSStack 10
88 static int _RTFGetChar();
89 static void _RTFGetToken ();
90 static void _RTFGetToken2 ();
91 static int GetChar ();
92 static void ReadFontTbl ();
93 static void ReadColorTbl ();
94 static void ReadStyleSheet ();
95 static void ReadInfoGroup ();
96 static void ReadPictGroup ();
97 static void ReadObjGroup ();
98 static void LookupInit ();
99 static void Lookup ();
100 static int Hash ();
102 static void CharSetInit ();
103 static void ReadCharSetMaps ();
107 * Public variables (listed in rtf.h)
110 int rtfClass;
111 int rtfMajor;
112 int rtfMinor;
113 int rtfParam;
114 int rtfFormat;
115 char *rtfTextBuf = (char *) NULL;
116 int rtfTextLen;
118 long rtfLineNum;
119 int rtfLinePos;
123 * Private stuff
126 static int pushedChar; /* pushback char if read too far */
128 static int pushedClass; /* pushed token info for RTFUngetToken() */
129 static int pushedMajor;
130 static int pushedMinor;
131 static int pushedParam;
132 static char *pushedTextBuf = (char *) NULL;
134 static int prevChar;
135 static int bumpLine;
137 static RTFFont *fontList = (RTFFont *) NULL; /* these lists MUST be */
138 static RTFColor *colorList = (RTFColor *) NULL; /* initialized to NULL */
139 static RTFStyle *styleList = (RTFStyle *) NULL;
141 static char *inputName = (char *) NULL;
142 static char *outputName = (char *) NULL;
144 static EDITSTREAM editstream;
145 static CHARLIST inputCharList = {0, NULL, NULL};
148 * This array is used to map standard character names onto their numeric codes.
149 * The position of the name within the array is the code.
150 * stdcharnames.h is generated in the ../h directory.
153 #include "stdcharnames.h"
156 * These arrays are used to map RTF input character values onto the standard
157 * character names represented by the values. Input character values are
158 * used as indices into the arrays to produce standard character codes.
162 static char *genCharSetFile = (char *) NULL;
163 static int genCharCode[charSetSize]; /* general */
164 static int haveGenCharSet = 0;
166 static char *symCharSetFile = (char *) NULL;
167 static int symCharCode[charSetSize]; /* symbol */
168 static int haveSymCharSet = 0;
170 static int curCharSet = rtfCSGeneral;
171 static int *curCharCode = genCharCode;
174 * By default, the reader is configured to handle charset mapping invisibly,
175 * including reading the charset files and switching charset maps as necessary
176 * for Symbol font.
179 static int autoCharSetFlags;
182 * Stack for keeping track of charset map on group begin/end. This is
183 * necessary because group termination reverts the font to the previous
184 * value, which may implicitly change it.
187 static int csStack[maxCSStack];
188 static int csTop = 0;
191 * Get a char from the charlist. The charlist is used to store characters
192 * from the editstream.
196 int _RTFGetChar(void)
198 char myChar;
200 TRACE("\n");
202 if(CHARLIST_GetNbItems(&inputCharList) == 0)
204 char buff[10];
205 long pcb;
206 editstream.pfnCallback(editstream.dwCookie, buff, 1, &pcb);
207 if(pcb == 0)
208 return EOF;
209 else
210 CHARLIST_Enqueue(&inputCharList, buff[0]);
212 myChar = CHARLIST_Dequeue(&inputCharList);
213 return (int) myChar;
216 void RTFSetEditStream(EDITSTREAM *es)
218 TRACE("\n");
220 editstream.dwCookie = es->dwCookie;
221 editstream.dwError = es->dwError;
222 editstream.pfnCallback = es->pfnCallback;
226 * Initialize the reader. This may be called multiple times,
227 * to read multiple files. The only thing not reset is the input
228 * stream; that must be done with RTFSetStream().
231 void RTFInit(void)
233 int i;
234 RTFColor *cp;
235 RTFFont *fp;
236 RTFStyle *sp;
237 RTFStyleElt *eltList, *ep;
239 TRACE("\n");
241 if (rtfTextBuf == (char *) NULL) /* initialize the text buffers */
243 rtfTextBuf = RTFAlloc (rtfBufSiz);
244 pushedTextBuf = RTFAlloc (rtfBufSiz);
245 if (rtfTextBuf == (char *) NULL
246 || pushedTextBuf == (char *) NULL)
247 RTFPanic ("Cannot allocate text buffers.");
248 rtfTextBuf[0] = pushedTextBuf[0] = '\0';
251 RTFFree (inputName);
252 RTFFree (outputName);
253 inputName = outputName = (char *) NULL;
255 /* initialize lookup table */
256 LookupInit ();
258 for (i = 0; i < rtfMaxClass; i++)
259 RTFSetClassCallback (i, (RTFFuncPtr) NULL);
260 for (i = 0; i < rtfMaxDestination; i++)
261 RTFSetDestinationCallback (i, (RTFFuncPtr) NULL);
263 /* install built-in destination readers */
264 RTFSetDestinationCallback (rtfFontTbl, ReadFontTbl);
265 RTFSetDestinationCallback (rtfColorTbl, ReadColorTbl);
266 RTFSetDestinationCallback (rtfStyleSheet, ReadStyleSheet);
267 RTFSetDestinationCallback (rtfInfo, ReadInfoGroup);
268 RTFSetDestinationCallback (rtfPict, ReadPictGroup);
269 RTFSetDestinationCallback (rtfObject, ReadObjGroup);
272 RTFSetReadHook ((RTFFuncPtr) NULL);
274 /* dump old lists if necessary */
276 while (fontList != (RTFFont *) NULL)
278 fp = fontList->rtfNextFont;
279 RTFFree (fontList->rtfFName);
280 RTFFree ((char *) fontList);
281 fontList = fp;
283 while (colorList != (RTFColor *) NULL)
285 cp = colorList->rtfNextColor;
286 RTFFree ((char *) colorList);
287 colorList = cp;
289 while (styleList != (RTFStyle *) NULL)
291 sp = styleList->rtfNextStyle;
292 eltList = styleList->rtfSSEList;
293 while (eltList != (RTFStyleElt *) NULL)
295 ep = eltList->rtfNextSE;
296 RTFFree (eltList->rtfSEText);
297 RTFFree ((char *) eltList);
298 eltList = ep;
300 RTFFree (styleList->rtfSName);
301 RTFFree ((char *) styleList);
302 styleList = sp;
305 rtfClass = -1;
306 pushedClass = -1;
307 pushedChar = EOF;
309 rtfLineNum = 0;
310 rtfLinePos = 0;
311 prevChar = EOF;
312 bumpLine = 0;
314 CharSetInit ();
315 csTop = 0;
319 * Set or get the input or output file name. These are never guaranteed
320 * to be accurate, only insofar as the calling program makes them so.
323 void RTFSetInputName(char *name)
325 TRACE("\n");
327 if ((inputName = RTFStrSave (name)) == (char *) NULL)
328 RTFPanic ("RTFSetInputName: out of memory");
332 char *RTFGetInputName(void)
334 return (inputName);
338 void RTFSetOutputName(char *name)
340 TRACE("\n");
342 if ((outputName = RTFStrSave (name)) == (char *) NULL)
343 RTFPanic ("RTFSetOutputName: out of memory");
347 char *RTFGetOutputName(void)
349 return (outputName);
354 /* ---------------------------------------------------------------------- */
357 * Callback table manipulation routines
362 * Install or return a writer callback for a token class
366 static RTFFuncPtr ccb[rtfMaxClass]; /* class callbacks */
369 void RTFSetClassCallback(int class, RTFFuncPtr callback)
371 if (class >= 0 && class < rtfMaxClass)
372 ccb[class] = callback;
376 RTFFuncPtr RTFGetClassCallback(int class)
378 if (class >= 0 && class < rtfMaxClass)
379 return (ccb[class]);
380 return ((RTFFuncPtr) NULL);
385 * Install or return a writer callback for a destination type
388 static RTFFuncPtr dcb[rtfMaxDestination]; /* destination callbacks */
391 void RTFSetDestinationCallback(int dest, RTFFuncPtr callback)
393 if (dest >= 0 && dest < rtfMaxDestination)
394 dcb[dest] = callback;
398 RTFFuncPtr RTFGetDestinationCallback(int dest)
400 if (dest >= 0 && dest < rtfMaxDestination)
401 return (dcb[dest]);
402 return ((RTFFuncPtr) NULL);
406 /* ---------------------------------------------------------------------- */
409 * Token reading routines
414 * Read the input stream, invoking the writer's callbacks
415 * where appropriate.
418 void RTFRead(void)
420 while (RTFGetToken () != rtfEOF)
421 RTFRouteToken ();
426 * Route a token. If it's a destination for which a reader is
427 * installed, process the destination internally, otherwise
428 * pass the token to the writer's class callback.
431 void RTFRouteToken(void)
433 RTFFuncPtr p;
435 TRACE("\n");
437 if (rtfClass < 0 || rtfClass >= rtfMaxClass) /* watchdog */
439 RTFPanic ("Unknown class %d: %s (reader malfunction)",
440 rtfClass, rtfTextBuf);
442 if (RTFCheckCM (rtfControl, rtfDestination))
444 /* invoke destination-specific callback if there is one */
445 if ((p = RTFGetDestinationCallback (rtfMinor))
446 != (RTFFuncPtr) NULL)
448 (*p) ();
449 return;
452 /* invoke class callback if there is one */
453 if ((p = RTFGetClassCallback (rtfClass)) != (RTFFuncPtr) NULL)
454 (*p) ();
459 * Skip to the end of the current group. When this returns,
460 * writers that maintain a state stack may want to call their
461 * state unstacker; global vars will still be set to the group's
462 * closing brace.
465 void RTFSkipGroup(void)
467 int level = 1;
468 TRACE("\n");
470 while (RTFGetToken () != rtfEOF)
472 if (rtfClass == rtfGroup)
474 if (rtfMajor == rtfBeginGroup)
475 ++level;
476 else if (rtfMajor == rtfEndGroup)
478 if (--level < 1)
479 break; /* end of initial group */
487 * Read one token. Call the read hook if there is one. The
488 * token class is the return value. Returns rtfEOF when there
489 * are no more tokens.
492 int RTFGetToken(void)
494 RTFFuncPtr p;
495 TRACE("\n");
497 for (;;)
499 _RTFGetToken ();
500 if ((p = RTFGetReadHook ()) != (RTFFuncPtr) NULL)
501 (*p) (); /* give read hook a look at token */
503 /* Silently discard newlines, carriage returns, nulls. */
504 if (!(rtfClass == rtfText && rtfFormat != SF_TEXT
505 && (rtfMajor == '\r' || rtfMajor == '\n' || rtfMajor == '\0')))
506 break;
508 return (rtfClass);
513 * Install or return a token reader hook.
516 static RTFFuncPtr readHook;
519 void RTFSetReadHook(RTFFuncPtr f)
521 readHook = f;
525 RTFFuncPtr RTFGetReadHook(void)
527 return (readHook);
531 void RTFUngetToken(void)
533 TRACE("\n");
535 if (pushedClass >= 0) /* there's already an ungotten token */
536 RTFPanic ("cannot unget two tokens");
537 if (rtfClass < 0)
538 RTFPanic ("no token to unget");
539 pushedClass = rtfClass;
540 pushedMajor = rtfMajor;
541 pushedMinor = rtfMinor;
542 pushedParam = rtfParam;
543 (void) strcpy (pushedTextBuf, rtfTextBuf);
547 int RTFPeekToken(void)
549 _RTFGetToken ();
550 RTFUngetToken ();
551 return (rtfClass);
555 static void _RTFGetToken(void)
557 RTFFont *fp;
559 TRACE("\n");
561 if (rtfFormat == SF_TEXT) {
562 rtfMajor = GetChar ();
563 rtfMinor = rtfSC_nothing;
564 rtfParam = rtfNoParam;
565 rtfTextBuf[rtfTextLen = 0] = '\0';
566 if (rtfMajor == EOF)
567 rtfClass = rtfEOF;
568 else
569 rtfClass = rtfText;
570 return;
573 /* first check for pushed token from RTFUngetToken() */
575 if (pushedClass >= 0)
577 rtfClass = pushedClass;
578 rtfMajor = pushedMajor;
579 rtfMinor = pushedMinor;
580 rtfParam = pushedParam;
581 (void) strcpy (rtfTextBuf, pushedTextBuf);
582 rtfTextLen = strlen (rtfTextBuf);
583 pushedClass = -1;
584 return;
588 * Beyond this point, no token is ever seen twice, which is
589 * important, e.g., for making sure no "}" pops the font stack twice.
592 _RTFGetToken2 ();
593 if (rtfClass == rtfText) /* map RTF char to standard code */
594 rtfMinor = RTFMapChar (rtfMajor);
597 * If auto-charset stuff is activated, see if anything needs doing,
598 * like reading the charset maps or switching between them.
601 if (autoCharSetFlags == 0)
602 return;
604 if ((autoCharSetFlags & rtfReadCharSet)
605 && RTFCheckCM (rtfControl, rtfCharSet))
607 ReadCharSetMaps ();
609 else if ((autoCharSetFlags & rtfSwitchCharSet)
610 && RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum))
612 if ((fp = RTFGetFont (rtfParam)) != (RTFFont *) NULL)
614 if (strncmp (fp->rtfFName, "Symbol", 6) == 0)
615 curCharSet = rtfCSSymbol;
616 else
617 curCharSet = rtfCSGeneral;
618 RTFSetCharSet (curCharSet);
621 else if ((autoCharSetFlags & rtfSwitchCharSet) && rtfClass == rtfGroup)
623 switch (rtfMajor)
625 case rtfBeginGroup:
626 if (csTop >= maxCSStack)
627 RTFPanic ("_RTFGetToken: stack overflow");
628 csStack[csTop++] = curCharSet;
629 break;
630 case rtfEndGroup:
631 if (csTop <= 0)
632 RTFPanic ("_RTFGetToken: stack underflow");
633 curCharSet = csStack[--csTop];
634 RTFSetCharSet (curCharSet);
635 break;
641 /* this shouldn't be called anywhere but from _RTFGetToken() */
643 static void _RTFGetToken2(void)
645 int sign;
646 int c;
648 TRACE("\n");
650 /* initialize token vars */
652 rtfClass = rtfUnknown;
653 rtfParam = rtfNoParam;
654 rtfTextBuf[rtfTextLen = 0] = '\0';
656 /* get first character, which may be a pushback from previous token */
658 if (pushedChar != EOF)
660 c = pushedChar;
661 rtfTextBuf[rtfTextLen++] = c;
662 rtfTextBuf[rtfTextLen] = '\0';
663 pushedChar = EOF;
665 else if ((c = GetChar ()) == EOF)
667 rtfClass = rtfEOF;
668 return;
671 if (c == '{')
673 rtfClass = rtfGroup;
674 rtfMajor = rtfBeginGroup;
675 return;
677 if (c == '}')
679 rtfClass = rtfGroup;
680 rtfMajor = rtfEndGroup;
681 return;
683 if (c != '\\')
686 * Two possibilities here:
687 * 1) ASCII 9, effectively like \tab control symbol
688 * 2) literal text char
690 if (c == '\t') /* ASCII 9 */
692 rtfClass = rtfControl;
693 rtfMajor = rtfSpecialChar;
694 rtfMinor = rtfTab;
696 else
698 rtfClass = rtfText;
699 rtfMajor = c;
701 return;
703 if ((c = GetChar ()) == EOF)
705 /* early eof, whoops (class is rtfUnknown) */
706 return;
708 if (!isalpha (c))
711 * Three possibilities here:
712 * 1) hex encoded text char, e.g., \'d5, \'d3
713 * 2) special escaped text char, e.g., \{, \}
714 * 3) control symbol, e.g., \_, \-, \|, \<10>
716 if (c == '\'') /* hex char */
718 int c2;
720 if ((c = GetChar ()) != EOF && (c2 = GetChar ()) != EOF)
722 /* should do isxdigit check! */
723 rtfClass = rtfText;
724 rtfMajor = RTFCharToHex (c) * 16
725 + RTFCharToHex (c2);
726 return;
728 /* early eof, whoops (class is rtfUnknown) */
729 return;
732 /* escaped char */
733 /*if (index (":{}\\", c) != (char *) NULL)*/ /* escaped char */
734 if (c == ':' || c == '{' || c == '}' || c == '\\')
736 rtfClass = rtfText;
737 rtfMajor = c;
738 return;
741 /* control symbol */
742 Lookup (rtfTextBuf); /* sets class, major, minor */
743 return;
745 /* control word */
746 while (isalpha (c))
748 if ((c = GetChar ()) == EOF)
749 break;
753 * At this point, the control word is all collected, so the
754 * major/minor numbers are determined before the parameter
755 * (if any) is scanned. There will be one too many characters
756 * in the buffer, though, so fix up before and restore after
757 * looking up.
760 if (c != EOF)
761 rtfTextBuf[rtfTextLen-1] = '\0';
762 Lookup (rtfTextBuf); /* sets class, major, minor */
763 if (c != EOF)
764 rtfTextBuf[rtfTextLen-1] = c;
767 * Should be looking at first digit of parameter if there
768 * is one, unless it's negative. In that case, next char
769 * is '-', so need to gobble next char, and remember sign.
772 sign = 1;
773 if (c == '-')
775 sign = -1;
776 c = GetChar ();
778 if (c != EOF && isdigit (c))
780 rtfParam = 0;
781 while (isdigit (c)) /* gobble parameter */
783 rtfParam = rtfParam * 10 + c - '0';
784 if ((c = GetChar ()) == EOF)
785 break;
787 rtfParam *= sign;
790 * If control symbol delimiter was a blank, gobble it.
791 * Otherwise the character is first char of next token, so
792 * push it back for next call. In either case, delete the
793 * delimiter from the token buffer.
795 if (c != EOF)
797 if (c != ' ')
798 pushedChar = c;
799 rtfTextBuf[--rtfTextLen] = '\0';
805 * Read the next character from the input. This handles setting the
806 * current line and position-within-line variables. Those variable are
807 * set correctly whether lines end with CR, LF, or CRLF (the last being
808 * the tricky case).
810 * bumpLine indicates whether the line number should be incremented on
811 * the *next* input character.
815 static int GetChar(void)
817 int c;
818 int oldBumpLine;
820 TRACE("\n");
822 if ((c = _RTFGetChar()) != EOF)
824 rtfTextBuf[rtfTextLen++] = c;
825 rtfTextBuf[rtfTextLen] = '\0';
827 if (prevChar == EOF)
828 bumpLine = 1;
829 oldBumpLine = bumpLine; /* non-zero if prev char was line ending */
830 bumpLine = 0;
831 if (c == '\r')
832 bumpLine = 1;
833 else if (c == '\n')
835 bumpLine = 1;
836 if (prevChar == '\r') /* oops, previous \r wasn't */
837 oldBumpLine = 0; /* really a line ending */
839 ++rtfLinePos;
840 if (oldBumpLine) /* were we supposed to increment the */
841 { /* line count on this char? */
842 ++rtfLineNum;
843 rtfLinePos = 1;
845 prevChar = c;
846 return (c);
851 * Synthesize a token by setting the global variables to the
852 * values supplied. Typically this is followed with a call
853 * to RTFRouteToken().
855 * If a param value other than rtfNoParam is passed, it becomes
856 * part of the token text.
859 void RTFSetToken(int class, int major, int minor, int param, char *text)
861 TRACE("\n");
863 rtfClass = class;
864 rtfMajor = major;
865 rtfMinor = minor;
866 rtfParam = param;
867 if (param == rtfNoParam)
868 (void) strcpy (rtfTextBuf, text);
869 else
870 sprintf (rtfTextBuf, "%s%d", text, param);
871 rtfTextLen = strlen (rtfTextBuf);
875 /* ---------------------------------------------------------------------- */
878 * Routines to handle mapping of RTF character sets
879 * onto standard characters.
881 * RTFStdCharCode(name) given char name, produce numeric code
882 * RTFStdCharName(code) given char code, return name
883 * RTFMapChar(c) map input (RTF) char code to std code
884 * RTFSetCharSet(id) select given charset map
885 * RTFGetCharSet() get current charset map
887 * See ../h/README for more information about charset names and codes.
892 * Initialize charset stuff.
895 static void CharSetInit(void)
897 TRACE("\n");
899 autoCharSetFlags = (rtfReadCharSet | rtfSwitchCharSet);
900 RTFFree (genCharSetFile);
901 genCharSetFile = (char *) NULL;
902 haveGenCharSet = 0;
903 RTFFree (symCharSetFile);
904 symCharSetFile = (char *) NULL;
905 haveSymCharSet = 0;
906 curCharSet = rtfCSGeneral;
907 curCharCode = genCharCode;
912 * Specify the name of a file to be read when auto-charset-file reading is
913 * done.
916 void RTFSetCharSetMap (char *name, int csId)
918 TRACE("\n");
920 if ((name = RTFStrSave (name)) == (char *) NULL) /* make copy */
921 RTFPanic ("RTFSetCharSetMap: out of memory");
922 switch (csId)
924 case rtfCSGeneral:
925 RTFFree (genCharSetFile); /* free any previous value */
926 genCharSetFile = name;
927 break;
928 case rtfCSSymbol:
929 RTFFree (symCharSetFile); /* free any previous value */
930 symCharSetFile = name;
931 break;
937 * Do auto-charset-file reading.
938 * will always use the ansi charset no mater what the value
939 * of the rtfTextBuf is.
941 * TODO: add support for other charset in the future.
945 static void ReadCharSetMaps(void)
947 char buf[rtfBufSiz];
949 TRACE("\n");
951 if (genCharSetFile != (char *) NULL)
952 (void) strcpy (buf, genCharSetFile);
953 else
954 sprintf (buf, "%s-gen", &rtfTextBuf[1]);
955 if (RTFReadCharSetMap (rtfCSGeneral) == 0)
956 RTFPanic ("ReadCharSetMaps: Cannot read charset map %s", buf);
957 if (symCharSetFile != (char *) NULL)
958 (void) strcpy (buf, symCharSetFile);
959 else
960 sprintf (buf, "%s-sym", &rtfTextBuf[1]);
961 if (RTFReadCharSetMap (rtfCSSymbol) == 0)
962 RTFPanic ("ReadCharSetMaps: Cannot read charset map %s", buf);
968 * Convert a CaracterSetMap (caracter_name, caracter) into
969 * this form : array[caracter_ident] = caracter;
972 int RTFReadCharSetMap(int csId)
974 int *stdCodeArray;
975 int i;
977 TRACE("\n");
979 switch (csId)
981 default:
982 return (0); /* illegal charset id */
983 case rtfCSGeneral:
985 haveGenCharSet = 1;
986 stdCodeArray = genCharCode;
987 for (i = 0; i < charSetSize; i++)
989 stdCodeArray[i] = rtfSC_nothing;
992 for ( i = 0 ; i< sizeof(ansi_gen)/(sizeof(int));i+=2)
994 stdCodeArray[ ansi_gen[i+1] ] = ansi_gen[i];
996 break;
998 case rtfCSSymbol:
1000 haveSymCharSet = 1;
1001 stdCodeArray = symCharCode;
1002 for (i = 0; i < charSetSize; i++)
1004 stdCodeArray[i] = rtfSC_nothing;
1007 for ( i = 0 ; i< sizeof(ansi_sym)/(sizeof(int));i+=2)
1009 stdCodeArray[ ansi_sym[i+1] ] = ansi_sym[i];
1011 break;
1014 return (1);
1019 * Given a standard character name (a string), find its code (a number).
1020 * Return -1 if name is unknown.
1023 int RTFStdCharCode(char *name)
1025 int i;
1027 TRACE("\n");
1029 for (i = 0; i < rtfSC_MaxChar; i++)
1031 if (strcmp (name, stdCharName[i]) == 0)
1032 return (i);
1034 return (-1);
1039 * Given a standard character code (a number), find its name (a string).
1040 * Return NULL if code is unknown.
1043 char *RTFStdCharName(int code)
1045 if (code < 0 || code >= rtfSC_MaxChar)
1046 return ((char *) NULL);
1047 return (stdCharName[code]);
1052 * Given an RTF input character code, find standard character code.
1053 * The translator should read the appropriate charset maps when it finds a
1054 * charset control. However, the file might not contain one. In this
1055 * case, no map will be available. When the first attempt is made to
1056 * map a character under these circumstances, RTFMapChar() assumes ANSI
1057 * and reads the map as necessary.
1060 int RTFMapChar(int c)
1062 TRACE("\n");
1064 switch (curCharSet)
1066 case rtfCSGeneral:
1067 if (!haveGenCharSet)
1069 if (RTFReadCharSetMap (rtfCSGeneral) == 0)
1070 RTFPanic ("RTFMapChar: cannot read ansi-gen");
1072 break;
1073 case rtfCSSymbol:
1074 if (!haveSymCharSet)
1076 if (RTFReadCharSetMap (rtfCSSymbol) == 0)
1077 RTFPanic ("RTFMapChar: cannot read ansi-sym");
1079 break;
1081 if (c < 0 || c >= charSetSize)
1082 return (rtfSC_nothing);
1083 return (curCharCode[c]);
1088 * Set the current character set. If csId is illegal, uses general charset.
1091 void RTFSetCharSet(int csId)
1093 TRACE("\n");
1095 switch (csId)
1097 default: /* use general if csId unknown */
1098 case rtfCSGeneral:
1099 curCharCode = genCharCode;
1100 curCharSet = csId;
1101 break;
1102 case rtfCSSymbol:
1103 curCharCode = symCharCode;
1104 curCharSet = csId;
1105 break;
1110 int RTFGetCharSet(void)
1112 return (curCharSet);
1116 /* ---------------------------------------------------------------------- */
1119 * Special destination readers. They gobble the destination so the
1120 * writer doesn't have to deal with them. That's wrong for any
1121 * translator that wants to process any of these itself. In that
1122 * case, these readers should be overridden by installing a different
1123 * destination callback.
1125 * NOTE: The last token read by each of these reader will be the
1126 * destination's terminating '}', which will then be the current token.
1127 * That '}' token is passed to RTFRouteToken() - the writer has already
1128 * seen the '{' that began the destination group, and may have pushed a
1129 * state; it also needs to know at the end of the group that a state
1130 * should be popped.
1132 * It's important that rtf.h and the control token lookup table list
1133 * as many symbols as possible, because these destination readers
1134 * unfortunately make strict assumptions about the input they expect,
1135 * and a token of class rtfUnknown will throw them off easily.
1140 * Read { \fonttbl ... } destination. Old font tables don't have
1141 * braces around each table entry; try to adjust for that.
1144 static void ReadFontTbl(void)
1146 RTFFont *fp = NULL;
1147 char buf[rtfBufSiz], *bp;
1148 int old = -1;
1149 char *fn = "ReadFontTbl";
1151 TRACE("\n");
1153 for (;;)
1155 (void) RTFGetToken ();
1156 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1157 break;
1158 if (old < 0) /* first entry - determine tbl type */
1160 if (RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum))
1161 old = 1; /* no brace */
1162 else if (RTFCheckCM (rtfGroup, rtfBeginGroup))
1163 old = 0; /* brace */
1164 else /* can't tell! */
1165 RTFPanic ("%s: Cannot determine format", fn);
1167 if (old == 0) /* need to find "{" here */
1169 if (!RTFCheckCM (rtfGroup, rtfBeginGroup))
1170 RTFPanic ("%s: missing \"{\"", fn);
1171 (void) RTFGetToken (); /* yes, skip to next token */
1173 if ((fp = New (RTFFont)) == (RTFFont *) NULL)
1174 RTFPanic ("%s: cannot allocate font entry", fn);
1176 fp->rtfNextFont = fontList;
1177 fontList = fp;
1179 fp->rtfFName = (char *) NULL;
1180 fp->rtfFAltName = (char *) NULL;
1181 fp->rtfFNum = -1;
1182 fp->rtfFFamily = 0;
1183 fp->rtfFCharSet = 0;
1184 fp->rtfFPitch = 0;
1185 fp->rtfFType = 0;
1186 fp->rtfFCodePage = 0;
1188 while (rtfClass != rtfEOF
1189 && !RTFCheckCM (rtfText, ';')
1190 && !RTFCheckCM (rtfGroup, rtfEndGroup))
1192 if (rtfClass == rtfControl)
1194 switch (rtfMajor)
1196 default:
1197 /* ignore token but announce it */
1198 RTFMsg ("%s: unknown token \"%s\"\n",
1199 fn, rtfTextBuf);
1200 case rtfFontFamily:
1201 fp->rtfFFamily = rtfMinor;
1202 break;
1203 case rtfCharAttr:
1204 switch (rtfMinor)
1206 default:
1207 break; /* ignore unknown? */
1208 case rtfFontNum:
1209 fp->rtfFNum = rtfParam;
1210 break;
1212 break;
1213 case rtfFontAttr:
1214 switch (rtfMinor)
1216 default:
1217 break; /* ignore unknown? */
1218 case rtfFontCharSet:
1219 fp->rtfFCharSet = rtfParam;
1220 break;
1221 case rtfFontPitch:
1222 fp->rtfFPitch = rtfParam;
1223 break;
1224 case rtfFontCodePage:
1225 fp->rtfFCodePage = rtfParam;
1226 break;
1227 case rtfFTypeNil:
1228 case rtfFTypeTrueType:
1229 fp->rtfFType = rtfParam;
1230 break;
1232 break;
1235 else if (RTFCheckCM (rtfGroup, rtfBeginGroup)) /* dest */
1237 RTFSkipGroup (); /* ignore for now */
1239 else if (rtfClass == rtfText) /* font name */
1241 bp = buf;
1242 while (rtfClass != rtfEOF
1243 && !RTFCheckCM (rtfText, ';')
1244 && !RTFCheckCM (rtfGroup, rtfEndGroup))
1246 *bp++ = rtfMajor;
1247 (void) RTFGetToken ();
1250 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
1251 if(RTFCheckCM (rtfGroup, rtfEndGroup))
1253 RTFUngetToken ();
1255 *bp = '\0';
1256 fp->rtfFName = RTFStrSave (buf);
1257 if (fp->rtfFName == (char *) NULL)
1258 RTFPanic ("%s: cannot allocate font name", fn);
1259 /* already have next token; don't read one */
1260 /* at bottom of loop */
1261 continue;
1263 else
1265 /* ignore token but announce it */
1266 RTFMsg ("%s: unknown token \"%s\"\n",
1267 fn, rtfTextBuf);
1269 (void) RTFGetToken ();
1271 if (old == 0) /* need to see "}" here */
1273 (void) RTFGetToken ();
1274 if (!RTFCheckCM (rtfGroup, rtfEndGroup))
1275 RTFPanic ("%s: missing \"}\"", fn);
1278 if (fp->rtfFNum == -1)
1279 RTFPanic ("%s: missing font number", fn);
1281 * Could check other pieces of structure here, too, I suppose.
1283 RTFRouteToken (); /* feed "}" back to router */
1288 * The color table entries have color values of -1 if
1289 * the default color should be used for the entry (only
1290 * a semi-colon is given in the definition, no color values).
1291 * There will be a problem if a partial entry (1 or 2 but
1292 * not 3 color values) is given. The possibility is ignored
1293 * here.
1296 static void ReadColorTbl(void)
1298 RTFColor *cp;
1299 int cnum = 0;
1300 char *fn = "ReadColorTbl";
1302 TRACE("\n");
1304 for (;;)
1306 (void) RTFGetToken ();
1307 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1308 break;
1309 if ((cp = New (RTFColor)) == (RTFColor *) NULL)
1310 RTFPanic ("%s: cannot allocate color entry", fn);
1311 cp->rtfCNum = cnum++;
1312 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
1313 cp->rtfNextColor = colorList;
1314 colorList = cp;
1315 while (RTFCheckCM (rtfControl, rtfColorName))
1317 switch (rtfMinor)
1319 case rtfRed: cp->rtfCRed = rtfParam; break;
1320 case rtfGreen: cp->rtfCGreen = rtfParam; break;
1321 case rtfBlue: cp->rtfCBlue = rtfParam; break;
1323 RTFGetToken ();
1325 if (!RTFCheckCM (rtfText, (int) ';'))
1326 RTFPanic ("%s: malformed entry", fn);
1328 RTFRouteToken (); /* feed "}" back to router */
1333 * The "Normal" style definition doesn't contain any style number,
1334 * all others do. Normal style is given style rtfNormalStyleNum.
1337 static void ReadStyleSheet(void)
1339 RTFStyle *sp;
1340 RTFStyleElt *sep, *sepLast;
1341 char buf[rtfBufSiz], *bp;
1342 char *fn = "ReadStyleSheet";
1344 TRACE("\n");
1346 for (;;)
1348 (void) RTFGetToken ();
1349 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1350 break;
1351 if ((sp = New (RTFStyle)) == (RTFStyle *) NULL)
1352 RTFPanic ("%s: cannot allocate stylesheet entry", fn);
1353 sp->rtfSName = (char *) NULL;
1354 sp->rtfSNum = -1;
1355 sp->rtfSType = rtfParStyle;
1356 sp->rtfSAdditive = 0;
1357 sp->rtfSBasedOn = rtfNoStyleNum;
1358 sp->rtfSNextPar = -1;
1359 sp->rtfSSEList = sepLast = (RTFStyleElt *) NULL;
1360 sp->rtfNextStyle = styleList;
1361 sp->rtfExpanding = 0;
1362 styleList = sp;
1363 if (!RTFCheckCM (rtfGroup, rtfBeginGroup))
1364 RTFPanic ("%s: missing \"{\"", fn);
1365 for (;;)
1367 (void) RTFGetToken ();
1368 if (rtfClass == rtfEOF
1369 || RTFCheckCM (rtfText, ';'))
1370 break;
1371 if (rtfClass == rtfControl)
1373 if (RTFCheckMM (rtfSpecialChar, rtfOptDest))
1374 continue; /* ignore "\*" */
1375 if (RTFCheckMM (rtfParAttr, rtfStyleNum))
1377 sp->rtfSNum = rtfParam;
1378 sp->rtfSType = rtfParStyle;
1379 continue;
1381 if (RTFCheckMM (rtfCharAttr, rtfCharStyleNum))
1383 sp->rtfSNum = rtfParam;
1384 sp->rtfSType = rtfCharStyle;
1385 continue;
1387 if (RTFCheckMM (rtfSectAttr, rtfSectStyleNum))
1389 sp->rtfSNum = rtfParam;
1390 sp->rtfSType = rtfSectStyle;
1391 continue;
1393 if (RTFCheckMM (rtfStyleAttr, rtfBasedOn))
1395 sp->rtfSBasedOn = rtfParam;
1396 continue;
1398 if (RTFCheckMM (rtfStyleAttr, rtfAdditive))
1400 sp->rtfSAdditive = 1;
1401 continue;
1403 if (RTFCheckMM (rtfStyleAttr, rtfNext))
1405 sp->rtfSNextPar = rtfParam;
1406 continue;
1408 if ((sep = New (RTFStyleElt)) == (RTFStyleElt *) NULL)
1409 RTFPanic ("%s: cannot allocate style element", fn);
1410 sep->rtfSEClass = rtfClass;
1411 sep->rtfSEMajor = rtfMajor;
1412 sep->rtfSEMinor = rtfMinor;
1413 sep->rtfSEParam = rtfParam;
1414 if ((sep->rtfSEText = RTFStrSave (rtfTextBuf))
1415 == (char *) NULL)
1416 RTFPanic ("%s: cannot allocate style element text", fn);
1417 if (sepLast == (RTFStyleElt *) NULL)
1418 sp->rtfSSEList = sep; /* first element */
1419 else /* add to end */
1420 sepLast->rtfNextSE = sep;
1421 sep->rtfNextSE = (RTFStyleElt *) NULL;
1422 sepLast = sep;
1424 else if (RTFCheckCM (rtfGroup, rtfBeginGroup))
1427 * This passes over "{\*\keycode ... }, among
1428 * other things. A temporary (perhaps) hack.
1430 RTFSkipGroup ();
1431 continue;
1433 else if (rtfClass == rtfText) /* style name */
1435 bp = buf;
1436 while (rtfClass == rtfText)
1438 if (rtfMajor == ';')
1440 /* put back for "for" loop */
1441 (void) RTFUngetToken ();
1442 break;
1444 *bp++ = rtfMajor;
1445 (void) RTFGetToken ();
1447 *bp = '\0';
1448 if ((sp->rtfSName = RTFStrSave (buf)) == (char *) NULL)
1449 RTFPanic ("%s: cannot allocate style name", fn);
1451 else /* unrecognized */
1453 /* ignore token but announce it */
1454 RTFMsg ("%s: unknown token \"%s\"\n",
1455 fn, rtfTextBuf);
1458 (void) RTFGetToken ();
1459 if (!RTFCheckCM (rtfGroup, rtfEndGroup))
1460 RTFPanic ("%s: missing \"}\"", fn);
1463 * Check over the style structure. A name is a must.
1464 * If no style number was specified, check whether it's the
1465 * Normal style (in which case it's given style number
1466 * rtfNormalStyleNum). Note that some "normal" style names
1467 * just begin with "Normal" and can have other stuff following,
1468 * e.g., "Normal,Times 10 point". Ugh.
1470 * Some German RTF writers use "Standard" instead of "Normal".
1472 if (sp->rtfSName == (char *) NULL)
1473 RTFPanic ("%s: missing style name", fn);
1474 if (sp->rtfSNum < 0)
1476 if (strncmp (buf, "Normal", 6) != 0
1477 && strncmp (buf, "Standard", 8) != 0)
1478 RTFPanic ("%s: missing style number", fn);
1479 sp->rtfSNum = rtfNormalStyleNum;
1481 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1482 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1484 RTFRouteToken (); /* feed "}" back to router */
1488 static void ReadInfoGroup(void)
1490 RTFSkipGroup ();
1491 RTFRouteToken (); /* feed "}" back to router */
1495 static void ReadPictGroup(void)
1497 RTFSkipGroup ();
1498 RTFRouteToken (); /* feed "}" back to router */
1502 static void ReadObjGroup(void)
1504 RTFSkipGroup ();
1505 RTFRouteToken (); /* feed "}" back to router */
1509 /* ---------------------------------------------------------------------- */
1512 * Routines to return pieces of stylesheet, or font or color tables.
1513 * References to style 0 are mapped onto the Normal style.
1517 RTFStyle *RTFGetStyle(int num)
1519 RTFStyle *s;
1521 if (num == -1)
1522 return (styleList);
1523 for (s = styleList; s != (RTFStyle *) NULL; s = s->rtfNextStyle)
1525 if (s->rtfSNum == num)
1526 break;
1528 return (s); /* NULL if not found */
1532 RTFFont *RTFGetFont(int num)
1534 RTFFont *f;
1536 if (num == -1)
1537 return (fontList);
1538 for (f = fontList; f != (RTFFont *) NULL; f = f->rtfNextFont)
1540 if (f->rtfFNum == num)
1541 break;
1543 return (f); /* NULL if not found */
1547 RTFColor *RTFGetColor(int num)
1549 RTFColor *c;
1551 if (num == -1)
1552 return (colorList);
1553 for (c = colorList; c != (RTFColor *) NULL; c = c->rtfNextColor)
1555 if (c->rtfCNum == num)
1556 break;
1558 return (c); /* NULL if not found */
1562 /* ---------------------------------------------------------------------- */
1566 * Expand style n, if there is such a style.
1569 void RTFExpandStyle(int n)
1571 RTFStyle *s;
1572 RTFStyleElt *se;
1574 TRACE("\n");
1576 if (n == -1 || (s = RTFGetStyle (n)) == (RTFStyle *) NULL)
1577 return;
1578 if (s->rtfExpanding != 0)
1579 RTFPanic ("Style expansion loop, style %d", n);
1580 s->rtfExpanding = 1; /* set expansion flag for loop detection */
1582 * Expand "based-on" style (unless it's the same as the current
1583 * style -- Normal style usually gives itself as its own based-on
1584 * style). Based-on style expansion is done by synthesizing
1585 * the token that the writer needs to see in order to trigger
1586 * another style expansion, and feeding to token back through
1587 * the router so the writer sees it.
1589 if (n != s->rtfSBasedOn)
1591 RTFSetToken (rtfControl, rtfParAttr, rtfStyleNum,
1592 s->rtfSBasedOn, "\\s");
1593 RTFRouteToken ();
1596 * Now route the tokens unique to this style. RTFSetToken()
1597 * isn't used because it would add the param value to the end
1598 * of the token text, which already has it in.
1600 for (se = s->rtfSSEList; se != (RTFStyleElt *) NULL; se = se->rtfNextSE)
1602 rtfClass = se->rtfSEClass;
1603 rtfMajor = se->rtfSEMajor;
1604 rtfMinor = se->rtfSEMinor;
1605 rtfParam = se->rtfSEParam;
1606 (void) strcpy (rtfTextBuf, se->rtfSEText);
1607 rtfTextLen = strlen (rtfTextBuf);
1608 RTFRouteToken ();
1610 s->rtfExpanding = 0; /* done - clear expansion flag */
1614 /* ---------------------------------------------------------------------- */
1617 * Control symbol lookup routines
1621 typedef struct RTFKey RTFKey;
1623 struct RTFKey
1625 int rtfKMajor; /* major number */
1626 int rtfKMinor; /* minor number */
1627 char *rtfKStr; /* symbol name */
1628 int rtfKHash; /* symbol name hash value */
1632 * A minor number of -1 means the token has no minor number
1633 * (all valid minor numbers are >= 0).
1636 static RTFKey rtfKey[] =
1639 * Special characters
1642 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1643 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1644 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1645 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1646 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1647 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1648 { rtfSpecialChar, rtfIYear, "yr", 0 },
1649 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1650 { rtfSpecialChar, rtfIDay, "dy", 0 },
1651 { rtfSpecialChar, rtfIHour, "hr", 0 },
1652 { rtfSpecialChar, rtfIMinute, "min", 0 },
1653 { rtfSpecialChar, rtfISecond, "sec", 0 },
1654 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1655 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1656 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1657 { rtfSpecialChar, rtfIIntID, "id", 0 },
1659 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1660 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1661 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1662 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1663 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1664 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1665 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1666 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1667 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1668 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1669 { rtfSpecialChar, rtfCell, "cell", 0 },
1670 { rtfSpecialChar, rtfRow, "row", 0 },
1671 { rtfSpecialChar, rtfPar, "par", 0 },
1672 /* newline and carriage return are synonyms for */
1673 /* \par when they are preceded by a \ character */
1674 { rtfSpecialChar, rtfPar, "\n", 0 },
1675 { rtfSpecialChar, rtfPar, "\r", 0 },
1676 { rtfSpecialChar, rtfSect, "sect", 0 },
1677 { rtfSpecialChar, rtfPage, "page", 0 },
1678 { rtfSpecialChar, rtfColumn, "column", 0 },
1679 { rtfSpecialChar, rtfLine, "line", 0 },
1680 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1681 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1682 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1683 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1684 { rtfSpecialChar, rtfTab, "tab", 0 },
1685 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1686 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1687 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1688 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1689 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1690 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1691 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1692 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1693 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1694 { rtfSpecialChar, rtfFormula, "|", 0 },
1695 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1696 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1697 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1698 { rtfSpecialChar, rtfOptDest, "*", 0 },
1699 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1700 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1701 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1702 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1703 /* is this valid? */
1704 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1707 * Character formatting attributes
1710 { rtfCharAttr, rtfPlain, "plain", 0 },
1711 { rtfCharAttr, rtfBold, "b", 0 },
1712 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1713 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1714 { rtfCharAttr, rtfSubScript, "dn", 0 },
1715 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1716 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1717 { rtfCharAttr, rtfExpand, "expnd", 0 },
1718 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1719 { rtfCharAttr, rtfKerning, "kerning", 0 },
1720 { rtfCharAttr, rtfFontNum, "f", 0 },
1721 { rtfCharAttr, rtfFontSize, "fs", 0 },
1722 { rtfCharAttr, rtfItalic, "i", 0 },
1723 { rtfCharAttr, rtfOutline, "outl", 0 },
1724 { rtfCharAttr, rtfRevised, "revised", 0 },
1725 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1726 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1727 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1728 { rtfCharAttr, rtfShadow, "shad", 0 },
1729 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1730 { rtfCharAttr, rtfUnderline, "ul", 0 },
1731 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1732 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1733 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1734 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1735 { rtfCharAttr, rtfSuperScript, "up", 0 },
1736 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1737 { rtfCharAttr, rtfInvisible, "v", 0 },
1738 { rtfCharAttr, rtfForeColor, "cf", 0 },
1739 { rtfCharAttr, rtfBackColor, "cb", 0 },
1740 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1741 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1742 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1743 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1744 { rtfCharAttr, rtfLanguage, "lang", 0 },
1745 /* this has disappeared from spec 1.2 */
1746 { rtfCharAttr, rtfGray, "gray", 0 },
1749 * Paragraph formatting attributes
1752 { rtfParAttr, rtfParDef, "pard", 0 },
1753 { rtfParAttr, rtfStyleNum, "s", 0 },
1754 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1755 { rtfParAttr, rtfInTable, "intbl", 0 },
1756 { rtfParAttr, rtfKeep, "keep", 0 },
1757 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1758 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1759 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1760 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1761 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1762 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1763 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1764 { rtfParAttr, rtfQuadRight, "qr", 0 },
1765 { rtfParAttr, rtfQuadJust, "qj", 0 },
1766 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1767 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1768 { rtfParAttr, rtfLeftIndent, "li", 0 },
1769 { rtfParAttr, rtfRightIndent, "ri", 0 },
1770 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1771 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1772 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1773 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1775 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1777 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1778 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1780 { rtfParAttr, rtfTabPos, "tx", 0 },
1782 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1783 * although it's not in the spec. It's also redundant, since lj
1784 * tabs are the default.
1786 { rtfParAttr, rtfTabLeft, "tql", 0 },
1787 { rtfParAttr, rtfTabRight, "tqr", 0 },
1788 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1789 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1790 { rtfParAttr, rtfTabBar, "tb", 0 },
1791 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1792 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1793 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1794 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1795 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1797 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1798 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1799 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1800 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1801 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1802 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1803 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1804 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1805 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1806 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1807 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1808 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1809 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1810 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1811 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1812 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1813 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1814 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1815 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1816 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1817 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1818 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1819 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1820 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1821 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1822 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1823 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1824 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1825 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1826 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1827 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1828 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1829 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1830 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1831 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1832 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1834 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1835 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1836 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1837 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1838 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1839 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1840 { rtfParAttr, rtfBorderBox, "box", 0 },
1841 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1842 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1843 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1844 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1845 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1846 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1847 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1848 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1849 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1850 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1852 { rtfParAttr, rtfShading, "shading", 0 },
1853 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1854 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1855 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1856 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1857 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1858 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1859 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1860 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1861 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1862 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1863 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1864 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1865 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1866 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1869 * Section formatting attributes
1872 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1873 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1874 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1875 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1876 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1878 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1879 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1880 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1881 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1882 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1884 { rtfSectAttr, rtfColumns, "cols", 0 },
1885 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1886 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1887 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1888 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1889 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1891 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1892 { rtfSectAttr, rtfLineDist, "linex", 0 },
1893 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1894 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1895 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1896 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1898 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1899 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1900 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1901 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1902 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1903 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1904 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1905 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1906 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1907 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1908 { rtfSectAttr, rtfFooterY, "footery", 0 },
1910 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1911 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1912 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1913 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1914 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1915 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1916 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1917 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1918 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1919 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1920 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1921 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1922 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1923 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1924 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1926 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1927 /* misspelled as "vertal" in specification 1.0 */
1928 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1929 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1930 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
1932 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
1933 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
1935 /* I've seen these in an old spec, but not in real files... */
1936 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1937 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1938 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1939 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1940 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1943 * Document formatting attributes
1946 { rtfDocAttr, rtfDefTab, "deftab", 0 },
1947 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
1948 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
1949 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
1950 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
1951 { rtfDocAttr, rtfLineStart, "linestart", 0 },
1952 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
1953 /* \makeback was given in old version of spec, it's now */
1954 /* listed as \makebackup */
1955 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
1956 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
1957 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
1958 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
1959 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
1960 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
1962 { rtfDocAttr, rtfFENoteType, "fet", 0 },
1963 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
1964 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
1965 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
1966 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
1967 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
1968 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
1969 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
1970 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
1971 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
1972 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
1973 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
1974 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
1975 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
1976 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
1977 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
1978 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
1979 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
1980 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
1981 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
1982 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
1983 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
1984 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
1985 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
1986 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
1987 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
1988 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
1989 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
1991 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
1992 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
1993 { rtfDocAttr, rtfPaperSize, "psz", 0 },
1994 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
1995 { rtfDocAttr, rtfRightMargin, "margr", 0 },
1996 { rtfDocAttr, rtfTopMargin, "margt", 0 },
1997 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
1998 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
1999 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
2000 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
2001 { rtfDocAttr, rtfLandscape, "landscape", 0 },
2002 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
2003 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
2005 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
2007 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
2008 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
2009 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
2010 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
2011 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
2012 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
2013 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
2014 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
2015 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
2016 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
2017 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
2018 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
2020 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
2021 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
2022 { rtfDocAttr, rtfFormShading, "formshade", 0 },
2023 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
2024 { rtfDocAttr, rtfPrintData, "printdata", 0 },
2026 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
2027 { rtfDocAttr, rtfRevisions, "revisions", 0 },
2028 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
2029 { rtfDocAttr, rtfRevBar, "revbar", 0 },
2031 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
2033 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
2034 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
2037 * Style attributes
2040 { rtfStyleAttr, rtfAdditive, "additive", 0 },
2041 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
2042 { rtfStyleAttr, rtfNext, "snext", 0 },
2045 * Picture attributes
2048 { rtfPictAttr, rtfMacQD, "macpict", 0 },
2049 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
2050 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
2051 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
2052 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
2053 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
2054 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
2055 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
2057 { rtfPictAttr, rtfPicWid, "picw", 0 },
2058 { rtfPictAttr, rtfPicHt, "pich", 0 },
2059 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
2060 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
2061 /* these two aren't in the spec, but some writers emit them */
2062 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
2063 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
2064 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
2065 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
2066 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
2067 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
2068 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
2069 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
2070 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
2072 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
2073 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
2075 { rtfPictAttr, rtfPicBinary, "bin", 0 },
2078 * NeXT graphic attributes
2081 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
2082 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
2085 * Destinations
2088 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
2089 { rtfDestination, rtfFontAltName, "falt", 0 },
2090 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
2091 { rtfDestination, rtfFontFile, "fontfile", 0 },
2092 { rtfDestination, rtfFileTbl, "filetbl", 0 },
2093 { rtfDestination, rtfFileInfo, "file", 0 },
2094 { rtfDestination, rtfColorTbl, "colortbl", 0 },
2095 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
2096 { rtfDestination, rtfKeyCode, "keycode", 0 },
2097 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
2098 { rtfDestination, rtfInfo, "info", 0 },
2099 { rtfDestination, rtfITitle, "title", 0 },
2100 { rtfDestination, rtfISubject, "subject", 0 },
2101 { rtfDestination, rtfIAuthor, "author", 0 },
2102 { rtfDestination, rtfIOperator, "operator", 0 },
2103 { rtfDestination, rtfIKeywords, "keywords", 0 },
2104 { rtfDestination, rtfIComment, "comment", 0 },
2105 { rtfDestination, rtfIVersion, "version", 0 },
2106 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
2107 /* \verscomm may not exist -- was seen in earlier spec version */
2108 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
2109 { rtfDestination, rtfNextFile, "nextfile", 0 },
2110 { rtfDestination, rtfTemplate, "template", 0 },
2111 { rtfDestination, rtfFNSep, "ftnsep", 0 },
2112 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
2113 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
2114 { rtfDestination, rtfENSep, "aftnsep", 0 },
2115 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
2116 { rtfDestination, rtfENContNotice, "aftncn", 0 },
2117 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
2118 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
2119 { rtfDestination, rtfHeader, "header", 0 },
2120 { rtfDestination, rtfFooter, "footer", 0 },
2121 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
2122 { rtfDestination, rtfHeaderRight, "headerr", 0 },
2123 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
2124 { rtfDestination, rtfFooterLeft, "footerl", 0 },
2125 { rtfDestination, rtfFooterRight, "footerr", 0 },
2126 { rtfDestination, rtfFooterFirst, "footerf", 0 },
2127 { rtfDestination, rtfParNumText, "pntext", 0 },
2128 { rtfDestination, rtfParNumbering, "pn", 0 },
2129 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
2130 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
2131 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
2132 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
2133 { rtfDestination, rtfPict, "pict", 0 },
2134 { rtfDestination, rtfObject, "object", 0 },
2135 { rtfDestination, rtfObjClass, "objclass", 0 },
2136 { rtfDestination, rtfObjName, "objname", 0 },
2137 { rtfObjAttr, rtfObjTime, "objtime", 0 },
2138 { rtfDestination, rtfObjData, "objdata", 0 },
2139 { rtfDestination, rtfObjAlias, "objalias", 0 },
2140 { rtfDestination, rtfObjSection, "objsect", 0 },
2141 /* objitem and objtopic aren't documented in the spec! */
2142 { rtfDestination, rtfObjItem, "objitem", 0 },
2143 { rtfDestination, rtfObjTopic, "objtopic", 0 },
2144 { rtfDestination, rtfObjResult, "result", 0 },
2145 { rtfDestination, rtfDrawObject, "do", 0 },
2146 { rtfDestination, rtfFootnote, "footnote", 0 },
2147 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
2148 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
2149 { rtfDestination, rtfAnnotID, "atnid", 0 },
2150 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
2151 { rtfDestination, rtfAnnotation, "annotation", 0 },
2152 { rtfDestination, rtfAnnotRef, "atnref", 0 },
2153 { rtfDestination, rtfAnnotTime, "atntime", 0 },
2154 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
2155 { rtfDestination, rtfField, "field", 0 },
2156 { rtfDestination, rtfFieldInst, "fldinst", 0 },
2157 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
2158 { rtfDestination, rtfDataField, "datafield", 0 },
2159 { rtfDestination, rtfIndex, "xe", 0 },
2160 { rtfDestination, rtfIndexText, "txe", 0 },
2161 { rtfDestination, rtfIndexRange, "rxe", 0 },
2162 { rtfDestination, rtfTOC, "tc", 0 },
2163 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
2166 * Font families
2169 { rtfFontFamily, rtfFFNil, "fnil", 0 },
2170 { rtfFontFamily, rtfFFRoman, "froman", 0 },
2171 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
2172 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
2173 { rtfFontFamily, rtfFFScript, "fscript", 0 },
2174 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
2175 { rtfFontFamily, rtfFFTech, "ftech", 0 },
2176 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
2179 * Font attributes
2182 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
2183 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
2184 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
2185 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
2186 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
2189 * File table attributes
2192 { rtfFileAttr, rtfFileNum, "fid", 0 },
2193 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
2194 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
2197 * File sources
2200 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
2201 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
2202 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
2203 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
2204 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
2207 * Color names
2210 { rtfColorName, rtfRed, "red", 0 },
2211 { rtfColorName, rtfGreen, "green", 0 },
2212 { rtfColorName, rtfBlue, "blue", 0 },
2215 * Charset names
2218 { rtfCharSet, rtfMacCharSet, "mac", 0 },
2219 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
2220 { rtfCharSet, rtfPcCharSet, "pc", 0 },
2221 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
2224 * Table attributes
2227 { rtfTblAttr, rtfRowDef, "trowd", 0 },
2228 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
2229 { rtfTblAttr, rtfCellPos, "cellx", 0 },
2230 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
2231 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
2233 { rtfTblAttr, rtfRowLeft, "trql", 0 },
2234 { rtfTblAttr, rtfRowRight, "trqr", 0 },
2235 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
2236 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
2237 { rtfTblAttr, rtfRowHt, "trrh", 0 },
2238 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
2239 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
2241 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
2242 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
2244 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
2245 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
2246 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
2247 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
2248 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
2249 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
2251 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
2252 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
2253 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
2254 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
2256 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
2257 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
2258 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
2259 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
2260 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
2261 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
2262 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
2264 * The spec lists "clbgdkhor", but the corresponding non-cell
2265 * control is "bgdkhoriz". At any rate Macintosh Word seems
2266 * to accept both "clbgdkhor" and "clbgdkhoriz".
2268 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
2269 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
2270 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
2271 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
2272 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
2273 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
2274 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
2275 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
2276 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
2279 * Field attributes
2282 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
2283 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
2284 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
2285 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
2286 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
2289 * Positioning attributes
2292 { rtfPosAttr, rtfAbsWid, "absw", 0 },
2293 { rtfPosAttr, rtfAbsHt, "absh", 0 },
2295 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
2296 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
2297 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
2298 { rtfPosAttr, rtfPosX, "posx", 0 },
2299 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
2300 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
2301 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
2302 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
2303 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
2304 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
2306 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
2307 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
2308 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
2309 { rtfPosAttr, rtfPosY, "posy", 0 },
2310 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
2311 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
2312 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
2313 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
2314 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
2316 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
2317 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
2318 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
2319 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
2320 /* \dyfrtext no longer exists in spec 1.2, apparently */
2321 /* replaced by \dfrmtextx and \dfrmtexty. */
2322 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
2324 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
2325 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
2328 * Object controls
2331 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
2332 { rtfObjAttr, rtfObjLink, "objlink", 0 },
2333 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
2334 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
2335 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
2336 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
2338 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
2339 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
2340 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
2342 { rtfObjAttr, rtfObjHt, "objh", 0 },
2343 { rtfObjAttr, rtfObjWid, "objw", 0 },
2344 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
2345 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
2346 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
2347 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
2348 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
2349 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
2350 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
2351 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
2352 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2354 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2355 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2356 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2357 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2358 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2360 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2361 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2364 * Associated character formatting attributes
2367 { rtfACharAttr, rtfACBold, "ab", 0 },
2368 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2369 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2370 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2371 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2372 { rtfACharAttr, rtfACFontNum, "af", 0 },
2373 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2374 { rtfACharAttr, rtfACItalic, "ai", 0 },
2375 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2376 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2377 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2378 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2379 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2380 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2381 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2382 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2383 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2384 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2385 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2388 * Footnote attributes
2391 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2394 * Key code attributes
2397 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2398 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2399 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2400 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2403 * Bookmark attributes
2406 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2407 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2410 * Index entry attributes
2413 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2414 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2415 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2418 * Table of contents attributes
2421 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2422 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2425 * Drawing object attributes
2428 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2429 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2430 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2431 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2432 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2433 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2434 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2435 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2437 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2438 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2439 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2440 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2441 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2442 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2443 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2444 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2445 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2446 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2447 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2449 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2450 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2451 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2452 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2454 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2455 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2456 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2457 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2458 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2459 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2460 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2461 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2462 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2463 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2464 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2465 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2466 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2467 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2468 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2469 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2470 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2472 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2473 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2474 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2476 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2477 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2478 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2480 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2481 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2483 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2484 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2485 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2486 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2487 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2488 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2489 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2490 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2491 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2492 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2493 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2494 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2496 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2497 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2498 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2499 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2500 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2501 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2502 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2503 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2505 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2506 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2507 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2508 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2509 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2510 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2511 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2512 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2513 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2514 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2515 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2517 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2518 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2519 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2521 { rtfVersion, -1, "rtf", 0 },
2522 { rtfDefFont, -1, "deff", 0 },
2524 { 0, -1, (char *) NULL, 0 }
2529 * Initialize lookup table hash values. Only need to do this once.
2532 static void LookupInit(void)
2534 static int inited = 0;
2535 RTFKey *rp;
2537 if (inited == 0)
2539 for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
2540 rp->rtfKHash = Hash (rp->rtfKStr);
2541 ++inited;
2547 * Determine major and minor number of control token. If it's
2548 * not found, the class turns into rtfUnknown.
2551 static void Lookup(char *s)
2553 RTFKey *rp;
2554 int hash;
2556 TRACE("\n");
2557 ++s; /* skip over the leading \ character */
2558 hash = Hash (s);
2559 for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
2561 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2563 rtfClass = rtfControl;
2564 rtfMajor = rp->rtfKMajor;
2565 rtfMinor = rp->rtfKMinor;
2566 return;
2569 rtfClass = rtfUnknown;
2574 * Compute hash value of symbol
2577 static int Hash(char *s)
2579 char c;
2580 int val = 0;
2582 while ((c = *s++) != '\0')
2583 val += (int) c;
2584 return (val);
2588 /* ---------------------------------------------------------------------- */
2591 * Memory allocation routines
2596 * Return pointer to block of size bytes, or NULL if there's
2597 * not enough memory available.
2599 * This is called through RTFAlloc(), a define which coerces the
2600 * argument to int. This avoids the persistent problem of allocation
2601 * failing under THINK C when a long is passed.
2604 char *_RTFAlloc(int size)
2606 return HeapAlloc(RICHED32_hHeap, 0, size);
2611 * Saves a string on the heap and returns a pointer to it.
2615 char *RTFStrSave(char *s)
2617 char *p;
2619 if ((p = RTFAlloc ((int) (strlen (s) + 1))) == (char *) NULL)
2620 return ((char *) NULL);
2621 return (strcpy (p, s));
2625 void RTFFree(char *p)
2627 if (p != (char *) NULL)
2628 HeapFree(RICHED32_hHeap, 0, p);
2632 /* ---------------------------------------------------------------------- */
2636 * Token comparison routines
2639 int RTFCheckCM(int class, int major)
2641 return (rtfClass == class && rtfMajor == major);
2645 int RTFCheckCMM(int class, int major, int minor)
2647 return (rtfClass == class && rtfMajor == major && rtfMinor == minor);
2651 int RTFCheckMM(int major, int minor)
2653 return (rtfMajor == major && rtfMinor == minor);
2657 /* ---------------------------------------------------------------------- */
2660 int RTFCharToHex(char c)
2662 if (isupper (c))
2663 c = tolower (c);
2664 if (isdigit (c))
2665 return (c - '0'); /* '0'..'9' */
2666 return (c - 'a' + 10); /* 'a'..'f' */
2670 int RTFHexToChar(int i)
2672 if (i < 10)
2673 return (i + '0');
2674 return (i - 10 + 'a');
2678 /* ---------------------------------------------------------------------- */
2681 * RTFReadOutputMap() -- Read output translation map
2685 * Read in an array describing the relation between the standard character set
2686 * and an RTF translator's corresponding output sequences. Each line consists
2687 * of a standard character name and the output sequence for that character.
2689 * outMap is an array of strings into which the sequences should be placed.
2690 * It should be declared like this in the calling program:
2692 * char *outMap[rtfSC_MaxChar];
2694 * reinit should be non-zero if outMap should be initialized
2695 * zero otherwise.
2699 int RTFReadOutputMap(char *outMap[], int reinit)
2701 int i;
2702 int stdCode;
2703 char *name, *seq;
2705 if (reinit)
2707 for (i = 0; i < rtfSC_MaxChar; i++)
2709 outMap[i] = (char *) NULL;
2713 for (i=0 ;i< sizeof(text_map)/sizeof(char*); i+=2)
2715 name = text_map[i];
2716 seq = text_map[i+1];
2717 stdCode = RTFStdCharCode( name );
2718 outMap[stdCode] = seq;
2721 return (1);
2724 /* ---------------------------------------------------------------------- */
2727 * Open a library file.
2731 static FILE *(*libFileOpen) () = NULL;
2735 void RTFSetOpenLibFileProc(FILE *(*proc)())
2737 libFileOpen = proc;
2741 FILE *RTFOpenLibFile (char *file, char *mode)
2743 if (libFileOpen == NULL)
2744 return ((FILE *) NULL);
2745 return ((*libFileOpen) (file, mode));
2749 /* ---------------------------------------------------------------------- */
2752 * Print message. Default is to send message to stderr
2753 * but this may be overridden with RTFSetMsgProc().
2755 * Message should include linefeeds as necessary. If the default
2756 * function is overridden, the overriding function may want to
2757 * map linefeeds to another line ending character or sequence if
2758 * the host system doesn't use linefeeds.
2762 static void DefaultMsgProc(char *s)
2764 MESSAGE( "%s", s);
2768 static RTFFuncPtr msgProc = DefaultMsgProc;
2771 void RTFSetMsgProc(RTFFuncPtr proc)
2773 msgProc = proc;
2777 void RTFMsg (char *fmt, ...)
2779 char buf[rtfBufSiz];
2781 va_list args;
2782 va_start (args,fmt);
2783 vsprintf (buf, fmt, args);
2784 va_end (args);
2785 (*msgProc) (buf);
2789 /* ---------------------------------------------------------------------- */
2793 * Process termination. Print error message and exit. Also prints
2794 * current token, and current input line number and position within
2795 * line if any input has been read from the current file. (No input
2796 * has been read if prevChar is EOF).
2799 static void DefaultPanicProc(char *s)
2801 MESSAGE( "%s", s);
2802 /*exit (1);*/
2806 static RTFFuncPtr panicProc = DefaultPanicProc;
2809 void RTFSetPanicProc(RTFFuncPtr proc)
2811 panicProc = proc;
2815 void RTFPanic(char *fmt, ...)
2817 char buf[rtfBufSiz];
2819 va_list args;
2820 va_start (args,fmt);
2821 vsprintf (buf, fmt, args);
2822 va_end (args);
2823 (void) strcat (buf, "\n");
2824 if (prevChar != EOF && rtfTextBuf != (char *) NULL)
2826 sprintf (buf + strlen (buf),
2827 "Last token read was \"%s\" near line %ld, position %d.\n",
2828 rtfTextBuf, rtfLineNum, rtfLinePos);
2830 (*panicProc) (buf);