UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fonts.h
1 /* fonts.h */
2 /* $Id: fonts.h,v 1.1 2000/02/17 15:02:24 vlad Exp $ */
3 #ifndef __fonts_h
4 #define __fonts_h
5 
6 /***********************************************************************
7  *
8  * Locale font support
9  *
10  ***********************************************************************/
11 
12 #include <X11/Xlib.h>
13 
14 #include <mix/wenv.h>
15 #include <mix/trans.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
20 
21 
22 /***********************************************************************
23  * Z font files
24  ***********************************************************************/
25 
26 /* Z-X font name list mapping filename */
27 #define ZLF_XFONTS_MAP_FILENAME "xfonts.list"
28 
29 /* Z-X font encoding list mapping filename */
30 #define ZLF_XFENC_MAP_FILENAME "xfenc.list"
31 
32 /* Maxmimum allowed width of line in xfonts.list */
33 #define ZLF_XFONTS_MAX_LINE_WIDTH 1024
34 
35 /* Maxmimum allowed width of line in xfenc.list */
36 #define ZLF_XFENC_MAX_LINE_WIDTH 1024
37 
38 
39 /***********************************************************************
40  * Z font naming schema
41  ***********************************************************************/
42 
43 /* Basic font characteristics (mask) */
44 #define ZLF_LANG (1<<0) /* language */
45 #define ZLF_METRIC (1<<1) /* proportional or non-prop */
46 #define ZLF_SIZE (1<<2) /* size in pt (approximately) */
47 #define ZLF_STYLE (1<<3) /* style of the font: normal, bold, italic */
48 
49 /* Local font name part separator:
50  LANG:METRIC:SIZE:STYLE:... */
51 #define ZLF_SEPARATOR ':'
52 
53 /* Local font name maximum length with EOL and separators */
54 #define ZLF_NAME_MAX_LEN (2+1+7+1+3+1+6+1)
55 
56 
57 /***********************************************************************
58  * Z font numeric id schema
59  ***********************************************************************/
60 
61 /* Z font identifier representation type */
62 typedef unsigned long ZFontId;
63 
64 /* Z font numeric id:
65  LANG: 0 - default (weGetPrefLanguage())
66  1 - English ("en")
67  2 - Russian ("ru")
68  3 - Chinese ("cn")
69  ..31 (up to 31 custom languages)
70  METRIC: 0 - non proportional (courier)
71  1 - proportional (times, helvetica etc)
72  SIZE: 0 - smallest available size
73  10, 16, 20, 24 - vertical pixel size
74  ..127 (up to pxlsz=127)
75  STYLE: 0 - any available style
76  1 - normal
77  2 - bold
78  3 - italic
79 
80  Per bit map:
81  0 1 2 3
82  01234567890123456789012345678901
83  |_____||___|||_||______________|
84  Size Lang M Style Reserved
85  */
86 
87 /* Z font identifier decoded */
88 typedef struct
89 {
90  unsigned size:7; /* 0-smallest available, #-pxlsz */
91  unsigned lang:5; /* 0-default, 1-en, 2-ru, 3-cn */
92  unsigned metric:1; /* 0-nonprop, 1-prop */
93  unsigned style:3; /* 0-any style, 1-normal, 2-bold, 3-italic */
94 
95 } ZFontIdBits;
96 
97 /* Z font union */
98 typedef union
99 {
100  ZFontId id; /* id number */
101  ZFontIdBits bits; /* bits of id */
102 
103 } ZFontIdUnited;
104 
105 
106 /* Bit-field get operations */
107 #define ZFontIdGetSize(ID) ((ZFontStyleKind)(((ID)>>0)&0x7f))
108 #define ZFontIdGetLang(ID) ((ZFontLangKind)(((ID)>>7)&0x1f))
109 #define ZFontIdGetMetric(ID) ((ZFontMetricKind)(((ID)>>12)&0x01))
110 #define ZFontIdGetStyle(ID) (((ID)>>13)&0x03)
111 
112 /* Bit-field set operations */
113 #define ZFontIdSetSize(ID,SI) ((ID)|((((unsigned)(SI))&0x7f)<<0))
114 #define ZFontIdSetLang(ID,LA) ((ID)|((((unsigned)(LA))&0x1f)<<7))
115 #define ZFontIdSetMetric(ID,ME) ((ID)|((((unsigned)(ME))&0x01)<<12))
116 #define ZFontIdSetStyle(ID,ST) ((ID)|((((unsigned)(ST))&0x03)<<13))
117 
118 /* Bit-field build operation */
119 #define ZFontBuildId(LA,ME,ST,SI) (((((unsigned)(SI))&0x7f)<<0)|\
120  ((((unsigned)(LA))&0x1f)<<7)|\
121  ((((unsigned)(ME))&0x01)<<12)|\
122  ((((unsigned)(ST))&0x03)<<13))
123 
124 /* Default localized font id = 0 */
125 #define ZFontDefaultId (ZFontBuildId(ZFontLangDefault,\
126  ZFontMetricNonProp,\
127  0, ZFontStyleAny))
128 
129 /* Mask to fetch all fonts */
130 #define ZAllFontsMask ((ZFontId)(-1))
131 
132 
133 /* Allowed languages */
134 typedef enum
135 {
136  ZFontLangDefault = 0,
137  ZFontLangEnglish = 1,
138  ZFontLangRussian = 2,
139  ZFontLangChinese = 3,
140 
141  __ZFontLangNumber /* special meaning */
142 
143 } ZFontLangKind;
144 
145 /* Language symbolic codes */
146 #define ZLF_LANG_ENGLISH WE_LANG_ENGLISH
147 #define ZLF_LANG_RUSSIAN WE_LANG_RUSSIAN
148 #define ZLF_LANG_CHINESE WE_LANG_CHINESE
149 
150 /* Allowed metrics */
151 typedef enum
152 {
153  ZFontMetricNonProp = 0, /* non-proportional (courier, typewriter) */
154  ZFontMetricProp = 1, /* proportional (times, helvetica, etc) */
155 
156  __ZFontMetricNumber /* special meaning */
157 
158 } ZFontMetricKind;
159 
160 /* Metric symbolic codes */
161 #define ZLF_METRIC_NONPROP "nonprop"
162 #define ZLF_METRIC_PROP "prop"
163 
164 /* Type for font size (pixel): 0-smallest available, 16, 20, 24 etc */
165 typedef int ZFontSizeType;
166 
167 /* Allowed styles */
168 typedef enum
169 {
170  ZFontStyleAny = 0,
171  ZFontStyleNormal = 1,
172  ZFontStyleBold = 2,
173  ZFontStyleItalic = 3,
174 
175  __ZFontStyleNumber /* special meaning */
176 
177 } ZFontStyleKind;
178 
179 /* Style symbolic codes */
180 #define ZLF_STYLE_NORMAL "normal"
181 #define ZLF_STYLE_BOLD "bold"
182 #define ZLF_STYLE_ITALIC "italic"
183 
184 
185 /***********************************************************************
186  * Methods
187  ***********************************************************************/
188 
189 /*
190  * Font name
191  */
192 
193 /* Build string Z font name (dynamic/apriori memory allocated) */
194 char* ZBuildFontName (ZFontId zfid);
195 char* ZBuildFontNameHere (ZFontId zfid,
196  char szBuf[ZLF_NAME_MAX_LEN]);
197 
198 /* Parse string Z font name. Returns ZFontDefaultId if some errors
199  occured. */
200 ZFontId ZParseFontName (const char* zfname);
201 
202 
203 /*
204  * Font encoding
205  */
206 
207 /* Load system encoding schema only once per session. */
208 void ZFontEncMapInit ();
209 
210 /* Load xfenc.list mapping file
211  Returns number of failed lines (missed encoding or bad syntax) or
212  -1 - NULL szPath;
213  -2 - can't open file szPath;
214  -3 - can't alloc some memory block. */
215 int ZLoadFontEncMap (const char* szPath);
216 
217 /* Return the list of encodings matches to given X font name.
218  List is dynamically allocated and contains pointers to const char.
219  The last pointer - NULL. Don't change any of the encoding strings! */
220 char** ZFontXEncMatched (const char* szXFont);
221 
222 /* Return encoding for representing given language by given X font. */
223 const char* ZGetXFontNameByLang (ZFontId zfid, const char* szLang,
224  TextEncoding* eTextEnc);
225 
226 
227 /*
228  * Font list
229  */
230 
231 /* Load system font mapping schema only once per session. */
232 void ZFontMapInit ();
233 
234 /* Load xfonts.list mapping file
235  Returns number of failed lines (bad syntax) or
236  -1 - NULL szPath;
237  -2 - can't open file szPath;
238  -3 - can't alloc some memory block. */
239 int ZLoadFontMap (const char* szPath);
240 
241 /* Get masked list of fonts dynamically allocated.
242  If zfmask == ZAllFontsMask then all fonts will be listed. */
243 void ZGetFontList (ZFontId zfmask, ZFontId** zflist, int* zfnum);
244 
245 
246 /*
247  * X font porting
248  */
249 
250 /* Get name of the closest X font to given z font. Returns NULL if no
251  font is available. err_mask contains bits of font where errors or
252  not exact matches were found. */
253 const char* ZGetXFontName (ZFontId zfid, int* err_mask);
254 
255 /* Load font and query its info. */
256 XFontStruct* ZXLoadQueryFont (Display* dpy, ZFontId zfid);
257 
258 
259 #ifdef __cplusplus
260 };
261 #endif /* __cplusplus */
262 
263 #endif /* fonts.h */
Definition: fonts.h:88
Definition: fonts.h:98