emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/xfns.c [emacs-unicode-2]


From: Miles Bader
Subject: [Emacs-diffs] Changes to emacs/src/xfns.c [emacs-unicode-2]
Date: Fri, 22 Oct 2004 06:21:34 -0400

Index: emacs/src/xfns.c
diff -c emacs/src/xfns.c:1.590.2.8 emacs/src/xfns.c:1.590.2.9
*** emacs/src/xfns.c:1.590.2.8  Thu Oct 14 08:49:54 2004
--- emacs/src/xfns.c    Fri Oct 22 10:13:35 2004
***************
*** 1921,1949 ****
  };
  
  
! /* Create an X fontset on frame F with base font name
!    BASE_FONTNAME.. */
  
  static XFontSet
  xic_create_xfontset (f, base_fontname)
       struct frame *f;
       char *base_fontname;
  {
!   XFontSet xfs;
    char **missing_list;
    int missing_count;
    char *def_string;
  
!   xfs = XCreateFontSet (FRAME_X_DISPLAY (f),
!                       base_fontname, &missing_list,
!                       &missing_count, &def_string);
    if (missing_list)
      XFreeStringList (missing_list);
  
!   /* No need to free def_string. */
    return xfs;
  }
  
  
  /* Value is the best input style, given user preferences USER (already
     checked to be supported by Emacs), and styles supported by the
--- 1921,2003 ----
  };
  
  
! /* Create an X fontset on frame F with base font name BASE_FONTNAME.  */
  
  static XFontSet
  xic_create_xfontset (f, base_fontname)
       struct frame *f;
       char *base_fontname;
  {
!   XFontSet xfs = NULL;
    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)
+           && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
+           && !strcmp (FRAME_XIC_BASE_FONTNAME (cf), base_fontname))
+         {
+           xfs = FRAME_XIC_FONTSET (cf);
+           break;
+         }
+     }
  
!   if (!xfs)
!     /* New fontset.  */
!     xfs = XCreateFontSet (FRAME_X_DISPLAY (f),
!                           base_fontname, &missing_list,
!                           &missing_count, &def_string);
    if (missing_list)
      XFreeStringList (missing_list);
  
!   if (FRAME_XIC_BASE_FONTNAME (f))
!     xfree (FRAME_XIC_BASE_FONTNAME (f));
!   FRAME_XIC_BASE_FONTNAME (f) = xstrdup (base_fontname);
! 
!   /* No need to free def_string.  */
    return xfs;
  }
  
+ /* Free the X fontset of frame F if it is the last frame using it.  */
+ 
+ void
+ xic_free_xfontset (f)
+      struct frame *f;
+ {
+   Lisp_Object rest, frame;
+   int shared_p = 0;
+ 
+   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_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
+           && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f))
+         {
+           shared_p = 1;
+           break;
+         }
+     }
+ 
+   if (!shared_p)
+     /* The fontset is not used anymore.  It is safe to free it.  */
+     XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
+ 
+   if (FRAME_XIC_BASE_FONTNAME (f))
+     xfree (FRAME_XIC_BASE_FONTNAME (f));
+   FRAME_XIC_BASE_FONTNAME (f) = NULL;
+   FRAME_XIC_FONTSET (f) = NULL;
+ }
+ 
  
  /* Value is the best input style, given user preferences USER (already
     checked to be supported by Emacs), and styles supported by the
***************
*** 2094,2104 ****
      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;
  }
  
  
--- 2148,2156 ----
      return;
  
    XDestroyIC (FRAME_XIC (f));
!   xic_free_xfontset (f);
  
    FRAME_XIC (f) = NULL;
  }
  
  
***************
*** 2177,2182 ****
--- 2229,2236 ----
    XVaNestedList attr;
    XFontSet xfs;
  
+   xic_free_xfontset (f);
+ 
    xfs = xic_create_xfontset (f, base_fontname);
  
    attr = XVaCreateNestedList (0, XNFontSet, xfs, NULL);
***************
*** 2186,2193 ****
      XSetICValues (FRAME_XIC (f), XNStatusAttributes, attr, NULL);
    XFree (attr);
  
-   if (FRAME_XIC_FONTSET (f))
-     XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
    FRAME_XIC_FONTSET (f) = xfs;
  }
  
--- 2240,2245 ----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]