1 /************************************************************************/
2 /*									*/
3 /*  Writing RTF.							*/
4 /*									*/
5 /************************************************************************/
6 
7 #   ifndef		RTF_WRITER_IMPL_H
8 #   define		RTF_WRITER_IMPL_H
9 
10 #   include	<docBuf.h>
11 #   include	<sioGeneral.h>
12 #   include	"docRtfWriter.h"
13 
14 struct TabStopList;
15 
16 /************************************************************************/
17 /*									*/
18 /*  The writer.								*/
19 /*									*/
20 /************************************************************************/
21 
22 typedef struct PushedAttribute
23     {
24     struct PushedAttribute *	paNext;
25     TextAttribute		paTextAttribute;
26     int				paTextCharset;
27     } PushedAttribute;
28 
29 struct RtfWriter
30     {
31     struct BufferDocument *	rwDocument;
32 				/**
33 				 *  The current text attribute. The state of
34 				 *  the writer is also determined by the charset
35 				 *  of the current text, as the RTF file format
36 				 *  includes the charset of the text in the
37 				 *  identity of the font.
38 				 */
39     TextAttribute		rwTextAttribute;
40 				/**
41 				 *  The rtf charset of the current text attribute.
42 				 *  This is needed as the RTF file format
43 				 *  represents text with 8-bit characters belonging
44 				 *  to different fonts if there are too many
45 				 *  different characters in the font.
46 				 */
47     int				rwTextCharset;
48     ParagraphProperties		rwcParagraphProperties;
49     RowProperties		rwRowProperties;
50 
51     ParagraphProperties		rwcOutsideTableParagraphProperties;
52 
53     PagedList			rwcEncodedFontList;
54 
55     PushedAttribute *		rwcPushedAttribute;
56     int				rwcInFldrslt;
57 				/**
58 				  *  The current depth of table nesting:
59 				  *  0: outside tables, 1: In table,
60 				  *  2+: in a nested table.
61 				  */
62     int				rwTableNesting;
63 				/**
64 				  *  The deepest depth of table nesting:
65 				  *  If the value >1, Ted will emit
66 				  *  itap tags along with intbl tags.
67 				  *  This is because itap tags confuse wordpad.
68 				  */
69     int				rwDeepestTableNesting;
70 
71 				/**
72 				  *  While writing a selection, it is not
73 				  *  obvious that the section properties
74 				  *  are saved: If the selection is contained
75 				  *  in a single child of the section, we
76 				  *  start in that child. So we never actually
77 				  *  enter the section node.
78 				  */
79     int				rwSectionPropertiesSaved;
80 
81     int				rwcAfter;
82 #				define RTFafterTAG	'T'
83 #				define RTFafterARG	'0'
84 #				define RTFafterTEXT	'*'
85     int				rwcLastNodeLevel;
86 
87     int				rwSaveFlags;
88 
89     int				rwCol;
90     SimpleOutputStream *	rwSosOut;
91 
92 				/**
93 				 * Used for RTF conversions. I.E where
94 				 * no font applies
95 				 */
96     struct TextConverter *	rwRtfTextConverter;
97 				/**
98 				 * Used for Text conversions. I.E where
99 				 * a font applies
100 				 */
101     struct TextConverter *	rwTextTextConverter;
102 
103     const PropertyMask *	rwPpExtraMask;
104     const PropertyMask *	rwCpExtraMask;
105     const PropertyMask *	rwRpExtraMask;
106     const PropertyMask *	rwSpExtraMask;
107     };
108 
109 /************************************************************************/
110 /*									*/
111 /*  Routine declarations.						*/
112 /*									*/
113 /************************************************************************/
114 
115 extern int docRtfWriteArgTag(		RtfWriter *		rwc,
116 					const char *		tag,
117 					int			arg );
118 
119 extern void docRtfWriteFlagTag(		RtfWriter *		rwc,
120 					const char *		tag,
121 					int			arg );
122 
123 extern void docRtfWriteAltTag(		RtfWriter *		rwc,
124 					const char *		yesTag,
125 					const char *		noTag,
126 					int			arg );
127 
128 extern void docRtfWriteEnumTag(		RtfWriter *		rwc,
129 					const char * const *	tags,
130 					int			arg,
131 					int			tagCount,
132 					int			enumCount );
133 
134 extern int docRtfWriteTag(		RtfWriter *		rwc,
135 					const char *		tag );
136 
137 extern void docRtfWriteDocEncodedString(RtfWriter *		rwc,
138 					const char *		s,
139 					int			n );
140 
141 extern void docRtfWriteFontEncodedString( RtfWriter *	rwc,
142 					const char *		s,
143 					int			n );
144 
145 extern void docRtfWriteRawBytes(	RtfWriter *	rwc,
146 					const char *		s,
147 					int			n );
148 
149 extern void docRtfWriteDocEncodedStringDestination(
150 					RtfWriter *		rwc,
151 					const char *		tag,
152 					const char *		s,
153 					int			n,
154 					int			addSemicolon );
155 
156 extern void docRtfWriteRawBytesDestination(
157 					RtfWriter *		rwc,
158 					const char *		tag,
159 					const char *		s,
160 					int			n );
161 
162 extern void docRtfWriteNextLine(	RtfWriter *		rwc );
163 
164 extern void docRtfSaveBorderByNumber(	RtfWriter *			rwc,
165 					const char *			tag,
166 					int				num,
167 					int				anywy );
168 
169 extern void docRtfSaveTextAttribute(	RtfWriter *		rwc,
170 					const PropertyMask *	updMask,
171 					const TextAttribute *	ta );
172 
173 extern void docRtfSaveParagraphProperties(
174 				RtfWriter *			rwc,
175 				const PropertyMask *		updMask,
176 				const ParagraphProperties *	pp );
177 
178 extern int docRtfWriteDestinationBegin( RtfWriter *		rwc,
179 					const char *		tag );
180 
181 extern int docRtfWriteDestinationEnd(	RtfWriter *		rwc );
182 
183 extern int docRtfSavePictureTags(
184 				RtfWriter *			rwc,
185 				const PropertyMask *		pipSetMask,
186 				const PictureProperties *	pipSet );
187 
188 extern int docRtfPicturePropertyMask(
189 				PropertyMask *			pipSetMask,
190 				const PictureProperties *	pipSet );
191 
192 extern int docRtfWriteMemoryBuffer(	RtfWriter *			rwc,
193 					const MemoryBuffer *		mb );
194 
195 extern void docRtfSaveSectionProperties( RtfWriter *		rwc,
196 				const PropertyMask *		updMask,
197 				const SectionProperties *	sp );
198 
199 extern int docRtfSaveSectionPropertiesOfNode(
200 				RtfWriter *			rwc,
201 				const DocumentSelection *	ds,
202 				const struct BufferItem *	sectNode );
203 
204 extern int docRtfWriteGetDefaultFont(
205 				RtfWriter *			rw,
206 				int				deff );
207 
208 extern void docRtfWriteFontTable( RtfWriter *			rwc );
209 
210 extern int docRtfWriteColorTable( RtfWriter *			rwc,
211 				const DocumentProperties *	dp );
212 
213 extern void docRtfWriteStyleSheet(
214 				RtfWriter *			rwc,
215 				const DocumentStyleSheet *	dss );
216 
217 extern int docRtfWriteArgDestinationBegin( RtfWriter *		rwc,
218 					const char *		tag,
219 					int			arg );
220 
221 extern int docRtfSaveDocumentProperties( RtfWriter *			rwc,
222 					int				fet,
223 					const PropertyMask *		dpMask,
224 					const DocumentProperties *	dp );
225 
226 extern int docRtfSaveNotesProperties(
227 		RtfWriter *			rw,
228 		const PropertyMask *		mask,
229 		const NotesProperties *		np,
230 		const int			propMap[NOTESprop_COUNT],
231 		const char *			startNrTag,
232 		const char * const *		justificationTags,
233 		int				justificationTagCount,
234 		const char * const *		placementTags,
235 		int				placementTagCount,
236 		const char * const *		restartTags,
237 		int				restartTagCount,
238 		const char * const *		styleTags,
239 		int				styleTagCount );
240 
241 extern void docRtfSaveParaFrameProperties(
242 				RtfWriter *			rwc,
243 				const FrameProperties *		fp );
244 extern void docRtfSaveRowFrameProperties(
245 				RtfWriter *			rwc,
246 				const FrameProperties *		fp );
247 
248 extern int docRtfSaveSectHeadersFooters( RtfWriter *		rwc,
249 					const struct BufferItem *	bi );
250 
251 extern int docRtfSaveHeaderFooter(	RtfWriter *		rwc,
252 					const DocumentTree *	dt );
253 
254 extern int docRtfSaveDocumentTree(	RtfWriter *		rwc,
255 					const char *		tag,
256 					const DocumentTree *	dt,
257 					int			evenIfAbsent,
258 					int			forcePar );
259 
260 extern int docRtfSaveDocNotesSeparators( RtfWriter *		rwc,
261 					const BufferDocument *	bd );
262 
263 extern void docRtfSaveCellProperties(	RtfWriter *		rwc,
264 					const PropertyMask *	cpSetMask,
265 					const CellProperties *	cpSet,
266 					int			shiftLeft );
267 
268 extern void docRtfSaveRowProperties(	RtfWriter *		rwc,
269 					const PropertyMask *	rpSetMask,
270 					const RowProperties *	rpSet,
271 					int			col0,
272 					int			col1 );
273 
274 extern void docRtfSaveAutoSpace(	RtfWriter *		rwc,
275 					const char *		unitTag,
276 					int			unit,
277 					const char *		numberTag,
278 					int			number );
279 
280 extern int docRtfWriteListProps(	RtfWriter *			rw,
281 					const struct DocumentList *	dl );
282 
283 extern void docRtfWriteListTable(
284 				RtfWriter *			rwc,
285 				const DocumentListTable *	dlt );
286 
287 extern void docRtfWriteListOverrideTable(
288 				RtfWriter *			rwc,
289 				const ListOverrideTable *	lot );
290 
291 extern void docRtfWriteListLevel(
292 				RtfWriter *			rwc,
293 				const struct ListLevel *	ll );
294 
295 extern void docRtfSaveTabStopList(
296 				RtfWriter *			rwc,
297 				const struct TabStopList *	tsl );
298 
299 extern void docRtfSaveShadingByNumber(	RtfWriter *		rwc,
300 					int			num,
301 					const char * const *	patTags,
302 					int			patTagCount,
303 					const char *		foreTag,
304 					const char *		backTag,
305 					const char *		levelTag );
306 
307 extern void docRtfReserveColumns(	RtfWriter *		rwc,
308 					int			cols );
309 
310 extern int docRtfSaveParaNode(	RtfWriter *			rwc,
311 				const struct BufferItem *	bi,
312 				const DocumentSelection *	ds,
313 				const int			flattenCell,
314 				const int			firstInRow );
315 
316 extern void docRtfWriteSemicolon(	RtfWriter *	rwc );
317 
318 extern void docRtfSaveParaTableNesting(	RtfWriter *		rwc,
319 					int			nest );
320 
321 extern int docRtfPushAttribute(		RtfWriter *	rwc );
322 extern int docRtfPopAttribute(		RtfWriter *	rwc );
323 
324 extern void docRtfWriteSwitchTextAttributes(
325 					RtfWriter *		rwc,
326 					int			textAttrNr,
327 					const char *		first );
328 
329 extern void docRtfWriteSwitchToPlain(	RtfWriter *		rwc );
330 
331 extern int docRtfWriteBuildFontAdmin(	RtfWriter *		rwc );
332 
333 extern int docRtfWriteGetCharset(
334 				RtfWriter *			rwc,
335 				int *				pCharset,
336 				const DocumentFont *		df,
337 				int				symbol );
338 
339 
340 extern int docRtfSaveFieldHead(		RtfWriter *		rwc,
341 					const struct BufferItem *	paraNode,
342 					int			part );
343 
344 extern int docRtfSaveFieldTail(		RtfWriter *		rwc,
345 					const struct BufferItem *	paraNode,
346 					int			part );
347 
348 extern int docRtfDocPropMask(	PropertyMask *			dpSaveMask,
349 				const DocumentProperties *	dpDoc );
350 
351 extern int docRtfWriteSelection(	RtfWriter *			rw,
352 					const DocumentSelection *	ds );
353 
354 extern int docRtfSaveDate(		RtfWriter *		rw,
355 					const char *		tag,
356 					const struct tm *	tm );
357 
358 extern void docRtfWriteSetupTextConverters(	RtfWriter *	rw );
359 
360 #   endif	/*	RTF_WRITER_IMPL_H	*/
361