output.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. #include "antiword.h"
  9. static conversion_type eConversionType = conversion_unknown;
  10. static encoding_type eEncoding = encoding_neutral;
  11. /*
  12. * vPrologue1 - get options and call a specific initialization
  13. */
  14. static void
  15. vPrologue1(diagram_type *pDiag, const char *szTask, const char *szFilename)
  16. {
  17. options_type tOptions;
  18. fail(pDiag == NULL);
  19. fail(szTask == NULL || szTask[0] == '\0');
  20. vGetOptions(&tOptions);
  21. eConversionType = tOptions.eConversionType;
  22. eEncoding = tOptions.eEncoding;
  23. switch (eConversionType) {
  24. case conversion_text:
  25. vPrologueTXT(pDiag, &tOptions);
  26. break;
  27. case conversion_fmt_text:
  28. vPrologueFMT(pDiag, &tOptions);
  29. break;
  30. case conversion_ps:
  31. vProloguePS(pDiag, szTask, szFilename, &tOptions);
  32. break;
  33. case conversion_xml:
  34. vPrologueXML(pDiag, &tOptions);
  35. break;
  36. case conversion_pdf:
  37. vProloguePDF(pDiag, szTask, &tOptions);
  38. break;
  39. default:
  40. DBG_DEC(eConversionType);
  41. break;
  42. }
  43. } /* end of vPrologue1 */
  44. /*
  45. * vEpilogue - clean up after everything is done
  46. */
  47. static void
  48. vEpilogue(diagram_type *pDiag)
  49. {
  50. switch (eConversionType) {
  51. case conversion_text:
  52. case conversion_fmt_text:
  53. vEpilogueTXT(pDiag->pOutFile);
  54. break;
  55. case conversion_ps:
  56. vEpiloguePS(pDiag);
  57. break;
  58. case conversion_xml:
  59. vEpilogueXML(pDiag);
  60. break;
  61. case conversion_pdf:
  62. vEpiloguePDF(pDiag);
  63. break;
  64. default:
  65. DBG_DEC(eConversionType);
  66. break;
  67. }
  68. } /* end of vEpilogue */
  69. /*
  70. * vImagePrologue - perform image initialization
  71. */
  72. void
  73. vImagePrologue(diagram_type *pDiag, const imagedata_type *pImg)
  74. {
  75. switch (eConversionType) {
  76. case conversion_text:
  77. case conversion_fmt_text:
  78. break;
  79. case conversion_ps:
  80. vImageProloguePS(pDiag, pImg);
  81. break;
  82. case conversion_xml:
  83. break;
  84. case conversion_pdf:
  85. vImageProloguePDF(pDiag, pImg);
  86. break;
  87. default:
  88. DBG_DEC(eConversionType);
  89. break;
  90. }
  91. } /* end of vImagePrologue */
  92. /*
  93. * vImageEpilogue - clean up an image
  94. */
  95. void
  96. vImageEpilogue(diagram_type *pDiag)
  97. {
  98. switch (eConversionType) {
  99. case conversion_text:
  100. case conversion_fmt_text:
  101. break;
  102. case conversion_ps:
  103. vImageEpiloguePS(pDiag);
  104. break;
  105. case conversion_xml:
  106. break;
  107. case conversion_pdf:
  108. vImageEpiloguePDF(pDiag);
  109. break;
  110. default:
  111. DBG_DEC(eConversionType);
  112. break;
  113. }
  114. } /* end of vImageEpilogue */
  115. /*
  116. * bAddDummyImage - add a dummy image
  117. *
  118. * return TRUE when successful, otherwise FALSE
  119. */
  120. BOOL
  121. bAddDummyImage(diagram_type *pDiag, const imagedata_type *pImg)
  122. {
  123. switch (eConversionType) {
  124. case conversion_text:
  125. case conversion_fmt_text:
  126. return FALSE;
  127. case conversion_ps:
  128. return bAddDummyImagePS(pDiag, pImg);
  129. case conversion_xml:
  130. return FALSE;
  131. case conversion_pdf:
  132. return bAddDummyImagePDF(pDiag, pImg);
  133. default:
  134. DBG_DEC(eConversionType);
  135. return FALSE;
  136. }
  137. } /* end of bAddDummyImage */
  138. /*
  139. * pCreateDiagram - create and initialize a diagram
  140. *
  141. * remark: does not return if the diagram can't be created
  142. */
  143. diagram_type *
  144. pCreateDiagram(const char *szTask, const char *szFilename)
  145. {
  146. diagram_type *pDiag;
  147. fail(szTask == NULL || szTask[0] == '\0');
  148. DBG_MSG("pCreateDiagram");
  149. /* Get the necessary memory */
  150. pDiag = xmalloc(sizeof(diagram_type));
  151. /* Initialization */
  152. pDiag->pOutFile = stdout;
  153. vPrologue1(pDiag, szTask, szFilename);
  154. /* Return success */
  155. return pDiag;
  156. } /* end of pCreateDiagram */
  157. /*
  158. * vDestroyDiagram - remove a diagram by freeing the memory it uses
  159. */
  160. void
  161. vDestroyDiagram(diagram_type *pDiag)
  162. {
  163. DBG_MSG("vDestroyDiagram");
  164. fail(pDiag == NULL);
  165. if (pDiag == NULL) {
  166. return;
  167. }
  168. vEpilogue(pDiag);
  169. pDiag = xfree(pDiag);
  170. } /* end of vDestroyDiagram */
  171. /*
  172. * vPrologue2 - call a specific initialization
  173. */
  174. void
  175. vPrologue2(diagram_type *pDiag, int iWordVersion)
  176. {
  177. switch (eConversionType) {
  178. case conversion_text:
  179. case conversion_fmt_text:
  180. break;
  181. case conversion_ps:
  182. vAddFontsPS(pDiag);
  183. break;
  184. case conversion_xml:
  185. vCreateBookIntro(pDiag, iWordVersion);
  186. break;
  187. case conversion_pdf:
  188. vCreateInfoDictionary(pDiag, iWordVersion);
  189. vAddFontsPDF(pDiag);
  190. break;
  191. default:
  192. DBG_DEC(eConversionType);
  193. break;
  194. }
  195. } /* end of vPrologue2 */
  196. /*
  197. * vMove2NextLine - move to the next line
  198. */
  199. void
  200. vMove2NextLine(diagram_type *pDiag, drawfile_fontref tFontRef,
  201. USHORT usFontSize)
  202. {
  203. fail(pDiag == NULL);
  204. fail(pDiag->pOutFile == NULL);
  205. fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);
  206. switch (eConversionType) {
  207. case conversion_text:
  208. case conversion_fmt_text:
  209. vMove2NextLineTXT(pDiag);
  210. break;
  211. case conversion_ps:
  212. vMove2NextLinePS(pDiag, usFontSize);
  213. break;
  214. case conversion_xml:
  215. vMove2NextLineXML(pDiag);
  216. break;
  217. case conversion_pdf:
  218. vMove2NextLinePDF(pDiag, usFontSize);
  219. break;
  220. default:
  221. DBG_DEC(eConversionType);
  222. break;
  223. }
  224. } /* end of vMove2NextLine */
  225. /*
  226. * vSubstring2Diagram - put a sub string into a diagram
  227. */
  228. void
  229. vSubstring2Diagram(diagram_type *pDiag,
  230. char *szString, size_t tStringLength, long lStringWidth,
  231. UCHAR ucFontColor, USHORT usFontstyle, drawfile_fontref tFontRef,
  232. USHORT usFontSize, USHORT usMaxFontSize)
  233. {
  234. switch (eConversionType) {
  235. case conversion_text:
  236. vSubstringTXT(pDiag, szString, tStringLength, lStringWidth);
  237. break;
  238. case conversion_fmt_text:
  239. vSubstringFMT(pDiag, szString, tStringLength, lStringWidth,
  240. usFontstyle);
  241. break;
  242. case conversion_ps:
  243. vSubstringPS(pDiag, szString, tStringLength, lStringWidth,
  244. ucFontColor, usFontstyle, tFontRef,
  245. usFontSize, usMaxFontSize);
  246. break;
  247. case conversion_xml:
  248. vSubstringXML(pDiag, szString, tStringLength, lStringWidth,
  249. usFontstyle);
  250. break;
  251. case conversion_pdf:
  252. vSubstringPDF(pDiag, szString, tStringLength, lStringWidth,
  253. ucFontColor, usFontstyle, tFontRef,
  254. usFontSize, usMaxFontSize);
  255. break;
  256. default:
  257. DBG_DEC(eConversionType);
  258. break;
  259. }
  260. pDiag->lXleft += lStringWidth;
  261. } /* end of vSubstring2Diagram */
  262. /*
  263. * Create a start of paragraph (phase 1)
  264. * Before indentation, list numbering, bullets etc.
  265. */
  266. void
  267. vStartOfParagraph1(diagram_type *pDiag, long lBeforeIndentation)
  268. {
  269. fail(pDiag == NULL);
  270. switch (eConversionType) {
  271. case conversion_text:
  272. case conversion_fmt_text:
  273. vStartOfParagraphTXT(pDiag, lBeforeIndentation);
  274. break;
  275. case conversion_ps:
  276. vStartOfParagraphPS(pDiag, lBeforeIndentation);
  277. break;
  278. case conversion_xml:
  279. break;
  280. case conversion_pdf:
  281. vStartOfParagraphPDF(pDiag, lBeforeIndentation);
  282. break;
  283. default:
  284. DBG_DEC(eConversionType);
  285. break;
  286. }
  287. } /* end of vStartOfParagraph1 */
  288. /*
  289. * Create a start of paragraph (phase 2)
  290. * After indentation, list numbering, bullets etc.
  291. */
  292. void
  293. vStartOfParagraph2(diagram_type *pDiag)
  294. {
  295. fail(pDiag == NULL);
  296. switch (eConversionType) {
  297. case conversion_text:
  298. case conversion_fmt_text:
  299. break;
  300. case conversion_ps:
  301. break;
  302. case conversion_xml:
  303. vStartOfParagraphXML(pDiag, 1);
  304. break;
  305. case conversion_pdf:
  306. break;
  307. default:
  308. DBG_DEC(eConversionType);
  309. break;
  310. }
  311. } /* end of vStartOfParagraph2 */
  312. /*
  313. * Create an end of paragraph
  314. */
  315. void
  316. vEndOfParagraph(diagram_type *pDiag,
  317. drawfile_fontref tFontRef, USHORT usFontSize, long lAfterIndentation)
  318. {
  319. fail(pDiag == NULL);
  320. fail(pDiag->pOutFile == NULL);
  321. fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);
  322. fail(lAfterIndentation < 0);
  323. switch (eConversionType) {
  324. case conversion_text:
  325. case conversion_fmt_text:
  326. vEndOfParagraphTXT(pDiag, lAfterIndentation);
  327. break;
  328. case conversion_ps:
  329. vEndOfParagraphPS(pDiag, usFontSize, lAfterIndentation);
  330. break;
  331. case conversion_xml:
  332. vEndOfParagraphXML(pDiag, 1);
  333. break;
  334. case conversion_pdf:
  335. vEndOfParagraphPDF(pDiag, usFontSize, lAfterIndentation);
  336. break;
  337. default:
  338. DBG_DEC(eConversionType);
  339. break;
  340. }
  341. } /* end of vEndOfParagraph */
  342. /*
  343. * Create an end of page
  344. */
  345. void
  346. vEndOfPage(diagram_type *pDiag, long lAfterIndentation, BOOL bNewSection)
  347. {
  348. switch (eConversionType) {
  349. case conversion_text:
  350. case conversion_fmt_text:
  351. vEndOfPageTXT(pDiag, lAfterIndentation);
  352. break;
  353. case conversion_ps:
  354. vEndOfPagePS(pDiag, bNewSection);
  355. break;
  356. case conversion_xml:
  357. vEndOfPageXML(pDiag);
  358. break;
  359. case conversion_pdf:
  360. vEndOfPagePDF(pDiag, bNewSection);
  361. break;
  362. default:
  363. DBG_DEC(eConversionType);
  364. break;
  365. }
  366. } /* end of vEndOfPage */
  367. /*
  368. * vSetHeaders - set the headers
  369. */
  370. void
  371. vSetHeaders(diagram_type *pDiag, USHORT usIstd)
  372. {
  373. switch (eConversionType) {
  374. case conversion_text:
  375. case conversion_fmt_text:
  376. break;
  377. case conversion_ps:
  378. break;
  379. case conversion_xml:
  380. vSetHeadersXML(pDiag, usIstd);
  381. break;
  382. case conversion_pdf:
  383. break;
  384. default:
  385. DBG_DEC(eConversionType);
  386. break;
  387. }
  388. } /* end of vSetHeaders */
  389. /*
  390. * Create a start of list
  391. */
  392. void
  393. vStartOfList(diagram_type *pDiag, UCHAR ucNFC, BOOL bIsEndOfTable)
  394. {
  395. switch (eConversionType) {
  396. case conversion_text:
  397. case conversion_fmt_text:
  398. break;
  399. case conversion_ps:
  400. break;
  401. case conversion_xml:
  402. vStartOfListXML(pDiag, ucNFC, bIsEndOfTable);
  403. break;
  404. case conversion_pdf:
  405. break;
  406. default:
  407. DBG_DEC(eConversionType);
  408. break;
  409. }
  410. } /* end of vStartOfList */
  411. /*
  412. * Create an end of list
  413. */
  414. void
  415. vEndOfList(diagram_type *pDiag)
  416. {
  417. switch (eConversionType) {
  418. case conversion_text:
  419. case conversion_fmt_text:
  420. break;
  421. case conversion_ps:
  422. break;
  423. case conversion_xml:
  424. vEndOfListXML(pDiag);
  425. break;
  426. case conversion_pdf:
  427. break;
  428. default:
  429. DBG_DEC(eConversionType);
  430. break;
  431. }
  432. } /* end of vEndOfList */
  433. /*
  434. * Create a start of a list item
  435. */
  436. void
  437. vStartOfListItem(diagram_type *pDiag, BOOL bNoMarks)
  438. {
  439. switch (eConversionType) {
  440. case conversion_text:
  441. case conversion_fmt_text:
  442. break;
  443. case conversion_ps:
  444. break;
  445. case conversion_xml:
  446. vStartOfListItemXML(pDiag, bNoMarks);
  447. break;
  448. case conversion_pdf:
  449. break;
  450. default:
  451. DBG_DEC(eConversionType);
  452. break;
  453. }
  454. } /* end of vStartOfListItem */
  455. /*
  456. * Create an end of a table
  457. */
  458. void
  459. vEndOfTable(diagram_type *pDiag)
  460. {
  461. switch (eConversionType) {
  462. case conversion_text:
  463. case conversion_fmt_text:
  464. break;
  465. case conversion_ps:
  466. break;
  467. case conversion_xml:
  468. vEndOfTableXML(pDiag);
  469. break;
  470. case conversion_pdf:
  471. break;
  472. default:
  473. DBG_DEC(eConversionType);
  474. break;
  475. }
  476. } /* end of vEndOfTable */
  477. /*
  478. * Add a table row
  479. *
  480. * Returns TRUE when conversion type is XML
  481. */
  482. BOOL
  483. bAddTableRow(diagram_type *pDiag, char **aszColTxt,
  484. int iNbrOfColumns, const short *asColumnWidth, UCHAR ucBorderInfo)
  485. {
  486. switch (eConversionType) {
  487. case conversion_text:
  488. case conversion_fmt_text:
  489. break;
  490. case conversion_ps:
  491. break;
  492. case conversion_xml:
  493. vAddTableRowXML(pDiag, aszColTxt,
  494. iNbrOfColumns, asColumnWidth,
  495. ucBorderInfo);
  496. return TRUE;
  497. case conversion_pdf:
  498. break;
  499. default:
  500. DBG_DEC(eConversionType);
  501. break;
  502. }
  503. return FALSE;
  504. } /* end of bAddTableRow */