+static MRealizedFont *
+try_font_group (MRealizedFontset *realized,
+ MPlist *font_group, MGlyph *g, int *num, int size)
+{
+ MFrame *frame = realized->frame;
+ MRealizedFont *rfont;
+ MPlist *plist;
+ int i;
+
+ if (MPLIST_PLIST_P (font_group))
+ realize_font_group (frame, &realized->spec, font_group, size);
+
+ MPLIST_DO (plist, font_group)
+ {
+ rfont = (MRealizedFont *) MPLIST_VAL (plist);
+ if (rfont->status < 0)
+ continue;
+ /* Check if this font can display all glyphs. */
+ for (i = 0; i < *num; i++)
+ {
+ g[i].code = mfont__encode_char (rfont,
+ g[i].type == GLYPH_CHAR ? g[i].c
+ : ' ');
+ if (g[i].code == MCHAR_INVALID_CODE)
+ break;
+ }
+ if (i == *num)
+ {
+ if (rfont->status > 0
+ || mfont__open (rfont) == 0)
+ /* We found a font that can display all glyphs. */
+ return rfont;
+ }
+ }
+
+ /* We couldn't find a font that can display all glyphs. Find one
+ that can display at least the first glyph. */
+ MPLIST_DO (plist, font_group)
+ {
+ rfont = (MRealizedFont *) MPLIST_VAL (plist);
+ if (rfont->status < 0)
+ continue;
+ g->code = mfont__encode_char (rfont,
+ g->type == GLYPH_CHAR ? g->c : ' ');
+ if (g->code != MCHAR_INVALID_CODE)
+ {
+ if (rfont->status > 0
+ || mfont__open (rfont) == 0)
+ {
+ /* Ok, let's use this font. Check how many more
+ characters it supports. */
+ int i;
+
+ for (i = 1; i < *num; i++)
+ {
+ g[i].code = mfont__encode_char (rfont,
+ g[i].type == GLYPH_CHAR
+ ? g[i].c : ' ');
+ if (g[i].code == MCHAR_INVALID_CODE)
+ break;
+ }
+ *num = i;
+ return rfont;
+ }
+ }
+ }
+
+ return NULL;
+}
+