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