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