3 * Copyright (C) 1999-2004 A.J. van Os; Released under GNU GPL
6 * Functions to deal with the Text format
13 /* The character set */
14 static encoding_type eEncoding
= encoding_neutral
;
15 /* Current vertical position information */
16 static long lYtopCurr
= 0;
17 /* Local representation of the non-breaking space */
18 static UCHAR ucNbsp
= 0;
22 * vPrologueTXT - set options and perform the Text initialization
25 vPrologueTXT(diagram_type
*pDiag
, const options_type
*pOptions
)
28 fail(pOptions
== NULL
);
30 eEncoding
= pOptions
->eEncoding
;
34 } /* end of vPrologueTXT */
37 * vEpilogueTXT - clean up after everything is done
40 vEpilogueTXT(FILE *pOutFile
)
42 fail(pOutFile
== NULL
);
44 fprintf(pOutFile
, "\n");
45 } /* end of vEpilogueTXT */
48 * vPrintTXT - print a Text string
51 vPrintTXT(FILE *pFile
, const char *szString
, size_t tStringLength
)
56 fail(szString
== NULL
);
58 if (szString
== NULL
|| szString
[0] == '\0' || tStringLength
== 0) {
62 if (eEncoding
== encoding_utf_8
) {
63 fprintf(pFile
, "%.*s", (int)tStringLength
, szString
);
68 ucNbsp
= ucGetNbspCharacter();
69 DBG_HEX_C(ucNbsp
!= 0xa0, ucNbsp
);
72 ucBytes
= (UCHAR
*)szString
;
73 for (tCount
= 0; tCount
< tStringLength
; tCount
++) {
74 if (ucBytes
[tCount
] == ucNbsp
) {
75 (void)putc(' ', pFile
);
77 (void)putc(szString
[tCount
], pFile
);
80 } /* end of vPrintTXT */
83 * vMoveTo - move to the given X,Y coordinates
85 * Move the current position of the given diagram to its X,Y coordinates,
86 * start on a new page if needed
89 vMoveTo(diagram_type
*pDiag
)
94 fail(pDiag
->pOutFile
== NULL
);
96 if (pDiag
->lYtop
!= lYtopCurr
) {
97 iNbr
= iDrawUnits2Char(pDiag
->lXleft
);
98 for (iCount
= 0; iCount
< iNbr
; iCount
++) {
99 (void)putc(FILLER_CHAR
, pDiag
->pOutFile
);
101 lYtopCurr
= pDiag
->lYtop
;
103 } /* end of vMoveTo */
106 * vMove2NextLineTXT - move to the next line
109 vMove2NextLineTXT(diagram_type
*pDiag
)
112 fail(pDiag
->pOutFile
== NULL
);
115 (void)fprintf(pDiag
->pOutFile
, "\n");
116 } /* end of vMove2NextLineTXT */
119 * vSubstringTXT - print a sub string
122 vSubstringTXT(diagram_type
*pDiag
,
123 const char *szString
, size_t tStringLength
, long lStringWidth
)
125 fail(pDiag
== NULL
|| szString
== NULL
);
126 fail(pDiag
->pOutFile
== NULL
);
127 fail(pDiag
->lXleft
< 0);
128 fail(tStringLength
!= strlen(szString
));
130 if (szString
[0] == '\0' || tStringLength
== 0) {
135 vPrintTXT(pDiag
->pOutFile
, szString
, tStringLength
);
136 pDiag
->lXleft
+= lStringWidth
;
137 } /* end of vSubstringTXT */
140 * Create an start of paragraph by moving the y-top mark
143 vStartOfParagraphTXT(diagram_type
*pDiag
, long lBeforeIndentation
)
146 fail(lBeforeIndentation
< 0);
148 if (lBeforeIndentation
>= lTwips2MilliPoints(HEADING_GAP
)) {
149 /* A large gap is replaced by an empty line */
150 vMove2NextLineTXT(pDiag
);
152 } /* end of vStartOfParagraphTXT */
155 * Create an end of paragraph by moving the y-top mark
158 vEndOfParagraphTXT(diagram_type
*pDiag
, long lAfterIndentation
)
161 fail(pDiag
->pOutFile
== NULL
);
162 fail(lAfterIndentation
< 0);
164 if (pDiag
->lXleft
> 0) {
165 /* To the start of the line */
166 vMove2NextLineTXT(pDiag
);
169 if (lAfterIndentation
>= lTwips2MilliPoints(HEADING_GAP
)) {
170 /* A large gap is replaced by an empty line */
171 vMove2NextLineTXT(pDiag
);
173 } /* end of vEndOfParagraphTXT */
176 * Create an end of page
179 vEndOfPageTXT(diagram_type
*pDiag
, long lAfterIndentation
)
181 vEndOfParagraphTXT(pDiag
, lAfterIndentation
);
182 } /* end of vEndOfPageTXT */