1 /************************************************************************/
2 /*									*/
3 /*  Exchange text properties with an RTF file.				*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docRtfConfig.h"
8 
9 #   include	<stdio.h>
10 #   include	<ctype.h>
11 
12 #   include	<appDebugon.h>
13 
14 #   include	"docRtfReaderImpl.h"
15 #   include	"docRtfFlags.h"
16 
17 /************************************************************************/
18 /*									*/
19 /*  Handle a text property when reading RTF.				*/
20 /*									*/
21 /************************************************************************/
22 
docRtfRememberTextPropertyImpl(TextAttribute * ta,const RtfControlWord * rcw,int arg,RtfReader * rrc)23 static int docRtfRememberTextPropertyImpl(	TextAttribute *		ta,
24 						const RtfControlWord *	rcw,
25 						int			arg,
26 						RtfReader *		rrc )
27     {
28     switch( rcw->rcwID )
29 	{
30 	case TAprop_NONE:
31 	    docPlainTextAttribute( ta, rrc->rrDocument );
32 	    return 0;
33 
34 	case TApropFONTSIZE:
35 	    if  ( arg < 1 || arg > 2000 )
36 		{ LSLDEB(rrc->rrCurrentLine,rcw->rcwWord,arg); arg= 20; }
37 	    break;
38 
39 	case TApropBORDER:
40 	    arg= docRtfReadGetBorderNumber( rrc );
41 	    if  ( arg < 0 )
42 		{ LDEB(arg); return -1;	}
43 	    break;
44 
45 	default:
46 	    break;
47 	}
48 
49     if  ( utilSetTextProperty( ta, rcw->rcwID, arg ) < 0 )
50 	{ SLDEB(rcw->rcwWord,arg); return -1;	}
51 
52     return 0;
53     }
54 
docRtfRememberTextShadingProperty(const RtfControlWord * rcw,int arg,RtfReader * rrc)55 int docRtfRememberTextShadingProperty(	const RtfControlWord *	rcw,
56 					int			arg,
57 					RtfReader *	rrc )
58     {
59     RtfReadingState *	rrs= rrc->rrcState;
60 
61     if  ( docSetShadingProperty( &(rrs->rrsTextShading),
62 						    rcw->rcwID, arg ) < 0 )
63 	{ SLDEB(rcw->rcwWord,arg); return -1;	}
64 
65     rrs->rrsTextShadingChanged= 1;
66 
67     return 0;
68     }
69 
docRtfRememberTextProperty(const RtfControlWord * rcw,int arg,RtfReader * rrc)70 int docRtfRememberTextProperty(		const RtfControlWord *	rcw,
71 					int			arg,
72 					RtfReader *		rrc )
73     {
74     RtfReadingState *	rrs= rrc->rrcState;
75 
76     if  ( rcw->rcwID == TApropTEXT_STYLE )
77 	{
78 	const	DocumentStyleSheet *	dss= &(rrc->rrDocument->bdStyleSheet);
79 
80 	rrc->rrcStyle.dsLevel= DOClevSPAN;
81 
82 	if  ( arg >= 0 && arg < dss->dssStyleCount )
83 	    {
84 	    const DocumentStyle *	ds= dss->dssStyles[arg];
85 
86 	    if  ( ds && ds->dsLevel == DOClevSPAN )
87 		{
88 		PropertyMask	doneMask;
89 
90 		if  ( rrs->rrsTextShadingChanged )
91 		    { docRtfRefreshTextShading( rrc, rrs );	}
92 
93 		utilUpdateTextAttribute( &doneMask, &(rrs->rrsTextAttribute),
94 				&(ds->dsTextMask), &(ds->dsTextAttribute) );
95 		}
96 	    }
97 	}
98 
99     /* Also used to start a font in the font list		*/
100     if  ( rcw->rcwID == TApropFONT_NUMBER )
101 	{
102 	docRtfRestartFont( rrc );
103 
104 	rrc->rrcCurrentEncodedFont.ecFileFontNumber= arg;
105 
106 	if  ( ! ( rrc->rrReadFlags & RTFflagUNENCODED ) )
107 	    {
108 	    if  ( ! docRtfReadMapFont( rrc,
109 			    &(rrc->rrcCurrentEncodedFont.ecBufFontNumber),
110 			    &(rrc->rrcCurrentEncodedFont.ecCharset),
111 			    rrc->rrcCurrentEncodedFont.ecFileFontNumber ) )
112 		{
113 		rrc->rrcCurrentFont.dfDocFontNumber=
114 				    rrc->rrcCurrentEncodedFont.ecBufFontNumber;
115 		rrs->rrsTextCharset= rrc->rrcCurrentEncodedFont.ecCharset;
116 
117 		arg= rrc->rrcCurrentEncodedFont.ecBufFontNumber;
118 		}
119 	    }
120 	else{
121 	    rrc->rrcCurrentEncodedFont.ecBufFontNumber=
122 				rrc->rrcCurrentEncodedFont.ecFileFontNumber;
123 	    }
124 	}
125 
126     if  ( rcw->rcwID == TAprop_NONE )
127 	{
128 	docInitItemShading( &(rrs->rrsTextShading) );
129 	rrs->rrsTextShadingChanged= 0;
130 	}
131 
132     if  ( docRtfRememberTextPropertyImpl( &(rrs->rrsTextAttribute),
133 							    rcw, arg, rrc ) )
134 	{ SDEB(rcw->rcwWord); return -1;	}
135 
136     if  ( rcw->rcwID != TAprop_NONE && rcw->rcwID < TAprop_COUNT )
137 	{ PROPmaskADD( &(rrc->rrcStyle.dsTextMask), rcw->rcwID ); }
138 
139     return 0;
140     }
141 
docRtfRememberPntextProperty(const RtfControlWord * rcw,int arg,RtfReader * rrc)142 int docRtfRememberPntextProperty(	const RtfControlWord *	rcw,
143 					int			arg,
144 					RtfReader *		rrc )
145     {
146     /* Also used to start a font in the font list		*/
147     if  ( rcw->rcwID == TApropFONT_NUMBER )
148 	{
149 	int		bufFontNum;
150 	int		charset;
151 
152 	if  ( ! docRtfReadMapFont( rrc, &bufFontNum, &charset, arg ) )
153 	    { arg= bufFontNum;	}
154 	}
155 
156     if  ( rcw->rcwID == TAprop_NONE )
157 	{
158 	docInitItemShading( &(rrc->rrcParagraphNumberTextShading) );
159 	/*rrc->rrcParagraphNumberTextShadingChanged= 0;*/
160 	}
161 
162     if  ( docRtfRememberTextPropertyImpl(
163 		&(rrc->rrcParagraphNumber.pnTextAttribute), rcw, arg, rrc ) )
164 	{ SDEB(rcw->rcwWord); return -1;	}
165 
166     return 0;
167     }
168 
docRtfResetTextAttribute(RtfReadingState * rrs,BufferDocument * bd)169 void docRtfResetTextAttribute(	RtfReadingState *	rrs,
170 				BufferDocument *	bd )
171     {
172     docPlainTextAttribute( &(rrs->rrsTextAttribute), bd );
173     docInitItemShading( &(rrs->rrsTextShading) );
174     rrs->rrsTextShadingChanged= 0;
175 
176     return;
177     }
178 
179 /************************************************************************/
180 /*									*/
181 /*  Translate the separate text shading properties that we have		*/
182 /*  collected to a shading number.					*/
183 /*									*/
184 /************************************************************************/
185 
docRtfRefreshTextShading(RtfReader * rrc,RtfReadingState * rrs)186 void docRtfRefreshTextShading(	RtfReader *		rrc,
187 				RtfReadingState *	rrs )
188     {
189     rrs->rrsTextAttribute.taShadingNumber= docItemShadingNumber(
190 				    rrc->rrDocument, &(rrs->rrsTextShading) );
191     rrs->rrsTextShadingChanged= 0;
192 
193     return;
194     }
195 
196