3 * Copyright (C) 1999-2002 A.J. van Os; Released under GPL
6 * Functions to deal with fonts (RiscOs version)
13 static font tFontCurr
= (font
)-1;
16 * pOpenFontTableFile - open the Font translation file
17 * Copy the file to the proper place if necessary.
19 * Returns the file pointer or NULL
22 pOpenFontTableFile(void)
24 FILE *pFileR
, *pFileW
;
25 char *szFontNamesFile
;
30 pFileR
= fopen("<AntiWord$FontNamesFile>", "r");
32 /* The font table is already in the right directory */
36 szFontNamesFile
= getenv("AntiWord$FontNamesSave");
37 if (szFontNamesFile
== NULL
) {
38 werr(0, "Warning: Name of the FontNames file not found");
41 DBG_MSG(szFontNamesFile
);
43 pFileR
= fopen("<AntiWord$Dir>.Resources.Default", "r");
45 werr(0, "I can't find 'Resources.Default'");
48 /* Here the default font translation table is known to exist */
50 if (!bMakeDirectory(szFontNamesFile
)) {
52 "I can't make a directory for the FontNames file");
55 /* Here the proper directory is known to exist */
57 pFileW
= fopen(szFontNamesFile
, "w");
60 werr(0, "I can't create a default FontNames file");
63 /* Here the proper directory is known to be writeable */
65 /* Copy the default FontNames file */
67 while (!feof(pFileR
)) {
68 tSize
= fread(acBuffer
, 1, sizeof(acBuffer
), pFileR
);
70 DBG_MSG("Read error");
74 if (fwrite(acBuffer
, 1, tSize
, pFileW
) != tSize
) {
75 DBG_MSG("Write error");
83 DBG_MSG("Copying the FontNames file failed");
84 (void)remove(szFontNamesFile
);
87 return fopen(szFontNamesFile
, "r");
88 } /* end of pOpenFontTableFile */
91 * vCloseFont - close the current font, if any
98 NO_DBG_MSG("vCloseFont");
100 if (tFontCurr
== (font
)-1) {
103 e
= font_lose(tFontCurr
);
105 werr(0, "Close font error %d: %s", e
->errnum
, e
->errmess
);
108 } /* end of vCloseFont */
111 * tOpenFont - make the specified font the current font
113 * Returns the font reference number for use in a draw file
116 tOpenFont(UCHAR ucWordFontNumber
, USHORT usFontStyle
, USHORT usWordFontSize
)
119 const char *szOurFontname
;
123 NO_DBG_MSG("tOpenFont");
124 NO_DBG_DEC(ucWordFontNumber
);
125 NO_DBG_HEX(usFontStyle
);
126 NO_DBG_DEC(usWordFontSize
);
128 /* Keep the relevant bits */
129 usFontStyle
&= FONT_BOLD
|FONT_ITALIC
;
130 NO_DBG_HEX(usFontStyle
);
132 iFontnumber
= iGetFontByNumber(ucWordFontNumber
, usFontStyle
);
133 szOurFontname
= szGetOurFontname(iFontnumber
);
134 if (szOurFontname
== NULL
|| szOurFontname
[0] == '\0') {
135 tFontCurr
= (font
)-1;
136 return (draw_fontref
)0;
138 NO_DBG_MSG(szOurFontname
);
139 e
= font_find((char *)szOurFontname
,
140 (int)usWordFontSize
* 8, (int)usWordFontSize
* 8,
145 werr(0, "%s", e
->errmess
);
148 werr(0, "Open font error %d: %s",
149 e
->errnum
, e
->errmess
);
152 tFontCurr
= (font
)-1;
153 return (draw_fontref
)0;
156 NO_DBG_DEC(tFontCurr
);
157 return (draw_fontref
)(iFontnumber
+ 1);
158 } /* end of tOpenFont */
161 * tOpenTableFont - make the table font the current font
163 * Returns the font reference number for use in a draw file
166 tOpenTableFont(USHORT usWordFontSize
)
170 NO_DBG_MSG("tOpenTableFont");
172 iWordFontnumber
= iFontname2Fontnumber(TABLE_FONT
, FONT_REGULAR
);
173 if (iWordFontnumber
< 0 || iWordFontnumber
> (int)UCHAR_MAX
) {
174 DBG_DEC(iWordFontnumber
);
175 tFontCurr
= (font
)-1;
176 return (draw_fontref
)0;
179 return tOpenFont((UCHAR
)iWordFontnumber
, FONT_REGULAR
, usWordFontSize
);
180 } /* end of tOpenTableFont */
183 * lComputeStringWidth - compute the string width
185 * Returns the string width in millipoints
188 lComputeStringWidth(const char *szString
, size_t tStringLength
,
189 draw_fontref tFontRef
, USHORT usFontSize
)
194 fail(szString
== NULL
);
195 fail(usFontSize
< MIN_FONT_SIZE
|| usFontSize
> MAX_FONT_SIZE
);
197 if (szString
[0] == '\0' || tStringLength
== 0) {
201 if (tStringLength
== 1 && szString
[0] == TABLE_SEPARATOR
) {
202 /* Font_strwidth doesn't like control characters */
205 if (tFontCurr
== (font
)-1) {
206 /* No current font, use systemfont */
207 return lChar2MilliPoints(tStringLength
);
209 tStr
.s
= (char *)szString
;
213 tStr
.term
= tStringLength
;
214 e
= font_strwidth(&tStr
);
220 DBG_DEC(tStringLength
);
222 werr(0, "String width error %d: %s", e
->errnum
, e
->errmess
);
223 return lChar2MilliPoints(tStringLength
);
224 } /* end of lComputeStringWidth */
227 * tCountColumns - count the number of columns in a string
229 * Returns the number of columns
232 tCountColumns(const char *szString
, size_t tLength
)
234 fail(szString
== NULL
);
236 /* One byte, one character, one column */
238 } /* end of tCountColumns */
241 * tGetCharacterLength - the length of the specified character in bytes
243 * Returns the length in bytes
246 tGetCharacterLength(const char *szString
)
249 } /* end of tGetCharacterLength */