fontset.h 9.9 KB
Newer Older
Karl Heuer's avatar
Karl Heuer committed
1
/* Header for fontset handler.
2 3
   Copyright (C) 1998, 2002, 2003, 2004, 2005,
                 2006 Free Software Foundation, Inc.
Kenichi Handa's avatar
Kenichi Handa committed
4 5 6
   Copyright (C) 1995, 1997, 2000
     National Institute of Advanced Industrial Science and Technology (AIST)
     Registration Number H14PRO021
Karl Heuer's avatar
Karl Heuer committed
7

Karl Heuer's avatar
Karl Heuer committed
8 9 10 11 12 13
This file is part of GNU Emacs.

GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Karl Heuer's avatar
Karl Heuer committed
14

Karl Heuer's avatar
Karl Heuer committed
15 16 17 18
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
Karl Heuer's avatar
Karl Heuer committed
19

Karl Heuer's avatar
Karl Heuer committed
20 21
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING.  If not, write to
Lute Kamstra's avatar
Lute Kamstra committed
22 23
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.  */
Karl Heuer's avatar
Karl Heuer committed
24

25 26
#ifndef EMACS_FONTSET_H
#define EMACS_FONTSET_H
Karl Heuer's avatar
Karl Heuer committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

/* This data type is used for the font_table field of window system
   depending data area (e.g. struct x_display_info on X window).  */

struct font_info
{
  /* Pointer to window system dependent font structure.  On X window,
     this value should be coerced to (XFontStruct *).  */
  void *font;

  /* Index number of the font.  */
  int font_idx;

  /* Name to be used to find the font.  */
  char *name;

  /* Full name of the font given by a window system.  */
  char *full_name;

  /* Charset of characters displayed by the font.  */
  int charset;

49 50 51 52 53
#ifdef WINDOWSNT
  /* Codepage of characters that will be displayed by the font.  */
  int codepage;
#endif

Karl Heuer's avatar
Karl Heuer committed
54 55 56 57
  /* Maximum bound width over all existing characters of the font.  On
     X window, this is same as (font->max_bounds.width) */
  int size;

58 59
  /* Height of the font.  On X window, this is the same as
     (font->ascent + font->descent).  */
Karl Heuer's avatar
Karl Heuer committed
60 61
  int height;

62 63 64 65 66 67
  /* Width of the space glyph of the font.  */
  int space_width;

  /* Average width of glyphs in the font.  */
  int average_width;

68 69 70
  /* 1 iff `vertical-centering-font-regexp' matches this font name.
     In this case, we render characters at vartical center positions
     of lines.  */
71 72
  int vertical_centering;

73
  /* Encodings of the font indexed by CHARSET.  The value is one of
Karl Heuer's avatar
Karl Heuer committed
74 75 76 77 78 79 80 81 82 83 84 85 86
     0, 1, 2, or 3:
	0: code points 0x20..0x7F or 0x2020..0x7F7F are used
	1: code points 0xA0..0xFF or 0xA0A0..0xFFFF are used
	2: code points 0x20A0..0x7FFF are used
	3: code points 0xA020..0xFF7F are used
     For instance, ASCII and Latin-1 characters may use the same font
     but different code points (ASCII uses 0x20..0x7F and Latin-1 uses
     0xA0..0xFF).

     If the value can't be decided from information of the font, we
     consult `font-encoding-alist' to get of the corresponding charset
     whose default value is defined in lisp/fontset.el.  Since there's
     no charset whose id is 1, we use encoding[1] to store the
87 88 89 90
     encoding information decided by the font itself.

     If the member `font_encoder' is not NULL, this member is ignored.
  */
91
  unsigned char encoding[MAX_CHARSET + 1];
Karl Heuer's avatar
Karl Heuer committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

  /* The baseline position of a font is normally `ascent' value of the
     font.  However, there exists many fonts which don't set `ascent'
     an appropriate value to be used as baseline position.  This is
     typical in such ASCII fonts which are designed to be used with
     Chinese, Japanese, Korean characters.  When we use mixture of
     such fonts and normal fonts (having correct `ascent' value), a
     display line gets very ugly.  Since we have no way to fix it
     automatically, it is users responsibility to supply well designed
     fonts or correct `ascent' value of fonts.  But, the latter
     requires heavy work (modifying all bitmap data in BDF files).
     So, Emacs accepts a private font property
     `_MULE_BASELINE_OFFSET'.  If a font has this property, we
     calculate the baseline position by subtracting the value from
     `ascent'.  In other words, the value indicates how many bits
     higher we should draw a character of the font than normal ASCII
     text for a better looking.
109

Karl Heuer's avatar
Karl Heuer committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
     We also have to consider the fact that the concept of `baseline'
     differs among languages to which each character belongs.  For
     instance, baseline should be at the bottom most position of all
     glyphs for Chinese, Japanese, and Korean.  But, many of existing
     fonts for those characters doesn't have correct `ascent' values
     because they are designed to be used with ASCII fonts.  To
     display characters of different language on the same line, the
     best way will be to arrange them in the middle of the line.  So,
     in such a case, again, we utilize the font property
     `_MULE_BASELINE_OFFSET'.  If the value is larger than `ascent' we
     calculate baseline so that a character is arranged in the middle
     of a line.  */

  int baseline_offset;

  /* Non zero means a character should be composed at a position
     relative to the height (or depth) of previous glyphs in the
     following cases:
	(1) The bottom of the character is higher than this value.  In
	this case, the character is drawn above the previous glyphs.
	(2) The top of the character is lower than 0 (i.e. baseline
	height).  In this case, the character is drawn beneath the
	previous glyphs.

134
     This value is taken from a private font property
Karl Heuer's avatar
Karl Heuer committed
135 136 137
     `_MULE_RELATIVE_COMPOSE' which is introduced by Emacs.  */
  int relative_compose;

Kenichi Handa's avatar
Kenichi Handa committed
138 139 140 141
  /* Non zero means an ascent value to be used for a character
     registered in char-table `use-default-ascent'.  */
  int default_ascent;

Karl Heuer's avatar
Karl Heuer committed
142 143 144 145
  /* CCL program to calculate code points of the font.  */
  struct ccl_program *font_encoder;
};

146 147 148
/* A value which may appear in the member `encoding' of struch
   font_info indicating that a font itself doesn't tell which encoding
   to be used.  */
149
#define FONT_ENCODING_NOT_DECIDED 255
150

151 152 153
/* Forward declaration for prototypes.  */
struct frame;

Karl Heuer's avatar
Karl Heuer committed
154 155 156 157 158 159
/* The following six are window system dependent functions.
   Initialization routine of each window system should set appropriate
   functions to these variables.  For instance, in case of X window,
   x_term_init does this.  */

/* Return a pointer to struct font_info of font FONT_IDX of frame F.  */
160 161
extern struct font_info *(*get_font_info_func) P_ ((struct frame *f,
						    int font_idx));
Karl Heuer's avatar
Karl Heuer committed
162 163 164

/* Return a list of font names which matches PATTERN.  See the document of
   `x-list-fonts' for more detail.  */
165 166 167 168
extern Lisp_Object (*list_fonts_func) P_ ((struct frame *f,
					   Lisp_Object pattern,
					   int size,
					   int maxnames));
Karl Heuer's avatar
Karl Heuer committed
169 170 171

/* Load a font named NAME for frame F and return a pointer to the
   information of the loaded font.  If loading is failed, return -1.  */
172 173
extern struct font_info *(*load_font_func) P_ ((struct frame *f,
						char *name, int));
Karl Heuer's avatar
Karl Heuer committed
174 175 176

/* Return a pointer to struct font_info of a font named NAME for frame F.
   If no such font is loaded, return NULL.  */
177
extern struct font_info *(*query_font_func) P_ ((struct frame *f, char *name));
Karl Heuer's avatar
Karl Heuer committed
178 179 180 181

/* Additional function for setting fontset or changing fontset
   contents of frame F.  This function may change the coordinate of
   the frame.  */
182 183
extern void (*set_frame_fontset_func) P_ ((struct frame *f, Lisp_Object arg,
					   Lisp_Object oldval));
Karl Heuer's avatar
Karl Heuer committed
184

185 186 187 188 189
/* To find a CCL program, fs_load_font calls this function.
   The argument is a pointer to the struct font_info.
   This function set the memer `encoder' of the structure.  */
extern void (*find_ccl_program_func) P_ ((struct font_info *));

Karl Heuer's avatar
Karl Heuer committed
190
/* Check if any window system is used now.  */
191 192
extern void (*check_window_system_func) P_ ((void));

193 194
struct face;

195
extern void free_face_fontset P_ ((FRAME_PTR, struct face *));
196 197 198 199
extern Lisp_Object fontset_font_pattern P_ ((FRAME_PTR, int, int));
extern int face_suitable_for_char_p P_ ((struct face *, int));
extern int face_for_char P_ ((FRAME_PTR, struct face *, int));
extern int make_fontset_for_ascii_face P_ ((FRAME_PTR, int));
200
extern void set_default_ascii_font P_ ((Lisp_Object));
201 202 203
extern struct font_info *fs_load_font P_ ((struct frame *, int, char *, int,
					   struct face *));
extern int fs_query_fontset P_ ((Lisp_Object, int));
204
EXFUN (Fquery_fontset, 2);
205
extern Lisp_Object list_fontsets P_ ((struct frame *, Lisp_Object, int));
Karl Heuer's avatar
Karl Heuer committed
206 207

extern Lisp_Object Qfontset;
208
extern Lisp_Object Vuse_default_ascent;
209
extern Lisp_Object Vignore_relative_composition;
210
extern Lisp_Object Valternate_fontname_alist;
211
extern Lisp_Object Vfontset_alias_alist;
212
extern Lisp_Object Vvertical_centering_font_regexp;
Kenichi Handa's avatar
Kenichi Handa committed
213

214 215 216 217 218 219 220 221 222 223
/* Load a font named FONTNAME for displaying character C.  All fonts
   for frame F is stored in a table pointed by FONT_TABLE.  Return a
   pointer to the struct font_info of the loaded font.  If loading
   fails, return 0; If FONTNAME is NULL, the name is taken from the
   information of FONTSET.  If FONTSET is given, try to load a font
   whose size matches that of FONTSET, and, the font index is stored
   in the table for FONTSET.  */

#define FS_LOAD_FONT(f, c, fontname, fontset)  \
  fs_load_font (f, c, fontname, fontset, NULL)
224

225 226
#define FS_LOAD_FACE_FONT(f, c, fontname, face) \
  fs_load_font (f, c, fontname, -1, face)
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

/* Return an immutable id for font_info FONT_INFO on frame F.  The
   reason for this macro is hat one cannot hold pointers to font_info
   structures in other data structures, because the table is
   reallocated in x_list_fonts.  */

#define FONT_INFO_ID(F, FONT_INFO) \
     (FONT_INFO) - (FRAME_X_DISPLAY_INFO ((F))->font_table)

/* Given a font_info id ID, return a pointer to the font_info
   structure on frame F.  If ID is invalid, return null.  */

#define FONT_INFO_FROM_ID(F, ID)					\
     (((ID) >= 0 && (ID) < FRAME_X_DISPLAY_INFO ((F))->font_table_size)	\
      ? (FRAME_X_DISPLAY_INFO ((F))->font_table + (ID))			\
      : 0)

244 245 246 247
extern Lisp_Object fontset_name P_ ((int));
extern Lisp_Object fontset_ascii P_ ((int));
extern int fontset_height P_ ((int));

248
#endif /* EMACS_FONTSET_H */
Miles Bader's avatar
Miles Bader committed
249 250 251

/* arch-tag: c27cef7b-3cab-488a-8398-7a4daa96bb77
   (do not change this comment) */