X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Ffont.h;h=985aedda491d70b66d711afc232bd504f1ae3b4e;hb=032fa01988c08909d017f7e1ef922335a55fd7c5;hp=5c9f0be1e0af50e80a37c278b6a5df1b1ce4b733;hpb=8dd2171ec49e473f44d959725ed2daf44503e22e;p=m17n%2Fm17n-lib.git diff --git a/src/font.h b/src/font.h index 5c9f0be..985aedd 100644 --- a/src/font.h +++ b/src/font.h @@ -23,22 +23,6 @@ #ifndef _M17N_FONT_H_ #define _M17N_FONT_H_ -/** Type of font. Now obsolete. */ - -enum MFontType - { - /** Fonts supproted by a window system natively. On X Window - System, it is an X font. */ - MFONT_TYPE_WIN, - - /** Fonts supported by FreeType library. */ - MFONT_TYPE_FT, - - /** anchor */ - MFONT_TYPE_MAX - }; - - enum MFontProperty { /* The order of MFONT_FOUNDRY to MFONT_ADSTYLE must be the same as @@ -50,12 +34,41 @@ enum MFontProperty MFONT_STRETCH, MFONT_ADSTYLE, MFONT_REGISTRY, - MFONT_SIZE, MFONT_RESY, + /* The follwoings should not be used as an index to + MFont->propperty. */ + MFONT_SIZE, + MFONT_SPACING, /* anchor */ - MFONT_PROPERTY_MAX + MFONT_PROPERTY_MAX = MFONT_SIZE + }; + +enum MFontType + { + MFONT_TYPE_SPEC, + MFONT_TYPE_OBJECT, + MFONT_TYPE_REALIZED, + MFONT_TYPE_FAILURE }; +enum MFontSource + { + MFONT_SOURCE_UNDECIDED = 0, + MFONT_SOURCE_X = 1, + MFONT_SOURCE_FT = 2 + }; + +enum MFontSpacing + { + MFONT_SPACING_UNDECIDED, + MFONT_SPACING_PROPORTIONAL, + MFONT_SPACING_MONO, + MFONT_SPACING_CHARCELL + }; + +typedef struct MFontEncoding MFontEncoding; +typedef struct MFontDriver MFontDriver; + /** Information about a font. This structure is used in three ways: FONT-OBJ, FONT-OPENED, and FONT-SPEC. @@ -80,19 +93,27 @@ struct MFont means that the correponding property is not specified (i.e. wild card). - [MFONT_SIZE] is the size of the font in 1/10 pixels. - For FONT-OBJ: If the value is 0, the font is scalable or auto-scaled. For FONT-OPENED: The actual size of opened font. - [MFONT_RESY] is the designed resolution of the font in + [MFONT_RESY] is the designed resolution of the font in DPI, or zero. Zero means that the font is scalable. For the time being, we mention only Y-resolution (resy) and assume that resx is always equal to resy. */ unsigned short property[MFONT_PROPERTY_MAX]; + enum MFontType type : 2; + enum MFontSource source : 2; + enum MFontSpacing spacing : 2; + unsigned for_full_width : 1; + /* Pixel size of the font in 1/10 pixels. The negative value means + a point size in 1/10 pt. */ + int size : 25; + MSymbol file; + MSymbol capability; + MFontEncoding *encoding; }; typedef struct @@ -106,80 +127,77 @@ extern MFontPropertyTable mfont__property_table[MFONT_REGISTRY + 1]; /** Return the symbol of the Nth font property of FONT. */ #define FONT_PROPERTY(font, n) \ - mfont__property_table[(n)].names[(font)->property[(n)]] - -typedef struct MFontEncoding MFontEncoding; + (mfont__property_table[(n)].names[(font)->property[(n)]]) struct MRealizedFont { - /* Frame on which the font is realized. */ - MFrame *frame; - - /* Font spec used to find the font. */ + /* Font spec used to find the font. + MRealizedFont::spec.property[MFONT_TYPE] is MFONT_TYPE_REALIZED + so that this object can be distingushed from MFont. */ MFont spec; - /* Font spec requested by a face. */ - MFont request; + /* Frame on which the font is realized. */ + MFrame *frame; /* The found font. */ - MFont font; - - /* How well matches with . */ - int score; + MFont *font; MFontDriver *driver; - /* Font Layout Table for the font. */ + /* Font Layout Table for the font. This is just a container to + carry the infomation. */ MSymbol layouter; - /* 0: not yet tried to open - -1: failed to open - 1: succeessfully opened. */ - int status; - - /* Extra information set by ->select or ->open. If + /* Extra information set by MRealizedFont::driver->open. If non-NULL, it must be a pointer to a managed object. */ void *info; - short ascent, descent; - - MFontEncoding *encoding; - - /* Type of the font: Mx, Mfreetype, or Mxft. */ - MSymbol type; + int ascent, descent, max_advance, average_width, baseline_offset; /* Pointer to the font structure. */ void *fontp; + + MRealizedFont *next; }; -/** Structure to hold a list of fonts of each registry. */ +typedef struct { + MFont *font; + int score; +} MFontScore; + +/** Structure to hold a list of fonts. */ typedef struct { - MSymbol tag; + MFont object; + MFontScore *fonts; int nfonts; - MFont *fonts; } MFontList; - struct MFontDriver { - /** Return a font satisfying REQUEST and best matching with SPEC. - For the moment, LIMITTED_SIZE is ignored. */ - MRealizedFont *(*select) (MFrame *frame, MFont *spec, MFont *request, - int limitted_size); + /** Return a font best matching with FONT. */ + MFont *(*select) (MFrame *frame, MFont *font, int limited_size); /** Open a font specified by RFONT. */ - int (*open) (MRealizedFont *rfont); + MRealizedFont *(*open) (MFrame *frame, MFont *font, MFont *spec, + MRealizedFont *rfont); /** Set metrics of glyphs in GSTRING from FROM to TO. */ void (*find_metric) (MRealizedFont *rfont, MGlyphString *gstring, int from, int to); + /** Check if the font has a glyph for CODE. CODE is a code point of + a character in font->encoder->encoding_charset. Return nonzero + iff the font has the glyph. */ + int (*has_char) (MFrame *frame, MFont *font, MFont *spec, + int c, unsigned code); + /** Encode CODE into a glyph code the font. CODE is a code point of a character in rfont->encoder->encoding_charset. If the font has no glyph for CODE, return MCHAR_INVALID_CODE. */ - unsigned (*encode_char) (MRealizedFont *rfont, unsigned code); + unsigned (*encode_char) (MFrame *frame, MFont *font, MFont *spec, + unsigned code); /** Draw glyphs from FROM to TO (exclusive) on window WIN of FRAME at coordinate (X, Y) relative to WIN. */ @@ -187,9 +205,13 @@ struct MFontDriver MGlyphString *gstring, MGlyph *from, MGlyph *to, int reverse, MDrawRegion region); - /** Push to PLIST a list of fonts matching with FONT. LANGUAGE, if - not Mnil, limits fonts to ones that support LANGUAGE. */ - void (*list) (MFrame *frame, MPlist *plist, MFont *font, MSymbol language); + /** Push to PLIST fonts matching with FONT. MAXNUM if greater than + 0 limits the number of listed fonts. Return the number of fonts + listed. */ + int (*list) (MFrame *frame, MPlist *plist, MFont *font, int maxnum); + + /** Check if RFONT support CAPABILITY. */ + int (*check_capability) (MRealizedFont *rfont, MSymbol capability); }; /** Initialize the members of FONT. */ @@ -197,6 +219,8 @@ struct MFontDriver #define MFONT_INIT(font) memset ((font), 0, sizeof (MFont)) extern MSymbol Mlayouter; +extern MSymbol Miso8859_1, Miso10646_1, Municode_bmp, Municode_full; +extern MSymbol Mapple_roman; extern int mfont__flt_init (); @@ -212,28 +236,30 @@ extern void mfont__flt_fini (); #ifdef HAVE_OTF #include -#endif /* HAVE_OTF */ +#else /* not HAVE_OTF */ +typedef unsigned OTF_Tag; +#endif /* not HAVE_OTF */ + +enum MFontOpenTypeTable + { + MFONT_OTT_GSUB, + MFONT_OTT_GPOS, + MFONT_OTT_MAX + }; typedef struct { M17NObject control; - MFont font; - char *filename; - int otf_flag; /* This font is OTF (1), may be OTF (0), is not OTF (-1). */ - MPlist *charmap_list; - int charmap_index; - FT_Face ft_face; - char *languages; -#ifdef HAVE_OTF - OTF *otf; -#endif /* HAVE_OTF */ -#ifdef HAVE_FONTCONFIG - FcLangSet *langset; -#else - void *langset; -#endif - void *extra_info; /* Xft uses this member. */ -} MFTInfo; + MSymbol *lang; + MSymbol script; + OTF_Tag script_tag; + OTF_Tag langsys_tag; + struct { + char *str; + int nfeatures; + OTF_Tag *tags; + } features[MFONT_OTT_MAX]; +} MFontCapability; extern MFontDriver mfont__ft_driver; @@ -241,15 +267,14 @@ extern int mfont__ft_init (); extern void mfont__ft_fini (); -extern int mfont__ft_parse_name (char *name, MFont *font); +extern int mfont__ft_parse_name (const char *name, MFont *font); extern char *mfont__ft_unparse_name (MFont *font); #ifdef HAVE_OTF extern int mfont__ft_drive_otf (MGlyphString *gstring, int from, int to, - MSymbol script, MSymbol langsys, - MSymbol gsub_features, MSymbol gpos_features); + MFontCapability *capability); extern int mfont__ft_decode_otf (MGlyph *g); @@ -261,8 +286,7 @@ extern void mfont__free_realized (MRealizedFont *rfont); extern int mfont__match_p (MFont *font, MFont *spec, int prop); -extern int mfont__score (MFont *font, MFont *spec, MFont *request, - int limitted_size); +extern int mfont__merge (MFont *dst, MFont *src, int error_on_conflict); extern void mfont__set_spec_from_face (MFont *spec, MFace *face); @@ -270,13 +294,17 @@ extern MSymbol mfont__set_spec_from_plist (MFont *spec, MPlist *plist); extern void mfont__resize (MFont *spec, MFont *request); -extern unsigned mfont__encode_char (MRealizedFont *rfont, int c); +extern int mfont__has_char (MFrame *frame, MFont *font, MFont *spec, int c); + +extern unsigned mfont__encode_char (MFrame *frame, MFont *font, MFont *spec, + int c); + +extern MFont *mfont__select (MFrame *frame, MFont *font, int max_size); -extern MRealizedFont *mfont__select (MFrame *frame, MFont *spec, - MFont *request, int limitted_size, - MSymbol layouter); +extern MFontList *mfont__list (MFrame *frame, MFont *spec, MFont *request, + int limited_size); -extern int mfont__open (MRealizedFont *rfont); +extern MRealizedFont *mfont__open (MFrame *frame, MFont *font, MFont *spec); extern void mfont__get_metric (MGlyphString *gstring, int from, int to); @@ -286,15 +314,15 @@ extern void mfont__set_property (MFont *font, enum MFontProperty key, extern int mfont__split_name (char *name, int *property_idx, unsigned short *point, unsigned short *resy); -extern void mfont__set_spec (MFont *font, - MSymbol attrs[MFONT_PROPERTY_MAX], - unsigned short size, unsigned short resy); - -extern int mfont__parse_name_into_font (char *name, MSymbol format, +extern int mfont__parse_name_into_font (const char *name, MSymbol format, MFont *font); extern MPlist *mfont__encoding_list (void); +extern MFontCapability *mfont__get_capability (MSymbol sym); + +extern int mfont__check_capability (MRealizedFont *rfont, MSymbol capability); + extern unsigned mfont__flt_encode_char (MSymbol layouter_name, int c); extern int mfont__flt_run (MGlyphString *gstring, int from, int to,