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