File: output.c

package info (click to toggle)
antiword 0.37-16
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 2,236 kB
  • sloc: ansic: 27,835; perl: 174; sh: 129; php: 83; makefile: 24
file content (538 lines) | stat: -rw-r--r-- 10,773 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/*
 * output.c
 * Copyright (C) 2002-2004 A.J. van Os; Released under GNU GPL
 *
 * Description:
 * Generic output generating functions
 */

#include "antiword.h"

static conversion_type	eConversionType = conversion_unknown;
static encoding_type	eEncoding = encoding_neutral;


/*
 * vPrologue1 - get options and call a specific initialization
 */
static void
vPrologue1(diagram_type *pDiag, const char *szTask, const char *szFilename)
{
	options_type	tOptions;

	fail(pDiag == NULL);
	fail(szTask == NULL || szTask[0] == '\0');

	vGetOptions(&tOptions);
	eConversionType = tOptions.eConversionType;
	eEncoding = tOptions.eEncoding;

	switch (eConversionType) {
	case conversion_text:
		vPrologueTXT(pDiag, &tOptions);
		break;
	case conversion_fmt_text:
		vPrologueFMT(pDiag, &tOptions);
		break;
	case conversion_ps:
		vProloguePS(pDiag, szTask, szFilename, &tOptions);
		break;
	case conversion_xml:
		vPrologueXML(pDiag, &tOptions);
		break;
	case conversion_pdf:
		vProloguePDF(pDiag, szTask, &tOptions);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vPrologue1 */

/*
 * vEpilogue - clean up after everything is done
 */
static void
vEpilogue(diagram_type *pDiag)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		vEpilogueTXT(pDiag->pOutFile);
		break;
	case conversion_ps:
		vEpiloguePS(pDiag);
		break;
	case conversion_xml:
		vEpilogueXML(pDiag);
		break;
	case conversion_pdf:
		vEpiloguePDF(pDiag);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vEpilogue */

/*
 * vImagePrologue - perform image initialization
 */
void
vImagePrologue(diagram_type *pDiag, const imagedata_type *pImg)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		vImageProloguePS(pDiag, pImg);
		break;
	case conversion_xml:
		break;
	case conversion_pdf:
		vImageProloguePDF(pDiag, pImg);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vImagePrologue */

/*
 * vImageEpilogue - clean up an image
 */
void
vImageEpilogue(diagram_type *pDiag)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		vImageEpiloguePS(pDiag);
		break;
	case conversion_xml:
		break;
	case conversion_pdf:
		vImageEpiloguePDF(pDiag);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vImageEpilogue */

/*
 * bAddDummyImage - add a dummy image
 *
 * return TRUE when successful, otherwise FALSE
 */
BOOL
bAddDummyImage(diagram_type *pDiag, const imagedata_type *pImg)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		return FALSE;
	case conversion_ps:
		return bAddDummyImagePS(pDiag, pImg);
	case conversion_xml:
		return FALSE;
	case conversion_pdf:
		return bAddDummyImagePDF(pDiag, pImg);
	default:
		DBG_DEC(eConversionType);
		return FALSE;
	}
} /* end of bAddDummyImage */

/*
 * pCreateDiagram - create and initialize a diagram
 *
 * remark: does not return if the diagram can't be created
 */
diagram_type *
pCreateDiagram(const char *szTask, const char *szFilename)
{
	diagram_type	*pDiag;

	fail(szTask == NULL || szTask[0] == '\0');
	DBG_MSG("pCreateDiagram");

	/* Get the necessary memory */
	pDiag = xmalloc(sizeof(diagram_type));
	/* Initialization */
	pDiag->pOutFile = stdout;
	vPrologue1(pDiag, szTask, szFilename);
	/* Return success */
	return pDiag;
} /* end of pCreateDiagram */

/*
 * vDestroyDiagram - remove a diagram by freeing the memory it uses
 */
void
vDestroyDiagram(diagram_type *pDiag)
{
	DBG_MSG("vDestroyDiagram");

	fail(pDiag == NULL);

	if (pDiag == NULL) {
		return;
	}
	vEpilogue(pDiag);
	pDiag = xfree(pDiag);
} /* end of vDestroyDiagram */

/*
 * vPrologue2 - call a specific initialization
 */
void
vPrologue2(diagram_type *pDiag, int iWordVersion)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		vAddFontsPS(pDiag);
		break;
	case conversion_xml:
		vCreateBookIntro(pDiag, iWordVersion);
		break;
	case conversion_pdf:
		vCreateInfoDictionary(pDiag, iWordVersion);
		vAddFontsPDF(pDiag);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vPrologue2 */

/*
 * vMove2NextLine - move to the next line
 */
void
vMove2NextLine(diagram_type *pDiag, drawfile_fontref tFontRef,
	USHORT usFontSize)
{
	fail(pDiag == NULL);
	fail(pDiag->pOutFile == NULL);
	fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);

	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		vMove2NextLineTXT(pDiag);
		break;
	case conversion_ps:
		vMove2NextLinePS(pDiag, usFontSize);
		break;
	case conversion_xml:
		vMove2NextLineXML(pDiag);
		break;
	case conversion_pdf:
		vMove2NextLinePDF(pDiag, usFontSize);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vMove2NextLine */

/*
 * vSubstring2Diagram - put a sub string into a diagram
 */
void
vSubstring2Diagram(diagram_type *pDiag,
	char *szString, size_t tStringLength, long lStringWidth,
	UCHAR ucFontColor, USHORT usFontstyle, drawfile_fontref tFontRef,
	USHORT usFontSize, USHORT usMaxFontSize)
{
	switch (eConversionType) {
	case conversion_text:
		vSubstringTXT(pDiag, szString, tStringLength, lStringWidth);
		break;
	case conversion_fmt_text:
		vSubstringFMT(pDiag, szString, tStringLength, lStringWidth,
				usFontstyle);
		break;
	case conversion_ps:
		vSubstringPS(pDiag, szString, tStringLength, lStringWidth,
				ucFontColor, usFontstyle, tFontRef,
				usFontSize, usMaxFontSize);
		break;
	case conversion_xml:
		vSubstringXML(pDiag, szString, tStringLength, lStringWidth,
				usFontstyle);
		break;
	case conversion_pdf:
		vSubstringPDF(pDiag, szString, tStringLength, lStringWidth,
				ucFontColor, usFontstyle, tFontRef,
				usFontSize, usMaxFontSize);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
	pDiag->lXleft += lStringWidth;
} /* end of vSubstring2Diagram */

/*
 * Create a start of paragraph (phase 1)
 * Before indentation, list numbering, bullets etc.
 */
void
vStartOfParagraph1(diagram_type *pDiag, long lBeforeIndentation)
{
	fail(pDiag == NULL);

	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		vStartOfParagraphTXT(pDiag, lBeforeIndentation);
		break;
	case conversion_ps:
		vStartOfParagraphPS(pDiag, lBeforeIndentation);
		break;
	case conversion_xml:
		break;
	case conversion_pdf:
		vStartOfParagraphPDF(pDiag, lBeforeIndentation);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vStartOfParagraph1 */

/*
 * Create a start of paragraph (phase 2)
 * After indentation, list numbering, bullets etc.
 */
void
vStartOfParagraph2(diagram_type *pDiag)
{
	fail(pDiag == NULL);

	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		break;
	case conversion_xml:
		vStartOfParagraphXML(pDiag, 1);
		break;
	case conversion_pdf:
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vStartOfParagraph2 */

/*
 * Create an end of paragraph
 */
void
vEndOfParagraph(diagram_type *pDiag,
	drawfile_fontref tFontRef, USHORT usFontSize, long lAfterIndentation)
{
	fail(pDiag == NULL);
	fail(pDiag->pOutFile == NULL);
	fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);
	fail(lAfterIndentation < 0);

	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		vEndOfParagraphTXT(pDiag, lAfterIndentation);
		break;
	case conversion_ps:
		vEndOfParagraphPS(pDiag, usFontSize, lAfterIndentation);
		break;
	case conversion_xml:
		vEndOfParagraphXML(pDiag, 1);
		break;
	case conversion_pdf:
		vEndOfParagraphPDF(pDiag, usFontSize, lAfterIndentation);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vEndOfParagraph */

/*
 * Create an end of page
 */
void
vEndOfPage(diagram_type *pDiag, long lAfterIndentation, BOOL bNewSection)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		vEndOfPageTXT(pDiag, lAfterIndentation);
		break;
	case conversion_ps:
		vEndOfPagePS(pDiag, bNewSection);
		break;
	case conversion_xml:
		vEndOfPageXML(pDiag);
		break;
	case conversion_pdf:
		vEndOfPagePDF(pDiag, bNewSection);
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vEndOfPage */

/*
 * vSetHeaders - set the headers
 */
void
vSetHeaders(diagram_type *pDiag, USHORT usIstd)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		break;
	case conversion_xml:
		vSetHeadersXML(pDiag, usIstd);
		break;
	case conversion_pdf:
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vSetHeaders */

/*
 * Create a start of list
 */
void
vStartOfList(diagram_type *pDiag, UCHAR ucNFC, BOOL bIsEndOfTable)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		break;
	case conversion_xml:
		vStartOfListXML(pDiag, ucNFC, bIsEndOfTable);
		break;
	case conversion_pdf:
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vStartOfList */

/*
 * Create an end of list
 */
void
vEndOfList(diagram_type *pDiag)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		break;
	case conversion_xml:
		vEndOfListXML(pDiag);
		break;
	case conversion_pdf:
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vEndOfList */

/*
 * Create a start of a list item
 */
void
vStartOfListItem(diagram_type *pDiag, BOOL bNoMarks)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		break;
	case conversion_xml:
		vStartOfListItemXML(pDiag, bNoMarks);
		break;
	case conversion_pdf:
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vStartOfListItem */

/*
 * Create an end of a table
 */
void
vEndOfTable(diagram_type *pDiag)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		break;
	case conversion_xml:
		vEndOfTableXML(pDiag);
		break;
	case conversion_pdf:
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
} /* end of vEndOfTable */

/*
 * Add a table row
 *
 * Returns TRUE when conversion type is XML
 */
BOOL
bAddTableRow(diagram_type *pDiag, char **aszColTxt,
	int iNbrOfColumns, const short *asColumnWidth, UCHAR ucBorderInfo)
{
	switch (eConversionType) {
	case conversion_text:
	case conversion_fmt_text:
		break;
	case conversion_ps:
		break;
	case conversion_xml:
		vAddTableRowXML(pDiag, aszColTxt,
				iNbrOfColumns, asColumnWidth,
				ucBorderInfo);
		return TRUE;
	case conversion_pdf:
		break;
	default:
		DBG_DEC(eConversionType);
		break;
	}
	return FALSE;
} /* end of bAddTableRow */