All codes rewritten or adjusted for the change of
[bpt/emacs.git] / src / fontset.h
CommitLineData
4ed46869 1/* Header for fontset handler.
75c8c592
RS
2 Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN.
3 Licensed to the Free Software Foundation.
4ed46869 4
369314dc
KH
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
4ed46869 11
369314dc
KH
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
4ed46869 16
369314dc
KH
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
4ed46869
KH
21
22#ifndef _FONTSET_H
23#define _FONTSET_H
24
4ed46869
KH
25/* This data type is used for the font_table field of window system
26 depending data area (e.g. struct x_display_info on X window). */
27
28struct font_info
29{
30 /* Pointer to window system dependent font structure. On X window,
31 this value should be coerced to (XFontStruct *). */
32 void *font;
33
34 /* Index number of the font. */
35 int font_idx;
36
37 /* Name to be used to find the font. */
38 char *name;
39
40 /* Full name of the font given by a window system. */
41 char *full_name;
42
43 /* Charset of characters displayed by the font. */
44 int charset;
45
46 /* Maximum bound width over all existing characters of the font. On
47 X window, this is same as (font->max_bounds.width) */
48 int size;
49
50 /* Height of the font. On X window, this is same as (font->ascent
51 + font->descent). */
52 int height;
53
21fa1afa
KH
54 /* 1 iff we render characters at vartical center positions of lines. */
55 int vertical_centering;
56
4ed46869
KH
57 /* Encodings of the font indexed by CHARSET. The value an integer
58 0, 1, 2, or 3:
59 0: code points 0x20..0x7F or 0x2020..0x7F7F are used
60 1: code points 0xA0..0xFF or 0xA0A0..0xFFFF are used
61 2: code points 0x20A0..0x7FFF are used
62 3: code points 0xA020..0xFF7F are used
63 For instance, ASCII and Latin-1 characters may use the same font
64 but different code points (ASCII uses 0x20..0x7F and Latin-1 uses
65 0xA0..0xFF).
66
67 If the value can't be decided from information of the font, we
68 consult `font-encoding-alist' to get of the corresponding charset
69 whose default value is defined in lisp/fontset.el. Since there's
70 no charset whose id is 1, we use encoding[1] to store the
71 encoding information decided by the font itself. */
d987e6cb 72 unsigned char encoding[MAX_CHARSET + 1];
4ed46869
KH
73
74 /* The baseline position of a font is normally `ascent' value of the
75 font. However, there exists many fonts which don't set `ascent'
76 an appropriate value to be used as baseline position. This is
77 typical in such ASCII fonts which are designed to be used with
78 Chinese, Japanese, Korean characters. When we use mixture of
79 such fonts and normal fonts (having correct `ascent' value), a
80 display line gets very ugly. Since we have no way to fix it
81 automatically, it is users responsibility to supply well designed
82 fonts or correct `ascent' value of fonts. But, the latter
83 requires heavy work (modifying all bitmap data in BDF files).
84 So, Emacs accepts a private font property
85 `_MULE_BASELINE_OFFSET'. If a font has this property, we
86 calculate the baseline position by subtracting the value from
87 `ascent'. In other words, the value indicates how many bits
88 higher we should draw a character of the font than normal ASCII
89 text for a better looking.
90
91 We also have to consider the fact that the concept of `baseline'
92 differs among languages to which each character belongs. For
93 instance, baseline should be at the bottom most position of all
94 glyphs for Chinese, Japanese, and Korean. But, many of existing
95 fonts for those characters doesn't have correct `ascent' values
96 because they are designed to be used with ASCII fonts. To
97 display characters of different language on the same line, the
98 best way will be to arrange them in the middle of the line. So,
99 in such a case, again, we utilize the font property
100 `_MULE_BASELINE_OFFSET'. If the value is larger than `ascent' we
101 calculate baseline so that a character is arranged in the middle
102 of a line. */
103
104 int baseline_offset;
105
106 /* Non zero means a character should be composed at a position
107 relative to the height (or depth) of previous glyphs in the
108 following cases:
109 (1) The bottom of the character is higher than this value. In
110 this case, the character is drawn above the previous glyphs.
111 (2) The top of the character is lower than 0 (i.e. baseline
112 height). In this case, the character is drawn beneath the
113 previous glyphs.
114
467e7675 115 This value is taken from a private font property
4ed46869
KH
116 `_MULE_RELATIVE_COMPOSE' which is introduced by Emacs. */
117 int relative_compose;
118
b65dbda3
KH
119 /* Non zero means an ascent value to be used for a character
120 registered in char-table `use-default-ascent'. */
121 int default_ascent;
122
4ed46869
KH
123 /* CCL program to calculate code points of the font. */
124 struct ccl_program *font_encoder;
125};
126
71c27002
KH
127/* A value which may appear in the member encoding of struch font_info
128 indicating that a font itself doesn't tell which encoding to be
129 used. */
c2c8997e 130#define FONT_ENCODING_NOT_DECIDED 255
71c27002 131
4ed46869
KH
132#define FONT_NOT_OPENED -1
133#define FONT_NOT_FOUND -2
134
135struct fontset_info
136{
137 /* Name of the fontset. */
138 char *name;
139
140 /* Size of the fontset. This is the same as the size of ASCII font
141 of this fontset. */
142 int size;
143
144 /* Height of the tallest font in the fontset. */
145 int height;
146
147 /* Table of font name for each character set. */
467e7675 148 char *fontname[MAX_CHARSET + 1];
4ed46869
KH
149
150 /* Table of index numbers of fonts indexed by charset. If a font is
151 not yet loaded, the value is -1 (FONT_NOT_OPENED). If font
152 loading is failed, the value is -2 (FONT_NOT_FOUND). */
467e7675 153 int font_indexes[MAX_CHARSET + 1];
4ed46869
KH
154};
155
156/* This data type is used for the fontset_data field of struct frame. */
157
158struct fontset_data
159{
160 /* A table of pointers to all the fontsets. */
161 struct fontset_info **fontset_table;
162
163 /* The current capacity of fontset_table. */
164 int fontset_table_size;
165
166 /* The number of fontsets actually stored in fontset_table.
167 fontset_table[n] is used and valid iff 0 <= n < n_fontsets.
168 0 <= n_fontsets <= fontset_table_size. */
169 int n_fontsets;
170};
171
d748a3db
AS
172/* Forward declaration for prototypes. */
173struct frame;
174
4ed46869
KH
175/* The following six are window system dependent functions.
176 Initialization routine of each window system should set appropriate
177 functions to these variables. For instance, in case of X window,
178 x_term_init does this. */
179
180/* Return a pointer to struct font_info of font FONT_IDX of frame F. */
d748a3db
AS
181extern struct font_info *(*get_font_info_func) P_ ((struct frame *f,
182 int font_idx));
4ed46869
KH
183
184/* Return a list of font names which matches PATTERN. See the document of
185 `x-list-fonts' for more detail. */
9625ce22
KH
186extern Lisp_Object (*list_fonts_func) P_ ((struct frame *f,
187 Lisp_Object pattern,
188 int size,
189 int maxnames));
4ed46869
KH
190
191/* Load a font named NAME for frame F and return a pointer to the
192 information of the loaded font. If loading is failed, return -1. */
d748a3db
AS
193extern struct font_info *(*load_font_func) P_ ((struct frame *f,
194 char *name, int));
4ed46869
KH
195
196/* Return a pointer to struct font_info of a font named NAME for frame F.
197 If no such font is loaded, return NULL. */
d748a3db 198extern struct font_info *(*query_font_func) P_ ((struct frame *f, char *name));
4ed46869
KH
199
200/* Additional function for setting fontset or changing fontset
201 contents of frame F. This function may change the coordinate of
202 the frame. */
d748a3db
AS
203extern void (*set_frame_fontset_func) P_ ((struct frame *f, Lisp_Object arg,
204 Lisp_Object oldval));
4ed46869 205
c2c8997e
KH
206/* To find a CCL program, fs_load_font calls this function.
207 The argument is a pointer to the struct font_info.
208 This function set the memer `encoder' of the structure. */
209extern void (*find_ccl_program_func) P_ ((struct font_info *));
210
4ed46869 211/* Check if any window system is used now. */
d748a3db
AS
212extern void (*check_window_system_func) P_ ((void));
213
214extern struct fontset_data *alloc_fontset_data P_ ((void));
215extern void free_fontset_data P_ ((struct fontset_data *));
216extern struct font_info *fs_load_font P_ ((struct frame *, struct font_info *,
217 int, char *, int));
218extern int fs_query_fontset P_ ((struct frame *, char *));
219extern int fs_register_fontset P_ ((struct frame *, Lisp_Object));
c2c8997e 220EXFUN (Fquery_fontset, 2);
d748a3db 221extern Lisp_Object list_fontsets P_ ((struct frame *, Lisp_Object, int));
4ed46869 222extern Lisp_Object Vglobal_fontset_alist;
e18f9922
GM
223struct frame;
224int fs_query_fontset P_ ((struct frame *f, char *name));
4ed46869
KH
225
226extern Lisp_Object Qfontset;
b65dbda3 227extern Lisp_Object Vuse_default_ascent;
32eb3f08 228extern Lisp_Object Vignore_relative_composition;
015e1bb0 229extern Lisp_Object Valternate_fontname_alist;
e497c1f3
KH
230extern Lisp_Object Vhighlight_wrong_size_font;
231extern Lisp_Object Vclip_large_size_font;
21fa1afa 232extern Lisp_Object Vvertical_centering_font_regexp;
7bca5cf2
KH
233extern int font_idx_temp;
234
235/* Load a font named FONTNAME for displaying CHARSET on frame F.
236 All fonts for frame F is stored in a table pointed by FONT_TABLE.
237 Return a pointer to the struct font_info of the loaded font.
238 If loading fails, return 0;
239 If FONTNAME is NULL, the name is taken from the information of FONTSET.
240 If FONTSET is given, try to load a font whose size matches that of
241 FONTSET, and, the font index is stored in the table for FONTSET. */
242
243#define FS_LOAD_FONT(f, font_table, charset, fontname, fontset) \
244 (fontset >= 0 && fontset < FRAME_FONTSET_DATA (f)->n_fontsets \
245 && (font_idx_temp = (FRAME_FONTSET_DATA (f) \
246 ->fontset_table[fontset]->font_indexes[charset]), \
247 font_idx_temp >= 0) \
248 ? font_table + font_idx_temp \
249 : fs_load_font (f, font_table, charset, fontname, fontset))
250
e18f9922
GM
251extern Lisp_Object Vfontset_alias_alist;
252extern Lisp_Object Vglobal_fontset_alist;
253
254
255/* Return an immutable id for font_info FONT_INFO on frame F. The
256 reason for this macro is hat one cannot hold pointers to font_info
257 structures in other data structures, because the table is
258 reallocated in x_list_fonts. */
259
260#define FONT_INFO_ID(F, FONT_INFO) \
261 (FONT_INFO) - (FRAME_X_DISPLAY_INFO ((F))->font_table)
262
263/* Given a font_info id ID, return a pointer to the font_info
264 structure on frame F. If ID is invalid, return null. */
265
266#define FONT_INFO_FROM_ID(F, ID) \
267 (((ID) >= 0 && (ID) < FRAME_X_DISPLAY_INFO ((F))->font_table_size) \
268 ? (FRAME_X_DISPLAY_INFO ((F))->font_table + (ID)) \
269 : 0)
270
d295ed3c 271#endif /* _FONTSET_H */