taskmgr: Remove dead code.
[wine/multimedia.git] / dlls / riched20 / reader.c
blobe5202aabe4beb8470f641968bea0a1405b9a2d9b
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 static int _RTFGetChar(RTF_Info *);
56 static void _RTFGetToken (RTF_Info *);
57 static void _RTFGetToken2 (RTF_Info *);
58 static int GetChar (RTF_Info *);
59 static void ReadFontTbl (RTF_Info *);
60 static void ReadColorTbl (RTF_Info *);
61 static void ReadStyleSheet (RTF_Info *);
62 static void ReadInfoGroup (RTF_Info *);
63 static void ReadPictGroup (RTF_Info *);
64 static void ReadObjGroup (RTF_Info *);
65 static void Lookup (RTF_Info *, char *);
66 static int Hash (const char *);
68 static void CharAttr(RTF_Info *info);
69 static void CharSet(RTF_Info *info);
70 static void DocAttr(RTF_Info *info);
72 static void RTFFlushCPOutputBuffer(RTF_Info *info);
73 static void RTFPutCodePageChar(RTF_Info *info, int c);
75 /* ---------------------------------------------------------------------- */
79 * Saves a string on the heap and returns a pointer to it.
81 static inline char *RTFStrSave(const char *s)
83 char *p;
85 p = heap_alloc (lstrlenA(s) + 1);
86 if (p == NULL)
87 return NULL;
88 return lstrcpyA (p, s);
92 /* ---------------------------------------------------------------------- */
95 int _RTFGetChar(RTF_Info *info)
97 int ch;
98 ME_InStream *stream = info->stream;
100 if (stream->dwSize <= stream->dwUsed)
102 ME_StreamInFill(stream);
103 /* if error, it's EOF */
104 if (stream->editstream->dwError)
105 return EOF;
106 /* if no bytes read, it's EOF */
107 if (stream->dwSize == 0)
108 return EOF;
110 ch = (unsigned char)stream->buffer[stream->dwUsed++];
111 if (!ch)
112 return EOF;
113 return ch;
116 void RTFSetEditStream(RTF_Info *info, ME_InStream *stream)
118 info->stream = stream;
121 static void
122 RTFDestroyAttrs(RTF_Info *info)
124 RTFColor *cp;
125 RTFFont *fp;
126 RTFStyle *sp;
127 RTFStyleElt *eltList, *ep;
129 while (info->fontList)
131 fp = info->fontList->rtfNextFont;
132 heap_free (info->fontList->rtfFName);
133 heap_free (info->fontList);
134 info->fontList = fp;
136 while (info->colorList)
138 cp = info->colorList->rtfNextColor;
139 heap_free (info->colorList);
140 info->colorList = cp;
142 while (info->styleList)
144 sp = info->styleList->rtfNextStyle;
145 eltList = info->styleList->rtfSSEList;
146 while (eltList)
148 ep = eltList->rtfNextSE;
149 heap_free (eltList->rtfSEText);
150 heap_free (eltList);
151 eltList = ep;
153 heap_free (info->styleList->rtfSName);
154 heap_free (info->styleList);
155 info->styleList = sp;
160 void
161 RTFDestroy(RTF_Info *info)
163 if (info->rtfTextBuf)
165 heap_free(info->rtfTextBuf);
166 heap_free(info->pushedTextBuf);
168 RTFDestroyAttrs(info);
169 heap_free(info->cpOutputBuffer);
170 while (info->tableDef)
172 RTFTable *tableDef = info->tableDef;
173 info->tableDef = tableDef->parent;
174 heap_free(tableDef);
180 /* ---------------------------------------------------------------------- */
183 * Callback table manipulation routines
188 * Install or return a writer callback for a token class
191 static void RTFSetClassCallback(RTF_Info *info, int class, RTFFuncPtr callback)
193 if (class >= 0 && class < rtfMaxClass)
194 info->ccb[class] = callback;
198 static RTFFuncPtr RTFGetClassCallback(const RTF_Info *info, int class)
200 if (class >= 0 && class < rtfMaxClass)
201 return info->ccb[class];
202 return NULL;
207 * Initialize the reader. This may be called multiple times,
208 * to read multiple files. The only thing not reset is the input
209 * stream; that must be done with RTFSetStream().
212 void RTFInit(RTF_Info *info)
214 int i;
216 if (info->rtfTextBuf == NULL) /* initialize the text buffers */
218 info->rtfTextBuf = heap_alloc (rtfBufSiz);
219 info->pushedTextBuf = heap_alloc (rtfBufSiz);
220 if (info->rtfTextBuf == NULL || info->pushedTextBuf == NULL) {
221 ERR ("Cannot allocate text buffers.\n");
222 return;
224 info->rtfTextBuf[0] = info->pushedTextBuf[0] = '\0';
227 for (i = 0; i < rtfMaxClass; i++)
228 RTFSetClassCallback (info, i, NULL);
229 for (i = 0; i < rtfMaxDestination; i++)
230 RTFSetDestinationCallback (info, i, NULL);
232 /* install built-in destination readers */
233 RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl);
234 RTFSetDestinationCallback (info, rtfColorTbl, ReadColorTbl);
235 RTFSetDestinationCallback (info, rtfStyleSheet, ReadStyleSheet);
236 RTFSetDestinationCallback (info, rtfInfo, ReadInfoGroup);
237 RTFSetDestinationCallback (info, rtfPict, ReadPictGroup);
238 RTFSetDestinationCallback (info, rtfObject, ReadObjGroup);
241 RTFSetReadHook (info, NULL);
243 /* dump old lists if necessary */
245 RTFDestroyAttrs(info);
247 info->ansiCodePage = 1252; /* Latin-1; actually unused */
248 info->unicodeLength = 1; /* \uc1 is the default */
249 info->codePage = info->ansiCodePage;
250 info->defFont = 0;
252 info->rtfClass = -1;
253 info->pushedClass = -1;
254 info->pushedChar = EOF;
256 info->rtfLineNum = 0;
257 info->rtfLinePos = 0;
258 info->prevChar = EOF;
259 info->bumpLine = FALSE;
261 info->dwCPOutputCount = 0;
262 if (!info->cpOutputBuffer)
264 info->dwMaxCPOutputCount = 0x1000;
265 info->cpOutputBuffer = heap_alloc(info->dwMaxCPOutputCount);
268 info->tableDef = NULL;
269 info->nestingLevel = 0;
270 info->canInheritInTbl = FALSE;
271 info->borderType = 0;
275 * Install or return a writer callback for a destination type
278 void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback)
280 if (dest >= 0 && dest < rtfMaxDestination)
281 info->dcb[dest] = callback;
285 static RTFFuncPtr RTFGetDestinationCallback(const RTF_Info *info, int dest)
287 if (dest >= 0 && dest < rtfMaxDestination)
288 return info->dcb[dest];
289 return NULL;
293 /* ---------------------------------------------------------------------- */
296 * Token reading routines
301 * Read the input stream, invoking the writer's callbacks
302 * where appropriate.
305 void RTFRead(RTF_Info *info)
307 while (RTFGetToken (info) != rtfEOF)
308 RTFRouteToken (info);
313 * Route a token. If it's a destination for which a reader is
314 * installed, process the destination internally, otherwise
315 * pass the token to the writer's class callback.
318 void RTFRouteToken(RTF_Info *info)
320 RTFFuncPtr p;
322 if (info->rtfClass < 0 || info->rtfClass >= rtfMaxClass) /* watchdog */
324 ERR( "Unknown class %d: %s (reader malfunction)\n",
325 info->rtfClass, info->rtfTextBuf);
327 if (RTFCheckCM (info, rtfControl, rtfDestination))
329 /* invoke destination-specific callback if there is one */
330 p = RTFGetDestinationCallback (info, info->rtfMinor);
331 if (p != NULL)
333 (*p) (info);
334 return;
337 /* invoke class callback if there is one */
338 p = RTFGetClassCallback (info, info->rtfClass);
339 if (p != NULL)
340 (*p) (info);
345 * Skip to the end of the current group. When this returns,
346 * writers that maintain a state stack may want to call their
347 * state unstacker; global vars will still be set to the group's
348 * closing brace.
351 void RTFSkipGroup(RTF_Info *info)
353 int level = 1;
355 while (RTFGetToken (info) != rtfEOF)
357 if (info->rtfClass == rtfGroup)
359 if (info->rtfMajor == rtfBeginGroup)
360 ++level;
361 else if (info->rtfMajor == rtfEndGroup)
363 if (--level < 1)
364 break; /* end of initial group */
371 * Do no special processing on the group.
373 * This acts as a placeholder for a callback in order to indicate that it
374 * shouldn't be ignored. Instead it will fallback on the loop in RTFRead.
376 void RTFReadGroup (RTF_Info *info)
382 * Install or return a token reader hook.
385 void RTFSetReadHook(RTF_Info *info, RTFFuncPtr f)
387 info->readHook = f;
391 static RTFFuncPtr RTFGetReadHook(const RTF_Info *info)
393 return (info->readHook);
398 * Read one token. Call the read hook if there is one. The
399 * token class is the return value. Returns rtfEOF when there
400 * are no more tokens.
403 int RTFGetToken(RTF_Info *info)
405 RTFFuncPtr p;
407 /* don't try to return anything once EOF is reached */
408 if (info->rtfClass == rtfEOF) {
409 return rtfEOF;
412 for (;;)
414 _RTFGetToken (info);
415 p = RTFGetReadHook (info);
416 if (p != NULL)
417 (*p) (info); /* give read hook a look at token */
419 /* Silently discard newlines, carriage returns, nulls. */
420 if (!(info->rtfClass == rtfText && info->rtfFormat != SF_TEXT
421 && (info->rtfMajor == '\r' || info->rtfMajor == '\n' || info->rtfMajor == '\0')))
422 break;
424 return (info->rtfClass);
428 static void RTFUngetToken(RTF_Info *info)
430 if (info->pushedClass >= 0) /* there's already an ungotten token */
431 ERR ("cannot unget two tokens\n");
432 if (info->rtfClass < 0)
433 ERR ("no token to unget\n");
434 info->pushedClass = info->rtfClass;
435 info->pushedMajor = info->rtfMajor;
436 info->pushedMinor = info->rtfMinor;
437 info->pushedParam = info->rtfParam;
438 lstrcpyA (info->pushedTextBuf, info->rtfTextBuf);
439 /* The read hook decrements stackTop on rtfEndGroup, so
440 * increment the value to compensate for it being decremented
441 * twice due to the RTFUngetToken. */
442 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
444 info->stack[info->stackTop].style = info->style;
445 ME_AddRefStyle(info->style);
446 info->stackTop++;
451 static void _RTFGetToken(RTF_Info *info)
453 if (info->rtfFormat == SF_TEXT)
455 info->rtfMajor = GetChar (info);
456 info->rtfMinor = 0;
457 info->rtfParam = rtfNoParam;
458 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
459 if (info->rtfMajor == EOF)
460 info->rtfClass = rtfEOF;
461 else
462 info->rtfClass = rtfText;
463 return;
466 /* first check for pushed token from RTFUngetToken() */
468 if (info->pushedClass >= 0)
470 info->rtfClass = info->pushedClass;
471 info->rtfMajor = info->pushedMajor;
472 info->rtfMinor = info->pushedMinor;
473 info->rtfParam = info->pushedParam;
474 lstrcpyA (info->rtfTextBuf, info->pushedTextBuf);
475 info->rtfTextLen = lstrlenA(info->rtfTextBuf);
476 info->pushedClass = -1;
477 return;
481 * Beyond this point, no token is ever seen twice, which is
482 * important, e.g., for making sure no "}" pops the font stack twice.
485 _RTFGetToken2 (info);
490 RTFCharSetToCodePage(RTF_Info *info, int charset)
492 switch (charset)
494 case ANSI_CHARSET:
495 return 1252;
496 case DEFAULT_CHARSET:
497 return CP_ACP;
498 case SYMBOL_CHARSET:
499 return CP_SYMBOL;
500 case MAC_CHARSET:
501 return CP_MACCP;
502 case SHIFTJIS_CHARSET:
503 return 932;
504 case HANGEUL_CHARSET:
505 return 949;
506 case JOHAB_CHARSET:
507 return 1361;
508 case GB2312_CHARSET:
509 return 936;
510 case CHINESEBIG5_CHARSET:
511 return 950;
512 case GREEK_CHARSET:
513 return 1253;
514 case TURKISH_CHARSET:
515 return 1254;
516 case VIETNAMESE_CHARSET:
517 return 1258;
518 case HEBREW_CHARSET:
519 return 1255;
520 case ARABIC_CHARSET:
521 return 1256;
522 case BALTIC_CHARSET:
523 return 1257;
524 case RUSSIAN_CHARSET:
525 return 1251;
526 case THAI_CHARSET:
527 return 874;
528 case EASTEUROPE_CHARSET:
529 return 1250;
530 case OEM_CHARSET:
531 return CP_OEMCP;
532 default:
534 CHARSETINFO csi;
535 DWORD n = charset;
537 /* FIXME: TranslateCharsetInfo does not work as good as it
538 * should, so let's use it only when all else fails */
539 if (!TranslateCharsetInfo(&n, &csi, TCI_SRCCHARSET))
540 ERR("unknown charset %d\n", charset);
541 else
542 return csi.ciACP;
545 return 0;
549 /* this shouldn't be called anywhere but from _RTFGetToken() */
551 static void _RTFGetToken2(RTF_Info *info)
553 int sign;
554 int c;
556 /* initialize token vars */
558 info->rtfClass = rtfUnknown;
559 info->rtfParam = rtfNoParam;
560 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
562 /* get first character, which may be a pushback from previous token */
564 if (info->pushedChar != EOF)
566 c = info->pushedChar;
567 info->rtfTextBuf[info->rtfTextLen++] = c;
568 info->rtfTextBuf[info->rtfTextLen] = '\0';
569 info->pushedChar = EOF;
571 else if ((c = GetChar (info)) == EOF)
573 info->rtfClass = rtfEOF;
574 return;
577 if (c == '{')
579 info->rtfClass = rtfGroup;
580 info->rtfMajor = rtfBeginGroup;
581 return;
583 if (c == '}')
585 info->rtfClass = rtfGroup;
586 info->rtfMajor = rtfEndGroup;
587 return;
589 if (c != '\\')
592 * Two possibilities here:
593 * 1) ASCII 9, effectively like \tab control symbol
594 * 2) literal text char
596 if (c == '\t') /* ASCII 9 */
598 info->rtfClass = rtfControl;
599 info->rtfMajor = rtfSpecialChar;
600 info->rtfMinor = rtfTab;
602 else
604 info->rtfClass = rtfText;
605 info->rtfMajor = c;
607 return;
609 if ((c = GetChar (info)) == EOF)
611 /* early eof, whoops (class is rtfUnknown) */
612 return;
614 if (!isalpha (c))
617 * Three possibilities here:
618 * 1) hex encoded text char, e.g., \'d5, \'d3
619 * 2) special escaped text char, e.g., \{, \}
620 * 3) control symbol, e.g., \_, \-, \|, \<10>
622 if (c == '\'') /* hex char */
624 int c2;
626 if ((c = GetChar (info)) != EOF && (c2 = GetChar (info)) != EOF
627 && isxdigit(c) && isxdigit(c2))
629 info->rtfClass = rtfText;
630 info->rtfMajor = RTFCharToHex (c) * 16 + RTFCharToHex (c2);
631 return;
633 /* early eof, whoops */
634 info->rtfClass = rtfEOF;
635 info->stream->editstream->dwError = -14;
636 return;
639 /* escaped char */
640 /*if (index (":{}\\", c) != NULL)*/ /* escaped char */
641 if (c == ':' || c == '{' || c == '}' || c == '\\')
643 info->rtfClass = rtfText;
644 info->rtfMajor = c;
645 return;
648 /* control symbol */
649 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
650 return;
652 /* control word */
653 while (isalpha (c))
655 if ((c = GetChar (info)) == EOF)
656 break;
660 * At this point, the control word is all collected, so the
661 * major/minor numbers are determined before the parameter
662 * (if any) is scanned. There will be one too many characters
663 * in the buffer, though, so fix up before and restore after
664 * looking up.
667 if (c != EOF)
668 info->rtfTextBuf[info->rtfTextLen-1] = '\0';
669 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
670 if (c != EOF)
671 info->rtfTextBuf[info->rtfTextLen-1] = c;
674 * Should be looking at first digit of parameter if there
675 * is one, unless it's negative. In that case, next char
676 * is '-', so need to gobble next char, and remember sign.
679 sign = 1;
680 if (c == '-')
682 sign = -1;
683 c = GetChar (info);
685 if (c != EOF && isdigit (c))
687 info->rtfParam = 0;
688 while (isdigit (c)) /* gobble parameter */
690 info->rtfParam = info->rtfParam * 10 + c - '0';
691 if ((c = GetChar (info)) == EOF)
692 break;
694 info->rtfParam *= sign;
697 * If control symbol delimiter was a blank, gobble it.
698 * Otherwise the character is first char of next token, so
699 * push it back for next call. In either case, delete the
700 * delimiter from the token buffer.
702 if (c != EOF)
704 if (c != ' ')
705 info->pushedChar = c;
706 info->rtfTextBuf[--info->rtfTextLen] = '\0';
712 * Read the next character from the input. This handles setting the
713 * current line and position-within-line variables. Those variables are
714 * set correctly whether lines end with CR, LF, or CRLF (the last being
715 * the tricky case).
717 * bumpLine indicates whether the line number should be incremented on
718 * the *next* input character.
722 static int GetChar(RTF_Info *info)
724 int c;
725 BOOL oldBumpLine;
727 if ((c = _RTFGetChar(info)) != EOF)
729 info->rtfTextBuf[info->rtfTextLen++] = c;
730 info->rtfTextBuf[info->rtfTextLen] = '\0';
732 if (info->prevChar == EOF)
733 info->bumpLine = TRUE;
734 oldBumpLine = info->bumpLine; /* TRUE if prev char was line ending */
735 info->bumpLine = FALSE;
736 if (c == '\r')
737 info->bumpLine = TRUE;
738 else if (c == '\n')
740 info->bumpLine = TRUE;
741 if (info->prevChar == '\r') /* oops, previous \r wasn't */
742 oldBumpLine = FALSE; /* really a line ending */
744 ++info->rtfLinePos;
745 if (oldBumpLine) /* were we supposed to increment the */
746 { /* line count on this char? */
747 ++info->rtfLineNum;
748 info->rtfLinePos = 1;
750 info->prevChar = c;
751 return (c);
755 /* ---------------------------------------------------------------------- */
758 * Special destination readers. They gobble the destination so the
759 * writer doesn't have to deal with them. That's wrong for any
760 * translator that wants to process any of these itself. In that
761 * case, these readers should be overridden by installing a different
762 * destination callback.
764 * NOTE: The last token read by each of these reader will be the
765 * destination's terminating '}', which will then be the current token.
766 * That '}' token is passed to RTFRouteToken() - the writer has already
767 * seen the '{' that began the destination group, and may have pushed a
768 * state; it also needs to know at the end of the group that a state
769 * should be popped.
771 * It's important that rtf.h and the control token lookup table list
772 * as many symbols as possible, because these destination readers
773 * unfortunately make strict assumptions about the input they expect,
774 * and a token of class rtfUnknown will throw them off easily.
779 * Read { \fonttbl ... } destination. Old font tables don't have
780 * braces around each table entry; try to adjust for that.
783 static void ReadFontTbl(RTF_Info *info)
785 RTFFont *fp = NULL;
786 char buf[rtfBufSiz], *bp;
787 int old = -1;
789 for (;;)
791 RTFGetToken (info);
792 if (info->rtfClass == rtfEOF)
793 break;
794 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
795 break;
796 if (old < 0) /* first entry - determine tbl type */
798 if (RTFCheckCMM (info, rtfControl, rtfCharAttr, rtfFontNum))
799 old = 1; /* no brace */
800 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
801 old = 0; /* brace */
802 else /* can't tell! */
803 ERR ("cannot determine format\n");
805 if (old == 0) /* need to find "{" here */
807 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
808 ERR ("missing \"{\"\n");
809 RTFGetToken (info); /* yes, skip to next token */
810 if (info->rtfClass == rtfEOF)
811 break;
813 fp = New (RTFFont);
814 if (fp == NULL) {
815 ERR ("cannot allocate font entry\n");
816 break;
819 fp->rtfNextFont = info->fontList;
820 info->fontList = fp;
822 fp->rtfFName = NULL;
823 fp->rtfFAltName = NULL;
824 fp->rtfFNum = -1;
825 fp->rtfFFamily = FF_DONTCARE;
826 fp->rtfFCharSet = DEFAULT_CHARSET; /* 1 */
827 fp->rtfFPitch = DEFAULT_PITCH;
828 fp->rtfFType = 0;
829 fp->rtfFCodePage = CP_ACP;
831 while (info->rtfClass != rtfEOF
832 && !RTFCheckCM (info, rtfText, ';')
833 && !RTFCheckCM (info, rtfGroup, rtfEndGroup))
835 if (info->rtfClass == rtfControl)
837 switch (info->rtfMajor)
839 default:
840 /* ignore token but announce it */
841 WARN ("unknown token \"%s\"\n",
842 info->rtfTextBuf);
843 break;
844 case rtfFontFamily:
845 fp->rtfFFamily = info->rtfMinor;
846 break;
847 case rtfCharAttr:
848 switch (info->rtfMinor)
850 default:
851 break; /* ignore unknown? */
852 case rtfFontNum:
853 fp->rtfFNum = info->rtfParam;
854 break;
856 break;
857 case rtfFontAttr:
858 switch (info->rtfMinor)
860 default:
861 break; /* ignore unknown? */
862 case rtfFontCharSet:
863 fp->rtfFCharSet = info->rtfParam;
864 if (!fp->rtfFCodePage)
865 fp->rtfFCodePage = RTFCharSetToCodePage(info, info->rtfParam);
866 break;
867 case rtfFontPitch:
868 fp->rtfFPitch = info->rtfParam;
869 break;
870 case rtfFontCodePage:
871 fp->rtfFCodePage = info->rtfParam;
872 break;
873 case rtfFTypeNil:
874 case rtfFTypeTrueType:
875 fp->rtfFType = info->rtfParam;
876 break;
878 break;
881 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup)) /* dest */
883 RTFSkipGroup (info); /* ignore for now */
885 else if (info->rtfClass == rtfText) /* font name */
887 bp = buf;
888 while (info->rtfClass == rtfText
889 && !RTFCheckCM (info, rtfText, ';'))
891 *bp++ = info->rtfMajor;
892 RTFGetToken (info);
895 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
896 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
898 RTFUngetToken (info);
900 *bp = '\0';
901 fp->rtfFName = RTFStrSave (buf);
902 if (fp->rtfFName == NULL)
903 ERR ("cannot allocate font name\n");
904 /* already have next token; don't read one */
905 /* at bottom of loop */
906 continue;
908 else
910 /* ignore token but announce it */
911 WARN ("unknown token \"%s\"\n", info->rtfTextBuf);
913 RTFGetToken (info);
914 if (info->rtfClass == rtfEOF)
915 break;
917 if (info->rtfClass == rtfEOF)
918 break;
919 if (old == 0) /* need to see "}" here */
921 RTFGetToken (info);
922 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
923 ERR ("missing \"}\"\n");
924 if (info->rtfClass == rtfEOF)
925 break;
928 /* Apply the real properties of the default font */
929 if (fp->rtfFNum == info->defFont)
931 if (info->ansiCodePage != CP_UTF8)
932 info->codePage = fp->rtfFCodePage;
933 TRACE("default font codepage %d\n", info->codePage);
936 if (!fp || (fp->rtfFNum == -1))
937 ERR("missing font number\n");
939 * Could check other pieces of structure here, too, I suppose.
941 RTFRouteToken (info); /* feed "}" back to router */
943 /* Set default font */
944 info->rtfClass = rtfControl;
945 info->rtfMajor = rtfCharAttr;
946 info->rtfMinor = rtfFontNum;
947 info->rtfParam = info->defFont;
948 lstrcpyA(info->rtfTextBuf, "f");
949 RTFUngetToken(info);
954 * The color table entries have color values of -1 if
955 * the default color should be used for the entry (only
956 * a semi-colon is given in the definition, no color values).
957 * There will be a problem if a partial entry (1 or 2 but
958 * not 3 color values) is given. The possibility is ignored
959 * here.
962 static void ReadColorTbl(RTF_Info *info)
964 RTFColor *cp;
965 int cnum = 0;
966 int group_level = 1;
968 for (;;)
970 RTFGetToken (info);
971 if (info->rtfClass == rtfEOF)
972 break;
973 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
975 group_level--;
976 if (!group_level)
977 break;
978 continue;
980 else if (RTFCheckCM(info, rtfGroup, rtfBeginGroup))
982 group_level++;
983 continue;
986 cp = New (RTFColor);
987 if (cp == NULL) {
988 ERR ("cannot allocate color entry\n");
989 break;
991 cp->rtfCNum = cnum++;
992 cp->rtfNextColor = info->colorList;
993 info->colorList = cp;
994 if (!RTFCheckCM (info, rtfControl, rtfColorName))
995 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
996 else {
997 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = 0;
998 do {
999 switch (info->rtfMinor)
1001 case rtfRed: cp->rtfCRed = info->rtfParam & 0xFF; break;
1002 case rtfGreen: cp->rtfCGreen = info->rtfParam & 0xFF; break;
1003 case rtfBlue: cp->rtfCBlue = info->rtfParam & 0xFF; break;
1005 RTFGetToken (info);
1006 } while (RTFCheckCM (info, rtfControl, rtfColorName));
1008 if (info->rtfClass == rtfEOF)
1009 break;
1010 if (!RTFCheckCM (info, rtfText, ';'))
1011 ERR ("malformed entry\n");
1013 RTFRouteToken (info); /* feed "}" back to router */
1018 * The "Normal" style definition doesn't contain any style number,
1019 * all others do. Normal style is given style rtfNormalStyleNum.
1022 static void ReadStyleSheet(RTF_Info *info)
1024 RTFStyle *sp;
1025 RTFStyleElt *sep, *sepLast;
1026 char buf[rtfBufSiz], *bp;
1027 int real_style;
1029 for (;;)
1031 RTFGetToken (info);
1032 if (info->rtfClass == rtfEOF)
1033 break;
1034 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1035 break;
1036 sp = New (RTFStyle);
1037 if (sp == NULL) {
1038 ERR ("cannot allocate stylesheet entry\n");
1039 break;
1041 sp->rtfSName = NULL;
1042 sp->rtfSNum = -1;
1043 sp->rtfSType = rtfParStyle;
1044 sp->rtfSAdditive = 0;
1045 sp->rtfSBasedOn = rtfNoStyleNum;
1046 sp->rtfSNextPar = -1;
1047 sp->rtfSSEList = sepLast = NULL;
1048 sp->rtfNextStyle = info->styleList;
1049 sp->rtfExpanding = 0;
1050 info->styleList = sp;
1051 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1052 ERR ("missing \"{\"\n");
1053 real_style = TRUE;
1054 for (;;)
1056 RTFGetToken (info);
1057 if (info->rtfClass == rtfEOF
1058 || RTFCheckCM (info, rtfText, ';'))
1059 break;
1060 if (info->rtfClass == rtfControl)
1062 if (RTFCheckMM (info, rtfSpecialChar, rtfOptDest)) {
1063 RTFGetToken(info);
1064 ERR("skipping optional destination\n");
1065 RTFSkipGroup(info);
1066 info->rtfClass = rtfGroup;
1067 info->rtfMajor = rtfEndGroup;
1068 real_style = FALSE;
1069 break; /* ignore "\*" */
1071 if (RTFCheckMM (info, rtfParAttr, rtfStyleNum))
1073 sp->rtfSNum = info->rtfParam;
1074 sp->rtfSType = rtfParStyle;
1075 continue;
1077 if (RTFCheckMM (info, rtfCharAttr, rtfCharStyleNum))
1079 sp->rtfSNum = info->rtfParam;
1080 sp->rtfSType = rtfCharStyle;
1081 continue;
1083 if (RTFCheckMM (info, rtfSectAttr, rtfSectStyleNum))
1085 sp->rtfSNum = info->rtfParam;
1086 sp->rtfSType = rtfSectStyle;
1087 continue;
1089 if (RTFCheckMM (info, rtfStyleAttr, rtfBasedOn))
1091 sp->rtfSBasedOn = info->rtfParam;
1092 continue;
1094 if (RTFCheckMM (info, rtfStyleAttr, rtfAdditive))
1096 sp->rtfSAdditive = 1;
1097 continue;
1099 if (RTFCheckMM (info, rtfStyleAttr, rtfNext))
1101 sp->rtfSNextPar = info->rtfParam;
1102 continue;
1104 sep = New (RTFStyleElt);
1105 if (sep == NULL)
1107 ERR ("cannot allocate style element\n");
1108 break;
1110 sep->rtfSEClass = info->rtfClass;
1111 sep->rtfSEMajor = info->rtfMajor;
1112 sep->rtfSEMinor = info->rtfMinor;
1113 sep->rtfSEParam = info->rtfParam;
1114 sep->rtfSEText = RTFStrSave (info->rtfTextBuf);
1115 if (sep->rtfSEText == NULL)
1116 ERR ("cannot allocate style element text\n");
1117 if (sepLast == NULL)
1118 sp->rtfSSEList = sep; /* first element */
1119 else /* add to end */
1120 sepLast->rtfNextSE = sep;
1121 sep->rtfNextSE = NULL;
1122 sepLast = sep;
1124 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1127 * This passes over "{\*\keycode ... }, among
1128 * other things. A temporary (perhaps) hack.
1130 ERR("skipping begin\n");
1131 RTFSkipGroup (info);
1132 continue;
1134 else if (info->rtfClass == rtfText) /* style name */
1136 bp = buf;
1137 while (info->rtfClass == rtfText)
1139 if (info->rtfMajor == ';')
1141 /* put back for "for" loop */
1142 RTFUngetToken (info);
1143 break;
1145 *bp++ = info->rtfMajor;
1146 RTFGetToken (info);
1148 *bp = '\0';
1149 sp->rtfSName = RTFStrSave (buf);
1150 if (sp->rtfSName == NULL)
1151 ERR ("cannot allocate style name\n");
1153 else /* unrecognized */
1155 /* ignore token but announce it */
1156 WARN ("unknown token \"%s\"\n", info->rtfTextBuf);
1159 if (real_style) {
1160 RTFGetToken (info);
1161 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1162 ERR ("missing \"}\"\n");
1164 * Check over the style structure. A name is a must.
1165 * If no style number was specified, check whether it's the
1166 * Normal style (in which case it's given style number
1167 * rtfNormalStyleNum). Note that some "normal" style names
1168 * just begin with "Normal" and can have other stuff following,
1169 * e.g., "Normal,Times 10 point". Ugh.
1171 * Some German RTF writers use "Standard" instead of "Normal".
1173 if (sp->rtfSName == NULL)
1174 ERR ("missing style name\n");
1175 if (sp->rtfSNum < 0)
1177 if (strncmp (buf, "Normal", 6) != 0
1178 && strncmp (buf, "Standard", 8) != 0)
1179 ERR ("missing style number\n");
1180 sp->rtfSNum = rtfNormalStyleNum;
1182 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1183 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1185 /* otherwise we're just dealing with fake end group from skipped group */
1187 RTFRouteToken (info); /* feed "}" back to router */
1191 static void ReadInfoGroup(RTF_Info *info)
1193 RTFSkipGroup (info);
1194 RTFRouteToken (info); /* feed "}" back to router */
1198 static void ReadPictGroup(RTF_Info *info)
1200 RTFSkipGroup (info);
1201 RTFRouteToken (info); /* feed "}" back to router */
1205 static void ReadObjGroup(RTF_Info *info)
1207 RTFSkipGroup (info);
1208 RTFRouteToken (info); /* feed "}" back to router */
1212 /* ---------------------------------------------------------------------- */
1215 * Routines to return pieces of stylesheet, or font or color tables.
1216 * References to style 0 are mapped onto the Normal style.
1219 RTFFont *RTFGetFont(const RTF_Info *info, int num)
1221 RTFFont *f;
1223 if (num == -1)
1224 return (info->fontList);
1225 for (f = info->fontList; f != NULL; f = f->rtfNextFont)
1227 if (f->rtfFNum == num)
1228 break;
1230 return (f); /* NULL if not found */
1234 RTFColor *RTFGetColor(const RTF_Info *info, int num)
1236 RTFColor *c;
1238 if (num == -1)
1239 return (info->colorList);
1240 for (c = info->colorList; c != NULL; c = c->rtfNextColor)
1242 if (c->rtfCNum == num)
1243 break;
1245 return (c); /* NULL if not found */
1249 /* ---------------------------------------------------------------------- */
1252 * Control symbol lookup routines
1256 typedef struct RTFKey RTFKey;
1258 struct RTFKey
1260 int rtfKMajor; /* major number */
1261 int rtfKMinor; /* minor number */
1262 const char *rtfKStr; /* symbol name */
1263 int rtfKHash; /* symbol name hash value */
1267 * A minor number of -1 means the token has no minor number
1268 * (all valid minor numbers are >= 0).
1271 static RTFKey rtfKey[] =
1274 * Special characters
1277 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1278 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1279 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1280 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1281 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1282 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1283 { rtfSpecialChar, rtfIYear, "yr", 0 },
1284 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1285 { rtfSpecialChar, rtfIDay, "dy", 0 },
1286 { rtfSpecialChar, rtfIHour, "hr", 0 },
1287 { rtfSpecialChar, rtfIMinute, "min", 0 },
1288 { rtfSpecialChar, rtfISecond, "sec", 0 },
1289 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1290 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1291 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1292 { rtfSpecialChar, rtfIIntID, "id", 0 },
1294 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1295 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1296 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1297 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1298 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1299 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1300 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1301 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1302 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1303 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1304 { rtfSpecialChar, rtfCell, "cell", 0 },
1305 { rtfSpecialChar, rtfRow, "row", 0 },
1306 { rtfSpecialChar, rtfPar, "par", 0 },
1307 /* newline and carriage return are synonyms for */
1308 /* \par when they are preceded by a \ character */
1309 { rtfSpecialChar, rtfPar, "\n", 0 },
1310 { rtfSpecialChar, rtfPar, "\r", 0 },
1311 { rtfSpecialChar, rtfSect, "sect", 0 },
1312 { rtfSpecialChar, rtfPage, "page", 0 },
1313 { rtfSpecialChar, rtfColumn, "column", 0 },
1314 { rtfSpecialChar, rtfLine, "line", 0 },
1315 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1316 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1317 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1318 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1319 { rtfSpecialChar, rtfTab, "tab", 0 },
1320 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1321 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1322 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1323 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1324 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1325 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1326 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1327 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1328 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1329 { rtfSpecialChar, rtfFormula, "|", 0 },
1330 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1331 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1332 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1333 { rtfSpecialChar, rtfOptDest, "*", 0 },
1334 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1335 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1336 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1337 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1338 /* is this valid? */
1339 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1340 { rtfSpecialChar, rtfUnicode, "u", 0 },
1341 { rtfSpecialChar, rtfNestCell, "nestcell", 0 },
1342 { rtfSpecialChar, rtfNestRow, "nestrow", 0 },
1345 * Character formatting attributes
1348 { rtfCharAttr, rtfPlain, "plain", 0 },
1349 { rtfCharAttr, rtfBold, "b", 0 },
1350 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1351 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1352 { rtfCharAttr, rtfSubScript, "dn", 0 },
1353 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1354 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1355 { rtfCharAttr, rtfExpand, "expnd", 0 },
1356 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1357 { rtfCharAttr, rtfKerning, "kerning", 0 },
1358 { rtfCharAttr, rtfFontNum, "f", 0 },
1359 { rtfCharAttr, rtfFontSize, "fs", 0 },
1360 { rtfCharAttr, rtfItalic, "i", 0 },
1361 { rtfCharAttr, rtfOutline, "outl", 0 },
1362 { rtfCharAttr, rtfRevised, "revised", 0 },
1363 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1364 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1365 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1366 { rtfCharAttr, rtfShadow, "shad", 0 },
1367 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1368 { rtfCharAttr, rtfUnderline, "ul", 0 },
1369 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1370 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1371 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1372 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1373 { rtfCharAttr, rtfSuperScript, "up", 0 },
1374 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1375 { rtfCharAttr, rtfInvisible, "v", 0 },
1376 { rtfCharAttr, rtfForeColor, "cf", 0 },
1377 { rtfCharAttr, rtfBackColor, "cb", 0 },
1378 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1379 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1380 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1381 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1382 { rtfCharAttr, rtfLanguage, "lang", 0 },
1383 /* this has disappeared from spec 1.2 */
1384 { rtfCharAttr, rtfGray, "gray", 0 },
1385 { rtfCharAttr, rtfUnicodeLength, "uc", 0 },
1388 * Paragraph formatting attributes
1391 { rtfParAttr, rtfParDef, "pard", 0 },
1392 { rtfParAttr, rtfStyleNum, "s", 0 },
1393 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1394 { rtfParAttr, rtfInTable, "intbl", 0 },
1395 { rtfParAttr, rtfKeep, "keep", 0 },
1396 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1397 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1398 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1399 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1400 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1401 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1402 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1403 { rtfParAttr, rtfQuadRight, "qr", 0 },
1404 { rtfParAttr, rtfQuadJust, "qj", 0 },
1405 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1406 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1407 { rtfParAttr, rtfLeftIndent, "li", 0 },
1408 { rtfParAttr, rtfRightIndent, "ri", 0 },
1409 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1410 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1411 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1412 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1414 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1416 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1417 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1419 { rtfParAttr, rtfTabPos, "tx", 0 },
1421 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1422 * although it's not in the spec. It's also redundant, since lj
1423 * tabs are the default.
1425 { rtfParAttr, rtfTabLeft, "tql", 0 },
1426 { rtfParAttr, rtfTabRight, "tqr", 0 },
1427 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1428 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1429 { rtfParAttr, rtfTabBar, "tb", 0 },
1430 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1431 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1432 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1433 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1434 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1436 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1437 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1438 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1439 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1440 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1441 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1442 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1443 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1444 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1445 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1446 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1447 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1448 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1449 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1450 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1451 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1452 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1453 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1454 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1455 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1456 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1457 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1458 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1459 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1460 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1461 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1462 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1463 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1464 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1465 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1466 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1467 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1468 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1469 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1470 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1471 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1473 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1474 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1475 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1476 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1477 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1478 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1479 { rtfParAttr, rtfBorderBox, "box", 0 },
1480 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1481 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1482 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1483 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1484 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1485 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1486 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1487 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1488 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1489 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1491 { rtfParAttr, rtfShading, "shading", 0 },
1492 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1493 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1494 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1495 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1496 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1497 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1498 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1499 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1500 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1501 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1502 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1503 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1504 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1505 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1506 { rtfParAttr, rtfNestLevel, "itap", 0 },
1509 * Section formatting attributes
1512 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1513 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1514 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1515 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1516 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1518 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1519 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1520 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1521 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1522 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1524 { rtfSectAttr, rtfColumns, "cols", 0 },
1525 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1526 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1527 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1528 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1529 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1531 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1532 { rtfSectAttr, rtfLineDist, "linex", 0 },
1533 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1534 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1535 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1536 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1538 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1539 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1540 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1541 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1542 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1543 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1544 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1545 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1546 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1547 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1548 { rtfSectAttr, rtfFooterY, "footery", 0 },
1550 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1551 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1552 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1553 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1554 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1555 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1556 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1557 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1558 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1559 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1560 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1561 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1562 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1563 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1564 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1566 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1567 /* misspelled as "vertal" in specification 1.0 */
1568 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1569 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1570 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
1572 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
1573 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
1575 /* I've seen these in an old spec, but not in real files... */
1576 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1577 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1578 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1579 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1580 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1583 * Document formatting attributes
1586 { rtfDocAttr, rtfDefTab, "deftab", 0 },
1587 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
1588 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
1589 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
1590 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
1591 { rtfDocAttr, rtfLineStart, "linestart", 0 },
1592 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
1593 /* \makeback was given in old version of spec, it's now */
1594 /* listed as \makebackup */
1595 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
1596 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
1597 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
1598 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
1599 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
1600 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
1602 { rtfDocAttr, rtfFENoteType, "fet", 0 },
1603 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
1604 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
1605 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
1606 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
1607 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
1608 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
1609 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
1610 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
1611 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
1612 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
1613 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
1614 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
1615 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
1616 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
1617 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
1618 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
1619 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
1620 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
1621 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
1622 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
1623 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
1624 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
1625 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
1626 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
1627 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
1628 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
1629 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
1631 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
1632 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
1633 { rtfDocAttr, rtfPaperSize, "psz", 0 },
1634 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
1635 { rtfDocAttr, rtfRightMargin, "margr", 0 },
1636 { rtfDocAttr, rtfTopMargin, "margt", 0 },
1637 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
1638 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
1639 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
1640 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
1641 { rtfDocAttr, rtfLandscape, "landscape", 0 },
1642 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
1643 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
1645 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
1647 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
1648 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
1649 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
1650 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
1651 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
1652 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
1653 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
1654 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
1655 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
1656 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
1657 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
1658 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
1660 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
1661 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
1662 { rtfDocAttr, rtfFormShading, "formshade", 0 },
1663 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
1664 { rtfDocAttr, rtfPrintData, "printdata", 0 },
1666 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
1667 { rtfDocAttr, rtfRevisions, "revisions", 0 },
1668 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
1669 { rtfDocAttr, rtfRevBar, "revbar", 0 },
1671 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
1673 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
1674 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
1676 { rtfDocAttr, rtfAnsiCodePage, "ansicpg", 0 },
1677 { rtfDocAttr, rtfUTF8RTF, "urtf", 0 },
1680 * Style attributes
1683 { rtfStyleAttr, rtfAdditive, "additive", 0 },
1684 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
1685 { rtfStyleAttr, rtfNext, "snext", 0 },
1688 * Picture attributes
1691 { rtfPictAttr, rtfMacQD, "macpict", 0 },
1692 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
1693 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
1694 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
1695 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
1696 { rtfPictAttr, rtfEmfBlip, "emfblip", 0 },
1697 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
1698 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
1699 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
1701 { rtfPictAttr, rtfPicWid, "picw", 0 },
1702 { rtfPictAttr, rtfPicHt, "pich", 0 },
1703 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
1704 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
1705 /* these two aren't in the spec, but some writers emit them */
1706 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
1707 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
1708 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
1709 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
1710 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
1711 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
1712 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
1713 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
1714 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
1716 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
1717 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
1719 { rtfPictAttr, rtfPicBinary, "bin", 0 },
1722 * NeXT graphic attributes
1725 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
1726 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
1729 * Destinations
1732 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
1733 { rtfDestination, rtfFontAltName, "falt", 0 },
1734 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
1735 { rtfDestination, rtfFontFile, "fontfile", 0 },
1736 { rtfDestination, rtfFileTbl, "filetbl", 0 },
1737 { rtfDestination, rtfFileInfo, "file", 0 },
1738 { rtfDestination, rtfColorTbl, "colortbl", 0 },
1739 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
1740 { rtfDestination, rtfKeyCode, "keycode", 0 },
1741 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
1742 { rtfDestination, rtfGenerator, "generator", 0 },
1743 { rtfDestination, rtfInfo, "info", 0 },
1744 { rtfDestination, rtfITitle, "title", 0 },
1745 { rtfDestination, rtfISubject, "subject", 0 },
1746 { rtfDestination, rtfIAuthor, "author", 0 },
1747 { rtfDestination, rtfIOperator, "operator", 0 },
1748 { rtfDestination, rtfIKeywords, "keywords", 0 },
1749 { rtfDestination, rtfIComment, "comment", 0 },
1750 { rtfDestination, rtfIVersion, "version", 0 },
1751 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
1752 /* \verscomm may not exist -- was seen in earlier spec version */
1753 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
1754 { rtfDestination, rtfNextFile, "nextfile", 0 },
1755 { rtfDestination, rtfTemplate, "template", 0 },
1756 { rtfDestination, rtfFNSep, "ftnsep", 0 },
1757 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
1758 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
1759 { rtfDestination, rtfENSep, "aftnsep", 0 },
1760 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
1761 { rtfDestination, rtfENContNotice, "aftncn", 0 },
1762 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
1763 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
1764 { rtfDestination, rtfHeader, "header", 0 },
1765 { rtfDestination, rtfFooter, "footer", 0 },
1766 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
1767 { rtfDestination, rtfHeaderRight, "headerr", 0 },
1768 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
1769 { rtfDestination, rtfFooterLeft, "footerl", 0 },
1770 { rtfDestination, rtfFooterRight, "footerr", 0 },
1771 { rtfDestination, rtfFooterFirst, "footerf", 0 },
1772 { rtfDestination, rtfParNumText, "pntext", 0 },
1773 { rtfDestination, rtfParNumbering, "pn", 0 },
1774 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
1775 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
1776 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
1777 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
1778 { rtfDestination, rtfPict, "pict", 0 },
1779 { rtfDestination, rtfObject, "object", 0 },
1780 { rtfDestination, rtfObjClass, "objclass", 0 },
1781 { rtfDestination, rtfObjName, "objname", 0 },
1782 { rtfObjAttr, rtfObjTime, "objtime", 0 },
1783 { rtfDestination, rtfObjData, "objdata", 0 },
1784 { rtfDestination, rtfObjAlias, "objalias", 0 },
1785 { rtfDestination, rtfObjSection, "objsect", 0 },
1786 /* objitem and objtopic aren't documented in the spec! */
1787 { rtfDestination, rtfObjItem, "objitem", 0 },
1788 { rtfDestination, rtfObjTopic, "objtopic", 0 },
1789 { rtfDestination, rtfObjResult, "result", 0 },
1790 { rtfDestination, rtfDrawObject, "do", 0 },
1791 { rtfDestination, rtfFootnote, "footnote", 0 },
1792 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
1793 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
1794 { rtfDestination, rtfAnnotID, "atnid", 0 },
1795 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
1796 { rtfDestination, rtfAnnotation, "annotation", 0 },
1797 { rtfDestination, rtfAnnotRef, "atnref", 0 },
1798 { rtfDestination, rtfAnnotTime, "atntime", 0 },
1799 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
1800 { rtfDestination, rtfField, "field", 0 },
1801 { rtfDestination, rtfFieldInst, "fldinst", 0 },
1802 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
1803 { rtfDestination, rtfDataField, "datafield", 0 },
1804 { rtfDestination, rtfIndex, "xe", 0 },
1805 { rtfDestination, rtfIndexText, "txe", 0 },
1806 { rtfDestination, rtfIndexRange, "rxe", 0 },
1807 { rtfDestination, rtfTOC, "tc", 0 },
1808 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
1809 { rtfDestination, rtfNestTableProps, "nesttableprops", 0 },
1810 { rtfDestination, rtfNoNestTables, "nonesttables", 0 },
1813 * Font families
1816 { rtfFontFamily, rtfFFNil, "fnil", 0 },
1817 { rtfFontFamily, rtfFFRoman, "froman", 0 },
1818 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
1819 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
1820 { rtfFontFamily, rtfFFScript, "fscript", 0 },
1821 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
1822 { rtfFontFamily, rtfFFTech, "ftech", 0 },
1823 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
1826 * Font attributes
1829 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
1830 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
1831 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
1832 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
1833 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
1836 * File table attributes
1839 { rtfFileAttr, rtfFileNum, "fid", 0 },
1840 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
1841 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
1844 * File sources
1847 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
1848 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
1849 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
1850 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
1851 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
1854 * Color names
1857 { rtfColorName, rtfRed, "red", 0 },
1858 { rtfColorName, rtfGreen, "green", 0 },
1859 { rtfColorName, rtfBlue, "blue", 0 },
1862 * Charset names
1865 { rtfCharSet, rtfMacCharSet, "mac", 0 },
1866 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
1867 { rtfCharSet, rtfPcCharSet, "pc", 0 },
1868 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
1871 * Table attributes
1874 { rtfTblAttr, rtfRowDef, "trowd", 0 },
1875 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
1876 { rtfTblAttr, rtfCellPos, "cellx", 0 },
1877 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
1878 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
1880 { rtfTblAttr, rtfRowLeft, "trql", 0 },
1881 { rtfTblAttr, rtfRowRight, "trqr", 0 },
1882 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
1883 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
1884 { rtfTblAttr, rtfRowHt, "trrh", 0 },
1885 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
1886 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
1888 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
1889 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
1891 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
1892 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
1893 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
1894 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
1895 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
1896 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
1898 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
1899 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
1900 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
1901 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
1903 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
1904 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
1905 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
1906 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
1907 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
1908 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
1909 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
1911 * The spec lists "clbgdkhor", but the corresponding non-cell
1912 * control is "bgdkhoriz". At any rate Macintosh Word seems
1913 * to accept both "clbgdkhor" and "clbgdkhoriz".
1915 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
1916 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
1917 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
1918 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
1919 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
1920 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
1921 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
1922 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
1923 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
1926 * Field attributes
1929 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
1930 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
1931 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
1932 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
1933 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
1936 * Positioning attributes
1939 { rtfPosAttr, rtfAbsWid, "absw", 0 },
1940 { rtfPosAttr, rtfAbsHt, "absh", 0 },
1942 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
1943 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
1944 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
1945 { rtfPosAttr, rtfPosX, "posx", 0 },
1946 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
1947 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
1948 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
1949 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
1950 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
1951 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
1953 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
1954 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
1955 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
1956 { rtfPosAttr, rtfPosY, "posy", 0 },
1957 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
1958 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
1959 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
1960 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
1961 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
1963 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
1964 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
1965 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
1966 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
1967 /* \dyfrtext no longer exists in spec 1.2, apparently */
1968 /* replaced by \dfrmtextx and \dfrmtexty. */
1969 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
1971 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
1972 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
1975 * Object controls
1978 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
1979 { rtfObjAttr, rtfObjLink, "objlink", 0 },
1980 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
1981 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
1982 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
1983 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
1985 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
1986 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
1987 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
1989 { rtfObjAttr, rtfObjHt, "objh", 0 },
1990 { rtfObjAttr, rtfObjWid, "objw", 0 },
1991 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
1992 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
1993 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
1994 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
1995 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
1996 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
1997 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
1998 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
1999 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2001 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2002 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2003 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2004 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2005 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2007 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2008 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2011 * Associated character formatting attributes
2014 { rtfACharAttr, rtfACBold, "ab", 0 },
2015 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2016 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2017 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2018 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2019 { rtfACharAttr, rtfACFontNum, "af", 0 },
2020 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2021 { rtfACharAttr, rtfACItalic, "ai", 0 },
2022 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2023 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2024 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2025 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2026 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2027 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2028 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2029 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2030 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2031 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2032 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2035 * Footnote attributes
2038 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2041 * Key code attributes
2044 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2045 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2046 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2047 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2050 * Bookmark attributes
2053 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2054 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2057 * Index entry attributes
2060 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2061 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2062 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2065 * Table of contents attributes
2068 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2069 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2072 * Drawing object attributes
2075 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2076 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2077 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2078 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2079 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2080 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2081 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2082 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2084 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2085 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2086 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2087 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2088 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2089 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2090 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2091 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2092 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2093 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2094 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2096 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2097 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2098 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2099 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2101 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2102 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2103 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2104 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2105 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2106 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2107 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2108 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2109 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2110 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2111 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2112 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2113 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2114 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2115 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2116 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2117 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2119 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2120 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2121 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2123 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2124 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2125 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2127 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2128 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2130 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2131 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2132 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2133 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2134 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2135 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2136 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2137 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2138 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2139 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2140 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2141 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2143 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2144 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2145 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2146 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2147 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2148 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2149 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2150 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2152 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2153 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2154 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2155 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2156 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2157 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2158 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2159 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2160 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2161 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2162 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2164 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2165 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2166 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2168 { rtfVersion, -1, "rtf", 0 },
2169 { rtfDefFont, -1, "deff", 0 },
2171 { 0, -1, NULL, 0 }
2173 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2175 typedef struct tagRTFHashTableEntry {
2176 int count;
2177 RTFKey **value;
2178 } RTFHashTableEntry;
2180 static RTFHashTableEntry rtfHashTable[RTF_KEY_COUNT * 2];
2184 * Initialize lookup table hash values. Only need to do this once.
2187 void LookupInit(void)
2189 RTFKey *rp;
2191 memset(rtfHashTable, 0, sizeof rtfHashTable);
2192 for (rp = rtfKey; rp->rtfKStr != NULL; rp++)
2194 int index;
2196 rp->rtfKHash = Hash (rp->rtfKStr);
2197 index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
2198 if (!rtfHashTable[index].count)
2199 rtfHashTable[index].value = heap_alloc(sizeof(RTFKey *));
2200 else
2201 rtfHashTable[index].value = heap_realloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
2202 rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
2206 void LookupCleanup(void)
2208 unsigned int i;
2210 for (i=0; i<RTF_KEY_COUNT*2; i++)
2212 heap_free( rtfHashTable[i].value );
2213 rtfHashTable[i].value = NULL;
2214 rtfHashTable[i].count = 0;
2220 * Determine major and minor number of control token. If it's
2221 * not found, the class turns into rtfUnknown.
2224 static void Lookup(RTF_Info *info, char *s)
2226 RTFKey *rp;
2227 int hash;
2228 RTFHashTableEntry *entry;
2229 int i;
2231 ++s; /* skip over the leading \ character */
2232 hash = Hash (s);
2233 entry = &rtfHashTable[hash % (RTF_KEY_COUNT * 2)];
2234 for (i = 0; i < entry->count; i++)
2236 rp = entry->value[i];
2237 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2239 info->rtfClass = rtfControl;
2240 info->rtfMajor = rp->rtfKMajor;
2241 info->rtfMinor = rp->rtfKMinor;
2242 return;
2245 info->rtfClass = rtfUnknown;
2250 * Compute hash value of symbol
2253 static int Hash(const char *s)
2255 char c;
2256 int val = 0;
2258 while ((c = *s++) != '\0')
2259 val += c;
2260 return (val);
2265 /* ---------------------------------------------------------------------- */
2269 * Token comparison routines
2272 int RTFCheckCM(const RTF_Info *info, int class, int major)
2274 return (info->rtfClass == class && info->rtfMajor == major);
2278 int RTFCheckCMM(const RTF_Info *info, int class, int major, int minor)
2280 return (info->rtfClass == class && info->rtfMajor == major && info->rtfMinor == minor);
2284 int RTFCheckMM(const RTF_Info *info, int major, int minor)
2286 return (info->rtfMajor == major && info->rtfMinor == minor);
2290 /* ---------------------------------------------------------------------- */
2293 int RTFCharToHex(char c)
2295 if (isupper (c))
2296 c = tolower (c);
2297 if (isdigit (c))
2298 return (c - '0'); /* '0'..'9' */
2299 return (c - 'a' + 10); /* 'a'..'f' */
2303 /* ---------------------------------------------------------------------- */
2306 * originally from RTF tools' text-writer.c
2308 * text-writer -- RTF-to-text translation writer code.
2310 * Read RTF input, write text of document (text extraction).
2313 static void TextClass (RTF_Info *info);
2314 static void ControlClass (RTF_Info *info);
2315 static void DefFont(RTF_Info *info);
2316 static void Destination (RTF_Info *info);
2317 static void SpecialChar (RTF_Info *info);
2318 static void RTFPutUnicodeChar (RTF_Info *info, int c);
2321 * Initialize the writer.
2324 void
2325 WriterInit (RTF_Info *info )
2331 BeginFile (RTF_Info *info )
2333 /* install class callbacks */
2335 RTFSetClassCallback (info, rtfText, TextClass);
2336 RTFSetClassCallback (info, rtfControl, ControlClass);
2338 return (1);
2342 * Write out a character.
2345 static void
2346 TextClass (RTF_Info *info)
2348 RTFPutCodePageChar(info, info->rtfMajor);
2352 static void
2353 ControlClass (RTF_Info *info)
2355 switch (info->rtfMajor)
2357 case rtfCharAttr:
2358 CharAttr(info);
2359 ME_RTFCharAttrHook(info);
2360 break;
2361 case rtfParAttr:
2362 ME_RTFParAttrHook(info);
2363 break;
2364 case rtfTblAttr:
2365 ME_RTFTblAttrHook(info);
2366 break;
2367 case rtfCharSet:
2368 CharSet(info);
2369 break;
2370 case rtfDefFont:
2371 DefFont(info);
2372 break;
2373 case rtfDestination:
2374 Destination (info);
2375 break;
2376 case rtfDocAttr:
2377 DocAttr(info);
2378 break;
2379 case rtfSpecialChar:
2380 SpecialChar (info);
2381 ME_RTFSpecialCharHook(info);
2382 break;
2387 static void
2388 CharAttr(RTF_Info *info)
2390 RTFFont *font;
2392 switch (info->rtfMinor)
2394 case rtfFontNum:
2395 font = RTFGetFont(info, info->rtfParam);
2396 if (font)
2398 if (info->ansiCodePage != CP_UTF8 && info->codePage != font->rtfFCodePage)
2400 RTFFlushOutputBuffer(info);
2401 info->codePage = font->rtfFCodePage;
2403 TRACE("font %d codepage %d\n", info->rtfParam, info->codePage);
2405 else
2406 ERR( "unknown font %d\n", info->rtfParam);
2407 break;
2408 case rtfUnicodeLength:
2409 info->unicodeLength = info->rtfParam;
2410 break;
2415 static void
2416 CharSet(RTF_Info *info)
2418 if (info->ansiCodePage == CP_UTF8)
2419 return;
2421 switch (info->rtfMinor)
2423 case rtfAnsiCharSet:
2424 info->ansiCodePage = 1252; /* Latin-1 */
2425 break;
2426 case rtfMacCharSet:
2427 info->ansiCodePage = 10000; /* MacRoman */
2428 break;
2429 case rtfPcCharSet:
2430 info->ansiCodePage = 437;
2431 break;
2432 case rtfPcaCharSet:
2433 info->ansiCodePage = 850;
2434 break;
2439 * This function notices destinations that aren't explicitly handled
2440 * and skips to their ends. This keeps, for instance, picture
2441 * data from being considered as plain text.
2444 static void
2445 Destination (RTF_Info *info)
2447 if (!RTFGetDestinationCallback(info, info->rtfMinor))
2448 RTFSkipGroup (info);
2452 static void
2453 DefFont(RTF_Info *info)
2455 TRACE("%d\n", info->rtfParam);
2456 info->defFont = info->rtfParam;
2460 static void
2461 DocAttr(RTF_Info *info)
2463 TRACE("minor %d, param %d\n", info->rtfMinor, info->rtfParam);
2465 switch (info->rtfMinor)
2467 case rtfAnsiCodePage:
2468 info->codePage = info->ansiCodePage = info->rtfParam;
2469 break;
2470 case rtfUTF8RTF:
2471 info->codePage = info->ansiCodePage = CP_UTF8;
2472 break;
2477 static void SpecialChar (RTF_Info *info)
2479 switch (info->rtfMinor)
2481 case rtfOptDest:
2482 /* the next token determines destination, if it's unknown, skip the group */
2483 /* this way we filter out the garbage coming from unknown destinations */
2484 RTFGetToken(info);
2485 if (info->rtfClass != rtfDestination)
2486 RTFSkipGroup(info);
2487 else
2488 RTFRouteToken(info); /* "\*" is ignored with known destinations */
2489 break;
2490 case rtfUnicode:
2492 int i;
2494 RTFPutUnicodeChar(info, info->rtfParam);
2496 /* After \u we must skip number of character tokens set by \ucN */
2497 for (i = 0; i < info->unicodeLength; i++)
2499 RTFGetToken(info);
2500 if (info->rtfClass != rtfText)
2502 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2503 info->rtfClass, info->rtfMajor, info->rtfMinor);
2504 RTFUngetToken(info);
2505 break;
2508 break;
2510 case rtfLine:
2511 RTFFlushOutputBuffer(info);
2512 ME_InsertEndRowFromCursor(info->editor, 0);
2513 break;
2514 case rtfPage:
2515 case rtfSect:
2516 case rtfPar:
2517 RTFPutUnicodeChar (info, '\r');
2518 if (info->editor->bEmulateVersion10) RTFPutUnicodeChar (info, '\n');
2519 break;
2520 case rtfNoBrkSpace:
2521 RTFPutUnicodeChar (info, 0x00A0);
2522 break;
2523 case rtfTab:
2524 RTFPutUnicodeChar (info, '\t');
2525 break;
2526 case rtfNoBrkHyphen:
2527 RTFPutUnicodeChar (info, 0x2011);
2528 break;
2529 case rtfBullet:
2530 RTFPutUnicodeChar (info, 0x2022);
2531 break;
2532 case rtfEmDash:
2533 RTFPutUnicodeChar (info, 0x2014);
2534 break;
2535 case rtfEnDash:
2536 RTFPutUnicodeChar (info, 0x2013);
2537 break;
2538 case rtfLQuote:
2539 RTFPutUnicodeChar (info, 0x2018);
2540 break;
2541 case rtfRQuote:
2542 RTFPutUnicodeChar (info, 0x2019);
2543 break;
2544 case rtfLDblQuote:
2545 RTFPutUnicodeChar (info, 0x201C);
2546 break;
2547 case rtfRDblQuote:
2548 RTFPutUnicodeChar (info, 0x201D);
2549 break;
2554 static void
2555 RTFFlushUnicodeOutputBuffer(RTF_Info *info)
2557 if (info->dwOutputCount)
2559 ME_InsertTextFromCursor(info->editor, 0, info->OutputBuffer,
2560 info->dwOutputCount, info->style);
2561 info->dwOutputCount = 0;
2566 static void
2567 RTFPutUnicodeString(RTF_Info *info, const WCHAR *string, int length)
2569 if (info->dwCPOutputCount)
2570 RTFFlushCPOutputBuffer(info);
2571 while (length)
2573 int fit = min(length, sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount);
2575 memmove(info->OutputBuffer + info->dwOutputCount, string, fit * sizeof(WCHAR));
2576 info->dwOutputCount += fit;
2577 length -= fit;
2578 string += fit;
2579 if (sizeof(info->OutputBuffer) / sizeof(WCHAR) == info->dwOutputCount)
2580 RTFFlushUnicodeOutputBuffer(info);
2584 static void
2585 RTFFlushCPOutputBuffer(RTF_Info *info)
2587 int bufferMax = info->dwCPOutputCount * 2 * sizeof(WCHAR);
2588 WCHAR *buffer = heap_alloc(bufferMax);
2589 int length;
2591 length = MultiByteToWideChar(info->codePage, 0, info->cpOutputBuffer,
2592 info->dwCPOutputCount, buffer, bufferMax/sizeof(WCHAR));
2593 info->dwCPOutputCount = 0;
2595 RTFPutUnicodeString(info, buffer, length);
2596 heap_free(buffer);
2599 void
2600 RTFFlushOutputBuffer(RTF_Info *info)
2602 if (info->dwCPOutputCount)
2603 RTFFlushCPOutputBuffer(info);
2604 RTFFlushUnicodeOutputBuffer(info);
2607 static void
2608 RTFPutUnicodeChar(RTF_Info *info, int c)
2610 if (info->dwCPOutputCount)
2611 RTFFlushCPOutputBuffer(info);
2612 if (info->dwOutputCount * sizeof(WCHAR) >= ( sizeof info->OutputBuffer - 1 ) )
2613 RTFFlushUnicodeOutputBuffer( info );
2614 info->OutputBuffer[info->dwOutputCount++] = c;
2617 static void
2618 RTFPutCodePageChar(RTF_Info *info, int c)
2620 /* Use dynamic buffer here because it's the best way to handle
2621 * MBCS codepages without having to worry about partial chars */
2622 if (info->dwCPOutputCount >= info->dwMaxCPOutputCount)
2624 info->dwMaxCPOutputCount *= 2;
2625 info->cpOutputBuffer = heap_realloc(info->cpOutputBuffer, info->dwMaxCPOutputCount);
2627 info->cpOutputBuffer[info->dwCPOutputCount++] = c;