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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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.
33 * Author: Paul DuBois dubois@primate.wisc.edu
35 * This software may be redistributed without restriction and used for
36 * any purpose whatsoever.
48 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
55 extern HANDLE me_heap;
57 static int _RTFGetChar(RTF_Info *);
58 static void _RTFGetToken (RTF_Info *);
59 static void _RTFGetToken2 (RTF_Info *);
60 static int GetChar (RTF_Info *);
61 static void ReadFontTbl (RTF_Info *);
62 static void ReadColorTbl (RTF_Info *);
63 static void ReadStyleSheet (RTF_Info *);
64 static void ReadInfoGroup (RTF_Info *);
65 static void ReadPictGroup (RTF_Info *);
66 static void ReadObjGroup (RTF_Info *);
67 static void LookupInit (void);
68 static void Lookup (RTF_Info *, char *);
69 static int Hash (char*);
71 static void CharAttr(RTF_Info *info);
72 static void CharSet(RTF_Info *info);
73 static void DocAttr(RTF_Info *info);
75 static void RTFFlushCPOutputBuffer(RTF_Info *info);
76 static void RTFPutCodePageChar(RTF_Info *info, int c);
78 /* ---------------------------------------------------------------------- */
81 * Memory allocation routines
86 * Return pointer to block of size bytes, or NULL if there's
87 * not enough memory available.
89 static inline void *RTFAlloc(int size)
91 return HeapAlloc(me_heap, 0, size);
95 static inline void * RTFReAlloc(void *ptr, int size)
97 return HeapReAlloc(me_heap, 0, ptr, size);
102 * Saves a string on the heap and returns a pointer to it.
104 static inline char *RTFStrSave(char *s)
108 p = RTFAlloc (lstrlenA(s) + 1);
111 return lstrcpyA (p, s);
115 static inline void RTFFree(void *p)
117 HeapFree(me_heap, 0, p);
121 /* ---------------------------------------------------------------------- */
124 int _RTFGetChar(RTF_Info *info)
127 ME_InStream *stream = info->stream;
131 if (stream->dwSize <= stream->dwUsed)
133 ME_StreamInFill(stream);
134 /* if error, it's EOF */
135 if (stream->editstream->dwError)
137 /* if no bytes read, it's EOF */
138 if (stream->dwSize == 0)
141 ch = stream->buffer[stream->dwUsed++];
147 void RTFSetEditStream(RTF_Info *info, ME_InStream *stream)
151 info->stream = stream;
155 RTFDestroyAttrs(RTF_Info *info)
160 RTFStyleElt *eltList, *ep;
162 while (info->fontList)
164 fp = info->fontList->rtfNextFont;
165 RTFFree (info->fontList->rtfFName);
166 RTFFree (info->fontList);
169 while (info->colorList)
171 cp = info->colorList->rtfNextColor;
172 RTFFree (info->colorList);
173 info->colorList = cp;
175 while (info->styleList)
177 sp = info->styleList->rtfNextStyle;
178 eltList = info->styleList->rtfSSEList;
181 ep = eltList->rtfNextSE;
182 RTFFree (eltList->rtfSEText);
186 RTFFree (info->styleList->rtfSName);
187 RTFFree (info->styleList);
188 info->styleList = sp;
194 RTFDestroy(RTF_Info *info)
196 if (info->rtfTextBuf)
198 RTFFree(info->rtfTextBuf);
199 RTFFree(info->pushedTextBuf);
201 RTFDestroyAttrs(info);
202 RTFFree(info->cpOutputBuffer);
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)
218 if (info->rtfTextBuf == NULL) /* initialize the text buffers */
220 info->rtfTextBuf = RTFAlloc (rtfBufSiz);
221 info->pushedTextBuf = RTFAlloc (rtfBufSiz);
222 if (info->rtfTextBuf == NULL || info->pushedTextBuf == NULL)
223 ERR ("Cannot allocate text buffers.\n");
224 info->rtfTextBuf[0] = info->pushedTextBuf[0] = '\0';
227 RTFFree (info->inputName);
228 RTFFree (info->outputName);
229 info->inputName = info->outputName = NULL;
231 /* initialize lookup table */
234 for (i = 0; i < rtfMaxClass; i++)
235 RTFSetClassCallback (info, i, NULL);
236 for (i = 0; i < rtfMaxDestination; i++)
237 RTFSetDestinationCallback (info, i, NULL);
239 /* install built-in destination readers */
240 RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl);
241 RTFSetDestinationCallback (info, rtfColorTbl, ReadColorTbl);
242 RTFSetDestinationCallback (info, rtfStyleSheet, ReadStyleSheet);
243 RTFSetDestinationCallback (info, rtfInfo, ReadInfoGroup);
244 RTFSetDestinationCallback (info, rtfPict, ReadPictGroup);
245 RTFSetDestinationCallback (info, rtfObject, ReadObjGroup);
248 RTFSetReadHook (info, NULL);
250 /* dump old lists if necessary */
252 RTFDestroyAttrs(info);
254 info->ansiCodePage = 1252; /* Latin-1; actually unused */
255 info->unicodeLength = 1; /* \uc1 is the default */
256 info->codePage = info->ansiCodePage;
260 info->pushedClass = -1;
261 info->pushedChar = EOF;
263 info->rtfLineNum = 0;
264 info->rtfLinePos = 0;
265 info->prevChar = EOF;
268 info->dwCPOutputCount = 0;
269 if (!info->cpOutputBuffer)
271 info->dwMaxCPOutputCount = 0x1000;
272 info->cpOutputBuffer = RTFAlloc(info->dwMaxCPOutputCount);
277 * Set or get the input or output file name. These are never guaranteed
278 * to be accurate, only insofar as the calling program makes them so.
281 void RTFSetInputName(RTF_Info *info, char *name)
285 info->inputName = RTFStrSave (name);
286 if (info->inputName == NULL)
287 ERR ("RTFSetInputName: out of memory\n");
291 char *RTFGetInputName(RTF_Info *info)
293 return (info->inputName);
297 void RTFSetOutputName(RTF_Info *info, char *name)
301 info->outputName = RTFStrSave (name);
302 if (info->outputName == NULL)
303 ERR ("RTFSetOutputName: out of memory\n");
307 char *RTFGetOutputName(RTF_Info *info)
309 return (info->outputName);
314 /* ---------------------------------------------------------------------- */
317 * Callback table manipulation routines
322 * Install or return a writer callback for a token class
325 void RTFSetClassCallback(RTF_Info *info, int class, RTFFuncPtr callback)
327 if (class >= 0 && class < rtfMaxClass)
328 info->ccb[class] = callback;
332 RTFFuncPtr RTFGetClassCallback(RTF_Info *info, int class)
334 if (class >= 0 && class < rtfMaxClass)
335 return info->ccb[class];
341 * Install or return a writer callback for a destination type
344 void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback)
346 if (dest >= 0 && dest < rtfMaxDestination)
347 info->dcb[dest] = callback;
351 RTFFuncPtr RTFGetDestinationCallback(RTF_Info *info, int dest)
353 if (dest >= 0 && dest < rtfMaxDestination)
354 return info->dcb[dest];
359 /* ---------------------------------------------------------------------- */
362 * Token reading routines
367 * Read the input stream, invoking the writer's callbacks
371 void RTFRead(RTF_Info *info)
373 while (RTFGetToken (info) != rtfEOF)
374 RTFRouteToken (info);
379 * Route a token. If it's a destination for which a reader is
380 * installed, process the destination internally, otherwise
381 * pass the token to the writer's class callback.
384 void RTFRouteToken(RTF_Info *info)
390 if (info->rtfClass < 0 || info->rtfClass >= rtfMaxClass) /* watchdog */
392 ERR( "Unknown class %d: %s (reader malfunction)\n",
393 info->rtfClass, info->rtfTextBuf);
395 if (RTFCheckCM (info, rtfControl, rtfDestination))
397 /* invoke destination-specific callback if there is one */
398 p = RTFGetDestinationCallback (info, info->rtfMinor);
405 /* invoke class callback if there is one */
406 p = RTFGetClassCallback (info, info->rtfClass);
413 * Skip to the end of the current group. When this returns,
414 * writers that maintain a state stack may want to call their
415 * state unstacker; global vars will still be set to the group's
419 void RTFSkipGroup(RTF_Info *info)
425 while (RTFGetToken (info) != rtfEOF)
427 if (info->rtfClass == rtfGroup)
429 if (info->rtfMajor == rtfBeginGroup)
431 else if (info->rtfMajor == rtfEndGroup)
434 break; /* end of initial group */
442 * Read one token. Call the read hook if there is one. The
443 * token class is the return value. Returns rtfEOF when there
444 * are no more tokens.
447 int RTFGetToken(RTF_Info *info)
452 /* don't try to return anything once EOF is reached */
453 if (info->rtfClass == rtfEOF) {
460 p = RTFGetReadHook (info);
462 (*p) (info); /* give read hook a look at token */
464 /* Silently discard newlines, carriage returns, nulls. */
465 if (!(info->rtfClass == rtfText && info->rtfFormat != SF_TEXT
466 && (info->rtfMajor == '\r' || info->rtfMajor == '\n' || info->rtfMajor == '\0')))
469 return (info->rtfClass);
474 * Install or return a token reader hook.
477 void RTFSetReadHook(RTF_Info *info, RTFFuncPtr f)
483 RTFFuncPtr RTFGetReadHook(RTF_Info *info)
485 return (info->readHook);
489 void RTFUngetToken(RTF_Info *info)
493 if (info->pushedClass >= 0) /* there's already an ungotten token */
494 ERR ("cannot unget two tokens\n");
495 if (info->rtfClass < 0)
496 ERR ("no token to unget\n");
497 info->pushedClass = info->rtfClass;
498 info->pushedMajor = info->rtfMajor;
499 info->pushedMinor = info->rtfMinor;
500 info->pushedParam = info->rtfParam;
501 lstrcpyA (info->pushedTextBuf, info->rtfTextBuf);
505 int RTFPeekToken(RTF_Info *info)
508 RTFUngetToken (info);
509 return (info->rtfClass);
513 static void _RTFGetToken(RTF_Info *info)
517 if (info->rtfFormat == SF_TEXT)
519 info->rtfMajor = GetChar (info);
521 info->rtfParam = rtfNoParam;
522 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
523 if (info->rtfMajor == EOF)
524 info->rtfClass = rtfEOF;
526 info->rtfClass = rtfText;
530 /* first check for pushed token from RTFUngetToken() */
532 if (info->pushedClass >= 0)
534 info->rtfClass = info->pushedClass;
535 info->rtfMajor = info->pushedMajor;
536 info->rtfMinor = info->pushedMinor;
537 info->rtfParam = info->pushedParam;
538 lstrcpyA (info->rtfTextBuf, info->pushedTextBuf);
539 info->rtfTextLen = lstrlenA(info->rtfTextBuf);
540 info->pushedClass = -1;
545 * Beyond this point, no token is ever seen twice, which is
546 * important, e.g., for making sure no "}" pops the font stack twice.
549 _RTFGetToken2 (info);
554 RTFCharSetToCodePage(RTF_Info *info, int charset)
560 case DEFAULT_CHARSET:
566 case SHIFTJIS_CHARSET:
568 case HANGEUL_CHARSET:
574 case CHINESEBIG5_CHARSET:
578 case TURKISH_CHARSET:
580 case VIETNAMESE_CHARSET:
588 case RUSSIAN_CHARSET:
592 case EASTEUROPE_CHARSET:
601 /* FIXME: TranslateCharsetInfo does not work as good as it
602 * should, so let's use it only when all else fails */
603 if (!TranslateCharsetInfo(&n, &csi, TCI_SRCCHARSET))
604 ERR("%s: unknown charset %u\n", __FUNCTION__, charset);
613 /* this shouldn't be called anywhere but from _RTFGetToken() */
615 static void _RTFGetToken2(RTF_Info *info)
622 /* initialize token vars */
624 info->rtfClass = rtfUnknown;
625 info->rtfParam = rtfNoParam;
626 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
628 /* get first character, which may be a pushback from previous token */
630 if (info->pushedChar != EOF)
632 c = info->pushedChar;
633 info->rtfTextBuf[info->rtfTextLen++] = c;
634 info->rtfTextBuf[info->rtfTextLen] = '\0';
635 info->pushedChar = EOF;
637 else if ((c = GetChar (info)) == EOF)
639 info->rtfClass = rtfEOF;
645 info->rtfClass = rtfGroup;
646 info->rtfMajor = rtfBeginGroup;
651 info->rtfClass = rtfGroup;
652 info->rtfMajor = rtfEndGroup;
658 * Two possibilities here:
659 * 1) ASCII 9, effectively like \tab control symbol
660 * 2) literal text char
662 if (c == '\t') /* ASCII 9 */
664 info->rtfClass = rtfControl;
665 info->rtfMajor = rtfSpecialChar;
666 info->rtfMinor = rtfTab;
670 info->rtfClass = rtfText;
675 if ((c = GetChar (info)) == EOF)
677 /* early eof, whoops (class is rtfUnknown) */
683 * Three possibilities here:
684 * 1) hex encoded text char, e.g., \'d5, \'d3
685 * 2) special escaped text char, e.g., \{, \}
686 * 3) control symbol, e.g., \_, \-, \|, \<10>
688 if (c == '\'') /* hex char */
692 if ((c = GetChar (info)) != EOF && (c2 = GetChar (info)) != EOF)
694 /* should do isxdigit check! */
695 info->rtfClass = rtfText;
696 info->rtfMajor = RTFCharToHex (c) * 16 + RTFCharToHex (c2);
699 /* early eof, whoops (class is rtfUnknown) */
704 /*if (index (":{}\\", c) != (char *) NULL)*/ /* escaped char */
705 if (c == ':' || c == '{' || c == '}' || c == '\\')
707 info->rtfClass = rtfText;
713 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
719 if ((c = GetChar (info)) == EOF)
724 * At this point, the control word is all collected, so the
725 * major/minor numbers are determined before the parameter
726 * (if any) is scanned. There will be one too many characters
727 * in the buffer, though, so fix up before and restore after
732 info->rtfTextBuf[info->rtfTextLen-1] = '\0';
733 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
735 info->rtfTextBuf[info->rtfTextLen-1] = c;
738 * Should be looking at first digit of parameter if there
739 * is one, unless it's negative. In that case, next char
740 * is '-', so need to gobble next char, and remember sign.
749 if (c != EOF && isdigit (c))
752 while (isdigit (c)) /* gobble parameter */
754 info->rtfParam = info->rtfParam * 10 + c - '0';
755 if ((c = GetChar (info)) == EOF)
758 info->rtfParam *= sign;
761 * If control symbol delimiter was a blank, gobble it.
762 * Otherwise the character is first char of next token, so
763 * push it back for next call. In either case, delete the
764 * delimiter from the token buffer.
769 info->pushedChar = c;
770 info->rtfTextBuf[--info->rtfTextLen] = '\0';
776 * Read the next character from the input. This handles setting the
777 * current line and position-within-line variables. Those variable are
778 * set correctly whether lines end with CR, LF, or CRLF (the last being
781 * bumpLine indicates whether the line number should be incremented on
782 * the *next* input character.
786 static int GetChar(RTF_Info *info)
793 if ((c = _RTFGetChar(info)) != EOF)
795 info->rtfTextBuf[info->rtfTextLen++] = c;
796 info->rtfTextBuf[info->rtfTextLen] = '\0';
798 if (info->prevChar == EOF)
800 oldBumpLine = info->bumpLine; /* non-zero if prev char was line ending */
807 if (info->prevChar == '\r') /* oops, previous \r wasn't */
808 oldBumpLine = 0; /* really a line ending */
811 if (oldBumpLine) /* were we supposed to increment the */
812 { /* line count on this char? */
814 info->rtfLinePos = 1;
822 * Synthesize a token by setting the global variables to the
823 * values supplied. Typically this is followed with a call
824 * to RTFRouteToken().
826 * If a param value other than rtfNoParam is passed, it becomes
827 * part of the token text.
830 void RTFSetToken(RTF_Info *info, int class, int major, int minor, int param, const char *text)
834 info->rtfClass = class;
835 info->rtfMajor = major;
836 info->rtfMinor = minor;
837 info->rtfParam = param;
838 if (param == rtfNoParam)
839 lstrcpyA(info->rtfTextBuf, text);
841 sprintf (info->rtfTextBuf, "%s%d", text, param);
842 info->rtfTextLen = lstrlenA (info->rtfTextBuf);
846 /* ---------------------------------------------------------------------- */
849 * Special destination readers. They gobble the destination so the
850 * writer doesn't have to deal with them. That's wrong for any
851 * translator that wants to process any of these itself. In that
852 * case, these readers should be overridden by installing a different
853 * destination callback.
855 * NOTE: The last token read by each of these reader will be the
856 * destination's terminating '}', which will then be the current token.
857 * That '}' token is passed to RTFRouteToken() - the writer has already
858 * seen the '{' that began the destination group, and may have pushed a
859 * state; it also needs to know at the end of the group that a state
862 * It's important that rtf.h and the control token lookup table list
863 * as many symbols as possible, because these destination readers
864 * unfortunately make strict assumptions about the input they expect,
865 * and a token of class rtfUnknown will throw them off easily.
870 * Read { \fonttbl ... } destination. Old font tables don't have
871 * braces around each table entry; try to adjust for that.
874 static void ReadFontTbl(RTF_Info *info)
877 char buf[rtfBufSiz], *bp;
879 const char *fn = "ReadFontTbl";
886 if (info->rtfClass == rtfEOF)
888 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
890 if (old < 0) /* first entry - determine tbl type */
892 if (RTFCheckCMM (info, rtfControl, rtfCharAttr, rtfFontNum))
893 old = 1; /* no brace */
894 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
896 else /* can't tell! */
897 ERR ( "%s: Cannot determine format\n", fn);
899 if (old == 0) /* need to find "{" here */
901 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
902 ERR ( "%s: missing \"{\"\n", fn);
903 RTFGetToken (info); /* yes, skip to next token */
904 if (info->rtfClass == rtfEOF)
909 ERR ( "%s: cannot allocate font entry\n", fn);
911 fp->rtfNextFont = info->fontList;
915 fp->rtfFAltName = NULL;
918 fp->rtfFCharSet = DEFAULT_CHARSET; /* 1 */
921 fp->rtfFCodePage = CP_ACP;
923 while (info->rtfClass != rtfEOF
924 && !RTFCheckCM (info, rtfText, ';')
925 && !RTFCheckCM (info, rtfGroup, rtfEndGroup))
927 if (info->rtfClass == rtfControl)
929 switch (info->rtfMajor)
932 /* ignore token but announce it */
933 ERR ("%s: unknown token \"%s\"\n",
934 fn, info->rtfTextBuf);
937 fp->rtfFFamily = info->rtfMinor;
940 switch (info->rtfMinor)
943 break; /* ignore unknown? */
945 fp->rtfFNum = info->rtfParam;
950 switch (info->rtfMinor)
953 break; /* ignore unknown? */
955 fp->rtfFCharSet = info->rtfParam;
956 if (!fp->rtfFCodePage)
957 fp->rtfFCodePage = RTFCharSetToCodePage(info, info->rtfParam);
960 fp->rtfFPitch = info->rtfParam;
962 case rtfFontCodePage:
963 fp->rtfFCodePage = info->rtfParam;
966 case rtfFTypeTrueType:
967 fp->rtfFType = info->rtfParam;
973 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup)) /* dest */
975 RTFSkipGroup (info); /* ignore for now */
977 else if (info->rtfClass == rtfText) /* font name */
980 while (info->rtfClass == rtfText
981 && !RTFCheckCM (info, rtfText, ';'))
983 *bp++ = info->rtfMajor;
987 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
988 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
990 RTFUngetToken (info);
993 fp->rtfFName = RTFStrSave (buf);
994 if (fp->rtfFName == NULL)
995 ERR ( "%s: cannot allocate font name\n", fn);
996 /* already have next token; don't read one */
997 /* at bottom of loop */
1002 /* ignore token but announce it */
1003 ERR ( "%s: unknown token \"%s\"\n",
1004 fn,info->rtfTextBuf);
1007 if (info->rtfClass == rtfEOF)
1010 if (info->rtfClass == rtfEOF)
1012 if (old == 0) /* need to see "}" here */
1015 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1016 ERR ( "%s: missing \"}\"\n", fn);
1017 if (info->rtfClass == rtfEOF)
1021 /* Apply the real properties of the default font */
1022 if (fp->rtfFNum == info->defFont)
1024 if (info->ansiCodePage != CP_UTF8)
1025 info->codePage = fp->rtfFCodePage;
1026 TRACE("default font codepage %d\n", info->codePage);
1029 if (fp->rtfFNum == -1)
1030 ERR( "%s: missing font number\n", fn);
1032 * Could check other pieces of structure here, too, I suppose.
1034 RTFRouteToken (info); /* feed "}" back to router */
1036 /* Set default font */
1037 info->rtfClass = rtfControl;
1038 info->rtfMajor = rtfCharAttr;
1039 info->rtfMinor = rtfFontNum;
1040 info->rtfParam = info->defFont;
1041 lstrcpyA(info->rtfTextBuf, "f");
1042 RTFUngetToken(info);
1047 * The color table entries have color values of -1 if
1048 * the default color should be used for the entry (only
1049 * a semi-colon is given in the definition, no color values).
1050 * There will be a problem if a partial entry (1 or 2 but
1051 * not 3 color values) is given. The possibility is ignored
1055 static void ReadColorTbl(RTF_Info *info)
1059 const char *fn = "ReadColorTbl";
1066 if (info->rtfClass == rtfEOF)
1068 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1070 cp = New (RTFColor);
1072 ERR ( "%s: cannot allocate color entry\n", fn);
1073 cp->rtfCNum = cnum++;
1074 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
1075 cp->rtfNextColor = info->colorList;
1076 info->colorList = cp;
1077 while (RTFCheckCM (info, rtfControl, rtfColorName))
1079 switch (info->rtfMinor)
1081 case rtfRed: cp->rtfCRed = info->rtfParam; break;
1082 case rtfGreen: cp->rtfCGreen = info->rtfParam; break;
1083 case rtfBlue: cp->rtfCBlue = info->rtfParam; break;
1087 if (info->rtfClass == rtfEOF)
1089 if (!RTFCheckCM (info, rtfText, ';'))
1090 ERR ("%s: malformed entry\n", fn);
1092 RTFRouteToken (info); /* feed "}" back to router */
1097 * The "Normal" style definition doesn't contain any style number,
1098 * all others do. Normal style is given style rtfNormalStyleNum.
1101 static void ReadStyleSheet(RTF_Info *info)
1104 RTFStyleElt *sep, *sepLast;
1105 char buf[rtfBufSiz], *bp;
1106 const char *fn = "ReadStyleSheet";
1114 if (info->rtfClass == rtfEOF)
1116 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1118 sp = New (RTFStyle);
1120 ERR ( "%s: cannot allocate stylesheet entry\n", fn);
1121 sp->rtfSName = NULL;
1123 sp->rtfSType = rtfParStyle;
1124 sp->rtfSAdditive = 0;
1125 sp->rtfSBasedOn = rtfNoStyleNum;
1126 sp->rtfSNextPar = -1;
1127 sp->rtfSSEList = sepLast = NULL;
1128 sp->rtfNextStyle = info->styleList;
1129 sp->rtfExpanding = 0;
1130 info->styleList = sp;
1131 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1132 ERR ( "%s: missing \"{\"\n", fn);
1137 if (info->rtfClass == rtfEOF
1138 || RTFCheckCM (info, rtfText, ';'))
1140 if (info->rtfClass == rtfControl)
1142 if (RTFCheckMM (info, rtfSpecialChar, rtfOptDest)) {
1144 ERR( "%s: skipping optional destination\n", fn);
1146 info->rtfClass = rtfGroup;
1147 info->rtfMajor = rtfEndGroup;
1149 break; /* ignore "\*" */
1151 if (RTFCheckMM (info, rtfParAttr, rtfStyleNum))
1153 sp->rtfSNum = info->rtfParam;
1154 sp->rtfSType = rtfParStyle;
1157 if (RTFCheckMM (info, rtfCharAttr, rtfCharStyleNum))
1159 sp->rtfSNum = info->rtfParam;
1160 sp->rtfSType = rtfCharStyle;
1163 if (RTFCheckMM (info, rtfSectAttr, rtfSectStyleNum))
1165 sp->rtfSNum = info->rtfParam;
1166 sp->rtfSType = rtfSectStyle;
1169 if (RTFCheckMM (info, rtfStyleAttr, rtfBasedOn))
1171 sp->rtfSBasedOn = info->rtfParam;
1174 if (RTFCheckMM (info, rtfStyleAttr, rtfAdditive))
1176 sp->rtfSAdditive = 1;
1179 if (RTFCheckMM (info, rtfStyleAttr, rtfNext))
1181 sp->rtfSNextPar = info->rtfParam;
1184 sep = New (RTFStyleElt);
1186 ERR ( "%s: cannot allocate style element\n", fn);
1187 sep->rtfSEClass = info->rtfClass;
1188 sep->rtfSEMajor = info->rtfMajor;
1189 sep->rtfSEMinor = info->rtfMinor;
1190 sep->rtfSEParam = info->rtfParam;
1191 sep->rtfSEText = RTFStrSave (info->rtfTextBuf);
1192 if (sep->rtfSEText == NULL)
1193 ERR ( "%s: cannot allocate style element text\n", fn);
1194 if (sepLast == NULL)
1195 sp->rtfSSEList = sep; /* first element */
1196 else /* add to end */
1197 sepLast->rtfNextSE = sep;
1198 sep->rtfNextSE = NULL;
1201 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1204 * This passes over "{\*\keycode ... }, among
1205 * other things. A temporary (perhaps) hack.
1207 ERR( "%s: skipping begin\n", fn);
1208 RTFSkipGroup (info);
1211 else if (info->rtfClass == rtfText) /* style name */
1214 while (info->rtfClass == rtfText)
1216 if (info->rtfMajor == ';')
1218 /* put back for "for" loop */
1219 RTFUngetToken (info);
1222 *bp++ = info->rtfMajor;
1226 sp->rtfSName = RTFStrSave (buf);
1227 if (sp->rtfSName == NULL)
1228 ERR ( "%s: cannot allocate style name\n", fn);
1230 else /* unrecognized */
1232 /* ignore token but announce it */
1233 ERR ( "%s: unknown token \"%s\"\n",
1234 fn, info->rtfTextBuf);
1239 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1240 ERR ( "%s: missing \"}\"\n", fn);
1242 * Check over the style structure. A name is a must.
1243 * If no style number was specified, check whether it's the
1244 * Normal style (in which case it's given style number
1245 * rtfNormalStyleNum). Note that some "normal" style names
1246 * just begin with "Normal" and can have other stuff following,
1247 * e.g., "Normal,Times 10 point". Ugh.
1249 * Some German RTF writers use "Standard" instead of "Normal".
1251 if (sp->rtfSName == NULL)
1252 ERR ( "%s: missing style name\n", fn);
1253 if (sp->rtfSNum < 0)
1255 if (strncmp (buf, "Normal", 6) != 0
1256 && strncmp (buf, "Standard", 8) != 0)
1257 ERR ( "%s: missing style number\n", fn);
1258 sp->rtfSNum = rtfNormalStyleNum;
1260 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1261 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1263 /* otherwise we're just dealing with fake end group from skipped group */
1265 RTFRouteToken (info); /* feed "}" back to router */
1269 static void ReadInfoGroup(RTF_Info *info)
1271 RTFSkipGroup (info);
1272 RTFRouteToken (info); /* feed "}" back to router */
1276 static void ReadPictGroup(RTF_Info *info)
1278 RTFSkipGroup (info);
1279 RTFRouteToken (info); /* feed "}" back to router */
1283 static void ReadObjGroup(RTF_Info *info)
1285 RTFSkipGroup (info);
1286 RTFRouteToken (info); /* feed "}" back to router */
1290 /* ---------------------------------------------------------------------- */
1293 * Routines to return pieces of stylesheet, or font or color tables.
1294 * References to style 0 are mapped onto the Normal style.
1298 RTFStyle *RTFGetStyle(RTF_Info *info, int num)
1303 return (info->styleList);
1304 for (s = info->styleList; s != NULL; s = s->rtfNextStyle)
1306 if (s->rtfSNum == num)
1309 return (s); /* NULL if not found */
1313 RTFFont *RTFGetFont(RTF_Info *info, int num)
1318 return (info->fontList);
1319 for (f = info->fontList; f != NULL; f = f->rtfNextFont)
1321 if (f->rtfFNum == num)
1324 return (f); /* NULL if not found */
1328 RTFColor *RTFGetColor(RTF_Info *info, int num)
1333 return (info->colorList);
1334 for (c = info->colorList; c != NULL; c = c->rtfNextColor)
1336 if (c->rtfCNum == num)
1339 return (c); /* NULL if not found */
1343 /* ---------------------------------------------------------------------- */
1347 * Expand style n, if there is such a style.
1350 void RTFExpandStyle(RTF_Info *info, int n)
1359 s = RTFGetStyle (info, n);
1362 if (s->rtfExpanding != 0)
1363 ERR ("Style expansion loop, style %d\n", n);
1364 s->rtfExpanding = 1; /* set expansion flag for loop detection */
1366 * Expand "based-on" style (unless it's the same as the current
1367 * style -- Normal style usually gives itself as its own based-on
1368 * style). Based-on style expansion is done by synthesizing
1369 * the token that the writer needs to see in order to trigger
1370 * another style expansion, and feeding to token back through
1371 * the router so the writer sees it.
1373 if (n != s->rtfSBasedOn)
1375 RTFSetToken (info, rtfControl, rtfParAttr, rtfStyleNum,
1376 s->rtfSBasedOn, "\\s");
1377 RTFRouteToken (info);
1380 * Now route the tokens unique to this style. RTFSetToken()
1381 * isn't used because it would add the param value to the end
1382 * of the token text, which already has it in.
1384 for (se = s->rtfSSEList; se != NULL; se = se->rtfNextSE)
1386 info->rtfClass = se->rtfSEClass;
1387 info->rtfMajor = se->rtfSEMajor;
1388 info->rtfMinor = se->rtfSEMinor;
1389 info->rtfParam = se->rtfSEParam;
1390 lstrcpyA (info->rtfTextBuf, se->rtfSEText);
1391 info->rtfTextLen = lstrlenA (info->rtfTextBuf);
1392 RTFRouteToken (info);
1394 s->rtfExpanding = 0; /* done - clear expansion flag */
1398 /* ---------------------------------------------------------------------- */
1401 * Control symbol lookup routines
1405 typedef struct RTFKey RTFKey;
1409 int rtfKMajor; /* major number */
1410 int rtfKMinor; /* minor number */
1411 const char *rtfKStr; /* symbol name */
1412 int rtfKHash; /* symbol name hash value */
1416 * A minor number of -1 means the token has no minor number
1417 * (all valid minor numbers are >= 0).
1420 static RTFKey rtfKey[] =
1423 * Special characters
1426 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1427 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1428 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1429 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1430 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1431 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1432 { rtfSpecialChar, rtfIYear, "yr", 0 },
1433 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1434 { rtfSpecialChar, rtfIDay, "dy", 0 },
1435 { rtfSpecialChar, rtfIHour, "hr", 0 },
1436 { rtfSpecialChar, rtfIMinute, "min", 0 },
1437 { rtfSpecialChar, rtfISecond, "sec", 0 },
1438 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1439 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1440 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1441 { rtfSpecialChar, rtfIIntID, "id", 0 },
1443 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1444 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1445 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1446 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1447 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1448 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1449 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1450 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1451 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1452 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1453 { rtfSpecialChar, rtfCell, "cell", 0 },
1454 { rtfSpecialChar, rtfRow, "row", 0 },
1455 { rtfSpecialChar, rtfPar, "par", 0 },
1456 /* newline and carriage return are synonyms for */
1457 /* \par when they are preceded by a \ character */
1458 { rtfSpecialChar, rtfPar, "\n", 0 },
1459 { rtfSpecialChar, rtfPar, "\r", 0 },
1460 { rtfSpecialChar, rtfSect, "sect", 0 },
1461 { rtfSpecialChar, rtfPage, "page", 0 },
1462 { rtfSpecialChar, rtfColumn, "column", 0 },
1463 { rtfSpecialChar, rtfLine, "line", 0 },
1464 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1465 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1466 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1467 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1468 { rtfSpecialChar, rtfTab, "tab", 0 },
1469 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1470 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1471 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1472 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1473 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1474 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1475 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1476 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1477 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1478 { rtfSpecialChar, rtfFormula, "|", 0 },
1479 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1480 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1481 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1482 { rtfSpecialChar, rtfOptDest, "*", 0 },
1483 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1484 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1485 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1486 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1487 /* is this valid? */
1488 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1489 { rtfSpecialChar, rtfUnicode, "u", 0 },
1492 * Character formatting attributes
1495 { rtfCharAttr, rtfPlain, "plain", 0 },
1496 { rtfCharAttr, rtfBold, "b", 0 },
1497 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1498 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1499 { rtfCharAttr, rtfSubScript, "dn", 0 },
1500 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1501 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1502 { rtfCharAttr, rtfExpand, "expnd", 0 },
1503 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1504 { rtfCharAttr, rtfKerning, "kerning", 0 },
1505 { rtfCharAttr, rtfFontNum, "f", 0 },
1506 { rtfCharAttr, rtfFontSize, "fs", 0 },
1507 { rtfCharAttr, rtfItalic, "i", 0 },
1508 { rtfCharAttr, rtfOutline, "outl", 0 },
1509 { rtfCharAttr, rtfRevised, "revised", 0 },
1510 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1511 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1512 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1513 { rtfCharAttr, rtfShadow, "shad", 0 },
1514 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1515 { rtfCharAttr, rtfUnderline, "ul", 0 },
1516 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1517 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1518 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1519 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1520 { rtfCharAttr, rtfSuperScript, "up", 0 },
1521 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1522 { rtfCharAttr, rtfInvisible, "v", 0 },
1523 { rtfCharAttr, rtfForeColor, "cf", 0 },
1524 { rtfCharAttr, rtfBackColor, "cb", 0 },
1525 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1526 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1527 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1528 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1529 { rtfCharAttr, rtfLanguage, "lang", 0 },
1530 /* this has disappeared from spec 1.2 */
1531 { rtfCharAttr, rtfGray, "gray", 0 },
1532 { rtfCharAttr, rtfUnicodeLength, "uc", 0 },
1535 * Paragraph formatting attributes
1538 { rtfParAttr, rtfParDef, "pard", 0 },
1539 { rtfParAttr, rtfStyleNum, "s", 0 },
1540 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1541 { rtfParAttr, rtfInTable, "intbl", 0 },
1542 { rtfParAttr, rtfKeep, "keep", 0 },
1543 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1544 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1545 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1546 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1547 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1548 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1549 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1550 { rtfParAttr, rtfQuadRight, "qr", 0 },
1551 { rtfParAttr, rtfQuadJust, "qj", 0 },
1552 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1553 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1554 { rtfParAttr, rtfLeftIndent, "li", 0 },
1555 { rtfParAttr, rtfRightIndent, "ri", 0 },
1556 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1557 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1558 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1559 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1561 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1563 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1564 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1566 { rtfParAttr, rtfTabPos, "tx", 0 },
1568 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1569 * although it's not in the spec. It's also redundant, since lj
1570 * tabs are the default.
1572 { rtfParAttr, rtfTabLeft, "tql", 0 },
1573 { rtfParAttr, rtfTabRight, "tqr", 0 },
1574 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1575 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1576 { rtfParAttr, rtfTabBar, "tb", 0 },
1577 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1578 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1579 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1580 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1581 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1583 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1584 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1585 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1586 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1587 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1588 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1589 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1590 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1591 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1592 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1593 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1594 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1595 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1596 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1597 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1598 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1599 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1600 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1601 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1602 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1603 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1604 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1605 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1606 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1607 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1608 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1609 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1610 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1611 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1612 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1613 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1614 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1615 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1616 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1617 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1618 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1620 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1621 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1622 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1623 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1624 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1625 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1626 { rtfParAttr, rtfBorderBox, "box", 0 },
1627 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1628 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1629 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1630 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1631 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1632 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1633 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1634 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1635 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1636 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1638 { rtfParAttr, rtfShading, "shading", 0 },
1639 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1640 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1641 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1642 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1643 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1644 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1645 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1646 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1647 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1648 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1649 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1650 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1651 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1652 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1655 * Section formatting attributes
1658 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1659 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1660 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1661 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1662 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1664 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1665 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1666 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1667 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1668 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1670 { rtfSectAttr, rtfColumns, "cols", 0 },
1671 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1672 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1673 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1674 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1675 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1677 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1678 { rtfSectAttr, rtfLineDist, "linex", 0 },
1679 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1680 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1681 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1682 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1684 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1685 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1686 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1687 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1688 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1689 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1690 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1691 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1692 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1693 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1694 { rtfSectAttr, rtfFooterY, "footery", 0 },
1696 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1697 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1698 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1699 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1700 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1701 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1702 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1703 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1704 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1705 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1706 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1707 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1708 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1709 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1710 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1712 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1713 /* misspelled as "vertal" in specification 1.0 */
1714 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1715 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1716 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
1718 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
1719 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
1721 /* I've seen these in an old spec, but not in real files... */
1722 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1723 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1724 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1725 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1726 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1729 * Document formatting attributes
1732 { rtfDocAttr, rtfDefTab, "deftab", 0 },
1733 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
1734 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
1735 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
1736 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
1737 { rtfDocAttr, rtfLineStart, "linestart", 0 },
1738 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
1739 /* \makeback was given in old version of spec, it's now */
1740 /* listed as \makebackup */
1741 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
1742 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
1743 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
1744 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
1745 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
1746 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
1748 { rtfDocAttr, rtfFENoteType, "fet", 0 },
1749 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
1750 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
1751 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
1752 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
1753 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
1754 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
1755 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
1756 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
1757 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
1758 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
1759 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
1760 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
1761 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
1762 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
1763 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
1764 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
1765 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
1766 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
1767 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
1768 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
1769 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
1770 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
1771 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
1772 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
1773 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
1774 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
1775 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
1777 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
1778 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
1779 { rtfDocAttr, rtfPaperSize, "psz", 0 },
1780 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
1781 { rtfDocAttr, rtfRightMargin, "margr", 0 },
1782 { rtfDocAttr, rtfTopMargin, "margt", 0 },
1783 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
1784 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
1785 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
1786 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
1787 { rtfDocAttr, rtfLandscape, "landscape", 0 },
1788 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
1789 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
1791 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
1793 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
1794 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
1795 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
1796 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
1797 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
1798 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
1799 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
1800 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
1801 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
1802 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
1803 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
1804 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
1806 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
1807 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
1808 { rtfDocAttr, rtfFormShading, "formshade", 0 },
1809 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
1810 { rtfDocAttr, rtfPrintData, "printdata", 0 },
1812 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
1813 { rtfDocAttr, rtfRevisions, "revisions", 0 },
1814 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
1815 { rtfDocAttr, rtfRevBar, "revbar", 0 },
1817 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
1819 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
1820 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
1822 { rtfDocAttr, rtfAnsiCodePage, "ansicpg", 0 },
1823 { rtfDocAttr, rtfUTF8RTF, "urtf", 0 },
1829 { rtfStyleAttr, rtfAdditive, "additive", 0 },
1830 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
1831 { rtfStyleAttr, rtfNext, "snext", 0 },
1834 * Picture attributes
1837 { rtfPictAttr, rtfMacQD, "macpict", 0 },
1838 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
1839 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
1840 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
1841 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
1842 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
1843 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
1844 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
1846 { rtfPictAttr, rtfPicWid, "picw", 0 },
1847 { rtfPictAttr, rtfPicHt, "pich", 0 },
1848 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
1849 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
1850 /* these two aren't in the spec, but some writers emit them */
1851 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
1852 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
1853 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
1854 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
1855 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
1856 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
1857 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
1858 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
1859 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
1861 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
1862 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
1864 { rtfPictAttr, rtfPicBinary, "bin", 0 },
1867 * NeXT graphic attributes
1870 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
1871 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
1877 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
1878 { rtfDestination, rtfFontAltName, "falt", 0 },
1879 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
1880 { rtfDestination, rtfFontFile, "fontfile", 0 },
1881 { rtfDestination, rtfFileTbl, "filetbl", 0 },
1882 { rtfDestination, rtfFileInfo, "file", 0 },
1883 { rtfDestination, rtfColorTbl, "colortbl", 0 },
1884 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
1885 { rtfDestination, rtfKeyCode, "keycode", 0 },
1886 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
1887 { rtfDestination, rtfGenerator, "generator", 0 },
1888 { rtfDestination, rtfInfo, "info", 0 },
1889 { rtfDestination, rtfITitle, "title", 0 },
1890 { rtfDestination, rtfISubject, "subject", 0 },
1891 { rtfDestination, rtfIAuthor, "author", 0 },
1892 { rtfDestination, rtfIOperator, "operator", 0 },
1893 { rtfDestination, rtfIKeywords, "keywords", 0 },
1894 { rtfDestination, rtfIComment, "comment", 0 },
1895 { rtfDestination, rtfIVersion, "version", 0 },
1896 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
1897 /* \verscomm may not exist -- was seen in earlier spec version */
1898 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
1899 { rtfDestination, rtfNextFile, "nextfile", 0 },
1900 { rtfDestination, rtfTemplate, "template", 0 },
1901 { rtfDestination, rtfFNSep, "ftnsep", 0 },
1902 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
1903 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
1904 { rtfDestination, rtfENSep, "aftnsep", 0 },
1905 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
1906 { rtfDestination, rtfENContNotice, "aftncn", 0 },
1907 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
1908 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
1909 { rtfDestination, rtfHeader, "header", 0 },
1910 { rtfDestination, rtfFooter, "footer", 0 },
1911 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
1912 { rtfDestination, rtfHeaderRight, "headerr", 0 },
1913 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
1914 { rtfDestination, rtfFooterLeft, "footerl", 0 },
1915 { rtfDestination, rtfFooterRight, "footerr", 0 },
1916 { rtfDestination, rtfFooterFirst, "footerf", 0 },
1917 { rtfDestination, rtfParNumText, "pntext", 0 },
1918 { rtfDestination, rtfParNumbering, "pn", 0 },
1919 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
1920 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
1921 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
1922 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
1923 { rtfDestination, rtfPict, "pict", 0 },
1924 { rtfDestination, rtfObject, "object", 0 },
1925 { rtfDestination, rtfObjClass, "objclass", 0 },
1926 { rtfDestination, rtfObjName, "objname", 0 },
1927 { rtfObjAttr, rtfObjTime, "objtime", 0 },
1928 { rtfDestination, rtfObjData, "objdata", 0 },
1929 { rtfDestination, rtfObjAlias, "objalias", 0 },
1930 { rtfDestination, rtfObjSection, "objsect", 0 },
1931 /* objitem and objtopic aren't documented in the spec! */
1932 { rtfDestination, rtfObjItem, "objitem", 0 },
1933 { rtfDestination, rtfObjTopic, "objtopic", 0 },
1934 { rtfDestination, rtfObjResult, "result", 0 },
1935 { rtfDestination, rtfDrawObject, "do", 0 },
1936 { rtfDestination, rtfFootnote, "footnote", 0 },
1937 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
1938 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
1939 { rtfDestination, rtfAnnotID, "atnid", 0 },
1940 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
1941 { rtfDestination, rtfAnnotation, "annotation", 0 },
1942 { rtfDestination, rtfAnnotRef, "atnref", 0 },
1943 { rtfDestination, rtfAnnotTime, "atntime", 0 },
1944 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
1945 { rtfDestination, rtfField, "field", 0 },
1946 { rtfDestination, rtfFieldInst, "fldinst", 0 },
1947 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
1948 { rtfDestination, rtfDataField, "datafield", 0 },
1949 { rtfDestination, rtfIndex, "xe", 0 },
1950 { rtfDestination, rtfIndexText, "txe", 0 },
1951 { rtfDestination, rtfIndexRange, "rxe", 0 },
1952 { rtfDestination, rtfTOC, "tc", 0 },
1953 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
1959 { rtfFontFamily, rtfFFNil, "fnil", 0 },
1960 { rtfFontFamily, rtfFFRoman, "froman", 0 },
1961 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
1962 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
1963 { rtfFontFamily, rtfFFScript, "fscript", 0 },
1964 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
1965 { rtfFontFamily, rtfFFTech, "ftech", 0 },
1966 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
1972 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
1973 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
1974 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
1975 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
1976 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
1979 * File table attributes
1982 { rtfFileAttr, rtfFileNum, "fid", 0 },
1983 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
1984 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
1990 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
1991 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
1992 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
1993 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
1994 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
2000 { rtfColorName, rtfRed, "red", 0 },
2001 { rtfColorName, rtfGreen, "green", 0 },
2002 { rtfColorName, rtfBlue, "blue", 0 },
2008 { rtfCharSet, rtfMacCharSet, "mac", 0 },
2009 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
2010 { rtfCharSet, rtfPcCharSet, "pc", 0 },
2011 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
2017 { rtfTblAttr, rtfRowDef, "trowd", 0 },
2018 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
2019 { rtfTblAttr, rtfCellPos, "cellx", 0 },
2020 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
2021 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
2023 { rtfTblAttr, rtfRowLeft, "trql", 0 },
2024 { rtfTblAttr, rtfRowRight, "trqr", 0 },
2025 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
2026 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
2027 { rtfTblAttr, rtfRowHt, "trrh", 0 },
2028 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
2029 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
2031 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
2032 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
2034 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
2035 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
2036 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
2037 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
2038 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
2039 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
2041 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
2042 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
2043 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
2044 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
2046 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
2047 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
2048 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
2049 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
2050 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
2051 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
2052 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
2054 * The spec lists "clbgdkhor", but the corresponding non-cell
2055 * control is "bgdkhoriz". At any rate Macintosh Word seems
2056 * to accept both "clbgdkhor" and "clbgdkhoriz".
2058 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
2059 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
2060 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
2061 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
2062 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
2063 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
2064 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
2065 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
2066 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
2072 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
2073 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
2074 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
2075 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
2076 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
2079 * Positioning attributes
2082 { rtfPosAttr, rtfAbsWid, "absw", 0 },
2083 { rtfPosAttr, rtfAbsHt, "absh", 0 },
2085 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
2086 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
2087 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
2088 { rtfPosAttr, rtfPosX, "posx", 0 },
2089 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
2090 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
2091 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
2092 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
2093 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
2094 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
2096 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
2097 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
2098 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
2099 { rtfPosAttr, rtfPosY, "posy", 0 },
2100 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
2101 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
2102 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
2103 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
2104 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
2106 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
2107 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
2108 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
2109 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
2110 /* \dyfrtext no longer exists in spec 1.2, apparently */
2111 /* replaced by \dfrmtextx and \dfrmtexty. */
2112 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
2114 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
2115 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
2121 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
2122 { rtfObjAttr, rtfObjLink, "objlink", 0 },
2123 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
2124 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
2125 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
2126 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
2128 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
2129 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
2130 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
2132 { rtfObjAttr, rtfObjHt, "objh", 0 },
2133 { rtfObjAttr, rtfObjWid, "objw", 0 },
2134 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
2135 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
2136 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
2137 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
2138 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
2139 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
2140 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
2141 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
2142 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2144 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2145 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2146 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2147 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2148 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2150 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2151 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2154 * Associated character formatting attributes
2157 { rtfACharAttr, rtfACBold, "ab", 0 },
2158 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2159 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2160 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2161 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2162 { rtfACharAttr, rtfACFontNum, "af", 0 },
2163 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2164 { rtfACharAttr, rtfACItalic, "ai", 0 },
2165 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2166 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2167 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2168 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2169 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2170 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2171 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2172 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2173 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2174 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2175 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2178 * Footnote attributes
2181 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2184 * Key code attributes
2187 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2188 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2189 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2190 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2193 * Bookmark attributes
2196 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2197 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2200 * Index entry attributes
2203 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2204 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2205 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2208 * Table of contents attributes
2211 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2212 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2215 * Drawing object attributes
2218 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2219 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2220 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2221 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2222 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2223 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2224 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2225 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2227 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2228 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2229 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2230 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2231 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2232 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2233 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2234 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2235 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2236 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2237 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2239 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2240 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2241 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2242 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2244 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2245 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2246 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2247 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2248 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2249 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2250 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2251 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2252 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2253 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2254 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2255 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2256 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2257 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2258 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2259 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2260 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2262 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2263 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2264 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2266 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2267 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2268 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2270 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2271 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2273 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2274 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2275 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2276 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2277 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2278 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2279 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2280 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2281 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2282 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2283 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2284 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2286 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2287 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2288 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2289 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2290 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2291 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2292 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2293 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2295 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2296 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2297 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2298 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2299 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2300 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2301 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2302 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2303 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2304 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2305 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2307 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2308 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2309 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2311 { rtfVersion, -1, "rtf", 0 },
2312 { rtfDefFont, -1, "deff", 0 },
2314 { 0, -1, (char *) NULL, 0 }
2316 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2318 typedef struct tagRTFHashTableEntry {
2321 } RTFHashTableEntry;
2323 static RTFHashTableEntry rtfHashTable[RTF_KEY_COUNT * 2];
2327 * Initialize lookup table hash values. Only need to do this once.
2330 static void LookupInit(void)
2332 static int inited = 0;
2337 memset(rtfHashTable, 0, RTF_KEY_COUNT * 2 * sizeof(*rtfHashTable));
2338 for (rp = rtfKey; rp->rtfKStr != NULL; rp++) {
2341 rp->rtfKHash = Hash ((char*)rp->rtfKStr);
2342 index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
2343 if (!rtfHashTable[index].count)
2344 rtfHashTable[index].value = RTFAlloc(sizeof(RTFKey *));
2346 rtfHashTable[index].value = RTFReAlloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
2347 rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
2355 * Determine major and minor number of control token. If it's
2356 * not found, the class turns into rtfUnknown.
2359 static void Lookup(RTF_Info *info, char *s)
2363 RTFHashTableEntry *entry;
2367 ++s; /* skip over the leading \ character */
2369 entry = &rtfHashTable[hash % (RTF_KEY_COUNT * 2)];
2370 for (i = 0; i < entry->count; i++)
2372 rp = entry->value[i];
2373 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2375 info->rtfClass = rtfControl;
2376 info->rtfMajor = rp->rtfKMajor;
2377 info->rtfMinor = rp->rtfKMinor;
2381 info->rtfClass = rtfUnknown;
2386 * Compute hash value of symbol
2389 static int Hash(char *s)
2394 while ((c = *s++) != '\0')
2401 /* ---------------------------------------------------------------------- */
2405 * Token comparison routines
2408 int RTFCheckCM(RTF_Info *info, int class, int major)
2410 return (info->rtfClass == class && info->rtfMajor == major);
2414 int RTFCheckCMM(RTF_Info *info, int class, int major, int minor)
2416 return (info->rtfClass == class && info->rtfMajor == major && info->rtfMinor == minor);
2420 int RTFCheckMM(RTF_Info *info, int major, int minor)
2422 return (info->rtfMajor == major && info->rtfMinor == minor);
2426 /* ---------------------------------------------------------------------- */
2429 int RTFCharToHex(char c)
2434 return (c - '0'); /* '0'..'9' */
2435 return (c - 'a' + 10); /* 'a'..'f' */
2439 int RTFHexToChar(int i)
2443 return (i - 10 + 'a');
2447 /* ---------------------------------------------------------------------- */
2450 * originally from RTF tools' text-writer.c
2452 * text-writer -- RTF-to-text translation writer code.
2454 * Read RTF input, write text of document (text extraction).
2457 static void TextClass (RTF_Info *info);
2458 static void ControlClass (RTF_Info *info);
2459 static void DefFont(RTF_Info *info);
2460 static void Destination (RTF_Info *info);
2461 static void SpecialChar (RTF_Info *info);
2462 static void RTFPutUnicodeChar (RTF_Info *info, int c);
2465 * Initialize the writer.
2469 WriterInit (RTF_Info *info )
2475 BeginFile (RTF_Info *info )
2477 /* install class callbacks */
2479 RTFSetClassCallback (info, rtfText, TextClass);
2480 RTFSetClassCallback (info, rtfControl, ControlClass);
2486 * Write out a character.
2490 TextClass (RTF_Info *info)
2492 RTFPutCodePageChar(info, info->rtfMajor);
2497 ControlClass (RTF_Info *info)
2501 switch (info->rtfMajor)
2512 case rtfDestination:
2518 case rtfSpecialChar:
2526 CharAttr(RTF_Info *info)
2530 switch (info->rtfMinor)
2533 font = RTFGetFont(info, info->rtfParam);
2536 if (info->ansiCodePage != CP_UTF8)
2537 info->codePage = font->rtfFCodePage;
2538 TRACE("font %d codepage %d\n", info->rtfParam, info->codePage);
2541 ERR( "unknown font %d\n", info->rtfParam);
2543 case rtfUnicodeLength:
2544 info->unicodeLength = info->rtfParam;
2551 CharSet(RTF_Info *info)
2553 if (info->ansiCodePage == CP_UTF8)
2556 switch (info->rtfMinor)
2558 case rtfAnsiCharSet:
2559 info->ansiCodePage = 1252; /* Latin-1 */
2562 info->ansiCodePage = 10000; /* MacRoman */
2565 info->ansiCodePage = 437;
2568 info->ansiCodePage = 850;
2574 * This function notices destinations that aren't explicitly handled
2575 * and skips to their ends. This keeps, for instance, picture
2576 * data from being considered as plain text.
2580 Destination (RTF_Info *info)
2583 if (!RTFGetDestinationCallback(info, info->rtfMinor))
2584 RTFSkipGroup (info);
2589 DefFont(RTF_Info *info)
2591 TRACE("%d\n", info->rtfParam);
2592 info->defFont = info->rtfParam;
2597 DocAttr(RTF_Info *info)
2599 TRACE("minor %d, param %d\n", info->rtfMinor, info->rtfParam);
2601 switch (info->rtfMinor)
2603 case rtfAnsiCodePage:
2604 info->codePage = info->ansiCodePage = info->rtfParam;
2607 info->codePage = info->ansiCodePage = CP_UTF8;
2613 static void SpecialChar (RTF_Info *info)
2618 switch (info->rtfMinor)
2621 /* the next token determines destination, if it's unknown, skip the group */
2622 /* this way we filter out the garbage coming from unknown destinations */
2624 if (info->rtfClass != rtfDestination)
2627 RTFRouteToken(info); /* "\*" is ignored with known destinations */
2633 RTFPutUnicodeChar(info, info->rtfParam);
2635 /* After \u we must skip number of character tokens set by \ucN */
2636 for (i = 0; i < info->unicodeLength; i++)
2639 if (info->rtfClass != rtfText)
2641 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2642 info->rtfClass, info->rtfMajor, info->rtfMinor);
2643 RTFUngetToken(info);
2654 RTFPutUnicodeChar (info, '\n');
2657 RTFPutUnicodeChar (info, 0x00A0);
2660 RTFPutUnicodeChar (info, '\t');
2662 case rtfNoBrkHyphen:
2663 RTFPutUnicodeChar (info, 0x2011);
2666 RTFPutUnicodeChar (info, 0x2022);
2669 RTFPutUnicodeChar (info, 0x2014);
2672 RTFPutUnicodeChar (info, 0x2013);
2675 RTFPutUnicodeChar (info, 0x2018);
2678 RTFPutUnicodeChar (info, 0x2019);
2681 RTFPutUnicodeChar (info, 0x201C);
2684 RTFPutUnicodeChar (info, 0x201D);
2691 RTFFlushUnicodeOutputBuffer(RTF_Info *info)
2693 if (info->dwOutputCount)
2695 ME_InsertTextFromCursor(info->editor, 0, info->OutputBuffer,
2696 info->dwOutputCount, info->style);
2697 info->dwOutputCount = 0;
2702 RTFPutUnicodeString(RTF_Info *info, WCHAR *string, int length)
2704 if (info->dwCPOutputCount)
2705 RTFFlushCPOutputBuffer(info);
2708 int fit = min(length, sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount);
2710 memmove(info->OutputBuffer + info->dwOutputCount, string, fit * sizeof(WCHAR));
2711 info->dwOutputCount += fit;
2712 if (fit == sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount)
2713 RTFFlushUnicodeOutputBuffer(info);
2720 RTFFlushCPOutputBuffer(RTF_Info *info)
2722 int bufferMax = info->dwCPOutputCount * 2 * sizeof(WCHAR);
2723 WCHAR *buffer = (WCHAR *)RTFAlloc(bufferMax);
2726 length = MultiByteToWideChar(info->codePage, 0, info->cpOutputBuffer,
2727 info->dwCPOutputCount, buffer, bufferMax/sizeof(WCHAR));
2728 info->dwCPOutputCount = 0;
2730 RTFPutUnicodeString(info, buffer, length);
2731 RTFFree((char *)buffer);
2735 RTFFlushOutputBuffer(RTF_Info *info)
2737 if (info->dwCPOutputCount)
2738 RTFFlushCPOutputBuffer(info);
2739 RTFFlushUnicodeOutputBuffer(info);
2743 RTFPutUnicodeChar(RTF_Info *info, int c)
2745 if (info->dwCPOutputCount)
2746 RTFFlushCPOutputBuffer(info);
2747 if (info->dwOutputCount * sizeof(WCHAR) >= ( sizeof info->OutputBuffer - 1 ) )
2748 RTFFlushUnicodeOutputBuffer( info );
2749 info->OutputBuffer[info->dwOutputCount++] = c;
2753 RTFPutCodePageChar(RTF_Info *info, int c)
2755 /* Use dynamic buffer here because it's the best way to handle
2756 * MBCS codepages without having to worry about partial chars */
2757 if (info->dwCPOutputCount >= info->dwMaxCPOutputCount)
2759 info->dwMaxCPOutputCount *= 2;
2760 info->cpOutputBuffer = RTFReAlloc(info->cpOutputBuffer, info->dwMaxCPOutputCount);
2762 info->cpOutputBuffer[info->dwCPOutputCount++] = c;