123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- /*
- * 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 */
|