1 /*
2 * output.c
3 * Copyright (C) 2002-2004 A.J. van Os; Released under GNU GPL
4 *
5 * Description:
6 * Generic output generating functions
7 */
8
9 #include "antiword.h"
10
11 static conversion_type eConversionType = conversion_unknown;
12 static encoding_type eEncoding = encoding_neutral;
13
14
15 /*
16 * vPrologue1 - get options and call a specific initialization
17 */
18 static void
vPrologue1(diagram_type * pDiag,const char * szTask,const char * szFilename)19 vPrologue1(diagram_type *pDiag, const char *szTask, const char *szFilename)
20 {
21 options_type tOptions;
22
23 fail(pDiag == NULL);
24 fail(szTask == NULL || szTask[0] == '\0');
25
26 vGetOptions(&tOptions);
27 eConversionType = tOptions.eConversionType;
28 eEncoding = tOptions.eEncoding;
29
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;
49 }
50 } /* end of vPrologue1 */
51
52 /*
53 * vEpilogue - clean up after everything is done
54 */
55 static void
vEpilogue(diagram_type * pDiag)56 vEpilogue(diagram_type *pDiag)
57 {
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;
75 }
76 } /* end of vEpilogue */
77
78 /*
79 * vImagePrologue - perform image initialization
80 */
81 void
vImagePrologue(diagram_type * pDiag,const imagedata_type * pImg)82 vImagePrologue(diagram_type *pDiag, const imagedata_type *pImg)
83 {
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;
99 }
100 } /* end of vImagePrologue */
101
102 /*
103 * vImageEpilogue - clean up an image
104 */
105 void
vImageEpilogue(diagram_type * pDiag)106 vImageEpilogue(diagram_type *pDiag)
107 {
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;
123 }
124 } /* end of vImageEpilogue */
125
126 /*
127 * bAddDummyImage - add a dummy image
128 *
129 * return TRUE when successful, otherwise FALSE
130 */
131 BOOL
bAddDummyImage(diagram_type * pDiag,const imagedata_type * pImg)132 bAddDummyImage(diagram_type *pDiag, const imagedata_type *pImg)
133 {
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;
147 }
148 } /* end of bAddDummyImage */
149
150 /*
151 * pCreateDiagram - create and initialize a diagram
152 *
153 * remark: does not return if the diagram can't be created
154 */
155 diagram_type *
pCreateDiagram(const char * szTask,const char * szFilename)156 pCreateDiagram(const char *szTask, const char *szFilename)
157 {
158 diagram_type *pDiag;
159
160 fail(szTask == NULL || szTask[0] == '\0');
161 DBG_MSG("pCreateDiagram");
162
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 */
171
172 /*
173 * vDestroyDiagram - remove a diagram by freeing the memory it uses
174 */
175 void
vDestroyDiagram(diagram_type * pDiag)176 vDestroyDiagram(diagram_type *pDiag)
177 {
178 DBG_MSG("vDestroyDiagram");
179
180 fail(pDiag == NULL);
181
182 if (pDiag == NULL) {
183 return;
184 }
185 vEpilogue(pDiag);
186 pDiag = xfree(pDiag);
187 } /* end of vDestroyDiagram */
188
189 /*
190 * vPrologue2 - call a specific initialization
191 */
192 void
vPrologue2(diagram_type * pDiag,int iWordVersion)193 vPrologue2(diagram_type *pDiag, int iWordVersion)
194 {
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;
212 }
213 } /* end of vPrologue2 */
214
215 /*
216 * vMove2NextLine - move to the next line
217 */
218 void
vMove2NextLine(diagram_type * pDiag,drawfile_fontref tFontRef,USHORT usFontSize)219 vMove2NextLine(diagram_type *pDiag, drawfile_fontref tFontRef,
220 USHORT usFontSize)
221 {
222 fail(pDiag == NULL);
223 fail(pDiag->pOutFile == NULL);
224 fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);
225
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;
243 }
244 } /* end of vMove2NextLine */
245
246 /*
247 * vSubstring2Diagram - put a sub string into a diagram
248 */
249 void
vSubstring2Diagram(diagram_type * pDiag,char * szString,size_t tStringLength,long lStringWidth,UCHAR ucFontColor,USHORT usFontstyle,drawfile_fontref tFontRef,USHORT usFontSize,USHORT usMaxFontSize)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)
254 {
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;
280 }
281 pDiag->lXleft += lStringWidth;
282 } /* end of vSubstring2Diagram */
283
284 /*
285 * Create a start of paragraph (phase 1)
286 * Before indentation, list numbering, bullets etc.
287 */
288 void
vStartOfParagraph1(diagram_type * pDiag,long lBeforeIndentation)289 vStartOfParagraph1(diagram_type *pDiag, long lBeforeIndentation)
290 {
291 fail(pDiag == NULL);
292
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;
309 }
310 } /* end of vStartOfParagraph1 */
311
312 /*
313 * Create a start of paragraph (phase 2)
314 * After indentation, list numbering, bullets etc.
315 */
316 void
vStartOfParagraph2(diagram_type * pDiag)317 vStartOfParagraph2(diagram_type *pDiag)
318 {
319 fail(pDiag == NULL);
320
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;
335 }
336 } /* end of vStartOfParagraph2 */
337
338 /*
339 * Create an end of paragraph
340 */
341 void
vEndOfParagraph(diagram_type * pDiag,drawfile_fontref tFontRef,USHORT usFontSize,long lAfterIndentation)342 vEndOfParagraph(diagram_type *pDiag,
343 drawfile_fontref tFontRef, USHORT usFontSize, long lAfterIndentation)
344 {
345 fail(pDiag == NULL);
346 fail(pDiag->pOutFile == NULL);
347 fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);
348 fail(lAfterIndentation < 0);
349
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;
367 }
368 } /* end of vEndOfParagraph */
369
370 /*
371 * Create an end of page
372 */
373 void
vEndOfPage(diagram_type * pDiag,long lAfterIndentation,BOOL bNewSection)374 vEndOfPage(diagram_type *pDiag, long lAfterIndentation, BOOL bNewSection)
375 {
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;
393 }
394 } /* end of vEndOfPage */
395
396 /*
397 * vSetHeaders - set the headers
398 */
399 void
vSetHeaders(diagram_type * pDiag,USHORT usIstd)400 vSetHeaders(diagram_type *pDiag, USHORT usIstd)
401 {
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;
416 }
417 } /* end of vSetHeaders */
418
419 /*
420 * Create a start of list
421 */
422 void
vStartOfList(diagram_type * pDiag,UCHAR ucNFC,BOOL bIsEndOfTable)423 vStartOfList(diagram_type *pDiag, UCHAR ucNFC, BOOL bIsEndOfTable)
424 {
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;
439 }
440 } /* end of vStartOfList */
441
442 /*
443 * Create an end of list
444 */
445 void
vEndOfList(diagram_type * pDiag)446 vEndOfList(diagram_type *pDiag)
447 {
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;
462 }
463 } /* end of vEndOfList */
464
465 /*
466 * Create a start of a list item
467 */
468 void
vStartOfListItem(diagram_type * pDiag,BOOL bNoMarks)469 vStartOfListItem(diagram_type *pDiag, BOOL bNoMarks)
470 {
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;
485 }
486 } /* end of vStartOfListItem */
487
488 /*
489 * Create an end of a table
490 */
491 void
vEndOfTable(diagram_type * pDiag)492 vEndOfTable(diagram_type *pDiag)
493 {
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;
508 }
509 } /* end of vEndOfTable */
510
511 /*
512 * Add a table row
513 *
514 * Returns TRUE when conversion type is XML
515 */
516 BOOL
bAddTableRow(diagram_type * pDiag,char ** aszColTxt,int iNbrOfColumns,const short * asColumnWidth,UCHAR ucBorderInfo)517 bAddTableRow(diagram_type *pDiag, char **aszColTxt,
518 int iNbrOfColumns, const short *asColumnWidth, UCHAR ucBorderInfo)
519 {
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;
536 }
537 return FALSE;
538 } /* end of bAddTableRow */
539