4 * Portions Copyright 2004 Mike McCormack for CodeWeavers
5 * Portions Copyright 2006 by Phil Krylov
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.
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.
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
23 * Derived from RTF Tools by Paul DuBois (dubois@primate.wisc.edu)
24 * Homepage: http://www.snake.net/software/RTF/
25 * Original license follows:
29 * reader.c - RTF file reader. Release 1.10.
33 * Author: Paul DuBois dubois@primate.wisc.edu
35 * This software may be redistributed without restriction and used for
36 * any purpose whatsoever.
48 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
55 static int _RTFGetChar(RTF_Info
*);
56 static void _RTFGetToken (RTF_Info
*);
57 static void _RTFGetToken2 (RTF_Info
*);
58 static int GetChar (RTF_Info
*);
59 static void ReadFontTbl (RTF_Info
*);
60 static void ReadColorTbl (RTF_Info
*);
61 static void ReadStyleSheet (RTF_Info
*);
62 static void ReadInfoGroup (RTF_Info
*);
63 static void ReadPictGroup (RTF_Info
*);
64 static void ReadObjGroup (RTF_Info
*);
65 static void Lookup (RTF_Info
*, char *);
66 static int Hash (const char *);
68 static void CharAttr(RTF_Info
*info
);
69 static void CharSet(RTF_Info
*info
);
70 static void DocAttr(RTF_Info
*info
);
72 static void RTFFlushCPOutputBuffer(RTF_Info
*info
);
73 static void RTFPutCodePageChar(RTF_Info
*info
, int c
);
75 /* ---------------------------------------------------------------------- */
79 * Saves a string on the heap and returns a pointer to it.
81 static inline char *RTFStrSave(const char *s
)
85 p
= heap_alloc (lstrlenA(s
) + 1);
88 return lstrcpyA (p
, s
);
92 /* ---------------------------------------------------------------------- */
95 int _RTFGetChar(RTF_Info
*info
)
98 ME_InStream
*stream
= info
->stream
;
100 if (stream
->dwSize
<= stream
->dwUsed
)
102 ME_StreamInFill(stream
);
103 /* if error, it's EOF */
104 if (stream
->editstream
->dwError
)
106 /* if no bytes read, it's EOF */
107 if (stream
->dwSize
== 0)
110 ch
= (unsigned char)stream
->buffer
[stream
->dwUsed
++];
116 void RTFSetEditStream(RTF_Info
*info
, ME_InStream
*stream
)
118 info
->stream
= stream
;
122 RTFDestroyAttrs(RTF_Info
*info
)
127 RTFStyleElt
*eltList
, *ep
;
129 while (info
->fontList
)
131 fp
= info
->fontList
->rtfNextFont
;
132 heap_free (info
->fontList
->rtfFName
);
133 heap_free (info
->fontList
);
136 while (info
->colorList
)
138 cp
= info
->colorList
->rtfNextColor
;
139 heap_free (info
->colorList
);
140 info
->colorList
= cp
;
142 while (info
->styleList
)
144 sp
= info
->styleList
->rtfNextStyle
;
145 eltList
= info
->styleList
->rtfSSEList
;
148 ep
= eltList
->rtfNextSE
;
149 heap_free (eltList
->rtfSEText
);
153 heap_free (info
->styleList
->rtfSName
);
154 heap_free (info
->styleList
);
155 info
->styleList
= sp
;
161 RTFDestroy(RTF_Info
*info
)
163 if (info
->rtfTextBuf
)
165 heap_free(info
->rtfTextBuf
);
166 heap_free(info
->pushedTextBuf
);
168 RTFDestroyAttrs(info
);
169 heap_free(info
->cpOutputBuffer
);
170 while (info
->tableDef
)
172 RTFTable
*tableDef
= info
->tableDef
;
173 info
->tableDef
= tableDef
->parent
;
180 /* ---------------------------------------------------------------------- */
183 * Callback table manipulation routines
188 * Install or return a writer callback for a token class
191 static void RTFSetClassCallback(RTF_Info
*info
, int class, RTFFuncPtr callback
)
193 if (class >= 0 && class < rtfMaxClass
)
194 info
->ccb
[class] = callback
;
198 static RTFFuncPtr
RTFGetClassCallback(const RTF_Info
*info
, int class)
200 if (class >= 0 && class < rtfMaxClass
)
201 return info
->ccb
[class];
207 * Initialize the reader. This may be called multiple times,
208 * to read multiple files. The only thing not reset is the input
209 * stream; that must be done with RTFSetStream().
212 void RTFInit(RTF_Info
*info
)
216 if (info
->rtfTextBuf
== NULL
) /* initialize the text buffers */
218 info
->rtfTextBuf
= heap_alloc (rtfBufSiz
);
219 info
->pushedTextBuf
= heap_alloc (rtfBufSiz
);
220 if (info
->rtfTextBuf
== NULL
|| info
->pushedTextBuf
== NULL
) {
221 ERR ("Cannot allocate text buffers.\n");
224 info
->rtfTextBuf
[0] = info
->pushedTextBuf
[0] = '\0';
227 for (i
= 0; i
< rtfMaxClass
; i
++)
228 RTFSetClassCallback (info
, i
, NULL
);
229 for (i
= 0; i
< rtfMaxDestination
; i
++)
230 RTFSetDestinationCallback (info
, i
, NULL
);
232 /* install built-in destination readers */
233 RTFSetDestinationCallback (info
, rtfFontTbl
, ReadFontTbl
);
234 RTFSetDestinationCallback (info
, rtfColorTbl
, ReadColorTbl
);
235 RTFSetDestinationCallback (info
, rtfStyleSheet
, ReadStyleSheet
);
236 RTFSetDestinationCallback (info
, rtfInfo
, ReadInfoGroup
);
237 RTFSetDestinationCallback (info
, rtfPict
, ReadPictGroup
);
238 RTFSetDestinationCallback (info
, rtfObject
, ReadObjGroup
);
241 RTFSetReadHook (info
, NULL
);
243 /* dump old lists if necessary */
245 RTFDestroyAttrs(info
);
247 info
->ansiCodePage
= 1252; /* Latin-1; actually unused */
248 info
->unicodeLength
= 1; /* \uc1 is the default */
249 info
->codePage
= info
->ansiCodePage
;
253 info
->pushedClass
= -1;
254 info
->pushedChar
= EOF
;
256 info
->rtfLineNum
= 0;
257 info
->rtfLinePos
= 0;
258 info
->prevChar
= EOF
;
259 info
->bumpLine
= FALSE
;
261 info
->dwCPOutputCount
= 0;
262 if (!info
->cpOutputBuffer
)
264 info
->dwMaxCPOutputCount
= 0x1000;
265 info
->cpOutputBuffer
= heap_alloc(info
->dwMaxCPOutputCount
);
268 info
->tableDef
= NULL
;
269 info
->nestingLevel
= 0;
270 info
->canInheritInTbl
= FALSE
;
271 info
->borderType
= 0;
275 * Install or return a writer callback for a destination type
278 void RTFSetDestinationCallback(RTF_Info
*info
, int dest
, RTFFuncPtr callback
)
280 if (dest
>= 0 && dest
< rtfMaxDestination
)
281 info
->dcb
[dest
] = callback
;
285 static RTFFuncPtr
RTFGetDestinationCallback(const RTF_Info
*info
, int dest
)
287 if (dest
>= 0 && dest
< rtfMaxDestination
)
288 return info
->dcb
[dest
];
293 /* ---------------------------------------------------------------------- */
296 * Token reading routines
301 * Read the input stream, invoking the writer's callbacks
305 void RTFRead(RTF_Info
*info
)
307 while (RTFGetToken (info
) != rtfEOF
)
308 RTFRouteToken (info
);
313 * Route a token. If it's a destination for which a reader is
314 * installed, process the destination internally, otherwise
315 * pass the token to the writer's class callback.
318 void RTFRouteToken(RTF_Info
*info
)
322 if (info
->rtfClass
< 0 || info
->rtfClass
>= rtfMaxClass
) /* watchdog */
324 ERR( "Unknown class %d: %s (reader malfunction)\n",
325 info
->rtfClass
, info
->rtfTextBuf
);
327 if (RTFCheckCM (info
, rtfControl
, rtfDestination
))
329 /* invoke destination-specific callback if there is one */
330 p
= RTFGetDestinationCallback (info
, info
->rtfMinor
);
337 /* invoke class callback if there is one */
338 p
= RTFGetClassCallback (info
, info
->rtfClass
);
345 * Skip to the end of the current group. When this returns,
346 * writers that maintain a state stack may want to call their
347 * state unstacker; global vars will still be set to the group's
351 void RTFSkipGroup(RTF_Info
*info
)
355 while (RTFGetToken (info
) != rtfEOF
)
357 if (info
->rtfClass
== rtfGroup
)
359 if (info
->rtfMajor
== rtfBeginGroup
)
361 else if (info
->rtfMajor
== rtfEndGroup
)
364 break; /* end of initial group */
371 * Do no special processing on the group.
373 * This acts as a placeholder for a callback in order to indicate that it
374 * shouldn't be ignored. Instead it will fallback on the loop in RTFRead.
376 void RTFReadGroup (RTF_Info
*info
)
382 * Install or return a token reader hook.
385 void RTFSetReadHook(RTF_Info
*info
, RTFFuncPtr f
)
391 static RTFFuncPtr
RTFGetReadHook(const RTF_Info
*info
)
393 return (info
->readHook
);
398 * Read one token. Call the read hook if there is one. The
399 * token class is the return value. Returns rtfEOF when there
400 * are no more tokens.
403 int RTFGetToken(RTF_Info
*info
)
407 /* don't try to return anything once EOF is reached */
408 if (info
->rtfClass
== rtfEOF
) {
415 p
= RTFGetReadHook (info
);
417 (*p
) (info
); /* give read hook a look at token */
419 /* Silently discard newlines, carriage returns, nulls. */
420 if (!(info
->rtfClass
== rtfText
&& info
->rtfFormat
!= SF_TEXT
421 && (info
->rtfMajor
== '\r' || info
->rtfMajor
== '\n' || info
->rtfMajor
== '\0')))
424 return (info
->rtfClass
);
428 static void RTFUngetToken(RTF_Info
*info
)
430 if (info
->pushedClass
>= 0) /* there's already an ungotten token */
431 ERR ("cannot unget two tokens\n");
432 if (info
->rtfClass
< 0)
433 ERR ("no token to unget\n");
434 info
->pushedClass
= info
->rtfClass
;
435 info
->pushedMajor
= info
->rtfMajor
;
436 info
->pushedMinor
= info
->rtfMinor
;
437 info
->pushedParam
= info
->rtfParam
;
438 lstrcpyA (info
->pushedTextBuf
, info
->rtfTextBuf
);
439 /* The read hook decrements stackTop on rtfEndGroup, so
440 * increment the value to compensate for it being decremented
441 * twice due to the RTFUngetToken. */
442 if(RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
444 info
->stack
[info
->stackTop
].style
= info
->style
;
445 ME_AddRefStyle(info
->style
);
451 static void _RTFGetToken(RTF_Info
*info
)
453 if (info
->rtfFormat
== SF_TEXT
)
455 info
->rtfMajor
= GetChar (info
);
457 info
->rtfParam
= rtfNoParam
;
458 info
->rtfTextBuf
[info
->rtfTextLen
= 0] = '\0';
459 if (info
->rtfMajor
== EOF
)
460 info
->rtfClass
= rtfEOF
;
462 info
->rtfClass
= rtfText
;
466 /* first check for pushed token from RTFUngetToken() */
468 if (info
->pushedClass
>= 0)
470 info
->rtfClass
= info
->pushedClass
;
471 info
->rtfMajor
= info
->pushedMajor
;
472 info
->rtfMinor
= info
->pushedMinor
;
473 info
->rtfParam
= info
->pushedParam
;
474 lstrcpyA (info
->rtfTextBuf
, info
->pushedTextBuf
);
475 info
->rtfTextLen
= lstrlenA(info
->rtfTextBuf
);
476 info
->pushedClass
= -1;
481 * Beyond this point, no token is ever seen twice, which is
482 * important, e.g., for making sure no "}" pops the font stack twice.
485 _RTFGetToken2 (info
);
490 RTFCharSetToCodePage(RTF_Info
*info
, int charset
)
496 case DEFAULT_CHARSET
:
502 case SHIFTJIS_CHARSET
:
504 case HANGEUL_CHARSET
:
510 case CHINESEBIG5_CHARSET
:
514 case TURKISH_CHARSET
:
516 case VIETNAMESE_CHARSET
:
524 case RUSSIAN_CHARSET
:
528 case EASTEUROPE_CHARSET
:
537 /* FIXME: TranslateCharsetInfo does not work as good as it
538 * should, so let's use it only when all else fails */
539 if (!TranslateCharsetInfo(&n
, &csi
, TCI_SRCCHARSET
))
540 ERR("unknown charset %d\n", charset
);
549 /* this shouldn't be called anywhere but from _RTFGetToken() */
551 static void _RTFGetToken2(RTF_Info
*info
)
556 /* initialize token vars */
558 info
->rtfClass
= rtfUnknown
;
559 info
->rtfParam
= rtfNoParam
;
560 info
->rtfTextBuf
[info
->rtfTextLen
= 0] = '\0';
562 /* get first character, which may be a pushback from previous token */
564 if (info
->pushedChar
!= EOF
)
566 c
= info
->pushedChar
;
567 info
->rtfTextBuf
[info
->rtfTextLen
++] = c
;
568 info
->rtfTextBuf
[info
->rtfTextLen
] = '\0';
569 info
->pushedChar
= EOF
;
571 else if ((c
= GetChar (info
)) == EOF
)
573 info
->rtfClass
= rtfEOF
;
579 info
->rtfClass
= rtfGroup
;
580 info
->rtfMajor
= rtfBeginGroup
;
585 info
->rtfClass
= rtfGroup
;
586 info
->rtfMajor
= rtfEndGroup
;
592 * Two possibilities here:
593 * 1) ASCII 9, effectively like \tab control symbol
594 * 2) literal text char
596 if (c
== '\t') /* ASCII 9 */
598 info
->rtfClass
= rtfControl
;
599 info
->rtfMajor
= rtfSpecialChar
;
600 info
->rtfMinor
= rtfTab
;
604 info
->rtfClass
= rtfText
;
609 if ((c
= GetChar (info
)) == EOF
)
611 /* early eof, whoops (class is rtfUnknown) */
617 * Three possibilities here:
618 * 1) hex encoded text char, e.g., \'d5, \'d3
619 * 2) special escaped text char, e.g., \{, \}
620 * 3) control symbol, e.g., \_, \-, \|, \<10>
622 if (c
== '\'') /* hex char */
626 if ((c
= GetChar (info
)) != EOF
&& (c2
= GetChar (info
)) != EOF
627 && isxdigit(c
) && isxdigit(c2
))
629 info
->rtfClass
= rtfText
;
630 info
->rtfMajor
= RTFCharToHex (c
) * 16 + RTFCharToHex (c2
);
633 /* early eof, whoops */
634 info
->rtfClass
= rtfEOF
;
635 info
->stream
->editstream
->dwError
= -14;
640 /*if (index (":{}\\", c) != NULL)*/ /* escaped char */
641 if (c
== ':' || c
== '{' || c
== '}' || c
== '\\')
643 info
->rtfClass
= rtfText
;
649 Lookup (info
, info
->rtfTextBuf
); /* sets class, major, minor */
655 if ((c
= GetChar (info
)) == EOF
)
660 * At this point, the control word is all collected, so the
661 * major/minor numbers are determined before the parameter
662 * (if any) is scanned. There will be one too many characters
663 * in the buffer, though, so fix up before and restore after
668 info
->rtfTextBuf
[info
->rtfTextLen
-1] = '\0';
669 Lookup (info
, info
->rtfTextBuf
); /* sets class, major, minor */
671 info
->rtfTextBuf
[info
->rtfTextLen
-1] = c
;
674 * Should be looking at first digit of parameter if there
675 * is one, unless it's negative. In that case, next char
676 * is '-', so need to gobble next char, and remember sign.
685 if (c
!= EOF
&& isdigit (c
))
688 while (isdigit (c
)) /* gobble parameter */
690 info
->rtfParam
= info
->rtfParam
* 10 + c
- '0';
691 if ((c
= GetChar (info
)) == EOF
)
694 info
->rtfParam
*= sign
;
697 * If control symbol delimiter was a blank, gobble it.
698 * Otherwise the character is first char of next token, so
699 * push it back for next call. In either case, delete the
700 * delimiter from the token buffer.
705 info
->pushedChar
= c
;
706 info
->rtfTextBuf
[--info
->rtfTextLen
] = '\0';
712 * Read the next character from the input. This handles setting the
713 * current line and position-within-line variables. Those variables are
714 * set correctly whether lines end with CR, LF, or CRLF (the last being
717 * bumpLine indicates whether the line number should be incremented on
718 * the *next* input character.
722 static int GetChar(RTF_Info
*info
)
727 if ((c
= _RTFGetChar(info
)) != EOF
)
729 info
->rtfTextBuf
[info
->rtfTextLen
++] = c
;
730 info
->rtfTextBuf
[info
->rtfTextLen
] = '\0';
732 if (info
->prevChar
== EOF
)
733 info
->bumpLine
= TRUE
;
734 oldBumpLine
= info
->bumpLine
; /* TRUE if prev char was line ending */
735 info
->bumpLine
= FALSE
;
737 info
->bumpLine
= TRUE
;
740 info
->bumpLine
= TRUE
;
741 if (info
->prevChar
== '\r') /* oops, previous \r wasn't */
742 oldBumpLine
= FALSE
; /* really a line ending */
745 if (oldBumpLine
) /* were we supposed to increment the */
746 { /* line count on this char? */
748 info
->rtfLinePos
= 1;
755 /* ---------------------------------------------------------------------- */
758 * Special destination readers. They gobble the destination so the
759 * writer doesn't have to deal with them. That's wrong for any
760 * translator that wants to process any of these itself. In that
761 * case, these readers should be overridden by installing a different
762 * destination callback.
764 * NOTE: The last token read by each of these reader will be the
765 * destination's terminating '}', which will then be the current token.
766 * That '}' token is passed to RTFRouteToken() - the writer has already
767 * seen the '{' that began the destination group, and may have pushed a
768 * state; it also needs to know at the end of the group that a state
771 * It's important that rtf.h and the control token lookup table list
772 * as many symbols as possible, because these destination readers
773 * unfortunately make strict assumptions about the input they expect,
774 * and a token of class rtfUnknown will throw them off easily.
779 * Read { \fonttbl ... } destination. Old font tables don't have
780 * braces around each table entry; try to adjust for that.
783 static void ReadFontTbl(RTF_Info
*info
)
786 char buf
[rtfBufSiz
], *bp
;
792 if (info
->rtfClass
== rtfEOF
)
794 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
796 if (old
< 0) /* first entry - determine tbl type */
798 if (RTFCheckCMM (info
, rtfControl
, rtfCharAttr
, rtfFontNum
))
799 old
= 1; /* no brace */
800 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
802 else /* can't tell! */
803 ERR ("cannot determine format\n");
805 if (old
== 0) /* need to find "{" here */
807 if (!RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
808 ERR ("missing \"{\"\n");
809 RTFGetToken (info
); /* yes, skip to next token */
810 if (info
->rtfClass
== rtfEOF
)
815 ERR ("cannot allocate font entry\n");
819 fp
->rtfNextFont
= info
->fontList
;
823 fp
->rtfFAltName
= NULL
;
825 fp
->rtfFFamily
= FF_DONTCARE
;
826 fp
->rtfFCharSet
= DEFAULT_CHARSET
; /* 1 */
827 fp
->rtfFPitch
= DEFAULT_PITCH
;
829 fp
->rtfFCodePage
= CP_ACP
;
831 while (info
->rtfClass
!= rtfEOF
832 && !RTFCheckCM (info
, rtfText
, ';')
833 && !RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
835 if (info
->rtfClass
== rtfControl
)
837 switch (info
->rtfMajor
)
840 /* ignore token but announce it */
841 WARN ("unknown token \"%s\"\n",
845 fp
->rtfFFamily
= info
->rtfMinor
;
848 switch (info
->rtfMinor
)
851 break; /* ignore unknown? */
853 fp
->rtfFNum
= info
->rtfParam
;
858 switch (info
->rtfMinor
)
861 break; /* ignore unknown? */
863 fp
->rtfFCharSet
= info
->rtfParam
;
864 if (!fp
->rtfFCodePage
)
865 fp
->rtfFCodePage
= RTFCharSetToCodePage(info
, info
->rtfParam
);
868 fp
->rtfFPitch
= info
->rtfParam
;
870 case rtfFontCodePage
:
871 fp
->rtfFCodePage
= info
->rtfParam
;
874 case rtfFTypeTrueType
:
875 fp
->rtfFType
= info
->rtfParam
;
881 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
)) /* dest */
883 RTFSkipGroup (info
); /* ignore for now */
885 else if (info
->rtfClass
== rtfText
) /* font name */
888 while (info
->rtfClass
== rtfText
889 && !RTFCheckCM (info
, rtfText
, ';'))
891 *bp
++ = info
->rtfMajor
;
895 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
896 if(RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
898 RTFUngetToken (info
);
901 fp
->rtfFName
= RTFStrSave (buf
);
902 if (fp
->rtfFName
== NULL
)
903 ERR ("cannot allocate font name\n");
904 /* already have next token; don't read one */
905 /* at bottom of loop */
910 /* ignore token but announce it */
911 WARN ("unknown token \"%s\"\n", info
->rtfTextBuf
);
914 if (info
->rtfClass
== rtfEOF
)
917 if (info
->rtfClass
== rtfEOF
)
919 if (old
== 0) /* need to see "}" here */
922 if (!RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
923 ERR ("missing \"}\"\n");
924 if (info
->rtfClass
== rtfEOF
)
928 /* Apply the real properties of the default font */
929 if (fp
->rtfFNum
== info
->defFont
)
931 if (info
->ansiCodePage
!= CP_UTF8
)
932 info
->codePage
= fp
->rtfFCodePage
;
933 TRACE("default font codepage %d\n", info
->codePage
);
936 if (!fp
|| (fp
->rtfFNum
== -1))
937 ERR("missing font number\n");
939 * Could check other pieces of structure here, too, I suppose.
941 RTFRouteToken (info
); /* feed "}" back to router */
943 /* Set default font */
944 info
->rtfClass
= rtfControl
;
945 info
->rtfMajor
= rtfCharAttr
;
946 info
->rtfMinor
= rtfFontNum
;
947 info
->rtfParam
= info
->defFont
;
948 lstrcpyA(info
->rtfTextBuf
, "f");
954 * The color table entries have color values of -1 if
955 * the default color should be used for the entry (only
956 * a semi-colon is given in the definition, no color values).
957 * There will be a problem if a partial entry (1 or 2 but
958 * not 3 color values) is given. The possibility is ignored
962 static void ReadColorTbl(RTF_Info
*info
)
971 if (info
->rtfClass
== rtfEOF
)
973 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
980 else if (RTFCheckCM(info
, rtfGroup
, rtfBeginGroup
))
988 ERR ("cannot allocate color entry\n");
991 cp
->rtfCNum
= cnum
++;
992 cp
->rtfNextColor
= info
->colorList
;
993 info
->colorList
= cp
;
994 if (!RTFCheckCM (info
, rtfControl
, rtfColorName
))
995 cp
->rtfCRed
= cp
->rtfCGreen
= cp
->rtfCBlue
= -1;
997 cp
->rtfCRed
= cp
->rtfCGreen
= cp
->rtfCBlue
= 0;
999 switch (info
->rtfMinor
)
1001 case rtfRed
: cp
->rtfCRed
= info
->rtfParam
& 0xFF; break;
1002 case rtfGreen
: cp
->rtfCGreen
= info
->rtfParam
& 0xFF; break;
1003 case rtfBlue
: cp
->rtfCBlue
= info
->rtfParam
& 0xFF; break;
1006 } while (RTFCheckCM (info
, rtfControl
, rtfColorName
));
1008 if (info
->rtfClass
== rtfEOF
)
1010 if (!RTFCheckCM (info
, rtfText
, ';'))
1011 ERR ("malformed entry\n");
1013 RTFRouteToken (info
); /* feed "}" back to router */
1018 * The "Normal" style definition doesn't contain any style number,
1019 * all others do. Normal style is given style rtfNormalStyleNum.
1022 static void ReadStyleSheet(RTF_Info
*info
)
1025 RTFStyleElt
*sep
, *sepLast
;
1026 char buf
[rtfBufSiz
], *bp
;
1032 if (info
->rtfClass
== rtfEOF
)
1034 if (RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
1036 sp
= New (RTFStyle
);
1038 ERR ("cannot allocate stylesheet entry\n");
1041 sp
->rtfSName
= NULL
;
1043 sp
->rtfSType
= rtfParStyle
;
1044 sp
->rtfSAdditive
= 0;
1045 sp
->rtfSBasedOn
= rtfNoStyleNum
;
1046 sp
->rtfSNextPar
= -1;
1047 sp
->rtfSSEList
= sepLast
= NULL
;
1048 sp
->rtfNextStyle
= info
->styleList
;
1049 sp
->rtfExpanding
= 0;
1050 info
->styleList
= sp
;
1051 if (!RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
1052 ERR ("missing \"{\"\n");
1057 if (info
->rtfClass
== rtfEOF
1058 || RTFCheckCM (info
, rtfText
, ';'))
1060 if (info
->rtfClass
== rtfControl
)
1062 if (RTFCheckMM (info
, rtfSpecialChar
, rtfOptDest
)) {
1064 ERR("skipping optional destination\n");
1066 info
->rtfClass
= rtfGroup
;
1067 info
->rtfMajor
= rtfEndGroup
;
1069 break; /* ignore "\*" */
1071 if (RTFCheckMM (info
, rtfParAttr
, rtfStyleNum
))
1073 sp
->rtfSNum
= info
->rtfParam
;
1074 sp
->rtfSType
= rtfParStyle
;
1077 if (RTFCheckMM (info
, rtfCharAttr
, rtfCharStyleNum
))
1079 sp
->rtfSNum
= info
->rtfParam
;
1080 sp
->rtfSType
= rtfCharStyle
;
1083 if (RTFCheckMM (info
, rtfSectAttr
, rtfSectStyleNum
))
1085 sp
->rtfSNum
= info
->rtfParam
;
1086 sp
->rtfSType
= rtfSectStyle
;
1089 if (RTFCheckMM (info
, rtfStyleAttr
, rtfBasedOn
))
1091 sp
->rtfSBasedOn
= info
->rtfParam
;
1094 if (RTFCheckMM (info
, rtfStyleAttr
, rtfAdditive
))
1096 sp
->rtfSAdditive
= 1;
1099 if (RTFCheckMM (info
, rtfStyleAttr
, rtfNext
))
1101 sp
->rtfSNextPar
= info
->rtfParam
;
1104 sep
= New (RTFStyleElt
);
1107 ERR ("cannot allocate style element\n");
1110 sep
->rtfSEClass
= info
->rtfClass
;
1111 sep
->rtfSEMajor
= info
->rtfMajor
;
1112 sep
->rtfSEMinor
= info
->rtfMinor
;
1113 sep
->rtfSEParam
= info
->rtfParam
;
1114 sep
->rtfSEText
= RTFStrSave (info
->rtfTextBuf
);
1115 if (sep
->rtfSEText
== NULL
)
1116 ERR ("cannot allocate style element text\n");
1117 if (sepLast
== NULL
)
1118 sp
->rtfSSEList
= sep
; /* first element */
1119 else /* add to end */
1120 sepLast
->rtfNextSE
= sep
;
1121 sep
->rtfNextSE
= NULL
;
1124 else if (RTFCheckCM (info
, rtfGroup
, rtfBeginGroup
))
1127 * This passes over "{\*\keycode ... }, among
1128 * other things. A temporary (perhaps) hack.
1130 ERR("skipping begin\n");
1131 RTFSkipGroup (info
);
1134 else if (info
->rtfClass
== rtfText
) /* style name */
1137 while (info
->rtfClass
== rtfText
)
1139 if (info
->rtfMajor
== ';')
1141 /* put back for "for" loop */
1142 RTFUngetToken (info
);
1145 *bp
++ = info
->rtfMajor
;
1149 sp
->rtfSName
= RTFStrSave (buf
);
1150 if (sp
->rtfSName
== NULL
)
1151 ERR ("cannot allocate style name\n");
1153 else /* unrecognized */
1155 /* ignore token but announce it */
1156 WARN ("unknown token \"%s\"\n", info
->rtfTextBuf
);
1161 if (!RTFCheckCM (info
, rtfGroup
, rtfEndGroup
))
1162 ERR ("missing \"}\"\n");
1164 * Check over the style structure. A name is a must.
1165 * If no style number was specified, check whether it's the
1166 * Normal style (in which case it's given style number
1167 * rtfNormalStyleNum). Note that some "normal" style names
1168 * just begin with "Normal" and can have other stuff following,
1169 * e.g., "Normal,Times 10 point". Ugh.
1171 * Some German RTF writers use "Standard" instead of "Normal".
1173 if (sp
->rtfSName
== NULL
)
1174 ERR ("missing style name\n");
1175 if (sp
->rtfSNum
< 0)
1177 if (strncmp (buf
, "Normal", 6) != 0
1178 && strncmp (buf
, "Standard", 8) != 0)
1179 ERR ("missing style number\n");
1180 sp
->rtfSNum
= rtfNormalStyleNum
;
1182 if (sp
->rtfSNextPar
== -1) /* if \snext not given, */
1183 sp
->rtfSNextPar
= sp
->rtfSNum
; /* next is itself */
1185 /* otherwise we're just dealing with fake end group from skipped group */
1187 RTFRouteToken (info
); /* feed "}" back to router */
1191 static void ReadInfoGroup(RTF_Info
*info
)
1193 RTFSkipGroup (info
);
1194 RTFRouteToken (info
); /* feed "}" back to router */
1198 static void ReadPictGroup(RTF_Info
*info
)
1200 RTFSkipGroup (info
);
1201 RTFRouteToken (info
); /* feed "}" back to router */
1205 static void ReadObjGroup(RTF_Info
*info
)
1207 RTFSkipGroup (info
);
1208 RTFRouteToken (info
); /* feed "}" back to router */
1212 /* ---------------------------------------------------------------------- */
1215 * Routines to return pieces of stylesheet, or font or color tables.
1216 * References to style 0 are mapped onto the Normal style.
1219 RTFFont
*RTFGetFont(const RTF_Info
*info
, int num
)
1224 return (info
->fontList
);
1225 for (f
= info
->fontList
; f
!= NULL
; f
= f
->rtfNextFont
)
1227 if (f
->rtfFNum
== num
)
1230 return (f
); /* NULL if not found */
1234 RTFColor
*RTFGetColor(const RTF_Info
*info
, int num
)
1239 return (info
->colorList
);
1240 for (c
= info
->colorList
; c
!= NULL
; c
= c
->rtfNextColor
)
1242 if (c
->rtfCNum
== num
)
1245 return (c
); /* NULL if not found */
1249 /* ---------------------------------------------------------------------- */
1252 * Control symbol lookup routines
1256 typedef struct RTFKey RTFKey
;
1260 int rtfKMajor
; /* major number */
1261 int rtfKMinor
; /* minor number */
1262 const char *rtfKStr
; /* symbol name */
1263 int rtfKHash
; /* symbol name hash value */
1267 * A minor number of -1 means the token has no minor number
1268 * (all valid minor numbers are >= 0).
1271 static RTFKey rtfKey
[] =
1274 * Special characters
1277 { rtfSpecialChar
, rtfIIntVersion
, "vern", 0 },
1278 { rtfSpecialChar
, rtfICreateTime
, "creatim", 0 },
1279 { rtfSpecialChar
, rtfIRevisionTime
, "revtim", 0 },
1280 { rtfSpecialChar
, rtfIPrintTime
, "printim", 0 },
1281 { rtfSpecialChar
, rtfIBackupTime
, "buptim", 0 },
1282 { rtfSpecialChar
, rtfIEditTime
, "edmins", 0 },
1283 { rtfSpecialChar
, rtfIYear
, "yr", 0 },
1284 { rtfSpecialChar
, rtfIMonth
, "mo", 0 },
1285 { rtfSpecialChar
, rtfIDay
, "dy", 0 },
1286 { rtfSpecialChar
, rtfIHour
, "hr", 0 },
1287 { rtfSpecialChar
, rtfIMinute
, "min", 0 },
1288 { rtfSpecialChar
, rtfISecond
, "sec", 0 },
1289 { rtfSpecialChar
, rtfINPages
, "nofpages", 0 },
1290 { rtfSpecialChar
, rtfINWords
, "nofwords", 0 },
1291 { rtfSpecialChar
, rtfINChars
, "nofchars", 0 },
1292 { rtfSpecialChar
, rtfIIntID
, "id", 0 },
1294 { rtfSpecialChar
, rtfCurHeadDate
, "chdate", 0 },
1295 { rtfSpecialChar
, rtfCurHeadDateLong
, "chdpl", 0 },
1296 { rtfSpecialChar
, rtfCurHeadDateAbbrev
, "chdpa", 0 },
1297 { rtfSpecialChar
, rtfCurHeadTime
, "chtime", 0 },
1298 { rtfSpecialChar
, rtfCurHeadPage
, "chpgn", 0 },
1299 { rtfSpecialChar
, rtfSectNum
, "sectnum", 0 },
1300 { rtfSpecialChar
, rtfCurFNote
, "chftn", 0 },
1301 { rtfSpecialChar
, rtfCurAnnotRef
, "chatn", 0 },
1302 { rtfSpecialChar
, rtfFNoteSep
, "chftnsep", 0 },
1303 { rtfSpecialChar
, rtfFNoteCont
, "chftnsepc", 0 },
1304 { rtfSpecialChar
, rtfCell
, "cell", 0 },
1305 { rtfSpecialChar
, rtfRow
, "row", 0 },
1306 { rtfSpecialChar
, rtfPar
, "par", 0 },
1307 /* newline and carriage return are synonyms for */
1308 /* \par when they are preceded by a \ character */
1309 { rtfSpecialChar
, rtfPar
, "\n", 0 },
1310 { rtfSpecialChar
, rtfPar
, "\r", 0 },
1311 { rtfSpecialChar
, rtfSect
, "sect", 0 },
1312 { rtfSpecialChar
, rtfPage
, "page", 0 },
1313 { rtfSpecialChar
, rtfColumn
, "column", 0 },
1314 { rtfSpecialChar
, rtfLine
, "line", 0 },
1315 { rtfSpecialChar
, rtfSoftPage
, "softpage", 0 },
1316 { rtfSpecialChar
, rtfSoftColumn
, "softcol", 0 },
1317 { rtfSpecialChar
, rtfSoftLine
, "softline", 0 },
1318 { rtfSpecialChar
, rtfSoftLineHt
, "softlheight", 0 },
1319 { rtfSpecialChar
, rtfTab
, "tab", 0 },
1320 { rtfSpecialChar
, rtfEmDash
, "emdash", 0 },
1321 { rtfSpecialChar
, rtfEnDash
, "endash", 0 },
1322 { rtfSpecialChar
, rtfEmSpace
, "emspace", 0 },
1323 { rtfSpecialChar
, rtfEnSpace
, "enspace", 0 },
1324 { rtfSpecialChar
, rtfBullet
, "bullet", 0 },
1325 { rtfSpecialChar
, rtfLQuote
, "lquote", 0 },
1326 { rtfSpecialChar
, rtfRQuote
, "rquote", 0 },
1327 { rtfSpecialChar
, rtfLDblQuote
, "ldblquote", 0 },
1328 { rtfSpecialChar
, rtfRDblQuote
, "rdblquote", 0 },
1329 { rtfSpecialChar
, rtfFormula
, "|", 0 },
1330 { rtfSpecialChar
, rtfNoBrkSpace
, "~", 0 },
1331 { rtfSpecialChar
, rtfNoReqHyphen
, "-", 0 },
1332 { rtfSpecialChar
, rtfNoBrkHyphen
, "_", 0 },
1333 { rtfSpecialChar
, rtfOptDest
, "*", 0 },
1334 { rtfSpecialChar
, rtfLTRMark
, "ltrmark", 0 },
1335 { rtfSpecialChar
, rtfRTLMark
, "rtlmark", 0 },
1336 { rtfSpecialChar
, rtfNoWidthJoiner
, "zwj", 0 },
1337 { rtfSpecialChar
, rtfNoWidthNonJoiner
, "zwnj", 0 },
1338 /* is this valid? */
1339 { rtfSpecialChar
, rtfCurHeadPict
, "chpict", 0 },
1340 { rtfSpecialChar
, rtfUnicode
, "u", 0 },
1341 { rtfSpecialChar
, rtfNestCell
, "nestcell", 0 },
1342 { rtfSpecialChar
, rtfNestRow
, "nestrow", 0 },
1345 * Character formatting attributes
1348 { rtfCharAttr
, rtfPlain
, "plain", 0 },
1349 { rtfCharAttr
, rtfBold
, "b", 0 },
1350 { rtfCharAttr
, rtfAllCaps
, "caps", 0 },
1351 { rtfCharAttr
, rtfDeleted
, "deleted", 0 },
1352 { rtfCharAttr
, rtfSubScript
, "dn", 0 },
1353 { rtfCharAttr
, rtfSubScrShrink
, "sub", 0 },
1354 { rtfCharAttr
, rtfNoSuperSub
, "nosupersub", 0 },
1355 { rtfCharAttr
, rtfExpand
, "expnd", 0 },
1356 { rtfCharAttr
, rtfExpandTwips
, "expndtw", 0 },
1357 { rtfCharAttr
, rtfKerning
, "kerning", 0 },
1358 { rtfCharAttr
, rtfFontNum
, "f", 0 },
1359 { rtfCharAttr
, rtfFontSize
, "fs", 0 },
1360 { rtfCharAttr
, rtfItalic
, "i", 0 },
1361 { rtfCharAttr
, rtfOutline
, "outl", 0 },
1362 { rtfCharAttr
, rtfRevised
, "revised", 0 },
1363 { rtfCharAttr
, rtfRevAuthor
, "revauth", 0 },
1364 { rtfCharAttr
, rtfRevDTTM
, "revdttm", 0 },
1365 { rtfCharAttr
, rtfSmallCaps
, "scaps", 0 },
1366 { rtfCharAttr
, rtfShadow
, "shad", 0 },
1367 { rtfCharAttr
, rtfStrikeThru
, "strike", 0 },
1368 { rtfCharAttr
, rtfUnderline
, "ul", 0 },
1369 { rtfCharAttr
, rtfDotUnderline
, "uld", 0 },
1370 { rtfCharAttr
, rtfDbUnderline
, "uldb", 0 },
1371 { rtfCharAttr
, rtfNoUnderline
, "ulnone", 0 },
1372 { rtfCharAttr
, rtfWordUnderline
, "ulw", 0 },
1373 { rtfCharAttr
, rtfSuperScript
, "up", 0 },
1374 { rtfCharAttr
, rtfSuperScrShrink
, "super", 0 },
1375 { rtfCharAttr
, rtfInvisible
, "v", 0 },
1376 { rtfCharAttr
, rtfForeColor
, "cf", 0 },
1377 { rtfCharAttr
, rtfBackColor
, "cb", 0 },
1378 { rtfCharAttr
, rtfRTLChar
, "rtlch", 0 },
1379 { rtfCharAttr
, rtfLTRChar
, "ltrch", 0 },
1380 { rtfCharAttr
, rtfCharStyleNum
, "cs", 0 },
1381 { rtfCharAttr
, rtfCharCharSet
, "cchs", 0 },
1382 { rtfCharAttr
, rtfLanguage
, "lang", 0 },
1383 /* this has disappeared from spec 1.2 */
1384 { rtfCharAttr
, rtfGray
, "gray", 0 },
1385 { rtfCharAttr
, rtfUnicodeLength
, "uc", 0 },
1388 * Paragraph formatting attributes
1391 { rtfParAttr
, rtfParDef
, "pard", 0 },
1392 { rtfParAttr
, rtfStyleNum
, "s", 0 },
1393 { rtfParAttr
, rtfHyphenate
, "hyphpar", 0 },
1394 { rtfParAttr
, rtfInTable
, "intbl", 0 },
1395 { rtfParAttr
, rtfKeep
, "keep", 0 },
1396 { rtfParAttr
, rtfNoWidowControl
, "nowidctlpar", 0 },
1397 { rtfParAttr
, rtfKeepNext
, "keepn", 0 },
1398 { rtfParAttr
, rtfOutlineLevel
, "level", 0 },
1399 { rtfParAttr
, rtfNoLineNum
, "noline", 0 },
1400 { rtfParAttr
, rtfPBBefore
, "pagebb", 0 },
1401 { rtfParAttr
, rtfSideBySide
, "sbys", 0 },
1402 { rtfParAttr
, rtfQuadLeft
, "ql", 0 },
1403 { rtfParAttr
, rtfQuadRight
, "qr", 0 },
1404 { rtfParAttr
, rtfQuadJust
, "qj", 0 },
1405 { rtfParAttr
, rtfQuadCenter
, "qc", 0 },
1406 { rtfParAttr
, rtfFirstIndent
, "fi", 0 },
1407 { rtfParAttr
, rtfLeftIndent
, "li", 0 },
1408 { rtfParAttr
, rtfRightIndent
, "ri", 0 },
1409 { rtfParAttr
, rtfSpaceBefore
, "sb", 0 },
1410 { rtfParAttr
, rtfSpaceAfter
, "sa", 0 },
1411 { rtfParAttr
, rtfSpaceBetween
, "sl", 0 },
1412 { rtfParAttr
, rtfSpaceMultiply
, "slmult", 0 },
1414 { rtfParAttr
, rtfSubDocument
, "subdocument", 0 },
1416 { rtfParAttr
, rtfRTLPar
, "rtlpar", 0 },
1417 { rtfParAttr
, rtfLTRPar
, "ltrpar", 0 },
1419 { rtfParAttr
, rtfTabPos
, "tx", 0 },
1421 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1422 * although it's not in the spec. It's also redundant, since lj
1423 * tabs are the default.
1425 { rtfParAttr
, rtfTabLeft
, "tql", 0 },
1426 { rtfParAttr
, rtfTabRight
, "tqr", 0 },
1427 { rtfParAttr
, rtfTabCenter
, "tqc", 0 },
1428 { rtfParAttr
, rtfTabDecimal
, "tqdec", 0 },
1429 { rtfParAttr
, rtfTabBar
, "tb", 0 },
1430 { rtfParAttr
, rtfLeaderDot
, "tldot", 0 },
1431 { rtfParAttr
, rtfLeaderHyphen
, "tlhyph", 0 },
1432 { rtfParAttr
, rtfLeaderUnder
, "tlul", 0 },
1433 { rtfParAttr
, rtfLeaderThick
, "tlth", 0 },
1434 { rtfParAttr
, rtfLeaderEqual
, "tleq", 0 },
1436 { rtfParAttr
, rtfParLevel
, "pnlvl", 0 },
1437 { rtfParAttr
, rtfParBullet
, "pnlvlblt", 0 },
1438 { rtfParAttr
, rtfParSimple
, "pnlvlbody", 0 },
1439 { rtfParAttr
, rtfParNumCont
, "pnlvlcont", 0 },
1440 { rtfParAttr
, rtfParNumOnce
, "pnnumonce", 0 },
1441 { rtfParAttr
, rtfParNumAcross
, "pnacross", 0 },
1442 { rtfParAttr
, rtfParHangIndent
, "pnhang", 0 },
1443 { rtfParAttr
, rtfParNumRestart
, "pnrestart", 0 },
1444 { rtfParAttr
, rtfParNumCardinal
, "pncard", 0 },
1445 { rtfParAttr
, rtfParNumDecimal
, "pndec", 0 },
1446 { rtfParAttr
, rtfParNumULetter
, "pnucltr", 0 },
1447 { rtfParAttr
, rtfParNumURoman
, "pnucrm", 0 },
1448 { rtfParAttr
, rtfParNumLLetter
, "pnlcltr", 0 },
1449 { rtfParAttr
, rtfParNumLRoman
, "pnlcrm", 0 },
1450 { rtfParAttr
, rtfParNumOrdinal
, "pnord", 0 },
1451 { rtfParAttr
, rtfParNumOrdinalText
, "pnordt", 0 },
1452 { rtfParAttr
, rtfParNumBold
, "pnb", 0 },
1453 { rtfParAttr
, rtfParNumItalic
, "pni", 0 },
1454 { rtfParAttr
, rtfParNumAllCaps
, "pncaps", 0 },
1455 { rtfParAttr
, rtfParNumSmallCaps
, "pnscaps", 0 },
1456 { rtfParAttr
, rtfParNumUnder
, "pnul", 0 },
1457 { rtfParAttr
, rtfParNumDotUnder
, "pnuld", 0 },
1458 { rtfParAttr
, rtfParNumDbUnder
, "pnuldb", 0 },
1459 { rtfParAttr
, rtfParNumNoUnder
, "pnulnone", 0 },
1460 { rtfParAttr
, rtfParNumWordUnder
, "pnulw", 0 },
1461 { rtfParAttr
, rtfParNumStrikethru
, "pnstrike", 0 },
1462 { rtfParAttr
, rtfParNumForeColor
, "pncf", 0 },
1463 { rtfParAttr
, rtfParNumFont
, "pnf", 0 },
1464 { rtfParAttr
, rtfParNumFontSize
, "pnfs", 0 },
1465 { rtfParAttr
, rtfParNumIndent
, "pnindent", 0 },
1466 { rtfParAttr
, rtfParNumSpacing
, "pnsp", 0 },
1467 { rtfParAttr
, rtfParNumInclPrev
, "pnprev", 0 },
1468 { rtfParAttr
, rtfParNumCenter
, "pnqc", 0 },
1469 { rtfParAttr
, rtfParNumLeft
, "pnql", 0 },
1470 { rtfParAttr
, rtfParNumRight
, "pnqr", 0 },
1471 { rtfParAttr
, rtfParNumStartAt
, "pnstart", 0 },
1473 { rtfParAttr
, rtfBorderTop
, "brdrt", 0 },
1474 { rtfParAttr
, rtfBorderBottom
, "brdrb", 0 },
1475 { rtfParAttr
, rtfBorderLeft
, "brdrl", 0 },
1476 { rtfParAttr
, rtfBorderRight
, "brdrr", 0 },
1477 { rtfParAttr
, rtfBorderBetween
, "brdrbtw", 0 },
1478 { rtfParAttr
, rtfBorderBar
, "brdrbar", 0 },
1479 { rtfParAttr
, rtfBorderBox
, "box", 0 },
1480 { rtfParAttr
, rtfBorderSingle
, "brdrs", 0 },
1481 { rtfParAttr
, rtfBorderThick
, "brdrth", 0 },
1482 { rtfParAttr
, rtfBorderShadow
, "brdrsh", 0 },
1483 { rtfParAttr
, rtfBorderDouble
, "brdrdb", 0 },
1484 { rtfParAttr
, rtfBorderDot
, "brdrdot", 0 },
1485 { rtfParAttr
, rtfBorderDot
, "brdrdash", 0 },
1486 { rtfParAttr
, rtfBorderHair
, "brdrhair", 0 },
1487 { rtfParAttr
, rtfBorderWidth
, "brdrw", 0 },
1488 { rtfParAttr
, rtfBorderColor
, "brdrcf", 0 },
1489 { rtfParAttr
, rtfBorderSpace
, "brsp", 0 },
1491 { rtfParAttr
, rtfShading
, "shading", 0 },
1492 { rtfParAttr
, rtfBgPatH
, "bghoriz", 0 },
1493 { rtfParAttr
, rtfBgPatV
, "bgvert", 0 },
1494 { rtfParAttr
, rtfFwdDiagBgPat
, "bgfdiag", 0 },
1495 { rtfParAttr
, rtfBwdDiagBgPat
, "bgbdiag", 0 },
1496 { rtfParAttr
, rtfHatchBgPat
, "bgcross", 0 },
1497 { rtfParAttr
, rtfDiagHatchBgPat
, "bgdcross", 0 },
1498 { rtfParAttr
, rtfDarkBgPatH
, "bgdkhoriz", 0 },
1499 { rtfParAttr
, rtfDarkBgPatV
, "bgdkvert", 0 },
1500 { rtfParAttr
, rtfFwdDarkBgPat
, "bgdkfdiag", 0 },
1501 { rtfParAttr
, rtfBwdDarkBgPat
, "bgdkbdiag", 0 },
1502 { rtfParAttr
, rtfDarkHatchBgPat
, "bgdkcross", 0 },
1503 { rtfParAttr
, rtfDarkDiagHatchBgPat
, "bgdkdcross", 0 },
1504 { rtfParAttr
, rtfBgPatLineColor
, "cfpat", 0 },
1505 { rtfParAttr
, rtfBgPatColor
, "cbpat", 0 },
1506 { rtfParAttr
, rtfNestLevel
, "itap", 0 },
1509 * Section formatting attributes
1512 { rtfSectAttr
, rtfSectDef
, "sectd", 0 },
1513 { rtfSectAttr
, rtfENoteHere
, "endnhere", 0 },
1514 { rtfSectAttr
, rtfPrtBinFirst
, "binfsxn", 0 },
1515 { rtfSectAttr
, rtfPrtBin
, "binsxn", 0 },
1516 { rtfSectAttr
, rtfSectStyleNum
, "ds", 0 },
1518 { rtfSectAttr
, rtfNoBreak
, "sbknone", 0 },
1519 { rtfSectAttr
, rtfColBreak
, "sbkcol", 0 },
1520 { rtfSectAttr
, rtfPageBreak
, "sbkpage", 0 },
1521 { rtfSectAttr
, rtfEvenBreak
, "sbkeven", 0 },
1522 { rtfSectAttr
, rtfOddBreak
, "sbkodd", 0 },
1524 { rtfSectAttr
, rtfColumns
, "cols", 0 },
1525 { rtfSectAttr
, rtfColumnSpace
, "colsx", 0 },
1526 { rtfSectAttr
, rtfColumnNumber
, "colno", 0 },
1527 { rtfSectAttr
, rtfColumnSpRight
, "colsr", 0 },
1528 { rtfSectAttr
, rtfColumnWidth
, "colw", 0 },
1529 { rtfSectAttr
, rtfColumnLine
, "linebetcol", 0 },
1531 { rtfSectAttr
, rtfLineModulus
, "linemod", 0 },
1532 { rtfSectAttr
, rtfLineDist
, "linex", 0 },
1533 { rtfSectAttr
, rtfLineStarts
, "linestarts", 0 },
1534 { rtfSectAttr
, rtfLineRestart
, "linerestart", 0 },
1535 { rtfSectAttr
, rtfLineRestartPg
, "lineppage", 0 },
1536 { rtfSectAttr
, rtfLineCont
, "linecont", 0 },
1538 { rtfSectAttr
, rtfSectPageWid
, "pgwsxn", 0 },
1539 { rtfSectAttr
, rtfSectPageHt
, "pghsxn", 0 },
1540 { rtfSectAttr
, rtfSectMarginLeft
, "marglsxn", 0 },
1541 { rtfSectAttr
, rtfSectMarginRight
, "margrsxn", 0 },
1542 { rtfSectAttr
, rtfSectMarginTop
, "margtsxn", 0 },
1543 { rtfSectAttr
, rtfSectMarginBottom
, "margbsxn", 0 },
1544 { rtfSectAttr
, rtfSectMarginGutter
, "guttersxn", 0 },
1545 { rtfSectAttr
, rtfSectLandscape
, "lndscpsxn", 0 },
1546 { rtfSectAttr
, rtfTitleSpecial
, "titlepg", 0 },
1547 { rtfSectAttr
, rtfHeaderY
, "headery", 0 },
1548 { rtfSectAttr
, rtfFooterY
, "footery", 0 },
1550 { rtfSectAttr
, rtfPageStarts
, "pgnstarts", 0 },
1551 { rtfSectAttr
, rtfPageCont
, "pgncont", 0 },
1552 { rtfSectAttr
, rtfPageRestart
, "pgnrestart", 0 },
1553 { rtfSectAttr
, rtfPageNumRight
, "pgnx", 0 },
1554 { rtfSectAttr
, rtfPageNumTop
, "pgny", 0 },
1555 { rtfSectAttr
, rtfPageDecimal
, "pgndec", 0 },
1556 { rtfSectAttr
, rtfPageURoman
, "pgnucrm", 0 },
1557 { rtfSectAttr
, rtfPageLRoman
, "pgnlcrm", 0 },
1558 { rtfSectAttr
, rtfPageULetter
, "pgnucltr", 0 },
1559 { rtfSectAttr
, rtfPageLLetter
, "pgnlcltr", 0 },
1560 { rtfSectAttr
, rtfPageNumHyphSep
, "pgnhnsh", 0 },
1561 { rtfSectAttr
, rtfPageNumSpaceSep
, "pgnhnsp", 0 },
1562 { rtfSectAttr
, rtfPageNumColonSep
, "pgnhnsc", 0 },
1563 { rtfSectAttr
, rtfPageNumEmdashSep
, "pgnhnsm", 0 },
1564 { rtfSectAttr
, rtfPageNumEndashSep
, "pgnhnsn", 0 },
1566 { rtfSectAttr
, rtfTopVAlign
, "vertalt", 0 },
1567 /* misspelled as "vertal" in specification 1.0 */
1568 { rtfSectAttr
, rtfBottomVAlign
, "vertalb", 0 },
1569 { rtfSectAttr
, rtfCenterVAlign
, "vertalc", 0 },
1570 { rtfSectAttr
, rtfJustVAlign
, "vertalj", 0 },
1572 { rtfSectAttr
, rtfRTLSect
, "rtlsect", 0 },
1573 { rtfSectAttr
, rtfLTRSect
, "ltrsect", 0 },
1575 /* I've seen these in an old spec, but not in real files... */
1576 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1577 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1578 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1579 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1580 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1583 * Document formatting attributes
1586 { rtfDocAttr
, rtfDefTab
, "deftab", 0 },
1587 { rtfDocAttr
, rtfHyphHotZone
, "hyphhotz", 0 },
1588 { rtfDocAttr
, rtfHyphConsecLines
, "hyphconsec", 0 },
1589 { rtfDocAttr
, rtfHyphCaps
, "hyphcaps", 0 },
1590 { rtfDocAttr
, rtfHyphAuto
, "hyphauto", 0 },
1591 { rtfDocAttr
, rtfLineStart
, "linestart", 0 },
1592 { rtfDocAttr
, rtfFracWidth
, "fracwidth", 0 },
1593 /* \makeback was given in old version of spec, it's now */
1594 /* listed as \makebackup */
1595 { rtfDocAttr
, rtfMakeBackup
, "makeback", 0 },
1596 { rtfDocAttr
, rtfMakeBackup
, "makebackup", 0 },
1597 { rtfDocAttr
, rtfRTFDefault
, "defformat", 0 },
1598 { rtfDocAttr
, rtfPSOverlay
, "psover", 0 },
1599 { rtfDocAttr
, rtfDocTemplate
, "doctemp", 0 },
1600 { rtfDocAttr
, rtfDefLanguage
, "deflang", 0 },
1602 { rtfDocAttr
, rtfFENoteType
, "fet", 0 },
1603 { rtfDocAttr
, rtfFNoteEndSect
, "endnotes", 0 },
1604 { rtfDocAttr
, rtfFNoteEndDoc
, "enddoc", 0 },
1605 { rtfDocAttr
, rtfFNoteText
, "ftntj", 0 },
1606 { rtfDocAttr
, rtfFNoteBottom
, "ftnbj", 0 },
1607 { rtfDocAttr
, rtfENoteEndSect
, "aendnotes", 0 },
1608 { rtfDocAttr
, rtfENoteEndDoc
, "aenddoc", 0 },
1609 { rtfDocAttr
, rtfENoteText
, "aftntj", 0 },
1610 { rtfDocAttr
, rtfENoteBottom
, "aftnbj", 0 },
1611 { rtfDocAttr
, rtfFNoteStart
, "ftnstart", 0 },
1612 { rtfDocAttr
, rtfENoteStart
, "aftnstart", 0 },
1613 { rtfDocAttr
, rtfFNoteRestartPage
, "ftnrstpg", 0 },
1614 { rtfDocAttr
, rtfFNoteRestart
, "ftnrestart", 0 },
1615 { rtfDocAttr
, rtfFNoteRestartCont
, "ftnrstcont", 0 },
1616 { rtfDocAttr
, rtfENoteRestart
, "aftnrestart", 0 },
1617 { rtfDocAttr
, rtfENoteRestartCont
, "aftnrstcont", 0 },
1618 { rtfDocAttr
, rtfFNoteNumArabic
, "ftnnar", 0 },
1619 { rtfDocAttr
, rtfFNoteNumLLetter
, "ftnnalc", 0 },
1620 { rtfDocAttr
, rtfFNoteNumULetter
, "ftnnauc", 0 },
1621 { rtfDocAttr
, rtfFNoteNumLRoman
, "ftnnrlc", 0 },
1622 { rtfDocAttr
, rtfFNoteNumURoman
, "ftnnruc", 0 },
1623 { rtfDocAttr
, rtfFNoteNumChicago
, "ftnnchi", 0 },
1624 { rtfDocAttr
, rtfENoteNumArabic
, "aftnnar", 0 },
1625 { rtfDocAttr
, rtfENoteNumLLetter
, "aftnnalc", 0 },
1626 { rtfDocAttr
, rtfENoteNumULetter
, "aftnnauc", 0 },
1627 { rtfDocAttr
, rtfENoteNumLRoman
, "aftnnrlc", 0 },
1628 { rtfDocAttr
, rtfENoteNumURoman
, "aftnnruc", 0 },
1629 { rtfDocAttr
, rtfENoteNumChicago
, "aftnnchi", 0 },
1631 { rtfDocAttr
, rtfPaperWidth
, "paperw", 0 },
1632 { rtfDocAttr
, rtfPaperHeight
, "paperh", 0 },
1633 { rtfDocAttr
, rtfPaperSize
, "psz", 0 },
1634 { rtfDocAttr
, rtfLeftMargin
, "margl", 0 },
1635 { rtfDocAttr
, rtfRightMargin
, "margr", 0 },
1636 { rtfDocAttr
, rtfTopMargin
, "margt", 0 },
1637 { rtfDocAttr
, rtfBottomMargin
, "margb", 0 },
1638 { rtfDocAttr
, rtfFacingPage
, "facingp", 0 },
1639 { rtfDocAttr
, rtfGutterWid
, "gutter", 0 },
1640 { rtfDocAttr
, rtfMirrorMargin
, "margmirror", 0 },
1641 { rtfDocAttr
, rtfLandscape
, "landscape", 0 },
1642 { rtfDocAttr
, rtfPageStart
, "pgnstart", 0 },
1643 { rtfDocAttr
, rtfWidowCtrl
, "widowctrl", 0 },
1645 { rtfDocAttr
, rtfLinkStyles
, "linkstyles", 0 },
1647 { rtfDocAttr
, rtfNoAutoTabIndent
, "notabind", 0 },
1648 { rtfDocAttr
, rtfWrapSpaces
, "wraptrsp", 0 },
1649 { rtfDocAttr
, rtfPrintColorsBlack
, "prcolbl", 0 },
1650 { rtfDocAttr
, rtfNoExtraSpaceRL
, "noextrasprl", 0 },
1651 { rtfDocAttr
, rtfNoColumnBalance
, "nocolbal", 0 },
1652 { rtfDocAttr
, rtfCvtMailMergeQuote
, "cvmme", 0 },
1653 { rtfDocAttr
, rtfSuppressTopSpace
, "sprstsp", 0 },
1654 { rtfDocAttr
, rtfSuppressPreParSpace
, "sprsspbf", 0 },
1655 { rtfDocAttr
, rtfCombineTblBorders
, "otblrul", 0 },
1656 { rtfDocAttr
, rtfTranspMetafiles
, "transmf", 0 },
1657 { rtfDocAttr
, rtfSwapBorders
, "swpbdr", 0 },
1658 { rtfDocAttr
, rtfShowHardBreaks
, "brkfrm", 0 },
1660 { rtfDocAttr
, rtfFormProtected
, "formprot", 0 },
1661 { rtfDocAttr
, rtfAllProtected
, "allprot", 0 },
1662 { rtfDocAttr
, rtfFormShading
, "formshade", 0 },
1663 { rtfDocAttr
, rtfFormDisplay
, "formdisp", 0 },
1664 { rtfDocAttr
, rtfPrintData
, "printdata", 0 },
1666 { rtfDocAttr
, rtfRevProtected
, "revprot", 0 },
1667 { rtfDocAttr
, rtfRevisions
, "revisions", 0 },
1668 { rtfDocAttr
, rtfRevDisplay
, "revprop", 0 },
1669 { rtfDocAttr
, rtfRevBar
, "revbar", 0 },
1671 { rtfDocAttr
, rtfAnnotProtected
, "annotprot", 0 },
1673 { rtfDocAttr
, rtfRTLDoc
, "rtldoc", 0 },
1674 { rtfDocAttr
, rtfLTRDoc
, "ltrdoc", 0 },
1676 { rtfDocAttr
, rtfAnsiCodePage
, "ansicpg", 0 },
1677 { rtfDocAttr
, rtfUTF8RTF
, "urtf", 0 },
1683 { rtfStyleAttr
, rtfAdditive
, "additive", 0 },
1684 { rtfStyleAttr
, rtfBasedOn
, "sbasedon", 0 },
1685 { rtfStyleAttr
, rtfNext
, "snext", 0 },
1688 * Picture attributes
1691 { rtfPictAttr
, rtfMacQD
, "macpict", 0 },
1692 { rtfPictAttr
, rtfPMMetafile
, "pmmetafile", 0 },
1693 { rtfPictAttr
, rtfWinMetafile
, "wmetafile", 0 },
1694 { rtfPictAttr
, rtfDevIndBitmap
, "dibitmap", 0 },
1695 { rtfPictAttr
, rtfWinBitmap
, "wbitmap", 0 },
1696 { rtfPictAttr
, rtfEmfBlip
, "emfblip", 0 },
1697 { rtfPictAttr
, rtfPixelBits
, "wbmbitspixel", 0 },
1698 { rtfPictAttr
, rtfBitmapPlanes
, "wbmplanes", 0 },
1699 { rtfPictAttr
, rtfBitmapWid
, "wbmwidthbytes", 0 },
1701 { rtfPictAttr
, rtfPicWid
, "picw", 0 },
1702 { rtfPictAttr
, rtfPicHt
, "pich", 0 },
1703 { rtfPictAttr
, rtfPicGoalWid
, "picwgoal", 0 },
1704 { rtfPictAttr
, rtfPicGoalHt
, "pichgoal", 0 },
1705 /* these two aren't in the spec, but some writers emit them */
1706 { rtfPictAttr
, rtfPicGoalWid
, "picwGoal", 0 },
1707 { rtfPictAttr
, rtfPicGoalHt
, "pichGoal", 0 },
1708 { rtfPictAttr
, rtfPicScaleX
, "picscalex", 0 },
1709 { rtfPictAttr
, rtfPicScaleY
, "picscaley", 0 },
1710 { rtfPictAttr
, rtfPicScaled
, "picscaled", 0 },
1711 { rtfPictAttr
, rtfPicCropTop
, "piccropt", 0 },
1712 { rtfPictAttr
, rtfPicCropBottom
, "piccropb", 0 },
1713 { rtfPictAttr
, rtfPicCropLeft
, "piccropl", 0 },
1714 { rtfPictAttr
, rtfPicCropRight
, "piccropr", 0 },
1716 { rtfPictAttr
, rtfPicMFHasBitmap
, "picbmp", 0 },
1717 { rtfPictAttr
, rtfPicMFBitsPerPixel
, "picbpp", 0 },
1719 { rtfPictAttr
, rtfPicBinary
, "bin", 0 },
1722 * NeXT graphic attributes
1725 { rtfNeXTGrAttr
, rtfNeXTGWidth
, "width", 0 },
1726 { rtfNeXTGrAttr
, rtfNeXTGHeight
, "height", 0 },
1732 { rtfDestination
, rtfFontTbl
, "fonttbl", 0 },
1733 { rtfDestination
, rtfFontAltName
, "falt", 0 },
1734 { rtfDestination
, rtfEmbeddedFont
, "fonteb", 0 },
1735 { rtfDestination
, rtfFontFile
, "fontfile", 0 },
1736 { rtfDestination
, rtfFileTbl
, "filetbl", 0 },
1737 { rtfDestination
, rtfFileInfo
, "file", 0 },
1738 { rtfDestination
, rtfColorTbl
, "colortbl", 0 },
1739 { rtfDestination
, rtfStyleSheet
, "stylesheet", 0 },
1740 { rtfDestination
, rtfKeyCode
, "keycode", 0 },
1741 { rtfDestination
, rtfRevisionTbl
, "revtbl", 0 },
1742 { rtfDestination
, rtfGenerator
, "generator", 0 },
1743 { rtfDestination
, rtfInfo
, "info", 0 },
1744 { rtfDestination
, rtfITitle
, "title", 0 },
1745 { rtfDestination
, rtfISubject
, "subject", 0 },
1746 { rtfDestination
, rtfIAuthor
, "author", 0 },
1747 { rtfDestination
, rtfIOperator
, "operator", 0 },
1748 { rtfDestination
, rtfIKeywords
, "keywords", 0 },
1749 { rtfDestination
, rtfIComment
, "comment", 0 },
1750 { rtfDestination
, rtfIVersion
, "version", 0 },
1751 { rtfDestination
, rtfIDoccomm
, "doccomm", 0 },
1752 /* \verscomm may not exist -- was seen in earlier spec version */
1753 { rtfDestination
, rtfIVerscomm
, "verscomm", 0 },
1754 { rtfDestination
, rtfNextFile
, "nextfile", 0 },
1755 { rtfDestination
, rtfTemplate
, "template", 0 },
1756 { rtfDestination
, rtfFNSep
, "ftnsep", 0 },
1757 { rtfDestination
, rtfFNContSep
, "ftnsepc", 0 },
1758 { rtfDestination
, rtfFNContNotice
, "ftncn", 0 },
1759 { rtfDestination
, rtfENSep
, "aftnsep", 0 },
1760 { rtfDestination
, rtfENContSep
, "aftnsepc", 0 },
1761 { rtfDestination
, rtfENContNotice
, "aftncn", 0 },
1762 { rtfDestination
, rtfPageNumLevel
, "pgnhn", 0 },
1763 { rtfDestination
, rtfParNumLevelStyle
, "pnseclvl", 0 },
1764 { rtfDestination
, rtfHeader
, "header", 0 },
1765 { rtfDestination
, rtfFooter
, "footer", 0 },
1766 { rtfDestination
, rtfHeaderLeft
, "headerl", 0 },
1767 { rtfDestination
, rtfHeaderRight
, "headerr", 0 },
1768 { rtfDestination
, rtfHeaderFirst
, "headerf", 0 },
1769 { rtfDestination
, rtfFooterLeft
, "footerl", 0 },
1770 { rtfDestination
, rtfFooterRight
, "footerr", 0 },
1771 { rtfDestination
, rtfFooterFirst
, "footerf", 0 },
1772 { rtfDestination
, rtfParNumText
, "pntext", 0 },
1773 { rtfDestination
, rtfParNumbering
, "pn", 0 },
1774 { rtfDestination
, rtfParNumTextAfter
, "pntexta", 0 },
1775 { rtfDestination
, rtfParNumTextBefore
, "pntextb", 0 },
1776 { rtfDestination
, rtfBookmarkStart
, "bkmkstart", 0 },
1777 { rtfDestination
, rtfBookmarkEnd
, "bkmkend", 0 },
1778 { rtfDestination
, rtfPict
, "pict", 0 },
1779 { rtfDestination
, rtfObject
, "object", 0 },
1780 { rtfDestination
, rtfObjClass
, "objclass", 0 },
1781 { rtfDestination
, rtfObjName
, "objname", 0 },
1782 { rtfObjAttr
, rtfObjTime
, "objtime", 0 },
1783 { rtfDestination
, rtfObjData
, "objdata", 0 },
1784 { rtfDestination
, rtfObjAlias
, "objalias", 0 },
1785 { rtfDestination
, rtfObjSection
, "objsect", 0 },
1786 /* objitem and objtopic aren't documented in the spec! */
1787 { rtfDestination
, rtfObjItem
, "objitem", 0 },
1788 { rtfDestination
, rtfObjTopic
, "objtopic", 0 },
1789 { rtfDestination
, rtfObjResult
, "result", 0 },
1790 { rtfDestination
, rtfDrawObject
, "do", 0 },
1791 { rtfDestination
, rtfFootnote
, "footnote", 0 },
1792 { rtfDestination
, rtfAnnotRefStart
, "atrfstart", 0 },
1793 { rtfDestination
, rtfAnnotRefEnd
, "atrfend", 0 },
1794 { rtfDestination
, rtfAnnotID
, "atnid", 0 },
1795 { rtfDestination
, rtfAnnotAuthor
, "atnauthor", 0 },
1796 { rtfDestination
, rtfAnnotation
, "annotation", 0 },
1797 { rtfDestination
, rtfAnnotRef
, "atnref", 0 },
1798 { rtfDestination
, rtfAnnotTime
, "atntime", 0 },
1799 { rtfDestination
, rtfAnnotIcon
, "atnicn", 0 },
1800 { rtfDestination
, rtfField
, "field", 0 },
1801 { rtfDestination
, rtfFieldInst
, "fldinst", 0 },
1802 { rtfDestination
, rtfFieldResult
, "fldrslt", 0 },
1803 { rtfDestination
, rtfDataField
, "datafield", 0 },
1804 { rtfDestination
, rtfIndex
, "xe", 0 },
1805 { rtfDestination
, rtfIndexText
, "txe", 0 },
1806 { rtfDestination
, rtfIndexRange
, "rxe", 0 },
1807 { rtfDestination
, rtfTOC
, "tc", 0 },
1808 { rtfDestination
, rtfNeXTGraphic
, "NeXTGraphic", 0 },
1809 { rtfDestination
, rtfNestTableProps
, "nesttableprops", 0 },
1810 { rtfDestination
, rtfNoNestTables
, "nonesttables", 0 },
1816 { rtfFontFamily
, rtfFFNil
, "fnil", 0 },
1817 { rtfFontFamily
, rtfFFRoman
, "froman", 0 },
1818 { rtfFontFamily
, rtfFFSwiss
, "fswiss", 0 },
1819 { rtfFontFamily
, rtfFFModern
, "fmodern", 0 },
1820 { rtfFontFamily
, rtfFFScript
, "fscript", 0 },
1821 { rtfFontFamily
, rtfFFDecor
, "fdecor", 0 },
1822 { rtfFontFamily
, rtfFFTech
, "ftech", 0 },
1823 { rtfFontFamily
, rtfFFBidirectional
, "fbidi", 0 },
1829 { rtfFontAttr
, rtfFontCharSet
, "fcharset", 0 },
1830 { rtfFontAttr
, rtfFontPitch
, "fprq", 0 },
1831 { rtfFontAttr
, rtfFontCodePage
, "cpg", 0 },
1832 { rtfFontAttr
, rtfFTypeNil
, "ftnil", 0 },
1833 { rtfFontAttr
, rtfFTypeTrueType
, "fttruetype", 0 },
1836 * File table attributes
1839 { rtfFileAttr
, rtfFileNum
, "fid", 0 },
1840 { rtfFileAttr
, rtfFileRelPath
, "frelative", 0 },
1841 { rtfFileAttr
, rtfFileOSNum
, "fosnum", 0 },
1847 { rtfFileSource
, rtfSrcMacintosh
, "fvalidmac", 0 },
1848 { rtfFileSource
, rtfSrcDOS
, "fvaliddos", 0 },
1849 { rtfFileSource
, rtfSrcNTFS
, "fvalidntfs", 0 },
1850 { rtfFileSource
, rtfSrcHPFS
, "fvalidhpfs", 0 },
1851 { rtfFileSource
, rtfSrcNetwork
, "fnetwork", 0 },
1857 { rtfColorName
, rtfRed
, "red", 0 },
1858 { rtfColorName
, rtfGreen
, "green", 0 },
1859 { rtfColorName
, rtfBlue
, "blue", 0 },
1865 { rtfCharSet
, rtfMacCharSet
, "mac", 0 },
1866 { rtfCharSet
, rtfAnsiCharSet
, "ansi", 0 },
1867 { rtfCharSet
, rtfPcCharSet
, "pc", 0 },
1868 { rtfCharSet
, rtfPcaCharSet
, "pca", 0 },
1874 { rtfTblAttr
, rtfRowDef
, "trowd", 0 },
1875 { rtfTblAttr
, rtfRowGapH
, "trgaph", 0 },
1876 { rtfTblAttr
, rtfCellPos
, "cellx", 0 },
1877 { rtfTblAttr
, rtfMergeRngFirst
, "clmgf", 0 },
1878 { rtfTblAttr
, rtfMergePrevious
, "clmrg", 0 },
1880 { rtfTblAttr
, rtfRowLeft
, "trql", 0 },
1881 { rtfTblAttr
, rtfRowRight
, "trqr", 0 },
1882 { rtfTblAttr
, rtfRowCenter
, "trqc", 0 },
1883 { rtfTblAttr
, rtfRowLeftEdge
, "trleft", 0 },
1884 { rtfTblAttr
, rtfRowHt
, "trrh", 0 },
1885 { rtfTblAttr
, rtfRowHeader
, "trhdr", 0 },
1886 { rtfTblAttr
, rtfRowKeep
, "trkeep", 0 },
1888 { rtfTblAttr
, rtfRTLRow
, "rtlrow", 0 },
1889 { rtfTblAttr
, rtfLTRRow
, "ltrrow", 0 },
1891 { rtfTblAttr
, rtfRowBordTop
, "trbrdrt", 0 },
1892 { rtfTblAttr
, rtfRowBordLeft
, "trbrdrl", 0 },
1893 { rtfTblAttr
, rtfRowBordBottom
, "trbrdrb", 0 },
1894 { rtfTblAttr
, rtfRowBordRight
, "trbrdrr", 0 },
1895 { rtfTblAttr
, rtfRowBordHoriz
, "trbrdrh", 0 },
1896 { rtfTblAttr
, rtfRowBordVert
, "trbrdrv", 0 },
1898 { rtfTblAttr
, rtfCellBordBottom
, "clbrdrb", 0 },
1899 { rtfTblAttr
, rtfCellBordTop
, "clbrdrt", 0 },
1900 { rtfTblAttr
, rtfCellBordLeft
, "clbrdrl", 0 },
1901 { rtfTblAttr
, rtfCellBordRight
, "clbrdrr", 0 },
1903 { rtfTblAttr
, rtfCellShading
, "clshdng", 0 },
1904 { rtfTblAttr
, rtfCellBgPatH
, "clbghoriz", 0 },
1905 { rtfTblAttr
, rtfCellBgPatV
, "clbgvert", 0 },
1906 { rtfTblAttr
, rtfCellFwdDiagBgPat
, "clbgfdiag", 0 },
1907 { rtfTblAttr
, rtfCellBwdDiagBgPat
, "clbgbdiag", 0 },
1908 { rtfTblAttr
, rtfCellHatchBgPat
, "clbgcross", 0 },
1909 { rtfTblAttr
, rtfCellDiagHatchBgPat
, "clbgdcross", 0 },
1911 * The spec lists "clbgdkhor", but the corresponding non-cell
1912 * control is "bgdkhoriz". At any rate Macintosh Word seems
1913 * to accept both "clbgdkhor" and "clbgdkhoriz".
1915 { rtfTblAttr
, rtfCellDarkBgPatH
, "clbgdkhoriz", 0 },
1916 { rtfTblAttr
, rtfCellDarkBgPatH
, "clbgdkhor", 0 },
1917 { rtfTblAttr
, rtfCellDarkBgPatV
, "clbgdkvert", 0 },
1918 { rtfTblAttr
, rtfCellFwdDarkBgPat
, "clbgdkfdiag", 0 },
1919 { rtfTblAttr
, rtfCellBwdDarkBgPat
, "clbgdkbdiag", 0 },
1920 { rtfTblAttr
, rtfCellDarkHatchBgPat
, "clbgdkcross", 0 },
1921 { rtfTblAttr
, rtfCellDarkDiagHatchBgPat
, "clbgdkdcross", 0 },
1922 { rtfTblAttr
, rtfCellBgPatLineColor
, "clcfpat", 0 },
1923 { rtfTblAttr
, rtfCellBgPatColor
, "clcbpat", 0 },
1929 { rtfFieldAttr
, rtfFieldDirty
, "flddirty", 0 },
1930 { rtfFieldAttr
, rtfFieldEdited
, "fldedit", 0 },
1931 { rtfFieldAttr
, rtfFieldLocked
, "fldlock", 0 },
1932 { rtfFieldAttr
, rtfFieldPrivate
, "fldpriv", 0 },
1933 { rtfFieldAttr
, rtfFieldAlt
, "fldalt", 0 },
1936 * Positioning attributes
1939 { rtfPosAttr
, rtfAbsWid
, "absw", 0 },
1940 { rtfPosAttr
, rtfAbsHt
, "absh", 0 },
1942 { rtfPosAttr
, rtfRPosMargH
, "phmrg", 0 },
1943 { rtfPosAttr
, rtfRPosPageH
, "phpg", 0 },
1944 { rtfPosAttr
, rtfRPosColH
, "phcol", 0 },
1945 { rtfPosAttr
, rtfPosX
, "posx", 0 },
1946 { rtfPosAttr
, rtfPosNegX
, "posnegx", 0 },
1947 { rtfPosAttr
, rtfPosXCenter
, "posxc", 0 },
1948 { rtfPosAttr
, rtfPosXInside
, "posxi", 0 },
1949 { rtfPosAttr
, rtfPosXOutSide
, "posxo", 0 },
1950 { rtfPosAttr
, rtfPosXRight
, "posxr", 0 },
1951 { rtfPosAttr
, rtfPosXLeft
, "posxl", 0 },
1953 { rtfPosAttr
, rtfRPosMargV
, "pvmrg", 0 },
1954 { rtfPosAttr
, rtfRPosPageV
, "pvpg", 0 },
1955 { rtfPosAttr
, rtfRPosParaV
, "pvpara", 0 },
1956 { rtfPosAttr
, rtfPosY
, "posy", 0 },
1957 { rtfPosAttr
, rtfPosNegY
, "posnegy", 0 },
1958 { rtfPosAttr
, rtfPosYInline
, "posyil", 0 },
1959 { rtfPosAttr
, rtfPosYTop
, "posyt", 0 },
1960 { rtfPosAttr
, rtfPosYCenter
, "posyc", 0 },
1961 { rtfPosAttr
, rtfPosYBottom
, "posyb", 0 },
1963 { rtfPosAttr
, rtfNoWrap
, "nowrap", 0 },
1964 { rtfPosAttr
, rtfDistFromTextAll
, "dxfrtext", 0 },
1965 { rtfPosAttr
, rtfDistFromTextX
, "dfrmtxtx", 0 },
1966 { rtfPosAttr
, rtfDistFromTextY
, "dfrmtxty", 0 },
1967 /* \dyfrtext no longer exists in spec 1.2, apparently */
1968 /* replaced by \dfrmtextx and \dfrmtexty. */
1969 { rtfPosAttr
, rtfTextDistY
, "dyfrtext", 0 },
1971 { rtfPosAttr
, rtfDropCapLines
, "dropcapli", 0 },
1972 { rtfPosAttr
, rtfDropCapType
, "dropcapt", 0 },
1978 { rtfObjAttr
, rtfObjEmb
, "objemb", 0 },
1979 { rtfObjAttr
, rtfObjLink
, "objlink", 0 },
1980 { rtfObjAttr
, rtfObjAutoLink
, "objautlink", 0 },
1981 { rtfObjAttr
, rtfObjSubscriber
, "objsub", 0 },
1982 { rtfObjAttr
, rtfObjPublisher
, "objpub", 0 },
1983 { rtfObjAttr
, rtfObjICEmb
, "objicemb", 0 },
1985 { rtfObjAttr
, rtfObjLinkSelf
, "linkself", 0 },
1986 { rtfObjAttr
, rtfObjLock
, "objupdate", 0 },
1987 { rtfObjAttr
, rtfObjUpdate
, "objlock", 0 },
1989 { rtfObjAttr
, rtfObjHt
, "objh", 0 },
1990 { rtfObjAttr
, rtfObjWid
, "objw", 0 },
1991 { rtfObjAttr
, rtfObjSetSize
, "objsetsize", 0 },
1992 { rtfObjAttr
, rtfObjAlign
, "objalign", 0 },
1993 { rtfObjAttr
, rtfObjTransposeY
, "objtransy", 0 },
1994 { rtfObjAttr
, rtfObjCropTop
, "objcropt", 0 },
1995 { rtfObjAttr
, rtfObjCropBottom
, "objcropb", 0 },
1996 { rtfObjAttr
, rtfObjCropLeft
, "objcropl", 0 },
1997 { rtfObjAttr
, rtfObjCropRight
, "objcropr", 0 },
1998 { rtfObjAttr
, rtfObjScaleX
, "objscalex", 0 },
1999 { rtfObjAttr
, rtfObjScaleY
, "objscaley", 0 },
2001 { rtfObjAttr
, rtfObjResRTF
, "rsltrtf", 0 },
2002 { rtfObjAttr
, rtfObjResPict
, "rsltpict", 0 },
2003 { rtfObjAttr
, rtfObjResBitmap
, "rsltbmp", 0 },
2004 { rtfObjAttr
, rtfObjResText
, "rslttxt", 0 },
2005 { rtfObjAttr
, rtfObjResMerge
, "rsltmerge", 0 },
2007 { rtfObjAttr
, rtfObjBookmarkPubObj
, "bkmkpub", 0 },
2008 { rtfObjAttr
, rtfObjPubAutoUpdate
, "pubauto", 0 },
2011 * Associated character formatting attributes
2014 { rtfACharAttr
, rtfACBold
, "ab", 0 },
2015 { rtfACharAttr
, rtfACAllCaps
, "caps", 0 },
2016 { rtfACharAttr
, rtfACForeColor
, "acf", 0 },
2017 { rtfACharAttr
, rtfACSubScript
, "adn", 0 },
2018 { rtfACharAttr
, rtfACExpand
, "aexpnd", 0 },
2019 { rtfACharAttr
, rtfACFontNum
, "af", 0 },
2020 { rtfACharAttr
, rtfACFontSize
, "afs", 0 },
2021 { rtfACharAttr
, rtfACItalic
, "ai", 0 },
2022 { rtfACharAttr
, rtfACLanguage
, "alang", 0 },
2023 { rtfACharAttr
, rtfACOutline
, "aoutl", 0 },
2024 { rtfACharAttr
, rtfACSmallCaps
, "ascaps", 0 },
2025 { rtfACharAttr
, rtfACShadow
, "ashad", 0 },
2026 { rtfACharAttr
, rtfACStrikeThru
, "astrike", 0 },
2027 { rtfACharAttr
, rtfACUnderline
, "aul", 0 },
2028 { rtfACharAttr
, rtfACDotUnderline
, "auld", 0 },
2029 { rtfACharAttr
, rtfACDbUnderline
, "auldb", 0 },
2030 { rtfACharAttr
, rtfACNoUnderline
, "aulnone", 0 },
2031 { rtfACharAttr
, rtfACWordUnderline
, "aulw", 0 },
2032 { rtfACharAttr
, rtfACSuperScript
, "aup", 0 },
2035 * Footnote attributes
2038 { rtfFNoteAttr
, rtfFNAlt
, "ftnalt", 0 },
2041 * Key code attributes
2044 { rtfKeyCodeAttr
, rtfAltKey
, "alt", 0 },
2045 { rtfKeyCodeAttr
, rtfShiftKey
, "shift", 0 },
2046 { rtfKeyCodeAttr
, rtfControlKey
, "ctrl", 0 },
2047 { rtfKeyCodeAttr
, rtfFunctionKey
, "fn", 0 },
2050 * Bookmark attributes
2053 { rtfBookmarkAttr
, rtfBookmarkFirstCol
, "bkmkcolf", 0 },
2054 { rtfBookmarkAttr
, rtfBookmarkLastCol
, "bkmkcoll", 0 },
2057 * Index entry attributes
2060 { rtfIndexAttr
, rtfIndexNumber
, "xef", 0 },
2061 { rtfIndexAttr
, rtfIndexBold
, "bxe", 0 },
2062 { rtfIndexAttr
, rtfIndexItalic
, "ixe", 0 },
2065 * Table of contents attributes
2068 { rtfTOCAttr
, rtfTOCType
, "tcf", 0 },
2069 { rtfTOCAttr
, rtfTOCLevel
, "tcl", 0 },
2072 * Drawing object attributes
2075 { rtfDrawAttr
, rtfDrawLock
, "dolock", 0 },
2076 { rtfDrawAttr
, rtfDrawPageRelX
, "doxpage", 0 },
2077 { rtfDrawAttr
, rtfDrawColumnRelX
, "dobxcolumn", 0 },
2078 { rtfDrawAttr
, rtfDrawMarginRelX
, "dobxmargin", 0 },
2079 { rtfDrawAttr
, rtfDrawPageRelY
, "dobypage", 0 },
2080 { rtfDrawAttr
, rtfDrawColumnRelY
, "dobycolumn", 0 },
2081 { rtfDrawAttr
, rtfDrawMarginRelY
, "dobymargin", 0 },
2082 { rtfDrawAttr
, rtfDrawHeight
, "dobhgt", 0 },
2084 { rtfDrawAttr
, rtfDrawBeginGroup
, "dpgroup", 0 },
2085 { rtfDrawAttr
, rtfDrawGroupCount
, "dpcount", 0 },
2086 { rtfDrawAttr
, rtfDrawEndGroup
, "dpendgroup", 0 },
2087 { rtfDrawAttr
, rtfDrawArc
, "dparc", 0 },
2088 { rtfDrawAttr
, rtfDrawCallout
, "dpcallout", 0 },
2089 { rtfDrawAttr
, rtfDrawEllipse
, "dpellipse", 0 },
2090 { rtfDrawAttr
, rtfDrawLine
, "dpline", 0 },
2091 { rtfDrawAttr
, rtfDrawPolygon
, "dppolygon", 0 },
2092 { rtfDrawAttr
, rtfDrawPolyLine
, "dppolyline", 0 },
2093 { rtfDrawAttr
, rtfDrawRect
, "dprect", 0 },
2094 { rtfDrawAttr
, rtfDrawTextBox
, "dptxbx", 0 },
2096 { rtfDrawAttr
, rtfDrawOffsetX
, "dpx", 0 },
2097 { rtfDrawAttr
, rtfDrawSizeX
, "dpxsize", 0 },
2098 { rtfDrawAttr
, rtfDrawOffsetY
, "dpy", 0 },
2099 { rtfDrawAttr
, rtfDrawSizeY
, "dpysize", 0 },
2101 { rtfDrawAttr
, rtfCOAngle
, "dpcoa", 0 },
2102 { rtfDrawAttr
, rtfCOAccentBar
, "dpcoaccent", 0 },
2103 { rtfDrawAttr
, rtfCOBestFit
, "dpcobestfit", 0 },
2104 { rtfDrawAttr
, rtfCOBorder
, "dpcoborder", 0 },
2105 { rtfDrawAttr
, rtfCOAttachAbsDist
, "dpcodabs", 0 },
2106 { rtfDrawAttr
, rtfCOAttachBottom
, "dpcodbottom", 0 },
2107 { rtfDrawAttr
, rtfCOAttachCenter
, "dpcodcenter", 0 },
2108 { rtfDrawAttr
, rtfCOAttachTop
, "dpcodtop", 0 },
2109 { rtfDrawAttr
, rtfCOLength
, "dpcolength", 0 },
2110 { rtfDrawAttr
, rtfCONegXQuadrant
, "dpcominusx", 0 },
2111 { rtfDrawAttr
, rtfCONegYQuadrant
, "dpcominusy", 0 },
2112 { rtfDrawAttr
, rtfCOOffset
, "dpcooffset", 0 },
2113 { rtfDrawAttr
, rtfCOAttachSmart
, "dpcosmarta", 0 },
2114 { rtfDrawAttr
, rtfCODoubleLine
, "dpcotdouble", 0 },
2115 { rtfDrawAttr
, rtfCORightAngle
, "dpcotright", 0 },
2116 { rtfDrawAttr
, rtfCOSingleLine
, "dpcotsingle", 0 },
2117 { rtfDrawAttr
, rtfCOTripleLine
, "dpcottriple", 0 },
2119 { rtfDrawAttr
, rtfDrawTextBoxMargin
, "dptxbxmar", 0 },
2120 { rtfDrawAttr
, rtfDrawTextBoxText
, "dptxbxtext", 0 },
2121 { rtfDrawAttr
, rtfDrawRoundRect
, "dproundr", 0 },
2123 { rtfDrawAttr
, rtfDrawPointX
, "dpptx", 0 },
2124 { rtfDrawAttr
, rtfDrawPointY
, "dppty", 0 },
2125 { rtfDrawAttr
, rtfDrawPolyCount
, "dppolycount", 0 },
2127 { rtfDrawAttr
, rtfDrawArcFlipX
, "dparcflipx", 0 },
2128 { rtfDrawAttr
, rtfDrawArcFlipY
, "dparcflipy", 0 },
2130 { rtfDrawAttr
, rtfDrawLineBlue
, "dplinecob", 0 },
2131 { rtfDrawAttr
, rtfDrawLineGreen
, "dplinecog", 0 },
2132 { rtfDrawAttr
, rtfDrawLineRed
, "dplinecor", 0 },
2133 { rtfDrawAttr
, rtfDrawLinePalette
, "dplinepal", 0 },
2134 { rtfDrawAttr
, rtfDrawLineDashDot
, "dplinedado", 0 },
2135 { rtfDrawAttr
, rtfDrawLineDashDotDot
, "dplinedadodo", 0 },
2136 { rtfDrawAttr
, rtfDrawLineDash
, "dplinedash", 0 },
2137 { rtfDrawAttr
, rtfDrawLineDot
, "dplinedot", 0 },
2138 { rtfDrawAttr
, rtfDrawLineGray
, "dplinegray", 0 },
2139 { rtfDrawAttr
, rtfDrawLineHollow
, "dplinehollow", 0 },
2140 { rtfDrawAttr
, rtfDrawLineSolid
, "dplinesolid", 0 },
2141 { rtfDrawAttr
, rtfDrawLineWidth
, "dplinew", 0 },
2143 { rtfDrawAttr
, rtfDrawHollowEndArrow
, "dpaendhol", 0 },
2144 { rtfDrawAttr
, rtfDrawEndArrowLength
, "dpaendl", 0 },
2145 { rtfDrawAttr
, rtfDrawSolidEndArrow
, "dpaendsol", 0 },
2146 { rtfDrawAttr
, rtfDrawEndArrowWidth
, "dpaendw", 0 },
2147 { rtfDrawAttr
, rtfDrawHollowStartArrow
,"dpastarthol", 0 },
2148 { rtfDrawAttr
, rtfDrawStartArrowLength
,"dpastartl", 0 },
2149 { rtfDrawAttr
, rtfDrawSolidStartArrow
, "dpastartsol", 0 },
2150 { rtfDrawAttr
, rtfDrawStartArrowWidth
, "dpastartw", 0 },
2152 { rtfDrawAttr
, rtfDrawBgFillBlue
, "dpfillbgcb", 0 },
2153 { rtfDrawAttr
, rtfDrawBgFillGreen
, "dpfillbgcg", 0 },
2154 { rtfDrawAttr
, rtfDrawBgFillRed
, "dpfillbgcr", 0 },
2155 { rtfDrawAttr
, rtfDrawBgFillPalette
, "dpfillbgpal", 0 },
2156 { rtfDrawAttr
, rtfDrawBgFillGray
, "dpfillbggray", 0 },
2157 { rtfDrawAttr
, rtfDrawFgFillBlue
, "dpfillfgcb", 0 },
2158 { rtfDrawAttr
, rtfDrawFgFillGreen
, "dpfillfgcg", 0 },
2159 { rtfDrawAttr
, rtfDrawFgFillRed
, "dpfillfgcr", 0 },
2160 { rtfDrawAttr
, rtfDrawFgFillPalette
, "dpfillfgpal", 0 },
2161 { rtfDrawAttr
, rtfDrawFgFillGray
, "dpfillfggray", 0 },
2162 { rtfDrawAttr
, rtfDrawFillPatIndex
, "dpfillpat", 0 },
2164 { rtfDrawAttr
, rtfDrawShadow
, "dpshadow", 0 },
2165 { rtfDrawAttr
, rtfDrawShadowXOffset
, "dpshadx", 0 },
2166 { rtfDrawAttr
, rtfDrawShadowYOffset
, "dpshady", 0 },
2168 { rtfVersion
, -1, "rtf", 0 },
2169 { rtfDefFont
, -1, "deff", 0 },
2173 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2175 typedef struct tagRTFHashTableEntry
{
2178 } RTFHashTableEntry
;
2180 static RTFHashTableEntry rtfHashTable
[RTF_KEY_COUNT
* 2];
2184 * Initialize lookup table hash values. Only need to do this once.
2187 void LookupInit(void)
2191 memset(rtfHashTable
, 0, sizeof rtfHashTable
);
2192 for (rp
= rtfKey
; rp
->rtfKStr
!= NULL
; rp
++)
2196 rp
->rtfKHash
= Hash (rp
->rtfKStr
);
2197 index
= rp
->rtfKHash
% (RTF_KEY_COUNT
* 2);
2198 if (!rtfHashTable
[index
].count
)
2199 rtfHashTable
[index
].value
= heap_alloc(sizeof(RTFKey
*));
2201 rtfHashTable
[index
].value
= heap_realloc(rtfHashTable
[index
].value
, sizeof(RTFKey
*) * (rtfHashTable
[index
].count
+ 1));
2202 rtfHashTable
[index
].value
[rtfHashTable
[index
].count
++] = rp
;
2206 void LookupCleanup(void)
2210 for (i
=0; i
<RTF_KEY_COUNT
*2; i
++)
2212 heap_free( rtfHashTable
[i
].value
);
2213 rtfHashTable
[i
].value
= NULL
;
2214 rtfHashTable
[i
].count
= 0;
2220 * Determine major and minor number of control token. If it's
2221 * not found, the class turns into rtfUnknown.
2224 static void Lookup(RTF_Info
*info
, char *s
)
2228 RTFHashTableEntry
*entry
;
2231 ++s
; /* skip over the leading \ character */
2233 entry
= &rtfHashTable
[hash
% (RTF_KEY_COUNT
* 2)];
2234 for (i
= 0; i
< entry
->count
; i
++)
2236 rp
= entry
->value
[i
];
2237 if (hash
== rp
->rtfKHash
&& strcmp (s
, rp
->rtfKStr
) == 0)
2239 info
->rtfClass
= rtfControl
;
2240 info
->rtfMajor
= rp
->rtfKMajor
;
2241 info
->rtfMinor
= rp
->rtfKMinor
;
2245 info
->rtfClass
= rtfUnknown
;
2250 * Compute hash value of symbol
2253 static int Hash(const char *s
)
2258 while ((c
= *s
++) != '\0')
2265 /* ---------------------------------------------------------------------- */
2269 * Token comparison routines
2272 int RTFCheckCM(const RTF_Info
*info
, int class, int major
)
2274 return (info
->rtfClass
== class && info
->rtfMajor
== major
);
2278 int RTFCheckCMM(const RTF_Info
*info
, int class, int major
, int minor
)
2280 return (info
->rtfClass
== class && info
->rtfMajor
== major
&& info
->rtfMinor
== minor
);
2284 int RTFCheckMM(const RTF_Info
*info
, int major
, int minor
)
2286 return (info
->rtfMajor
== major
&& info
->rtfMinor
== minor
);
2290 /* ---------------------------------------------------------------------- */
2293 int RTFCharToHex(char c
)
2298 return (c
- '0'); /* '0'..'9' */
2299 return (c
- 'a' + 10); /* 'a'..'f' */
2303 /* ---------------------------------------------------------------------- */
2306 * originally from RTF tools' text-writer.c
2308 * text-writer -- RTF-to-text translation writer code.
2310 * Read RTF input, write text of document (text extraction).
2313 static void TextClass (RTF_Info
*info
);
2314 static void ControlClass (RTF_Info
*info
);
2315 static void DefFont(RTF_Info
*info
);
2316 static void Destination (RTF_Info
*info
);
2317 static void SpecialChar (RTF_Info
*info
);
2318 static void RTFPutUnicodeChar (RTF_Info
*info
, int c
);
2321 * Initialize the writer.
2325 WriterInit (RTF_Info
*info
)
2331 BeginFile (RTF_Info
*info
)
2333 /* install class callbacks */
2335 RTFSetClassCallback (info
, rtfText
, TextClass
);
2336 RTFSetClassCallback (info
, rtfControl
, ControlClass
);
2342 * Write out a character.
2346 TextClass (RTF_Info
*info
)
2348 RTFPutCodePageChar(info
, info
->rtfMajor
);
2353 ControlClass (RTF_Info
*info
)
2355 switch (info
->rtfMajor
)
2359 ME_RTFCharAttrHook(info
);
2362 ME_RTFParAttrHook(info
);
2365 ME_RTFTblAttrHook(info
);
2373 case rtfDestination
:
2379 case rtfSpecialChar
:
2381 ME_RTFSpecialCharHook(info
);
2388 CharAttr(RTF_Info
*info
)
2392 switch (info
->rtfMinor
)
2395 font
= RTFGetFont(info
, info
->rtfParam
);
2398 if (info
->ansiCodePage
!= CP_UTF8
&& info
->codePage
!= font
->rtfFCodePage
)
2400 RTFFlushOutputBuffer(info
);
2401 info
->codePage
= font
->rtfFCodePage
;
2403 TRACE("font %d codepage %d\n", info
->rtfParam
, info
->codePage
);
2406 ERR( "unknown font %d\n", info
->rtfParam
);
2408 case rtfUnicodeLength
:
2409 info
->unicodeLength
= info
->rtfParam
;
2416 CharSet(RTF_Info
*info
)
2418 if (info
->ansiCodePage
== CP_UTF8
)
2421 switch (info
->rtfMinor
)
2423 case rtfAnsiCharSet
:
2424 info
->ansiCodePage
= 1252; /* Latin-1 */
2427 info
->ansiCodePage
= 10000; /* MacRoman */
2430 info
->ansiCodePage
= 437;
2433 info
->ansiCodePage
= 850;
2439 * This function notices destinations that aren't explicitly handled
2440 * and skips to their ends. This keeps, for instance, picture
2441 * data from being considered as plain text.
2445 Destination (RTF_Info
*info
)
2447 if (!RTFGetDestinationCallback(info
, info
->rtfMinor
))
2448 RTFSkipGroup (info
);
2453 DefFont(RTF_Info
*info
)
2455 TRACE("%d\n", info
->rtfParam
);
2456 info
->defFont
= info
->rtfParam
;
2461 DocAttr(RTF_Info
*info
)
2463 TRACE("minor %d, param %d\n", info
->rtfMinor
, info
->rtfParam
);
2465 switch (info
->rtfMinor
)
2467 case rtfAnsiCodePage
:
2468 info
->codePage
= info
->ansiCodePage
= info
->rtfParam
;
2471 info
->codePage
= info
->ansiCodePage
= CP_UTF8
;
2477 static void SpecialChar (RTF_Info
*info
)
2479 switch (info
->rtfMinor
)
2482 /* the next token determines destination, if it's unknown, skip the group */
2483 /* this way we filter out the garbage coming from unknown destinations */
2485 if (info
->rtfClass
!= rtfDestination
)
2488 RTFRouteToken(info
); /* "\*" is ignored with known destinations */
2494 RTFPutUnicodeChar(info
, info
->rtfParam
);
2496 /* After \u we must skip number of character tokens set by \ucN */
2497 for (i
= 0; i
< info
->unicodeLength
; i
++)
2500 if (info
->rtfClass
!= rtfText
)
2502 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2503 info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
2504 RTFUngetToken(info
);
2511 RTFFlushOutputBuffer(info
);
2512 ME_InsertEndRowFromCursor(info
->editor
, 0);
2517 RTFPutUnicodeChar (info
, '\r');
2518 if (info
->editor
->bEmulateVersion10
) RTFPutUnicodeChar (info
, '\n');
2521 RTFPutUnicodeChar (info
, 0x00A0);
2524 RTFPutUnicodeChar (info
, '\t');
2526 case rtfNoBrkHyphen
:
2527 RTFPutUnicodeChar (info
, 0x2011);
2530 RTFPutUnicodeChar (info
, 0x2022);
2533 RTFPutUnicodeChar (info
, 0x2014);
2536 RTFPutUnicodeChar (info
, 0x2013);
2539 RTFPutUnicodeChar (info
, 0x2018);
2542 RTFPutUnicodeChar (info
, 0x2019);
2545 RTFPutUnicodeChar (info
, 0x201C);
2548 RTFPutUnicodeChar (info
, 0x201D);
2555 RTFFlushUnicodeOutputBuffer(RTF_Info
*info
)
2557 if (info
->dwOutputCount
)
2559 ME_InsertTextFromCursor(info
->editor
, 0, info
->OutputBuffer
,
2560 info
->dwOutputCount
, info
->style
);
2561 info
->dwOutputCount
= 0;
2567 RTFPutUnicodeString(RTF_Info
*info
, const WCHAR
*string
, int length
)
2569 if (info
->dwCPOutputCount
)
2570 RTFFlushCPOutputBuffer(info
);
2573 int fit
= min(length
, sizeof(info
->OutputBuffer
) / sizeof(WCHAR
) - info
->dwOutputCount
);
2575 memmove(info
->OutputBuffer
+ info
->dwOutputCount
, string
, fit
* sizeof(WCHAR
));
2576 info
->dwOutputCount
+= fit
;
2579 if (sizeof(info
->OutputBuffer
) / sizeof(WCHAR
) == info
->dwOutputCount
)
2580 RTFFlushUnicodeOutputBuffer(info
);
2585 RTFFlushCPOutputBuffer(RTF_Info
*info
)
2587 int bufferMax
= info
->dwCPOutputCount
* 2 * sizeof(WCHAR
);
2588 WCHAR
*buffer
= heap_alloc(bufferMax
);
2591 length
= MultiByteToWideChar(info
->codePage
, 0, info
->cpOutputBuffer
,
2592 info
->dwCPOutputCount
, buffer
, bufferMax
/sizeof(WCHAR
));
2593 info
->dwCPOutputCount
= 0;
2595 RTFPutUnicodeString(info
, buffer
, length
);
2600 RTFFlushOutputBuffer(RTF_Info
*info
)
2602 if (info
->dwCPOutputCount
)
2603 RTFFlushCPOutputBuffer(info
);
2604 RTFFlushUnicodeOutputBuffer(info
);
2608 RTFPutUnicodeChar(RTF_Info
*info
, int c
)
2610 if (info
->dwCPOutputCount
)
2611 RTFFlushCPOutputBuffer(info
);
2612 if (info
->dwOutputCount
* sizeof(WCHAR
) >= ( sizeof info
->OutputBuffer
- 1 ) )
2613 RTFFlushUnicodeOutputBuffer( info
);
2614 info
->OutputBuffer
[info
->dwOutputCount
++] = c
;
2618 RTFPutCodePageChar(RTF_Info
*info
, int c
)
2620 /* Use dynamic buffer here because it's the best way to handle
2621 * MBCS codepages without having to worry about partial chars */
2622 if (info
->dwCPOutputCount
>= info
->dwMaxCPOutputCount
)
2624 info
->dwMaxCPOutputCount
*= 2;
2625 info
->cpOutputBuffer
= heap_realloc(info
->cpOutputBuffer
, info
->dwMaxCPOutputCount
);
2627 info
->cpOutputBuffer
[info
->dwCPOutputCount
++] = c
;