1 /* fontset.c -- fontset 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
24 @addtogroup m17nFontset
25 @brief A fontset is an object that maps a character to fonts.
27 A @e fontset is an object of the type @c MFontset. When drawing an
28 M-text, a fontset provides rules to select a font for each
29 character in the M-text according to the following information.
31 @li The script character property of a character.
32 @li The language text property of a character.
33 @li The charset text property of a character.
35 The documentation of mdraw_text () describes how that information is
38 /***ja @addtogroup m17nFontset
40 @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ïʸ»ú¤«¤é¥Õ¥©¥ó¥È¤Ø¤ÎÂбþÉÕ¤±¤ò¹Ô¤¦¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
42 @e ¥Õ¥©¥ó¥È¥»¥Ã¥È ¤Ï @c MFontset ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë¡£M-text ¤ò
43 ɽ¼¨¤¹¤ëºÝ¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ï M-text Ãæ¤Î¸Ä¡¹¤Îʸ»ú¤ËÂФ·¤Æ¤É¤Î¥Õ¥©
44 ¥ó¥È¤òÍѤ¤¤ë¤«¤Îµ¬Â§¤ò¡¢°Ê²¼¤Î¾ðÊó¤Ë½¾¤Ã¤ÆÍ¿¤¨¤ë¡£
46 @li ʸ»ú¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£ "¥¹¥¯¥ê¥×¥È"
47 @li ʸ»ú¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ "¸À¸ì"
48 @li ʸ»ú¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ "ʸ»ú¥»¥Ã¥È"
50 ¤³¤ì¤é¤Î¾ðÊ󤬤ɤΤ褦¤ËÍѤ¤¤é¤ì¤ë¤«¤Ï mdraw_text () ¤ÎÀâÌÀ¤ò»²¾È
57 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
58 /*** @addtogroup m17nInternal
68 #include "m17n-misc.h"
72 #include "character.h"
74 #include "internal-gui.h"
82 /* Name of the fontset. */
85 /* Initialized to 0, and incremented by one each time the fontset is
89 /* Database from which to load the contents of the fontset. Once
90 loaded, this member is set to NULL. */
93 /* SCRIPT vs PER-LANGUAGE (which is a plist LANGUAGE vs FONT-GROUP) */
96 /* CHARSET vs FONT-GROUP */
102 /* Plist of Mt vs font specs. */
103 MPlist *font_spec_list;
106 static MFontset *default_fontset;
108 static MPlist *fontset_list;
110 struct MRealizedFontset
112 /* Fontset from which the realized fontset is realized. */
115 /* Initialized to <fontset>->tick. */
118 /* Font spec extracted from a face. */
121 /* The frame on which the realized fontset is realized. */
133 load_font_group (MPlist *plist, MPlist *elt, MPlist *spec_list)
137 /* ELT ::= ( FONT-SPEC-LIST [ LAYOUTER ] ) ... */
139 MFont font, *spec = NULL;
140 MSymbol layouter_name;
142 if (! MPLIST_PLIST_P (elt))
143 MWARNING (MERROR_FONTSET);
144 elt2 = MPLIST_PLIST (elt);
145 if (! MPLIST_PLIST_P (elt2))
146 MWARNING (MERROR_FONTSET);
147 mfont__set_spec_from_plist (&font, MPLIST_PLIST (elt2));
148 MPLIST_DO (p, spec_list)
150 if (! memcmp (MPLIST_VAL (p), &font, sizeof (MFont)))
152 spec = MPLIST_VAL (p);
158 MSTRUCT_MALLOC (spec, MERROR_FONTSET);
160 mplist_add (spec_list, Mt, spec);
162 elt2 = MPLIST_NEXT (elt2);
164 if (MPLIST_SYMBOL_P (elt2))
165 layouter_name = MPLIST_SYMBOL (elt2);
166 if (layouter_name == Mnil)
168 plist = mplist_add (plist, layouter_name, spec);
171 /* ANSI-C requires some statement after a label. */
177 /* Load FONTSET->per_script from the data in FONTSET->mdb. */
180 load_fontset_contents (MFontset *fontset)
182 MPlist *per_script, *per_charset, *fallback, *spec_list, *font_group;
183 MSymbol script, lang;
184 MPlist *fontset_def, *plist;
186 fontset->per_script = per_script = mplist ();
187 fontset->per_charset = per_charset = mplist ();
188 fontset->fallback = fallback = mplist ();
189 fontset->font_spec_list = spec_list = mplist ();
190 if (! (fontset_def = (MPlist *) mdatabase_load (fontset->mdb)))
193 MPLIST_DO (plist, fontset_def)
195 /* PLIST ::= ( SCRIPT ( LANGUAGE FONT-SPEC-ELT ... ) ... )
196 | (CHARSET FONT-SPEC-ELT ...)
200 if (! MPLIST_PLIST_P (plist))
201 MWARNING (MERROR_FONTSET);
202 elt = MPLIST_PLIST (plist);
203 if (! MPLIST_SYMBOL_P (elt))
204 MWARNING (MERROR_FONTSET);
205 script = MPLIST_SYMBOL (elt);
206 elt = MPLIST_NEXT (elt);
207 if (! MPLIST_PLIST_P (elt))
208 MWARNING (MERROR_FONTSET);
210 fallback = load_font_group (fallback, elt, spec_list);
211 else if (MPLIST_PLIST_P (MPLIST_PLIST (elt)))
213 font_group = mplist_find_by_key (fontset->per_charset, script);
216 font_group = mplist ();
217 per_charset = mplist_add (per_charset, script, font_group);
219 load_font_group (font_group, elt, spec_list);
223 MPlist *per_lang = mplist_find_by_key (fontset->per_script, script);
227 per_lang = mplist ();
228 per_script = mplist_add (per_script, script, per_lang);
233 /* ELT ::= ( LANGUAGE FONT-DEF ...) ... */
236 if (! MPLIST_PLIST_P (elt))
237 MWARNING (MERROR_FONTSET);
238 elt2 = MPLIST_PLIST (elt);
239 if (! MPLIST_SYMBOL_P (elt2))
240 MWARNING (MERROR_FONTSET);
241 lang = MPLIST_SYMBOL (elt2);
244 font_group = mplist_find_by_key (per_lang, lang);
247 font_group = mplist ();
248 mplist_add (per_lang, lang, font_group);
250 elt2 = MPLIST_NEXT (elt2);
251 load_font_group (font_group, elt2, spec_list);
257 /* ANSI-C requires some statement after a label. */
261 M17N_OBJECT_UNREF (fontset_def);
266 free_fontset (void *object)
268 MFontset *fontset = (MFontset *) object;
269 MPlist *plist, *pl, *p;
271 if (fontset->per_script)
273 MPLIST_DO (plist, fontset->per_script)
275 MPLIST_DO (pl, MPLIST_PLIST (plist))
277 p = MPLIST_PLIST (pl);
278 M17N_OBJECT_UNREF (p);
280 pl = MPLIST_PLIST (plist);
281 M17N_OBJECT_UNREF (pl);
283 M17N_OBJECT_UNREF (fontset->per_script);
285 if (fontset->per_charset)
287 MPLIST_DO (plist, fontset->per_charset)
289 pl = MPLIST_PLIST (plist);
290 M17N_OBJECT_UNREF (pl);
292 M17N_OBJECT_UNREF (fontset->per_charset);
294 if (fontset->fallback)
295 M17N_OBJECT_UNREF (fontset->fallback);
296 plist = mplist_find_by_key (fontset_list, fontset->name);
300 if (fontset->font_spec_list)
302 if (((M17NObject *) (fontset->font_spec_list))->ref_count == 1)
303 MPLIST_DO (plist, fontset->font_spec_list)
304 free (MPLIST_VAL (plist));
305 M17N_OBJECT_UNREF (fontset->font_spec_list);
311 realize_font_group (MFrame *frame, MFont *request, MPlist *font_group,
314 MPlist *plist = MPLIST_VAL (font_group), *pl, *p;
316 mplist_set (font_group, Mnil, NULL);
317 MPLIST_DO (pl, plist)
319 MSymbol layouter = MPLIST_KEY (pl);
320 MFont this_request = *request;
321 MRealizedFont *rfont;
323 mfont__resize (MPLIST_VAL (pl), &this_request);
324 rfont = mfont__select (frame, MPLIST_VAL (pl), &this_request,
325 size, layouter == Mt ? Mnil : layouter);
329 MPLIST_DO (p, font_group)
330 if (((MRealizedFont *) (MPLIST_VAL (p)))->score > rfont->score)
332 mplist_push (p, Mt, rfont);
338 realize_fontset_elements (MFrame *frame, MRealizedFontset *realized,
339 MFontset *fontset, MFont *request)
341 MPlist *per_script, *per_lang, *per_charset, *font_group;
344 realized->fontset = fontset;
345 realized->tick = fontset->tick;
346 realized->spec = *request;
347 realized->frame = frame;
348 realized->per_script = per_script = mplist ();
349 MPLIST_DO (plist, fontset->per_script)
351 per_lang = mplist ();
352 per_script = mplist_add (per_script, MPLIST_KEY (plist), per_lang);
353 MPLIST_DO (pl, MPLIST_PLIST (plist))
355 font_group = mplist ();
356 mplist_add (font_group, Mplist, MPLIST_VAL (pl));
357 per_lang = mplist_add (per_lang, MPLIST_KEY (pl), font_group);
361 realized->per_charset = per_charset = mplist ();
362 MPLIST_DO (plist, fontset->per_charset)
364 font_group = mplist ();
365 mplist_add (font_group, Mplist, MPLIST_VAL (plist));
366 per_charset = mplist_add (per_charset, MPLIST_KEY (plist), font_group);
369 realized->fallback = mplist ();
370 mplist_add (realized->fallback, Mplist, fontset->fallback);
375 free_realized_fontset_elements (MRealizedFontset *realized)
377 MPlist *plist, *pl, *p;
378 MRealizedFont *rfont;
380 if (realized->per_script)
382 MPLIST_DO (plist, realized->per_script)
384 MPLIST_DO (pl, MPLIST_PLIST (plist))
386 MPLIST_DO (p, MPLIST_PLIST (pl))
387 if ((rfont = MPLIST_VAL (p)) && ! rfont->frame)
389 p = MPLIST_PLIST (pl);
390 M17N_OBJECT_UNREF (p);
392 pl = MPLIST_PLIST (plist);
393 M17N_OBJECT_UNREF (pl);
395 M17N_OBJECT_UNREF (realized->per_script);
397 if (realized->per_charset)
399 MPLIST_DO (plist, realized->per_charset)
401 MPLIST_DO (pl, MPLIST_PLIST (plist))
402 if ((rfont = MPLIST_VAL (pl)) && ! rfont->frame)
404 pl = MPLIST_PLIST (plist);
405 M17N_OBJECT_UNREF (pl);
407 M17N_OBJECT_UNREF (realized->per_charset);
409 if (realized->fallback)
411 MPLIST_DO (plist, realized->fallback)
412 if ((rfont = MPLIST_VAL (plist)) && ! rfont->frame)
414 M17N_OBJECT_UNREF (realized->fallback);
419 update_fontset_elements (MRealizedFontset *realized)
421 free_realized_fontset_elements (realized);
422 realize_fontset_elements (realized->frame, realized, realized->fontset,
432 mfont__fontset_init ()
434 Mfontset = msymbol ("fontset");
435 Mfontset->managing_key = 1;
436 fontset_list = mplist ();
437 default_fontset = mfontset ("default");
438 if (! default_fontset->mdb)
443 mfont_put_prop (&font, Mregistry, msymbol ("iso8859-1"));
444 mfontset_modify_entry (default_fontset, Mnil, Mnil, Mnil,
446 mfont_put_prop (&font, Mregistry, msymbol ("iso10646-1"));
447 mfontset_modify_entry (default_fontset, Mnil, Mnil, Mnil,
455 mfont__fontset_fini ()
457 while (! MPLIST_TAIL_P (fontset_list))
458 free_fontset ((MFontset *) MPLIST_VAL (fontset_list));
459 M17N_OBJECT_UNREF (fontset_list);
465 mfont__realize_fontset (MFrame *frame, MFontset *fontset, MFace *face)
467 MRealizedFontset *realized;
472 load_fontset_contents (fontset);
474 mfont__set_spec_from_face (&request, face);
475 if (request.property[MFONT_SIZE] <= 0)
478 request.property[MFONT_SIZE] = 120;
480 MPLIST_DO (plist, frame->realized_fontset_list)
482 realized = (MRealizedFontset *) MPLIST_VAL (plist);
483 if (fontset->name == MPLIST_KEY (plist)
484 && ! memcmp (&request, &realized->spec, sizeof (request)))
488 MSTRUCT_MALLOC (realized, MERROR_FONTSET);
489 realize_fontset_elements (frame, realized, fontset, &request);
490 mplist_add (frame->realized_fontset_list, fontset->name, realized);
496 mfont__free_realized_fontset (MRealizedFontset *realized)
498 free_realized_fontset_elements (realized);
504 mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
505 MSymbol script, MSymbol language, MSymbol charset,
508 MFrame *frame = realized->frame;
509 MCharset *preferred_charset = (charset == Mnil ? NULL : MCHARSET (charset));
510 MPlist *per_charset, *per_script, *per_lang;
511 MPlist *font_groups[256], *plist;
512 int n_font_group = 0;
513 MRealizedFont *rfont;
516 if (realized->tick != realized->fontset->tick)
517 update_fontset_elements (realized);
519 if (preferred_charset
520 && (per_charset = mplist_get (realized->per_charset, charset)) != NULL)
521 font_groups[n_font_group++] = per_charset;
523 && ((per_script = mplist_find_by_key (realized->per_script, script))
526 /* We prefer font groups in this order:
527 (1) group matching LANGUAGE
528 (2) group for generic LANGUAGE
529 (3) group non-matching LANGUAGE */
530 if (language == Mnil)
532 per_lang = mplist_find_by_key (MPLIST_PLIST (per_script), language);
535 font_groups[n_font_group++] = MPLIST_PLIST (per_lang);
538 MPLIST_DO (per_lang, MPLIST_PLIST (per_script))
539 if (MPLIST_KEY (per_lang) != language)
540 font_groups[n_font_group++] = MPLIST_PLIST (per_lang);
545 plist = mplist_get (MPLIST_PLIST (per_script), Mt);
547 font_groups[n_font_group++] = plist;
549 MPLIST_DO (per_lang, MPLIST_PLIST (per_script))
550 if (MPLIST_KEY (per_lang) != language
551 && MPLIST_KEY (per_lang) != Mt)
552 font_groups[n_font_group++] = MPLIST_PLIST (per_lang);
554 font_groups[n_font_group++] = realized->fallback;
556 if (n_font_group == 1)
558 /* As we only have a fallback font group, try all the other
560 MPLIST_DO (per_script, realized->per_script)
561 MPLIST_DO (per_lang, MPLIST_PLIST (per_script))
562 font_groups[n_font_group++] = MPLIST_PLIST (per_lang);
563 MPLIST_DO (per_charset, realized->per_charset)
564 font_groups[n_font_group++] = MPLIST_PLIST (per_charset);
567 for (i = 0; i < n_font_group; i++)
571 if (MPLIST_PLIST_P (font_groups[i]))
572 realize_font_group (frame, &realized->spec, font_groups[i], size);
574 MPLIST_DO (plist, font_groups[i])
576 rfont = (MRealizedFont *) MPLIST_VAL (plist);
577 if (rfont->status < 0)
579 /* Check if this font can display all glyphs. */
580 for (j = 0; j < *num; j++)
582 g[j].code = mfont__encode_char (rfont,
583 g[j].type == GLYPH_CHAR ? g[j].c
585 if (g[j].code == MCHAR_INVALID_CODE)
590 if (rfont->status > 0
591 || mfont__open (rfont) == 0)
592 /* We found a font that can display all glyphs. */
596 if (! MPLIST_TAIL_P (plist))
600 if (i < n_font_group)
603 /* We couldn't find a font that can display all glyphs. Find one
604 that can display at least the first glyph. */
605 for (i = 0; i < n_font_group; i++)
607 MPLIST_DO (plist, font_groups[i])
609 rfont = (MRealizedFont *) MPLIST_VAL (plist);
610 if (rfont->status < 0)
612 g->code = mfont__encode_char (rfont,
613 g->type == GLYPH_CHAR ? g->c : ' ');
614 if (g->code != MCHAR_INVALID_CODE)
616 if (rfont->status > 0
617 || mfont__open (rfont) == 0)
621 if (! MPLIST_TAIL_P (plist))
624 return (i < n_font_group ? rfont : NULL);
628 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
633 /*** @addtogroup m17nFontset */
638 @brief Return a fontset.
640 The mfontset () function returns a pointer to a fontset object of
641 name $NAME. If $NAME is @c NULL, it returns a pointer to the
644 If no fontset has the name $NAME, a new one is created. At that
645 time, if there exists a data \<@c fontset, $NAME\> in the m17n
646 database, the fontset contents are initialized according to the
647 data. If no such data exists, the fontset contents are left
650 The macro M17N_INIT () creates the default fontset. An
651 application program can modify it before the first call of
655 This function returns a pointer to the found or newly created
658 @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤òÊÖ¤¹.
660 ´Ø¿ô mfontset () ¤Ï̾Á° $NAME ¤ò»ý¤Ä¥Õ¥©¥ó¥È¥»¥Ã¥È¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î
661 ¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£ $NAME ¤¬ @c NULL ¤Ê¤é¤Ð¡¢¥Ç¥Õ¥©¥ë¥È¥Õ¥©¥ó¥È¥»¥Ã¥È
664 $NAME ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥Õ¥©¥ó¥È¥»¥Ã¥È¤¬¤Ê¤±¤ì¤Ð¡¢¿·¤·¤¤¤â¤Î¤¬ºî¤é¤ì
665 ¤ë¡£¤½¤ÎºÝ¡¢m17n ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë \<@c fontset, $NAME\> ¤È¤¤¤¦¥Ç¡¼¥¿
666 ¤¬¤¢¤ì¤Ð¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ï¤½¤Î¥Ç¡¼¥¿¤Ë±è¤Ã¤Æ½é´ü²½¤µ¤ì¤ë¡£¤Ê¤±¤ì¤Ð¡¢
669 ¥Þ¥¯¥í M17N_INIT () ¤Ï¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¥»¥Ã¥È¤òºî¤ë¡£¥¢¥×¥ê¥±¡¼
670 ¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï mframe () ¤ò½é¤á¤Æ¸Æ¤Ö¤Þ¤Ç¤Ï¥Ç¥Õ¥©¥ë¥È¥Õ¥©¥ó¥È
671 ¥»¥Ã¥È¤òÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
674 ¤³¤Î´Ø¿ô¤Ï¸«¤Ä¤«¤Ã¤¿¡¢¤¢¤ë¤¤¤Ïºî¤Ã¤¿¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
678 mfontset (char *name)
684 fontset = default_fontset;
687 sym = msymbol (name);
688 fontset = mplist_get (fontset_list, sym);
691 M17N_OBJECT (fontset, free_fontset, MERROR_FONTSET);
693 fontset->mdb = mdatabase_find (Mfontset, sym, Mnil, Mnil);
696 fontset->per_script = mplist ();
697 fontset->per_charset = mplist ();
698 fontset->fallback = mplist ();
699 fontset->font_spec_list = mplist ();
701 mplist_put (fontset_list, sym, fontset);
704 M17N_OBJECT_REF (fontset);
711 @brief Return the name of a fontset.
713 The mfontset_name () function returns the name of fontset $FONTSET. */
715 @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤Î̾Á°¤òÊÖ¤¹.
717 ´Ø¿ô mfontset_name () ¤Ï¥Õ¥©¥ó¥È¥»¥Ã¥È $FONTSET ¤Î̾Á°¤òÊÖ¤¹¡£ */
719 mfontset_name (MFontset *fontset)
721 return fontset->name;
727 @brief Make a copy of a fontset.
729 The mfontset_copy () function makes a copy of fontset $FONTSET, gives it a
730 name $NAME, and returns a pointer to the created copy. $NAME must
731 not be a name of existing fontset. In such case, this function
732 returns NULL without making a copy. */
734 @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤Î¥³¥Ô¡¼¤òºî¤ë.
736 ´Ø¿ô mfontset_copy () ¤Ï¥Õ¥©¥ó¥È¥»¥Ã¥È $FONTSET ¤Î¥³¥Ô¡¼¤òºî¤Ã¤Æ¡¢
737 ̾Á° $NAME ¤òÍ¿¤¨¡¢¤½¤Î¥³¥Ô¡¼¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£$NAME ¤Ï´û¸¤Î
738 ¥Õ¥©¥ó¥È¥»¥Ã¥È¤Î̾Á°¤Ç¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤½¤Î¾ì¹ç¤Ë¤Ï¥³¥Ô¡¼¤òºî¤é¤º
742 mfontset_copy (MFontset *fontset, char *name)
744 MSymbol sym = msymbol (name);
745 MFontset *copy = mplist_get (fontset_list, sym);
750 M17N_OBJECT (copy, free_fontset, MERROR_FONTSET);
754 load_fontset_contents (fontset);
756 if (fontset->per_script)
758 copy->per_script = mplist ();
759 MPLIST_DO (plist, fontset->per_script)
761 MPlist *new = mplist ();
763 MPLIST_DO (pl, MPLIST_PLIST (plist))
764 mplist_add (new, MPLIST_KEY (pl), mplist_copy (MPLIST_PLIST (pl)));
765 mplist_add (copy->per_script, MPLIST_KEY (plist), new);
768 if (fontset->per_charset)
770 copy->per_charset = mplist ();
771 MPLIST_DO (plist, fontset->per_charset)
772 mplist_add (copy->per_charset, MPLIST_KEY (plist),
773 mplist_copy (MPLIST_PLIST (plist)));
775 if (fontset->fallback)
776 copy->fallback = mplist_copy (fontset->fallback);
778 copy->font_spec_list = fontset->font_spec_list;
779 M17N_OBJECT_REF (copy->font_spec_list);
781 mplist_put (fontset_list, sym, copy);
782 M17N_OBJECT_REF (copy);
789 @brief Modify the contents of a fontset.
791 The mfontset_modify_entry () function associates, in fontset
792 $FONTSET, a copy of $FONT with the $SCRIPT / $LANGUAGE pair or
795 Each font in a fontset is associated with a particular
796 script/language pair, with a particular charset, or with the
797 symbol @c Mnil. The fonts that are associated with the same item
800 If $SCRIPT is not @c Mnil, it must be a symbol identifying a
801 script. In this case, $LANGUAGE is either a symbol identifying a
802 language or @c Mnil, and $FONT is associated with the $SCRIPT /
805 If $CHARSET is not @c Mnil, it must be a symbol representing a
806 charset object. In this case, $FONT is associated with that
809 If both $SCRIPT and $CHARSET are not @c Mnil, two copies of $FONT
810 are created. Then one is associated with the $SCRIPT / $LANGUAGE
811 pair and the other with that charset.
813 If both $SCRIPT and $CHARSET are @c Mnil, $FONT is associated with
814 @c Mnil. This kind of fonts are called @e fallback @e fonts.
816 The argument $HOW specifies the priority of $FONT. If $HOW is
817 positive, $FONT has the highest priority in the group of fonts
818 that are associated with the same item. If $HOW is negative,
819 $FONT has the lowest priority. If $HOW is zero, $FONT becomes the
820 only available font for the associated item; all the other fonts
821 are removed from the group.
823 If $LAYOUTER_NAME is not @c Mnil, it must be a symbol
824 representing a @ref flt. In that case, if $FONT is selected for
825 drawing an M-text, that font layout table is used to generate a
826 glyph code sequence from a character sequence.
829 If the operation was successful, mfontset_modify_entry () returns 0.
830 Otherwise it returns -1 and assigns an error code to the external
831 variable #merror_code. */
834 @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤ÎÆâÍƤòÊѹ¹¤¹¤ë.
836 ´Ø¿ô mfontset_modify_entry () ¤Ï¡¢$LANGUAGE ¤È $SCRIPT ¤ÎÁȤ߹ç¤ï
837 ¤»¤Þ¤¿¤Ï $CHARSET ¤ËÂФ·¤Æ $FONT ¤Î¥³¥Ô¡¼¤ò»È¤¦¤è¤¦¤Ë¡¢¥Õ¥©¥ó¥È¥»¥Ã
838 ¥È $FONTSET ¤òÀßÄꤹ¤ë¡£
840 ¥Õ¥©¥ó¥È¥»¥Ã¥È¤Î³Æ¥Õ¥©¥ó¥È¤Ï¡¢ÆÃÄê¤Î¥¹¥¯¥ê¥×¥È¤È¸À¸ì¤Î¥Ú¥¢¡¢ÆÃÄê¤Î
841 ʸ»ú¥»¥Ã¥È¡¢¥·¥ó¥Ü¥ë @c Mnil ¤Î¤¤¤º¤ì¤«¤È´ØÏ¢ÉÕ¤±¤é¤ì¤Æ¤¤¤ë¡£Æ±¤¸
842 ¤â¤Î¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥©¥ó¥È¤Ï¥°¥ë¡¼¥×¤ò¹½À®¤¹¤ë¡£
844 $SCRIPT ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢¥¹¥¯¥ê¥×¥È¤òÆÃÄꤹ¤ë¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
845 ¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢$LANGUAGE ¤Ï¸À¸ì¤òÆÃÄꤹ¤ë¥·¥ó¥Ü¥ë¤« @c
846 Mnil ¤Ç¤¢¤ê¡¢$FONT ¤Ïthe $SCRIPT / $LANGUAGE ¥Ú¥¢¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤ë¡£
848 $CHARSET ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢Ê¸»ú¥»¥Ã¥È¥ª¥Ö¥¸¥§¥¯¥È¤òɽ¤¹¥·¥ó¥Ü¥ë
849 ¤Ç¤¢¤ë¡£¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï $FONT ¤Ï¤½¤Îʸ»ú¥»¥Ã¥È¤È´ØÏ¢ÉÕ¤±¤é¤ì
852 $SCRIPT ¤È $CHARSET ¤ÎÁÐÊý¤¬ @c Mnil ¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï $FONT ¤Î¥³¥Ô¡¼
853 ¤¬£²¤Äºî¤é¤ì¡¢¤½¤ì¤¾¤ì $SCRIPT / $LANGUAGE ¥Ú¥¢¤Èʸ»ú¥»¥Ã¥È¤Ë´ØÏ¢
856 $SCRIPT ¤È $CHARSET ¤ÎÁÐÊý¤¬ @c Mnil ¤Ê¤é¤Ð¡¢ $FONT ¤Ï @c Mnil ¤È
857 ´ØÏ¢ÉÕ¤±¤é¤ì¤ë¡£¤³¤Î¼ï¤Î¥Õ¥©¥ó¥È¤Ï @e fallback @e font ¤È¸Æ¤Ð¤ì¤ë¡£
859 °ú¿ô $HOW ¤Ï $FONT ¤ÎÍ¥ÀèÅÙ¤ò»ØÄꤹ¤ë¡£$HOW ¤¬Àµ¤Ê¤é¤Ð¡¢$FONT ¤ÏƱ
860 ¤¸¤â¤Î¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥°¥ë¡¼¥×Ãæ¤ÇºÇ¹â¤ÎÍ¥ÀèÅÙ¤ò»ý¤Ä¡£$HOW ¤¬Éé¤Ê
861 ¤é¤Ð¡¢ºÇÄã¤ÎÍ¥ÀèÅÙ¤ò»ý¤Ä¡£$HOW ¤¬ 0 ¤Ê¤é¤Ð¡¢$FONT ¤Ï´ØÏ¢ÉÕ¤±¤é¤ì¤¿
862 ¤â¤Î¤ËÂФ¹¤ëÍ£°ì¤ÎÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤È¤Ê¤ê¡¢Â¾¤Î¥Õ¥©¥ó¥È¤Ï¥°¥ë¡¼¥×
865 $LAYOUTER_NAME ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢@ref flt ¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
866 ¥·¥ó¥Ü¥ë¤Ç¤¢¤ì¤Ð¡¢$FONT ¤òÍѤ¤¤ÆM-text ¤òɽ¼¨¤¹¤ëºÝ¤Ë¤Ï¡¢¤½¤Î FONT
867 LAYOUT TABLE ¤ò»È¤Ã¤Æʸ»úÎ󤫤饰¥ê¥Õ¥³¡¼¥ÉÎó¤òÀ¸À®¤¹¤ë¡£
870 ½èÍý¤¬À®¸ù¤·¤¿¤È¤¡¢mfontset_modify_entry () ¤Ï 0 ¤òÊÖ¤¹¡£
871 ¼ºÇÔ¤·¤¿¤È¤¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤ò
879 mfontset_modify_entry (MFontset *fontset,
880 MSymbol script, MSymbol language, MSymbol charset,
881 MFont *spec, MSymbol layouter_name,
884 MPlist *per_lang, *plist[3], *pl;
889 load_fontset_contents (fontset);
891 if (! fontset->font_spec_list)
892 fontset->font_spec_list = mplist ();
894 MPLIST_DO (pl, fontset->font_spec_list)
896 if (! memcmp (MPLIST_VAL (pl), spec, sizeof (MFont)))
898 font = MPLIST_VAL (pl);
906 mplist_add (fontset->font_spec_list, Mt, font);
912 if (language == Mnil)
914 per_lang = mplist_get (fontset->per_script, script);
916 mplist_add (fontset->per_script, script, per_lang = mplist ());
917 plist[i] = mplist_get (per_lang, language);
919 mplist_add (per_lang, language, plist[i] = mplist ());
924 plist[i] = mplist_get (fontset->per_charset, charset);
926 mplist_add (fontset->per_charset, charset, plist[i] = mplist ());
929 if (script == Mnil && charset == Mnil)
931 plist[i++] = fontset->fallback;
934 if (layouter_name == Mnil)
936 for (i--; i >= 0; i--)
939 mplist_push (plist[i], layouter_name, font);
941 mplist_add (plist[i], layouter_name, font);
944 mplist_set (plist[i], Mnil, NULL);
945 mplist_add (plist[i], layouter_name, font);
956 @brief Lookup a fontset.
958 The mfontset_lookup () function lookups $FONTSET and returns a
959 plist that describes the contents of $FONTSET corresponding to the
960 specified script, language, and charset.
962 If $SCRIPT is @c Mt, keys of the returned plist are script name
963 symbols for which some fonts are specified and values are NULL.
965 If $SCIRPT is a script symbol, the returned plist is decided by
968 If $LANGUAGE is @c Mt, keys of the plist are language name symbols
969 for which some fonts are specified and values are NULL. A key may
970 be @c Mt which means some fallback fonts are specified for the
973 If $LANGUAGE is a language name symbol, the plist is a @c
974 FONT-GROUP for the specified script and langauge.
976 If $LANGAUGE is @c Mt, the plist is fallback @c FONT-GROUP for the
979 If $SCRIPT is @c Mnil, the returned plist is decided as below.
981 If $CHARSET is @c Mt, keys of the returned plist are charset name
982 symbols for which some fonts are specified and values are NULL.
984 If $CHARSET is a charset symbol, the plist is a @c FONT-GROUP for
987 If $CHARSET is @c Mnil, the plist is a fallback @c FONT-GROUP.
989 @c FONT-GROUP is a plist whose keys are FLT name symbols (@c Mt if
990 no FLT is associated with the font) and values are pointers to
994 It returns a plist describing the contents of a fontset. The
995 plist should be freed by m17n_object_unref (). */
998 mfontset_lookup (MFontset *fontset,
999 MSymbol script, MSymbol language, MSymbol charset)
1001 MPlist *plist = mplist (), *pl, *p;
1004 load_fontset_contents (fontset);
1007 if (! fontset->per_script)
1010 MPLIST_DO (pl, fontset->per_script)
1011 p = mplist_add (p, MPLIST_KEY (pl), NULL);
1016 if (! fontset->per_script)
1018 pl = mplist_get (fontset->per_script, script);
1025 p = mplist_add (p, MPLIST_KEY (pl), NULL);
1028 if (language == Mnil)
1030 pl = mplist_get (pl, language);
1032 else if (charset != Mnil)
1034 if (! fontset->per_charset)
1039 MPLIST_DO (pl, fontset->per_charset)
1040 p = mplist_add (p, MPLIST_KEY (pl), NULL);
1043 pl = mplist_get (fontset->per_charset, charset);
1046 pl = fontset->fallback;
1049 return mplist_copy (pl);
1055 /*** @addtogroup m17nDebug */
1060 @brief Dump a fontset.
1062 The mdebug_dump_fontset () function prints fontset $FONTSET in a human readable
1063 way to the stderr. $INDENT specifies how many columns to indent
1064 the lines but the first one.
1067 This function returns $FONTSET. */
1069 @brief ¥Õ¥©¥ó¥È¥»¥Ã¥È¤ò¥À¥ó¥×¤¹¤ë.
1071 ´Ø¿ô mdebug_dump_face () ¤Ï¥Õ¥©¥ó¥È¥»¥Ã¥È $FONTSET ¤ò stderr ¤Ë¿Í
1072 ´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ
1076 ¤³¤Î´Ø¿ô¤Ï $FONTSET ¤òÊÖ¤¹¡£ */
1079 mdebug_dump_fontset (MFontset *fontset, int indent)
1081 char *prefix = (char *) alloca (indent + 1);
1082 MPlist *plist, *pl, *p;
1084 memset (prefix, 32, indent);
1087 fprintf (stderr, "(fontset %s", fontset->name->name);
1088 if (fontset->per_script)
1089 MPLIST_DO (plist, fontset->per_script)
1091 fprintf (stderr, "\n %s(%s", prefix, MPLIST_KEY (plist)->name);
1092 MPLIST_DO (pl, MPLIST_PLIST (plist))
1094 fprintf (stderr, "\n %s(%s", prefix, MPLIST_KEY (pl)->name);
1095 MPLIST_DO (p, MPLIST_PLIST (pl))
1097 fprintf (stderr, "\n %s(%s ", prefix,
1098 MPLIST_KEY (p)->name);
1099 mdebug_dump_font (MPLIST_VAL (p));
1100 fprintf (stderr, ")");
1102 fprintf (stderr, ")");
1104 fprintf (stderr, ")");
1106 if (fontset->per_charset)
1107 MPLIST_DO (pl, fontset->per_charset)
1109 fprintf (stderr, "\n %s(%s", prefix, MPLIST_KEY (pl)->name);
1110 MPLIST_DO (p, MPLIST_PLIST (pl))
1112 fprintf (stderr, "\n %s(%s ", prefix, MPLIST_KEY (p)->name);
1113 mdebug_dump_font (MPLIST_VAL (p));
1114 fprintf (stderr, ")");
1116 fprintf (stderr, ")");
1119 if (fontset->fallback)
1120 MPLIST_DO (p, fontset->fallback)
1122 fprintf (stderr, "\n %s(%s ", prefix, MPLIST_KEY (p)->name);
1123 mdebug_dump_font (MPLIST_VAL (p));
1124 fprintf (stderr, ")");
1127 fprintf (stderr, ")");