From: handa Date: Tue, 22 Jun 2004 05:55:26 +0000 (+0000) Subject: (realize_fontset_elements) X-Git-Tag: withdl~49 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd4b7c605fb0d7b3634e132b978e9abd275d82aa;p=m17n%2Fm17n-lib.git (realize_fontset_elements) (free_realized_fontset_elements, update_fontset_elements): New functions. (mfont__realize_fontset): Call realize_fontset_elements. (mfont__free_realized_fontset): Call free_realized_fontset_elements. (mfont__lookup_fontset): If a fontset was modified, update the realized fontset. (mfontset_modify_entry): Increment fontset->tick. (mfontset_lookup): New function. --- diff --git a/src/fontset.c b/src/fontset.c index 2e045cc..8e72f9f 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -333,72 +333,16 @@ realize_font_group (MFrame *frame, MFont *request, MPlist *font_group, } } - - -/* Internal API */ - -int -mfont__fontset_init () -{ - Mfontset = msymbol ("fontset"); - Mfontset->managing_key = 1; - fontset_list = mplist (); - default_fontset = mfontset ("default"); - if (! default_fontset->mdb) - { - MFont font; - - MFONT_INIT (&font); - mfont_put_prop (&font, Mregistry, msymbol ("iso8859-1")); - mfontset_modify_entry (default_fontset, Mnil, Mnil, Mnil, - &font, Mnil, 1); - mfont_put_prop (&font, Mregistry, msymbol ("iso10646-1")); - mfontset_modify_entry (default_fontset, Mnil, Mnil, Mnil, - &font, Mnil, 1); - } - return 0; -} - - -void -mfont__fontset_fini () -{ - while (! MPLIST_TAIL_P (fontset_list)) - free_fontset ((MFontset *) MPLIST_VAL (fontset_list)); - M17N_OBJECT_UNREF (fontset_list); - fontset_list = NULL; -} - - -MRealizedFontset * -mfont__realize_fontset (MFrame *frame, MFontset *fontset, MFace *face) +static void +realize_fontset_elements (MFrame *frame, MRealizedFontset *realized, + MFontset *fontset, MFont *request) { - MRealizedFontset *realized; - MFont request; MPlist *per_script, *per_lang, *per_charset, *font_group; - MPlist *plist, *pl, *p; - - if (fontset->mdb) - load_fontset_contents (fontset); - - mfont__set_spec_from_face (&request, face); - if (request.property[MFONT_SIZE] <= 0) - { - mdebug_hook (); - request.property[MFONT_SIZE] = 120; - } - MPLIST_DO (p, frame->realized_fontset_list) - { - realized = (MRealizedFontset *) MPLIST_VAL (p); - if (fontset->name == MPLIST_KEY (p) - && ! memcmp (&request, &realized->spec, sizeof (request))) - return realized; - } + MPlist *plist, *pl; - MSTRUCT_MALLOC (realized, MERROR_FONTSET); realized->fontset = fontset; realized->tick = fontset->tick; - realized->spec = request; + realized->spec = *request; realized->frame = frame; realized->per_script = per_script = mplist (); MPLIST_DO (plist, fontset->per_script) @@ -424,13 +368,10 @@ mfont__realize_fontset (MFrame *frame, MFontset *fontset, MFace *face) realized->fallback = mplist (); mplist_add (realized->fallback, Mplist, fontset->fallback); - mplist_add (frame->realized_fontset_list, fontset->name, realized); - return realized; } - -void -mfont__free_realized_fontset (MRealizedFontset *realized) +static void +free_realized_fontset_elements (MRealizedFontset *realized) { MPlist *plist, *pl, *p; MRealizedFont *rfont; @@ -471,7 +412,89 @@ mfont__free_realized_fontset (MRealizedFontset *realized) free (rfont); M17N_OBJECT_UNREF (realized->fallback); } +} + +static void +update_fontset_elements (MRealizedFontset *realized) +{ + free_realized_fontset_elements (realized); + realize_fontset_elements (realized->frame, realized, realized->fontset, + &realized->spec); +} + + + + +/* Internal API */ + +int +mfont__fontset_init () +{ + Mfontset = msymbol ("fontset"); + Mfontset->managing_key = 1; + fontset_list = mplist (); + default_fontset = mfontset ("default"); + if (! default_fontset->mdb) + { + MFont font; + + MFONT_INIT (&font); + mfont_put_prop (&font, Mregistry, msymbol ("iso8859-1")); + mfontset_modify_entry (default_fontset, Mnil, Mnil, Mnil, + &font, Mnil, 1); + mfont_put_prop (&font, Mregistry, msymbol ("iso10646-1")); + mfontset_modify_entry (default_fontset, Mnil, Mnil, Mnil, + &font, Mnil, 1); + } + return 0; +} + + +void +mfont__fontset_fini () +{ + while (! MPLIST_TAIL_P (fontset_list)) + free_fontset ((MFontset *) MPLIST_VAL (fontset_list)); + M17N_OBJECT_UNREF (fontset_list); + fontset_list = NULL; +} + + +MRealizedFontset * +mfont__realize_fontset (MFrame *frame, MFontset *fontset, MFace *face) +{ + MRealizedFontset *realized; + MFont request; + MPlist *plist; + + if (fontset->mdb) + load_fontset_contents (fontset); + + mfont__set_spec_from_face (&request, face); + if (request.property[MFONT_SIZE] <= 0) + { + mdebug_hook (); + request.property[MFONT_SIZE] = 120; + } + MPLIST_DO (plist, frame->realized_fontset_list) + { + realized = (MRealizedFontset *) MPLIST_VAL (plist); + if (fontset->name == MPLIST_KEY (plist) + && ! memcmp (&request, &realized->spec, sizeof (request))) + return realized; + } + + MSTRUCT_MALLOC (realized, MERROR_FONTSET); + realize_fontset_elements (frame, realized, fontset, &request); + mplist_add (frame->realized_fontset_list, fontset->name, realized); + return realized; +} + +void +mfont__free_realized_fontset (MRealizedFontset *realized) +{ + free_realized_fontset_elements (realized); free (realized); } @@ -489,6 +512,9 @@ mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num, MRealizedFont *rfont; int i; + if (realized->tick != realized->fontset->tick) + update_fontset_elements (realized); + if (preferred_charset && (per_charset = mplist_get (realized->per_charset, charset)) != NULL) font_groups[n_font_group++] = per_charset; @@ -912,9 +938,110 @@ mfontset_modify_entry (MFontset *fontset, } } + fontset->tick++; return 0; } +/*=*/ + +/***en + @brief Lookup a fontset. + + The mfontset_lookup () function lookups $FONTSET and returns a + plist that describes the contents of $FONTSET corresponding to the + specified script, language, and charset. + + If $SCRIPT is @c Mt, keys of the returned plist are script name + symbols for which some fonts are specified and values are NULL. + + If $SCIRPT is a script symbol, the returned plist is decided by + $LANGUAGE. + + If $LANGUAGE is @c Mt, keys of the plist are language name symbols + for which some fonts are specified and values are NULL. A key may + be @c Mt which means some fallback fonts are specified for the + script. + + If $LANGUAGE is a language name symbol, the plist is a @c + FONT-GROUP for the specified script and langauge. + + If $LANGAUGE is @c Mt, the plist is fallback @c FONT-GROUP for the + script. + + If $SCRIPT is @c Mnil, the returned plist is decided as below. + + If $CHARSET is @c Mt, keys of the returned plist are charset name + symbols for which some fonts are specified and values are NULL. + + If $CHARSET is a charset symbol, the plist is a @c FONT-GROUP for + the charset. + + If $CHARSET is @c Mnil, the plist is a fallback @c FONT-GROUP. + + @c FONT-GROUP is a plist whose keys are FLT name symbols (@c Mt if + no FLT is associated with the font) and values are pointers to + #MFont. + + @return + It returns a plist describing the contents of a fontset. The + plist should be freed by m17n_object_unref (). */ + +MPlist * +mfontset_lookup (MFontset *fontset, + MSymbol script, MSymbol language, MSymbol charset) +{ + MPlist *plist = mplist (), *pl, *p; + + if (fontset->mdb) + load_fontset_contents (fontset); + if (script == Mt) + { + if (! fontset->per_script) + return plist; + p = plist; + MPLIST_DO (pl, fontset->per_script) + p = mplist_add (p, MPLIST_KEY (pl), NULL); + return plist; + } + if (script != Mnil) + { + if (! fontset->per_script) + return plist; + pl = mplist_get (fontset->per_script, script); + if (! pl) + return plist; + if (language == Mt) + { + p = plist; + MPLIST_DO (pl, pl) + p = mplist_add (p, MPLIST_KEY (pl), NULL); + return plist; + } + if (language == Mnil) + language = Mt; + pl = mplist_get (pl, language); + } + else if (charset != Mnil) + { + if (! fontset->per_charset) + return plist; + if (charset == Mt) + { + p = plist; + MPLIST_DO (pl, fontset->per_charset) + p = mplist_add (p, MPLIST_KEY (pl), NULL); + return plist; + } + pl = mplist_get (fontset->per_charset, charset); + } + else + pl = fontset->fallback; + if (! pl) + return plist; + return mplist_copy (pl); +} + + /*** @} */ /*** @addtogroup m17nDebug */