00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <string.h>
00011 #include "antiword.h"
00012
00013
00014 static encoding_type eEncoding = encoding_neutral;
00015
00016 static long lYtopCurr = 0;
00017
00018 static UCHAR ucNbsp = 0;
00019
00020
00021
00022
00023
00024 void
00025 vPrologueTXT(diagram_type *pDiag, const options_type *pOptions)
00026 {
00027 fail(pDiag == NULL);
00028 fail(pOptions == NULL);
00029
00030 eEncoding = pOptions->eEncoding;
00031 pDiag->lXleft = 0;
00032 pDiag->lYtop = 0;
00033 lYtopCurr = 0;
00034 }
00035
00036
00037
00038
00039 void
00040 vEpilogueTXT(FILE *pOutFile)
00041 {
00042 fail(pOutFile == NULL);
00043
00044 fprintf(pOutFile, "\n");
00045 }
00046
00047
00048
00049
00050 static void
00051 vPrintTXT(FILE *pFile, const char *szString, size_t tStringLength)
00052 {
00053 const UCHAR *ucBytes;
00054 size_t tCount;
00055
00056 fail(szString == NULL);
00057
00058 if (szString == NULL || szString[0] == '\0' || tStringLength == 0) {
00059 return;
00060 }
00061
00062 if (eEncoding == encoding_utf_8) {
00063 fprintf(pFile, "%.*s", (int)tStringLength, szString);
00064 return;
00065 }
00066
00067 if (ucNbsp == 0) {
00068 ucNbsp = ucGetNbspCharacter();
00069 DBG_HEX_C(ucNbsp != 0xa0, ucNbsp);
00070 }
00071
00072 ucBytes = (UCHAR *)szString;
00073 for (tCount = 0; tCount < tStringLength ; tCount++) {
00074 if (ucBytes[tCount] == ucNbsp) {
00075 (void)putc(' ', pFile);
00076 } else {
00077 (void)putc(szString[tCount], pFile);
00078 }
00079 }
00080 }
00081
00082
00083
00084
00085
00086
00087
00088 static void
00089 vMoveTo(diagram_type *pDiag)
00090 {
00091 int iCount, iNbr;
00092
00093 fail(pDiag == NULL);
00094 fail(pDiag->pOutFile == NULL);
00095
00096 if (pDiag->lYtop != lYtopCurr) {
00097 iNbr = iDrawUnits2Char(pDiag->lXleft);
00098 for (iCount = 0; iCount < iNbr; iCount++) {
00099 (void)putc(FILLER_CHAR, pDiag->pOutFile);
00100 }
00101 lYtopCurr = pDiag->lYtop;
00102 }
00103 }
00104
00105
00106
00107
00108 void
00109 vMove2NextLineTXT(diagram_type *pDiag)
00110 {
00111 fail(pDiag == NULL);
00112 fail(pDiag->pOutFile == NULL);
00113
00114 pDiag->lYtop++;
00115 (void)fprintf(pDiag->pOutFile, "\n");
00116 }
00117
00118
00119
00120
00121 void
00122 vSubstringTXT(diagram_type *pDiag,
00123 const char *szString, size_t tStringLength, long lStringWidth)
00124 {
00125 fail(pDiag == NULL || szString == NULL);
00126 fail(pDiag->pOutFile == NULL);
00127 fail(pDiag->lXleft < 0);
00128 fail(tStringLength != strlen(szString));
00129
00130 if (szString[0] == '\0' || tStringLength == 0) {
00131 return;
00132 }
00133
00134 vMoveTo(pDiag);
00135 vPrintTXT(pDiag->pOutFile, szString, tStringLength);
00136 pDiag->lXleft += lStringWidth;
00137 }
00138
00139
00140
00141
00142 void
00143 vStartOfParagraphTXT(diagram_type *pDiag, long lBeforeIndentation)
00144 {
00145 fail(pDiag == NULL);
00146 fail(lBeforeIndentation < 0);
00147
00148 if (lBeforeIndentation >= lTwips2MilliPoints(HEADING_GAP)) {
00149
00150 vMove2NextLineTXT(pDiag);
00151 }
00152 }
00153
00154
00155
00156
00157 void
00158 vEndOfParagraphTXT(diagram_type *pDiag, long lAfterIndentation)
00159 {
00160 fail(pDiag == NULL);
00161 fail(pDiag->pOutFile == NULL);
00162 fail(lAfterIndentation < 0);
00163
00164 if (pDiag->lXleft > 0) {
00165
00166 vMove2NextLineTXT(pDiag);
00167 }
00168
00169 if (lAfterIndentation >= lTwips2MilliPoints(HEADING_GAP)) {
00170
00171 vMove2NextLineTXT(pDiag);
00172 }
00173 }
00174
00175
00176
00177
00178 void
00179 vEndOfPageTXT(diagram_type *pDiag, long lAfterIndentation)
00180 {
00181 vEndOfParagraphTXT(pDiag, lAfterIndentation);
00182 }