3 * Copyright (C) 2004 A.J. van Os; Released under GNU GPL
6 * Functions to deal with the Formatted Text format
8 * Based on patches send by: Ofir Reichenberg <ofir@qlusters.com>
10 * The credit should go to him, but all the bugs are mine.
16 /* The character set */
17 static encoding_type eEncoding
= encoding_neutral
;
18 /* Current vertical position information */
19 static long lYtopCurr
= 0;
20 /* Local representation of the non-breaking space */
21 static UCHAR ucNbsp
= 0;
25 * vPrologueFMT - set options and perform the Formatted Text initialization
28 vPrologueFMT(diagram_type
*pDiag
, const options_type
*pOptions
)
31 fail(pOptions
== NULL
);
33 eEncoding
= pOptions
->eEncoding
;
37 } /* end of vPrologueFMT */
40 * vPrintFMT - print a Formatted Text string
43 vPrintFMT(FILE *pFile
,
44 const char *szString
, size_t tStringLength
, USHORT usFontstyle
)
46 const UCHAR
*pucByte
, *pucStart
, *pucLast
, *pucNonSpace
;
48 fail(szString
== NULL
);
50 if (szString
== NULL
|| szString
[0] == '\0' || tStringLength
== 0) {
54 if (eEncoding
== encoding_utf_8
) {
55 fprintf(pFile
, "%.*s", (int)tStringLength
, szString
);
60 ucNbsp
= ucGetNbspCharacter();
61 DBG_HEX_C(ucNbsp
!= 0xa0, ucNbsp
);
64 pucStart
= (UCHAR
*)szString
;
65 pucLast
= pucStart
+ tStringLength
- 1;
66 pucNonSpace
= pucLast
;
67 while ((*pucNonSpace
== (UCHAR
)' ' || *pucNonSpace
== ucNbsp
) &&
68 pucNonSpace
> pucStart
) {
72 /* 1: The spaces at the start */
74 while ((*pucByte
== (UCHAR
)' ' || *pucByte
== ucNbsp
) &&
76 (void)putc(' ', pFile
);
80 if (pucByte
> pucLast
) {
81 /* There is no text, just spaces */
85 /* 2: Start the *bold*, /italic/ and _underline_ */
86 if (bIsBold(usFontstyle
)) {
87 (void)putc('*', pFile
);
89 if (bIsItalic(usFontstyle
)) {
90 (void)putc('/', pFile
);
92 if (bIsUnderline(usFontstyle
)) {
93 (void)putc('_', pFile
);
96 /* 3: The text itself */
97 while (pucByte
<= pucNonSpace
) {
98 if (*pucByte
== ucNbsp
) {
99 (void)putc(' ', pFile
);
101 (void)putc((char)*pucByte
, pFile
);
106 /* 4: End the *bold*, /italic/ and _underline_ */
107 if (bIsUnderline(usFontstyle
)) {
108 (void)putc('_', pFile
);
110 if (bIsItalic(usFontstyle
)) {
111 (void)putc('/', pFile
);
113 if (bIsBold(usFontstyle
)) {
114 (void)putc('*', pFile
);
117 /* 5: The spaces at the end */
118 while (pucByte
<= pucLast
) {
119 (void)putc(' ', pFile
);
122 } /* end of vPrintFMT */
125 * vMoveTo - move to the given X,Y coordinates
127 * Move the current position of the given diagram to its X,Y coordinates,
128 * start on a new page if needed
131 vMoveTo(diagram_type
*pDiag
)
136 fail(pDiag
->pOutFile
== NULL
);
138 if (pDiag
->lYtop
!= lYtopCurr
) {
139 iNbr
= iDrawUnits2Char(pDiag
->lXleft
);
140 for (iCount
= 0; iCount
< iNbr
; iCount
++) {
141 (void)putc(FILLER_CHAR
, pDiag
->pOutFile
);
143 lYtopCurr
= pDiag
->lYtop
;
145 } /* end of vMoveTo */
148 * vSubstringFMT - print a sub string
151 vSubstringFMT(diagram_type
*pDiag
,
152 const char *szString
, size_t tStringLength
, long lStringWidth
,
155 fail(pDiag
== NULL
|| szString
== NULL
);
156 fail(pDiag
->pOutFile
== NULL
);
157 fail(pDiag
->lXleft
< 0);
158 fail(tStringLength
!= strlen(szString
));
160 if (szString
[0] == '\0' || tStringLength
== 0) {
165 vPrintFMT(pDiag
->pOutFile
, szString
, tStringLength
, usFontstyle
);
166 pDiag
->lXleft
+= lStringWidth
;
167 } /* end of vSubstringFMT */