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