+/*=*/
+
+/***en
+ @brief Get resize information of a font.
+
+ The mfont_resize_ratio () function lookups the m17n database
+ \<font, reisize\> and returns a resizing ratio (in percentage) of
+ FONT. For instance, if the return value is 150, that means that
+ the m17n library uses an 1.5 time bigger font than a specified
+ size. */
+
+/***ja
+ @brief ¥Õ¥©¥ó¥È¤Î¥ê¥µ¥¤¥º¾ðÊó¤òÆÀ¤ë
+
+ ´Ø¿ô mfont_resize_ratio ¤Ï m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹ \<font, reisize\>
+ ¤ò¸¡º÷¤·¡¢¥Õ¥©¥ó¥È FONT ¤Î¥ê¥µ¥¤¥º¤ÎÈæΨ¡Ê¥Ñ¡¼¥»¥ó¥Æ¡¼¥¸¡Ë
+ ¤òÊÖ¤¹¡£¤¿¤È¤¨¤ÐÊÖ¤¹Ãͤ¬ 150 ¤Ç¤¢¤ì¤Ð¡¢m17n ¥é¥¤¥Ö¥é¥ê¤Ï»ØÄꤵ¤ì¤¿¥µ¥¤¥º¤Î 1.5
+ ÇܤΥե©¥ó¥È¤ò»ÈÍѤ¹¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£ */
+
+int
+mfont_resize_ratio (MFont *font)
+{
+ MSymbol registry = FONT_PROPERTY (font, MFONT_REGISTRY);
+ MFontResize *resize;
+ MPlist *plist;
+
+ if (! font_resize_list)
+ load_font_resize_table ();
+ if (! MPLIST_TAIL_P (font_resize_list))
+ while (1)
+ {
+ plist = font_resize_list;
+ while (registry ? (plist = mplist_find_by_key (plist, registry))
+ : plist)
+ {
+ resize = (MFontResize *) MPLIST_VAL (plist);
+ if (mfont__match_p (font, &resize->spec, MFONT_ADSTYLE))
+ return resize->resize;
+ plist = MPLIST_NEXT (plist);
+ }
+ if (registry == Mt)
+ break;
+ registry = Mt;
+ }
+ return 100;
+}
+
+/*=*/
+
+/***en
+ @brief Get a list of fonts.
+
+ The mfont_list () functions returns a list of fonts available on
+ frame $FRAME. $FONT, if not NULL, limits fonts to ones
+ that match with $FONT. $LANGUAGE, if not @c Mnil, limits fonts to
+ ones that support $LANGUAGE. $MAXNUM, if greater than 0, limits
+ the number of fonts.
+
+ $LANGUAGE argument exists just for backward compatibility, and the
+ use is deprecated. Use #Mlanguage font property instead. If
+ $FONT already has #Mlanguage property, $LANGUAGE is ignored.
+
+ @return
+ This function returns a plist whose keys are family names and
+ values are pointers to the object MFont. The plist must be freed
+ by m17n_object_unref (). If no font is found, it returns
+ NULL. */
+
+/***ja
+ @brief ¥Õ¥©¥ó¥È¤Î¥ê¥¹¥È¤òÆÀ¤ë
+
+ ´Ø¿ô mfont_list () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤ÇÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤Î¥ê¥¹¥È¤ò
+ ÊÖ¤¹¡£$FONT ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢$FONT ¤È¹çÃפ¹¤ëÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È
+ ¤Î¥ê¥¹¥È¤òÊÖ¤¹¡£$LANGUAGE ¤¬ @c Mnil ¤Ç¤Ê¤±¤ì¤Ð¡¢$LANGUAGE ¤ò¥µ¥Ý¡¼
+ ¥È¤¹¤ëÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤Î¥ê¥¹¥È¤òÊÖ¤¹¡£$MAXNUM ¤Ï¡¢0 ¤è¤êÂ礤¤¾ì
+ ¹ç¤Ë¤Ï¡¢ÊÖ¤¹¥Õ¥©¥ó¥È¤Î¿ô¤Î¾å¸Â¤Ç¤¢¤ë¡£
+
+ ¤¿¤À¤·¡¢°ú¿ô $LANGUAGE ¤ÏµìÈǤȤÎÀ°¹çÀ¤Î¤¿¤á¤À¤±¤Ë¤¢¤ê¡¢¤½¤Î»ÈÍѤÏ
+ ´«¤á¤é¤ì¤Ê¤¤¡£¥Õ¥©¥ó¥È¤Î #Mlanguage ¥×¥í¥Ñ¥Æ¥£¤ò»È¤¦¤Ù¤¤Ç¤¢¤ë¡£¤â
+ ¤· $FONT ¤¬¤¹¤Ç¤Ë¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ã¤Æ¤¤¤¿¤é¡¢°ú¿ô $LANGUAGE ¤Ï̵
+
+
+ @return
+ ¤³¤Î´Ø¿ô¤Ï¥¡¼¤¬¥Õ¥©¥ó¥È¥Õ¥¡¥ß¥ê̾¤Ç¤¢¤êÃͤ¬ MFont ¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î
+ ¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤è¤¦¤Êplist ¤òÊÖ¤¹¡£plist ¤Ï m17n_object_unref () ¤Ç
+ ²òÊü¤¹¤ëɬÍפ¬¤¢¤ë¡£¥Õ¥©¥ó¥È¤¬¸«¤Ä¤«¤é¤Ê¤±¤ì¤ÐNULL ¤òÊÖ¤¹¡£ */
+
+MPlist *
+mfont_list (MFrame *frame, MFont *font, MSymbol language, int maxnum)
+{
+ MPlist *plist, *pl;
+ MFontList *font_list;
+ int i;
+ MFont spec;
+
+ if (font)
+ spec = *font;
+ else
+ MFONT_INIT (&spec);
+
+ if (spec.size < 0)
+ {
+ double pt = - spec.size;
+
+ spec.size = pt * frame->dpi / 72.27 + 0.5;
+ }
+
+ if (language != Mnil)
+ spec.capability = merge_capability (spec.capability, Mlanguage, language,
+ 0);
+
+ font_list = mfont__list (frame, &spec, &spec, 0);
+ if (! font_list)
+ return NULL;
+ if (font_list->nfonts == 0)
+ {
+ free (font_list);
+ return NULL;
+ }
+
+ plist = pl = mplist ();
+ for (i = 0; i < font_list->nfonts; i++)
+ {
+ MSymbol family = FONT_PROPERTY (font_list->fonts[i].font, MFONT_FAMILY);
+
+ if (family != Mnil)
+ pl = mplist_add (pl, family, font_list->fonts[i].font);
+ }
+ free (font_list);
+ return plist;
+}
+
+/***en
+ @brief Get a list of font famiy names.
+
+ The mfont_list_family_names () functions returns a list of font
+ family names available on frame $FRAME.
+
+ @return
+
+ This function returns a plist whose keys are #Msymbol and values
+ are symbols representing font family names. The elements are
+ sorted by alphabetical order. The plist must be freed by
+ m17n_object_unref (). If not font is found, it returns NULL. */
+
+MPlist *
+mfont_list_family_names (MFrame *frame)
+{
+ MPlist *plist = mplist (), *p;
+
+ MPLIST_DO (p, frame->font_driver_list)
+ {
+ MFontDriver *driver = MPLIST_VAL (p);
+
+ (driver->list_family_names) (frame, plist);
+ }
+ return plist;
+}
+
+
+/*=*/
+
+/***en
+ @brief Check the usability of a font.
+
+ The mfont_check () function checkes if $FONT can be used for
+ $SCRIPT and $LANGUAGE in $FONTSET on $FRAME.
+
+ @return
+ If the font is usable, return 1. Otherwise return 0.
+ */
+
+int
+mfont_check (MFrame *frame, MFontset *fontset,
+ MSymbol script, MSymbol language, MFont *font)
+{
+ MRealizedFont *rfont;
+ int best, score;
+
+ if (! fontset)
+ fontset = frame->face->property[MFACE_FONTSET];
+ rfont = mfontset__get_font (frame, fontset, script, language, font, &best);
+ if (! rfont || ! best)
+ return 0;
+ score = font_score (&rfont->spec, font);
+ return (score == 0 ? 2 : 1);
+}
+
+/*=*/
+
+/***en
+ @brief Check is a font matches with a font spec.
+
+ The mfont_match_p () function checks if $FONT matches with the
+ font-spec $SPEC.
+
+ @return
+ If the font matches, 1 is returned. Otherwise 0 is returned. */
+
+int
+mfont_match_p (MFont *font, MFont *spec)
+{
+ return mfont__match_p (font, spec, MFONT_REGISTRY);
+}
+
+/*=*/
+/***en
+ @brief Open a font.
+
+ The mfont_open () function opens $FONT on $FRAME, and returns a
+ realized font.
+
+ @return
+ If the font was successfully opened, a realized font is returned.
+ Otherwize NULL is returned.
+
+ @seealso
+ mfont_close (). */
+
+
+MFont *
+mfont_open (MFrame *frame, MFont *font)
+{
+ enum MFontType font_type = font->type;
+
+ if (font_type == MFONT_TYPE_SPEC)
+ return mfont_find (frame, font, NULL, 0);
+ if (font_type == MFONT_TYPE_OBJECT)
+ return (MFont *) mfont__open (frame, font, font);
+ if (font_type == MFONT_TYPE_REALIZED)
+ return font;
+ MERROR (MERROR_FONT, NULL);
+}
+
+/*=*/
+/***en
+ @brief Encapusulate a font.
+
+ The mfont_encapsulate () functions realizes a font by
+ encapusulating data $DATA or type $DATA_TYPE on $FRAME. Currently
+ $DATA_TAPE is #Mfontconfig or #Mfreetype, and $DATA points to an
+ object of FcPattern or FT_Face respectively.
+
+ @return
+ If the operation was successful, a realized font is returned.
+ Otherwise NULL is return.
+
+ @seealso
+ mfont_close (). */
+
+
+MFont *
+mfont_encapsulate (MFrame *frame, MSymbol data_type, void *data)
+{
+ MPlist *p;
+
+ MPLIST_DO (p, frame->font_driver_list)
+ {
+ MFontDriver *driver = MPLIST_VAL (p);
+ MRealizedFont *rfont;
+
+ if (driver->encapsulate
+ && (rfont = driver->encapsulate (frame, data_type, data)))
+ return (MFont *) rfont;
+ }
+
+ return NULL;
+}
+
+/*=*/
+/***en
+ @brief Close a font.
+
+ The mfont_close () function close a realized font $FONT. $FONT
+ must be opened previously by mfont_open () or mfont_encapsulate
+ ().
+
+ @return
+ If the operation was successful, 0 is returned. Otherwise, -1 is
+ returned.
+
+ @seealso
+ mfont_open (), mfont_encapsulate (). */
+
+int
+mfont_close (MFont *font)
+{
+ enum MFontType font_type = font->type;
+ MRealizedFont *rfont;
+
+ if (font_type != MFONT_TYPE_REALIZED)
+ MERROR (MERROR_FONT, -1);
+ rfont = (MRealizedFont *) font;
+ if (rfont->encapsulating
+ && rfont->driver->close)
+ rfont->driver->close (rfont);
+ return 0;
+}
+