1 /* font.h -- header file for the font module.
2 Copyright (C) 2003, 2004
3 National Institute of Advanced Industrial Science and Technology (AIST)
4 Registration Number H15PRO112
6 This file is part of the m17n library.
8 The m17n library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public License
10 as published by the Free Software Foundation; either version 2.1 of
11 the License, or (at your option) any later version.
13 The m17n library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the m17n library; if not, write to the Free
20 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 /* The order of MFONT_FOUNDRY to MFONT_ADSTYLE must be the same as
29 enum MFaceProperty. */
38 /* The follwoings should not be used as an index to
43 MFONT_PROPERTY_MAX = MFONT_SIZE
56 MFONT_SOURCE_UNDECIDED = 0,
63 MFONT_SPACING_UNDECIDED,
64 MFONT_SPACING_PROPORTIONAL,
66 MFONT_SPACING_CHARCELL
69 typedef struct MFontEncoding MFontEncoding;
70 typedef struct MFontDriver MFontDriver;
72 /** Information about a font. This structure is used in three ways:
73 FONT-OBJ, FONT-OPENED, and FONT-SPEC.
75 FONT-OBJ: To store information of an existing font. Instances
76 appear only in <font_list> of MDisplay.
78 FONT-OPENED: To store information of an opened font. Instances
79 appear only in <opend_list> of MDisplay.
81 FONT-SPEC: To store specifications of a font. Instances appear
82 only in <spec_list> of MFontset. */
86 /** Numeric value of each font property. Also used as an index to
87 the table @c mfont__property_table to get the actual name of the
90 For FONT-OBJ, FONT-OPENED: The value is greater than zero.
92 For FONT-SPEC: The value is equal to or greater than zero. Zero
93 means that the correponding property is not specified (i.e. wild
96 For FONT-OBJ: If the value is 0, the font is scalable or
99 For FONT-OPENED: The actual size of opened font.
101 <property>[MFONT_RESY] is the designed resolution of the font in
102 DPI, or zero. Zero means that the font is scalable.
104 For the time being, we mention only Y-resolution (resy) and
105 assume that resx is always equal to resy. */
106 unsigned short property[MFONT_PROPERTY_MAX];
109 unsigned spacing : 2;
110 unsigned for_full_width : 1;
111 /* For FONT-OBJ, 1 means `size' is a logical or of bit masks for
112 available pixel sizes (Nth bit corresponds to (6 + N) pixels), 0
113 means `size' is an actual pixel size * 10. For FONT-SPEC and
114 FONT-OPENED, this is always 0, and `size' is an actual pixel
116 unsigned multiple_sizes : 1;
120 MFontEncoding *encoding;
128 } MFontPropertyTable;
130 extern MFontPropertyTable mfont__property_table[MFONT_REGISTRY + 1];
132 /** Return the symbol of the Nth font property of FONT. */
133 #define FONT_PROPERTY(font, n) \
134 (mfont__property_table[(n)].names[(font)->property[(n)]])
138 /* Font spec used to find the font.
139 MRealizedFont::spec.property[MFONT_TYPE] is MFONT_TYPE_REALIZED
140 so that this object can be distingushed from MFont. */
143 /* Frame on which the font is realized. */
146 /* The found font. */
151 /* Font Layout Table for the font. This is just a container to
152 carry the infomation. */
155 /* 1 iff the font is opend by encapsulating client-side font data. */
158 /* Extra information set by MRealizedFont::driver->open. If
159 non-NULL, it must be a pointer to a managed object. */
164 int ascent, descent, max_advance, average_width, baseline_offset;
166 /* Pointer to the font structure. */
172 typedef struct MFLTFontForRealized {
174 MRealizedFont *rfont;
175 } MFLTFontForRealized;
182 /** Structure to hold a list of fonts. */
193 /** Return a font best matching with FONT. */
194 MFont *(*select) (MFrame *frame, MFont *font, int limited_size);
196 /** Open a font specified by RFONT. */
197 MRealizedFont *(*open) (MFrame *frame, MFont *font, MFont *spec,
198 MRealizedFont *rfont);
200 /** Set metrics of glyphs in GSTRING from FROM to TO. */
201 void (*find_metric) (MRealizedFont *rfont, MGlyphString *gstring,
204 /** Check if the font has a glyph for CODE. CODE is a code point of
205 a character in font->encoder->encoding_charset. Return nonzero
206 iff the font has the glyph. */
207 int (*has_char) (MFrame *frame, MFont *font, MFont *spec,
208 int c, unsigned code);
210 /** Encode CODE into a glyph code the font. CODE is a code point of
211 a character in rfont->encoder->encoding_charset. If the font
212 has no glyph for CODE, return MCHAR_INVALID_CODE. */
213 unsigned (*encode_char) (MFrame *frame, MFont *font, MFont *spec,
216 /** Draw glyphs from FROM to TO (exclusive) on window WIN of FRAME
217 at coordinate (X, Y) relative to WIN. */
218 void (*render) (MDrawWindow win, int x, int y,
219 MGlyphString *gstring, MGlyph *from, MGlyph *to,
220 int reverse, MDrawRegion region);
222 /** Push to PLIST fonts matching with FONT. MAXNUM if greater than
223 0 limits the number of listed fonts. Return the number of fonts
225 int (*list) (MFrame *frame, MPlist *plist, MFont *font, int maxnum);
227 /** Push to PLIST font family names (symbol) available on FRAME. */
228 void (*list_family_names) (MFrame *frame, MPlist *plist);
230 /** Check if RFONT support CAPABILITY. */
231 int (*check_capability) (MRealizedFont *rfont, MSymbol capability);
233 /** Open a font by encapsulating DATA. */
234 MRealizedFont *(*encapsulate) (MFrame *frame, MSymbol source, void *data);
236 void (*close) (MRealizedFont *rfont);
238 int (*check_otf) (MFLTFont *font, MFLTOtfSpec *spec);
240 int (*drive_otf) (MFLTFont *font, MFLTOtfSpec *spec,
241 MFLTGlyphString *in, int from, int to,
242 MFLTGlyphString *out, MFLTGlyphAdjustment *adjustment);
245 /** Initialize the members of FONT. */
247 #define MFONT_INIT(font) memset ((font), 0, sizeof (MFont))
249 extern MSymbol Mlayouter;
250 extern MSymbol Miso8859_1, Miso10646_1, Municode_bmp, Municode_full;
251 extern MSymbol Mapple_roman;
253 extern int mfont__flt_init ();
255 extern void mfont__flt_fini ();
258 #include <ft2build.h>
259 #include FT_FREETYPE_H
261 #ifdef HAVE_FONTCONFIG
262 #include <fontconfig/fontconfig.h>
267 #else /* not HAVE_OTF */
268 typedef unsigned OTF_Tag;
269 #endif /* not HAVE_OTF */
271 enum MFontOpenTypeTable
290 } features[MFONT_OTT_MAX];
293 extern MFontDriver mfont__ft_driver;
295 extern int mfont__ft_init ();
297 extern void mfont__ft_fini ();
299 extern int mfont__ft_parse_name (const char *name, MFont *font);
301 extern char *mfont__ft_unparse_name (MFont *font);
305 extern int mfont__ft_drive_otf (MGlyphString *gstring, int from, int to,
306 MFontCapability *capability);
308 extern int mfont__ft_decode_otf (MGlyph *g);
310 #endif /* HAVE_OTF */
312 #endif /* HAVE_FREETYPE */
314 extern void mfont__free_realized (MRealizedFont *rfont);
316 extern int mfont__match_p (MFont *font, MFont *spec, int prop);
318 extern int mfont__merge (MFont *dst, MFont *src, int error_on_conflict);
320 extern void mfont__set_spec_from_face (MFont *spec, MFace *face);
322 extern MSymbol mfont__set_spec_from_plist (MFont *spec, MPlist *plist);
324 extern int mfont__has_char (MFrame *frame, MFont *font, MFont *spec, int c);
326 extern unsigned mfont__encode_char (MFrame *frame, MFont *font, MFont *spec,
329 extern int mfont__get_glyph_id (MFLTFont *font, MFLTGlyphString *gstring,
332 extern MFont *mfont__select (MFrame *frame, MFont *font, int max_size);
334 extern MFontList *mfont__list (MFrame *frame, MFont *spec, MFont *request,
337 extern MRealizedFont *mfont__open (MFrame *frame, MFont *font, MFont *spec);
339 extern void mfont__get_metric (MGlyphString *gstring, int from, int to);
341 extern int mfont__get_metrics (MFLTFont *font, MFLTGlyphString *gstring,
344 extern void mfont__set_property (MFont *font, enum MFontProperty key,
347 extern int mfont__split_name (char *name, int *property_idx,
348 unsigned short *point, unsigned short *resy);
350 extern int mfont__parse_name_into_font (const char *name, MSymbol format,
353 extern MPlist *mfont__encoding_list (void);
355 extern MFontCapability *mfont__get_capability (MSymbol sym);
357 extern int mfont__check_capability (MRealizedFont *rfont, MSymbol capability);
359 extern unsigned mfont__flt_encode_char (MSymbol layouter_name, int c);
361 extern int mfont__flt_run (MGlyphString *gstring, int from, int to,
362 MRealizedFace *rface);
364 #endif /* _M17N_FONT_H_ */