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