Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / riched20 / reader.c
blob9f88cf775546adeb9e32b72432904fae7284210f
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 for (i = 0; i < rtfMaxClass; i++)
230 RTFSetClassCallback (info, i, NULL);
231 for (i = 0; i < rtfMaxDestination; i++)
232 RTFSetDestinationCallback (info, i, NULL);
234 /* install built-in destination readers */
235 RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl);
236 RTFSetDestinationCallback (info, rtfColorTbl, ReadColorTbl);
237 RTFSetDestinationCallback (info, rtfStyleSheet, ReadStyleSheet);
238 RTFSetDestinationCallback (info, rtfInfo, ReadInfoGroup);
239 RTFSetDestinationCallback (info, rtfPict, ReadPictGroup);
240 RTFSetDestinationCallback (info, rtfObject, ReadObjGroup);
243 RTFSetReadHook (info, NULL);
245 /* dump old lists if necessary */
247 RTFDestroyAttrs(info);
249 info->ansiCodePage = 1252; /* Latin-1; actually unused */
250 info->unicodeLength = 1; /* \uc1 is the default */
251 info->codePage = info->ansiCodePage;
252 info->defFont = 0;
254 info->rtfClass = -1;
255 info->pushedClass = -1;
256 info->pushedChar = EOF;
258 info->rtfLineNum = 0;
259 info->rtfLinePos = 0;
260 info->prevChar = EOF;
261 info->bumpLine = 0;
263 info->dwCPOutputCount = 0;
264 if (!info->cpOutputBuffer)
266 info->dwMaxCPOutputCount = 0x1000;
267 info->cpOutputBuffer = heap_alloc(info->dwMaxCPOutputCount);
270 info->tableDef = NULL;
271 info->nestingLevel = 0;
272 info->canInheritInTbl = FALSE;
273 info->borderType = 0;
277 * Install or return a writer callback for a destination type
280 void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback)
282 if (dest >= 0 && dest < rtfMaxDestination)
283 info->dcb[dest] = callback;
287 static RTFFuncPtr RTFGetDestinationCallback(const RTF_Info *info, int dest)
289 if (dest >= 0 && dest < rtfMaxDestination)
290 return info->dcb[dest];
291 return NULL;
295 /* ---------------------------------------------------------------------- */
298 * Token reading routines
303 * Read the input stream, invoking the writer's callbacks
304 * where appropriate.
307 void RTFRead(RTF_Info *info)
309 while (RTFGetToken (info) != rtfEOF)
310 RTFRouteToken (info);
315 * Route a token. If it's a destination for which a reader is
316 * installed, process the destination internally, otherwise
317 * pass the token to the writer's class callback.
320 void RTFRouteToken(RTF_Info *info)
322 RTFFuncPtr p;
324 if (info->rtfClass < 0 || info->rtfClass >= rtfMaxClass) /* watchdog */
326 ERR( "Unknown class %d: %s (reader malfunction)\n",
327 info->rtfClass, info->rtfTextBuf);
329 if (RTFCheckCM (info, rtfControl, rtfDestination))
331 /* invoke destination-specific callback if there is one */
332 p = RTFGetDestinationCallback (info, info->rtfMinor);
333 if (p != NULL)
335 (*p) (info);
336 return;
339 /* invoke class callback if there is one */
340 p = RTFGetClassCallback (info, info->rtfClass);
341 if (p != NULL)
342 (*p) (info);
347 * Skip to the end of the current group. When this returns,
348 * writers that maintain a state stack may want to call their
349 * state unstacker; global vars will still be set to the group's
350 * closing brace.
353 void RTFSkipGroup(RTF_Info *info)
355 int level = 1;
357 while (RTFGetToken (info) != rtfEOF)
359 if (info->rtfClass == rtfGroup)
361 if (info->rtfMajor == rtfBeginGroup)
362 ++level;
363 else if (info->rtfMajor == rtfEndGroup)
365 if (--level < 1)
366 break; /* end of initial group */
373 * Do no special processing on the group.
375 * This acts as a placeholder for a callback in order to indicate that it
376 * shouldn't be ignored. Instead it will fallback on the loop in RTFRead.
378 void RTFReadGroup (RTF_Info *info)
384 * Install or return a token reader hook.
387 void RTFSetReadHook(RTF_Info *info, RTFFuncPtr f)
389 info->readHook = f;
393 static RTFFuncPtr RTFGetReadHook(const RTF_Info *info)
395 return (info->readHook);
400 * Read one token. Call the read hook if there is one. The
401 * token class is the return value. Returns rtfEOF when there
402 * are no more tokens.
405 int RTFGetToken(RTF_Info *info)
407 RTFFuncPtr p;
409 /* don't try to return anything once EOF is reached */
410 if (info->rtfClass == rtfEOF) {
411 return rtfEOF;
414 for (;;)
416 _RTFGetToken (info);
417 p = RTFGetReadHook (info);
418 if (p != NULL)
419 (*p) (info); /* give read hook a look at token */
421 /* Silently discard newlines, carriage returns, nulls. */
422 if (!(info->rtfClass == rtfText && info->rtfFormat != SF_TEXT
423 && (info->rtfMajor == '\r' || info->rtfMajor == '\n' || info->rtfMajor == '\0')))
424 break;
426 return (info->rtfClass);
430 static void RTFUngetToken(RTF_Info *info)
432 if (info->pushedClass >= 0) /* there's already an ungotten token */
433 ERR ("cannot unget two tokens\n");
434 if (info->rtfClass < 0)
435 ERR ("no token to unget\n");
436 info->pushedClass = info->rtfClass;
437 info->pushedMajor = info->rtfMajor;
438 info->pushedMinor = info->rtfMinor;
439 info->pushedParam = info->rtfParam;
440 lstrcpyA (info->pushedTextBuf, info->rtfTextBuf);
441 /* The read hook decrements stackTop on rtfEndGroup, so
442 * increment the value to compensate for it being decremented
443 * twice due to the RTFUngetToken. */
444 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
446 info->stack[info->stackTop].style = info->style;
447 ME_AddRefStyle(info->style);
448 info->stackTop++;
453 static void _RTFGetToken(RTF_Info *info)
455 if (info->rtfFormat == SF_TEXT)
457 info->rtfMajor = GetChar (info);
458 info->rtfMinor = 0;
459 info->rtfParam = rtfNoParam;
460 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
461 if (info->rtfMajor == EOF)
462 info->rtfClass = rtfEOF;
463 else
464 info->rtfClass = rtfText;
465 return;
468 /* first check for pushed token from RTFUngetToken() */
470 if (info->pushedClass >= 0)
472 info->rtfClass = info->pushedClass;
473 info->rtfMajor = info->pushedMajor;
474 info->rtfMinor = info->pushedMinor;
475 info->rtfParam = info->pushedParam;
476 lstrcpyA (info->rtfTextBuf, info->pushedTextBuf);
477 info->rtfTextLen = lstrlenA(info->rtfTextBuf);
478 info->pushedClass = -1;
479 return;
483 * Beyond this point, no token is ever seen twice, which is
484 * important, e.g., for making sure no "}" pops the font stack twice.
487 _RTFGetToken2 (info);
492 RTFCharSetToCodePage(RTF_Info *info, int charset)
494 switch (charset)
496 case ANSI_CHARSET:
497 return 1252;
498 case DEFAULT_CHARSET:
499 return CP_ACP;
500 case SYMBOL_CHARSET:
501 return CP_SYMBOL;
502 case MAC_CHARSET:
503 return CP_MACCP;
504 case SHIFTJIS_CHARSET:
505 return 932;
506 case HANGEUL_CHARSET:
507 return 949;
508 case JOHAB_CHARSET:
509 return 1361;
510 case GB2312_CHARSET:
511 return 936;
512 case CHINESEBIG5_CHARSET:
513 return 950;
514 case GREEK_CHARSET:
515 return 1253;
516 case TURKISH_CHARSET:
517 return 1254;
518 case VIETNAMESE_CHARSET:
519 return 1258;
520 case HEBREW_CHARSET:
521 return 1255;
522 case ARABIC_CHARSET:
523 return 1256;
524 case BALTIC_CHARSET:
525 return 1257;
526 case RUSSIAN_CHARSET:
527 return 1251;
528 case THAI_CHARSET:
529 return 874;
530 case EASTEUROPE_CHARSET:
531 return 1250;
532 case OEM_CHARSET:
533 return CP_OEMCP;
534 default:
536 CHARSETINFO csi;
537 DWORD n = charset;
539 /* FIXME: TranslateCharsetInfo does not work as good as it
540 * should, so let's use it only when all else fails */
541 if (!TranslateCharsetInfo(&n, &csi, TCI_SRCCHARSET))
542 ERR("unknown charset %d\n", charset);
543 else
544 return csi.ciACP;
547 return 0;
551 /* this shouldn't be called anywhere but from _RTFGetToken() */
553 static void _RTFGetToken2(RTF_Info *info)
555 int sign;
556 int c;
558 /* initialize token vars */
560 info->rtfClass = rtfUnknown;
561 info->rtfParam = rtfNoParam;
562 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
564 /* get first character, which may be a pushback from previous token */
566 if (info->pushedChar != EOF)
568 c = info->pushedChar;
569 info->rtfTextBuf[info->rtfTextLen++] = c;
570 info->rtfTextBuf[info->rtfTextLen] = '\0';
571 info->pushedChar = EOF;
573 else if ((c = GetChar (info)) == EOF)
575 info->rtfClass = rtfEOF;
576 return;
579 if (c == '{')
581 info->rtfClass = rtfGroup;
582 info->rtfMajor = rtfBeginGroup;
583 return;
585 if (c == '}')
587 info->rtfClass = rtfGroup;
588 info->rtfMajor = rtfEndGroup;
589 return;
591 if (c != '\\')
594 * Two possibilities here:
595 * 1) ASCII 9, effectively like \tab control symbol
596 * 2) literal text char
598 if (c == '\t') /* ASCII 9 */
600 info->rtfClass = rtfControl;
601 info->rtfMajor = rtfSpecialChar;
602 info->rtfMinor = rtfTab;
604 else
606 info->rtfClass = rtfText;
607 info->rtfMajor = c;
609 return;
611 if ((c = GetChar (info)) == EOF)
613 /* early eof, whoops (class is rtfUnknown) */
614 return;
616 if (!isalpha (c))
619 * Three possibilities here:
620 * 1) hex encoded text char, e.g., \'d5, \'d3
621 * 2) special escaped text char, e.g., \{, \}
622 * 3) control symbol, e.g., \_, \-, \|, \<10>
624 if (c == '\'') /* hex char */
626 int c2;
628 if ((c = GetChar (info)) != EOF && (c2 = GetChar (info)) != EOF
629 && isxdigit(c) && isxdigit(c2))
631 info->rtfClass = rtfText;
632 info->rtfMajor = RTFCharToHex (c) * 16 + RTFCharToHex (c2);
633 return;
635 /* early eof, whoops */
636 info->rtfClass = rtfEOF;
637 info->stream->editstream->dwError = -14;
638 return;
641 /* escaped char */
642 /*if (index (":{}\\", c) != NULL)*/ /* escaped char */
643 if (c == ':' || c == '{' || c == '}' || c == '\\')
645 info->rtfClass = rtfText;
646 info->rtfMajor = c;
647 return;
650 /* control symbol */
651 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
652 return;
654 /* control word */
655 while (isalpha (c))
657 if ((c = GetChar (info)) == EOF)
658 break;
662 * At this point, the control word is all collected, so the
663 * major/minor numbers are determined before the parameter
664 * (if any) is scanned. There will be one too many characters
665 * in the buffer, though, so fix up before and restore after
666 * looking up.
669 if (c != EOF)
670 info->rtfTextBuf[info->rtfTextLen-1] = '\0';
671 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
672 if (c != EOF)
673 info->rtfTextBuf[info->rtfTextLen-1] = c;
676 * Should be looking at first digit of parameter if there
677 * is one, unless it's negative. In that case, next char
678 * is '-', so need to gobble next char, and remember sign.
681 sign = 1;
682 if (c == '-')
684 sign = -1;
685 c = GetChar (info);
687 if (c != EOF && isdigit (c))
689 info->rtfParam = 0;
690 while (isdigit (c)) /* gobble parameter */
692 info->rtfParam = info->rtfParam * 10 + c - '0';
693 if ((c = GetChar (info)) == EOF)
694 break;
696 info->rtfParam *= sign;
699 * If control symbol delimiter was a blank, gobble it.
700 * Otherwise the character is first char of next token, so
701 * push it back for next call. In either case, delete the
702 * delimiter from the token buffer.
704 if (c != EOF)
706 if (c != ' ')
707 info->pushedChar = c;
708 info->rtfTextBuf[--info->rtfTextLen] = '\0';
714 * Read the next character from the input. This handles setting the
715 * current line and position-within-line variables. Those variable are
716 * set correctly whether lines end with CR, LF, or CRLF (the last being
717 * the tricky case).
719 * bumpLine indicates whether the line number should be incremented on
720 * the *next* input character.
724 static int GetChar(RTF_Info *info)
726 int c;
727 int oldBumpLine;
729 if ((c = _RTFGetChar(info)) != EOF)
731 info->rtfTextBuf[info->rtfTextLen++] = c;
732 info->rtfTextBuf[info->rtfTextLen] = '\0';
734 if (info->prevChar == EOF)
735 info->bumpLine = 1;
736 oldBumpLine = info->bumpLine; /* non-zero if prev char was line ending */
737 info->bumpLine = 0;
738 if (c == '\r')
739 info->bumpLine = 1;
740 else if (c == '\n')
742 info->bumpLine = 1;
743 if (info->prevChar == '\r') /* oops, previous \r wasn't */
744 oldBumpLine = 0; /* really a line ending */
746 ++info->rtfLinePos;
747 if (oldBumpLine) /* were we supposed to increment the */
748 { /* line count on this char? */
749 ++info->rtfLineNum;
750 info->rtfLinePos = 1;
752 info->prevChar = c;
753 return (c);
757 /* ---------------------------------------------------------------------- */
760 * Special destination readers. They gobble the destination so the
761 * writer doesn't have to deal with them. That's wrong for any
762 * translator that wants to process any of these itself. In that
763 * case, these readers should be overridden by installing a different
764 * destination callback.
766 * NOTE: The last token read by each of these reader will be the
767 * destination's terminating '}', which will then be the current token.
768 * That '}' token is passed to RTFRouteToken() - the writer has already
769 * seen the '{' that began the destination group, and may have pushed a
770 * state; it also needs to know at the end of the group that a state
771 * should be popped.
773 * It's important that rtf.h and the control token lookup table list
774 * as many symbols as possible, because these destination readers
775 * unfortunately make strict assumptions about the input they expect,
776 * and a token of class rtfUnknown will throw them off easily.
781 * Read { \fonttbl ... } destination. Old font tables don't have
782 * braces around each table entry; try to adjust for that.
785 static void ReadFontTbl(RTF_Info *info)
787 RTFFont *fp = NULL;
788 char buf[rtfBufSiz], *bp;
789 int old = -1;
791 for (;;)
793 RTFGetToken (info);
794 if (info->rtfClass == rtfEOF)
795 break;
796 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
797 break;
798 if (old < 0) /* first entry - determine tbl type */
800 if (RTFCheckCMM (info, rtfControl, rtfCharAttr, rtfFontNum))
801 old = 1; /* no brace */
802 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
803 old = 0; /* brace */
804 else /* can't tell! */
805 ERR ("cannot determine format\n");
807 if (old == 0) /* need to find "{" here */
809 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
810 ERR ("missing \"{\"\n");
811 RTFGetToken (info); /* yes, skip to next token */
812 if (info->rtfClass == rtfEOF)
813 break;
815 fp = New (RTFFont);
816 if (fp == NULL) {
817 ERR ("cannot allocate font entry\n");
818 break;
821 fp->rtfNextFont = info->fontList;
822 info->fontList = fp;
824 fp->rtfFName = NULL;
825 fp->rtfFAltName = NULL;
826 fp->rtfFNum = -1;
827 fp->rtfFFamily = FF_DONTCARE;
828 fp->rtfFCharSet = DEFAULT_CHARSET; /* 1 */
829 fp->rtfFPitch = DEFAULT_PITCH;
830 fp->rtfFType = 0;
831 fp->rtfFCodePage = CP_ACP;
833 while (info->rtfClass != rtfEOF
834 && !RTFCheckCM (info, rtfText, ';')
835 && !RTFCheckCM (info, rtfGroup, rtfEndGroup))
837 if (info->rtfClass == rtfControl)
839 switch (info->rtfMajor)
841 default:
842 /* ignore token but announce it */
843 WARN ("unknown token \"%s\"\n",
844 info->rtfTextBuf);
845 break;
846 case rtfFontFamily:
847 fp->rtfFFamily = info->rtfMinor;
848 break;
849 case rtfCharAttr:
850 switch (info->rtfMinor)
852 default:
853 break; /* ignore unknown? */
854 case rtfFontNum:
855 fp->rtfFNum = info->rtfParam;
856 break;
858 break;
859 case rtfFontAttr:
860 switch (info->rtfMinor)
862 default:
863 break; /* ignore unknown? */
864 case rtfFontCharSet:
865 fp->rtfFCharSet = info->rtfParam;
866 if (!fp->rtfFCodePage)
867 fp->rtfFCodePage = RTFCharSetToCodePage(info, info->rtfParam);
868 break;
869 case rtfFontPitch:
870 fp->rtfFPitch = info->rtfParam;
871 break;
872 case rtfFontCodePage:
873 fp->rtfFCodePage = info->rtfParam;
874 break;
875 case rtfFTypeNil:
876 case rtfFTypeTrueType:
877 fp->rtfFType = info->rtfParam;
878 break;
880 break;
883 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup)) /* dest */
885 RTFSkipGroup (info); /* ignore for now */
887 else if (info->rtfClass == rtfText) /* font name */
889 bp = buf;
890 while (info->rtfClass == rtfText
891 && !RTFCheckCM (info, rtfText, ';'))
893 *bp++ = info->rtfMajor;
894 RTFGetToken (info);
897 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
898 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
900 RTFUngetToken (info);
902 *bp = '\0';
903 fp->rtfFName = RTFStrSave (buf);
904 if (fp->rtfFName == NULL)
905 ERR ("cannot allocate font name\n");
906 /* already have next token; don't read one */
907 /* at bottom of loop */
908 continue;
910 else
912 /* ignore token but announce it */
913 WARN ("unknown token \"%s\"\n", info->rtfTextBuf);
915 RTFGetToken (info);
916 if (info->rtfClass == rtfEOF)
917 break;
919 if (info->rtfClass == rtfEOF)
920 break;
921 if (old == 0) /* need to see "}" here */
923 RTFGetToken (info);
924 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
925 ERR ("missing \"}\"\n");
926 if (info->rtfClass == rtfEOF)
927 break;
930 /* Apply the real properties of the default font */
931 if (fp->rtfFNum == info->defFont)
933 if (info->ansiCodePage != CP_UTF8)
934 info->codePage = fp->rtfFCodePage;
935 TRACE("default font codepage %d\n", info->codePage);
938 if (!fp || (fp->rtfFNum == -1))
939 ERR("missing font number\n");
941 * Could check other pieces of structure here, too, I suppose.
943 RTFRouteToken (info); /* feed "}" back to router */
945 /* Set default font */
946 info->rtfClass = rtfControl;
947 info->rtfMajor = rtfCharAttr;
948 info->rtfMinor = rtfFontNum;
949 info->rtfParam = info->defFont;
950 lstrcpyA(info->rtfTextBuf, "f");
951 RTFUngetToken(info);
956 * The color table entries have color values of -1 if
957 * the default color should be used for the entry (only
958 * a semi-colon is given in the definition, no color values).
959 * There will be a problem if a partial entry (1 or 2 but
960 * not 3 color values) is given. The possibility is ignored
961 * here.
964 static void ReadColorTbl(RTF_Info *info)
966 RTFColor *cp;
967 int cnum = 0;
968 int group_level = 1;
970 for (;;)
972 RTFGetToken (info);
973 if (info->rtfClass == rtfEOF)
974 break;
975 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
977 group_level--;
978 if (!group_level)
979 break;
980 continue;
982 else if (RTFCheckCM(info, rtfGroup, rtfBeginGroup))
984 group_level++;
985 continue;
988 cp = New (RTFColor);
989 if (cp == NULL) {
990 ERR ("cannot allocate color entry\n");
991 break;
993 cp->rtfCNum = cnum++;
994 cp->rtfNextColor = info->colorList;
995 info->colorList = cp;
996 if (!RTFCheckCM (info, rtfControl, rtfColorName))
997 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
998 else {
999 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = 0;
1000 do {
1001 switch (info->rtfMinor)
1003 case rtfRed: cp->rtfCRed = info->rtfParam & 0xFF; break;
1004 case rtfGreen: cp->rtfCGreen = info->rtfParam & 0xFF; break;
1005 case rtfBlue: cp->rtfCBlue = info->rtfParam & 0xFF; break;
1007 RTFGetToken (info);
1008 } while (RTFCheckCM (info, rtfControl, rtfColorName));
1010 if (info->rtfClass == rtfEOF)
1011 break;
1012 if (!RTFCheckCM (info, rtfText, ';'))
1013 ERR ("malformed entry\n");
1015 RTFRouteToken (info); /* feed "}" back to router */
1020 * The "Normal" style definition doesn't contain any style number,
1021 * all others do. Normal style is given style rtfNormalStyleNum.
1024 static void ReadStyleSheet(RTF_Info *info)
1026 RTFStyle *sp;
1027 RTFStyleElt *sep, *sepLast;
1028 char buf[rtfBufSiz], *bp;
1029 int real_style;
1031 for (;;)
1033 RTFGetToken (info);
1034 if (info->rtfClass == rtfEOF)
1035 break;
1036 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1037 break;
1038 sp = New (RTFStyle);
1039 if (sp == NULL) {
1040 ERR ("cannot allocate stylesheet entry\n");
1041 break;
1043 sp->rtfSName = NULL;
1044 sp->rtfSNum = -1;
1045 sp->rtfSType = rtfParStyle;
1046 sp->rtfSAdditive = 0;
1047 sp->rtfSBasedOn = rtfNoStyleNum;
1048 sp->rtfSNextPar = -1;
1049 sp->rtfSSEList = sepLast = NULL;
1050 sp->rtfNextStyle = info->styleList;
1051 sp->rtfExpanding = 0;
1052 info->styleList = sp;
1053 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1054 ERR ("missing \"{\"\n");
1055 real_style = TRUE;
1056 for (;;)
1058 RTFGetToken (info);
1059 if (info->rtfClass == rtfEOF
1060 || RTFCheckCM (info, rtfText, ';'))
1061 break;
1062 if (info->rtfClass == rtfControl)
1064 if (RTFCheckMM (info, rtfSpecialChar, rtfOptDest)) {
1065 RTFGetToken(info);
1066 ERR("skipping optional destination\n");
1067 RTFSkipGroup(info);
1068 info->rtfClass = rtfGroup;
1069 info->rtfMajor = rtfEndGroup;
1070 real_style = FALSE;
1071 break; /* ignore "\*" */
1073 if (RTFCheckMM (info, rtfParAttr, rtfStyleNum))
1075 sp->rtfSNum = info->rtfParam;
1076 sp->rtfSType = rtfParStyle;
1077 continue;
1079 if (RTFCheckMM (info, rtfCharAttr, rtfCharStyleNum))
1081 sp->rtfSNum = info->rtfParam;
1082 sp->rtfSType = rtfCharStyle;
1083 continue;
1085 if (RTFCheckMM (info, rtfSectAttr, rtfSectStyleNum))
1087 sp->rtfSNum = info->rtfParam;
1088 sp->rtfSType = rtfSectStyle;
1089 continue;
1091 if (RTFCheckMM (info, rtfStyleAttr, rtfBasedOn))
1093 sp->rtfSBasedOn = info->rtfParam;
1094 continue;
1096 if (RTFCheckMM (info, rtfStyleAttr, rtfAdditive))
1098 sp->rtfSAdditive = 1;
1099 continue;
1101 if (RTFCheckMM (info, rtfStyleAttr, rtfNext))
1103 sp->rtfSNextPar = info->rtfParam;
1104 continue;
1106 sep = New (RTFStyleElt);
1107 if (sep == NULL)
1109 ERR ("cannot allocate style element\n");
1110 break;
1112 sep->rtfSEClass = info->rtfClass;
1113 sep->rtfSEMajor = info->rtfMajor;
1114 sep->rtfSEMinor = info->rtfMinor;
1115 sep->rtfSEParam = info->rtfParam;
1116 sep->rtfSEText = RTFStrSave (info->rtfTextBuf);
1117 if (sep->rtfSEText == NULL)
1118 ERR ("cannot allocate style element text\n");
1119 if (sepLast == NULL)
1120 sp->rtfSSEList = sep; /* first element */
1121 else /* add to end */
1122 sepLast->rtfNextSE = sep;
1123 sep->rtfNextSE = NULL;
1124 sepLast = sep;
1126 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1129 * This passes over "{\*\keycode ... }, among
1130 * other things. A temporary (perhaps) hack.
1132 ERR("skipping begin\n");
1133 RTFSkipGroup (info);
1134 continue;
1136 else if (info->rtfClass == rtfText) /* style name */
1138 bp = buf;
1139 while (info->rtfClass == rtfText)
1141 if (info->rtfMajor == ';')
1143 /* put back for "for" loop */
1144 RTFUngetToken (info);
1145 break;
1147 *bp++ = info->rtfMajor;
1148 RTFGetToken (info);
1150 *bp = '\0';
1151 sp->rtfSName = RTFStrSave (buf);
1152 if (sp->rtfSName == NULL)
1153 ERR ("cannot allocate style name\n");
1155 else /* unrecognized */
1157 /* ignore token but announce it */
1158 WARN ("unknown token \"%s\"\n", info->rtfTextBuf);
1161 if (real_style) {
1162 RTFGetToken (info);
1163 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1164 ERR ("missing \"}\"\n");
1166 * Check over the style structure. A name is a must.
1167 * If no style number was specified, check whether it's the
1168 * Normal style (in which case it's given style number
1169 * rtfNormalStyleNum). Note that some "normal" style names
1170 * just begin with "Normal" and can have other stuff following,
1171 * e.g., "Normal,Times 10 point". Ugh.
1173 * Some German RTF writers use "Standard" instead of "Normal".
1175 if (sp->rtfSName == NULL)
1176 ERR ("missing style name\n");
1177 if (sp->rtfSNum < 0)
1179 if (strncmp (buf, "Normal", 6) != 0
1180 && strncmp (buf, "Standard", 8) != 0)
1181 ERR ("missing style number\n");
1182 sp->rtfSNum = rtfNormalStyleNum;
1184 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1185 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1187 /* otherwise we're just dealing with fake end group from skipped group */
1189 RTFRouteToken (info); /* feed "}" back to router */
1193 static void ReadInfoGroup(RTF_Info *info)
1195 RTFSkipGroup (info);
1196 RTFRouteToken (info); /* feed "}" back to router */
1200 static void ReadPictGroup(RTF_Info *info)
1202 RTFSkipGroup (info);
1203 RTFRouteToken (info); /* feed "}" back to router */
1207 static void ReadObjGroup(RTF_Info *info)
1209 RTFSkipGroup (info);
1210 RTFRouteToken (info); /* feed "}" back to router */
1214 /* ---------------------------------------------------------------------- */
1217 * Routines to return pieces of stylesheet, or font or color tables.
1218 * References to style 0 are mapped onto the Normal style.
1221 RTFFont *RTFGetFont(const RTF_Info *info, int num)
1223 RTFFont *f;
1225 if (num == -1)
1226 return (info->fontList);
1227 for (f = info->fontList; f != NULL; f = f->rtfNextFont)
1229 if (f->rtfFNum == num)
1230 break;
1232 return (f); /* NULL if not found */
1236 RTFColor *RTFGetColor(const RTF_Info *info, int num)
1238 RTFColor *c;
1240 if (num == -1)
1241 return (info->colorList);
1242 for (c = info->colorList; c != NULL; c = c->rtfNextColor)
1244 if (c->rtfCNum == num)
1245 break;
1247 return (c); /* NULL if not found */
1251 /* ---------------------------------------------------------------------- */
1254 * Control symbol lookup routines
1258 typedef struct RTFKey RTFKey;
1260 struct RTFKey
1262 int rtfKMajor; /* major number */
1263 int rtfKMinor; /* minor number */
1264 const char *rtfKStr; /* symbol name */
1265 int rtfKHash; /* symbol name hash value */
1269 * A minor number of -1 means the token has no minor number
1270 * (all valid minor numbers are >= 0).
1273 static RTFKey rtfKey[] =
1276 * Special characters
1279 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1280 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1281 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1282 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1283 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1284 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1285 { rtfSpecialChar, rtfIYear, "yr", 0 },
1286 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1287 { rtfSpecialChar, rtfIDay, "dy", 0 },
1288 { rtfSpecialChar, rtfIHour, "hr", 0 },
1289 { rtfSpecialChar, rtfIMinute, "min", 0 },
1290 { rtfSpecialChar, rtfISecond, "sec", 0 },
1291 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1292 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1293 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1294 { rtfSpecialChar, rtfIIntID, "id", 0 },
1296 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1297 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1298 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1299 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1300 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1301 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1302 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1303 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1304 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1305 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1306 { rtfSpecialChar, rtfCell, "cell", 0 },
1307 { rtfSpecialChar, rtfRow, "row", 0 },
1308 { rtfSpecialChar, rtfPar, "par", 0 },
1309 /* newline and carriage return are synonyms for */
1310 /* \par when they are preceded by a \ character */
1311 { rtfSpecialChar, rtfPar, "\n", 0 },
1312 { rtfSpecialChar, rtfPar, "\r", 0 },
1313 { rtfSpecialChar, rtfSect, "sect", 0 },
1314 { rtfSpecialChar, rtfPage, "page", 0 },
1315 { rtfSpecialChar, rtfColumn, "column", 0 },
1316 { rtfSpecialChar, rtfLine, "line", 0 },
1317 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1318 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1319 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1320 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1321 { rtfSpecialChar, rtfTab, "tab", 0 },
1322 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1323 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1324 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1325 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1326 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1327 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1328 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1329 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1330 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1331 { rtfSpecialChar, rtfFormula, "|", 0 },
1332 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1333 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1334 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1335 { rtfSpecialChar, rtfOptDest, "*", 0 },
1336 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1337 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1338 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1339 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1340 /* is this valid? */
1341 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1342 { rtfSpecialChar, rtfUnicode, "u", 0 },
1343 { rtfSpecialChar, rtfNestCell, "nestcell", 0 },
1344 { rtfSpecialChar, rtfNestRow, "nestrow", 0 },
1347 * Character formatting attributes
1350 { rtfCharAttr, rtfPlain, "plain", 0 },
1351 { rtfCharAttr, rtfBold, "b", 0 },
1352 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1353 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1354 { rtfCharAttr, rtfSubScript, "dn", 0 },
1355 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1356 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1357 { rtfCharAttr, rtfExpand, "expnd", 0 },
1358 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1359 { rtfCharAttr, rtfKerning, "kerning", 0 },
1360 { rtfCharAttr, rtfFontNum, "f", 0 },
1361 { rtfCharAttr, rtfFontSize, "fs", 0 },
1362 { rtfCharAttr, rtfItalic, "i", 0 },
1363 { rtfCharAttr, rtfOutline, "outl", 0 },
1364 { rtfCharAttr, rtfRevised, "revised", 0 },
1365 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1366 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1367 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1368 { rtfCharAttr, rtfShadow, "shad", 0 },
1369 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1370 { rtfCharAttr, rtfUnderline, "ul", 0 },
1371 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1372 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1373 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1374 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1375 { rtfCharAttr, rtfSuperScript, "up", 0 },
1376 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1377 { rtfCharAttr, rtfInvisible, "v", 0 },
1378 { rtfCharAttr, rtfForeColor, "cf", 0 },
1379 { rtfCharAttr, rtfBackColor, "cb", 0 },
1380 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1381 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1382 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1383 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1384 { rtfCharAttr, rtfLanguage, "lang", 0 },
1385 /* this has disappeared from spec 1.2 */
1386 { rtfCharAttr, rtfGray, "gray", 0 },
1387 { rtfCharAttr, rtfUnicodeLength, "uc", 0 },
1390 * Paragraph formatting attributes
1393 { rtfParAttr, rtfParDef, "pard", 0 },
1394 { rtfParAttr, rtfStyleNum, "s", 0 },
1395 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1396 { rtfParAttr, rtfInTable, "intbl", 0 },
1397 { rtfParAttr, rtfKeep, "keep", 0 },
1398 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1399 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1400 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1401 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1402 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1403 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1404 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1405 { rtfParAttr, rtfQuadRight, "qr", 0 },
1406 { rtfParAttr, rtfQuadJust, "qj", 0 },
1407 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1408 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1409 { rtfParAttr, rtfLeftIndent, "li", 0 },
1410 { rtfParAttr, rtfRightIndent, "ri", 0 },
1411 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1412 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1413 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1414 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1416 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1418 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1419 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1421 { rtfParAttr, rtfTabPos, "tx", 0 },
1423 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1424 * although it's not in the spec. It's also redundant, since lj
1425 * tabs are the default.
1427 { rtfParAttr, rtfTabLeft, "tql", 0 },
1428 { rtfParAttr, rtfTabRight, "tqr", 0 },
1429 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1430 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1431 { rtfParAttr, rtfTabBar, "tb", 0 },
1432 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1433 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1434 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1435 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1436 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1438 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1439 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1440 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1441 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1442 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1443 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1444 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1445 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1446 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1447 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1448 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1449 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1450 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1451 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1452 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1453 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1454 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1455 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1456 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1457 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1458 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1459 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1460 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1461 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1462 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1463 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1464 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1465 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1466 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1467 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1468 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1469 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1470 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1471 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1472 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1473 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1475 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1476 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1477 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1478 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1479 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1480 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1481 { rtfParAttr, rtfBorderBox, "box", 0 },
1482 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1483 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1484 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1485 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1486 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1487 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1488 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1489 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1490 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1491 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1493 { rtfParAttr, rtfShading, "shading", 0 },
1494 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1495 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1496 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1497 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1498 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1499 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1500 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1501 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1502 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1503 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1504 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1505 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1506 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1507 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1508 { rtfParAttr, rtfNestLevel, "itap", 0 },
1511 * Section formatting attributes
1514 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1515 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1516 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1517 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1518 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1520 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1521 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1522 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1523 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1524 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1526 { rtfSectAttr, rtfColumns, "cols", 0 },
1527 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1528 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1529 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1530 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1531 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1533 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1534 { rtfSectAttr, rtfLineDist, "linex", 0 },
1535 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1536 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1537 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1538 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1540 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1541 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1542 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1543 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1544 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1545 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1546 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1547 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1548 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1549 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1550 { rtfSectAttr, rtfFooterY, "footery", 0 },
1552 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1553 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1554 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1555 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1556 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1557 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1558 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1559 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1560 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1561 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1562 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1563 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1564 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1565 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1566 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1568 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1569 /* misspelled as "vertal" in specification 1.0 */
1570 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1571 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1572 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
1574 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
1575 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
1577 /* I've seen these in an old spec, but not in real files... */
1578 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1579 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1580 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1581 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1582 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1585 * Document formatting attributes
1588 { rtfDocAttr, rtfDefTab, "deftab", 0 },
1589 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
1590 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
1591 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
1592 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
1593 { rtfDocAttr, rtfLineStart, "linestart", 0 },
1594 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
1595 /* \makeback was given in old version of spec, it's now */
1596 /* listed as \makebackup */
1597 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
1598 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
1599 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
1600 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
1601 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
1602 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
1604 { rtfDocAttr, rtfFENoteType, "fet", 0 },
1605 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
1606 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
1607 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
1608 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
1609 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
1610 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
1611 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
1612 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
1613 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
1614 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
1615 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
1616 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
1617 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
1618 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
1619 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
1620 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
1621 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
1622 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
1623 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
1624 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
1625 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
1626 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
1627 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
1628 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
1629 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
1630 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
1631 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
1633 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
1634 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
1635 { rtfDocAttr, rtfPaperSize, "psz", 0 },
1636 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
1637 { rtfDocAttr, rtfRightMargin, "margr", 0 },
1638 { rtfDocAttr, rtfTopMargin, "margt", 0 },
1639 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
1640 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
1641 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
1642 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
1643 { rtfDocAttr, rtfLandscape, "landscape", 0 },
1644 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
1645 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
1647 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
1649 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
1650 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
1651 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
1652 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
1653 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
1654 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
1655 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
1656 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
1657 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
1658 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
1659 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
1660 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
1662 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
1663 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
1664 { rtfDocAttr, rtfFormShading, "formshade", 0 },
1665 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
1666 { rtfDocAttr, rtfPrintData, "printdata", 0 },
1668 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
1669 { rtfDocAttr, rtfRevisions, "revisions", 0 },
1670 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
1671 { rtfDocAttr, rtfRevBar, "revbar", 0 },
1673 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
1675 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
1676 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
1678 { rtfDocAttr, rtfAnsiCodePage, "ansicpg", 0 },
1679 { rtfDocAttr, rtfUTF8RTF, "urtf", 0 },
1682 * Style attributes
1685 { rtfStyleAttr, rtfAdditive, "additive", 0 },
1686 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
1687 { rtfStyleAttr, rtfNext, "snext", 0 },
1690 * Picture attributes
1693 { rtfPictAttr, rtfMacQD, "macpict", 0 },
1694 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
1695 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
1696 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
1697 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
1698 { rtfPictAttr, rtfEmfBlip, "emfblip", 0 },
1699 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
1700 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
1701 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
1703 { rtfPictAttr, rtfPicWid, "picw", 0 },
1704 { rtfPictAttr, rtfPicHt, "pich", 0 },
1705 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
1706 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
1707 /* these two aren't in the spec, but some writers emit them */
1708 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
1709 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
1710 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
1711 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
1712 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
1713 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
1714 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
1715 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
1716 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
1718 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
1719 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
1721 { rtfPictAttr, rtfPicBinary, "bin", 0 },
1724 * NeXT graphic attributes
1727 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
1728 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
1731 * Destinations
1734 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
1735 { rtfDestination, rtfFontAltName, "falt", 0 },
1736 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
1737 { rtfDestination, rtfFontFile, "fontfile", 0 },
1738 { rtfDestination, rtfFileTbl, "filetbl", 0 },
1739 { rtfDestination, rtfFileInfo, "file", 0 },
1740 { rtfDestination, rtfColorTbl, "colortbl", 0 },
1741 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
1742 { rtfDestination, rtfKeyCode, "keycode", 0 },
1743 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
1744 { rtfDestination, rtfGenerator, "generator", 0 },
1745 { rtfDestination, rtfInfo, "info", 0 },
1746 { rtfDestination, rtfITitle, "title", 0 },
1747 { rtfDestination, rtfISubject, "subject", 0 },
1748 { rtfDestination, rtfIAuthor, "author", 0 },
1749 { rtfDestination, rtfIOperator, "operator", 0 },
1750 { rtfDestination, rtfIKeywords, "keywords", 0 },
1751 { rtfDestination, rtfIComment, "comment", 0 },
1752 { rtfDestination, rtfIVersion, "version", 0 },
1753 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
1754 /* \verscomm may not exist -- was seen in earlier spec version */
1755 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
1756 { rtfDestination, rtfNextFile, "nextfile", 0 },
1757 { rtfDestination, rtfTemplate, "template", 0 },
1758 { rtfDestination, rtfFNSep, "ftnsep", 0 },
1759 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
1760 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
1761 { rtfDestination, rtfENSep, "aftnsep", 0 },
1762 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
1763 { rtfDestination, rtfENContNotice, "aftncn", 0 },
1764 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
1765 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
1766 { rtfDestination, rtfHeader, "header", 0 },
1767 { rtfDestination, rtfFooter, "footer", 0 },
1768 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
1769 { rtfDestination, rtfHeaderRight, "headerr", 0 },
1770 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
1771 { rtfDestination, rtfFooterLeft, "footerl", 0 },
1772 { rtfDestination, rtfFooterRight, "footerr", 0 },
1773 { rtfDestination, rtfFooterFirst, "footerf", 0 },
1774 { rtfDestination, rtfParNumText, "pntext", 0 },
1775 { rtfDestination, rtfParNumbering, "pn", 0 },
1776 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
1777 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
1778 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
1779 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
1780 { rtfDestination, rtfPict, "pict", 0 },
1781 { rtfDestination, rtfObject, "object", 0 },
1782 { rtfDestination, rtfObjClass, "objclass", 0 },
1783 { rtfDestination, rtfObjName, "objname", 0 },
1784 { rtfObjAttr, rtfObjTime, "objtime", 0 },
1785 { rtfDestination, rtfObjData, "objdata", 0 },
1786 { rtfDestination, rtfObjAlias, "objalias", 0 },
1787 { rtfDestination, rtfObjSection, "objsect", 0 },
1788 /* objitem and objtopic aren't documented in the spec! */
1789 { rtfDestination, rtfObjItem, "objitem", 0 },
1790 { rtfDestination, rtfObjTopic, "objtopic", 0 },
1791 { rtfDestination, rtfObjResult, "result", 0 },
1792 { rtfDestination, rtfDrawObject, "do", 0 },
1793 { rtfDestination, rtfFootnote, "footnote", 0 },
1794 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
1795 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
1796 { rtfDestination, rtfAnnotID, "atnid", 0 },
1797 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
1798 { rtfDestination, rtfAnnotation, "annotation", 0 },
1799 { rtfDestination, rtfAnnotRef, "atnref", 0 },
1800 { rtfDestination, rtfAnnotTime, "atntime", 0 },
1801 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
1802 { rtfDestination, rtfField, "field", 0 },
1803 { rtfDestination, rtfFieldInst, "fldinst", 0 },
1804 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
1805 { rtfDestination, rtfDataField, "datafield", 0 },
1806 { rtfDestination, rtfIndex, "xe", 0 },
1807 { rtfDestination, rtfIndexText, "txe", 0 },
1808 { rtfDestination, rtfIndexRange, "rxe", 0 },
1809 { rtfDestination, rtfTOC, "tc", 0 },
1810 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
1811 { rtfDestination, rtfNestTableProps, "nesttableprops", 0 },
1812 { rtfDestination, rtfNoNestTables, "nonesttables", 0 },
1815 * Font families
1818 { rtfFontFamily, rtfFFNil, "fnil", 0 },
1819 { rtfFontFamily, rtfFFRoman, "froman", 0 },
1820 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
1821 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
1822 { rtfFontFamily, rtfFFScript, "fscript", 0 },
1823 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
1824 { rtfFontFamily, rtfFFTech, "ftech", 0 },
1825 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
1828 * Font attributes
1831 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
1832 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
1833 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
1834 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
1835 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
1838 * File table attributes
1841 { rtfFileAttr, rtfFileNum, "fid", 0 },
1842 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
1843 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
1846 * File sources
1849 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
1850 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
1851 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
1852 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
1853 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
1856 * Color names
1859 { rtfColorName, rtfRed, "red", 0 },
1860 { rtfColorName, rtfGreen, "green", 0 },
1861 { rtfColorName, rtfBlue, "blue", 0 },
1864 * Charset names
1867 { rtfCharSet, rtfMacCharSet, "mac", 0 },
1868 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
1869 { rtfCharSet, rtfPcCharSet, "pc", 0 },
1870 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
1873 * Table attributes
1876 { rtfTblAttr, rtfRowDef, "trowd", 0 },
1877 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
1878 { rtfTblAttr, rtfCellPos, "cellx", 0 },
1879 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
1880 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
1882 { rtfTblAttr, rtfRowLeft, "trql", 0 },
1883 { rtfTblAttr, rtfRowRight, "trqr", 0 },
1884 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
1885 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
1886 { rtfTblAttr, rtfRowHt, "trrh", 0 },
1887 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
1888 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
1890 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
1891 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
1893 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
1894 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
1895 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
1896 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
1897 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
1898 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
1900 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
1901 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
1902 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
1903 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
1905 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
1906 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
1907 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
1908 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
1909 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
1910 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
1911 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
1913 * The spec lists "clbgdkhor", but the corresponding non-cell
1914 * control is "bgdkhoriz". At any rate Macintosh Word seems
1915 * to accept both "clbgdkhor" and "clbgdkhoriz".
1917 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
1918 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
1919 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
1920 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
1921 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
1922 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
1923 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
1924 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
1925 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
1928 * Field attributes
1931 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
1932 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
1933 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
1934 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
1935 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
1938 * Positioning attributes
1941 { rtfPosAttr, rtfAbsWid, "absw", 0 },
1942 { rtfPosAttr, rtfAbsHt, "absh", 0 },
1944 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
1945 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
1946 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
1947 { rtfPosAttr, rtfPosX, "posx", 0 },
1948 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
1949 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
1950 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
1951 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
1952 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
1953 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
1955 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
1956 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
1957 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
1958 { rtfPosAttr, rtfPosY, "posy", 0 },
1959 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
1960 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
1961 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
1962 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
1963 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
1965 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
1966 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
1967 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
1968 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
1969 /* \dyfrtext no longer exists in spec 1.2, apparently */
1970 /* replaced by \dfrmtextx and \dfrmtexty. */
1971 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
1973 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
1974 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
1977 * Object controls
1980 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
1981 { rtfObjAttr, rtfObjLink, "objlink", 0 },
1982 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
1983 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
1984 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
1985 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
1987 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
1988 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
1989 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
1991 { rtfObjAttr, rtfObjHt, "objh", 0 },
1992 { rtfObjAttr, rtfObjWid, "objw", 0 },
1993 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
1994 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
1995 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
1996 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
1997 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
1998 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
1999 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
2000 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
2001 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2003 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2004 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2005 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2006 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2007 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2009 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2010 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2013 * Associated character formatting attributes
2016 { rtfACharAttr, rtfACBold, "ab", 0 },
2017 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2018 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2019 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2020 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2021 { rtfACharAttr, rtfACFontNum, "af", 0 },
2022 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2023 { rtfACharAttr, rtfACItalic, "ai", 0 },
2024 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2025 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2026 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2027 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2028 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2029 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2030 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2031 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2032 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2033 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2034 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2037 * Footnote attributes
2040 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2043 * Key code attributes
2046 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2047 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2048 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2049 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2052 * Bookmark attributes
2055 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2056 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2059 * Index entry attributes
2062 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2063 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2064 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2067 * Table of contents attributes
2070 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2071 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2074 * Drawing object attributes
2077 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2078 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2079 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2080 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2081 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2082 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2083 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2084 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2086 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2087 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2088 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2089 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2090 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2091 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2092 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2093 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2094 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2095 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2096 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2098 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2099 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2100 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2101 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2103 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2104 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2105 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2106 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2107 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2108 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2109 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2110 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2111 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2112 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2113 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2114 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2115 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2116 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2117 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2118 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2119 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2121 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2122 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2123 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2125 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2126 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2127 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2129 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2130 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2132 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2133 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2134 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2135 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2136 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2137 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2138 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2139 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2140 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2141 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2142 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2143 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2145 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2146 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2147 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2148 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2149 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2150 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2151 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2152 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2154 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2155 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2156 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2157 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2158 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2159 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2160 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2161 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2162 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2163 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2164 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2166 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2167 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2168 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2170 { rtfVersion, -1, "rtf", 0 },
2171 { rtfDefFont, -1, "deff", 0 },
2173 { 0, -1, NULL, 0 }
2175 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2177 typedef struct tagRTFHashTableEntry {
2178 int count;
2179 RTFKey **value;
2180 } RTFHashTableEntry;
2182 static RTFHashTableEntry rtfHashTable[RTF_KEY_COUNT * 2];
2186 * Initialize lookup table hash values. Only need to do this once.
2189 void LookupInit(void)
2191 RTFKey *rp;
2193 memset(rtfHashTable, 0, sizeof rtfHashTable);
2194 for (rp = rtfKey; rp->rtfKStr != NULL; rp++)
2196 int index;
2198 rp->rtfKHash = Hash (rp->rtfKStr);
2199 index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
2200 if (!rtfHashTable[index].count)
2201 rtfHashTable[index].value = heap_alloc(sizeof(RTFKey *));
2202 else
2203 rtfHashTable[index].value = heap_realloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
2204 rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
2208 void LookupCleanup(void)
2210 unsigned int i;
2212 for (i=0; i<RTF_KEY_COUNT*2; i++)
2214 heap_free( rtfHashTable[i].value );
2215 rtfHashTable[i].value = NULL;
2216 rtfHashTable[i].count = 0;
2222 * Determine major and minor number of control token. If it's
2223 * not found, the class turns into rtfUnknown.
2226 static void Lookup(RTF_Info *info, char *s)
2228 RTFKey *rp;
2229 int hash;
2230 RTFHashTableEntry *entry;
2231 int i;
2233 ++s; /* skip over the leading \ character */
2234 hash = Hash (s);
2235 entry = &rtfHashTable[hash % (RTF_KEY_COUNT * 2)];
2236 for (i = 0; i < entry->count; i++)
2238 rp = entry->value[i];
2239 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2241 info->rtfClass = rtfControl;
2242 info->rtfMajor = rp->rtfKMajor;
2243 info->rtfMinor = rp->rtfKMinor;
2244 return;
2247 info->rtfClass = rtfUnknown;
2252 * Compute hash value of symbol
2255 static int Hash(const char *s)
2257 char c;
2258 int val = 0;
2260 while ((c = *s++) != '\0')
2261 val += c;
2262 return (val);
2267 /* ---------------------------------------------------------------------- */
2271 * Token comparison routines
2274 int RTFCheckCM(const RTF_Info *info, int class, int major)
2276 return (info->rtfClass == class && info->rtfMajor == major);
2280 int RTFCheckCMM(const RTF_Info *info, int class, int major, int minor)
2282 return (info->rtfClass == class && info->rtfMajor == major && info->rtfMinor == minor);
2286 int RTFCheckMM(const RTF_Info *info, int major, int minor)
2288 return (info->rtfMajor == major && info->rtfMinor == minor);
2292 /* ---------------------------------------------------------------------- */
2295 int RTFCharToHex(char c)
2297 if (isupper (c))
2298 c = tolower (c);
2299 if (isdigit (c))
2300 return (c - '0'); /* '0'..'9' */
2301 return (c - 'a' + 10); /* 'a'..'f' */
2305 /* ---------------------------------------------------------------------- */
2308 * originally from RTF tools' text-writer.c
2310 * text-writer -- RTF-to-text translation writer code.
2312 * Read RTF input, write text of document (text extraction).
2315 static void TextClass (RTF_Info *info);
2316 static void ControlClass (RTF_Info *info);
2317 static void DefFont(RTF_Info *info);
2318 static void Destination (RTF_Info *info);
2319 static void SpecialChar (RTF_Info *info);
2320 static void RTFPutUnicodeChar (RTF_Info *info, int c);
2323 * Initialize the writer.
2326 void
2327 WriterInit (RTF_Info *info )
2333 BeginFile (RTF_Info *info )
2335 /* install class callbacks */
2337 RTFSetClassCallback (info, rtfText, TextClass);
2338 RTFSetClassCallback (info, rtfControl, ControlClass);
2340 return (1);
2344 * Write out a character.
2347 static void
2348 TextClass (RTF_Info *info)
2350 RTFPutCodePageChar(info, info->rtfMajor);
2354 static void
2355 ControlClass (RTF_Info *info)
2357 switch (info->rtfMajor)
2359 case rtfCharAttr:
2360 CharAttr(info);
2361 ME_RTFCharAttrHook(info);
2362 break;
2363 case rtfParAttr:
2364 ME_RTFParAttrHook(info);
2365 break;
2366 case rtfTblAttr:
2367 ME_RTFTblAttrHook(info);
2368 break;
2369 case rtfCharSet:
2370 CharSet(info);
2371 break;
2372 case rtfDefFont:
2373 DefFont(info);
2374 break;
2375 case rtfDestination:
2376 Destination (info);
2377 break;
2378 case rtfDocAttr:
2379 DocAttr(info);
2380 break;
2381 case rtfSpecialChar:
2382 SpecialChar (info);
2383 ME_RTFSpecialCharHook(info);
2384 break;
2389 static void
2390 CharAttr(RTF_Info *info)
2392 RTFFont *font;
2394 switch (info->rtfMinor)
2396 case rtfFontNum:
2397 font = RTFGetFont(info, info->rtfParam);
2398 if (font)
2400 if (info->ansiCodePage != CP_UTF8)
2401 info->codePage = font->rtfFCodePage;
2402 TRACE("font %d codepage %d\n", info->rtfParam, info->codePage);
2404 else
2405 ERR( "unknown font %d\n", info->rtfParam);
2406 break;
2407 case rtfUnicodeLength:
2408 info->unicodeLength = info->rtfParam;
2409 break;
2414 static void
2415 CharSet(RTF_Info *info)
2417 if (info->ansiCodePage == CP_UTF8)
2418 return;
2420 switch (info->rtfMinor)
2422 case rtfAnsiCharSet:
2423 info->ansiCodePage = 1252; /* Latin-1 */
2424 break;
2425 case rtfMacCharSet:
2426 info->ansiCodePage = 10000; /* MacRoman */
2427 break;
2428 case rtfPcCharSet:
2429 info->ansiCodePage = 437;
2430 break;
2431 case rtfPcaCharSet:
2432 info->ansiCodePage = 850;
2433 break;
2438 * This function notices destinations that aren't explicitly handled
2439 * and skips to their ends. This keeps, for instance, picture
2440 * data from being considered as plain text.
2443 static void
2444 Destination (RTF_Info *info)
2446 if (!RTFGetDestinationCallback(info, info->rtfMinor))
2447 RTFSkipGroup (info);
2451 static void
2452 DefFont(RTF_Info *info)
2454 TRACE("%d\n", info->rtfParam);
2455 info->defFont = info->rtfParam;
2459 static void
2460 DocAttr(RTF_Info *info)
2462 TRACE("minor %d, param %d\n", info->rtfMinor, info->rtfParam);
2464 switch (info->rtfMinor)
2466 case rtfAnsiCodePage:
2467 info->codePage = info->ansiCodePage = info->rtfParam;
2468 break;
2469 case rtfUTF8RTF:
2470 info->codePage = info->ansiCodePage = CP_UTF8;
2471 break;
2476 static void SpecialChar (RTF_Info *info)
2478 switch (info->rtfMinor)
2480 case rtfOptDest:
2481 /* the next token determines destination, if it's unknown, skip the group */
2482 /* this way we filter out the garbage coming from unknown destinations */
2483 RTFGetToken(info);
2484 if (info->rtfClass != rtfDestination)
2485 RTFSkipGroup(info);
2486 else
2487 RTFRouteToken(info); /* "\*" is ignored with known destinations */
2488 break;
2489 case rtfUnicode:
2491 int i;
2493 RTFPutUnicodeChar(info, info->rtfParam);
2495 /* After \u we must skip number of character tokens set by \ucN */
2496 for (i = 0; i < info->unicodeLength; i++)
2498 RTFGetToken(info);
2499 if (info->rtfClass != rtfText)
2501 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2502 info->rtfClass, info->rtfMajor, info->rtfMinor);
2503 RTFUngetToken(info);
2504 break;
2507 break;
2509 case rtfLine:
2510 RTFFlushOutputBuffer(info);
2511 ME_InsertEndRowFromCursor(info->editor, 0);
2512 break;
2513 case rtfPage:
2514 case rtfSect:
2515 case rtfPar:
2516 RTFPutUnicodeChar (info, '\r');
2517 if (info->editor->bEmulateVersion10) RTFPutUnicodeChar (info, '\n');
2518 break;
2519 case rtfNoBrkSpace:
2520 RTFPutUnicodeChar (info, 0x00A0);
2521 break;
2522 case rtfTab:
2523 RTFPutUnicodeChar (info, '\t');
2524 break;
2525 case rtfNoBrkHyphen:
2526 RTFPutUnicodeChar (info, 0x2011);
2527 break;
2528 case rtfBullet:
2529 RTFPutUnicodeChar (info, 0x2022);
2530 break;
2531 case rtfEmDash:
2532 RTFPutUnicodeChar (info, 0x2014);
2533 break;
2534 case rtfEnDash:
2535 RTFPutUnicodeChar (info, 0x2013);
2536 break;
2537 case rtfLQuote:
2538 RTFPutUnicodeChar (info, 0x2018);
2539 break;
2540 case rtfRQuote:
2541 RTFPutUnicodeChar (info, 0x2019);
2542 break;
2543 case rtfLDblQuote:
2544 RTFPutUnicodeChar (info, 0x201C);
2545 break;
2546 case rtfRDblQuote:
2547 RTFPutUnicodeChar (info, 0x201D);
2548 break;
2553 static void
2554 RTFFlushUnicodeOutputBuffer(RTF_Info *info)
2556 if (info->dwOutputCount)
2558 ME_InsertTextFromCursor(info->editor, 0, info->OutputBuffer,
2559 info->dwOutputCount, info->style);
2560 info->dwOutputCount = 0;
2565 static void
2566 RTFPutUnicodeString(RTF_Info *info, const WCHAR *string, int length)
2568 if (info->dwCPOutputCount)
2569 RTFFlushCPOutputBuffer(info);
2570 while (length)
2572 int fit = min(length, sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount);
2574 memmove(info->OutputBuffer + info->dwOutputCount, string, fit * sizeof(WCHAR));
2575 info->dwOutputCount += fit;
2576 length -= fit;
2577 string += fit;
2578 if (sizeof(info->OutputBuffer) / sizeof(WCHAR) == info->dwOutputCount)
2579 RTFFlushUnicodeOutputBuffer(info);
2583 static void
2584 RTFFlushCPOutputBuffer(RTF_Info *info)
2586 int bufferMax = info->dwCPOutputCount * 2 * sizeof(WCHAR);
2587 WCHAR *buffer = heap_alloc(bufferMax);
2588 int length;
2590 length = MultiByteToWideChar(info->codePage, 0, info->cpOutputBuffer,
2591 info->dwCPOutputCount, buffer, bufferMax/sizeof(WCHAR));
2592 info->dwCPOutputCount = 0;
2594 RTFPutUnicodeString(info, buffer, length);
2595 heap_free(buffer);
2598 void
2599 RTFFlushOutputBuffer(RTF_Info *info)
2601 if (info->dwCPOutputCount)
2602 RTFFlushCPOutputBuffer(info);
2603 RTFFlushUnicodeOutputBuffer(info);
2606 static void
2607 RTFPutUnicodeChar(RTF_Info *info, int c)
2609 if (info->dwCPOutputCount)
2610 RTFFlushCPOutputBuffer(info);
2611 if (info->dwOutputCount * sizeof(WCHAR) >= ( sizeof info->OutputBuffer - 1 ) )
2612 RTFFlushUnicodeOutputBuffer( info );
2613 info->OutputBuffer[info->dwOutputCount++] = c;
2616 static void
2617 RTFPutCodePageChar(RTF_Info *info, int c)
2619 /* Use dynamic buffer here because it's the best way to handle
2620 * MBCS codepages without having to worry about partial chars */
2621 if (info->dwCPOutputCount >= info->dwMaxCPOutputCount)
2623 info->dwMaxCPOutputCount *= 2;
2624 info->cpOutputBuffer = heap_realloc(info->cpOutputBuffer, info->dwMaxCPOutputCount);
2626 info->cpOutputBuffer[info->dwCPOutputCount++] = c;