1 /* font.c -- 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., 59 Temple Place, Suite 330, Boston, MA
27 The m17n GUI API represents a font by an object of the type @c
28 MFont. A font can have @e font @e properties. Like other types
29 of properties, a font property consists of a key and a value. The
30 key of a font property must be one of the following symbols:
32 @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
33 @c Madstyle, @c Mregistry, @c Msize, @c Mresolution.
35 When the key of a font property is @c Msize or @c Mresolution, its
36 value is an integer. Otherwise the value is a symbol. "The font
37 property that belongs to font F and whose key is @c Mxxx" may be
38 shortened to "the xxx property of F".
40 The value of a foundry property is a symbol representing font
41 foundry information, e.g. adobe, misc, etc.
43 The value of a family property is a symbol representing font family
44 information, e.g. times, helvetica, etc.
46 The value of a weight property is a symbol representing weight
47 information, e.g. normal, bold, etc.
49 The value of a style property is a symbol representing slant
50 information, e.g. normal, italic, etc.
52 The value of a stretch property is a symbol representing width
53 information, e.g. normal, semicondensed, etc.
55 The value of an adstyle property is a symbol representing abstract
56 font family information, e.g. serif, sans-serif, etc.
58 The value of a registry property is a symbol representing registry
59 information, e.g. iso10646-1, iso8895-1, etc.
61 The value of a size property is an integer representing design
62 size in the unit of 1/10 point.
64 The value of a resolution property is an integer representing
65 assumed device resolution in the unit of dots per inch (dpi)
67 The m17n library uses font objects for two purposes: to receive
68 font specification from an application program, and to present
69 available fonts to an application program. When the m17n library
70 presents an available font to an application program, all font
71 properties have a concrete value.
73 The m17n library supports three kinds of fonts: Window system fonts,
74 FreeType fonts, and OpenType fonts.
78 <li> Window system fonts
80 The m17n-X library supports all fonts handled by an X server and
81 an X font server. The correspondence between XLFD fields and font
82 properties are shown below.
86 --------------- --------
92 ADD_STYLE_NAME adstyle
94 RESOLUTION_Y resolution
95 CHARSET_REGISTRY-CHARSET_ENCODING registry
98 XLFD fields not listed in the above table are ignored.
102 The m17n library, if configured to use the FreeType library,
103 supports all fonts that can be handled by the FreeType library.
104 The variable #mfont_freetype_path is initialized properly accoding
105 to the configuration of the m17n librayr and the environment
106 variable @c M17NDIR. See the documentation of the variable for
109 The family name of a FreeType font corresponds to the family
110 property. Style names of FreeType fonts correspond to the weight,
111 style, and stretch properties as below.
114 style name weight style stretch
115 ---------- ------ ----- -------
116 Regular medium r normal
117 Italic medium i normal
119 Bold Italic bold i normal
120 Narrow medium r condensed
121 Narrow Italic medium i condensed
122 Narrow Bold bold r condensed
123 Narrow Bold Italic bold i condensed
125 Black Italic black i normal
128 Style names not listed in the above table are treated as
131 Combination of a platform ID and an encoding ID corresponds to the
132 registry property. For example, if a font has the combination (1
133 1), the registry property is 1-1. Some frequent combinations have
134 a predefined registry property as below.
137 platform ID encoding ID registry property
138 ----------- ----------- -----------------
146 Thus, a font that has two combinations (1 0) and (3 1) corresponds
147 to four font objects whose registries are 1-0, apple-roman, 3-1,
152 The m17n library, if configured to use both the FreeType library
153 and the OTF library, supports any OpenType fonts. The list of
154 actually available fonts is created in the same way as in the case
155 of FreeType fonts. If a fontset instructs to use an OpenType font
156 via an FLT (Font Layout Table), and the FLT has an OTF-related
157 command (e.g. otf:deva), the OTF library converts a character
158 sequence to a glyph code sequence according to the OpenType layout
159 tables of the font, and the FreeType library gives a bitmap image
168 @brief ¥Õ¥©¥ó¥È¤È¤Ï¡¢¸Ä¡¹¤Î¥·¥¹¥Æ¥à¥Õ¥©¥ó¥È¤ËÂбþ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë
170 m17n-win API ¤Ë¤ª¤±¤ë @e ¥Õ¥©¥ó¥È ¤È¤Ï¡¢@c MFont ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È
171 ¤Ç¤¢¤ê¡¢¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à°Í¸¤Î @e ¥·¥¹¥Æ¥à¥Õ¥©¥ó¥È ¤È°ìÂаì¤ËÂÐ
172 ±þÉÕ¤±¤é¤ì¤ë¡£¥Õ¥©¥ó¥È¤Ï¸ÇÄê¸Ä¿ô¤Î @e ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£ ¤ò»ý¤Ä¡£
173 ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Ï¥¡¼¤ÈÃͤ«¤é¤Ê¤ë¡£¥¡¼¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢
175 @c Mfoundry, @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
176 @c Madstyle, @c Mregistry, @c Msize, @c Mresolution
178 ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£¥¡¼¤¬ @c Msize ¤¢¤ë¤¤¤Ï @c Mresolution ¤Î¾ì¹ç¡¢
179 ÃͤÏÀ°¿ô¤Ç¤¢¤ë¡£¥¡¼¤¬¤½¤ì°Ê³°¤Î¾ì¹ç¡¢Ãͤϥ·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£¡Ö¥Õ¥©¥ó
180 ¥È F ¤Î¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥¡¼¤¬ @c Mxxx ¤Ç¤¢¤ë¤â¤Î¡×¤Î¤³¤È¤ò
181 ´Êñ¤Ë¡ÖF ¤Î xxx ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£
183 Family ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢times, helvetica Åù¤Î¥Õ¥©¥ó¥È¥Õ¥¡¥ß¥ê¡¼¤ò
186 Weight ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢normal, bold Åù¤ÎÂÀ¤µ¤Ë´Ø¤¹¤ë¾ðÊó¤òɽ¤ï¤¹¡£
188 Style ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢normal, italic Åù¤Î·¹¤¤Ë´Ø¤¹¤ë¾ðÊó¤òɽ¤ï
191 Stretch ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢normal, semicondensed Åù¤Îʸ»úÉý¤Ë´Ø¤¹¤ë
194 Adstyle ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢serif, sans-serif Åù¤ÎÃê¾ÝŪ¤Ê¥Õ¥©¥ó¥È
197 Registry ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢iso10646, iso8895-1 ¤Î¥ì¥¸¥¹¥È¥ê¤òɽ¤ï
200 Size ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¥Õ¥©¥ó¥È¤Î¥Ç¥¶¥¤¥ó¥µ¥¤¥º¤òɽ¤ï¤¹¡£Ã±°Ì
201 ¤Ï 1/10 ¥Ý¥¤¥ó¥È¤Ç¤¢¤ë¡£
203 Resolution ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢ÁÛÄꤵ¤ì¤Æ¤¤¤ë¥Ç¥Ð¥¤¥¹¤Î²òÁüÅÙ¤ò ɽ¤ï
204 ¤¹¡£Ã±°Ì¤Ï dots per inch (dpi) ¤Ç¤¢¤ë¡£ */
208 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
209 /*** @addtogroup m17nInternal
218 #include "m17n-gui.h"
219 #include "m17n-misc.h"
220 #include "internal.h"
225 #include "internal-gui.h"
229 MFontDriver *mfont__driver_list[MFONT_TYPE_MAX];
231 /** Indices to font properties sorted by their priority. */
232 static int font_score_priority[] =
242 #define FONT_SCORE_PRIORITY_SIZE \
243 (sizeof font_score_priority / sizeof font_score_priority[0])
245 /* Indexed by a font property MFONT_XXX, and the value is how many
246 bits to shift the difference of property values. */
247 static int font_score_shift_bits[MFONT_PROPERTY_MAX];
249 /** Predefined symbols for each font property. The order is important
250 because the function score_font () decides how well a font matches
251 with a spec by checking how close the index is. */
253 static char *common_foundry[] =
256 static char *common_family[] =
261 static char *common_weight[] =
275 static char *common_style[] =
281 static char *common_stretch[] =
288 static char *common_adstyle[] =
292 static char *common_registry[] =
295 /* Table containing all the data above. */
297 struct MFontCommonNames
303 static struct MFontCommonNames font_common_names[] =
305 { sizeof (common_foundry) / sizeof (char *), common_foundry},
306 { sizeof (common_family) / sizeof (char *), common_family},
307 { sizeof (common_weight) / sizeof (char *), common_weight},
308 { sizeof (common_style) / sizeof (char *), common_style},
309 { sizeof (common_stretch) / sizeof (char *), common_stretch},
310 { sizeof (common_adstyle) / sizeof (char *), common_adstyle},
311 { sizeof (common_registry) / sizeof (char *), common_registry}
315 /** Table of available font property names. */
317 MFontPropertyTable mfont__property_table[MFONT_REGISTRY + 1];
320 /** Return the numeric value of SYMBOL as the Nth font property. */
322 #define FONT_PROPERTY_NUMERIC(symbol, n) \
325 : ((int) msymbol_get ((symbol), mfont__property_table[(n)].property)))
328 /** Set the numeric value of SYMBOL as the Nth font property to NUMERIC. */
330 #define SET_FONT_PROPERTY_NUMERIC(symbol, n, numeric) \
331 msymbol_put((symbol), mfont__property_table[(n)].property, \
335 gen_font_name (char *buf, MFont *font)
341 for (i = 0; i <= MFONT_REGISTRY; i++)
342 if (FONT_PROPERTY (font, i) != Mnil)
344 char *name = msymbol_name (FONT_PROPERTY (font, i));
353 sprintf (size, ",%d", font->property[MFONT_SIZE] / 10);
362 struct MFontEncoding {
364 MSymbol encoding_name;
365 MCharset *encoding_charset;
366 MSymbol repertory_name;
367 MCharset *repertory_charset;
370 static MPlist *font_encoding_list;
371 static MFontEncoding default_encoding;
373 /** Load font encoding table from the data <font encoding>.
374 The data has this form:
375 (FONT-SPEC ENCODING) ...
376 where FONT-SPEC has this form:
377 ([FOUNDRY FAMILY [WEIGHT [STYLE [STRETCH [ADSTYLE]]]]] REGISTRY)
378 All elements are symbols. */
381 load_font_encoding_table ()
384 MPlist *encoding_list, *plist, *pl, *elt;
386 font_encoding_list = pl = mplist ();
388 mdb = mdatabase_find (Mfont, msymbol ("encoding"), Mnil, Mnil);
390 || ! (encoding_list = (MPlist *) mdatabase_load (mdb)))
391 MERROR (MERROR_FONT, -1);
393 MPLIST_DO (plist, encoding_list)
395 MFontEncoding *encoding;
398 MSTRUCT_CALLOC (encoding, MERROR_FONT);
400 if (! MPLIST_PLIST_P (plist)
401 || (elt = MPLIST_PLIST (plist), mplist_length (elt) < 2)
402 || ! MPLIST_PLIST_P (elt))
403 MWARNING (MERROR_FONT);
404 registry = mfont__set_spec_from_plist (&encoding->spec,
406 elt = MPLIST_NEXT (elt);
407 if (! MPLIST_SYMBOL_P (elt))
408 MWARNING (MERROR_FONT);
409 encoding->encoding_name = MPLIST_SYMBOL (elt);
410 elt = MPLIST_NEXT (elt);
411 if (MPLIST_TAIL_P (elt))
412 encoding->repertory_name = encoding->encoding_name;
413 else if (! MPLIST_SYMBOL_P (elt))
414 MWARNING (MERROR_FONT);
416 encoding->repertory_name = MPLIST_SYMBOL (elt);
418 if (registry == Mnil)
420 pl = mplist_add (pl, registry, encoding);
427 M17N_OBJECT_UNREF (encoding_list);
436 static MPlist *font_resize_list;
438 /** Load font size table from the data <font size>.
439 The data has this form:
440 (FONT-SPEC RESIZE-FACTOR) ...
441 where FONT-SPEC has this form:
442 ([FOUNDRY FAMILY [WEIGHT [STYLE [STRETCH [ADSTYLE]]]]] REGISTRY)
443 All elements of FONT-SPEC are symbols. */
446 load_font_resize_table ()
449 MPlist *size_adjust_list, *plist, *pl, *elt;
451 font_resize_list = pl = mplist ();
453 mdb = mdatabase_find (Mfont, msymbol ("resize"), Mnil, Mnil);
456 if (! (size_adjust_list = (MPlist *) mdatabase_load (mdb)))
457 MERROR (MERROR_FONT, -1);
459 MPLIST_DO (plist, size_adjust_list)
464 MSTRUCT_CALLOC (resize, MERROR_FONT);
466 if (! MPLIST_PLIST_P (plist)
467 || (elt = MPLIST_PLIST (plist), mplist_length (elt) != 2)
468 || ! MPLIST_PLIST_P (elt))
469 MWARNING (MERROR_FONT);
470 registry = mfont__set_spec_from_plist (&resize->spec,
472 elt = MPLIST_NEXT (elt);
473 if (! MPLIST_INTEGER_P (elt))
474 MWARNING (MERROR_FONT);
475 resize->resize = MPLIST_INTEGER (elt);
477 if (registry == Mnil)
479 pl = mplist_add (pl, registry, resize);
486 M17N_OBJECT_UNREF (size_adjust_list);
490 /** Return a font encoding (and repertory) of FONT. */
492 static MFontEncoding *
493 find_encoding (MFont *font)
495 MSymbol registry = FONT_PROPERTY (font, MFONT_REGISTRY);
496 MFontEncoding *encoding = NULL;
499 if (! font_encoding_list)
500 load_font_encoding_table ();
501 if (! MPLIST_TAIL_P (font_encoding_list))
504 plist = font_encoding_list;
505 while (registry ? (plist = mplist_find_by_key (plist, registry))
508 encoding = (MFontEncoding *) MPLIST_VAL (plist);
509 if (mfont__match_p (font, &encoding->spec, MFONT_ADSTYLE))
511 if (! encoding->encoding_charset)
512 encoding->encoding_charset
513 = MCHARSET (encoding->encoding_name);
514 if (! encoding->encoding_charset)
519 if (encoding->repertory_name == encoding->encoding_name)
520 encoding->repertory_charset = encoding->encoding_charset;
521 else if (encoding->repertory_name != Mnil)
523 encoding->repertory_charset
524 = MCHARSET (encoding->repertory_name);
525 if (! encoding->repertory_charset)
534 plist = MPLIST_NEXT (plist);
536 if (registry == Mnil || registry == Mt)
540 return &default_encoding;
552 Mfoundry = msymbol ("foundry");
553 mfont__property_table[MFONT_FOUNDRY].property = Mfoundry;
554 Mfamily = msymbol ("family");
555 mfont__property_table[MFONT_FAMILY].property = Mfamily;
556 Mweight = msymbol ("weight");
557 mfont__property_table[MFONT_WEIGHT].property = Mweight;
558 Mstyle = msymbol ("style");
559 mfont__property_table[MFONT_STYLE].property = Mstyle;
560 Mstretch = msymbol ("stretch");
561 mfont__property_table[MFONT_STRETCH].property = Mstretch;
562 Madstyle = msymbol ("adstyle");
563 mfont__property_table[MFONT_ADSTYLE].property = Madstyle;
564 Mregistry = msymbol ("registry");
565 mfont__property_table[MFONT_REGISTRY].property = Mregistry;
567 Msize = msymbol ("size");
568 Mresolution = msymbol ("resolution");
570 /* The first entry of each mfont__property_table must be Mnil so
571 that actual properties get positive numeric numbers. */
572 for (i = 0; i <= MFONT_REGISTRY; i++)
574 MLIST_INIT1 (&mfont__property_table[i], names, 8);
575 MLIST_APPEND1 (&mfont__property_table[i], names, Mnil, MERROR_FONT);
578 /* Register predefined font property names. */
579 for (i = 0; i <= MFONT_REGISTRY; i++)
583 for (j = 0; j < font_common_names[i].num; j++)
585 MSymbol sym = msymbol (font_common_names[i].names[j]);
589 if (msymbol_put(sym, mfont__property_table[i].property,
590 (void *) (j + 1)) < 0)
592 MLIST_APPEND1 (&mfont__property_table[i], names, sym, MERROR_FONT);
596 memset (mfont__driver_list, 0, sizeof mfont__driver_list);
598 /* Here, SHIFT starts from 1, not 0. This is because the lowest bit
599 of a score is a flag for a scalable font (see the documentation
601 i = FONT_SCORE_PRIORITY_SIZE - 1;
602 for (shift = 1; i >= 0; i--)
604 font_score_shift_bits[font_score_priority[i]] = shift;
605 if (font_score_priority[i] == MFONT_SIZE)
611 MFONT_INIT (&default_encoding.spec);
612 default_encoding.encoding_name = Mnil;
613 default_encoding.encoding_charset = NULL;
614 default_encoding.repertory_name = Mnil;
615 default_encoding.repertory_charset = NULL;
620 mfont_freetype_path = mplist ();
621 bufsize = strlen (M17NDIR) + 7;
622 buf = alloca (bufsize);
623 sprintf (buf, "%s/fonts", M17NDIR);
624 mplist_add (mfont_freetype_path, Mstring, strdup (buf));
625 path = getenv ("M17NDIR");
628 i = strlen (path) + 7;
631 sprintf (buf, "%s/fonts", path);
632 mplist_push (mfont_freetype_path, Mstring, strdup (buf));
637 if (mfont__ft_init () < 0)
639 #endif /* HAVE_FREETYPE */
640 if (mfont__flt_init () < 0)
655 #endif /* HAVE_FREETYPE */
657 MPLIST_DO (plist, mfont_freetype_path)
658 free (MPLIST_VAL (plist));
659 M17N_OBJECT_UNREF (mfont_freetype_path);
661 if (font_resize_list)
663 MPLIST_DO (plist, font_resize_list)
664 free (MPLIST_VAL (plist));
665 M17N_OBJECT_UNREF (font_resize_list);
666 font_resize_list = NULL;
668 if (font_encoding_list)
670 MPLIST_DO (plist, font_encoding_list)
671 free (MPLIST_VAL (plist));
672 M17N_OBJECT_UNREF (font_encoding_list);
673 font_encoding_list = NULL;
675 for (i = 0; i <= MFONT_REGISTRY; i++)
676 MLIST_FREE1 (&mfont__property_table[i], names);
680 mfont__free_realized (MRealizedFont *rfont)
683 M17N_OBJECT_UNREF (rfont->info);
688 /* Compare FONT with REQUEST and return how much they differs. If
689 FONT does not match with SPEC, return -1. */
692 mfont__score (MFont *font, MFont *spec, MFont *request, int limited_size)
695 int i = FONT_SCORE_PRIORITY_SIZE;
699 enum MFontProperty prop = font_score_priority[i];
701 if (request->property[prop] != 0)
705 if (spec->property[prop] && font->property[prop]
706 && font->property[prop] != spec->property[prop])
708 if (font->property[prop])
709 val = abs (font->property[prop] - request->property[prop]);
710 if (prop == MFONT_SIZE)
712 if (font->property[MFONT_RESY] == 0)
713 /* This is a scalable font. We prefer a bitmap font
714 if the size matches exactly. */
717 score |= (val << font_score_shift_bits[MFONT_SIZE]
718 | ((limited_size && val > 0) ? 0x400000 : 0));
721 score |= (val > 3 ? 3 : val) << font_score_shift_bits[prop];
728 /** Return 1 iff FONT matches SPEC. */
731 mfont__match_p (MFont *font, MFont *spec, int prop)
733 for (; prop >= 0; prop--)
734 if (spec->property[prop] && font->property[prop]
735 && font->property[prop] != spec->property[prop])
742 mfont__set_spec_from_face (MFont *spec, MFace *face)
746 for (i = 0; i <= MFONT_ADSTYLE; i++)
747 mfont__set_property (spec, i, face->property[i]);
748 /* The value 1 is "iso8859-1". */
749 spec->property[MFONT_REGISTRY] = 1;
750 spec->property[MFONT_SIZE] = (int) (face->property[MFACE_SIZE]);
751 spec->property[MFONT_RESY] = 0;
752 spec->property[MFONT_TYPE] = 0;
757 mfont__set_spec_from_plist (MFont *spec, MPlist *plist)
760 MSymbol spec_list[MFONT_REGISTRY + 1];
764 memset (spec_list, 0, sizeof spec_list);
765 for (i = 0; ! MPLIST_TAIL_P (plist); i++, plist = MPLIST_NEXT (plist))
767 if (! MPLIST_SYMBOL_P (plist))
768 MERROR (MERROR_FONT, Mnil);
769 spec_list[i] = MPLIST_SYMBOL (plist);
771 registry = spec_list[i - 1];
772 mfont__set_property (spec, MFONT_REGISTRY, registry);
773 for (i -= 2; i >= 0; i--)
774 mfont__set_property (spec, i, spec_list[i]);
779 mfont__select (MFrame *frame, MFont *spec, MFont *request, int limited_size)
781 MSymbol registry = FONT_PROPERTY (spec, MFONT_REGISTRY);
782 MPlist *realized_font_list;
783 MRealizedFont *best_font[MFONT_TYPE_MAX];
786 int mdebug_mask = MDEBUG_FONT;
788 if (registry == Mnil)
791 MPLIST_DO (realized_font_list, frame->realized_font_list)
793 MRealizedFont *best = MPLIST_VAL (realized_font_list);
795 if (MPLIST_KEY (realized_font_list) == registry
796 && ! memcmp (&best->spec, spec, sizeof (MFont))
797 && ! memcmp (&best->request, request, sizeof (MFont)))
803 for (i = 0; i < MFONT_TYPE_MAX; i++)
805 MFontDriver *driver = mfont__driver_list[i];
807 best_font[i] = (driver
808 ? (driver->select) (frame, spec, request, limited_size)
812 || best_font[best_index]->score > best_font[i]->score))
815 for (i = 0; i < MFONT_TYPE_MAX; i++)
818 mplist_add (frame->realized_font_list, registry, best_font[i]);
819 else if (best_font[i])
823 if (mdebug__flag & mdebug_mask)
825 char buf1[256], buf2[256];
828 for (i = 0; i < MFONT_PROPERTY_MAX; i++)
829 if (! font.property[i])
830 font.property[i] = request->property[i];
831 gen_font_name (buf2, &font);
834 MDEBUG_PRINT_TIME ("FONT",
835 (stderr, " to select <%s> from <%s>.",
837 &best_font[best_index]->font),
840 MDEBUG_PRINT_TIME ("FONT", (stderr, " to fail to find <%s>.", buf2));
844 return (best_index >= 0 ? best_font[best_index] : NULL);
848 /** Open a font specified in RFONT. Return 0 if successfully
849 opened, otherwise return -1. */
852 mfont__open (MRealizedFont *rfont)
854 MPlist *realized_font_list;
855 MSymbol registry = FONT_PROPERTY (&rfont->font, MFONT_REGISTRY);
860 MPLIST_DO (realized_font_list, rfont->frame->realized_font_list)
862 MRealizedFont *this_rfont = MPLIST_VAL (realized_font_list);
864 if (this_rfont->status != 0
865 && MPLIST_KEY (realized_font_list) == registry
866 && ! memcmp (&this_rfont->font, &rfont->font, sizeof (MFont)))
869 M17N_OBJECT_UNREF (rfont->info);
870 rfont->info = this_rfont->info;
871 M17N_OBJECT_REF (this_rfont->info);
872 rfont->status = this_rfont->status;
873 return (this_rfont->status > 0 ? 0 : -1);
877 return (rfont->driver->open) (rfont);
881 mfont__close (MRealizedFont *rfont)
883 (rfont->driver->close) (rfont);
887 mfont__resize (MFont *spec, MFont *request)
889 MSymbol registry = FONT_PROPERTY (spec, MFONT_REGISTRY);
893 if (! font_resize_list)
894 load_font_resize_table ();
895 if (! MPLIST_TAIL_P (font_resize_list))
898 plist = font_resize_list;
899 while (registry ? (plist = mplist_find_by_key (plist, registry))
902 resize = (MFontResize *) MPLIST_VAL (plist);
903 if (mfont__match_p (spec, &resize->spec, MFONT_ADSTYLE))
905 request->property[MFONT_SIZE]
906 = request->property[MFONT_SIZE] * resize->resize / 100;
909 plist = MPLIST_NEXT (plist);
917 /* Return 1 if C is encodable, 0, if C is not encodable, -1 if it
918 can't be decided now. */
921 mfont__encodable_p (MRealizedFont *rfont, MSymbol layouter_name, int c)
923 MFontEncoding *encoding;
925 if (layouter_name != Mnil)
926 return (mfont__flt_encode_char (layouter_name, c)
927 != MCHAR_INVALID_CODE);
928 if (! rfont->encoding)
929 rfont->encoding = find_encoding (&rfont->spec);
930 encoding = rfont->encoding;
931 if (! encoding->repertory_charset)
933 return (ENCODE_CHAR (encoding->repertory_charset, c) != MCHAR_INVALID_CODE);
937 mfont__encode_char (MRealizedFont *rfont, int c)
939 MFontEncoding *encoding;
942 if (rfont->layouter != Mnil)
943 return mfont__flt_encode_char (rfont->layouter, c);
944 if (! rfont->encoding)
945 rfont->encoding = find_encoding (&rfont->font);
946 encoding = rfont->encoding;
947 if (! encoding->encoding_charset)
948 return MCHAR_INVALID_CODE;
949 code = ENCODE_CHAR (encoding->encoding_charset, c);
950 if (code == MCHAR_INVALID_CODE)
951 return MCHAR_INVALID_CODE;
952 if (! encoding->repertory_charset)
953 return (rfont->driver->encode_char) (rfont, c, code);
954 if (ENCODE_CHAR (encoding->repertory_charset, c) == MCHAR_INVALID_CODE)
955 return MCHAR_INVALID_CODE;
960 mfont__get_metric (MRealizedFont *rfont, MGlyph *g)
962 (rfont->driver->find_metric) (rfont, g);
967 mfont__set_property (MFont *font, enum MFontProperty key, MSymbol val)
975 numeric = FONT_PROPERTY_NUMERIC (val, key);
978 numeric = mfont__property_table[key].used;
979 MLIST_APPEND1 (mfont__property_table + key, names, val, MERROR_FONT);
980 SET_FONT_PROPERTY_NUMERIC (val, key, numeric);
983 font->property[key] = numeric;
987 mfont__set_spec (MFont *font, MSymbol *attrs,
988 unsigned short size, unsigned short resy)
992 for (i = 0; i <= MFONT_REGISTRY; i++)
993 mfont__set_property (font, i, attrs[i]);
994 font->property[MFONT_SIZE] = size;
995 font->property[MFONT_RESY] = resy;
999 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
1005 /*** @addtogroup m17nFont */
1009 /***en @name Variables: Keys of font property. */
1010 /***ja @name ÊÑ¿ô: ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ëÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë */
1015 @brief Key of font property specifying foundry.
1017 The variable #Mfoundry is a symbol of name <tt>"foundry"</tt> and
1018 is used as a key of font property and face property. The property
1019 value must be a symbol whose name is a foundry name of a font. */
1024 @brief Key of font property specifying foundry.
1026 The variable #Mfamily is a symbol of name <tt>"family"</tt> and is
1027 used as a key of font property and face property. The property
1028 value must be a symbol whose name is a family name of a font. */
1031 @brief ¥Õ¥©¥ó¥È¤Î family ¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥·¥ó¥Ü¥ë
1033 ¥·¥ó¥Ü¥ë @c Mfamily ¤Ï <tt>"family"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢¥Õ¥©¥ó
1034 ¥È¤Î family ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë¤È¤¤Ë´Ø¿ô mfont_get_prop () ¤Î°ú
1037 ¤Þ¤¿¤³¤Î¥·¥ó¥Ü¥ë¤Ï¡¢¥Õ¥§¡¼¥¹Á´ÂΤˤª¤±¤ë¥Ç¥Õ¥©¥ë¥È¤Î family ¤ò»ØÄê
1038 ¤¹¤ëºÝ¤Ë¡¢¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤È¤·¤Æ¤â»È¤ï¤ì¤ë¡£ */
1043 @brief Key of font property specifying weight.
1045 The variable #Mweight is a symbol of name <tt>"weight"</tt> and is
1046 used as a key of font property and face property. The property
1047 value must be a symbol whose name is a weight name of a font (e.g
1048 "medium", "bold"). */
1051 @brief ¥Õ¥©¥ó¥È¤Î weight ¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥·¥ó¥Ü¥ë
1053 ¥·¥ó¥Ü¥ë @c Mweight ¤Ï <tt>"weight"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢¥Õ¥©¥ó
1054 ¥È¤Î weight ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë¤È¤¤Ë´Ø¿ô mfont_get_prop () ¤Î°ú
1057 ¤Þ¤¿¤³¤Î¥·¥ó¥Ü¥ë¤Ï¡¢¥Õ¥§¡¼¥¹Á´ÂΤˤª¤±¤ë¥Ç¥Õ¥©¥ë¥È¤Î weight ¤ò»ØÄê
1058 ¤¹¤ëºÝ¤Ë¡¢¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤È¤·¤Æ¤â»È¤ï¤ì¤ë¡£ */
1063 @brief Key of font property specifying style.
1065 The variable #Mstyle is a symbol of name <tt>"style"</tt> and is
1066 used as a key of font property and face property. The property
1067 value must be a symbol whose name is a style name of a font (e.g
1071 @brief ¥Õ¥©¥ó¥È¤Î style ¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥·¥ó¥Ü¥ë
1073 ¥·¥ó¥Ü¥ë @c Mstyle ¤Ï <tt>"style"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢¥Õ¥©¥ó¥È
1074 ¤Î style ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë¤È¤¤Ë´Ø¿ô mfont_get_prop () ¤Î°ú¿ô¤È
1077 ¤Þ¤¿¤³¤Î¥·¥ó¥Ü¥ë¤Ï¡¢¥Õ¥§¡¼¥¹Á´ÂΤˤª¤±¤ë¥Ç¥Õ¥©¥ë¥È¤Î style ¤ò»ØÄê
1078 ¤¹¤ëºÝ¤Ë¡¢¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤È¤·¤Æ¤â»È¤ï¤ì¤ë¡£ */
1083 @brief Key of font property specifying stretch.
1085 The variable #Mstretch is a symbol of name <tt>"stretch"</tt> and
1086 is used as a key of font property and face property. The property
1087 value must be a symbol whose name is a stretch name of a font (e.g
1088 "normal", "condensed"). */
1091 @brief ¥Õ¥©¥ó¥È¤Î stretch ¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥·¥ó¥Ü¥ë
1093 ¥·¥ó¥Ü¥ë @c Mstretch ¤Ï <tt>"stretch"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢¥Õ¥©
1094 ¥ó¥È¤Î stretch ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë¤È¤¤Ë´Ø¿ô mfont_get_prop () ¤Î
1095 °ú¿ô¤È¤·¤Æ»È¤ï¤ì¤ë¡£
1097 ¤Þ¤¿¤³¤Î¥·¥ó¥Ü¥ë¤Ï¡¢¥Õ¥§¡¼¥¹Á´ÂΤˤª¤±¤ë¥Ç¥Õ¥©¥ë¥È¤Î stretch ¤ò»Ø
1098 Äꤹ¤ëºÝ¤Ë¡¢¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤È¤·¤Æ¤â»È¤ï¤ì¤ë¡£ */
1103 @brief Key of font property specifying additional style.
1105 The variable #Madstyle is a symbol of name <tt>"adstyle"</tt> and
1106 is used as a key of font property and face property. The property
1107 value must be a symbol whose name is an additional style name of a
1108 font (e.g "serif", "", "sans"). */
1111 @brief ¥Õ¥©¥ó¥È¤Î adstyle ¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥·¥ó¥Ü¥ë
1113 ¥·¥ó¥Ü¥ë @c Madstyle ¤Ï <tt>"adstyle"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢¥Õ¥©
1114 ¥ó¥È¤Î adstyle ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë¤È¤¤Ë´Ø¿ô mfont_get_prop () ¤Î
1115 °ú¿ô¤È¤·¤Æ»È¤ï¤ì¤ë¡£
1117 ¤Þ¤¿¤³¤Î¥·¥ó¥Ü¥ë¤Ï¡¢¥Õ¥§¡¼¥¹Á´ÂΤˤª¤±¤ë¥Ç¥Õ¥©¥ë¥È¤Î adstyle ¤ò»Ø
1118 Äꤹ¤ëºÝ¤Ë¡¢¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£ */
1123 @brief Key of font property specifying registry.
1125 The variable #Mregistry is a symbol of name <tt>"registry"</tt>
1126 and is used as a key of font property. The property value must be
1127 a symbol whose name is a registry name a font registry
1128 (e.g. "iso8859-1", "jisx0208.1983-0"). */
1131 @brief ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£ registry ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë
1133 ¥·¥ó¥Ü¥ë @c Mregistry ¤Ï <tt>"registry"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢¥Õ¥©
1134 ¥ó¥È¤Î registry ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë¤È¤¤Ë¡¢´Ø¿ô mfont_get_prop ()
1135 ¤Î°ú¿ô¤È¤·¤Æ»È¤ï¤ì¤ë¡£ */
1140 @brief Key of font property specifying size.
1142 The variable #Msize is a symbol of name <tt>"size"</tt> and is
1143 used as a key of font property and face property. The property
1144 value must be an integer specifying a font design size in the unit
1145 of 1/10 point (on 100 dpi display). */
1148 @brief ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£ size ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë
1150 ¥·¥ó¥Ü¥ë @c Msize ¤Ï <tt>"size"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢¥Õ¥©¥ó¥È¤Î size ¥×¥í
1151 ¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë¤È¤¤Ë´Ø¿ô mfont_get_prop () ¤Î°ú¿ô¤È¤·¤Æ»È¤ï¤ì¤ë¡£
1153 ¤Þ¤¿¤³¤Î¥·¥ó¥Ü¥ë¤Ï¡¢¥Õ¥§¡¼¥¹Á´ÂΤˤª¤±¤ë¥Ç¥Õ¥©¥ë¥È¤Î size ¤ò»ØÄꤹ
1154 ¤ëºÝ¤Ë¡¢¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£ */
1159 @brief Key of font property specifying resolution.
1161 The variable #Mresolution is a symbol of name <tt>"size"</tt> and
1162 is used as a key of font property and face property. The property
1163 value must be an integer to specifying a font resolution in the
1164 unit of dots per inch (dpi). */
1167 @brief ¥Õ¥©¥ó¥È¥×¥í¥Ñ¥Æ¥£ resolution ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë
1169 ¥·¥ó¥Ü¥ë @c Mresolution ¤Ï <tt>"resolution"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
1170 ¥Õ¥©¥ó¥È¤Î resolution ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë¤È¤¤Ë¡¢´Ø¿ô
1171 mfont_get_prop () ¤Î°ú¿ô¤È¤·¤Æ»È¤ï¤ì¤ë¡£ */
1173 MSymbol Mresolution;
1180 @brief List of font files and directories that contain font files.
1182 The variable @c mfont_freetype_path is a plist of FreeType font
1183 files and directories that contain FreeType font files. Key of
1184 the element is @c Mstring, and the value is a string that
1185 represents a font file or a directory.
1187 The macro M17N_INIT () sets up this variable to contain the
1188 sub-directory "fonts" of the m17n database and the environment
1189 variable "M17NDIR". The first call of mframe () creates the
1190 internal list of the actually available fonts from this variable.
1191 Thus, an application program, if necessary, must modify the
1192 variable before calling mframe (). If it is going to add a new
1193 element, value must be a string that can be safely freed.
1195 If the m17n library is not configured to use the FreeType library,
1196 this variable is not used. */
1198 MPlist *mfont_freetype_path;
1203 @brief Create a new font.
1205 The mfont () function creates a new font object that has no
1209 This function returns a pointer to the created font object. */
1217 MSTRUCT_CALLOC (font, MERROR_FONT);
1224 @brief Create a new font from fontname.
1226 The mfont_from_name () function creates a new font object. The
1227 properties are extracted fontname $NAME.
1229 How to extract properties is window system dependent. The m17n-X
1230 library parses $NAME as XLFD (X Logical Font Description).
1233 If the operation was successful, this function returns a pointer
1234 to the created font. Otherwise it returns @c NULL. */
1237 @brief ¥Õ¥©¥ó¥È̾¤«¤é¥Õ¥©¥ó¥È¤òºî¤ë
1239 ´Ø¿ô mfont_from_name () ¤Ï¥Õ¥©¥ó¥È̾ $NAME ¤ò²òÀϤ·¡¢¿·¤·¤¤¥Õ¥©¥ó
1242 ¥Õ¥©¥ó¥È̾¤Îʸˡ¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£m17n-X ¥é¥¤¥Ö¥é¥ê
1243 ¤Î¾ì¹ç¤Ï XLFD (X Logical Font Description) ¤Ë½¾¤¦¡£
1246 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mfont_from_name () ¤Ï¿·¤·¤¯ºî¤é¤ì¤¿¥Õ¥©¥ó¥È¤Ø¤Î
1247 ¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£$NAME ¤Î²òÀϤ˼ºÇÔ¤·¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤¹¡£ */
1250 mfont_from_name (char *name)
1252 MFont template, *font;
1254 if (mwin__parse_font_name (name, &template) < 0)
1256 MSTRUCT_CALLOC (font, MERROR_FONT);
1264 @brief Return a copy of a font.
1266 The mfont_copy () function returns a new copy of $FONT. */
1269 mfont_copy (MFont *font)
1273 MSTRUCT_MALLOC (copy, MERROR_FONT);
1281 @brief Create a fontname from a font.
1283 The mfont_name () function creates a fontname string created from
1286 The syntax of fontname is window system dependent. The m17n-X
1287 library returns a fontname conforming to XLFD (X Logical Font
1291 This function returns the created fontname string, which is not freed
1292 unless the user explicitly does so by free (). */
1295 mfont_name (MFont *font)
1297 return mwin__build_font_name (font);
1303 @brief Get a property value of a font.
1305 The mfont_get_prop () function gets the value of $KEY property of
1306 $FONT. $KEY must be one of the following symbols:
1308 @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
1309 @c Madstyle, @c Mregistry, @c Msize, @c Mresolution.
1312 If $KEY is @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch, @c
1313 Madstyle, or @c Mregistry, this function returns the
1314 corresponding value as a symbol. If the font does not have $KEY
1315 property, it returns @c Mnil.
1317 If $KEY is @c Msize or @c Mresolution, this function returns the
1318 corresponding value as an integer. If the font does not have $KEY
1319 property, it returns 0.
1321 If $KEY is something else, it returns @c NULL and assigns an error
1322 code to the external variable @c merror_code. */
1325 @brief ¥Õ¥©¥ó¥È¤Î¥×¥í¥Ñ¥Æ¥£ÃͤòÆÀ¤ë
1327 ´Ø¿ô mfont_get_prop () ¤Ï¥Õ¥©¥ó¥È $FONT ¤Î¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥¡¼¤¬
1328 $KEY ¤Ç¤¢¤ë¤â¤Î¤ÎÃͤòÊÖ¤¹¡£$KEY ¤Ï°Ê²¼¤Î¥·¥ó¥Ü¥ë¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤±¤ì
1331 @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
1332 @c Madstyle, @c Mregistry, @c Msize, @c Mresolution.
1335 ¤â¤· $KEY ¤¬ @c Msize ¤¢¤ë¤¤¤Ï @c Mresolution ¤Î¾ì¹ç¡¢
1336 mfont_get_prop () ¤ÏÀ°¿ô¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¥¨¥é¡¼
1337 ¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô @c merror_code ¤Ë¥¨¥é¡¼
1338 ¥³¡¼¥É¤òÀßÄꤹ¤ë¡£ */
1341 mfont_get_prop (MFont *font, MSymbol key)
1343 if (key == Mfoundry)
1344 return (void *) FONT_PROPERTY (font, MFONT_FOUNDRY);
1346 return (void *) FONT_PROPERTY (font, MFONT_FAMILY);
1348 return (void *) FONT_PROPERTY (font, MFONT_WEIGHT);
1350 return (void *) FONT_PROPERTY (font, MFONT_STYLE);
1351 if (key == Mstretch)
1352 return (void *) FONT_PROPERTY (font, MFONT_STRETCH);
1353 if (key == Madstyle)
1354 return (void *) FONT_PROPERTY (font, MFONT_ADSTYLE);
1355 if (key == Mregistry)
1356 return (void *) FONT_PROPERTY (font, MFONT_REGISTRY);
1359 int size = font->property[MFONT_SIZE];
1360 return (void *) size;
1362 if (key == Mresolution)
1364 int resy = font->property[MFONT_RESY];
1365 return (void *) resy;
1368 MERROR (MERROR_FONT, NULL);
1374 @brief Put a property value to a font.
1376 The mfont_put_prop () function puts a font property whose key is
1377 $KEY and value is $VAL to $FONT. $KEY must be one of the following
1380 @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
1381 @c Madstyle, @c Mregistry, @c Msize, @c Mresolution.
1383 If $KEY is @c Msize of @c Mresolution, $VAL must be an integer.
1384 Otherwise, $VAL must be a symbol. */
1387 mfont_put_prop (MFont *font, MSymbol key, void *val)
1389 if (key == Mfoundry)
1390 mfont__set_property (font, MFONT_FOUNDRY, (MSymbol) val);
1391 else if (key == Mfamily)
1392 mfont__set_property (font, MFONT_FAMILY, (MSymbol) val);
1393 else if (key == Mweight)
1394 mfont__set_property (font, MFONT_WEIGHT, (MSymbol) val);
1395 else if (key == Mstyle)
1396 mfont__set_property (font, MFONT_STYLE, (MSymbol) val);
1397 else if (key == Mstretch)
1398 mfont__set_property (font, MFONT_STRETCH, (MSymbol) val);
1399 else if (key == Madstyle)
1400 mfont__set_property (font, MFONT_ADSTYLE, (MSymbol) val);
1401 else if (key == Mregistry)
1402 mfont__set_property (font, MFONT_REGISTRY, (MSymbol) val);
1403 else if (key == Msize)
1405 unsigned size = (unsigned) val;
1406 font->property[MFONT_SIZE] = size;
1408 else if (key == Mresolution)
1410 unsigned resy = (unsigned) val;
1411 font->property[MFONT_RESY] = resy;
1414 MERROR (MERROR_FONT, -1);
1421 @brief Return the font selection priority.
1423 The mfont_selection_priority () function returns a newly created
1424 array of six symbols. The elements are the following
1425 keys of font properties ordered by priority.
1427 @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
1428 @c Madstyle, @c Msize.
1430 The m17n library selects the best matching font according to the
1431 order of this array. A font that has a different value for a
1432 property of lower priority is preferred to a font that has a
1433 different value for a property of higher priority. */
1436 mfont_selection_priority ()
1441 MTABLE_MALLOC (keys, FONT_SCORE_PRIORITY_SIZE, MERROR_FONT);
1442 for (i = 0; i < FONT_SCORE_PRIORITY_SIZE; i++)
1444 enum MFontProperty prop = font_score_priority[i];
1446 if (prop == MFONT_SIZE)
1448 else if (prop == MFONT_ADSTYLE)
1450 else if (prop == MFONT_FAMILY)
1452 else if (prop == MFONT_WEIGHT)
1454 else if (prop == MFONT_STYLE)
1456 else if (prop == MFONT_STRETCH)
1467 @brief Set the font selection priority.
1469 The mfont_set_selection_priority () function sets font selection
1470 priority according to $KEYS, which is an array of six symbols.
1471 Each element must be one of the below. No two elements must be
1474 @c Mfamily, @c Mweight, @c Mstyle, @c Mstretch,
1475 @c Madstyle, @c Msize.
1477 See the documentation of the function mfont_selection_priority ()
1481 mfont_set_selection_priority (MSymbol *keys)
1483 int priority[FONT_SCORE_PRIORITY_SIZE];
1486 for (i = 0; i < FONT_SCORE_PRIORITY_SIZE; i++, keys++)
1488 enum MFontProperty prop;
1492 else if (*keys == Madstyle)
1493 prop = MFONT_ADSTYLE;
1494 else if (*keys == Mfamily)
1495 prop = MFONT_FAMILY;
1496 else if (*keys == Mweight)
1497 prop = MFONT_WEIGHT;
1498 else if (*keys == Mstyle)
1500 else if (*keys == Mstretch)
1501 prop = MFONT_STRETCH;
1502 else if (*keys == Mfoundry)
1503 prop = MFONT_FOUNDRY;
1505 /* Invalid element. */
1507 for (j = 0; j < i; j++)
1508 if (priority[j] == prop)
1509 /* Duplicated element. */
1513 for (i = 0; i < FONT_SCORE_PRIORITY_SIZE; i++)
1514 font_score_priority[i] = priority[i];
1523 The mfont_find () function returns a pointer to the available font
1524 that matches best the specification $SPEC on frame $FRAME.
1526 $SCORE, if not NULL, must point to a place to store the score
1527 value that indicates how well the found font matches to $SPEC. A
1528 smaller score means a better match. */
1531 @brief ¥Õ¥©¥ó¥È¤òõ¤¹
1533 ´Ø¿ô mfont_find () ¤Ï¡¢¥Õ¥ì¡¼¥à $FRAME ¾å¤Ç¥Õ¥©¥ó¥ÈÄêµÁ $SPEC ¤Ë¤â¤Ã
1534 ¤È¤â¶á¤¤¥Õ¥©¥ó¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£ */
1537 mfont_find (MFrame *frame, MFont *spec, int *score, int limited_size)
1540 MRealizedFont *rfont;
1542 MFONT_INIT (&spec_copy);
1543 spec_copy.property[MFONT_REGISTRY] = spec->property[MFONT_REGISTRY];
1545 rfont = mfont__select (frame, &spec_copy, spec, limited_size);
1549 *score = rfont->score;
1550 return &rfont->font;
1555 @brief Set encoding of a font.
1557 The mfont_set_encoding () function sets the encoding information
1560 If $ENCODING_NAME is be a symbol representing a charset that has
1561 the same encoding as the font.
1563 If $REPERTORY_NAME @c Mnil or a symbol representing a charset that
1564 has the same repertory as the font. If it is @c Mnil, whether a
1565 specific character is supported by the font is asked to each font
1569 If the operation was successful, this function returns 0.
1570 Otherwise it returns -1 and assigns an error code to the external
1571 variable @c merror_code. */
1574 mfont_set_encoding (MFont *font, MSymbol encoding_name, MSymbol repertory_name)
1576 MCharset *encoding_charset = MCHARSET (encoding_name);
1577 MCharset *repertory_charset;
1579 MFontEncoding *encoding;
1582 if (! encoding_charset)
1583 MERROR (MERROR_FONT, -1);
1584 if (repertory_name != Mnil)
1586 repertory_charset = MCHARSET (repertory_name);
1587 if (! repertory_charset)
1588 MERROR (MERROR_FONT, -1);
1591 repertory_charset = NULL;
1593 MSTRUCT_CALLOC (encoding, MERROR_FONT);
1594 encoding->spec = *font;
1595 encoding->encoding_name = encoding_name;
1596 encoding->encoding_charset = encoding_charset;
1597 encoding->repertory_name = repertory_name;
1598 encoding->repertory_charset = repertory_charset;
1599 registry = FONT_PROPERTY (font, MFONT_REGISTRY);
1600 if (registry == Mnil)
1602 if (! font_encoding_list)
1603 load_font_encoding_table ();
1604 mplist_push (font_encoding_list, registry, encoding);
1605 MPLIST_DO (plist, MPLIST_NEXT (font_encoding_list))
1606 if (! memcmp (font, &((MFontEncoding *) MPLIST_VAL (plist))->spec,
1617 /*** @addtogroup m17nDebug */
1624 The mdebug_dump_font () function prints $FONT in a human readable
1628 This function returns $FONT. */
1631 mdebug_dump_font (MFont *font)
1633 char *name = mwin__build_font_name (font);
1635 fprintf (stderr, "%s", name);