*** diff-old/src/xfns.c 2004-10-11 00:24:05.000000000 +0200 --- diff-new/src/xfns.c 2004-10-11 00:18:09.000000000 +0200 *************** *** 1953,1959 **** --- 1953,1970 ---- char **missing_list; int missing_count; char *def_string; + Lisp_Object rest, frame; + /* See if there is another frame already using same fontset. */ + FOR_EACH_FRAME (rest, frame) + { + struct frame *cf = XFRAME (frame); + if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf) + && !strcmp (FRAME_XIC_BASE_FONTNAME (cf), base_fontname)) + return FRAME_XIC_FONTSET (cf); + } + + /* New fontset. */ xfs = XCreateFontSet (FRAME_X_DISPLAY (f), base_fontname, &missing_list, &missing_count, &def_string); *************** *** 1964,1969 **** --- 1975,2003 ---- return xfs; } + /* Free the X fontset of frame F if it is the last frame using it. */ + + void + xic_delete_xfontset (f) + struct frame *f; + { + Lisp_Object rest, frame; + + if (!FRAME_XIC_FONTSET (f)) + return; + + /* See if there is another frame sharing the same fontset. */ + FOR_EACH_FRAME (rest, frame) + { + struct frame *cf = XFRAME (frame); + if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf) + && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f)) + return; + } + /* The fontset is not used anymore. It is safe to free it. */ + XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); + } + /* Value is the best input style, given user preferences USER (already checked to be supported by Emacs), and styles supported by the *************** *** 2101,2106 **** --- 2135,2141 ---- FRAME_XIC (f) = xic; FRAME_XIC_STYLE (f) = xic_style; FRAME_XIC_FONTSET (f) = xfs; + FRAME_XIC_BASE_FONTNAME (f) = xstrdup (base_fontname); } *************** *** 2114,2124 **** return; XDestroyIC (FRAME_XIC (f)); ! if (FRAME_XIC_FONTSET (f)) ! XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); FRAME_XIC (f) = NULL; FRAME_XIC_FONTSET (f) = NULL; } --- 2149,2161 ---- return; XDestroyIC (FRAME_XIC (f)); ! xic_delete_xfontset (f); ! if (FRAME_XIC_BASE_FONTNAME (f)) ! xfree (FRAME_XIC_BASE_FONTNAME (f)); FRAME_XIC (f) = NULL; FRAME_XIC_FONTSET (f) = NULL; + FRAME_XIC_BASE_FONTNAME (f) = NULL; } *************** *** 2207,2214 **** XFree (attr); if (FRAME_XIC_FONTSET (f)) ! XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); FRAME_XIC_FONTSET (f) = xfs; } #endif /* HAVE_X_I18N */ --- 2244,2256 ---- XFree (attr); if (FRAME_XIC_FONTSET (f)) ! xic_delete_xfontset (f); ! ! if (FRAME_XIC_BASE_FONTNAME (f)) ! xfree (FRAME_XIC_BASE_FONTNAME (f)); ! FRAME_XIC_FONTSET (f) = xfs; + FRAME_XIC_BASE_FONTNAME (f) = xstrdup (base_fontname); } #endif /* HAVE_X_I18N */