Imported from antiword-0.37.tar.gz.
[antiword.git] / output.c
blobb2757ab9affae7da10759ccb4591136f7671ef07
1 /*
2 * output.c
3 * Copyright (C) 2002-2004 A.J. van Os; Released under GNU GPL
5 * Description:
6 * Generic output generating functions
7 */
9 #include "antiword.h"
11 static conversion_type eConversionType = conversion_unknown;
12 static encoding_type eEncoding = encoding_neutral;
16 * vPrologue1 - get options and call a specific initialization
18 static void
19 vPrologue1(diagram_type *pDiag, const char *szTask, const char *szFilename)
21 options_type tOptions;
23 fail(pDiag == NULL);
24 fail(szTask == NULL || szTask[0] == '\0');
26 vGetOptions(&tOptions);
27 eConversionType = tOptions.eConversionType;
28 eEncoding = tOptions.eEncoding;
30 switch (eConversionType) {
31 case conversion_text:
32 vPrologueTXT(pDiag, &tOptions);
33 break;
34 case conversion_fmt_text:
35 vPrologueFMT(pDiag, &tOptions);
36 break;
37 case conversion_ps:
38 vProloguePS(pDiag, szTask, szFilename, &tOptions);
39 break;
40 case conversion_xml:
41 vPrologueXML(pDiag, &tOptions);
42 break;
43 case conversion_pdf:
44 vProloguePDF(pDiag, szTask, &tOptions);
45 break;
46 default:
47 DBG_DEC(eConversionType);
48 break;
50 } /* end of vPrologue1 */
53 * vEpilogue - clean up after everything is done
55 static void
56 vEpilogue(diagram_type *pDiag)
58 switch (eConversionType) {
59 case conversion_text:
60 case conversion_fmt_text:
61 vEpilogueTXT(pDiag->pOutFile);
62 break;
63 case conversion_ps:
64 vEpiloguePS(pDiag);
65 break;
66 case conversion_xml:
67 vEpilogueXML(pDiag);
68 break;
69 case conversion_pdf:
70 vEpiloguePDF(pDiag);
71 break;
72 default:
73 DBG_DEC(eConversionType);
74 break;
76 } /* end of vEpilogue */
79 * vImagePrologue - perform image initialization
81 void
82 vImagePrologue(diagram_type *pDiag, const imagedata_type *pImg)
84 switch (eConversionType) {
85 case conversion_text:
86 case conversion_fmt_text:
87 break;
88 case conversion_ps:
89 vImageProloguePS(pDiag, pImg);
90 break;
91 case conversion_xml:
92 break;
93 case conversion_pdf:
94 vImageProloguePDF(pDiag, pImg);
95 break;
96 default:
97 DBG_DEC(eConversionType);
98 break;
100 } /* end of vImagePrologue */
103 * vImageEpilogue - clean up an image
105 void
106 vImageEpilogue(diagram_type *pDiag)
108 switch (eConversionType) {
109 case conversion_text:
110 case conversion_fmt_text:
111 break;
112 case conversion_ps:
113 vImageEpiloguePS(pDiag);
114 break;
115 case conversion_xml:
116 break;
117 case conversion_pdf:
118 vImageEpiloguePDF(pDiag);
119 break;
120 default:
121 DBG_DEC(eConversionType);
122 break;
124 } /* end of vImageEpilogue */
127 * bAddDummyImage - add a dummy image
129 * return TRUE when successful, otherwise FALSE
131 BOOL
132 bAddDummyImage(diagram_type *pDiag, const imagedata_type *pImg)
134 switch (eConversionType) {
135 case conversion_text:
136 case conversion_fmt_text:
137 return FALSE;
138 case conversion_ps:
139 return bAddDummyImagePS(pDiag, pImg);
140 case conversion_xml:
141 return FALSE;
142 case conversion_pdf:
143 return bAddDummyImagePDF(pDiag, pImg);
144 default:
145 DBG_DEC(eConversionType);
146 return FALSE;
148 } /* end of bAddDummyImage */
151 * pCreateDiagram - create and initialize a diagram
153 * remark: does not return if the diagram can't be created
155 diagram_type *
156 pCreateDiagram(const char *szTask, const char *szFilename)
158 diagram_type *pDiag;
160 fail(szTask == NULL || szTask[0] == '\0');
161 DBG_MSG("pCreateDiagram");
163 /* Get the necessary memory */
164 pDiag = xmalloc(sizeof(diagram_type));
165 /* Initialization */
166 pDiag->pOutFile = stdout;
167 vPrologue1(pDiag, szTask, szFilename);
168 /* Return success */
169 return pDiag;
170 } /* end of pCreateDiagram */
173 * vDestroyDiagram - remove a diagram by freeing the memory it uses
175 void
176 vDestroyDiagram(diagram_type *pDiag)
178 DBG_MSG("vDestroyDiagram");
180 fail(pDiag == NULL);
182 if (pDiag == NULL) {
183 return;
185 vEpilogue(pDiag);
186 pDiag = xfree(pDiag);
187 } /* end of vDestroyDiagram */
190 * vPrologue2 - call a specific initialization
192 void
193 vPrologue2(diagram_type *pDiag, int iWordVersion)
195 switch (eConversionType) {
196 case conversion_text:
197 case conversion_fmt_text:
198 break;
199 case conversion_ps:
200 vAddFontsPS(pDiag);
201 break;
202 case conversion_xml:
203 vCreateBookIntro(pDiag, iWordVersion);
204 break;
205 case conversion_pdf:
206 vCreateInfoDictionary(pDiag, iWordVersion);
207 vAddFontsPDF(pDiag);
208 break;
209 default:
210 DBG_DEC(eConversionType);
211 break;
213 } /* end of vPrologue2 */
216 * vMove2NextLine - move to the next line
218 void
219 vMove2NextLine(diagram_type *pDiag, drawfile_fontref tFontRef,
220 USHORT usFontSize)
222 fail(pDiag == NULL);
223 fail(pDiag->pOutFile == NULL);
224 fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);
226 switch (eConversionType) {
227 case conversion_text:
228 case conversion_fmt_text:
229 vMove2NextLineTXT(pDiag);
230 break;
231 case conversion_ps:
232 vMove2NextLinePS(pDiag, usFontSize);
233 break;
234 case conversion_xml:
235 vMove2NextLineXML(pDiag);
236 break;
237 case conversion_pdf:
238 vMove2NextLinePDF(pDiag, usFontSize);
239 break;
240 default:
241 DBG_DEC(eConversionType);
242 break;
244 } /* end of vMove2NextLine */
247 * vSubstring2Diagram - put a sub string into a diagram
249 void
250 vSubstring2Diagram(diagram_type *pDiag,
251 char *szString, size_t tStringLength, long lStringWidth,
252 UCHAR ucFontColor, USHORT usFontstyle, drawfile_fontref tFontRef,
253 USHORT usFontSize, USHORT usMaxFontSize)
255 switch (eConversionType) {
256 case conversion_text:
257 vSubstringTXT(pDiag, szString, tStringLength, lStringWidth);
258 break;
259 case conversion_fmt_text:
260 vSubstringFMT(pDiag, szString, tStringLength, lStringWidth,
261 usFontstyle);
262 break;
263 case conversion_ps:
264 vSubstringPS(pDiag, szString, tStringLength, lStringWidth,
265 ucFontColor, usFontstyle, tFontRef,
266 usFontSize, usMaxFontSize);
267 break;
268 case conversion_xml:
269 vSubstringXML(pDiag, szString, tStringLength, lStringWidth,
270 usFontstyle);
271 break;
272 case conversion_pdf:
273 vSubstringPDF(pDiag, szString, tStringLength, lStringWidth,
274 ucFontColor, usFontstyle, tFontRef,
275 usFontSize, usMaxFontSize);
276 break;
277 default:
278 DBG_DEC(eConversionType);
279 break;
281 pDiag->lXleft += lStringWidth;
282 } /* end of vSubstring2Diagram */
285 * Create a start of paragraph (phase 1)
286 * Before indentation, list numbering, bullets etc.
288 void
289 vStartOfParagraph1(diagram_type *pDiag, long lBeforeIndentation)
291 fail(pDiag == NULL);
293 switch (eConversionType) {
294 case conversion_text:
295 case conversion_fmt_text:
296 vStartOfParagraphTXT(pDiag, lBeforeIndentation);
297 break;
298 case conversion_ps:
299 vStartOfParagraphPS(pDiag, lBeforeIndentation);
300 break;
301 case conversion_xml:
302 break;
303 case conversion_pdf:
304 vStartOfParagraphPDF(pDiag, lBeforeIndentation);
305 break;
306 default:
307 DBG_DEC(eConversionType);
308 break;
310 } /* end of vStartOfParagraph1 */
313 * Create a start of paragraph (phase 2)
314 * After indentation, list numbering, bullets etc.
316 void
317 vStartOfParagraph2(diagram_type *pDiag)
319 fail(pDiag == NULL);
321 switch (eConversionType) {
322 case conversion_text:
323 case conversion_fmt_text:
324 break;
325 case conversion_ps:
326 break;
327 case conversion_xml:
328 vStartOfParagraphXML(pDiag, 1);
329 break;
330 case conversion_pdf:
331 break;
332 default:
333 DBG_DEC(eConversionType);
334 break;
336 } /* end of vStartOfParagraph2 */
339 * Create an end of paragraph
341 void
342 vEndOfParagraph(diagram_type *pDiag,
343 drawfile_fontref tFontRef, USHORT usFontSize, long lAfterIndentation)
345 fail(pDiag == NULL);
346 fail(pDiag->pOutFile == NULL);
347 fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);
348 fail(lAfterIndentation < 0);
350 switch (eConversionType) {
351 case conversion_text:
352 case conversion_fmt_text:
353 vEndOfParagraphTXT(pDiag, lAfterIndentation);
354 break;
355 case conversion_ps:
356 vEndOfParagraphPS(pDiag, usFontSize, lAfterIndentation);
357 break;
358 case conversion_xml:
359 vEndOfParagraphXML(pDiag, 1);
360 break;
361 case conversion_pdf:
362 vEndOfParagraphPDF(pDiag, usFontSize, lAfterIndentation);
363 break;
364 default:
365 DBG_DEC(eConversionType);
366 break;
368 } /* end of vEndOfParagraph */
371 * Create an end of page
373 void
374 vEndOfPage(diagram_type *pDiag, long lAfterIndentation, BOOL bNewSection)
376 switch (eConversionType) {
377 case conversion_text:
378 case conversion_fmt_text:
379 vEndOfPageTXT(pDiag, lAfterIndentation);
380 break;
381 case conversion_ps:
382 vEndOfPagePS(pDiag, bNewSection);
383 break;
384 case conversion_xml:
385 vEndOfPageXML(pDiag);
386 break;
387 case conversion_pdf:
388 vEndOfPagePDF(pDiag, bNewSection);
389 break;
390 default:
391 DBG_DEC(eConversionType);
392 break;
394 } /* end of vEndOfPage */
397 * vSetHeaders - set the headers
399 void
400 vSetHeaders(diagram_type *pDiag, USHORT usIstd)
402 switch (eConversionType) {
403 case conversion_text:
404 case conversion_fmt_text:
405 break;
406 case conversion_ps:
407 break;
408 case conversion_xml:
409 vSetHeadersXML(pDiag, usIstd);
410 break;
411 case conversion_pdf:
412 break;
413 default:
414 DBG_DEC(eConversionType);
415 break;
417 } /* end of vSetHeaders */
420 * Create a start of list
422 void
423 vStartOfList(diagram_type *pDiag, UCHAR ucNFC, BOOL bIsEndOfTable)
425 switch (eConversionType) {
426 case conversion_text:
427 case conversion_fmt_text:
428 break;
429 case conversion_ps:
430 break;
431 case conversion_xml:
432 vStartOfListXML(pDiag, ucNFC, bIsEndOfTable);
433 break;
434 case conversion_pdf:
435 break;
436 default:
437 DBG_DEC(eConversionType);
438 break;
440 } /* end of vStartOfList */
443 * Create an end of list
445 void
446 vEndOfList(diagram_type *pDiag)
448 switch (eConversionType) {
449 case conversion_text:
450 case conversion_fmt_text:
451 break;
452 case conversion_ps:
453 break;
454 case conversion_xml:
455 vEndOfListXML(pDiag);
456 break;
457 case conversion_pdf:
458 break;
459 default:
460 DBG_DEC(eConversionType);
461 break;
463 } /* end of vEndOfList */
466 * Create a start of a list item
468 void
469 vStartOfListItem(diagram_type *pDiag, BOOL bNoMarks)
471 switch (eConversionType) {
472 case conversion_text:
473 case conversion_fmt_text:
474 break;
475 case conversion_ps:
476 break;
477 case conversion_xml:
478 vStartOfListItemXML(pDiag, bNoMarks);
479 break;
480 case conversion_pdf:
481 break;
482 default:
483 DBG_DEC(eConversionType);
484 break;
486 } /* end of vStartOfListItem */
489 * Create an end of a table
491 void
492 vEndOfTable(diagram_type *pDiag)
494 switch (eConversionType) {
495 case conversion_text:
496 case conversion_fmt_text:
497 break;
498 case conversion_ps:
499 break;
500 case conversion_xml:
501 vEndOfTableXML(pDiag);
502 break;
503 case conversion_pdf:
504 break;
505 default:
506 DBG_DEC(eConversionType);
507 break;
509 } /* end of vEndOfTable */
512 * Add a table row
514 * Returns TRUE when conversion type is XML
516 BOOL
517 bAddTableRow(diagram_type *pDiag, char **aszColTxt,
518 int iNbrOfColumns, const short *asColumnWidth, UCHAR ucBorderInfo)
520 switch (eConversionType) {
521 case conversion_text:
522 case conversion_fmt_text:
523 break;
524 case conversion_ps:
525 break;
526 case conversion_xml:
527 vAddTableRowXML(pDiag, aszColTxt,
528 iNbrOfColumns, asColumnWidth,
529 ucBorderInfo);
530 return TRUE;
531 case conversion_pdf:
532 break;
533 default:
534 DBG_DEC(eConversionType);
535 break;
537 return FALSE;
538 } /* end of bAddTableRow */