riched20: Fix placement of crlf on font table streamout.
[wine/hacks.git] / dlls / riched20 / reader.c
blobfa1ef79c9f07afb04a6ded479c4a158052d42e79
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 Lookup (RTF_Info *, char *);
68 static int Hash (const char *);
70 static void CharAttr(RTF_Info *info);
71 static void CharSet(RTF_Info *info);
72 static void DocAttr(RTF_Info *info);
74 static void RTFFlushCPOutputBuffer(RTF_Info *info);
75 static void RTFPutCodePageChar(RTF_Info *info, int c);
77 /* ---------------------------------------------------------------------- */
81 * Saves a string on the heap and returns a pointer to it.
83 static inline char *RTFStrSave(const char *s)
85 char *p;
87 p = heap_alloc (lstrlenA(s) + 1);
88 if (p == NULL)
89 return NULL;
90 return lstrcpyA (p, s);
94 /* ---------------------------------------------------------------------- */
97 int _RTFGetChar(RTF_Info *info)
99 int ch;
100 ME_InStream *stream = info->stream;
102 if (stream->dwSize <= stream->dwUsed)
104 ME_StreamInFill(stream);
105 /* if error, it's EOF */
106 if (stream->editstream->dwError)
107 return EOF;
108 /* if no bytes read, it's EOF */
109 if (stream->dwSize == 0)
110 return EOF;
112 ch = (unsigned char)stream->buffer[stream->dwUsed++];
113 if (!ch)
114 return EOF;
115 return ch;
118 void RTFSetEditStream(RTF_Info *info, ME_InStream *stream)
120 info->stream = stream;
123 static void
124 RTFDestroyAttrs(RTF_Info *info)
126 RTFColor *cp;
127 RTFFont *fp;
128 RTFStyle *sp;
129 RTFStyleElt *eltList, *ep;
131 while (info->fontList)
133 fp = info->fontList->rtfNextFont;
134 heap_free (info->fontList->rtfFName);
135 heap_free (info->fontList);
136 info->fontList = fp;
138 while (info->colorList)
140 cp = info->colorList->rtfNextColor;
141 heap_free (info->colorList);
142 info->colorList = cp;
144 while (info->styleList)
146 sp = info->styleList->rtfNextStyle;
147 eltList = info->styleList->rtfSSEList;
148 while (eltList)
150 ep = eltList->rtfNextSE;
151 heap_free (eltList->rtfSEText);
152 heap_free (eltList);
153 eltList = ep;
155 heap_free (info->styleList->rtfSName);
156 heap_free (info->styleList);
157 info->styleList = sp;
162 void
163 RTFDestroy(RTF_Info *info)
165 if (info->rtfTextBuf)
167 heap_free(info->rtfTextBuf);
168 heap_free(info->pushedTextBuf);
170 RTFDestroyAttrs(info);
171 heap_free(info->cpOutputBuffer);
172 while (info->tableDef)
174 RTFTable *tableDef = info->tableDef;
175 info->tableDef = tableDef->parent;
176 heap_free(tableDef);
182 /* ---------------------------------------------------------------------- */
185 * Callback table manipulation routines
190 * Install or return a writer callback for a token class
193 static void RTFSetClassCallback(RTF_Info *info, int class, RTFFuncPtr callback)
195 if (class >= 0 && class < rtfMaxClass)
196 info->ccb[class] = callback;
200 static RTFFuncPtr RTFGetClassCallback(const RTF_Info *info, int class)
202 if (class >= 0 && class < rtfMaxClass)
203 return info->ccb[class];
204 return NULL;
209 * Initialize the reader. This may be called multiple times,
210 * to read multiple files. The only thing not reset is the input
211 * stream; that must be done with RTFSetStream().
214 void RTFInit(RTF_Info *info)
216 int i;
218 if (info->rtfTextBuf == NULL) /* initialize the text buffers */
220 info->rtfTextBuf = heap_alloc (rtfBufSiz);
221 info->pushedTextBuf = heap_alloc (rtfBufSiz);
222 if (info->rtfTextBuf == NULL || info->pushedTextBuf == NULL) {
223 ERR ("Cannot allocate text buffers.\n");
224 return;
226 info->rtfTextBuf[0] = info->pushedTextBuf[0] = '\0';
229 heap_free (info->inputName);
230 heap_free (info->outputName);
231 info->inputName = info->outputName = NULL;
233 for (i = 0; i < rtfMaxClass; i++)
234 RTFSetClassCallback (info, i, NULL);
235 for (i = 0; i < rtfMaxDestination; i++)
236 RTFSetDestinationCallback (info, i, NULL);
238 /* install built-in destination readers */
239 RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl);
240 RTFSetDestinationCallback (info, rtfColorTbl, ReadColorTbl);
241 RTFSetDestinationCallback (info, rtfStyleSheet, ReadStyleSheet);
242 RTFSetDestinationCallback (info, rtfInfo, ReadInfoGroup);
243 RTFSetDestinationCallback (info, rtfPict, ReadPictGroup);
244 RTFSetDestinationCallback (info, rtfObject, ReadObjGroup);
247 RTFSetReadHook (info, NULL);
249 /* dump old lists if necessary */
251 RTFDestroyAttrs(info);
253 info->ansiCodePage = 1252; /* Latin-1; actually unused */
254 info->unicodeLength = 1; /* \uc1 is the default */
255 info->codePage = info->ansiCodePage;
256 info->defFont = 0;
258 info->rtfClass = -1;
259 info->pushedClass = -1;
260 info->pushedChar = EOF;
262 info->rtfLineNum = 0;
263 info->rtfLinePos = 0;
264 info->prevChar = EOF;
265 info->bumpLine = 0;
267 info->dwCPOutputCount = 0;
268 if (!info->cpOutputBuffer)
270 info->dwMaxCPOutputCount = 0x1000;
271 info->cpOutputBuffer = heap_alloc(info->dwMaxCPOutputCount);
274 info->tableDef = NULL;
275 info->nestingLevel = 0;
276 info->canInheritInTbl = FALSE;
277 info->borderType = 0;
281 * Set or get the input or output file name. These are never guaranteed
282 * to be accurate, only insofar as the calling program makes them so.
285 void RTFSetInputName(RTF_Info *info, const char *name)
287 info->inputName = RTFStrSave (name);
288 if (info->inputName == NULL)
289 ERR ("RTFSetInputName: out of memory\n");
293 char *RTFGetInputName(const RTF_Info *info)
295 return (info->inputName);
299 void RTFSetOutputName(RTF_Info *info, const char *name)
301 info->outputName = RTFStrSave (name);
302 if (info->outputName == NULL)
303 ERR ("RTFSetOutputName: out of memory\n");
307 char *RTFGetOutputName(const RTF_Info *info)
309 return (info->outputName);
314 * Install or return a writer callback for a destination type
317 void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback)
319 if (dest >= 0 && dest < rtfMaxDestination)
320 info->dcb[dest] = callback;
324 static RTFFuncPtr RTFGetDestinationCallback(const RTF_Info *info, int dest)
326 if (dest >= 0 && dest < rtfMaxDestination)
327 return info->dcb[dest];
328 return NULL;
332 /* ---------------------------------------------------------------------- */
335 * Token reading routines
340 * Read the input stream, invoking the writer's callbacks
341 * where appropriate.
344 void RTFRead(RTF_Info *info)
346 while (RTFGetToken (info) != rtfEOF)
347 RTFRouteToken (info);
352 * Route a token. If it's a destination for which a reader is
353 * installed, process the destination internally, otherwise
354 * pass the token to the writer's class callback.
357 void RTFRouteToken(RTF_Info *info)
359 RTFFuncPtr p;
361 if (info->rtfClass < 0 || info->rtfClass >= rtfMaxClass) /* watchdog */
363 ERR( "Unknown class %d: %s (reader malfunction)\n",
364 info->rtfClass, info->rtfTextBuf);
366 if (RTFCheckCM (info, rtfControl, rtfDestination))
368 /* invoke destination-specific callback if there is one */
369 p = RTFGetDestinationCallback (info, info->rtfMinor);
370 if (p != NULL)
372 (*p) (info);
373 return;
376 /* invoke class callback if there is one */
377 p = RTFGetClassCallback (info, info->rtfClass);
378 if (p != NULL)
379 (*p) (info);
384 * Skip to the end of the current group. When this returns,
385 * writers that maintain a state stack may want to call their
386 * state unstacker; global vars will still be set to the group's
387 * closing brace.
390 void RTFSkipGroup(RTF_Info *info)
392 int level = 1;
394 while (RTFGetToken (info) != rtfEOF)
396 if (info->rtfClass == rtfGroup)
398 if (info->rtfMajor == rtfBeginGroup)
399 ++level;
400 else if (info->rtfMajor == rtfEndGroup)
402 if (--level < 1)
403 break; /* end of initial group */
410 * Do no special processing on the group.
412 * This acts as a placeholder for a callback in order to indicate that it
413 * shouldn't be ignored. Instead it will fallback on the loop in RTFRead.
415 void RTFReadGroup (RTF_Info *info)
421 * Install or return a token reader hook.
424 void RTFSetReadHook(RTF_Info *info, RTFFuncPtr f)
426 info->readHook = f;
430 static RTFFuncPtr RTFGetReadHook(const RTF_Info *info)
432 return (info->readHook);
437 * Read one token. Call the read hook if there is one. The
438 * token class is the return value. Returns rtfEOF when there
439 * are no more tokens.
442 int RTFGetToken(RTF_Info *info)
444 RTFFuncPtr p;
446 /* don't try to return anything once EOF is reached */
447 if (info->rtfClass == rtfEOF) {
448 return rtfEOF;
451 for (;;)
453 _RTFGetToken (info);
454 p = RTFGetReadHook (info);
455 if (p != NULL)
456 (*p) (info); /* give read hook a look at token */
458 /* Silently discard newlines, carriage returns, nulls. */
459 if (!(info->rtfClass == rtfText && info->rtfFormat != SF_TEXT
460 && (info->rtfMajor == '\r' || info->rtfMajor == '\n' || info->rtfMajor == '\0')))
461 break;
463 return (info->rtfClass);
467 static void RTFUngetToken(RTF_Info *info)
469 if (info->pushedClass >= 0) /* there's already an ungotten token */
470 ERR ("cannot unget two tokens\n");
471 if (info->rtfClass < 0)
472 ERR ("no token to unget\n");
473 info->pushedClass = info->rtfClass;
474 info->pushedMajor = info->rtfMajor;
475 info->pushedMinor = info->rtfMinor;
476 info->pushedParam = info->rtfParam;
477 lstrcpyA (info->pushedTextBuf, info->rtfTextBuf);
478 /* The read hook decrements stackTop on rtfEndGroup, so
479 * increment the value to compensate for it being decremented
480 * twice due to the RTFUngetToken. */
481 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
482 info->stackTop++;
486 int RTFPeekToken(RTF_Info *info)
488 _RTFGetToken (info);
489 RTFUngetToken (info);
490 return (info->rtfClass);
494 static void _RTFGetToken(RTF_Info *info)
496 if (info->rtfFormat == SF_TEXT)
498 info->rtfMajor = GetChar (info);
499 info->rtfMinor = 0;
500 info->rtfParam = rtfNoParam;
501 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
502 if (info->rtfMajor == EOF)
503 info->rtfClass = rtfEOF;
504 else
505 info->rtfClass = rtfText;
506 return;
509 /* first check for pushed token from RTFUngetToken() */
511 if (info->pushedClass >= 0)
513 info->rtfClass = info->pushedClass;
514 info->rtfMajor = info->pushedMajor;
515 info->rtfMinor = info->pushedMinor;
516 info->rtfParam = info->pushedParam;
517 lstrcpyA (info->rtfTextBuf, info->pushedTextBuf);
518 info->rtfTextLen = lstrlenA(info->rtfTextBuf);
519 info->pushedClass = -1;
520 return;
524 * Beyond this point, no token is ever seen twice, which is
525 * important, e.g., for making sure no "}" pops the font stack twice.
528 _RTFGetToken2 (info);
533 RTFCharSetToCodePage(RTF_Info *info, int charset)
535 switch (charset)
537 case ANSI_CHARSET:
538 return 1252;
539 case DEFAULT_CHARSET:
540 return CP_ACP;
541 case SYMBOL_CHARSET:
542 return CP_SYMBOL;
543 case MAC_CHARSET:
544 return CP_MACCP;
545 case SHIFTJIS_CHARSET:
546 return 932;
547 case HANGEUL_CHARSET:
548 return 949;
549 case JOHAB_CHARSET:
550 return 1361;
551 case GB2312_CHARSET:
552 return 936;
553 case CHINESEBIG5_CHARSET:
554 return 950;
555 case GREEK_CHARSET:
556 return 1253;
557 case TURKISH_CHARSET:
558 return 1254;
559 case VIETNAMESE_CHARSET:
560 return 1258;
561 case HEBREW_CHARSET:
562 return 1255;
563 case ARABIC_CHARSET:
564 return 1256;
565 case BALTIC_CHARSET:
566 return 1257;
567 case RUSSIAN_CHARSET:
568 return 1251;
569 case THAI_CHARSET:
570 return 874;
571 case EASTEUROPE_CHARSET:
572 return 1250;
573 case OEM_CHARSET:
574 return CP_OEMCP;
575 default:
577 CHARSETINFO csi;
578 DWORD n = charset;
580 /* FIXME: TranslateCharsetInfo does not work as good as it
581 * should, so let's use it only when all else fails */
582 if (!TranslateCharsetInfo(&n, &csi, TCI_SRCCHARSET))
583 ERR("unknown charset %d\n", charset);
584 else
585 return csi.ciACP;
588 return 0;
592 /* this shouldn't be called anywhere but from _RTFGetToken() */
594 static void _RTFGetToken2(RTF_Info *info)
596 int sign;
597 int c;
599 /* initialize token vars */
601 info->rtfClass = rtfUnknown;
602 info->rtfParam = rtfNoParam;
603 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
605 /* get first character, which may be a pushback from previous token */
607 if (info->pushedChar != EOF)
609 c = info->pushedChar;
610 info->rtfTextBuf[info->rtfTextLen++] = c;
611 info->rtfTextBuf[info->rtfTextLen] = '\0';
612 info->pushedChar = EOF;
614 else if ((c = GetChar (info)) == EOF)
616 info->rtfClass = rtfEOF;
617 return;
620 if (c == '{')
622 info->rtfClass = rtfGroup;
623 info->rtfMajor = rtfBeginGroup;
624 return;
626 if (c == '}')
628 info->rtfClass = rtfGroup;
629 info->rtfMajor = rtfEndGroup;
630 return;
632 if (c != '\\')
635 * Two possibilities here:
636 * 1) ASCII 9, effectively like \tab control symbol
637 * 2) literal text char
639 if (c == '\t') /* ASCII 9 */
641 info->rtfClass = rtfControl;
642 info->rtfMajor = rtfSpecialChar;
643 info->rtfMinor = rtfTab;
645 else
647 info->rtfClass = rtfText;
648 info->rtfMajor = c;
650 return;
652 if ((c = GetChar (info)) == EOF)
654 /* early eof, whoops (class is rtfUnknown) */
655 return;
657 if (!isalpha (c))
660 * Three possibilities here:
661 * 1) hex encoded text char, e.g., \'d5, \'d3
662 * 2) special escaped text char, e.g., \{, \}
663 * 3) control symbol, e.g., \_, \-, \|, \<10>
665 if (c == '\'') /* hex char */
667 int c2;
669 if ((c = GetChar (info)) != EOF && (c2 = GetChar (info)) != EOF
670 && isxdigit(c) && isxdigit(c2))
672 info->rtfClass = rtfText;
673 info->rtfMajor = RTFCharToHex (c) * 16 + RTFCharToHex (c2);
674 return;
676 /* early eof, whoops */
677 info->rtfClass = rtfEOF;
678 info->stream->editstream->dwError = -14;
679 return;
682 /* escaped char */
683 /*if (index (":{}\\", c) != NULL)*/ /* escaped char */
684 if (c == ':' || c == '{' || c == '}' || c == '\\')
686 info->rtfClass = rtfText;
687 info->rtfMajor = c;
688 return;
691 /* control symbol */
692 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
693 return;
695 /* control word */
696 while (isalpha (c))
698 if ((c = GetChar (info)) == EOF)
699 break;
703 * At this point, the control word is all collected, so the
704 * major/minor numbers are determined before the parameter
705 * (if any) is scanned. There will be one too many characters
706 * in the buffer, though, so fix up before and restore after
707 * looking up.
710 if (c != EOF)
711 info->rtfTextBuf[info->rtfTextLen-1] = '\0';
712 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
713 if (c != EOF)
714 info->rtfTextBuf[info->rtfTextLen-1] = c;
717 * Should be looking at first digit of parameter if there
718 * is one, unless it's negative. In that case, next char
719 * is '-', so need to gobble next char, and remember sign.
722 sign = 1;
723 if (c == '-')
725 sign = -1;
726 c = GetChar (info);
728 if (c != EOF && isdigit (c))
730 info->rtfParam = 0;
731 while (isdigit (c)) /* gobble parameter */
733 info->rtfParam = info->rtfParam * 10 + c - '0';
734 if ((c = GetChar (info)) == EOF)
735 break;
737 info->rtfParam *= sign;
740 * If control symbol delimiter was a blank, gobble it.
741 * Otherwise the character is first char of next token, so
742 * push it back for next call. In either case, delete the
743 * delimiter from the token buffer.
745 if (c != EOF)
747 if (c != ' ')
748 info->pushedChar = c;
749 info->rtfTextBuf[--info->rtfTextLen] = '\0';
755 * Read the next character from the input. This handles setting the
756 * current line and position-within-line variables. Those variable are
757 * set correctly whether lines end with CR, LF, or CRLF (the last being
758 * the tricky case).
760 * bumpLine indicates whether the line number should be incremented on
761 * the *next* input character.
765 static int GetChar(RTF_Info *info)
767 int c;
768 int oldBumpLine;
770 if ((c = _RTFGetChar(info)) != EOF)
772 info->rtfTextBuf[info->rtfTextLen++] = c;
773 info->rtfTextBuf[info->rtfTextLen] = '\0';
775 if (info->prevChar == EOF)
776 info->bumpLine = 1;
777 oldBumpLine = info->bumpLine; /* non-zero if prev char was line ending */
778 info->bumpLine = 0;
779 if (c == '\r')
780 info->bumpLine = 1;
781 else if (c == '\n')
783 info->bumpLine = 1;
784 if (info->prevChar == '\r') /* oops, previous \r wasn't */
785 oldBumpLine = 0; /* really a line ending */
787 ++info->rtfLinePos;
788 if (oldBumpLine) /* were we supposed to increment the */
789 { /* line count on this char? */
790 ++info->rtfLineNum;
791 info->rtfLinePos = 1;
793 info->prevChar = c;
794 return (c);
799 * Synthesize a token by setting the global variables to the
800 * values supplied. Typically this is followed with a call
801 * to RTFRouteToken().
803 * If a param value other than rtfNoParam is passed, it becomes
804 * part of the token text.
807 static void RTFSetToken(RTF_Info *info, int class, int major, int minor, int param, const char *text)
809 info->rtfClass = class;
810 info->rtfMajor = major;
811 info->rtfMinor = minor;
812 info->rtfParam = param;
813 if (param == rtfNoParam)
814 lstrcpyA(info->rtfTextBuf, text);
815 else
816 sprintf (info->rtfTextBuf, "%s%d", text, param);
817 info->rtfTextLen = lstrlenA (info->rtfTextBuf);
821 /* ---------------------------------------------------------------------- */
824 * Special destination readers. They gobble the destination so the
825 * writer doesn't have to deal with them. That's wrong for any
826 * translator that wants to process any of these itself. In that
827 * case, these readers should be overridden by installing a different
828 * destination callback.
830 * NOTE: The last token read by each of these reader will be the
831 * destination's terminating '}', which will then be the current token.
832 * That '}' token is passed to RTFRouteToken() - the writer has already
833 * seen the '{' that began the destination group, and may have pushed a
834 * state; it also needs to know at the end of the group that a state
835 * should be popped.
837 * It's important that rtf.h and the control token lookup table list
838 * as many symbols as possible, because these destination readers
839 * unfortunately make strict assumptions about the input they expect,
840 * and a token of class rtfUnknown will throw them off easily.
845 * Read { \fonttbl ... } destination. Old font tables don't have
846 * braces around each table entry; try to adjust for that.
849 static void ReadFontTbl(RTF_Info *info)
851 RTFFont *fp = NULL;
852 char buf[rtfBufSiz], *bp;
853 int old = -1;
854 const char *fn = "ReadFontTbl";
856 for (;;)
858 RTFGetToken (info);
859 if (info->rtfClass == rtfEOF)
860 break;
861 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
862 break;
863 if (old < 0) /* first entry - determine tbl type */
865 if (RTFCheckCMM (info, rtfControl, rtfCharAttr, rtfFontNum))
866 old = 1; /* no brace */
867 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
868 old = 0; /* brace */
869 else /* can't tell! */
870 ERR ( "%s: Cannot determine format\n", fn);
872 if (old == 0) /* need to find "{" here */
874 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
875 ERR ( "%s: missing \"{\"\n", fn);
876 RTFGetToken (info); /* yes, skip to next token */
877 if (info->rtfClass == rtfEOF)
878 break;
880 fp = New (RTFFont);
881 if (fp == NULL) {
882 ERR ( "%s: cannot allocate font entry\n", fn);
883 break;
886 fp->rtfNextFont = info->fontList;
887 info->fontList = fp;
889 fp->rtfFName = NULL;
890 fp->rtfFAltName = NULL;
891 fp->rtfFNum = -1;
892 fp->rtfFFamily = FF_DONTCARE;
893 fp->rtfFCharSet = DEFAULT_CHARSET; /* 1 */
894 fp->rtfFPitch = DEFAULT_PITCH;
895 fp->rtfFType = 0;
896 fp->rtfFCodePage = CP_ACP;
898 while (info->rtfClass != rtfEOF
899 && !RTFCheckCM (info, rtfText, ';')
900 && !RTFCheckCM (info, rtfGroup, rtfEndGroup))
902 if (info->rtfClass == rtfControl)
904 switch (info->rtfMajor)
906 default:
907 /* ignore token but announce it */
908 WARN ("%s: unknown token \"%s\"\n",
909 fn, info->rtfTextBuf);
910 break;
911 case rtfFontFamily:
912 fp->rtfFFamily = info->rtfMinor;
913 break;
914 case rtfCharAttr:
915 switch (info->rtfMinor)
917 default:
918 break; /* ignore unknown? */
919 case rtfFontNum:
920 fp->rtfFNum = info->rtfParam;
921 break;
923 break;
924 case rtfFontAttr:
925 switch (info->rtfMinor)
927 default:
928 break; /* ignore unknown? */
929 case rtfFontCharSet:
930 fp->rtfFCharSet = info->rtfParam;
931 if (!fp->rtfFCodePage)
932 fp->rtfFCodePage = RTFCharSetToCodePage(info, info->rtfParam);
933 break;
934 case rtfFontPitch:
935 fp->rtfFPitch = info->rtfParam;
936 break;
937 case rtfFontCodePage:
938 fp->rtfFCodePage = info->rtfParam;
939 break;
940 case rtfFTypeNil:
941 case rtfFTypeTrueType:
942 fp->rtfFType = info->rtfParam;
943 break;
945 break;
948 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup)) /* dest */
950 RTFSkipGroup (info); /* ignore for now */
952 else if (info->rtfClass == rtfText) /* font name */
954 bp = buf;
955 while (info->rtfClass == rtfText
956 && !RTFCheckCM (info, rtfText, ';'))
958 *bp++ = info->rtfMajor;
959 RTFGetToken (info);
962 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
963 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
965 RTFUngetToken (info);
967 *bp = '\0';
968 fp->rtfFName = RTFStrSave (buf);
969 if (fp->rtfFName == NULL)
970 ERR ( "%s: cannot allocate font name\n", fn);
971 /* already have next token; don't read one */
972 /* at bottom of loop */
973 continue;
975 else
977 /* ignore token but announce it */
978 WARN ( "%s: unknown token \"%s\"\n",
979 fn,info->rtfTextBuf);
981 RTFGetToken (info);
982 if (info->rtfClass == rtfEOF)
983 break;
985 if (info->rtfClass == rtfEOF)
986 break;
987 if (old == 0) /* need to see "}" here */
989 RTFGetToken (info);
990 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
991 ERR ( "%s: missing \"}\"\n", fn);
992 if (info->rtfClass == rtfEOF)
993 break;
996 /* Apply the real properties of the default font */
997 if (fp->rtfFNum == info->defFont)
999 if (info->ansiCodePage != CP_UTF8)
1000 info->codePage = fp->rtfFCodePage;
1001 TRACE("default font codepage %d\n", info->codePage);
1004 if (!fp || (fp->rtfFNum == -1))
1005 ERR( "%s: missing font number\n", fn);
1007 * Could check other pieces of structure here, too, I suppose.
1009 RTFRouteToken (info); /* feed "}" back to router */
1011 /* Set default font */
1012 info->rtfClass = rtfControl;
1013 info->rtfMajor = rtfCharAttr;
1014 info->rtfMinor = rtfFontNum;
1015 info->rtfParam = info->defFont;
1016 lstrcpyA(info->rtfTextBuf, "f");
1017 RTFUngetToken(info);
1022 * The color table entries have color values of -1 if
1023 * the default color should be used for the entry (only
1024 * a semi-colon is given in the definition, no color values).
1025 * There will be a problem if a partial entry (1 or 2 but
1026 * not 3 color values) is given. The possibility is ignored
1027 * here.
1030 static void ReadColorTbl(RTF_Info *info)
1032 RTFColor *cp;
1033 int cnum = 0;
1034 const char *fn = "ReadColorTbl";
1035 int group_level = 1;
1037 for (;;)
1039 RTFGetToken (info);
1040 if (info->rtfClass == rtfEOF)
1041 break;
1042 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1044 group_level--;
1045 if (!group_level)
1046 break;
1047 continue;
1049 else if (RTFCheckCM(info, rtfGroup, rtfBeginGroup))
1051 group_level++;
1052 continue;
1055 cp = New (RTFColor);
1056 if (cp == NULL) {
1057 ERR ( "%s: cannot allocate color entry\n", fn);
1058 break;
1060 cp->rtfCNum = cnum++;
1061 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
1062 cp->rtfNextColor = info->colorList;
1063 info->colorList = cp;
1064 while (RTFCheckCM (info, rtfControl, rtfColorName))
1066 switch (info->rtfMinor)
1068 case rtfRed: cp->rtfCRed = info->rtfParam; break;
1069 case rtfGreen: cp->rtfCGreen = info->rtfParam; break;
1070 case rtfBlue: cp->rtfCBlue = info->rtfParam; break;
1072 RTFGetToken (info);
1074 if (info->rtfClass == rtfEOF)
1075 break;
1076 if (!RTFCheckCM (info, rtfText, ';'))
1077 ERR ("%s: malformed entry\n", fn);
1079 RTFRouteToken (info); /* feed "}" back to router */
1084 * The "Normal" style definition doesn't contain any style number,
1085 * all others do. Normal style is given style rtfNormalStyleNum.
1088 static void ReadStyleSheet(RTF_Info *info)
1090 RTFStyle *sp;
1091 RTFStyleElt *sep, *sepLast;
1092 char buf[rtfBufSiz], *bp;
1093 const char *fn = "ReadStyleSheet";
1094 int real_style;
1096 for (;;)
1098 RTFGetToken (info);
1099 if (info->rtfClass == rtfEOF)
1100 break;
1101 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1102 break;
1103 sp = New (RTFStyle);
1104 if (sp == NULL) {
1105 ERR ( "%s: cannot allocate stylesheet entry\n", fn);
1106 break;
1108 sp->rtfSName = NULL;
1109 sp->rtfSNum = -1;
1110 sp->rtfSType = rtfParStyle;
1111 sp->rtfSAdditive = 0;
1112 sp->rtfSBasedOn = rtfNoStyleNum;
1113 sp->rtfSNextPar = -1;
1114 sp->rtfSSEList = sepLast = NULL;
1115 sp->rtfNextStyle = info->styleList;
1116 sp->rtfExpanding = 0;
1117 info->styleList = sp;
1118 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1119 ERR ( "%s: missing \"{\"\n", fn);
1120 real_style = TRUE;
1121 for (;;)
1123 RTFGetToken (info);
1124 if (info->rtfClass == rtfEOF
1125 || RTFCheckCM (info, rtfText, ';'))
1126 break;
1127 if (info->rtfClass == rtfControl)
1129 if (RTFCheckMM (info, rtfSpecialChar, rtfOptDest)) {
1130 RTFGetToken(info);
1131 ERR( "%s: skipping optional destination\n", fn);
1132 RTFSkipGroup(info);
1133 info->rtfClass = rtfGroup;
1134 info->rtfMajor = rtfEndGroup;
1135 real_style = FALSE;
1136 break; /* ignore "\*" */
1138 if (RTFCheckMM (info, rtfParAttr, rtfStyleNum))
1140 sp->rtfSNum = info->rtfParam;
1141 sp->rtfSType = rtfParStyle;
1142 continue;
1144 if (RTFCheckMM (info, rtfCharAttr, rtfCharStyleNum))
1146 sp->rtfSNum = info->rtfParam;
1147 sp->rtfSType = rtfCharStyle;
1148 continue;
1150 if (RTFCheckMM (info, rtfSectAttr, rtfSectStyleNum))
1152 sp->rtfSNum = info->rtfParam;
1153 sp->rtfSType = rtfSectStyle;
1154 continue;
1156 if (RTFCheckMM (info, rtfStyleAttr, rtfBasedOn))
1158 sp->rtfSBasedOn = info->rtfParam;
1159 continue;
1161 if (RTFCheckMM (info, rtfStyleAttr, rtfAdditive))
1163 sp->rtfSAdditive = 1;
1164 continue;
1166 if (RTFCheckMM (info, rtfStyleAttr, rtfNext))
1168 sp->rtfSNextPar = info->rtfParam;
1169 continue;
1171 sep = New (RTFStyleElt);
1172 if (sep == NULL)
1173 ERR ( "%s: cannot allocate style element\n", fn);
1174 sep->rtfSEClass = info->rtfClass;
1175 sep->rtfSEMajor = info->rtfMajor;
1176 sep->rtfSEMinor = info->rtfMinor;
1177 sep->rtfSEParam = info->rtfParam;
1178 sep->rtfSEText = RTFStrSave (info->rtfTextBuf);
1179 if (sep->rtfSEText == NULL)
1180 ERR ( "%s: cannot allocate style element text\n", fn);
1181 if (sepLast == NULL)
1182 sp->rtfSSEList = sep; /* first element */
1183 else /* add to end */
1184 sepLast->rtfNextSE = sep;
1185 sep->rtfNextSE = NULL;
1186 sepLast = sep;
1188 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1191 * This passes over "{\*\keycode ... }, among
1192 * other things. A temporary (perhaps) hack.
1194 ERR( "%s: skipping begin\n", fn);
1195 RTFSkipGroup (info);
1196 continue;
1198 else if (info->rtfClass == rtfText) /* style name */
1200 bp = buf;
1201 while (info->rtfClass == rtfText)
1203 if (info->rtfMajor == ';')
1205 /* put back for "for" loop */
1206 RTFUngetToken (info);
1207 break;
1209 *bp++ = info->rtfMajor;
1210 RTFGetToken (info);
1212 *bp = '\0';
1213 sp->rtfSName = RTFStrSave (buf);
1214 if (sp->rtfSName == NULL)
1215 ERR ( "%s: cannot allocate style name\n", fn);
1217 else /* unrecognized */
1219 /* ignore token but announce it */
1220 WARN ( "%s: unknown token \"%s\"\n",
1221 fn, info->rtfTextBuf);
1224 if (real_style) {
1225 RTFGetToken (info);
1226 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1227 ERR ( "%s: missing \"}\"\n", fn);
1229 * Check over the style structure. A name is a must.
1230 * If no style number was specified, check whether it's the
1231 * Normal style (in which case it's given style number
1232 * rtfNormalStyleNum). Note that some "normal" style names
1233 * just begin with "Normal" and can have other stuff following,
1234 * e.g., "Normal,Times 10 point". Ugh.
1236 * Some German RTF writers use "Standard" instead of "Normal".
1238 if (sp->rtfSName == NULL)
1239 ERR ( "%s: missing style name\n", fn);
1240 if (sp->rtfSNum < 0)
1242 if (strncmp (buf, "Normal", 6) != 0
1243 && strncmp (buf, "Standard", 8) != 0)
1244 ERR ( "%s: missing style number\n", fn);
1245 sp->rtfSNum = rtfNormalStyleNum;
1247 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1248 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1250 /* otherwise we're just dealing with fake end group from skipped group */
1252 RTFRouteToken (info); /* feed "}" back to router */
1256 static void ReadInfoGroup(RTF_Info *info)
1258 RTFSkipGroup (info);
1259 RTFRouteToken (info); /* feed "}" back to router */
1263 static void ReadPictGroup(RTF_Info *info)
1265 RTFSkipGroup (info);
1266 RTFRouteToken (info); /* feed "}" back to router */
1270 static void ReadObjGroup(RTF_Info *info)
1272 RTFSkipGroup (info);
1273 RTFRouteToken (info); /* feed "}" back to router */
1277 /* ---------------------------------------------------------------------- */
1280 * Routines to return pieces of stylesheet, or font or color tables.
1281 * References to style 0 are mapped onto the Normal style.
1285 static RTFStyle *RTFGetStyle(const RTF_Info *info, int num)
1287 RTFStyle *s;
1289 if (num == -1)
1290 return (info->styleList);
1291 for (s = info->styleList; s != NULL; s = s->rtfNextStyle)
1293 if (s->rtfSNum == num)
1294 break;
1296 return (s); /* NULL if not found */
1300 RTFFont *RTFGetFont(const RTF_Info *info, int num)
1302 RTFFont *f;
1304 if (num == -1)
1305 return (info->fontList);
1306 for (f = info->fontList; f != NULL; f = f->rtfNextFont)
1308 if (f->rtfFNum == num)
1309 break;
1311 return (f); /* NULL if not found */
1315 RTFColor *RTFGetColor(const RTF_Info *info, int num)
1317 RTFColor *c;
1319 if (num == -1)
1320 return (info->colorList);
1321 for (c = info->colorList; c != NULL; c = c->rtfNextColor)
1323 if (c->rtfCNum == num)
1324 break;
1326 return (c); /* NULL if not found */
1330 /* ---------------------------------------------------------------------- */
1334 * Expand style n, if there is such a style.
1337 void RTFExpandStyle(RTF_Info *info, int n)
1339 RTFStyle *s;
1340 RTFStyleElt *se;
1342 if (n == -1)
1343 return;
1344 s = RTFGetStyle (info, n);
1345 if (s == NULL)
1346 return;
1347 if (s->rtfExpanding != 0)
1348 ERR ("Style expansion loop, style %d\n", n);
1349 s->rtfExpanding = 1; /* set expansion flag for loop detection */
1351 * Expand "based-on" style (unless it's the same as the current
1352 * style -- Normal style usually gives itself as its own based-on
1353 * style). Based-on style expansion is done by synthesizing
1354 * the token that the writer needs to see in order to trigger
1355 * another style expansion, and feeding to token back through
1356 * the router so the writer sees it.
1358 if (n != s->rtfSBasedOn)
1360 RTFSetToken (info, rtfControl, rtfParAttr, rtfStyleNum,
1361 s->rtfSBasedOn, "\\s");
1362 RTFRouteToken (info);
1365 * Now route the tokens unique to this style. RTFSetToken()
1366 * isn't used because it would add the param value to the end
1367 * of the token text, which already has it in.
1369 for (se = s->rtfSSEList; se != NULL; se = se->rtfNextSE)
1371 info->rtfClass = se->rtfSEClass;
1372 info->rtfMajor = se->rtfSEMajor;
1373 info->rtfMinor = se->rtfSEMinor;
1374 info->rtfParam = se->rtfSEParam;
1375 lstrcpyA (info->rtfTextBuf, se->rtfSEText);
1376 info->rtfTextLen = lstrlenA (info->rtfTextBuf);
1377 RTFRouteToken (info);
1379 s->rtfExpanding = 0; /* done - clear expansion flag */
1383 /* ---------------------------------------------------------------------- */
1386 * Control symbol lookup routines
1390 typedef struct RTFKey RTFKey;
1392 struct RTFKey
1394 int rtfKMajor; /* major number */
1395 int rtfKMinor; /* minor number */
1396 const char *rtfKStr; /* symbol name */
1397 int rtfKHash; /* symbol name hash value */
1401 * A minor number of -1 means the token has no minor number
1402 * (all valid minor numbers are >= 0).
1405 static RTFKey rtfKey[] =
1408 * Special characters
1411 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1412 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1413 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1414 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1415 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1416 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1417 { rtfSpecialChar, rtfIYear, "yr", 0 },
1418 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1419 { rtfSpecialChar, rtfIDay, "dy", 0 },
1420 { rtfSpecialChar, rtfIHour, "hr", 0 },
1421 { rtfSpecialChar, rtfIMinute, "min", 0 },
1422 { rtfSpecialChar, rtfISecond, "sec", 0 },
1423 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1424 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1425 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1426 { rtfSpecialChar, rtfIIntID, "id", 0 },
1428 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1429 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1430 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1431 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1432 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1433 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1434 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1435 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1436 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1437 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1438 { rtfSpecialChar, rtfCell, "cell", 0 },
1439 { rtfSpecialChar, rtfRow, "row", 0 },
1440 { rtfSpecialChar, rtfPar, "par", 0 },
1441 /* newline and carriage return are synonyms for */
1442 /* \par when they are preceded by a \ character */
1443 { rtfSpecialChar, rtfPar, "\n", 0 },
1444 { rtfSpecialChar, rtfPar, "\r", 0 },
1445 { rtfSpecialChar, rtfSect, "sect", 0 },
1446 { rtfSpecialChar, rtfPage, "page", 0 },
1447 { rtfSpecialChar, rtfColumn, "column", 0 },
1448 { rtfSpecialChar, rtfLine, "line", 0 },
1449 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1450 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1451 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1452 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1453 { rtfSpecialChar, rtfTab, "tab", 0 },
1454 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1455 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1456 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1457 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1458 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1459 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1460 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1461 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1462 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1463 { rtfSpecialChar, rtfFormula, "|", 0 },
1464 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1465 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1466 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1467 { rtfSpecialChar, rtfOptDest, "*", 0 },
1468 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1469 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1470 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1471 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1472 /* is this valid? */
1473 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1474 { rtfSpecialChar, rtfUnicode, "u", 0 },
1475 { rtfSpecialChar, rtfNestCell, "nestcell", 0 },
1476 { rtfSpecialChar, rtfNestRow, "nestrow", 0 },
1479 * Character formatting attributes
1482 { rtfCharAttr, rtfPlain, "plain", 0 },
1483 { rtfCharAttr, rtfBold, "b", 0 },
1484 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1485 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1486 { rtfCharAttr, rtfSubScript, "dn", 0 },
1487 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1488 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1489 { rtfCharAttr, rtfExpand, "expnd", 0 },
1490 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1491 { rtfCharAttr, rtfKerning, "kerning", 0 },
1492 { rtfCharAttr, rtfFontNum, "f", 0 },
1493 { rtfCharAttr, rtfFontSize, "fs", 0 },
1494 { rtfCharAttr, rtfItalic, "i", 0 },
1495 { rtfCharAttr, rtfOutline, "outl", 0 },
1496 { rtfCharAttr, rtfRevised, "revised", 0 },
1497 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1498 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1499 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1500 { rtfCharAttr, rtfShadow, "shad", 0 },
1501 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1502 { rtfCharAttr, rtfUnderline, "ul", 0 },
1503 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1504 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1505 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1506 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1507 { rtfCharAttr, rtfSuperScript, "up", 0 },
1508 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1509 { rtfCharAttr, rtfInvisible, "v", 0 },
1510 { rtfCharAttr, rtfForeColor, "cf", 0 },
1511 { rtfCharAttr, rtfBackColor, "cb", 0 },
1512 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1513 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1514 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1515 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1516 { rtfCharAttr, rtfLanguage, "lang", 0 },
1517 /* this has disappeared from spec 1.2 */
1518 { rtfCharAttr, rtfGray, "gray", 0 },
1519 { rtfCharAttr, rtfUnicodeLength, "uc", 0 },
1522 * Paragraph formatting attributes
1525 { rtfParAttr, rtfParDef, "pard", 0 },
1526 { rtfParAttr, rtfStyleNum, "s", 0 },
1527 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1528 { rtfParAttr, rtfInTable, "intbl", 0 },
1529 { rtfParAttr, rtfKeep, "keep", 0 },
1530 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1531 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1532 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1533 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1534 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1535 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1536 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1537 { rtfParAttr, rtfQuadRight, "qr", 0 },
1538 { rtfParAttr, rtfQuadJust, "qj", 0 },
1539 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1540 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1541 { rtfParAttr, rtfLeftIndent, "li", 0 },
1542 { rtfParAttr, rtfRightIndent, "ri", 0 },
1543 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1544 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1545 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1546 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1548 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1550 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1551 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1553 { rtfParAttr, rtfTabPos, "tx", 0 },
1555 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1556 * although it's not in the spec. It's also redundant, since lj
1557 * tabs are the default.
1559 { rtfParAttr, rtfTabLeft, "tql", 0 },
1560 { rtfParAttr, rtfTabRight, "tqr", 0 },
1561 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1562 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1563 { rtfParAttr, rtfTabBar, "tb", 0 },
1564 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1565 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1566 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1567 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1568 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1570 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1571 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1572 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1573 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1574 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1575 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1576 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1577 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1578 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1579 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1580 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1581 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1582 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1583 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1584 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1585 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1586 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1587 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1588 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1589 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1590 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1591 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1592 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1593 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1594 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1595 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1596 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1597 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1598 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1599 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1600 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1601 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1602 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1603 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1604 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1605 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1607 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1608 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1609 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1610 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1611 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1612 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1613 { rtfParAttr, rtfBorderBox, "box", 0 },
1614 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1615 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1616 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1617 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1618 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1619 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1620 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1621 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1622 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1623 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1625 { rtfParAttr, rtfShading, "shading", 0 },
1626 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1627 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1628 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1629 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1630 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1631 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1632 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1633 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1634 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1635 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1636 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1637 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1638 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1639 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1640 { rtfParAttr, rtfNestLevel, "itap", 0 },
1643 * Section formatting attributes
1646 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1647 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1648 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1649 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1650 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1652 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1653 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1654 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1655 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1656 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1658 { rtfSectAttr, rtfColumns, "cols", 0 },
1659 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1660 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1661 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1662 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1663 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1665 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1666 { rtfSectAttr, rtfLineDist, "linex", 0 },
1667 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1668 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1669 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1670 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1672 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1673 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1674 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1675 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1676 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1677 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1678 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1679 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1680 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1681 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1682 { rtfSectAttr, rtfFooterY, "footery", 0 },
1684 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1685 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1686 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1687 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1688 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1689 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1690 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1691 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1692 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1693 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1694 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1695 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1696 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1697 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1698 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1700 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1701 /* misspelled as "vertal" in specification 1.0 */
1702 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1703 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1704 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
1706 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
1707 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
1709 /* I've seen these in an old spec, but not in real files... */
1710 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1711 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1712 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1713 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1714 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1717 * Document formatting attributes
1720 { rtfDocAttr, rtfDefTab, "deftab", 0 },
1721 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
1722 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
1723 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
1724 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
1725 { rtfDocAttr, rtfLineStart, "linestart", 0 },
1726 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
1727 /* \makeback was given in old version of spec, it's now */
1728 /* listed as \makebackup */
1729 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
1730 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
1731 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
1732 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
1733 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
1734 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
1736 { rtfDocAttr, rtfFENoteType, "fet", 0 },
1737 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
1738 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
1739 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
1740 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
1741 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
1742 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
1743 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
1744 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
1745 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
1746 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
1747 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
1748 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
1749 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
1750 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
1751 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
1752 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
1753 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
1754 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
1755 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
1756 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
1757 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
1758 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
1759 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
1760 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
1761 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
1762 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
1763 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
1765 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
1766 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
1767 { rtfDocAttr, rtfPaperSize, "psz", 0 },
1768 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
1769 { rtfDocAttr, rtfRightMargin, "margr", 0 },
1770 { rtfDocAttr, rtfTopMargin, "margt", 0 },
1771 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
1772 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
1773 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
1774 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
1775 { rtfDocAttr, rtfLandscape, "landscape", 0 },
1776 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
1777 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
1779 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
1781 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
1782 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
1783 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
1784 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
1785 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
1786 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
1787 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
1788 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
1789 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
1790 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
1791 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
1792 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
1794 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
1795 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
1796 { rtfDocAttr, rtfFormShading, "formshade", 0 },
1797 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
1798 { rtfDocAttr, rtfPrintData, "printdata", 0 },
1800 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
1801 { rtfDocAttr, rtfRevisions, "revisions", 0 },
1802 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
1803 { rtfDocAttr, rtfRevBar, "revbar", 0 },
1805 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
1807 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
1808 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
1810 { rtfDocAttr, rtfAnsiCodePage, "ansicpg", 0 },
1811 { rtfDocAttr, rtfUTF8RTF, "urtf", 0 },
1814 * Style attributes
1817 { rtfStyleAttr, rtfAdditive, "additive", 0 },
1818 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
1819 { rtfStyleAttr, rtfNext, "snext", 0 },
1822 * Picture attributes
1825 { rtfPictAttr, rtfMacQD, "macpict", 0 },
1826 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
1827 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
1828 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
1829 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
1830 { rtfPictAttr, rtfEmfBlip, "emfblip", 0 },
1831 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
1832 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
1833 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
1835 { rtfPictAttr, rtfPicWid, "picw", 0 },
1836 { rtfPictAttr, rtfPicHt, "pich", 0 },
1837 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
1838 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
1839 /* these two aren't in the spec, but some writers emit them */
1840 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
1841 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
1842 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
1843 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
1844 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
1845 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
1846 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
1847 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
1848 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
1850 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
1851 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
1853 { rtfPictAttr, rtfPicBinary, "bin", 0 },
1856 * NeXT graphic attributes
1859 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
1860 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
1863 * Destinations
1866 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
1867 { rtfDestination, rtfFontAltName, "falt", 0 },
1868 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
1869 { rtfDestination, rtfFontFile, "fontfile", 0 },
1870 { rtfDestination, rtfFileTbl, "filetbl", 0 },
1871 { rtfDestination, rtfFileInfo, "file", 0 },
1872 { rtfDestination, rtfColorTbl, "colortbl", 0 },
1873 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
1874 { rtfDestination, rtfKeyCode, "keycode", 0 },
1875 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
1876 { rtfDestination, rtfGenerator, "generator", 0 },
1877 { rtfDestination, rtfInfo, "info", 0 },
1878 { rtfDestination, rtfITitle, "title", 0 },
1879 { rtfDestination, rtfISubject, "subject", 0 },
1880 { rtfDestination, rtfIAuthor, "author", 0 },
1881 { rtfDestination, rtfIOperator, "operator", 0 },
1882 { rtfDestination, rtfIKeywords, "keywords", 0 },
1883 { rtfDestination, rtfIComment, "comment", 0 },
1884 { rtfDestination, rtfIVersion, "version", 0 },
1885 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
1886 /* \verscomm may not exist -- was seen in earlier spec version */
1887 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
1888 { rtfDestination, rtfNextFile, "nextfile", 0 },
1889 { rtfDestination, rtfTemplate, "template", 0 },
1890 { rtfDestination, rtfFNSep, "ftnsep", 0 },
1891 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
1892 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
1893 { rtfDestination, rtfENSep, "aftnsep", 0 },
1894 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
1895 { rtfDestination, rtfENContNotice, "aftncn", 0 },
1896 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
1897 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
1898 { rtfDestination, rtfHeader, "header", 0 },
1899 { rtfDestination, rtfFooter, "footer", 0 },
1900 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
1901 { rtfDestination, rtfHeaderRight, "headerr", 0 },
1902 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
1903 { rtfDestination, rtfFooterLeft, "footerl", 0 },
1904 { rtfDestination, rtfFooterRight, "footerr", 0 },
1905 { rtfDestination, rtfFooterFirst, "footerf", 0 },
1906 { rtfDestination, rtfParNumText, "pntext", 0 },
1907 { rtfDestination, rtfParNumbering, "pn", 0 },
1908 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
1909 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
1910 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
1911 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
1912 { rtfDestination, rtfPict, "pict", 0 },
1913 { rtfDestination, rtfObject, "object", 0 },
1914 { rtfDestination, rtfObjClass, "objclass", 0 },
1915 { rtfDestination, rtfObjName, "objname", 0 },
1916 { rtfObjAttr, rtfObjTime, "objtime", 0 },
1917 { rtfDestination, rtfObjData, "objdata", 0 },
1918 { rtfDestination, rtfObjAlias, "objalias", 0 },
1919 { rtfDestination, rtfObjSection, "objsect", 0 },
1920 /* objitem and objtopic aren't documented in the spec! */
1921 { rtfDestination, rtfObjItem, "objitem", 0 },
1922 { rtfDestination, rtfObjTopic, "objtopic", 0 },
1923 { rtfDestination, rtfObjResult, "result", 0 },
1924 { rtfDestination, rtfDrawObject, "do", 0 },
1925 { rtfDestination, rtfFootnote, "footnote", 0 },
1926 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
1927 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
1928 { rtfDestination, rtfAnnotID, "atnid", 0 },
1929 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
1930 { rtfDestination, rtfAnnotation, "annotation", 0 },
1931 { rtfDestination, rtfAnnotRef, "atnref", 0 },
1932 { rtfDestination, rtfAnnotTime, "atntime", 0 },
1933 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
1934 { rtfDestination, rtfField, "field", 0 },
1935 { rtfDestination, rtfFieldInst, "fldinst", 0 },
1936 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
1937 { rtfDestination, rtfDataField, "datafield", 0 },
1938 { rtfDestination, rtfIndex, "xe", 0 },
1939 { rtfDestination, rtfIndexText, "txe", 0 },
1940 { rtfDestination, rtfIndexRange, "rxe", 0 },
1941 { rtfDestination, rtfTOC, "tc", 0 },
1942 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
1943 { rtfDestination, rtfNestTableProps, "nesttableprops", 0 },
1944 { rtfDestination, rtfNoNestTables, "nonesttables", 0 },
1947 * Font families
1950 { rtfFontFamily, rtfFFNil, "fnil", 0 },
1951 { rtfFontFamily, rtfFFRoman, "froman", 0 },
1952 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
1953 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
1954 { rtfFontFamily, rtfFFScript, "fscript", 0 },
1955 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
1956 { rtfFontFamily, rtfFFTech, "ftech", 0 },
1957 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
1960 * Font attributes
1963 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
1964 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
1965 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
1966 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
1967 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
1970 * File table attributes
1973 { rtfFileAttr, rtfFileNum, "fid", 0 },
1974 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
1975 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
1978 * File sources
1981 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
1982 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
1983 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
1984 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
1985 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
1988 * Color names
1991 { rtfColorName, rtfRed, "red", 0 },
1992 { rtfColorName, rtfGreen, "green", 0 },
1993 { rtfColorName, rtfBlue, "blue", 0 },
1996 * Charset names
1999 { rtfCharSet, rtfMacCharSet, "mac", 0 },
2000 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
2001 { rtfCharSet, rtfPcCharSet, "pc", 0 },
2002 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
2005 * Table attributes
2008 { rtfTblAttr, rtfRowDef, "trowd", 0 },
2009 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
2010 { rtfTblAttr, rtfCellPos, "cellx", 0 },
2011 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
2012 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
2014 { rtfTblAttr, rtfRowLeft, "trql", 0 },
2015 { rtfTblAttr, rtfRowRight, "trqr", 0 },
2016 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
2017 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
2018 { rtfTblAttr, rtfRowHt, "trrh", 0 },
2019 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
2020 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
2022 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
2023 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
2025 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
2026 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
2027 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
2028 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
2029 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
2030 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
2032 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
2033 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
2034 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
2035 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
2037 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
2038 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
2039 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
2040 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
2041 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
2042 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
2043 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
2045 * The spec lists "clbgdkhor", but the corresponding non-cell
2046 * control is "bgdkhoriz". At any rate Macintosh Word seems
2047 * to accept both "clbgdkhor" and "clbgdkhoriz".
2049 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
2050 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
2051 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
2052 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
2053 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
2054 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
2055 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
2056 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
2057 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
2060 * Field attributes
2063 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
2064 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
2065 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
2066 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
2067 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
2070 * Positioning attributes
2073 { rtfPosAttr, rtfAbsWid, "absw", 0 },
2074 { rtfPosAttr, rtfAbsHt, "absh", 0 },
2076 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
2077 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
2078 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
2079 { rtfPosAttr, rtfPosX, "posx", 0 },
2080 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
2081 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
2082 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
2083 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
2084 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
2085 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
2087 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
2088 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
2089 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
2090 { rtfPosAttr, rtfPosY, "posy", 0 },
2091 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
2092 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
2093 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
2094 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
2095 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
2097 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
2098 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
2099 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
2100 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
2101 /* \dyfrtext no longer exists in spec 1.2, apparently */
2102 /* replaced by \dfrmtextx and \dfrmtexty. */
2103 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
2105 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
2106 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
2109 * Object controls
2112 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
2113 { rtfObjAttr, rtfObjLink, "objlink", 0 },
2114 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
2115 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
2116 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
2117 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
2119 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
2120 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
2121 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
2123 { rtfObjAttr, rtfObjHt, "objh", 0 },
2124 { rtfObjAttr, rtfObjWid, "objw", 0 },
2125 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
2126 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
2127 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
2128 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
2129 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
2130 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
2131 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
2132 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
2133 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2135 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2136 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2137 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2138 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2139 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2141 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2142 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2145 * Associated character formatting attributes
2148 { rtfACharAttr, rtfACBold, "ab", 0 },
2149 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2150 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2151 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2152 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2153 { rtfACharAttr, rtfACFontNum, "af", 0 },
2154 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2155 { rtfACharAttr, rtfACItalic, "ai", 0 },
2156 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2157 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2158 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2159 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2160 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2161 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2162 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2163 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2164 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2165 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2166 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2169 * Footnote attributes
2172 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2175 * Key code attributes
2178 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2179 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2180 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2181 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2184 * Bookmark attributes
2187 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2188 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2191 * Index entry attributes
2194 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2195 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2196 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2199 * Table of contents attributes
2202 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2203 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2206 * Drawing object attributes
2209 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2210 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2211 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2212 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2213 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2214 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2215 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2216 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2218 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2219 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2220 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2221 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2222 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2223 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2224 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2225 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2226 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2227 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2228 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2230 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2231 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2232 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2233 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2235 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2236 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2237 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2238 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2239 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2240 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2241 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2242 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2243 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2244 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2245 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2246 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2247 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2248 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2249 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2250 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2251 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2253 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2254 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2255 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2257 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2258 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2259 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2261 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2262 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2264 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2265 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2266 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2267 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2268 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2269 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2270 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2271 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2272 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2273 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2274 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2275 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2277 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2278 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2279 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2280 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2281 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2282 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2283 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2284 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2286 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2287 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2288 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2289 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2290 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2291 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2292 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2293 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2294 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2295 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2296 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2298 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2299 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2300 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2302 { rtfVersion, -1, "rtf", 0 },
2303 { rtfDefFont, -1, "deff", 0 },
2305 { 0, -1, NULL, 0 }
2307 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2309 typedef struct tagRTFHashTableEntry {
2310 int count;
2311 RTFKey **value;
2312 } RTFHashTableEntry;
2314 static RTFHashTableEntry rtfHashTable[RTF_KEY_COUNT * 2];
2318 * Initialize lookup table hash values. Only need to do this once.
2321 void LookupInit(void)
2323 RTFKey *rp;
2325 memset(rtfHashTable, 0, sizeof rtfHashTable);
2326 for (rp = rtfKey; rp->rtfKStr != NULL; rp++)
2328 int index;
2330 rp->rtfKHash = Hash (rp->rtfKStr);
2331 index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
2332 if (!rtfHashTable[index].count)
2333 rtfHashTable[index].value = heap_alloc(sizeof(RTFKey *));
2334 else
2335 rtfHashTable[index].value = heap_realloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
2336 rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
2340 void LookupCleanup(void)
2342 unsigned int i;
2344 for (i=0; i<RTF_KEY_COUNT*2; i++)
2346 heap_free( rtfHashTable[i].value );
2347 rtfHashTable[i].value = NULL;
2348 rtfHashTable[i].count = 0;
2354 * Determine major and minor number of control token. If it's
2355 * not found, the class turns into rtfUnknown.
2358 static void Lookup(RTF_Info *info, char *s)
2360 RTFKey *rp;
2361 int hash;
2362 RTFHashTableEntry *entry;
2363 int i;
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(const RTF_Info *info, int class, int major)
2408 return (info->rtfClass == class && info->rtfMajor == major);
2412 int RTFCheckCMM(const RTF_Info *info, int class, int major, int minor)
2414 return (info->rtfClass == class && info->rtfMajor == major && info->rtfMinor == minor);
2418 int RTFCheckMM(const 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 switch (info->rtfMajor)
2499 case rtfCharAttr:
2500 CharAttr(info);
2501 ME_RTFCharAttrHook(info);
2502 break;
2503 case rtfParAttr:
2504 ME_RTFParAttrHook(info);
2505 break;
2506 case rtfTblAttr:
2507 ME_RTFTblAttrHook(info);
2508 break;
2509 case rtfCharSet:
2510 CharSet(info);
2511 break;
2512 case rtfDefFont:
2513 DefFont(info);
2514 break;
2515 case rtfDestination:
2516 Destination (info);
2517 break;
2518 case rtfDocAttr:
2519 DocAttr(info);
2520 break;
2521 case rtfSpecialChar:
2522 SpecialChar (info);
2523 ME_RTFSpecialCharHook(info);
2524 break;
2529 static void
2530 CharAttr(RTF_Info *info)
2532 RTFFont *font;
2534 switch (info->rtfMinor)
2536 case rtfFontNum:
2537 font = RTFGetFont(info, info->rtfParam);
2538 if (font)
2540 if (info->ansiCodePage != CP_UTF8)
2541 info->codePage = font->rtfFCodePage;
2542 TRACE("font %d codepage %d\n", info->rtfParam, info->codePage);
2544 else
2545 ERR( "unknown font %d\n", info->rtfParam);
2546 break;
2547 case rtfUnicodeLength:
2548 info->unicodeLength = info->rtfParam;
2549 break;
2554 static void
2555 CharSet(RTF_Info *info)
2557 if (info->ansiCodePage == CP_UTF8)
2558 return;
2560 switch (info->rtfMinor)
2562 case rtfAnsiCharSet:
2563 info->ansiCodePage = 1252; /* Latin-1 */
2564 break;
2565 case rtfMacCharSet:
2566 info->ansiCodePage = 10000; /* MacRoman */
2567 break;
2568 case rtfPcCharSet:
2569 info->ansiCodePage = 437;
2570 break;
2571 case rtfPcaCharSet:
2572 info->ansiCodePage = 850;
2573 break;
2578 * This function notices destinations that aren't explicitly handled
2579 * and skips to their ends. This keeps, for instance, picture
2580 * data from being considered as plain text.
2583 static void
2584 Destination (RTF_Info *info)
2586 if (!RTFGetDestinationCallback(info, info->rtfMinor))
2587 RTFSkipGroup (info);
2591 static void
2592 DefFont(RTF_Info *info)
2594 TRACE("%d\n", info->rtfParam);
2595 info->defFont = info->rtfParam;
2599 static void
2600 DocAttr(RTF_Info *info)
2602 TRACE("minor %d, param %d\n", info->rtfMinor, info->rtfParam);
2604 switch (info->rtfMinor)
2606 case rtfAnsiCodePage:
2607 info->codePage = info->ansiCodePage = info->rtfParam;
2608 break;
2609 case rtfUTF8RTF:
2610 info->codePage = info->ansiCodePage = CP_UTF8;
2611 break;
2616 static void SpecialChar (RTF_Info *info)
2618 switch (info->rtfMinor)
2620 case rtfOptDest:
2621 /* the next token determines destination, if it's unknown, skip the group */
2622 /* this way we filter out the garbage coming from unknown destinations */
2623 RTFGetToken(info);
2624 if (info->rtfClass != rtfDestination)
2625 RTFSkipGroup(info);
2626 else
2627 RTFRouteToken(info); /* "\*" is ignored with known destinations */
2628 break;
2629 case rtfUnicode:
2631 int i;
2633 RTFPutUnicodeChar(info, info->rtfParam);
2635 /* After \u we must skip number of character tokens set by \ucN */
2636 for (i = 0; i < info->unicodeLength; i++)
2638 RTFGetToken(info);
2639 if (info->rtfClass != rtfText)
2641 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2642 info->rtfClass, info->rtfMajor, info->rtfMinor);
2643 RTFUngetToken(info);
2644 break;
2647 break;
2649 case rtfLine:
2650 RTFFlushOutputBuffer(info);
2651 ME_InsertEndRowFromCursor(info->editor, 0);
2652 break;
2653 case rtfPage:
2654 case rtfSect:
2655 case rtfPar:
2656 RTFPutUnicodeChar (info, '\r');
2657 if (info->editor->bEmulateVersion10) RTFPutUnicodeChar (info, '\n');
2658 break;
2659 case rtfNoBrkSpace:
2660 RTFPutUnicodeChar (info, 0x00A0);
2661 break;
2662 case rtfTab:
2663 RTFPutUnicodeChar (info, '\t');
2664 break;
2665 case rtfNoBrkHyphen:
2666 RTFPutUnicodeChar (info, 0x2011);
2667 break;
2668 case rtfBullet:
2669 RTFPutUnicodeChar (info, 0x2022);
2670 break;
2671 case rtfEmDash:
2672 RTFPutUnicodeChar (info, 0x2014);
2673 break;
2674 case rtfEnDash:
2675 RTFPutUnicodeChar (info, 0x2013);
2676 break;
2677 case rtfLQuote:
2678 RTFPutUnicodeChar (info, 0x2018);
2679 break;
2680 case rtfRQuote:
2681 RTFPutUnicodeChar (info, 0x2019);
2682 break;
2683 case rtfLDblQuote:
2684 RTFPutUnicodeChar (info, 0x201C);
2685 break;
2686 case rtfRDblQuote:
2687 RTFPutUnicodeChar (info, 0x201D);
2688 break;
2693 static void
2694 RTFFlushUnicodeOutputBuffer(RTF_Info *info)
2696 if (info->dwOutputCount)
2698 ME_InsertTextFromCursor(info->editor, 0, info->OutputBuffer,
2699 info->dwOutputCount, info->style);
2700 info->dwOutputCount = 0;
2705 static void
2706 RTFPutUnicodeString(RTF_Info *info, const WCHAR *string, int length)
2708 if (info->dwCPOutputCount)
2709 RTFFlushCPOutputBuffer(info);
2710 while (length)
2712 int fit = min(length, sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount);
2714 memmove(info->OutputBuffer + info->dwOutputCount, string, fit * sizeof(WCHAR));
2715 info->dwOutputCount += fit;
2716 length -= fit;
2717 string += fit;
2718 if (sizeof(info->OutputBuffer) / sizeof(WCHAR) == info->dwOutputCount)
2719 RTFFlushUnicodeOutputBuffer(info);
2723 static void
2724 RTFFlushCPOutputBuffer(RTF_Info *info)
2726 int bufferMax = info->dwCPOutputCount * 2 * sizeof(WCHAR);
2727 WCHAR *buffer = heap_alloc(bufferMax);
2728 int length;
2730 length = MultiByteToWideChar(info->codePage, 0, info->cpOutputBuffer,
2731 info->dwCPOutputCount, buffer, bufferMax/sizeof(WCHAR));
2732 info->dwCPOutputCount = 0;
2734 RTFPutUnicodeString(info, buffer, length);
2735 heap_free(buffer);
2738 void
2739 RTFFlushOutputBuffer(RTF_Info *info)
2741 if (info->dwCPOutputCount)
2742 RTFFlushCPOutputBuffer(info);
2743 RTFFlushUnicodeOutputBuffer(info);
2746 static void
2747 RTFPutUnicodeChar(RTF_Info *info, int c)
2749 if (info->dwCPOutputCount)
2750 RTFFlushCPOutputBuffer(info);
2751 if (info->dwOutputCount * sizeof(WCHAR) >= ( sizeof info->OutputBuffer - 1 ) )
2752 RTFFlushUnicodeOutputBuffer( info );
2753 info->OutputBuffer[info->dwOutputCount++] = c;
2756 static void
2757 RTFPutCodePageChar(RTF_Info *info, int c)
2759 /* Use dynamic buffer here because it's the best way to handle
2760 * MBCS codepages without having to worry about partial chars */
2761 if (info->dwCPOutputCount >= info->dwMaxCPOutputCount)
2763 info->dwMaxCPOutputCount *= 2;
2764 info->cpOutputBuffer = heap_realloc(info->cpOutputBuffer, info->dwMaxCPOutputCount);
2766 info->cpOutputBuffer[info->dwCPOutputCount++] = c;