riched20: Create macro functions for allocating and freeing memory.
[wine/winequartzdrv.git] / dlls / riched20 / reader.c
blobb2fb4446fbf74a285e2acc04da0100a566c5749a
1 /*
2 * WINE RTF file reader
4 * Portions Copyright 2004 Mike McCormack for CodeWeavers
5 * Portions Copyright 2006 by Phil Krylov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Derived from RTF Tools by Paul DuBois (dubois@primate.wisc.edu)
24 * Homepage: http://www.snake.net/software/RTF/
25 * Original license follows:
29 * reader.c - RTF file reader. Release 1.10.
31 * ....
33 * Author: Paul DuBois dubois@primate.wisc.edu
35 * This software may be redistributed without restriction and used for
36 * any purpose whatsoever.
39 #include <stdio.h>
40 #include <ctype.h>
41 #include <string.h>
42 #include <stdarg.h>
43 #include <stdlib.h>
44 #include <assert.h>
46 #include "windef.h"
47 #include "winbase.h"
48 #include "wine/debug.h"
50 #include "editor.h"
51 #include "rtf.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
55 extern HANDLE me_heap;
57 static int _RTFGetChar(RTF_Info *);
58 static void _RTFGetToken (RTF_Info *);
59 static void _RTFGetToken2 (RTF_Info *);
60 static int GetChar (RTF_Info *);
61 static void ReadFontTbl (RTF_Info *);
62 static void ReadColorTbl (RTF_Info *);
63 static void ReadStyleSheet (RTF_Info *);
64 static void ReadInfoGroup (RTF_Info *);
65 static void ReadPictGroup (RTF_Info *);
66 static void ReadObjGroup (RTF_Info *);
67 static void LookupInit (void);
68 static void Lookup (RTF_Info *, char *);
69 static int Hash (const char *);
71 static void CharAttr(RTF_Info *info);
72 static void CharSet(RTF_Info *info);
73 static void DocAttr(RTF_Info *info);
75 static void RTFFlushCPOutputBuffer(RTF_Info *info);
76 static void RTFPutCodePageChar(RTF_Info *info, int c);
78 /* ---------------------------------------------------------------------- */
81 * Memory allocation routines
86 * Return pointer to block of size bytes, or NULL if there's
87 * not enough memory available.
89 #define RTFAlloc(size) richedit_alloc(size)
90 #define RTFReAlloc(ptr, size) richedit_realloc(ptr, size)
91 #define RTFFree(ptr) richedit_free(ptr)
94 * Saves a string on the heap and returns a pointer to it.
96 static inline char *RTFStrSave(char *s)
98 char *p;
100 p = RTFAlloc (lstrlenA(s) + 1);
101 if (p == NULL)
102 return NULL;
103 return lstrcpyA (p, s);
107 /* ---------------------------------------------------------------------- */
110 int _RTFGetChar(RTF_Info *info)
112 int ch;
113 ME_InStream *stream = info->stream;
115 TRACE("\n");
117 if (stream->dwSize <= stream->dwUsed)
119 ME_StreamInFill(stream);
120 /* if error, it's EOF */
121 if (stream->editstream->dwError)
122 return EOF;
123 /* if no bytes read, it's EOF */
124 if (stream->dwSize == 0)
125 return EOF;
127 ch = stream->buffer[stream->dwUsed++];
128 if (!ch)
129 return EOF;
130 return ch;
133 void RTFSetEditStream(RTF_Info *info, ME_InStream *stream)
135 TRACE("\n");
137 info->stream = stream;
140 static void
141 RTFDestroyAttrs(RTF_Info *info)
143 RTFColor *cp;
144 RTFFont *fp;
145 RTFStyle *sp;
146 RTFStyleElt *eltList, *ep;
148 while (info->fontList)
150 fp = info->fontList->rtfNextFont;
151 RTFFree (info->fontList->rtfFName);
152 RTFFree (info->fontList);
153 info->fontList = fp;
155 while (info->colorList)
157 cp = info->colorList->rtfNextColor;
158 RTFFree (info->colorList);
159 info->colorList = cp;
161 while (info->styleList)
163 sp = info->styleList->rtfNextStyle;
164 eltList = info->styleList->rtfSSEList;
165 while (eltList)
167 ep = eltList->rtfNextSE;
168 RTFFree (eltList->rtfSEText);
169 RTFFree (eltList);
170 eltList = ep;
172 RTFFree (info->styleList->rtfSName);
173 RTFFree (info->styleList);
174 info->styleList = sp;
179 void
180 RTFDestroy(RTF_Info *info)
182 if (info->rtfTextBuf)
184 RTFFree(info->rtfTextBuf);
185 RTFFree(info->pushedTextBuf);
187 RTFDestroyAttrs(info);
188 RTFFree(info->cpOutputBuffer);
193 * Initialize the reader. This may be called multiple times,
194 * to read multiple files. The only thing not reset is the input
195 * stream; that must be done with RTFSetStream().
198 void RTFInit(RTF_Info *info)
200 int i;
202 TRACE("\n");
204 if (info->rtfTextBuf == NULL) /* initialize the text buffers */
206 info->rtfTextBuf = RTFAlloc (rtfBufSiz);
207 info->pushedTextBuf = RTFAlloc (rtfBufSiz);
208 if (info->rtfTextBuf == NULL || info->pushedTextBuf == NULL)
209 ERR ("Cannot allocate text buffers.\n");
210 info->rtfTextBuf[0] = info->pushedTextBuf[0] = '\0';
213 RTFFree (info->inputName);
214 RTFFree (info->outputName);
215 info->inputName = info->outputName = NULL;
217 /* initialize lookup table */
218 LookupInit ();
220 for (i = 0; i < rtfMaxClass; i++)
221 RTFSetClassCallback (info, i, NULL);
222 for (i = 0; i < rtfMaxDestination; i++)
223 RTFSetDestinationCallback (info, i, NULL);
225 /* install built-in destination readers */
226 RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl);
227 RTFSetDestinationCallback (info, rtfColorTbl, ReadColorTbl);
228 RTFSetDestinationCallback (info, rtfStyleSheet, ReadStyleSheet);
229 RTFSetDestinationCallback (info, rtfInfo, ReadInfoGroup);
230 RTFSetDestinationCallback (info, rtfPict, ReadPictGroup);
231 RTFSetDestinationCallback (info, rtfObject, ReadObjGroup);
234 RTFSetReadHook (info, NULL);
236 /* dump old lists if necessary */
238 RTFDestroyAttrs(info);
240 info->ansiCodePage = 1252; /* Latin-1; actually unused */
241 info->unicodeLength = 1; /* \uc1 is the default */
242 info->codePage = info->ansiCodePage;
243 info->defFont = 0;
245 info->rtfClass = -1;
246 info->pushedClass = -1;
247 info->pushedChar = EOF;
249 info->rtfLineNum = 0;
250 info->rtfLinePos = 0;
251 info->prevChar = EOF;
252 info->bumpLine = 0;
254 info->dwCPOutputCount = 0;
255 if (!info->cpOutputBuffer)
257 info->dwMaxCPOutputCount = 0x1000;
258 info->cpOutputBuffer = RTFAlloc(info->dwMaxCPOutputCount);
263 * Set or get the input or output file name. These are never guaranteed
264 * to be accurate, only insofar as the calling program makes them so.
267 void RTFSetInputName(RTF_Info *info, char *name)
269 TRACE("\n");
271 info->inputName = RTFStrSave (name);
272 if (info->inputName == NULL)
273 ERR ("RTFSetInputName: out of memory\n");
277 char *RTFGetInputName(RTF_Info *info)
279 return (info->inputName);
283 void RTFSetOutputName(RTF_Info *info, char *name)
285 TRACE("\n");
287 info->outputName = RTFStrSave (name);
288 if (info->outputName == NULL)
289 ERR ("RTFSetOutputName: out of memory\n");
293 char *RTFGetOutputName(RTF_Info *info)
295 return (info->outputName);
300 /* ---------------------------------------------------------------------- */
303 * Callback table manipulation routines
308 * Install or return a writer callback for a token class
311 void RTFSetClassCallback(RTF_Info *info, int class, RTFFuncPtr callback)
313 if (class >= 0 && class < rtfMaxClass)
314 info->ccb[class] = callback;
318 RTFFuncPtr RTFGetClassCallback(RTF_Info *info, int class)
320 if (class >= 0 && class < rtfMaxClass)
321 return info->ccb[class];
322 return NULL;
327 * Install or return a writer callback for a destination type
330 void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback)
332 if (dest >= 0 && dest < rtfMaxDestination)
333 info->dcb[dest] = callback;
337 RTFFuncPtr RTFGetDestinationCallback(RTF_Info *info, int dest)
339 if (dest >= 0 && dest < rtfMaxDestination)
340 return info->dcb[dest];
341 return NULL;
345 /* ---------------------------------------------------------------------- */
348 * Token reading routines
353 * Read the input stream, invoking the writer's callbacks
354 * where appropriate.
357 void RTFRead(RTF_Info *info)
359 while (RTFGetToken (info) != rtfEOF)
360 RTFRouteToken (info);
365 * Route a token. If it's a destination for which a reader is
366 * installed, process the destination internally, otherwise
367 * pass the token to the writer's class callback.
370 void RTFRouteToken(RTF_Info *info)
372 RTFFuncPtr p;
374 TRACE("\n");
376 if (info->rtfClass < 0 || info->rtfClass >= rtfMaxClass) /* watchdog */
378 ERR( "Unknown class %d: %s (reader malfunction)\n",
379 info->rtfClass, info->rtfTextBuf);
381 if (RTFCheckCM (info, rtfControl, rtfDestination))
383 /* invoke destination-specific callback if there is one */
384 p = RTFGetDestinationCallback (info, info->rtfMinor);
385 if (p != NULL)
387 (*p) (info);
388 return;
391 /* invoke class callback if there is one */
392 p = RTFGetClassCallback (info, info->rtfClass);
393 if (p != NULL)
394 (*p) (info);
399 * Skip to the end of the current group. When this returns,
400 * writers that maintain a state stack may want to call their
401 * state unstacker; global vars will still be set to the group's
402 * closing brace.
405 void RTFSkipGroup(RTF_Info *info)
407 int level = 1;
409 TRACE("\n");
411 while (RTFGetToken (info) != rtfEOF)
413 if (info->rtfClass == rtfGroup)
415 if (info->rtfMajor == rtfBeginGroup)
416 ++level;
417 else if (info->rtfMajor == rtfEndGroup)
419 if (--level < 1)
420 break; /* end of initial group */
428 * Read one token. Call the read hook if there is one. The
429 * token class is the return value. Returns rtfEOF when there
430 * are no more tokens.
433 int RTFGetToken(RTF_Info *info)
435 RTFFuncPtr p;
437 TRACE("\n");
438 /* don't try to return anything once EOF is reached */
439 if (info->rtfClass == rtfEOF) {
440 return rtfEOF;
443 for (;;)
445 _RTFGetToken (info);
446 p = RTFGetReadHook (info);
447 if (p != NULL)
448 (*p) (info); /* give read hook a look at token */
450 /* Silently discard newlines, carriage returns, nulls. */
451 if (!(info->rtfClass == rtfText && info->rtfFormat != SF_TEXT
452 && (info->rtfMajor == '\r' || info->rtfMajor == '\n' || info->rtfMajor == '\0')))
453 break;
455 return (info->rtfClass);
460 * Install or return a token reader hook.
463 void RTFSetReadHook(RTF_Info *info, RTFFuncPtr f)
465 info->readHook = f;
469 RTFFuncPtr RTFGetReadHook(RTF_Info *info)
471 return (info->readHook);
475 void RTFUngetToken(RTF_Info *info)
477 TRACE("\n");
479 if (info->pushedClass >= 0) /* there's already an ungotten token */
480 ERR ("cannot unget two tokens\n");
481 if (info->rtfClass < 0)
482 ERR ("no token to unget\n");
483 info->pushedClass = info->rtfClass;
484 info->pushedMajor = info->rtfMajor;
485 info->pushedMinor = info->rtfMinor;
486 info->pushedParam = info->rtfParam;
487 lstrcpyA (info->pushedTextBuf, info->rtfTextBuf);
491 int RTFPeekToken(RTF_Info *info)
493 _RTFGetToken (info);
494 RTFUngetToken (info);
495 return (info->rtfClass);
499 static void _RTFGetToken(RTF_Info *info)
501 TRACE("\n");
503 if (info->rtfFormat == SF_TEXT)
505 info->rtfMajor = GetChar (info);
506 info->rtfMinor = 0;
507 info->rtfParam = rtfNoParam;
508 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
509 if (info->rtfMajor == EOF)
510 info->rtfClass = rtfEOF;
511 else
512 info->rtfClass = rtfText;
513 return;
516 /* first check for pushed token from RTFUngetToken() */
518 if (info->pushedClass >= 0)
520 info->rtfClass = info->pushedClass;
521 info->rtfMajor = info->pushedMajor;
522 info->rtfMinor = info->pushedMinor;
523 info->rtfParam = info->pushedParam;
524 lstrcpyA (info->rtfTextBuf, info->pushedTextBuf);
525 info->rtfTextLen = lstrlenA(info->rtfTextBuf);
526 info->pushedClass = -1;
527 return;
531 * Beyond this point, no token is ever seen twice, which is
532 * important, e.g., for making sure no "}" pops the font stack twice.
535 _RTFGetToken2 (info);
540 RTFCharSetToCodePage(RTF_Info *info, int charset)
542 switch (charset)
544 case ANSI_CHARSET:
545 return 1252;
546 case DEFAULT_CHARSET:
547 return CP_ACP;
548 case SYMBOL_CHARSET:
549 return CP_SYMBOL;
550 case MAC_CHARSET:
551 return CP_MACCP;
552 case SHIFTJIS_CHARSET:
553 return 932;
554 case HANGEUL_CHARSET:
555 return 949;
556 case JOHAB_CHARSET:
557 return 1361;
558 case GB2312_CHARSET:
559 return 936;
560 case CHINESEBIG5_CHARSET:
561 return 950;
562 case GREEK_CHARSET:
563 return 1253;
564 case TURKISH_CHARSET:
565 return 1254;
566 case VIETNAMESE_CHARSET:
567 return 1258;
568 case HEBREW_CHARSET:
569 return 1255;
570 case ARABIC_CHARSET:
571 return 1256;
572 case BALTIC_CHARSET:
573 return 1257;
574 case RUSSIAN_CHARSET:
575 return 1251;
576 case THAI_CHARSET:
577 return 874;
578 case EASTEUROPE_CHARSET:
579 return 1250;
580 case OEM_CHARSET:
581 return CP_OEMCP;
582 default:
584 CHARSETINFO csi;
585 DWORD n = charset;
587 /* FIXME: TranslateCharsetInfo does not work as good as it
588 * should, so let's use it only when all else fails */
589 if (!TranslateCharsetInfo(&n, &csi, TCI_SRCCHARSET))
590 ERR("%s: unknown charset %u\n", __FUNCTION__, charset);
591 else
592 return csi.ciACP;
595 return 0;
599 /* this shouldn't be called anywhere but from _RTFGetToken() */
601 static void _RTFGetToken2(RTF_Info *info)
603 int sign;
604 int c;
606 TRACE("\n");
608 /* initialize token vars */
610 info->rtfClass = rtfUnknown;
611 info->rtfParam = rtfNoParam;
612 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
614 /* get first character, which may be a pushback from previous token */
616 if (info->pushedChar != EOF)
618 c = info->pushedChar;
619 info->rtfTextBuf[info->rtfTextLen++] = c;
620 info->rtfTextBuf[info->rtfTextLen] = '\0';
621 info->pushedChar = EOF;
623 else if ((c = GetChar (info)) == EOF)
625 info->rtfClass = rtfEOF;
626 return;
629 if (c == '{')
631 info->rtfClass = rtfGroup;
632 info->rtfMajor = rtfBeginGroup;
633 return;
635 if (c == '}')
637 info->rtfClass = rtfGroup;
638 info->rtfMajor = rtfEndGroup;
639 return;
641 if (c != '\\')
644 * Two possibilities here:
645 * 1) ASCII 9, effectively like \tab control symbol
646 * 2) literal text char
648 if (c == '\t') /* ASCII 9 */
650 info->rtfClass = rtfControl;
651 info->rtfMajor = rtfSpecialChar;
652 info->rtfMinor = rtfTab;
654 else
656 info->rtfClass = rtfText;
657 info->rtfMajor = c;
659 return;
661 if ((c = GetChar (info)) == EOF)
663 /* early eof, whoops (class is rtfUnknown) */
664 return;
666 if (!isalpha (c))
669 * Three possibilities here:
670 * 1) hex encoded text char, e.g., \'d5, \'d3
671 * 2) special escaped text char, e.g., \{, \}
672 * 3) control symbol, e.g., \_, \-, \|, \<10>
674 if (c == '\'') /* hex char */
676 int c2;
678 if ((c = GetChar (info)) != EOF && (c2 = GetChar (info)) != EOF)
680 /* should do isxdigit check! */
681 info->rtfClass = rtfText;
682 info->rtfMajor = RTFCharToHex (c) * 16 + RTFCharToHex (c2);
683 return;
685 /* early eof, whoops (class is rtfUnknown) */
686 return;
689 /* escaped char */
690 /*if (index (":{}\\", c) != (char *) NULL)*/ /* escaped char */
691 if (c == ':' || c == '{' || c == '}' || c == '\\')
693 info->rtfClass = rtfText;
694 info->rtfMajor = c;
695 return;
698 /* control symbol */
699 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
700 return;
702 /* control word */
703 while (isalpha (c))
705 if ((c = GetChar (info)) == EOF)
706 break;
710 * At this point, the control word is all collected, so the
711 * major/minor numbers are determined before the parameter
712 * (if any) is scanned. There will be one too many characters
713 * in the buffer, though, so fix up before and restore after
714 * looking up.
717 if (c != EOF)
718 info->rtfTextBuf[info->rtfTextLen-1] = '\0';
719 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
720 if (c != EOF)
721 info->rtfTextBuf[info->rtfTextLen-1] = c;
724 * Should be looking at first digit of parameter if there
725 * is one, unless it's negative. In that case, next char
726 * is '-', so need to gobble next char, and remember sign.
729 sign = 1;
730 if (c == '-')
732 sign = -1;
733 c = GetChar (info);
735 if (c != EOF && isdigit (c))
737 info->rtfParam = 0;
738 while (isdigit (c)) /* gobble parameter */
740 info->rtfParam = info->rtfParam * 10 + c - '0';
741 if ((c = GetChar (info)) == EOF)
742 break;
744 info->rtfParam *= sign;
747 * If control symbol delimiter was a blank, gobble it.
748 * Otherwise the character is first char of next token, so
749 * push it back for next call. In either case, delete the
750 * delimiter from the token buffer.
752 if (c != EOF)
754 if (c != ' ')
755 info->pushedChar = c;
756 info->rtfTextBuf[--info->rtfTextLen] = '\0';
762 * Read the next character from the input. This handles setting the
763 * current line and position-within-line variables. Those variable are
764 * set correctly whether lines end with CR, LF, or CRLF (the last being
765 * the tricky case).
767 * bumpLine indicates whether the line number should be incremented on
768 * the *next* input character.
772 static int GetChar(RTF_Info *info)
774 int c;
775 int oldBumpLine;
777 TRACE("\n");
779 if ((c = _RTFGetChar(info)) != EOF)
781 info->rtfTextBuf[info->rtfTextLen++] = c;
782 info->rtfTextBuf[info->rtfTextLen] = '\0';
784 if (info->prevChar == EOF)
785 info->bumpLine = 1;
786 oldBumpLine = info->bumpLine; /* non-zero if prev char was line ending */
787 info->bumpLine = 0;
788 if (c == '\r')
789 info->bumpLine = 1;
790 else if (c == '\n')
792 info->bumpLine = 1;
793 if (info->prevChar == '\r') /* oops, previous \r wasn't */
794 oldBumpLine = 0; /* really a line ending */
796 ++info->rtfLinePos;
797 if (oldBumpLine) /* were we supposed to increment the */
798 { /* line count on this char? */
799 ++info->rtfLineNum;
800 info->rtfLinePos = 1;
802 info->prevChar = c;
803 return (c);
808 * Synthesize a token by setting the global variables to the
809 * values supplied. Typically this is followed with a call
810 * to RTFRouteToken().
812 * If a param value other than rtfNoParam is passed, it becomes
813 * part of the token text.
816 void RTFSetToken(RTF_Info *info, int class, int major, int minor, int param, const char *text)
818 TRACE("\n");
820 info->rtfClass = class;
821 info->rtfMajor = major;
822 info->rtfMinor = minor;
823 info->rtfParam = param;
824 if (param == rtfNoParam)
825 lstrcpyA(info->rtfTextBuf, text);
826 else
827 sprintf (info->rtfTextBuf, "%s%d", text, param);
828 info->rtfTextLen = lstrlenA (info->rtfTextBuf);
832 /* ---------------------------------------------------------------------- */
835 * Special destination readers. They gobble the destination so the
836 * writer doesn't have to deal with them. That's wrong for any
837 * translator that wants to process any of these itself. In that
838 * case, these readers should be overridden by installing a different
839 * destination callback.
841 * NOTE: The last token read by each of these reader will be the
842 * destination's terminating '}', which will then be the current token.
843 * That '}' token is passed to RTFRouteToken() - the writer has already
844 * seen the '{' that began the destination group, and may have pushed a
845 * state; it also needs to know at the end of the group that a state
846 * should be popped.
848 * It's important that rtf.h and the control token lookup table list
849 * as many symbols as possible, because these destination readers
850 * unfortunately make strict assumptions about the input they expect,
851 * and a token of class rtfUnknown will throw them off easily.
856 * Read { \fonttbl ... } destination. Old font tables don't have
857 * braces around each table entry; try to adjust for that.
860 static void ReadFontTbl(RTF_Info *info)
862 RTFFont *fp = NULL;
863 char buf[rtfBufSiz], *bp;
864 int old = -1;
865 const char *fn = "ReadFontTbl";
867 TRACE("\n");
869 for (;;)
871 RTFGetToken (info);
872 if (info->rtfClass == rtfEOF)
873 break;
874 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
875 break;
876 if (old < 0) /* first entry - determine tbl type */
878 if (RTFCheckCMM (info, rtfControl, rtfCharAttr, rtfFontNum))
879 old = 1; /* no brace */
880 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
881 old = 0; /* brace */
882 else /* can't tell! */
883 ERR ( "%s: Cannot determine format\n", fn);
885 if (old == 0) /* need to find "{" here */
887 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
888 ERR ( "%s: missing \"{\"\n", fn);
889 RTFGetToken (info); /* yes, skip to next token */
890 if (info->rtfClass == rtfEOF)
891 break;
893 fp = New (RTFFont);
894 if (fp == NULL)
895 ERR ( "%s: cannot allocate font entry\n", fn);
897 fp->rtfNextFont = info->fontList;
898 info->fontList = fp;
900 fp->rtfFName = NULL;
901 fp->rtfFAltName = NULL;
902 fp->rtfFNum = -1;
903 fp->rtfFFamily = 0;
904 fp->rtfFCharSet = DEFAULT_CHARSET; /* 1 */
905 fp->rtfFPitch = 0;
906 fp->rtfFType = 0;
907 fp->rtfFCodePage = CP_ACP;
909 while (info->rtfClass != rtfEOF
910 && !RTFCheckCM (info, rtfText, ';')
911 && !RTFCheckCM (info, rtfGroup, rtfEndGroup))
913 if (info->rtfClass == rtfControl)
915 switch (info->rtfMajor)
917 default:
918 /* ignore token but announce it */
919 ERR ("%s: unknown token \"%s\"\n",
920 fn, info->rtfTextBuf);
921 break;
922 case rtfFontFamily:
923 fp->rtfFFamily = info->rtfMinor;
924 break;
925 case rtfCharAttr:
926 switch (info->rtfMinor)
928 default:
929 break; /* ignore unknown? */
930 case rtfFontNum:
931 fp->rtfFNum = info->rtfParam;
932 break;
934 break;
935 case rtfFontAttr:
936 switch (info->rtfMinor)
938 default:
939 break; /* ignore unknown? */
940 case rtfFontCharSet:
941 fp->rtfFCharSet = info->rtfParam;
942 if (!fp->rtfFCodePage)
943 fp->rtfFCodePage = RTFCharSetToCodePage(info, info->rtfParam);
944 break;
945 case rtfFontPitch:
946 fp->rtfFPitch = info->rtfParam;
947 break;
948 case rtfFontCodePage:
949 fp->rtfFCodePage = info->rtfParam;
950 break;
951 case rtfFTypeNil:
952 case rtfFTypeTrueType:
953 fp->rtfFType = info->rtfParam;
954 break;
956 break;
959 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup)) /* dest */
961 RTFSkipGroup (info); /* ignore for now */
963 else if (info->rtfClass == rtfText) /* font name */
965 bp = buf;
966 while (info->rtfClass == rtfText
967 && !RTFCheckCM (info, rtfText, ';'))
969 *bp++ = info->rtfMajor;
970 RTFGetToken (info);
973 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
974 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
976 RTFUngetToken (info);
978 *bp = '\0';
979 fp->rtfFName = RTFStrSave (buf);
980 if (fp->rtfFName == NULL)
981 ERR ( "%s: cannot allocate font name\n", fn);
982 /* already have next token; don't read one */
983 /* at bottom of loop */
984 continue;
986 else
988 /* ignore token but announce it */
989 ERR ( "%s: unknown token \"%s\"\n",
990 fn,info->rtfTextBuf);
992 RTFGetToken (info);
993 if (info->rtfClass == rtfEOF)
994 break;
996 if (info->rtfClass == rtfEOF)
997 break;
998 if (old == 0) /* need to see "}" here */
1000 RTFGetToken (info);
1001 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1002 ERR ( "%s: missing \"}\"\n", fn);
1003 if (info->rtfClass == rtfEOF)
1004 break;
1007 /* Apply the real properties of the default font */
1008 if (fp->rtfFNum == info->defFont)
1010 if (info->ansiCodePage != CP_UTF8)
1011 info->codePage = fp->rtfFCodePage;
1012 TRACE("default font codepage %d\n", info->codePage);
1015 if (fp->rtfFNum == -1)
1016 ERR( "%s: missing font number\n", fn);
1018 * Could check other pieces of structure here, too, I suppose.
1020 RTFRouteToken (info); /* feed "}" back to router */
1022 /* Set default font */
1023 info->rtfClass = rtfControl;
1024 info->rtfMajor = rtfCharAttr;
1025 info->rtfMinor = rtfFontNum;
1026 info->rtfParam = info->defFont;
1027 lstrcpyA(info->rtfTextBuf, "f");
1028 RTFUngetToken(info);
1033 * The color table entries have color values of -1 if
1034 * the default color should be used for the entry (only
1035 * a semi-colon is given in the definition, no color values).
1036 * There will be a problem if a partial entry (1 or 2 but
1037 * not 3 color values) is given. The possibility is ignored
1038 * here.
1041 static void ReadColorTbl(RTF_Info *info)
1043 RTFColor *cp;
1044 int cnum = 0;
1045 const char *fn = "ReadColorTbl";
1046 int group_level = 1;
1048 TRACE("\n");
1050 for (;;)
1052 RTFGetToken (info);
1053 if (info->rtfClass == rtfEOF)
1054 break;
1055 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1057 group_level--;
1058 if (!group_level)
1059 break;
1060 continue;
1062 else if (RTFCheckCM(info, rtfGroup, rtfBeginGroup))
1064 group_level++;
1065 continue;
1068 cp = New (RTFColor);
1069 if (cp == NULL)
1070 ERR ( "%s: cannot allocate color entry\n", fn);
1071 cp->rtfCNum = cnum++;
1072 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
1073 cp->rtfNextColor = info->colorList;
1074 info->colorList = cp;
1075 while (RTFCheckCM (info, rtfControl, rtfColorName))
1077 switch (info->rtfMinor)
1079 case rtfRed: cp->rtfCRed = info->rtfParam; break;
1080 case rtfGreen: cp->rtfCGreen = info->rtfParam; break;
1081 case rtfBlue: cp->rtfCBlue = info->rtfParam; break;
1083 RTFGetToken (info);
1085 if (info->rtfClass == rtfEOF)
1086 break;
1087 if (!RTFCheckCM (info, rtfText, ';'))
1088 ERR ("%s: malformed entry\n", fn);
1090 RTFRouteToken (info); /* feed "}" back to router */
1095 * The "Normal" style definition doesn't contain any style number,
1096 * all others do. Normal style is given style rtfNormalStyleNum.
1099 static void ReadStyleSheet(RTF_Info *info)
1101 RTFStyle *sp;
1102 RTFStyleElt *sep, *sepLast;
1103 char buf[rtfBufSiz], *bp;
1104 const char *fn = "ReadStyleSheet";
1105 int real_style;
1107 TRACE("\n");
1109 for (;;)
1111 RTFGetToken (info);
1112 if (info->rtfClass == rtfEOF)
1113 break;
1114 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1115 break;
1116 sp = New (RTFStyle);
1117 if (sp == NULL)
1118 ERR ( "%s: cannot allocate stylesheet entry\n", fn);
1119 sp->rtfSName = NULL;
1120 sp->rtfSNum = -1;
1121 sp->rtfSType = rtfParStyle;
1122 sp->rtfSAdditive = 0;
1123 sp->rtfSBasedOn = rtfNoStyleNum;
1124 sp->rtfSNextPar = -1;
1125 sp->rtfSSEList = sepLast = NULL;
1126 sp->rtfNextStyle = info->styleList;
1127 sp->rtfExpanding = 0;
1128 info->styleList = sp;
1129 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1130 ERR ( "%s: missing \"{\"\n", fn);
1131 real_style = TRUE;
1132 for (;;)
1134 RTFGetToken (info);
1135 if (info->rtfClass == rtfEOF
1136 || RTFCheckCM (info, rtfText, ';'))
1137 break;
1138 if (info->rtfClass == rtfControl)
1140 if (RTFCheckMM (info, rtfSpecialChar, rtfOptDest)) {
1141 RTFGetToken(info);
1142 ERR( "%s: skipping optional destination\n", fn);
1143 RTFSkipGroup(info);
1144 info->rtfClass = rtfGroup;
1145 info->rtfMajor = rtfEndGroup;
1146 real_style = FALSE;
1147 break; /* ignore "\*" */
1149 if (RTFCheckMM (info, rtfParAttr, rtfStyleNum))
1151 sp->rtfSNum = info->rtfParam;
1152 sp->rtfSType = rtfParStyle;
1153 continue;
1155 if (RTFCheckMM (info, rtfCharAttr, rtfCharStyleNum))
1157 sp->rtfSNum = info->rtfParam;
1158 sp->rtfSType = rtfCharStyle;
1159 continue;
1161 if (RTFCheckMM (info, rtfSectAttr, rtfSectStyleNum))
1163 sp->rtfSNum = info->rtfParam;
1164 sp->rtfSType = rtfSectStyle;
1165 continue;
1167 if (RTFCheckMM (info, rtfStyleAttr, rtfBasedOn))
1169 sp->rtfSBasedOn = info->rtfParam;
1170 continue;
1172 if (RTFCheckMM (info, rtfStyleAttr, rtfAdditive))
1174 sp->rtfSAdditive = 1;
1175 continue;
1177 if (RTFCheckMM (info, rtfStyleAttr, rtfNext))
1179 sp->rtfSNextPar = info->rtfParam;
1180 continue;
1182 sep = New (RTFStyleElt);
1183 if (sep == NULL)
1184 ERR ( "%s: cannot allocate style element\n", fn);
1185 sep->rtfSEClass = info->rtfClass;
1186 sep->rtfSEMajor = info->rtfMajor;
1187 sep->rtfSEMinor = info->rtfMinor;
1188 sep->rtfSEParam = info->rtfParam;
1189 sep->rtfSEText = RTFStrSave (info->rtfTextBuf);
1190 if (sep->rtfSEText == NULL)
1191 ERR ( "%s: cannot allocate style element text\n", fn);
1192 if (sepLast == NULL)
1193 sp->rtfSSEList = sep; /* first element */
1194 else /* add to end */
1195 sepLast->rtfNextSE = sep;
1196 sep->rtfNextSE = NULL;
1197 sepLast = sep;
1199 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1202 * This passes over "{\*\keycode ... }, among
1203 * other things. A temporary (perhaps) hack.
1205 ERR( "%s: skipping begin\n", fn);
1206 RTFSkipGroup (info);
1207 continue;
1209 else if (info->rtfClass == rtfText) /* style name */
1211 bp = buf;
1212 while (info->rtfClass == rtfText)
1214 if (info->rtfMajor == ';')
1216 /* put back for "for" loop */
1217 RTFUngetToken (info);
1218 break;
1220 *bp++ = info->rtfMajor;
1221 RTFGetToken (info);
1223 *bp = '\0';
1224 sp->rtfSName = RTFStrSave (buf);
1225 if (sp->rtfSName == NULL)
1226 ERR ( "%s: cannot allocate style name\n", fn);
1228 else /* unrecognized */
1230 /* ignore token but announce it */
1231 ERR ( "%s: unknown token \"%s\"\n",
1232 fn, info->rtfTextBuf);
1235 if (real_style) {
1236 RTFGetToken (info);
1237 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1238 ERR ( "%s: missing \"}\"\n", fn);
1240 * Check over the style structure. A name is a must.
1241 * If no style number was specified, check whether it's the
1242 * Normal style (in which case it's given style number
1243 * rtfNormalStyleNum). Note that some "normal" style names
1244 * just begin with "Normal" and can have other stuff following,
1245 * e.g., "Normal,Times 10 point". Ugh.
1247 * Some German RTF writers use "Standard" instead of "Normal".
1249 if (sp->rtfSName == NULL)
1250 ERR ( "%s: missing style name\n", fn);
1251 if (sp->rtfSNum < 0)
1253 if (strncmp (buf, "Normal", 6) != 0
1254 && strncmp (buf, "Standard", 8) != 0)
1255 ERR ( "%s: missing style number\n", fn);
1256 sp->rtfSNum = rtfNormalStyleNum;
1258 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1259 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1261 /* otherwise we're just dealing with fake end group from skipped group */
1263 RTFRouteToken (info); /* feed "}" back to router */
1267 static void ReadInfoGroup(RTF_Info *info)
1269 RTFSkipGroup (info);
1270 RTFRouteToken (info); /* feed "}" back to router */
1274 static void ReadPictGroup(RTF_Info *info)
1276 RTFSkipGroup (info);
1277 RTFRouteToken (info); /* feed "}" back to router */
1281 static void ReadObjGroup(RTF_Info *info)
1283 RTFSkipGroup (info);
1284 RTFRouteToken (info); /* feed "}" back to router */
1288 /* ---------------------------------------------------------------------- */
1291 * Routines to return pieces of stylesheet, or font or color tables.
1292 * References to style 0 are mapped onto the Normal style.
1296 RTFStyle *RTFGetStyle(RTF_Info *info, int num)
1298 RTFStyle *s;
1300 if (num == -1)
1301 return (info->styleList);
1302 for (s = info->styleList; s != NULL; s = s->rtfNextStyle)
1304 if (s->rtfSNum == num)
1305 break;
1307 return (s); /* NULL if not found */
1311 RTFFont *RTFGetFont(RTF_Info *info, int num)
1313 RTFFont *f;
1315 if (num == -1)
1316 return (info->fontList);
1317 for (f = info->fontList; f != NULL; f = f->rtfNextFont)
1319 if (f->rtfFNum == num)
1320 break;
1322 return (f); /* NULL if not found */
1326 RTFColor *RTFGetColor(RTF_Info *info, int num)
1328 RTFColor *c;
1330 if (num == -1)
1331 return (info->colorList);
1332 for (c = info->colorList; c != NULL; c = c->rtfNextColor)
1334 if (c->rtfCNum == num)
1335 break;
1337 return (c); /* NULL if not found */
1341 /* ---------------------------------------------------------------------- */
1345 * Expand style n, if there is such a style.
1348 void RTFExpandStyle(RTF_Info *info, int n)
1350 RTFStyle *s;
1351 RTFStyleElt *se;
1353 TRACE("\n");
1355 if (n == -1)
1356 return;
1357 s = RTFGetStyle (info, n);
1358 if (s == NULL)
1359 return;
1360 if (s->rtfExpanding != 0)
1361 ERR ("Style expansion loop, style %d\n", n);
1362 s->rtfExpanding = 1; /* set expansion flag for loop detection */
1364 * Expand "based-on" style (unless it's the same as the current
1365 * style -- Normal style usually gives itself as its own based-on
1366 * style). Based-on style expansion is done by synthesizing
1367 * the token that the writer needs to see in order to trigger
1368 * another style expansion, and feeding to token back through
1369 * the router so the writer sees it.
1371 if (n != s->rtfSBasedOn)
1373 RTFSetToken (info, rtfControl, rtfParAttr, rtfStyleNum,
1374 s->rtfSBasedOn, "\\s");
1375 RTFRouteToken (info);
1378 * Now route the tokens unique to this style. RTFSetToken()
1379 * isn't used because it would add the param value to the end
1380 * of the token text, which already has it in.
1382 for (se = s->rtfSSEList; se != NULL; se = se->rtfNextSE)
1384 info->rtfClass = se->rtfSEClass;
1385 info->rtfMajor = se->rtfSEMajor;
1386 info->rtfMinor = se->rtfSEMinor;
1387 info->rtfParam = se->rtfSEParam;
1388 lstrcpyA (info->rtfTextBuf, se->rtfSEText);
1389 info->rtfTextLen = lstrlenA (info->rtfTextBuf);
1390 RTFRouteToken (info);
1392 s->rtfExpanding = 0; /* done - clear expansion flag */
1396 /* ---------------------------------------------------------------------- */
1399 * Control symbol lookup routines
1403 typedef struct RTFKey RTFKey;
1405 struct RTFKey
1407 int rtfKMajor; /* major number */
1408 int rtfKMinor; /* minor number */
1409 const char *rtfKStr; /* symbol name */
1410 int rtfKHash; /* symbol name hash value */
1414 * A minor number of -1 means the token has no minor number
1415 * (all valid minor numbers are >= 0).
1418 static RTFKey rtfKey[] =
1421 * Special characters
1424 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1425 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1426 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1427 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1428 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1429 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1430 { rtfSpecialChar, rtfIYear, "yr", 0 },
1431 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1432 { rtfSpecialChar, rtfIDay, "dy", 0 },
1433 { rtfSpecialChar, rtfIHour, "hr", 0 },
1434 { rtfSpecialChar, rtfIMinute, "min", 0 },
1435 { rtfSpecialChar, rtfISecond, "sec", 0 },
1436 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1437 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1438 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1439 { rtfSpecialChar, rtfIIntID, "id", 0 },
1441 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1442 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1443 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1444 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1445 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1446 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1447 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1448 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1449 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1450 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1451 { rtfSpecialChar, rtfCell, "cell", 0 },
1452 { rtfSpecialChar, rtfRow, "row", 0 },
1453 { rtfSpecialChar, rtfPar, "par", 0 },
1454 /* newline and carriage return are synonyms for */
1455 /* \par when they are preceded by a \ character */
1456 { rtfSpecialChar, rtfPar, "\n", 0 },
1457 { rtfSpecialChar, rtfPar, "\r", 0 },
1458 { rtfSpecialChar, rtfSect, "sect", 0 },
1459 { rtfSpecialChar, rtfPage, "page", 0 },
1460 { rtfSpecialChar, rtfColumn, "column", 0 },
1461 { rtfSpecialChar, rtfLine, "line", 0 },
1462 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1463 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1464 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1465 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1466 { rtfSpecialChar, rtfTab, "tab", 0 },
1467 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1468 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1469 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1470 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1471 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1472 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1473 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1474 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1475 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1476 { rtfSpecialChar, rtfFormula, "|", 0 },
1477 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1478 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1479 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1480 { rtfSpecialChar, rtfOptDest, "*", 0 },
1481 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1482 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1483 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1484 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1485 /* is this valid? */
1486 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1487 { rtfSpecialChar, rtfUnicode, "u", 0 },
1490 * Character formatting attributes
1493 { rtfCharAttr, rtfPlain, "plain", 0 },
1494 { rtfCharAttr, rtfBold, "b", 0 },
1495 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1496 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1497 { rtfCharAttr, rtfSubScript, "dn", 0 },
1498 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1499 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1500 { rtfCharAttr, rtfExpand, "expnd", 0 },
1501 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1502 { rtfCharAttr, rtfKerning, "kerning", 0 },
1503 { rtfCharAttr, rtfFontNum, "f", 0 },
1504 { rtfCharAttr, rtfFontSize, "fs", 0 },
1505 { rtfCharAttr, rtfItalic, "i", 0 },
1506 { rtfCharAttr, rtfOutline, "outl", 0 },
1507 { rtfCharAttr, rtfRevised, "revised", 0 },
1508 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1509 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1510 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1511 { rtfCharAttr, rtfShadow, "shad", 0 },
1512 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1513 { rtfCharAttr, rtfUnderline, "ul", 0 },
1514 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1515 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1516 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1517 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1518 { rtfCharAttr, rtfSuperScript, "up", 0 },
1519 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1520 { rtfCharAttr, rtfInvisible, "v", 0 },
1521 { rtfCharAttr, rtfForeColor, "cf", 0 },
1522 { rtfCharAttr, rtfBackColor, "cb", 0 },
1523 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1524 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1525 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1526 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1527 { rtfCharAttr, rtfLanguage, "lang", 0 },
1528 /* this has disappeared from spec 1.2 */
1529 { rtfCharAttr, rtfGray, "gray", 0 },
1530 { rtfCharAttr, rtfUnicodeLength, "uc", 0 },
1533 * Paragraph formatting attributes
1536 { rtfParAttr, rtfParDef, "pard", 0 },
1537 { rtfParAttr, rtfStyleNum, "s", 0 },
1538 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1539 { rtfParAttr, rtfInTable, "intbl", 0 },
1540 { rtfParAttr, rtfKeep, "keep", 0 },
1541 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1542 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1543 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1544 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1545 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1546 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1547 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1548 { rtfParAttr, rtfQuadRight, "qr", 0 },
1549 { rtfParAttr, rtfQuadJust, "qj", 0 },
1550 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1551 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1552 { rtfParAttr, rtfLeftIndent, "li", 0 },
1553 { rtfParAttr, rtfRightIndent, "ri", 0 },
1554 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1555 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1556 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1557 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1559 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1561 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1562 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1564 { rtfParAttr, rtfTabPos, "tx", 0 },
1566 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1567 * although it's not in the spec. It's also redundant, since lj
1568 * tabs are the default.
1570 { rtfParAttr, rtfTabLeft, "tql", 0 },
1571 { rtfParAttr, rtfTabRight, "tqr", 0 },
1572 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1573 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1574 { rtfParAttr, rtfTabBar, "tb", 0 },
1575 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1576 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1577 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1578 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1579 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1581 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1582 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1583 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1584 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1585 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1586 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1587 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1588 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1589 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1590 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1591 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1592 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1593 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1594 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1595 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1596 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1597 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1598 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1599 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1600 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1601 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1602 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1603 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1604 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1605 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1606 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1607 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1608 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1609 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1610 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1611 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1612 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1613 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1614 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1615 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1616 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1618 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1619 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1620 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1621 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1622 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1623 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1624 { rtfParAttr, rtfBorderBox, "box", 0 },
1625 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1626 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1627 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1628 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1629 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1630 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1631 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1632 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1633 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1634 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1636 { rtfParAttr, rtfShading, "shading", 0 },
1637 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1638 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1639 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1640 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1641 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1642 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1643 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1644 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1645 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1646 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1647 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1648 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1649 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1650 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1653 * Section formatting attributes
1656 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1657 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1658 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1659 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1660 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1662 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1663 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1664 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1665 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1666 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1668 { rtfSectAttr, rtfColumns, "cols", 0 },
1669 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1670 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1671 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1672 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1673 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1675 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1676 { rtfSectAttr, rtfLineDist, "linex", 0 },
1677 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1678 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1679 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1680 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1682 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1683 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1684 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1685 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1686 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1687 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1688 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1689 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1690 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1691 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1692 { rtfSectAttr, rtfFooterY, "footery", 0 },
1694 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1695 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1696 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1697 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1698 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1699 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1700 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1701 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1702 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1703 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1704 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1705 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1706 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1707 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1708 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1710 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1711 /* misspelled as "vertal" in specification 1.0 */
1712 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1713 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1714 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
1716 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
1717 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
1719 /* I've seen these in an old spec, but not in real files... */
1720 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1721 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1722 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1723 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1724 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1727 * Document formatting attributes
1730 { rtfDocAttr, rtfDefTab, "deftab", 0 },
1731 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
1732 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
1733 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
1734 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
1735 { rtfDocAttr, rtfLineStart, "linestart", 0 },
1736 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
1737 /* \makeback was given in old version of spec, it's now */
1738 /* listed as \makebackup */
1739 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
1740 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
1741 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
1742 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
1743 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
1744 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
1746 { rtfDocAttr, rtfFENoteType, "fet", 0 },
1747 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
1748 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
1749 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
1750 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
1751 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
1752 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
1753 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
1754 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
1755 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
1756 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
1757 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
1758 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
1759 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
1760 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
1761 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
1762 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
1763 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
1764 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
1765 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
1766 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
1767 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
1768 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
1769 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
1770 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
1771 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
1772 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
1773 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
1775 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
1776 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
1777 { rtfDocAttr, rtfPaperSize, "psz", 0 },
1778 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
1779 { rtfDocAttr, rtfRightMargin, "margr", 0 },
1780 { rtfDocAttr, rtfTopMargin, "margt", 0 },
1781 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
1782 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
1783 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
1784 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
1785 { rtfDocAttr, rtfLandscape, "landscape", 0 },
1786 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
1787 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
1789 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
1791 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
1792 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
1793 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
1794 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
1795 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
1796 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
1797 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
1798 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
1799 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
1800 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
1801 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
1802 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
1804 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
1805 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
1806 { rtfDocAttr, rtfFormShading, "formshade", 0 },
1807 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
1808 { rtfDocAttr, rtfPrintData, "printdata", 0 },
1810 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
1811 { rtfDocAttr, rtfRevisions, "revisions", 0 },
1812 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
1813 { rtfDocAttr, rtfRevBar, "revbar", 0 },
1815 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
1817 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
1818 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
1820 { rtfDocAttr, rtfAnsiCodePage, "ansicpg", 0 },
1821 { rtfDocAttr, rtfUTF8RTF, "urtf", 0 },
1824 * Style attributes
1827 { rtfStyleAttr, rtfAdditive, "additive", 0 },
1828 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
1829 { rtfStyleAttr, rtfNext, "snext", 0 },
1832 * Picture attributes
1835 { rtfPictAttr, rtfMacQD, "macpict", 0 },
1836 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
1837 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
1838 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
1839 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
1840 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
1841 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
1842 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
1844 { rtfPictAttr, rtfPicWid, "picw", 0 },
1845 { rtfPictAttr, rtfPicHt, "pich", 0 },
1846 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
1847 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
1848 /* these two aren't in the spec, but some writers emit them */
1849 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
1850 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
1851 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
1852 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
1853 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
1854 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
1855 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
1856 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
1857 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
1859 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
1860 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
1862 { rtfPictAttr, rtfPicBinary, "bin", 0 },
1865 * NeXT graphic attributes
1868 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
1869 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
1872 * Destinations
1875 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
1876 { rtfDestination, rtfFontAltName, "falt", 0 },
1877 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
1878 { rtfDestination, rtfFontFile, "fontfile", 0 },
1879 { rtfDestination, rtfFileTbl, "filetbl", 0 },
1880 { rtfDestination, rtfFileInfo, "file", 0 },
1881 { rtfDestination, rtfColorTbl, "colortbl", 0 },
1882 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
1883 { rtfDestination, rtfKeyCode, "keycode", 0 },
1884 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
1885 { rtfDestination, rtfGenerator, "generator", 0 },
1886 { rtfDestination, rtfInfo, "info", 0 },
1887 { rtfDestination, rtfITitle, "title", 0 },
1888 { rtfDestination, rtfISubject, "subject", 0 },
1889 { rtfDestination, rtfIAuthor, "author", 0 },
1890 { rtfDestination, rtfIOperator, "operator", 0 },
1891 { rtfDestination, rtfIKeywords, "keywords", 0 },
1892 { rtfDestination, rtfIComment, "comment", 0 },
1893 { rtfDestination, rtfIVersion, "version", 0 },
1894 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
1895 /* \verscomm may not exist -- was seen in earlier spec version */
1896 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
1897 { rtfDestination, rtfNextFile, "nextfile", 0 },
1898 { rtfDestination, rtfTemplate, "template", 0 },
1899 { rtfDestination, rtfFNSep, "ftnsep", 0 },
1900 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
1901 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
1902 { rtfDestination, rtfENSep, "aftnsep", 0 },
1903 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
1904 { rtfDestination, rtfENContNotice, "aftncn", 0 },
1905 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
1906 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
1907 { rtfDestination, rtfHeader, "header", 0 },
1908 { rtfDestination, rtfFooter, "footer", 0 },
1909 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
1910 { rtfDestination, rtfHeaderRight, "headerr", 0 },
1911 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
1912 { rtfDestination, rtfFooterLeft, "footerl", 0 },
1913 { rtfDestination, rtfFooterRight, "footerr", 0 },
1914 { rtfDestination, rtfFooterFirst, "footerf", 0 },
1915 { rtfDestination, rtfParNumText, "pntext", 0 },
1916 { rtfDestination, rtfParNumbering, "pn", 0 },
1917 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
1918 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
1919 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
1920 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
1921 { rtfDestination, rtfPict, "pict", 0 },
1922 { rtfDestination, rtfObject, "object", 0 },
1923 { rtfDestination, rtfObjClass, "objclass", 0 },
1924 { rtfDestination, rtfObjName, "objname", 0 },
1925 { rtfObjAttr, rtfObjTime, "objtime", 0 },
1926 { rtfDestination, rtfObjData, "objdata", 0 },
1927 { rtfDestination, rtfObjAlias, "objalias", 0 },
1928 { rtfDestination, rtfObjSection, "objsect", 0 },
1929 /* objitem and objtopic aren't documented in the spec! */
1930 { rtfDestination, rtfObjItem, "objitem", 0 },
1931 { rtfDestination, rtfObjTopic, "objtopic", 0 },
1932 { rtfDestination, rtfObjResult, "result", 0 },
1933 { rtfDestination, rtfDrawObject, "do", 0 },
1934 { rtfDestination, rtfFootnote, "footnote", 0 },
1935 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
1936 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
1937 { rtfDestination, rtfAnnotID, "atnid", 0 },
1938 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
1939 { rtfDestination, rtfAnnotation, "annotation", 0 },
1940 { rtfDestination, rtfAnnotRef, "atnref", 0 },
1941 { rtfDestination, rtfAnnotTime, "atntime", 0 },
1942 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
1943 { rtfDestination, rtfField, "field", 0 },
1944 { rtfDestination, rtfFieldInst, "fldinst", 0 },
1945 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
1946 { rtfDestination, rtfDataField, "datafield", 0 },
1947 { rtfDestination, rtfIndex, "xe", 0 },
1948 { rtfDestination, rtfIndexText, "txe", 0 },
1949 { rtfDestination, rtfIndexRange, "rxe", 0 },
1950 { rtfDestination, rtfTOC, "tc", 0 },
1951 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
1954 * Font families
1957 { rtfFontFamily, rtfFFNil, "fnil", 0 },
1958 { rtfFontFamily, rtfFFRoman, "froman", 0 },
1959 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
1960 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
1961 { rtfFontFamily, rtfFFScript, "fscript", 0 },
1962 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
1963 { rtfFontFamily, rtfFFTech, "ftech", 0 },
1964 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
1967 * Font attributes
1970 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
1971 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
1972 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
1973 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
1974 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
1977 * File table attributes
1980 { rtfFileAttr, rtfFileNum, "fid", 0 },
1981 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
1982 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
1985 * File sources
1988 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
1989 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
1990 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
1991 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
1992 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
1995 * Color names
1998 { rtfColorName, rtfRed, "red", 0 },
1999 { rtfColorName, rtfGreen, "green", 0 },
2000 { rtfColorName, rtfBlue, "blue", 0 },
2003 * Charset names
2006 { rtfCharSet, rtfMacCharSet, "mac", 0 },
2007 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
2008 { rtfCharSet, rtfPcCharSet, "pc", 0 },
2009 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
2012 * Table attributes
2015 { rtfTblAttr, rtfRowDef, "trowd", 0 },
2016 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
2017 { rtfTblAttr, rtfCellPos, "cellx", 0 },
2018 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
2019 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
2021 { rtfTblAttr, rtfRowLeft, "trql", 0 },
2022 { rtfTblAttr, rtfRowRight, "trqr", 0 },
2023 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
2024 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
2025 { rtfTblAttr, rtfRowHt, "trrh", 0 },
2026 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
2027 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
2029 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
2030 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
2032 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
2033 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
2034 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
2035 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
2036 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
2037 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
2039 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
2040 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
2041 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
2042 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
2044 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
2045 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
2046 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
2047 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
2048 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
2049 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
2050 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
2052 * The spec lists "clbgdkhor", but the corresponding non-cell
2053 * control is "bgdkhoriz". At any rate Macintosh Word seems
2054 * to accept both "clbgdkhor" and "clbgdkhoriz".
2056 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
2057 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
2058 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
2059 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
2060 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
2061 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
2062 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
2063 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
2064 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
2067 * Field attributes
2070 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
2071 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
2072 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
2073 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
2074 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
2077 * Positioning attributes
2080 { rtfPosAttr, rtfAbsWid, "absw", 0 },
2081 { rtfPosAttr, rtfAbsHt, "absh", 0 },
2083 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
2084 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
2085 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
2086 { rtfPosAttr, rtfPosX, "posx", 0 },
2087 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
2088 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
2089 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
2090 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
2091 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
2092 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
2094 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
2095 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
2096 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
2097 { rtfPosAttr, rtfPosY, "posy", 0 },
2098 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
2099 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
2100 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
2101 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
2102 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
2104 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
2105 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
2106 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
2107 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
2108 /* \dyfrtext no longer exists in spec 1.2, apparently */
2109 /* replaced by \dfrmtextx and \dfrmtexty. */
2110 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
2112 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
2113 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
2116 * Object controls
2119 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
2120 { rtfObjAttr, rtfObjLink, "objlink", 0 },
2121 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
2122 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
2123 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
2124 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
2126 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
2127 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
2128 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
2130 { rtfObjAttr, rtfObjHt, "objh", 0 },
2131 { rtfObjAttr, rtfObjWid, "objw", 0 },
2132 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
2133 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
2134 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
2135 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
2136 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
2137 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
2138 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
2139 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
2140 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2142 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2143 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2144 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2145 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2146 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2148 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2149 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2152 * Associated character formatting attributes
2155 { rtfACharAttr, rtfACBold, "ab", 0 },
2156 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2157 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2158 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2159 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2160 { rtfACharAttr, rtfACFontNum, "af", 0 },
2161 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2162 { rtfACharAttr, rtfACItalic, "ai", 0 },
2163 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2164 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2165 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2166 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2167 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2168 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2169 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2170 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2171 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2172 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2173 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2176 * Footnote attributes
2179 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2182 * Key code attributes
2185 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2186 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2187 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2188 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2191 * Bookmark attributes
2194 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2195 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2198 * Index entry attributes
2201 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2202 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2203 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2206 * Table of contents attributes
2209 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2210 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2213 * Drawing object attributes
2216 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2217 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2218 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2219 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2220 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2221 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2222 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2223 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2225 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2226 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2227 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2228 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2229 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2230 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2231 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2232 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2233 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2234 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2235 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2237 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2238 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2239 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2240 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2242 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2243 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2244 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2245 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2246 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2247 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2248 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2249 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2250 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2251 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2252 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2253 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2254 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2255 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2256 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2257 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2258 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2260 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2261 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2262 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2264 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2265 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2266 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2268 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2269 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2271 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2272 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2273 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2274 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2275 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2276 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2277 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2278 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2279 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2280 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2281 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2282 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2284 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2285 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2286 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2287 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2288 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2289 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2290 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2291 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2293 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2294 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2295 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2296 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2297 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2298 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2299 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2300 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2301 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2302 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2303 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2305 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2306 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2307 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2309 { rtfVersion, -1, "rtf", 0 },
2310 { rtfDefFont, -1, "deff", 0 },
2312 { 0, -1, (char *) NULL, 0 }
2314 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2316 typedef struct tagRTFHashTableEntry {
2317 int count;
2318 RTFKey **value;
2319 } RTFHashTableEntry;
2321 static RTFHashTableEntry rtfHashTable[RTF_KEY_COUNT * 2];
2325 * Initialize lookup table hash values. Only need to do this once.
2328 static void LookupInit(void)
2330 static int inited = 0;
2331 RTFKey *rp;
2333 if (inited == 0)
2335 memset(rtfHashTable, 0, RTF_KEY_COUNT * 2 * sizeof(*rtfHashTable));
2336 for (rp = rtfKey; rp->rtfKStr != NULL; rp++) {
2337 int index;
2339 rp->rtfKHash = Hash (rp->rtfKStr);
2340 index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
2341 if (!rtfHashTable[index].count)
2342 rtfHashTable[index].value = RTFAlloc(sizeof(RTFKey *));
2343 else
2344 rtfHashTable[index].value = RTFReAlloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
2345 rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
2347 ++inited;
2353 * Determine major and minor number of control token. If it's
2354 * not found, the class turns into rtfUnknown.
2357 static void Lookup(RTF_Info *info, char *s)
2359 RTFKey *rp;
2360 int hash;
2361 RTFHashTableEntry *entry;
2362 int i;
2364 TRACE("\n");
2365 ++s; /* skip over the leading \ character */
2366 hash = Hash (s);
2367 entry = &rtfHashTable[hash % (RTF_KEY_COUNT * 2)];
2368 for (i = 0; i < entry->count; i++)
2370 rp = entry->value[i];
2371 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2373 info->rtfClass = rtfControl;
2374 info->rtfMajor = rp->rtfKMajor;
2375 info->rtfMinor = rp->rtfKMinor;
2376 return;
2379 info->rtfClass = rtfUnknown;
2384 * Compute hash value of symbol
2387 static int Hash(const char *s)
2389 char c;
2390 int val = 0;
2392 while ((c = *s++) != '\0')
2393 val += c;
2394 return (val);
2399 /* ---------------------------------------------------------------------- */
2403 * Token comparison routines
2406 int RTFCheckCM(RTF_Info *info, int class, int major)
2408 return (info->rtfClass == class && info->rtfMajor == major);
2412 int RTFCheckCMM(RTF_Info *info, int class, int major, int minor)
2414 return (info->rtfClass == class && info->rtfMajor == major && info->rtfMinor == minor);
2418 int RTFCheckMM(RTF_Info *info, int major, int minor)
2420 return (info->rtfMajor == major && info->rtfMinor == minor);
2424 /* ---------------------------------------------------------------------- */
2427 int RTFCharToHex(char c)
2429 if (isupper (c))
2430 c = tolower (c);
2431 if (isdigit (c))
2432 return (c - '0'); /* '0'..'9' */
2433 return (c - 'a' + 10); /* 'a'..'f' */
2437 int RTFHexToChar(int i)
2439 if (i < 10)
2440 return (i + '0');
2441 return (i - 10 + 'a');
2445 /* ---------------------------------------------------------------------- */
2448 * originally from RTF tools' text-writer.c
2450 * text-writer -- RTF-to-text translation writer code.
2452 * Read RTF input, write text of document (text extraction).
2455 static void TextClass (RTF_Info *info);
2456 static void ControlClass (RTF_Info *info);
2457 static void DefFont(RTF_Info *info);
2458 static void Destination (RTF_Info *info);
2459 static void SpecialChar (RTF_Info *info);
2460 static void RTFPutUnicodeChar (RTF_Info *info, int c);
2463 * Initialize the writer.
2466 void
2467 WriterInit (RTF_Info *info )
2473 BeginFile (RTF_Info *info )
2475 /* install class callbacks */
2477 RTFSetClassCallback (info, rtfText, TextClass);
2478 RTFSetClassCallback (info, rtfControl, ControlClass);
2480 return (1);
2484 * Write out a character.
2487 static void
2488 TextClass (RTF_Info *info)
2490 RTFPutCodePageChar(info, info->rtfMajor);
2494 static void
2495 ControlClass (RTF_Info *info)
2497 TRACE("\n");
2499 switch (info->rtfMajor)
2501 case rtfCharAttr:
2502 CharAttr(info);
2503 break;
2504 case rtfCharSet:
2505 CharSet(info);
2506 break;
2507 case rtfDefFont:
2508 DefFont(info);
2509 break;
2510 case rtfDestination:
2511 Destination (info);
2512 break;
2513 case rtfDocAttr:
2514 DocAttr(info);
2515 break;
2516 case rtfSpecialChar:
2517 SpecialChar (info);
2518 break;
2523 static void
2524 CharAttr(RTF_Info *info)
2526 RTFFont *font;
2528 switch (info->rtfMinor)
2530 case rtfFontNum:
2531 font = RTFGetFont(info, info->rtfParam);
2532 if (font)
2534 if (info->ansiCodePage != CP_UTF8)
2535 info->codePage = font->rtfFCodePage;
2536 TRACE("font %d codepage %d\n", info->rtfParam, info->codePage);
2538 else
2539 ERR( "unknown font %d\n", info->rtfParam);
2540 break;
2541 case rtfUnicodeLength:
2542 info->unicodeLength = info->rtfParam;
2543 break;
2548 static void
2549 CharSet(RTF_Info *info)
2551 if (info->ansiCodePage == CP_UTF8)
2552 return;
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 DefFont(RTF_Info *info)
2589 TRACE("%d\n", info->rtfParam);
2590 info->defFont = info->rtfParam;
2594 static void
2595 DocAttr(RTF_Info *info)
2597 TRACE("minor %d, param %d\n", info->rtfMinor, info->rtfParam);
2599 switch (info->rtfMinor)
2601 case rtfAnsiCodePage:
2602 info->codePage = info->ansiCodePage = info->rtfParam;
2603 break;
2604 case rtfUTF8RTF:
2605 info->codePage = info->ansiCodePage = CP_UTF8;
2606 break;
2611 static void SpecialChar (RTF_Info *info)
2614 TRACE("\n");
2616 switch (info->rtfMinor)
2618 case rtfOptDest:
2619 /* the next token determines destination, if it's unknown, skip the group */
2620 /* this way we filter out the garbage coming from unknown destinations */
2621 RTFGetToken(info);
2622 if (info->rtfClass != rtfDestination)
2623 RTFSkipGroup(info);
2624 else
2625 RTFRouteToken(info); /* "\*" is ignored with known destinations */
2626 break;
2627 case rtfUnicode:
2629 int i;
2631 RTFPutUnicodeChar(info, info->rtfParam);
2633 /* After \u we must skip number of character tokens set by \ucN */
2634 for (i = 0; i < info->unicodeLength; i++)
2636 RTFGetToken(info);
2637 if (info->rtfClass != rtfText)
2639 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2640 info->rtfClass, info->rtfMajor, info->rtfMinor);
2641 RTFUngetToken(info);
2642 break;
2645 break;
2647 case rtfPage:
2648 case rtfSect:
2649 case rtfRow:
2650 case rtfLine:
2651 case rtfPar:
2652 RTFPutUnicodeChar (info, '\n');
2653 break;
2654 case rtfNoBrkSpace:
2655 RTFPutUnicodeChar (info, 0x00A0);
2656 break;
2657 case rtfTab:
2658 RTFPutUnicodeChar (info, '\t');
2659 break;
2660 case rtfNoBrkHyphen:
2661 RTFPutUnicodeChar (info, 0x2011);
2662 break;
2663 case rtfBullet:
2664 RTFPutUnicodeChar (info, 0x2022);
2665 break;
2666 case rtfEmDash:
2667 RTFPutUnicodeChar (info, 0x2014);
2668 break;
2669 case rtfEnDash:
2670 RTFPutUnicodeChar (info, 0x2013);
2671 break;
2672 case rtfLQuote:
2673 RTFPutUnicodeChar (info, 0x2018);
2674 break;
2675 case rtfRQuote:
2676 RTFPutUnicodeChar (info, 0x2019);
2677 break;
2678 case rtfLDblQuote:
2679 RTFPutUnicodeChar (info, 0x201C);
2680 break;
2681 case rtfRDblQuote:
2682 RTFPutUnicodeChar (info, 0x201D);
2683 break;
2688 static void
2689 RTFFlushUnicodeOutputBuffer(RTF_Info *info)
2691 if (info->dwOutputCount)
2693 ME_InsertTextFromCursor(info->editor, 0, info->OutputBuffer,
2694 info->dwOutputCount, info->style);
2695 info->dwOutputCount = 0;
2699 static void
2700 RTFPutUnicodeString(RTF_Info *info, WCHAR *string, int length)
2702 if (info->dwCPOutputCount)
2703 RTFFlushCPOutputBuffer(info);
2704 while (length)
2706 int fit = min(length, sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount);
2708 memmove(info->OutputBuffer + info->dwOutputCount, string, fit * sizeof(WCHAR));
2709 info->dwOutputCount += fit;
2710 if (fit == sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount)
2711 RTFFlushUnicodeOutputBuffer(info);
2712 length -= fit;
2713 string += fit;
2717 static void
2718 RTFFlushCPOutputBuffer(RTF_Info *info)
2720 int bufferMax = info->dwCPOutputCount * 2 * sizeof(WCHAR);
2721 WCHAR *buffer = (WCHAR *)RTFAlloc(bufferMax);
2722 int length;
2724 length = MultiByteToWideChar(info->codePage, 0, info->cpOutputBuffer,
2725 info->dwCPOutputCount, buffer, bufferMax/sizeof(WCHAR));
2726 info->dwCPOutputCount = 0;
2728 RTFPutUnicodeString(info, buffer, length);
2729 RTFFree((char *)buffer);
2732 void
2733 RTFFlushOutputBuffer(RTF_Info *info)
2735 if (info->dwCPOutputCount)
2736 RTFFlushCPOutputBuffer(info);
2737 RTFFlushUnicodeOutputBuffer(info);
2740 static void
2741 RTFPutUnicodeChar(RTF_Info *info, int c)
2743 if (info->dwCPOutputCount)
2744 RTFFlushCPOutputBuffer(info);
2745 if (info->dwOutputCount * sizeof(WCHAR) >= ( sizeof info->OutputBuffer - 1 ) )
2746 RTFFlushUnicodeOutputBuffer( info );
2747 info->OutputBuffer[info->dwOutputCount++] = c;
2750 static void
2751 RTFPutCodePageChar(RTF_Info *info, int c)
2753 /* Use dynamic buffer here because it's the best way to handle
2754 * MBCS codepages without having to worry about partial chars */
2755 if (info->dwCPOutputCount >= info->dwMaxCPOutputCount)
2757 info->dwMaxCPOutputCount *= 2;
2758 info->cpOutputBuffer = RTFReAlloc(info->cpOutputBuffer, info->dwMaxCPOutputCount);
2760 info->cpOutputBuffer[info->dwCPOutputCount++] = c;