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