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