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