- Separate application calls to ShowOwnedPopups from Wine calls (in
[wine.git] / dlls / richedit / reader.c
blob826f90cb97d0bc847b9a52f929f1d2cdef709d68
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>
75 #include "charlist.h"
76 #include "windows.h"
77 #include "debugtools.h"
79 extern HANDLE RICHED32_hHeap;
82 * Return pointer to new element of type t, or NULL
83 * if no memory available.
86 # define New(t) ((t *) RTFAlloc ((int) sizeof (t)))
88 /* maximum number of character values representable in a byte */
90 # define charSetSize 256
92 /* charset stack size */
94 # define maxCSStack 10
96 static int _RTFGetChar();
97 static void _RTFGetToken ();
98 static void _RTFGetToken2 ();
99 static int GetChar ();
100 static void ReadFontTbl ();
101 static void ReadColorTbl ();
102 static void ReadStyleSheet ();
103 static void ReadInfoGroup ();
104 static void ReadPictGroup ();
105 static void ReadObjGroup ();
106 static void LookupInit ();
107 static void Lookup ();
108 static int Hash ();
110 static void CharSetInit ();
111 static void ReadCharSetMaps ();
115 * Public variables (listed in rtf.h)
118 int rtfClass;
119 int rtfMajor;
120 int rtfMinor;
121 int rtfParam;
122 char *rtfTextBuf = (char *) NULL;
123 int rtfTextLen;
125 long rtfLineNum;
126 int rtfLinePos;
130 * Private stuff
133 static int pushedChar; /* pushback char if read too far */
135 static int pushedClass; /* pushed token info for RTFUngetToken() */
136 static int pushedMajor;
137 static int pushedMinor;
138 static int pushedParam;
139 static char *pushedTextBuf = (char *) NULL;
141 static int prevChar;
142 static int bumpLine;
144 static RTFFont *fontList = (RTFFont *) NULL; /* these lists MUST be */
145 static RTFColor *colorList = (RTFColor *) NULL; /* initialized to NULL */
146 static RTFStyle *styleList = (RTFStyle *) NULL;
148 static char *inputName = (char *) NULL;
149 static char *outputName = (char *) NULL;
151 static EDITSTREAM editstream;
152 static CHARLIST inputCharList = {0, NULL, NULL};
155 * This array is used to map standard character names onto their numeric codes.
156 * The position of the name within the array is the code.
157 * stdcharnames.h is generated in the ../h directory.
160 static char *stdCharName[] =
162 # include "stdcharnames.h"
163 (char *) NULL
168 * These arrays are used to map RTF input character values onto the standard
169 * character names represented by the values. Input character values are
170 * used as indices into the arrays to produce standard character codes.
174 static char *genCharSetFile = (char *) NULL;
175 static int genCharCode[charSetSize]; /* general */
176 static int haveGenCharSet = 0;
178 static char *symCharSetFile = (char *) NULL;
179 static int symCharCode[charSetSize]; /* symbol */
180 static int haveSymCharSet = 0;
182 static int curCharSet = rtfCSGeneral;
183 static int *curCharCode = genCharCode;
186 * By default, the reader is configured to handle charset mapping invisibly,
187 * including reading the charset files and switching charset maps as necessary
188 * for Symbol font.
191 static int autoCharSetFlags;
194 * Stack for keeping track of charset map on group begin/end. This is
195 * necessary because group termination reverts the font to the previous
196 * value, which may implicitly change it.
199 static int csStack[maxCSStack];
200 static int csTop = 0;
203 * Get a char from the charlist. The charlist is used to store characters
204 * from the editstream.
208 int
209 _RTFGetChar()
211 char myChar;
212 if(CHARLIST_GetNbItems(&inputCharList) == 0)
214 char buff[10];
215 long pcb;
216 editstream.pfnCallback(editstream.dwCookie, buff, 1, &pcb);
217 if(pcb == 0)
218 return EOF;
219 else
220 CHARLIST_Enqueue(&inputCharList, buff[0]);
222 myChar = CHARLIST_Dequeue(&inputCharList);
223 return (int) myChar;
226 void
227 RTFSetEditStream(EDITSTREAM *es)
229 editstream.dwCookie = es->dwCookie;
230 editstream.dwError = es->dwError;
231 editstream.pfnCallback = es->pfnCallback;
235 * Initialize the reader. This may be called multiple times,
236 * to read multiple files. The only thing not reset is the input
237 * stream; that must be done with RTFSetStream().
240 void
241 RTFInit ()
243 int i;
244 RTFColor *cp;
245 RTFFont *fp;
246 RTFStyle *sp;
247 RTFStyleElt *eltList, *ep;
249 if (rtfTextBuf == (char *) NULL) /* initialize the text buffers */
251 rtfTextBuf = RTFAlloc (rtfBufSiz);
252 pushedTextBuf = RTFAlloc (rtfBufSiz);
253 if (rtfTextBuf == (char *) NULL
254 || pushedTextBuf == (char *) NULL)
255 RTFPanic ("Cannot allocate text buffers.");
256 rtfTextBuf[0] = pushedTextBuf[0] = '\0';
259 RTFFree (inputName);
260 RTFFree (outputName);
261 inputName = outputName = (char *) NULL;
263 /* initialize lookup table */
264 LookupInit ();
266 for (i = 0; i < rtfMaxClass; i++)
267 RTFSetClassCallback (i, (RTFFuncPtr) NULL);
268 for (i = 0; i < rtfMaxDestination; i++)
269 RTFSetDestinationCallback (i, (RTFFuncPtr) NULL);
271 /* install built-in destination readers */
272 RTFSetDestinationCallback (rtfFontTbl, ReadFontTbl);
273 RTFSetDestinationCallback (rtfColorTbl, ReadColorTbl);
274 RTFSetDestinationCallback (rtfStyleSheet, ReadStyleSheet);
275 RTFSetDestinationCallback (rtfInfo, ReadInfoGroup);
276 RTFSetDestinationCallback (rtfPict, ReadPictGroup);
277 RTFSetDestinationCallback (rtfObject, ReadObjGroup);
280 RTFSetReadHook ((RTFFuncPtr) NULL);
282 /* dump old lists if necessary */
284 while (fontList != (RTFFont *) NULL)
286 fp = fontList->rtfNextFont;
287 RTFFree (fontList->rtfFName);
288 RTFFree ((char *) fontList);
289 fontList = fp;
291 while (colorList != (RTFColor *) NULL)
293 cp = colorList->rtfNextColor;
294 RTFFree ((char *) colorList);
295 colorList = cp;
297 while (styleList != (RTFStyle *) NULL)
299 sp = styleList->rtfNextStyle;
300 eltList = styleList->rtfSSEList;
301 while (eltList != (RTFStyleElt *) NULL)
303 ep = eltList->rtfNextSE;
304 RTFFree (eltList->rtfSEText);
305 RTFFree ((char *) eltList);
306 eltList = ep;
308 RTFFree (styleList->rtfSName);
309 RTFFree ((char *) styleList);
310 styleList = sp;
313 rtfClass = -1;
314 pushedClass = -1;
315 pushedChar = EOF;
317 rtfLineNum = 0;
318 rtfLinePos = 0;
319 prevChar = EOF;
320 bumpLine = 0;
322 CharSetInit ();
323 csTop = 0;
327 * Set or get the input or output file name. These are never guaranteed
328 * to be accurate, only insofar as the calling program makes them so.
331 void
332 RTFSetInputName (name)
333 char *name;
335 if ((inputName = RTFStrSave (name)) == (char *) NULL)
336 RTFPanic ("RTFSetInputName: out of memory");
340 char *
341 RTFGetInputName ()
343 return (inputName);
347 void
348 RTFSetOutputName (name)
349 char *name;
351 if ((outputName = RTFStrSave (name)) == (char *) NULL)
352 RTFPanic ("RTFSetOutputName: out of memory");
356 char *
357 RTFGetOutputName ()
359 return (outputName);
364 /* ---------------------------------------------------------------------- */
367 * Callback table manipulation routines
372 * Install or return a writer callback for a token class
376 static RTFFuncPtr ccb[rtfMaxClass]; /* class callbacks */
379 void
380 RTFSetClassCallback (class, callback)
381 int class;
382 RTFFuncPtr callback;
384 if (class >= 0 && class < rtfMaxClass)
385 ccb[class] = callback;
389 RTFFuncPtr
390 RTFGetClassCallback (class)
391 int class;
393 if (class >= 0 && class < rtfMaxClass)
394 return (ccb[class]);
395 return ((RTFFuncPtr) NULL);
400 * Install or return a writer callback for a destination type
403 static RTFFuncPtr dcb[rtfMaxDestination]; /* destination callbacks */
406 void
407 RTFSetDestinationCallback (dest, callback)
408 int dest;
409 RTFFuncPtr callback;
411 if (dest >= 0 && dest < rtfMaxDestination)
412 dcb[dest] = callback;
416 RTFFuncPtr
417 RTFGetDestinationCallback (dest)
418 int dest;
420 if (dest >= 0 && dest < rtfMaxDestination)
421 return (dcb[dest]);
422 return ((RTFFuncPtr) NULL);
426 /* ---------------------------------------------------------------------- */
429 * Token reading routines
434 * Read the input stream, invoking the writer's callbacks
435 * where appropriate.
438 void
439 RTFRead ()
441 while (RTFGetToken () != rtfEOF)
442 RTFRouteToken ();
447 * Route a token. If it's a destination for which a reader is
448 * installed, process the destination internally, otherwise
449 * pass the token to the writer's class callback.
452 void
453 RTFRouteToken ()
455 RTFFuncPtr p;
457 if (rtfClass < 0 || rtfClass >= rtfMaxClass) /* watchdog */
459 RTFPanic ("Unknown class %d: %s (reader malfunction)",
460 rtfClass, rtfTextBuf);
462 if (RTFCheckCM (rtfControl, rtfDestination))
464 /* invoke destination-specific callback if there is one */
465 if ((p = RTFGetDestinationCallback (rtfMinor))
466 != (RTFFuncPtr) NULL)
468 (*p) ();
469 return;
472 /* invoke class callback if there is one */
473 if ((p = RTFGetClassCallback (rtfClass)) != (RTFFuncPtr) NULL)
474 (*p) ();
479 * Skip to the end of the current group. When this returns,
480 * writers that maintain a state stack may want to call their
481 * state unstacker; global vars will still be set to the group's
482 * closing brace.
485 void
486 RTFSkipGroup ()
488 int level = 1;
490 while (RTFGetToken () != rtfEOF)
492 if (rtfClass == rtfGroup)
494 if (rtfMajor == rtfBeginGroup)
495 ++level;
496 else if (rtfMajor == rtfEndGroup)
498 if (--level < 1)
499 break; /* end of initial group */
507 * Read one token. Call the read hook if there is one. The
508 * token class is the return value. Returns rtfEOF when there
509 * are no more tokens.
513 RTFGetToken ()
515 RTFFuncPtr p;
517 for (;;)
519 _RTFGetToken ();
520 if ((p = RTFGetReadHook ()) != (RTFFuncPtr) NULL)
521 (*p) (); /* give read hook a look at token */
523 /* Silently discard newlines, carriage returns, nulls. */
524 if (!(rtfClass == rtfText
525 && (rtfMajor == '\n' || rtfMajor == '\r'
526 || rtfMajor == '\0')))
527 break;
529 return (rtfClass);
534 * Install or return a token reader hook.
537 static RTFFuncPtr readHook;
540 void
541 RTFSetReadHook (f)
542 RTFFuncPtr f;
544 readHook = f;
548 RTFFuncPtr
549 RTFGetReadHook ()
551 return (readHook);
555 void
556 RTFUngetToken ()
558 if (pushedClass >= 0) /* there's already an ungotten token */
559 RTFPanic ("cannot unget two tokens");
560 if (rtfClass < 0)
561 RTFPanic ("no token to unget");
562 pushedClass = rtfClass;
563 pushedMajor = rtfMajor;
564 pushedMinor = rtfMinor;
565 pushedParam = rtfParam;
566 (void) strcpy (pushedTextBuf, rtfTextBuf);
571 RTFPeekToken ()
573 _RTFGetToken ();
574 RTFUngetToken ();
575 return (rtfClass);
579 static void
580 _RTFGetToken ()
582 RTFFont *fp;
584 /* first check for pushed token from RTFUngetToken() */
586 if (pushedClass >= 0)
588 rtfClass = pushedClass;
589 rtfMajor = pushedMajor;
590 rtfMinor = pushedMinor;
591 rtfParam = pushedParam;
592 (void) strcpy (rtfTextBuf, pushedTextBuf);
593 rtfTextLen = strlen (rtfTextBuf);
594 pushedClass = -1;
595 return;
599 * Beyond this point, no token is ever seen twice, which is
600 * important, e.g., for making sure no "}" pops the font stack twice.
603 _RTFGetToken2 ();
604 if (rtfClass == rtfText) /* map RTF char to standard code */
605 rtfMinor = RTFMapChar (rtfMajor);
608 * If auto-charset stuff is activated, see if anything needs doing,
609 * like reading the charset maps or switching between them.
612 if (autoCharSetFlags == 0)
613 return;
615 if ((autoCharSetFlags & rtfReadCharSet)
616 && RTFCheckCM (rtfControl, rtfCharSet))
618 ReadCharSetMaps ();
620 else if ((autoCharSetFlags & rtfSwitchCharSet)
621 && RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum))
623 if ((fp = RTFGetFont (rtfParam)) != (RTFFont *) NULL)
625 if (strncmp (fp->rtfFName, "Symbol", 6) == 0)
626 curCharSet = rtfCSSymbol;
627 else
628 curCharSet = rtfCSGeneral;
629 RTFSetCharSet (curCharSet);
632 else if ((autoCharSetFlags & rtfSwitchCharSet) && rtfClass == rtfGroup)
634 switch (rtfMajor)
636 case rtfBeginGroup:
637 if (csTop >= maxCSStack)
638 RTFPanic ("_RTFGetToken: stack overflow");
639 csStack[csTop++] = curCharSet;
640 break;
641 case rtfEndGroup:
642 if (csTop <= 0)
643 RTFPanic ("_RTFGetToken: stack underflow");
644 curCharSet = csStack[--csTop];
645 RTFSetCharSet (curCharSet);
646 break;
652 /* this shouldn't be called anywhere but from _RTFGetToken() */
654 static void
655 _RTFGetToken2 ()
657 int sign;
658 int c;
660 /* initialize token vars */
662 rtfClass = rtfUnknown;
663 rtfParam = rtfNoParam;
664 rtfTextBuf[rtfTextLen = 0] = '\0';
666 /* get first character, which may be a pushback from previous token */
668 if (pushedChar != EOF)
670 c = pushedChar;
671 rtfTextBuf[rtfTextLen++] = c;
672 rtfTextBuf[rtfTextLen] = '\0';
673 pushedChar = EOF;
675 else if ((c = GetChar ()) == EOF)
677 rtfClass = rtfEOF;
678 return;
681 if (c == '{')
683 rtfClass = rtfGroup;
684 rtfMajor = rtfBeginGroup;
685 return;
687 if (c == '}')
689 rtfClass = rtfGroup;
690 rtfMajor = rtfEndGroup;
691 return;
693 if (c != '\\')
696 * Two possibilities here:
697 * 1) ASCII 9, effectively like \tab control symbol
698 * 2) literal text char
700 if (c == '\t') /* ASCII 9 */
702 rtfClass = rtfControl;
703 rtfMajor = rtfSpecialChar;
704 rtfMinor = rtfTab;
706 else
708 rtfClass = rtfText;
709 rtfMajor = c;
711 return;
713 if ((c = GetChar ()) == EOF)
715 /* early eof, whoops (class is rtfUnknown) */
716 return;
718 if (!isalpha (c))
721 * Three possibilities here:
722 * 1) hex encoded text char, e.g., \'d5, \'d3
723 * 2) special escaped text char, e.g., \{, \}
724 * 3) control symbol, e.g., \_, \-, \|, \<10>
726 if (c == '\'') /* hex char */
728 int c2;
730 if ((c = GetChar ()) != EOF && (c2 = GetChar ()) != EOF)
732 /* should do isxdigit check! */
733 rtfClass = rtfText;
734 rtfMajor = RTFCharToHex (c) * 16
735 + RTFCharToHex (c2);
736 return;
738 /* early eof, whoops (class is rtfUnknown) */
739 return;
742 /* escaped char */
743 /*if (index (":{}\\", c) != (char *) NULL)*/ /* escaped char */
744 if (c == ':' || c == '{' || c == '}' || c == '\\')
746 rtfClass = rtfText;
747 rtfMajor = c;
748 return;
751 /* control symbol */
752 Lookup (rtfTextBuf); /* sets class, major, minor */
753 return;
755 /* control word */
756 while (isalpha (c))
758 if ((c = GetChar ()) == EOF)
759 break;
763 * At this point, the control word is all collected, so the
764 * major/minor numbers are determined before the parameter
765 * (if any) is scanned. There will be one too many characters
766 * in the buffer, though, so fix up before and restore after
767 * looking up.
770 if (c != EOF)
771 rtfTextBuf[rtfTextLen-1] = '\0';
772 Lookup (rtfTextBuf); /* sets class, major, minor */
773 if (c != EOF)
774 rtfTextBuf[rtfTextLen-1] = c;
777 * Should be looking at first digit of parameter if there
778 * is one, unless it's negative. In that case, next char
779 * is '-', so need to gobble next char, and remember sign.
782 sign = 1;
783 if (c == '-')
785 sign = -1;
786 c = GetChar ();
788 if (c != EOF && isdigit (c))
790 rtfParam = 0;
791 while (isdigit (c)) /* gobble parameter */
793 rtfParam = rtfParam * 10 + c - '0';
794 if ((c = GetChar ()) == EOF)
795 break;
797 rtfParam *= sign;
800 * If control symbol delimiter was a blank, gobble it.
801 * Otherwise the character is first char of next token, so
802 * push it back for next call. In either case, delete the
803 * delimiter from the token buffer.
805 if (c != EOF)
807 if (c != ' ')
808 pushedChar = c;
809 rtfTextBuf[--rtfTextLen] = '\0';
815 * Read the next character from the input. This handles setting the
816 * current line and position-within-line variables. Those variable are
817 * set correctly whether lines end with CR, LF, or CRLF (the last being
818 * the tricky case).
820 * bumpLine indicates whether the line number should be incremented on
821 * the *next* input character.
825 static int
826 GetChar ()
828 int c;
829 int oldBumpLine;
831 if ((c = _RTFGetChar()) != EOF)
833 rtfTextBuf[rtfTextLen++] = c;
834 rtfTextBuf[rtfTextLen] = '\0';
836 if (prevChar == EOF)
837 bumpLine = 1;
838 oldBumpLine = bumpLine; /* non-zero if prev char was line ending */
839 bumpLine = 0;
840 if (c == '\r')
841 bumpLine = 1;
842 else if (c == '\n')
844 bumpLine = 1;
845 if (prevChar == '\r') /* oops, previous \r wasn't */
846 oldBumpLine = 0; /* really a line ending */
848 ++rtfLinePos;
849 if (oldBumpLine) /* were we supposed to increment the */
850 { /* line count on this char? */
851 ++rtfLineNum;
852 rtfLinePos = 1;
854 prevChar = c;
855 return (c);
860 * Synthesize a token by setting the global variables to the
861 * values supplied. Typically this is followed with a call
862 * to RTFRouteToken().
864 * If a param value other than rtfNoParam is passed, it becomes
865 * part of the token text.
868 void
869 RTFSetToken (class, major, minor, param, text)
870 int class, major, minor, param;
871 char *text;
873 rtfClass = class;
874 rtfMajor = major;
875 rtfMinor = minor;
876 rtfParam = param;
877 if (param == rtfNoParam)
878 (void) strcpy (rtfTextBuf, text);
879 else
880 sprintf (rtfTextBuf, "%s%d", text, param);
881 rtfTextLen = strlen (rtfTextBuf);
885 /* ---------------------------------------------------------------------- */
888 * Routines to handle mapping of RTF character sets
889 * onto standard characters.
891 * RTFStdCharCode(name) given char name, produce numeric code
892 * RTFStdCharName(code) given char code, return name
893 * RTFMapChar(c) map input (RTF) char code to std code
894 * RTFSetCharSet(id) select given charset map
895 * RTFGetCharSet() get current charset map
897 * See ../h/README for more information about charset names and codes.
902 * Initialize charset stuff.
905 static void
906 CharSetInit ()
908 autoCharSetFlags = (rtfReadCharSet | rtfSwitchCharSet);
909 RTFFree (genCharSetFile);
910 genCharSetFile = (char *) NULL;
911 haveGenCharSet = 0;
912 RTFFree (symCharSetFile);
913 symCharSetFile = (char *) NULL;
914 haveSymCharSet = 0;
915 curCharSet = rtfCSGeneral;
916 curCharCode = genCharCode;
921 * Specify the name of a file to be read when auto-charset-file reading is
922 * done.
925 void
926 RTFSetCharSetMap (name, csId)
927 char *name;
928 int csId;
930 if ((name = RTFStrSave (name)) == (char *) NULL) /* make copy */
931 RTFPanic ("RTFSetCharSetMap: out of memory");
932 switch (csId)
934 case rtfCSGeneral:
935 RTFFree (genCharSetFile); /* free any previous value */
936 genCharSetFile = name;
937 break;
938 case rtfCSSymbol:
939 RTFFree (symCharSetFile); /* free any previous value */
940 symCharSetFile = name;
941 break;
947 * Do auto-charset-file reading.
948 * will always use the ansi charset no mater what the value
949 * of the rtfTextBuf is.
951 * TODO: add support for other charset in the future.
955 static void
956 ReadCharSetMaps ()
958 char buf[rtfBufSiz];
960 if (genCharSetFile != (char *) NULL)
961 (void) strcpy (buf, genCharSetFile);
962 else
963 sprintf (buf, "%s-gen", &rtfTextBuf[1]);
964 if (RTFReadCharSetMap (rtfCSGeneral) == 0)
965 RTFPanic ("ReadCharSetMaps: Cannot read charset map %s", buf);
966 if (symCharSetFile != (char *) NULL)
967 (void) strcpy (buf, symCharSetFile);
968 else
969 sprintf (buf, "%s-sym", &rtfTextBuf[1]);
970 if (RTFReadCharSetMap (rtfCSSymbol) == 0)
971 RTFPanic ("ReadCharSetMaps: Cannot read charset map %s", buf);
977 * Convert a CaracterSetMap (caracter_name, caracter) into
978 * this form : array[caracter_ident] = caracter;
982 RTFReadCharSetMap (csId)
983 int csId;
985 int *stdCodeArray;
986 int i;
987 switch (csId)
989 default:
990 return (0); /* illegal charset id */
991 case rtfCSGeneral:
993 haveGenCharSet = 1;
994 stdCodeArray = genCharCode;
995 for (i = 0; i < charSetSize; i++)
997 stdCodeArray[i] = rtfSC_nothing;
1000 for ( i = 0 ; i< sizeof(ansi_gen)/(sizeof(int));i+=2)
1002 stdCodeArray[ ansi_gen[i+1] ] = ansi_gen[i];
1004 break;
1006 case rtfCSSymbol:
1008 haveSymCharSet = 1;
1009 stdCodeArray = symCharCode;
1010 for (i = 0; i < charSetSize; i++)
1012 stdCodeArray[i] = rtfSC_nothing;
1015 for ( i = 0 ; i< sizeof(ansi_sym)/(sizeof(int));i+=2)
1017 stdCodeArray[ ansi_sym[i+1] ] = ansi_sym[i];
1019 break;
1022 return (1);
1027 * Given a standard character name (a string), find its code (a number).
1028 * Return -1 if name is unknown.
1032 RTFStdCharCode (name)
1033 char *name;
1035 int i;
1037 for (i = 0; i < rtfSC_MaxChar; i++)
1039 if (strcmp (name, stdCharName[i]) == 0)
1040 return (i);
1042 return (-1);
1047 * Given a standard character code (a number), find its name (a string).
1048 * Return NULL if code is unknown.
1051 char *
1052 RTFStdCharName (code)
1053 int code;
1055 if (code < 0 || code >= rtfSC_MaxChar)
1056 return ((char *) NULL);
1057 return (stdCharName[code]);
1062 * Given an RTF input character code, find standard character code.
1063 * The translator should read the appropriate charset maps when it finds a
1064 * charset control. However, the file might not contain one. In this
1065 * case, no map will be available. When the first attempt is made to
1066 * map a character under these circumstances, RTFMapChar() assumes ANSI
1067 * and reads the map as necessary.
1071 RTFMapChar (c)
1072 int c;
1074 switch (curCharSet)
1076 case rtfCSGeneral:
1077 if (!haveGenCharSet)
1079 if (RTFReadCharSetMap (rtfCSGeneral) == 0)
1080 RTFPanic ("RTFMapChar: cannot read ansi-gen");
1082 break;
1083 case rtfCSSymbol:
1084 if (!haveSymCharSet)
1086 if (RTFReadCharSetMap (rtfCSSymbol) == 0)
1087 RTFPanic ("RTFMapChar: cannot read ansi-sym");
1089 break;
1091 if (c < 0 || c >= charSetSize)
1092 return (rtfSC_nothing);
1093 return (curCharCode[c]);
1098 * Set the current character set. If csId is illegal, uses general charset.
1101 void
1102 RTFSetCharSet (csId)
1103 int csId;
1105 switch (csId)
1107 default: /* use general if csId unknown */
1108 case rtfCSGeneral:
1109 curCharCode = genCharCode;
1110 curCharSet = csId;
1111 break;
1112 case rtfCSSymbol:
1113 curCharCode = symCharCode;
1114 curCharSet = csId;
1115 break;
1121 RTFGetCharSet ()
1123 return (curCharSet);
1127 /* ---------------------------------------------------------------------- */
1130 * Special destination readers. They gobble the destination so the
1131 * writer doesn't have to deal with them. That's wrong for any
1132 * translator that wants to process any of these itself. In that
1133 * case, these readers should be overridden by installing a different
1134 * destination callback.
1136 * NOTE: The last token read by each of these reader will be the
1137 * destination's terminating '}', which will then be the current token.
1138 * That '}' token is passed to RTFRouteToken() - the writer has already
1139 * seen the '{' that began the destination group, and may have pushed a
1140 * state; it also needs to know at the end of the group that a state
1141 * should be popped.
1143 * It's important that rtf.h and the control token lookup table list
1144 * as many symbols as possible, because these destination readers
1145 * unfortunately make strict assumptions about the input they expect,
1146 * and a token of class rtfUnknown will throw them off easily.
1151 * Read { \fonttbl ... } destination. Old font tables don't have
1152 * braces around each table entry; try to adjust for that.
1155 static void
1156 ReadFontTbl ()
1158 RTFFont *fp = NULL;
1159 char buf[rtfBufSiz], *bp;
1160 int old = -1;
1161 char *fn = "ReadFontTbl";
1163 for (;;)
1165 (void) RTFGetToken ();
1166 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1167 break;
1168 if (old < 0) /* first entry - determine tbl type */
1170 if (RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum))
1171 old = 1; /* no brace */
1172 else if (RTFCheckCM (rtfGroup, rtfBeginGroup))
1173 old = 0; /* brace */
1174 else /* can't tell! */
1175 RTFPanic ("%s: Cannot determine format", fn);
1177 if (old == 0) /* need to find "{" here */
1179 if (!RTFCheckCM (rtfGroup, rtfBeginGroup))
1180 RTFPanic ("%s: missing \"{\"", fn);
1181 (void) RTFGetToken (); /* yes, skip to next token */
1183 if ((fp = New (RTFFont)) == (RTFFont *) NULL)
1184 RTFPanic ("%s: cannot allocate font entry", fn);
1186 fp->rtfNextFont = fontList;
1187 fontList = fp;
1189 fp->rtfFName = (char *) NULL;
1190 fp->rtfFAltName = (char *) NULL;
1191 fp->rtfFNum = -1;
1192 fp->rtfFFamily = 0;
1193 fp->rtfFCharSet = 0;
1194 fp->rtfFPitch = 0;
1195 fp->rtfFType = 0;
1196 fp->rtfFCodePage = 0;
1198 while (rtfClass != rtfEOF
1199 && !RTFCheckCM (rtfText, ';')
1200 && !RTFCheckCM (rtfGroup, rtfEndGroup))
1202 if (rtfClass == rtfControl)
1204 switch (rtfMajor)
1206 default:
1207 /* ignore token but announce it */
1208 RTFMsg ("%s: unknown token \"%s\"\n",
1209 fn, rtfTextBuf);
1210 case rtfFontFamily:
1211 fp->rtfFFamily = rtfMinor;
1212 break;
1213 case rtfCharAttr:
1214 switch (rtfMinor)
1216 default:
1217 break; /* ignore unknown? */
1218 case rtfFontNum:
1219 fp->rtfFNum = rtfParam;
1220 break;
1222 break;
1223 case rtfFontAttr:
1224 switch (rtfMinor)
1226 default:
1227 break; /* ignore unknown? */
1228 case rtfFontCharSet:
1229 fp->rtfFCharSet = rtfParam;
1230 break;
1231 case rtfFontPitch:
1232 fp->rtfFPitch = rtfParam;
1233 break;
1234 case rtfFontCodePage:
1235 fp->rtfFCodePage = rtfParam;
1236 break;
1237 case rtfFTypeNil:
1238 case rtfFTypeTrueType:
1239 fp->rtfFType = rtfParam;
1240 break;
1242 break;
1245 else if (RTFCheckCM (rtfGroup, rtfBeginGroup)) /* dest */
1247 RTFSkipGroup (); /* ignore for now */
1249 else if (rtfClass == rtfText) /* font name */
1251 bp = buf;
1252 while (rtfClass != rtfEOF
1253 && !RTFCheckCM (rtfText, ';')
1254 && !RTFCheckCM (rtfGroup, rtfEndGroup))
1256 *bp++ = rtfMajor;
1257 (void) RTFGetToken ();
1260 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
1261 if(RTFCheckCM (rtfGroup, rtfEndGroup))
1263 RTFUngetToken ();
1265 *bp = '\0';
1266 fp->rtfFName = RTFStrSave (buf);
1267 if (fp->rtfFName == (char *) NULL)
1268 RTFPanic ("%s: cannot allocate font name", fn);
1269 /* already have next token; don't read one */
1270 /* at bottom of loop */
1271 continue;
1273 else
1275 /* ignore token but announce it */
1276 RTFMsg ("%s: unknown token \"%s\"\n",
1277 fn, rtfTextBuf);
1279 (void) RTFGetToken ();
1281 if (old == 0) /* need to see "}" here */
1283 (void) RTFGetToken ();
1284 if (!RTFCheckCM (rtfGroup, rtfEndGroup))
1285 RTFPanic ("%s: missing \"}\"", fn);
1288 if (fp->rtfFNum == -1)
1289 RTFPanic ("%s: missing font number", fn);
1291 * Could check other pieces of structure here, too, I suppose.
1293 RTFRouteToken (); /* feed "}" back to router */
1298 * The color table entries have color values of -1 if
1299 * the default color should be used for the entry (only
1300 * a semi-colon is given in the definition, no color values).
1301 * There will be a problem if a partial entry (1 or 2 but
1302 * not 3 color values) is given. The possibility is ignored
1303 * here.
1306 static void
1307 ReadColorTbl ()
1309 RTFColor *cp;
1310 int cnum = 0;
1311 char *fn = "ReadColorTbl";
1313 for (;;)
1315 (void) RTFGetToken ();
1316 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1317 break;
1318 if ((cp = New (RTFColor)) == (RTFColor *) NULL)
1319 RTFPanic ("%s: cannot allocate color entry", fn);
1320 cp->rtfCNum = cnum++;
1321 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
1322 cp->rtfNextColor = colorList;
1323 colorList = cp;
1324 while (RTFCheckCM (rtfControl, rtfColorName))
1326 switch (rtfMinor)
1328 case rtfRed: cp->rtfCRed = rtfParam; break;
1329 case rtfGreen: cp->rtfCGreen = rtfParam; break;
1330 case rtfBlue: cp->rtfCBlue = rtfParam; break;
1332 RTFGetToken ();
1334 if (!RTFCheckCM (rtfText, (int) ';'))
1335 RTFPanic ("%s: malformed entry", fn);
1337 RTFRouteToken (); /* feed "}" back to router */
1342 * The "Normal" style definition doesn't contain any style number,
1343 * all others do. Normal style is given style rtfNormalStyleNum.
1346 static void
1347 ReadStyleSheet ()
1349 RTFStyle *sp;
1350 RTFStyleElt *sep, *sepLast;
1351 char buf[rtfBufSiz], *bp;
1352 char *fn = "ReadStyleSheet";
1354 for (;;)
1356 (void) RTFGetToken ();
1357 if (RTFCheckCM (rtfGroup, rtfEndGroup))
1358 break;
1359 if ((sp = New (RTFStyle)) == (RTFStyle *) NULL)
1360 RTFPanic ("%s: cannot allocate stylesheet entry", fn);
1361 sp->rtfSName = (char *) NULL;
1362 sp->rtfSNum = -1;
1363 sp->rtfSType = rtfParStyle;
1364 sp->rtfSAdditive = 0;
1365 sp->rtfSBasedOn = rtfNoStyleNum;
1366 sp->rtfSNextPar = -1;
1367 sp->rtfSSEList = sepLast = (RTFStyleElt *) NULL;
1368 sp->rtfNextStyle = styleList;
1369 sp->rtfExpanding = 0;
1370 styleList = sp;
1371 if (!RTFCheckCM (rtfGroup, rtfBeginGroup))
1372 RTFPanic ("%s: missing \"{\"", fn);
1373 for (;;)
1375 (void) RTFGetToken ();
1376 if (rtfClass == rtfEOF
1377 || RTFCheckCM (rtfText, ';'))
1378 break;
1379 if (rtfClass == rtfControl)
1381 if (RTFCheckMM (rtfSpecialChar, rtfOptDest))
1382 continue; /* ignore "\*" */
1383 if (RTFCheckMM (rtfParAttr, rtfStyleNum))
1385 sp->rtfSNum = rtfParam;
1386 sp->rtfSType = rtfParStyle;
1387 continue;
1389 if (RTFCheckMM (rtfCharAttr, rtfCharStyleNum))
1391 sp->rtfSNum = rtfParam;
1392 sp->rtfSType = rtfCharStyle;
1393 continue;
1395 if (RTFCheckMM (rtfSectAttr, rtfSectStyleNum))
1397 sp->rtfSNum = rtfParam;
1398 sp->rtfSType = rtfSectStyle;
1399 continue;
1401 if (RTFCheckMM (rtfStyleAttr, rtfBasedOn))
1403 sp->rtfSBasedOn = rtfParam;
1404 continue;
1406 if (RTFCheckMM (rtfStyleAttr, rtfAdditive))
1408 sp->rtfSAdditive = 1;
1409 continue;
1411 if (RTFCheckMM (rtfStyleAttr, rtfNext))
1413 sp->rtfSNextPar = rtfParam;
1414 continue;
1416 if ((sep = New (RTFStyleElt)) == (RTFStyleElt *) NULL)
1417 RTFPanic ("%s: cannot allocate style element", fn);
1418 sep->rtfSEClass = rtfClass;
1419 sep->rtfSEMajor = rtfMajor;
1420 sep->rtfSEMinor = rtfMinor;
1421 sep->rtfSEParam = rtfParam;
1422 if ((sep->rtfSEText = RTFStrSave (rtfTextBuf))
1423 == (char *) NULL)
1424 RTFPanic ("%s: cannot allocate style element text", fn);
1425 if (sepLast == (RTFStyleElt *) NULL)
1426 sp->rtfSSEList = sep; /* first element */
1427 else /* add to end */
1428 sepLast->rtfNextSE = sep;
1429 sep->rtfNextSE = (RTFStyleElt *) NULL;
1430 sepLast = sep;
1432 else if (RTFCheckCM (rtfGroup, rtfBeginGroup))
1435 * This passes over "{\*\keycode ... }, among
1436 * other things. A temporary (perhaps) hack.
1438 RTFSkipGroup ();
1439 continue;
1441 else if (rtfClass == rtfText) /* style name */
1443 bp = buf;
1444 while (rtfClass == rtfText)
1446 if (rtfMajor == ';')
1448 /* put back for "for" loop */
1449 (void) RTFUngetToken ();
1450 break;
1452 *bp++ = rtfMajor;
1453 (void) RTFGetToken ();
1455 *bp = '\0';
1456 if ((sp->rtfSName = RTFStrSave (buf)) == (char *) NULL)
1457 RTFPanic ("%s: cannot allocate style name", fn);
1459 else /* unrecognized */
1461 /* ignore token but announce it */
1462 RTFMsg ("%s: unknown token \"%s\"\n",
1463 fn, rtfTextBuf);
1466 (void) RTFGetToken ();
1467 if (!RTFCheckCM (rtfGroup, rtfEndGroup))
1468 RTFPanic ("%s: missing \"}\"", fn);
1471 * Check over the style structure. A name is a must.
1472 * If no style number was specified, check whether it's the
1473 * Normal style (in which case it's given style number
1474 * rtfNormalStyleNum). Note that some "normal" style names
1475 * just begin with "Normal" and can have other stuff following,
1476 * e.g., "Normal,Times 10 point". Ugh.
1478 * Some German RTF writers use "Standard" instead of "Normal".
1480 if (sp->rtfSName == (char *) NULL)
1481 RTFPanic ("%s: missing style name", fn);
1482 if (sp->rtfSNum < 0)
1484 if (strncmp (buf, "Normal", 6) != 0
1485 && strncmp (buf, "Standard", 8) != 0)
1486 RTFPanic ("%s: missing style number", fn);
1487 sp->rtfSNum = rtfNormalStyleNum;
1489 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1490 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1492 RTFRouteToken (); /* feed "}" back to router */
1496 static void
1497 ReadInfoGroup ()
1499 RTFSkipGroup ();
1500 RTFRouteToken (); /* feed "}" back to router */
1504 static void
1505 ReadPictGroup ()
1507 RTFSkipGroup ();
1508 RTFRouteToken (); /* feed "}" back to router */
1512 static void
1513 ReadObjGroup ()
1515 RTFSkipGroup ();
1516 RTFRouteToken (); /* feed "}" back to router */
1520 /* ---------------------------------------------------------------------- */
1523 * Routines to return pieces of stylesheet, or font or color tables.
1524 * References to style 0 are mapped onto the Normal style.
1528 RTFStyle *
1529 RTFGetStyle (num)
1530 int num;
1532 RTFStyle *s;
1534 if (num == -1)
1535 return (styleList);
1536 for (s = styleList; s != (RTFStyle *) NULL; s = s->rtfNextStyle)
1538 if (s->rtfSNum == num)
1539 break;
1541 return (s); /* NULL if not found */
1545 RTFFont *
1546 RTFGetFont (num)
1547 int num;
1549 RTFFont *f;
1551 if (num == -1)
1552 return (fontList);
1553 for (f = fontList; f != (RTFFont *) NULL; f = f->rtfNextFont)
1555 if (f->rtfFNum == num)
1556 break;
1558 return (f); /* NULL if not found */
1562 RTFColor *
1563 RTFGetColor (num)
1564 int num;
1566 RTFColor *c;
1568 if (num == -1)
1569 return (colorList);
1570 for (c = colorList; c != (RTFColor *) NULL; c = c->rtfNextColor)
1572 if (c->rtfCNum == num)
1573 break;
1575 return (c); /* NULL if not found */
1579 /* ---------------------------------------------------------------------- */
1583 * Expand style n, if there is such a style.
1586 void
1587 RTFExpandStyle (n)
1588 int n;
1590 RTFStyle *s;
1591 RTFStyleElt *se;
1593 if (n == -1 || (s = RTFGetStyle (n)) == (RTFStyle *) NULL)
1594 return;
1595 if (s->rtfExpanding != 0)
1596 RTFPanic ("Style expansion loop, style %d", n);
1597 s->rtfExpanding = 1; /* set expansion flag for loop detection */
1599 * Expand "based-on" style (unless it's the same as the current
1600 * style -- Normal style usually gives itself as its own based-on
1601 * style). Based-on style expansion is done by synthesizing
1602 * the token that the writer needs to see in order to trigger
1603 * another style expansion, and feeding to token back through
1604 * the router so the writer sees it.
1606 if (n != s->rtfSBasedOn)
1608 RTFSetToken (rtfControl, rtfParAttr, rtfStyleNum,
1609 s->rtfSBasedOn, "\\s");
1610 RTFRouteToken ();
1613 * Now route the tokens unique to this style. RTFSetToken()
1614 * isn't used because it would add the param value to the end
1615 * of the token text, which already has it in.
1617 for (se = s->rtfSSEList; se != (RTFStyleElt *) NULL; se = se->rtfNextSE)
1619 rtfClass = se->rtfSEClass;
1620 rtfMajor = se->rtfSEMajor;
1621 rtfMinor = se->rtfSEMinor;
1622 rtfParam = se->rtfSEParam;
1623 (void) strcpy (rtfTextBuf, se->rtfSEText);
1624 rtfTextLen = strlen (rtfTextBuf);
1625 RTFRouteToken ();
1627 s->rtfExpanding = 0; /* done - clear expansion flag */
1631 /* ---------------------------------------------------------------------- */
1634 * Control symbol lookup routines
1638 typedef struct RTFKey RTFKey;
1640 struct RTFKey
1642 int rtfKMajor; /* major number */
1643 int rtfKMinor; /* minor number */
1644 char *rtfKStr; /* symbol name */
1645 int rtfKHash; /* symbol name hash value */
1649 * A minor number of -1 means the token has no minor number
1650 * (all valid minor numbers are >= 0).
1653 static RTFKey rtfKey[] =
1656 * Special characters
1659 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1660 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1661 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1662 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1663 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1664 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1665 { rtfSpecialChar, rtfIYear, "yr", 0 },
1666 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1667 { rtfSpecialChar, rtfIDay, "dy", 0 },
1668 { rtfSpecialChar, rtfIHour, "hr", 0 },
1669 { rtfSpecialChar, rtfIMinute, "min", 0 },
1670 { rtfSpecialChar, rtfISecond, "sec", 0 },
1671 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1672 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1673 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1674 { rtfSpecialChar, rtfIIntID, "id", 0 },
1676 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1677 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1678 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1679 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1680 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1681 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1682 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1683 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1684 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1685 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1686 { rtfSpecialChar, rtfCell, "cell", 0 },
1687 { rtfSpecialChar, rtfRow, "row", 0 },
1688 { rtfSpecialChar, rtfPar, "par", 0 },
1689 /* newline and carriage return are synonyms for */
1690 /* \par when they are preceded by a \ character */
1691 { rtfSpecialChar, rtfPar, "\n", 0 },
1692 { rtfSpecialChar, rtfPar, "\r", 0 },
1693 { rtfSpecialChar, rtfSect, "sect", 0 },
1694 { rtfSpecialChar, rtfPage, "page", 0 },
1695 { rtfSpecialChar, rtfColumn, "column", 0 },
1696 { rtfSpecialChar, rtfLine, "line", 0 },
1697 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1698 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1699 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1700 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1701 { rtfSpecialChar, rtfTab, "tab", 0 },
1702 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1703 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1704 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1705 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1706 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1707 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1708 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1709 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1710 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1711 { rtfSpecialChar, rtfFormula, "|", 0 },
1712 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1713 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1714 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1715 { rtfSpecialChar, rtfOptDest, "*", 0 },
1716 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1717 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1718 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1719 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1720 /* is this valid? */
1721 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1724 * Character formatting attributes
1727 { rtfCharAttr, rtfPlain, "plain", 0 },
1728 { rtfCharAttr, rtfBold, "b", 0 },
1729 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1730 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1731 { rtfCharAttr, rtfSubScript, "dn", 0 },
1732 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1733 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1734 { rtfCharAttr, rtfExpand, "expnd", 0 },
1735 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1736 { rtfCharAttr, rtfKerning, "kerning", 0 },
1737 { rtfCharAttr, rtfFontNum, "f", 0 },
1738 { rtfCharAttr, rtfFontSize, "fs", 0 },
1739 { rtfCharAttr, rtfItalic, "i", 0 },
1740 { rtfCharAttr, rtfOutline, "outl", 0 },
1741 { rtfCharAttr, rtfRevised, "revised", 0 },
1742 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1743 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1744 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1745 { rtfCharAttr, rtfShadow, "shad", 0 },
1746 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1747 { rtfCharAttr, rtfUnderline, "ul", 0 },
1748 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1749 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1750 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1751 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1752 { rtfCharAttr, rtfSuperScript, "up", 0 },
1753 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1754 { rtfCharAttr, rtfInvisible, "v", 0 },
1755 { rtfCharAttr, rtfForeColor, "cf", 0 },
1756 { rtfCharAttr, rtfBackColor, "cb", 0 },
1757 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1758 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1759 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1760 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1761 { rtfCharAttr, rtfLanguage, "lang", 0 },
1762 /* this has disappeared from spec 1.2 */
1763 { rtfCharAttr, rtfGray, "gray", 0 },
1766 * Paragraph formatting attributes
1769 { rtfParAttr, rtfParDef, "pard", 0 },
1770 { rtfParAttr, rtfStyleNum, "s", 0 },
1771 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1772 { rtfParAttr, rtfInTable, "intbl", 0 },
1773 { rtfParAttr, rtfKeep, "keep", 0 },
1774 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1775 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1776 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1777 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1778 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1779 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1780 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1781 { rtfParAttr, rtfQuadRight, "qr", 0 },
1782 { rtfParAttr, rtfQuadJust, "qj", 0 },
1783 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1784 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1785 { rtfParAttr, rtfLeftIndent, "li", 0 },
1786 { rtfParAttr, rtfRightIndent, "ri", 0 },
1787 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1788 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1789 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1790 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1792 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1794 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1795 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1797 { rtfParAttr, rtfTabPos, "tx", 0 },
1799 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1800 * although it's not in the spec. It's also redundant, since lj
1801 * tabs are the default.
1803 { rtfParAttr, rtfTabLeft, "tql", 0 },
1804 { rtfParAttr, rtfTabRight, "tqr", 0 },
1805 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1806 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1807 { rtfParAttr, rtfTabBar, "tb", 0 },
1808 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1809 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1810 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1811 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1812 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1814 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1815 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1816 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1817 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1818 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1819 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1820 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1821 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1822 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1823 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1824 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1825 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1826 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1827 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1828 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1829 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1830 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1831 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1832 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1833 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1834 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1835 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1836 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1837 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1838 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1839 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1840 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1841 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1842 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1843 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1844 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1845 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1846 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1847 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1848 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1849 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1851 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1852 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1853 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1854 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1855 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1856 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1857 { rtfParAttr, rtfBorderBox, "box", 0 },
1858 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1859 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1860 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1861 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1862 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1863 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1864 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1865 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1866 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1867 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1869 { rtfParAttr, rtfShading, "shading", 0 },
1870 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1871 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1872 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1873 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1874 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1875 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1876 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1877 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1878 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1879 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1880 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1881 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1882 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1883 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1886 * Section formatting attributes
1889 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1890 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1891 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1892 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1893 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1895 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1896 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1897 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1898 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1899 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1901 { rtfSectAttr, rtfColumns, "cols", 0 },
1902 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1903 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1904 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1905 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1906 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1908 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1909 { rtfSectAttr, rtfLineDist, "linex", 0 },
1910 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1911 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1912 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1913 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1915 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1916 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1917 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1918 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1919 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1920 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1921 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1922 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1923 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1924 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1925 { rtfSectAttr, rtfFooterY, "footery", 0 },
1927 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1928 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1929 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1930 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1931 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1932 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1933 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1934 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1935 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1936 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1937 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1938 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1939 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1940 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1941 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1943 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1944 /* misspelled as "vertal" in specification 1.0 */
1945 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1946 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1947 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
1949 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
1950 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
1952 /* I've seen these in an old spec, but not in real files... */
1953 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1954 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1955 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1956 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1957 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1960 * Document formatting attributes
1963 { rtfDocAttr, rtfDefTab, "deftab", 0 },
1964 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
1965 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
1966 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
1967 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
1968 { rtfDocAttr, rtfLineStart, "linestart", 0 },
1969 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
1970 /* \makeback was given in old version of spec, it's now */
1971 /* listed as \makebackup */
1972 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
1973 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
1974 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
1975 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
1976 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
1977 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
1979 { rtfDocAttr, rtfFENoteType, "fet", 0 },
1980 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
1981 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
1982 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
1983 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
1984 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
1985 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
1986 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
1987 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
1988 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
1989 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
1990 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
1991 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
1992 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
1993 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
1994 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
1995 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
1996 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
1997 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
1998 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
1999 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
2000 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
2001 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
2002 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
2003 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
2004 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
2005 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
2006 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
2008 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
2009 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
2010 { rtfDocAttr, rtfPaperSize, "psz", 0 },
2011 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
2012 { rtfDocAttr, rtfRightMargin, "margr", 0 },
2013 { rtfDocAttr, rtfTopMargin, "margt", 0 },
2014 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
2015 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
2016 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
2017 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
2018 { rtfDocAttr, rtfLandscape, "landscape", 0 },
2019 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
2020 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
2022 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
2024 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
2025 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
2026 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
2027 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
2028 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
2029 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
2030 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
2031 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
2032 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
2033 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
2034 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
2035 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
2037 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
2038 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
2039 { rtfDocAttr, rtfFormShading, "formshade", 0 },
2040 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
2041 { rtfDocAttr, rtfPrintData, "printdata", 0 },
2043 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
2044 { rtfDocAttr, rtfRevisions, "revisions", 0 },
2045 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
2046 { rtfDocAttr, rtfRevBar, "revbar", 0 },
2048 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
2050 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
2051 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
2054 * Style attributes
2057 { rtfStyleAttr, rtfAdditive, "additive", 0 },
2058 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
2059 { rtfStyleAttr, rtfNext, "snext", 0 },
2062 * Picture attributes
2065 { rtfPictAttr, rtfMacQD, "macpict", 0 },
2066 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
2067 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
2068 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
2069 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
2070 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
2071 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
2072 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
2074 { rtfPictAttr, rtfPicWid, "picw", 0 },
2075 { rtfPictAttr, rtfPicHt, "pich", 0 },
2076 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
2077 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
2078 /* these two aren't in the spec, but some writers emit them */
2079 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
2080 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
2081 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
2082 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
2083 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
2084 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
2085 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
2086 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
2087 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
2089 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
2090 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
2092 { rtfPictAttr, rtfPicBinary, "bin", 0 },
2095 * NeXT graphic attributes
2098 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
2099 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
2102 * Destinations
2105 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
2106 { rtfDestination, rtfFontAltName, "falt", 0 },
2107 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
2108 { rtfDestination, rtfFontFile, "fontfile", 0 },
2109 { rtfDestination, rtfFileTbl, "filetbl", 0 },
2110 { rtfDestination, rtfFileInfo, "file", 0 },
2111 { rtfDestination, rtfColorTbl, "colortbl", 0 },
2112 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
2113 { rtfDestination, rtfKeyCode, "keycode", 0 },
2114 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
2115 { rtfDestination, rtfInfo, "info", 0 },
2116 { rtfDestination, rtfITitle, "title", 0 },
2117 { rtfDestination, rtfISubject, "subject", 0 },
2118 { rtfDestination, rtfIAuthor, "author", 0 },
2119 { rtfDestination, rtfIOperator, "operator", 0 },
2120 { rtfDestination, rtfIKeywords, "keywords", 0 },
2121 { rtfDestination, rtfIComment, "comment", 0 },
2122 { rtfDestination, rtfIVersion, "version", 0 },
2123 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
2124 /* \verscomm may not exist -- was seen in earlier spec version */
2125 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
2126 { rtfDestination, rtfNextFile, "nextfile", 0 },
2127 { rtfDestination, rtfTemplate, "template", 0 },
2128 { rtfDestination, rtfFNSep, "ftnsep", 0 },
2129 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
2130 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
2131 { rtfDestination, rtfENSep, "aftnsep", 0 },
2132 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
2133 { rtfDestination, rtfENContNotice, "aftncn", 0 },
2134 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
2135 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
2136 { rtfDestination, rtfHeader, "header", 0 },
2137 { rtfDestination, rtfFooter, "footer", 0 },
2138 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
2139 { rtfDestination, rtfHeaderRight, "headerr", 0 },
2140 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
2141 { rtfDestination, rtfFooterLeft, "footerl", 0 },
2142 { rtfDestination, rtfFooterRight, "footerr", 0 },
2143 { rtfDestination, rtfFooterFirst, "footerf", 0 },
2144 { rtfDestination, rtfParNumText, "pntext", 0 },
2145 { rtfDestination, rtfParNumbering, "pn", 0 },
2146 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
2147 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
2148 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
2149 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
2150 { rtfDestination, rtfPict, "pict", 0 },
2151 { rtfDestination, rtfObject, "object", 0 },
2152 { rtfDestination, rtfObjClass, "objclass", 0 },
2153 { rtfDestination, rtfObjName, "objname", 0 },
2154 { rtfObjAttr, rtfObjTime, "objtime", 0 },
2155 { rtfDestination, rtfObjData, "objdata", 0 },
2156 { rtfDestination, rtfObjAlias, "objalias", 0 },
2157 { rtfDestination, rtfObjSection, "objsect", 0 },
2158 /* objitem and objtopic aren't documented in the spec! */
2159 { rtfDestination, rtfObjItem, "objitem", 0 },
2160 { rtfDestination, rtfObjTopic, "objtopic", 0 },
2161 { rtfDestination, rtfObjResult, "result", 0 },
2162 { rtfDestination, rtfDrawObject, "do", 0 },
2163 { rtfDestination, rtfFootnote, "footnote", 0 },
2164 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
2165 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
2166 { rtfDestination, rtfAnnotID, "atnid", 0 },
2167 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
2168 { rtfDestination, rtfAnnotation, "annotation", 0 },
2169 { rtfDestination, rtfAnnotRef, "atnref", 0 },
2170 { rtfDestination, rtfAnnotTime, "atntime", 0 },
2171 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
2172 { rtfDestination, rtfField, "field", 0 },
2173 { rtfDestination, rtfFieldInst, "fldinst", 0 },
2174 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
2175 { rtfDestination, rtfDataField, "datafield", 0 },
2176 { rtfDestination, rtfIndex, "xe", 0 },
2177 { rtfDestination, rtfIndexText, "txe", 0 },
2178 { rtfDestination, rtfIndexRange, "rxe", 0 },
2179 { rtfDestination, rtfTOC, "tc", 0 },
2180 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
2183 * Font families
2186 { rtfFontFamily, rtfFFNil, "fnil", 0 },
2187 { rtfFontFamily, rtfFFRoman, "froman", 0 },
2188 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
2189 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
2190 { rtfFontFamily, rtfFFScript, "fscript", 0 },
2191 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
2192 { rtfFontFamily, rtfFFTech, "ftech", 0 },
2193 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
2196 * Font attributes
2199 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
2200 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
2201 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
2202 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
2203 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
2206 * File table attributes
2209 { rtfFileAttr, rtfFileNum, "fid", 0 },
2210 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
2211 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
2214 * File sources
2217 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
2218 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
2219 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
2220 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
2221 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
2224 * Color names
2227 { rtfColorName, rtfRed, "red", 0 },
2228 { rtfColorName, rtfGreen, "green", 0 },
2229 { rtfColorName, rtfBlue, "blue", 0 },
2232 * Charset names
2235 { rtfCharSet, rtfMacCharSet, "mac", 0 },
2236 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
2237 { rtfCharSet, rtfPcCharSet, "pc", 0 },
2238 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
2241 * Table attributes
2244 { rtfTblAttr, rtfRowDef, "trowd", 0 },
2245 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
2246 { rtfTblAttr, rtfCellPos, "cellx", 0 },
2247 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
2248 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
2250 { rtfTblAttr, rtfRowLeft, "trql", 0 },
2251 { rtfTblAttr, rtfRowRight, "trqr", 0 },
2252 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
2253 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
2254 { rtfTblAttr, rtfRowHt, "trrh", 0 },
2255 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
2256 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
2258 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
2259 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
2261 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
2262 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
2263 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
2264 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
2265 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
2266 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
2268 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
2269 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
2270 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
2271 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
2273 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
2274 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
2275 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
2276 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
2277 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
2278 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
2279 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
2281 * The spec lists "clbgdkhor", but the corresponding non-cell
2282 * control is "bgdkhoriz". At any rate Macintosh Word seems
2283 * to accept both "clbgdkhor" and "clbgdkhoriz".
2285 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
2286 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
2287 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
2288 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
2289 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
2290 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
2291 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
2292 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
2293 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
2296 * Field attributes
2299 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
2300 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
2301 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
2302 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
2303 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
2306 * Positioning attributes
2309 { rtfPosAttr, rtfAbsWid, "absw", 0 },
2310 { rtfPosAttr, rtfAbsHt, "absh", 0 },
2312 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
2313 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
2314 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
2315 { rtfPosAttr, rtfPosX, "posx", 0 },
2316 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
2317 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
2318 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
2319 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
2320 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
2321 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
2323 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
2324 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
2325 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
2326 { rtfPosAttr, rtfPosY, "posy", 0 },
2327 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
2328 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
2329 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
2330 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
2331 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
2333 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
2334 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
2335 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
2336 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
2337 /* \dyfrtext no longer exists in spec 1.2, apparently */
2338 /* replaced by \dfrmtextx and \dfrmtexty. */
2339 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
2341 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
2342 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
2345 * Object controls
2348 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
2349 { rtfObjAttr, rtfObjLink, "objlink", 0 },
2350 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
2351 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
2352 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
2353 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
2355 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
2356 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
2357 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
2359 { rtfObjAttr, rtfObjHt, "objh", 0 },
2360 { rtfObjAttr, rtfObjWid, "objw", 0 },
2361 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
2362 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
2363 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
2364 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
2365 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
2366 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
2367 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
2368 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
2369 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2371 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2372 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2373 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2374 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2375 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2377 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2378 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2381 * Associated character formatting attributes
2384 { rtfACharAttr, rtfACBold, "ab", 0 },
2385 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2386 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2387 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2388 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2389 { rtfACharAttr, rtfACFontNum, "af", 0 },
2390 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2391 { rtfACharAttr, rtfACItalic, "ai", 0 },
2392 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2393 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2394 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2395 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2396 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2397 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2398 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2399 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2400 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2401 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2402 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2405 * Footnote attributes
2408 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2411 * Key code attributes
2414 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2415 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2416 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2417 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2420 * Bookmark attributes
2423 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2424 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2427 * Index entry attributes
2430 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2431 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2432 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2435 * Table of contents attributes
2438 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2439 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2442 * Drawing object attributes
2445 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2446 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2447 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2448 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2449 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2450 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2451 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2452 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2454 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2455 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2456 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2457 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2458 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2459 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2460 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2461 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2462 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2463 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2464 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2466 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2467 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2468 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2469 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2471 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2472 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2473 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2474 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2475 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2476 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2477 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2478 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2479 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2480 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2481 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2482 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2483 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2484 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2485 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2486 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2487 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2489 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2490 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2491 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2493 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2494 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2495 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2497 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2498 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2500 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2501 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2502 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2503 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2504 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2505 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2506 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2507 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2508 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2509 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2510 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2511 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2513 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2514 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2515 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2516 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2517 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2518 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2519 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2520 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2522 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2523 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2524 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2525 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2526 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2527 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2528 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2529 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2530 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2531 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2532 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2534 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2535 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2536 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2538 { rtfVersion, -1, "rtf", 0 },
2539 { rtfDefFont, -1, "deff", 0 },
2541 { 0, -1, (char *) NULL, 0 }
2546 * Initialize lookup table hash values. Only need to do this once.
2549 static void
2550 LookupInit ()
2552 static int inited = 0;
2553 RTFKey *rp;
2555 if (inited == 0)
2557 for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
2558 rp->rtfKHash = Hash (rp->rtfKStr);
2559 ++inited;
2565 * Determine major and minor number of control token. If it's
2566 * not found, the class turns into rtfUnknown.
2569 static void
2570 Lookup (s)
2571 char *s;
2573 RTFKey *rp;
2574 int hash;
2576 ++s; /* skip over the leading \ character */
2577 hash = Hash (s);
2578 for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
2580 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2582 rtfClass = rtfControl;
2583 rtfMajor = rp->rtfKMajor;
2584 rtfMinor = rp->rtfKMinor;
2585 return;
2588 rtfClass = rtfUnknown;
2593 * Compute hash value of symbol
2596 static int
2597 Hash (s)
2598 char *s;
2600 char c;
2601 int val = 0;
2603 while ((c = *s++) != '\0')
2604 val += (int) c;
2605 return (val);
2609 /* ---------------------------------------------------------------------- */
2612 * Memory allocation routines
2617 * Return pointer to block of size bytes, or NULL if there's
2618 * not enough memory available.
2620 * This is called through RTFAlloc(), a define which coerces the
2621 * argument to int. This avoids the persistent problem of allocation
2622 * failing under THINK C when a long is passed.
2625 char *
2626 _RTFAlloc (size)
2627 int size;
2629 return HeapAlloc(RICHED32_hHeap, 0, size);
2634 * Saves a string on the heap and returns a pointer to it.
2638 char *
2639 RTFStrSave (s)
2640 char *s;
2642 char *p;
2644 if ((p = RTFAlloc ((int) (strlen (s) + 1))) == (char *) NULL)
2645 return ((char *) NULL);
2646 return (strcpy (p, s));
2650 void
2651 RTFFree (p)
2652 char *p;
2654 if (p != (char *) NULL)
2655 HeapFree(RICHED32_hHeap, 0, p);
2659 /* ---------------------------------------------------------------------- */
2663 * Token comparison routines
2667 RTFCheckCM (class, major)
2668 int class, major;
2670 return (rtfClass == class && rtfMajor == major);
2675 RTFCheckCMM (class, major, minor)
2676 int class, major, minor;
2678 return (rtfClass == class && rtfMajor == major && rtfMinor == minor);
2683 RTFCheckMM (major, minor)
2684 int major, minor;
2686 return (rtfMajor == major && rtfMinor == minor);
2690 /* ---------------------------------------------------------------------- */
2694 RTFCharToHex (c)
2695 char c;
2697 if (isupper (c))
2698 c = tolower (c);
2699 if (isdigit (c))
2700 return (c - '0'); /* '0'..'9' */
2701 return (c - 'a' + 10); /* 'a'..'f' */
2706 RTFHexToChar (i)
2707 int i;
2709 if (i < 10)
2710 return (i + '0');
2711 return (i - 10 + 'a');
2715 /* ---------------------------------------------------------------------- */
2718 * RTFReadOutputMap() -- Read output translation map
2722 * Read in an array describing the relation between the standard character set
2723 * and an RTF translator's corresponding output sequences. Each line consists
2724 * of a standard character name and the output sequence for that character.
2726 * outMap is an array of strings into which the sequences should be placed.
2727 * It should be declared like this in the calling program:
2729 * char *outMap[rtfSC_MaxChar];
2731 * reinit should be non-zero if outMap should be initialized
2732 * zero otherwise.
2737 RTFReadOutputMap (outMap, reinit)
2738 char *outMap[];
2739 int reinit;
2741 int i;
2742 int stdCode;
2743 char *name, *seq;
2745 if (reinit)
2747 for (i = 0; i < rtfSC_MaxChar; i++)
2749 outMap[i] = (char *) NULL;
2753 for (i=0 ;i< sizeof(text_map)/sizeof(char*); i+=2)
2755 name = text_map[i];
2756 seq = text_map[i+1];
2757 stdCode = RTFStdCharCode( name );
2758 outMap[stdCode] = seq;
2761 return (1);
2764 /* ---------------------------------------------------------------------- */
2767 * Open a library file.
2771 static FILE *(*libFileOpen) () = NULL;
2775 void
2776 RTFSetOpenLibFileProc (proc)
2777 FILE *(*proc) ();
2779 libFileOpen = proc;
2783 FILE *
2784 RTFOpenLibFile (file, mode)
2785 char *file;
2786 char *mode;
2788 if (libFileOpen == NULL)
2789 return ((FILE *) NULL);
2790 return ((*libFileOpen) (file, mode));
2794 /* ---------------------------------------------------------------------- */
2797 * Print message. Default is to send message to stderr
2798 * but this may be overridden with RTFSetMsgProc().
2800 * Message should include linefeeds as necessary. If the default
2801 * function is overridden, the overriding function may want to
2802 * map linefeeds to another line ending character or sequence if
2803 * the host system doesn't use linefeeds.
2807 static void
2808 DefaultMsgProc (s)
2809 char *s;
2811 MESSAGE( "%s", s);
2815 static RTFFuncPtr msgProc = DefaultMsgProc;
2818 void
2819 RTFSetMsgProc (proc)
2820 RTFFuncPtr proc;
2822 msgProc = proc;
2826 # ifdef STDARG
2829 * This version is for systems with stdarg
2832 void
2833 RTFMsg (char *fmt, ...)
2835 char buf[rtfBufSiz];
2837 va_list args;
2838 va_start (args,fmt);
2839 vsprintf (buf, fmt, args);
2840 va_end (args);
2841 (*msgProc) (buf);
2844 # else /* !STDARG */
2846 # ifdef VARARGS
2850 * This version is for systems that have varargs.
2853 void
2854 RTFMsg (va_alist)
2855 va_dcl
2857 va_list args;
2858 char *fmt;
2859 char buf[rtfBufSiz];
2861 va_start (args);
2862 fmt = va_arg (args, char *);
2863 vsprintf (buf, fmt, args);
2864 va_end (args);
2865 (*msgProc) (buf);
2868 # else /* !VARARGS */
2871 * This version is for systems that don't have varargs.
2874 void
2875 RTFMsg (fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9)
2876 char *fmt;
2877 char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8, *a9;
2879 char buf[rtfBufSiz];
2881 sprintf (buf, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9);
2882 (*msgProc) (buf);
2885 # endif /* !VARARGS */
2886 # endif /* !STDARG */
2889 /* ---------------------------------------------------------------------- */
2893 * Process termination. Print error message and exit. Also prints
2894 * current token, and current input line number and position within
2895 * line if any input has been read from the current file. (No input
2896 * has been read if prevChar is EOF).
2899 static void
2900 DefaultPanicProc (s)
2901 char *s;
2903 MESSAGE( "%s", s);
2904 /*exit (1);*/
2908 static RTFFuncPtr panicProc = DefaultPanicProc;
2911 void
2912 RTFSetPanicProc (proc)
2913 RTFFuncPtr proc;
2915 panicProc = proc;
2919 # ifdef STDARG
2922 * This version is for systems with stdarg
2925 void
2926 RTFPanic (char *fmt, ...)
2928 char buf[rtfBufSiz];
2930 va_list args;
2931 va_start (args,fmt);
2932 vsprintf (buf, fmt, args);
2933 va_end (args);
2934 (void) strcat (buf, "\n");
2935 if (prevChar != EOF && rtfTextBuf != (char *) NULL)
2937 sprintf (buf + strlen (buf),
2938 "Last token read was \"%s\" near line %ld, position %d.\n",
2939 rtfTextBuf, rtfLineNum, rtfLinePos);
2941 (*panicProc) (buf);
2944 # else /* !STDARG */
2946 # ifdef VARARGS
2950 * This version is for systems that have varargs.
2953 void
2954 RTFPanic (va_alist)
2955 va_dcl
2957 va_list args;
2958 char *fmt;
2959 char buf[rtfBufSiz];
2961 va_start (args);
2962 fmt = va_arg (args, char *);
2963 vsprintf (buf, fmt, args);
2964 va_end (args);
2965 (void) strcat (buf, "\n");
2966 if (prevChar != EOF && rtfTextBuf != (char *) NULL)
2968 sprintf (buf + strlen (buf),
2969 "Last token read was \"%s\" near line %ld, position %d.\n",
2970 rtfTextBuf, rtfLineNum, rtfLinePos);
2972 (*panicProc) (buf);
2975 # else /* !VARARGS */
2978 * This version is for systems that don't have varargs.
2981 void
2982 RTFPanic (fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9)
2983 char *fmt;
2984 char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8, *a9;
2986 char buf[rtfBufSiz];
2988 sprintf (buf, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9);
2989 (void) strcat (buf, "\n");
2990 if (prevChar != EOF && rtfTextBuf != (char *) NULL)
2992 sprintf (buf + strlen (buf),
2993 "Last token read was \"%s\" near line %ld, position %d.\n",
2994 rtfTextBuf, rtfLineNum, rtfLinePos);
2996 (*panicProc) (buf);
2999 # endif /* !VARARGS */
3000 # endif /* !STDARG */