unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* `set-fontset-font' and ascii characters
@ 2003-04-27 10:22 Oliver Scholz
  2003-05-01  8:10 ` Kenichi Handa
  0 siblings, 1 reply; 18+ messages in thread
From: Oliver Scholz @ 2003-04-27 10:22 UTC (permalink / raw)


Is there any special reason why `set-fontset-font' should raise an
error, if CHARACTER specifies a single byte char? The patch below
seems to work, but I may be missing something.

    Oliver

*** fontset.c.~1.73.~	Fri Jan 17 09:10:00 2003
--- fontset.c	Sun Apr 27 12:05:48 2003
***************
*** 992,997 ****
--- 992,999 ----
    int from, to;
    int id;
    Lisp_Object family, registry;
+   int sbyte_change = 0; /* Flag indicating that CHARACTER specifies
+ 			   the `ascii' charset. */
  
    fontset = check_fontset_name (name);
  
***************
*** 1007,1013 ****
  	error ("Character range should be by non-generic characters.");
        if (!NILP (name)
  	  && (SINGLE_BYTE_CHAR_P (from) || SINGLE_BYTE_CHAR_P (to)))
! 	error ("Can't change font for a single byte character");
      }
    else if (SYMBOLP (character))
      {
--- 1009,1015 ----
  	error ("Character range should be by non-generic characters.");
        if (!NILP (name)
  	  && (SINGLE_BYTE_CHAR_P (from) || SINGLE_BYTE_CHAR_P (to)))
! 	sbyte_change = 1;
      }
    else if (SYMBOLP (character))
      {
***************
*** 1026,1038 ****
    if (!char_valid_p (from, 1))
      invalid_character (from);
    if (SINGLE_BYTE_CHAR_P (from))
!     error ("Can't change font for a single byte character");
    if (from < to)
      {
        if (!char_valid_p (to, 1))
  	invalid_character (to);
        if (SINGLE_BYTE_CHAR_P (to))
! 	error ("Can't change font for a single byte character");
      }
  
    if (STRINGP (fontname))
--- 1028,1040 ----
    if (!char_valid_p (from, 1))
      invalid_character (from);
    if (SINGLE_BYTE_CHAR_P (from))
!     sbyte_change = 1;
    if (from < to)
      {
        if (!char_valid_p (to, 1))
  	invalid_character (to);
        if (SINGLE_BYTE_CHAR_P (to))
! 	sbyte_change = 1;
      }
  
    if (STRINGP (fontname))
***************
*** 1067,1088 ****
      FONTSET_SET (fontset, from, elt);
    Foptimize_char_table (fontset);
  
!   /* If there's a realized fontset REALIZED whose parent is FONTSET,
!      clear all the elements of REALIZED and free all multibyte faces
!      whose fontset is REALIZED.  This way, the specified character(s)
!      are surely redisplayed by a correct font.  */
!   for (id = 0; id < ASIZE (Vfontset_table); id++)
!     {
!       realized = AREF (Vfontset_table, id);
!       if (!NILP (realized)
! 	  && !BASE_FONTSET_P (realized)
! 	  && EQ (FONTSET_BASE (realized), fontset))
! 	{
! 	  FRAME_PTR f = XFRAME (FONTSET_FRAME (realized));
! 	  clear_fontset_elements (realized);
! 	  free_realized_multibyte_face (f, id);
! 	}
!     }
  
    return Qnil;
  }
--- 1069,1100 ----
      FONTSET_SET (fontset, from, elt);
    Foptimize_char_table (fontset);
  
!   if (sbyte_change)
!     {
!       /* The ascii charset needs a special treatment in order to make
! 	 sure that it is redisplayed in the correct font. The
! 	 following (stolen from `internal-set-lisp-face-attribute')
! 	 makes sure that the next call to init_iterator will free all
! 	 realized faces. */
!       ++face_change_count;
!       ++windows_or_buffers_changed;
!     } else {
!     /* If there's a realized fontset REALIZED whose parent is FONTSET,
!        clear all the elements of REALIZED and free all multibyte faces
!        whose fontset is REALIZED.  This way, the specified character(s)
!        are surely redisplayed by a correct font.  */
!     for (id = 0; id < ASIZE (Vfontset_table); id++)
!       {
! 	realized = AREF (Vfontset_table, id);
! 	if (!NILP (realized)
! 	    && !BASE_FONTSET_P (realized)
! 	    && EQ (FONTSET_BASE (realized), fontset))
! 	  {
! 	    FRAME_PTR f = XFRAME (FONTSET_FRAME (realized));
! 	    clear_fontset_elements (realized);
! 	    free_realized_multibyte_face (f, id);
! 	  }
!       }}
  
    return Qnil;
  }


-- 
8 Floréal an 211 de la Révolution
Liberté, Egalité, Fraternité!

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-04-27 10:22 `set-fontset-font' and ascii characters Oliver Scholz
@ 2003-05-01  8:10 ` Kenichi Handa
  2003-05-01 17:48   ` Oliver Scholz
  2003-05-02  7:06   ` Richard Stallman
  0 siblings, 2 replies; 18+ messages in thread
From: Kenichi Handa @ 2003-05-01  8:10 UTC (permalink / raw)
  Cc: emacs-devel

In article <87he8kutns.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
> Is there any special reason why `set-fontset-font' should raise an
> error, if CHARACTER specifies a single byte char? The patch below
> seems to work, but I may be missing something.

Thank you for working on it.

If we change the ASCII font in the fontset of the default
face, I think it should have the same effect as changing the
font of the default face (e.g. changing the font size
results in chaning the frame size).  The reason I inhibitted
changing ASCII font in a fontset is that it seems difficult
to achieve that effect (or at least I didn't know how to do
that when I wrote the code).  Does you change pay attetion
to that?

---
Ken'ichi HANDA
handa@m17n.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-01  8:10 ` Kenichi Handa
@ 2003-05-01 17:48   ` Oliver Scholz
  2003-05-01 20:01     ` Oliver Scholz
  2003-05-02  7:06   ` Richard Stallman
  1 sibling, 1 reply; 18+ messages in thread
From: Oliver Scholz @ 2003-05-01 17:48 UTC (permalink / raw)
  Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1493 bytes --]

Kenichi Handa <handa@m17n.org> writes:

> In article <87he8kutns.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
>> Is there any special reason why `set-fontset-font' should raise an
>> error, if CHARACTER specifies a single byte char? The patch below
>> seems to work, but I may be missing something.
>
> Thank you for working on it.
>
> If we change the ASCII font in the fontset of the default
> face, I think it should have the same effect as changing the
> font of the default face (e.g. changing the font size
> results in chaning the frame size).  The reason I inhibitted
> changing ASCII font in a fontset is that it seems difficult
> to achieve that effect (or at least I didn't know how to do
> that when I wrote the code).  Does you change pay attetion
> to that?
[...]

It doesn't, sorry. I didn't realize that this could be an issue,
because I use an window manager which keeps frames full-size anyways.

But I spent the afternoon browsing the sources for a solution that
does. The two patches below seem to make it work (only slightly
tested).

Now, if an ASCII font was changed, Fset_fontset_font checks all frames
whether FONTSET is their frame fontset and forces a resizing of all
frames that have. This is done by the new function
x_new_fontset_force, which is like x_new_fontset, except that it does
its works even if new fontset = old fontset. (This is done by
factoring out a new function x_set_fontset_internal out of x_set_fontset.)

    Oliver


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fontset.diff --]
[-- Type: text/x-patch, Size: 4332 bytes --]

*** fontset.c.~1.76.~	Thu Feb 20 15:13:04 2003
--- fontset.c	Thu May  1 19:31:18 2003
***************
*** 36,41 ****
--- 36,42 ----
  #include "dispextern.h"
  #include "fontset.h"
  #include "window.h"
+ #include "xterm.h"
  
  #ifdef FONTSET_DEBUG
  #undef xassert
***************
*** 993,998 ****
--- 994,1001 ----
    int from, to;
    int id;
    Lisp_Object family, registry;
+   int sbyte_change = 0; /* Flag indicating that CHARACTER specifies
+ 			   the `ascii' charset. */
  
    fontset = check_fontset_name (name);
  
***************
*** 1008,1014 ****
  	error ("Character range should be by non-generic characters.");
        if (!NILP (name)
  	  && (SINGLE_BYTE_CHAR_P (from) || SINGLE_BYTE_CHAR_P (to)))
! 	error ("Can't change font for a single byte character");
      }
    else if (SYMBOLP (character))
      {
--- 1011,1017 ----
  	error ("Character range should be by non-generic characters.");
        if (!NILP (name)
  	  && (SINGLE_BYTE_CHAR_P (from) || SINGLE_BYTE_CHAR_P (to)))
! 	sbyte_change = 1;
      }
    else if (SYMBOLP (character))
      {
***************
*** 1027,1039 ****
    if (!char_valid_p (from, 1))
      invalid_character (from);
    if (SINGLE_BYTE_CHAR_P (from))
!     error ("Can't change font for a single byte character");
    if (from < to)
      {
        if (!char_valid_p (to, 1))
  	invalid_character (to);
        if (SINGLE_BYTE_CHAR_P (to))
! 	error ("Can't change font for a single byte character");
      }
  
    if (STRINGP (fontname))
--- 1030,1042 ----
    if (!char_valid_p (from, 1))
      invalid_character (from);
    if (SINGLE_BYTE_CHAR_P (from))
!     sbyte_change = 1;
    if (from < to)
      {
        if (!char_valid_p (to, 1))
  	invalid_character (to);
        if (SINGLE_BYTE_CHAR_P (to))
! 	sbyte_change = 1;
      }
  
    if (STRINGP (fontname))
***************
*** 1068,1089 ****
      FONTSET_SET (fontset, from, elt);
    Foptimize_char_table (fontset);
  
!   /* If there's a realized fontset REALIZED whose parent is FONTSET,
!      clear all the elements of REALIZED and free all multibyte faces
!      whose fontset is REALIZED.  This way, the specified character(s)
!      are surely redisplayed by a correct font.  */
!   for (id = 0; id < ASIZE (Vfontset_table); id++)
!     {
!       realized = AREF (Vfontset_table, id);
!       if (!NILP (realized)
! 	  && !BASE_FONTSET_P (realized)
! 	  && EQ (FONTSET_BASE (realized), fontset))
  	{
! 	  FRAME_PTR f = XFRAME (FONTSET_FRAME (realized));
! 	  clear_fontset_elements (realized);
! 	  free_realized_multibyte_face (f, id);
  	}
!     }
  
    return Qnil;
  }
--- 1071,1119 ----
      FONTSET_SET (fontset, from, elt);
    Foptimize_char_table (fontset);
  
!   /* Make sure that Emacs displays all faces with the correct
!      font. The ascii charset needs a special treatment.*/
!   if (sbyte_change)
!     {
!       Lisp_Object fr_list;
!       FRAME_PTR frpt;
!       
!       /* Check all frames whether they have FONTSET as the fontset for
! 	 the default face. If so, make sure that Emacs changes the
! 	 size of the frame accordingly. */
!       for (fr_list = Vframe_list;
! 	   CONSP (fr_list);
! 	   fr_list = XCDR (fr_list))
  	{
! 	  frpt = XFRAME (XCAR (fr_list));
! 	  if (FONTSET_ID (fontset) == FRAME_FONTSET (frpt))
! 	    {
! 	      Lisp_Object fpvalue = get_frame_param (frpt, Qfont);
! 	      x_new_fontset_force (frpt, SDATA (fpvalue));
! 	    }
  	}
!       /* Make sure that the next call to init_iterator will free all
! 	 realized faces (stolen from
! 	 `internal-set-lisp-face-attribute'). */
!       ++face_change_count;
!       ++windows_or_buffers_changed;
!     } else {
!     /* If there's a realized fontset REALIZED whose parent is FONTSET,
!        clear all the elements of REALIZED and free all multibyte faces
!        whose fontset is REALIZED.  This way, the specified character(s)
!        are surely redisplayed by a correct font.  */
!     for (id = 0; id < ASIZE (Vfontset_table); id++)
!       {
! 	realized = AREF (Vfontset_table, id);
! 	if (!NILP (realized)
! 	    && !BASE_FONTSET_P (realized)
! 	    && EQ (FONTSET_BASE (realized), fontset))
! 	  {
! 	    FRAME_PTR f = XFRAME (FONTSET_FRAME (realized));
! 	    clear_fontset_elements (realized);
! 	    free_realized_multibyte_face (f, id);
! 	  }
!       }}
  
    return Qnil;
  }

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: xterm.diff --]
[-- Type: text/x-patch, Size: 2109 bytes --]

*** xterm.c.~1.790.~	Wed Apr  9 18:44:46 2003
--- xterm.c	Thu May  1 19:30:51 2003
***************
*** 7937,7943 ****
       char *fontsetname;
  {
    int fontset = fs_query_fontset (build_string (fontsetname), 0);
-   Lisp_Object result;
  
    if (fontset < 0)
      return Qnil;
--- 7937,7942 ----
***************
*** 7947,7957 ****
         to do.  */
      return fontset_name (fontset);
  
!   result = x_new_font (f, (SDATA (fontset_ascii (fontset))));
  
    if (!STRINGP (result))
      /* Can't load ASCII font.  */
!     return Qnil;
  
    /* Since x_new_font doesn't update any fontset information, do it now.  */
    f->output_data.x->fontset = fontset;
--- 7946,7986 ----
         to do.  */
      return fontset_name (fontset);
  
!   if (x_new_fontset_internal (f, fontset) == 0)
!     return build_string (fontsetname);
!   else return Qnil;
! }
! 
! 
! /* Like x_new_fontset, but don't check wheter the fontset is already
!    set in the frame. */
! 
! Lisp_Object
! x_new_fontset_force (f, fontsetname)
!      struct frame *f;
!      char *fontsetname;
! {
!   int fontset = fs_query_fontset (build_string (fontsetname), 0);
! 
!   if (fontset < 0)
!     return Qnil;
! 
!   if (x_new_fontset_internal (f, fontset) == 0)
!     return build_string (fontsetname);
!   else return Qnil;
! }
! 
! int
! x_new_fontset_internal (f, fontset)
!      struct frame *f;
!      int fontset;
! {
!   Lisp_Object result
!     = x_new_font (f, (SDATA (fontset_ascii (fontset))));
  
    if (!STRINGP (result))
      /* Can't load ASCII font.  */
!     return 1;
  
    /* Since x_new_font doesn't update any fontset information, do it now.  */
    f->output_data.x->fontset = fontset;
***************
*** 7961,7968 ****
        && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea)))
      xic_set_xfontset (f, SDATA (fontset_ascii (fontset)));
  #endif
! 
!   return build_string (fontsetname);
  }
  
  \f
--- 7990,7996 ----
        && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea)))
      xic_set_xfontset (f, SDATA (fontset_ascii (fontset)));
  #endif
!   return 0;
  }
  
  \f

[-- Attachment #4: Type: text/plain, Size: 243 bytes --]



-- 
Oliver Scholz               12 Floréal an 211 de la Révolution
Taunusstr. 25               Liberté, Egalité, Fraternité!
60329 Frankfurt a. M.       http://www.jungdemokratenhessen.de
Tel. (069) 97 40 99 42      http://www.jdjl.org

[-- Attachment #5: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-01 17:48   ` Oliver Scholz
@ 2003-05-01 20:01     ` Oliver Scholz
  2003-05-01 23:53       ` Kenichi Handa
  0 siblings, 1 reply; 18+ messages in thread
From: Oliver Scholz @ 2003-05-01 20:01 UTC (permalink / raw)


Oliver Scholz <alkibiades@gmx.de> writes:
[...]
> Now, if an ASCII font was changed, Fset_fontset_font checks all frames
> whether FONTSET is their frame fontset and forces a resizing of all
> frames that have. This is done by the new function
> x_new_fontset_force, which is like x_new_fontset, except that it does
> its works even if new fontset = old fontset. (This is done by
> factoring out a new function x_set_fontset_internal out of x_set_fontset.)
[...]

Uh, sorry, I was confused. Upon further reading I realize now that it
is wrong to include xterm.h. Somehow I thought that xterm.c contains
only generic functions.

Currently fontset.c applies the function x_set_font by means of the
variable set_frame_fontset_func, which is set in xfns.c, macfns.c and
w32fns.c to x_set_font. So, would it be a proper way to use
x_new_font_set_force by doing something similar with a new variable,
say force_frame_fontset_func?

    Oliver
-- 
12 Floréal an 211 de la Révolution
Liberté, Egalité, Fraternité!

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-01 20:01     ` Oliver Scholz
@ 2003-05-01 23:53       ` Kenichi Handa
  2003-05-02  0:06         ` Kenichi Handa
  2003-05-02  0:39         ` Oliver Scholz
  0 siblings, 2 replies; 18+ messages in thread
From: Kenichi Handa @ 2003-05-01 23:53 UTC (permalink / raw)
  Cc: emacs-devel

In article <uvfwuh1x1.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
> Uh, sorry, I was confused. Upon further reading I realize now that it
> is wrong to include xterm.h. Somehow I thought that xterm.c contains
> only generic functions.

> Currently fontset.c applies the function x_set_font by means of the
> variable set_frame_fontset_func, which is set in xfns.c, macfns.c and
> w32fns.c to x_set_font. So, would it be a proper way to use
> x_new_font_set_force by doing something similar with a new variable,
> say force_frame_fontset_func?

Yes.  I tried to make fontset.c independent on a window
system.

By the way, I re-consider the problem of chaning the fontset
of the default face.

You wrote:
> Now, if an ASCII font was changed, Fset_fontset_font checks all frames
> whether FONTSET is their frame fontset and forces a resizing of all
> frames that have. This is done by the new function
> x_new_fontset_force, which is like x_new_fontset, except that it does
> its works even if new fontset = old fontset. (This is done by
> factoring out a new function x_set_fontset_internal out of x_set_fontset.)

Isn't it easier to call Finternal_set_lisp_face_attribute on
all faces that has FONTSET?  That function handles the
default face correctly.

Vface_new_frame_defaults holds all named faces, the format is
((FACE . LFACE) ...).  LFACE[LFACE_FONT] gives the font or
fontset name of FACE.

This may work also in the case of changing non-ASCII font.

If this method works, the resulting code becomes simpler.
We can get rid of these functions:
 clear_fontset_elements, free_realized_multibyte_face

---
Ken'ichi HANDA
handa@m17n.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-01 23:53       ` Kenichi Handa
@ 2003-05-02  0:06         ` Kenichi Handa
  2003-05-02  0:39         ` Oliver Scholz
  1 sibling, 0 replies; 18+ messages in thread
From: Kenichi Handa @ 2003-05-02  0:06 UTC (permalink / raw)
  Cc: alkibiades

I forgot to mention one thing.

In article <200305012353.IAA15973@etlken.m17n.org>, Kenichi Handa <handa@m17n.org> writes:
> Vface_new_frame_defaults holds all named faces, the format is
> ((FACE . LFACE) ...).  LFACE[LFACE_FONT] gives the font or
> fontset name of FACE.

LFACE[LFACE_FONT] may have a font name that is an alias of a
fontset.  So, we have to check the name by Fquery_fontset.

---
Ken'ichi HANDA
handa@m17n.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-01 23:53       ` Kenichi Handa
  2003-05-02  0:06         ` Kenichi Handa
@ 2003-05-02  0:39         ` Oliver Scholz
  2003-05-02  1:05           ` Kenichi Handa
  1 sibling, 1 reply; 18+ messages in thread
From: Oliver Scholz @ 2003-05-02  0:39 UTC (permalink / raw)
  Cc: emacs-devel

Kenichi Handa <handa@m17n.org> writes:
[...]
> By the way, I re-consider the problem of chaning the fontset
> of the default face.
>
> You wrote:
>> Now, if an ASCII font was changed, Fset_fontset_font checks all frames
>> whether FONTSET is their frame fontset and forces a resizing of all
>> frames that have. This is done by the new function
>> x_new_fontset_force, which is like x_new_fontset, except that it does
>> its works even if new fontset = old fontset. (This is done by
>> factoring out a new function x_set_fontset_internal out of x_set_fontset.)
>
> Isn't it easier to call Finternal_set_lisp_face_attribute on
> all faces that has FONTSET?  That function handles the
> default face correctly.

I guess so. Basically that is how I discovered x_new_fontset. I
started with Finternal_set_lisp_face_attribute and read the code until
I found the exact spot where the frame is resized. And now you tell
me that all this was pointless, because I could have used
Finternal_set_lisp_face in the first place? *moan* :-)

Allright, if you say that it is cleaner or easier to maintain this
way, then I'll look at it tomorrow.

    Oliver
-- 
Oliver Scholz               13 Floréal an 211 de la Révolution
Taunusstr. 25               Liberté, Egalité, Fraternité!
60329 Frankfurt a. M.       http://www.jungdemokratenhessen.de
Tel. (069) 97 40 99 42      http://www.jdjl.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-02  0:39         ` Oliver Scholz
@ 2003-05-02  1:05           ` Kenichi Handa
  2003-05-02 23:16             ` Oliver Scholz
  0 siblings, 1 reply; 18+ messages in thread
From: Kenichi Handa @ 2003-05-02  1:05 UTC (permalink / raw)
  Cc: emacs-devel

In article <uade6ji5i.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
> I guess so. Basically that is how I discovered x_new_fontset. I
> started with Finternal_set_lisp_face_attribute and read the code until
> I found the exact spot where the frame is resized. And now you tell
> me that all this was pointless, because I could have used
> Finternal_set_lisp_face in the first place? *moan* :-)

I should have got that idea from the start, sorry.  :-(

> Allright, if you say that it is cleaner or easier to maintain this
> way, then I'll look at it tomorrow.

Thank you very much.  That way, I think, fontset.c can be
modularized much more, which results in the easier
maintenance.

---
Ken'ichi HANDA
handa@m17n.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-01  8:10 ` Kenichi Handa
  2003-05-01 17:48   ` Oliver Scholz
@ 2003-05-02  7:06   ` Richard Stallman
  1 sibling, 0 replies; 18+ messages in thread
From: Richard Stallman @ 2003-05-02  7:06 UTC (permalink / raw)
  Cc: alkibiades

    If we change the ASCII font in the fontset of the default
    face, I think it should have the same effect as changing the
    font of the default face (e.g. changing the font size
    results in chaning the frame size).  The reason I inhibitted
    changing ASCII font in a fontset is that it seems difficult
    to achieve that effect (or at least I didn't know how to do
    that when I wrote the code).

Can't you achieve that effect by calling set-frame-font?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-02  1:05           ` Kenichi Handa
@ 2003-05-02 23:16             ` Oliver Scholz
  2003-05-03  2:48               ` Kenichi Handa
  0 siblings, 1 reply; 18+ messages in thread
From: Oliver Scholz @ 2003-05-02 23:16 UTC (permalink / raw)
  Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]

Kenichi Handa <handa@m17n.org> writes:

> In article <uade6ji5i.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
>> I guess so. Basically that is how I discovered x_new_fontset. I
>> started with Finternal_set_lisp_face_attribute and read the code until
>> I found the exact spot where the frame is resized. And now you tell
>> me that all this was pointless, because I could have used
>> Finternal_set_lisp_face in the first place? *moan* :-)
>
> I should have got that idea from the start, sorry.  :-(

I was just kidding. It was a good opportunity to read and understand
yet another part of the C code. And I had fun doing it. So my time
was well applied.

>> Allright, if you say that it is cleaner or easier to maintain this
>> way, then I'll look at it tomorrow.
>
> Thank you very much.  That way, I think, fontset.c can be
> modularized much more, which results in the easier
> maintenance.

O.k. Here's the new patch.

It seems that free_realized_multibyte_face is not used anymore. But it
is defined in xfaces.c, so I didn't touch it.

    Oliver


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 4126 bytes --]

*** fontset.c.~1.76.~	Thu Feb 20 15:13:04 2003
--- fontset.c	Sat May  3 01:09:28 2003
***************
*** 939,958 ****
    return Qnil;
  }
  
- 
- /* Clear all elements of FONTSET for multibyte characters.  */
- 
- static void
- clear_fontset_elements (fontset)
-      Lisp_Object fontset;
- {
-   int i;
- 
-   for (i = CHAR_TABLE_SINGLE_BYTE_SLOTS; i < CHAR_TABLE_ORDINARY_SLOTS; i++)
-     XCHAR_TABLE (fontset)->contents[i] = Qnil;
- }
- 
- 
  /* Check validity of NAME as a fontset name and return the
     corresponding fontset.  If not valid, signal an error.
     If NAME is nil, return Vdefault_fontset.  */
--- 939,944 ----
***************
*** 973,978 ****
--- 959,967 ----
    return FONTSET_FROM_ID (id);
  }
  
+ extern Lisp_Object QCfont;
+ extern Lisp_Object Vface_new_frame_defaults;
+ 
  DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 4, 0,
         doc: /* Modify fontset NAME to use FONTNAME for CHARACTER.
  
***************
*** 993,999 ****
--- 982,991 ----
    int from, to;
    int id;
    Lisp_Object family, registry;
+   Lisp_Object lf_fnt, lfaces, fontset_name;
+ 
  
+   fontset_name = Fquery_fontset (name, Qnil);
    fontset = check_fontset_name (name);
  
    if (CONSP (character))
***************
*** 1006,1014 ****
        to = XINT (XCDR (character));
        if (!char_valid_p (from, 0) || !char_valid_p (to, 0))
  	error ("Character range should be by non-generic characters.");
-       if (!NILP (name)
- 	  && (SINGLE_BYTE_CHAR_P (from) || SINGLE_BYTE_CHAR_P (to)))
- 	error ("Can't change font for a single byte character");
      }
    else if (SYMBOLP (character))
      {
--- 998,1003 ----
***************
*** 1026,1039 ****
      }
    if (!char_valid_p (from, 1))
      invalid_character (from);
-   if (SINGLE_BYTE_CHAR_P (from))
-     error ("Can't change font for a single byte character");
    if (from < to)
      {
        if (!char_valid_p (to, 1))
  	invalid_character (to);
-       if (SINGLE_BYTE_CHAR_P (to))
- 	error ("Can't change font for a single byte character");
      }
  
    if (STRINGP (fontname))
--- 1015,1024 ----
***************
*** 1068,1088 ****
      FONTSET_SET (fontset, from, elt);
    Foptimize_char_table (fontset);
  
!   /* If there's a realized fontset REALIZED whose parent is FONTSET,
!      clear all the elements of REALIZED and free all multibyte faces
!      whose fontset is REALIZED.  This way, the specified character(s)
!      are surely redisplayed by a correct font.  */
!   for (id = 0; id < ASIZE (Vfontset_table); id++)
!     {
!       realized = AREF (Vfontset_table, id);
!       if (!NILP (realized)
! 	  && !BASE_FONTSET_P (realized)
! 	  && EQ (FONTSET_BASE (realized), fontset))
! 	{
! 	  FRAME_PTR f = XFRAME (FONTSET_FRAME (realized));
! 	  clear_fontset_elements (realized);
! 	  free_realized_multibyte_face (f, id);
! 	}
      }
  
    return Qnil;
--- 1053,1082 ----
      FONTSET_SET (fontset, from, elt);
    Foptimize_char_table (fontset);
  
!   /* If the fontset is already used in a face, then we need to update
!      the display accordingly. 
! 
!      This is done by calling Finternal_set_lisp_face. To find the
!      faces which we need to update this way, we loop through all the
!      faces declared in Vface_new_frame_alist and check each face
!      whether FONTSET_NAME is specified as its fontset. Each element in
!      Vface_new_frame_alist a cons cell with the symbol for the face as
!      its car and an LFACE (a Lisp vector containing the face
!      specification) as its cdr. */
! 
!   for (lfaces = Vface_new_frame_defaults;
!        CONSP (lfaces);
!        lfaces = XCDR (lfaces))
!     {
!       /* Set lf_fnt to the font or fontset specified for the current
! 	 LFACE. */
!       lf_fnt = AREF (XCDR (XCAR (lfaces)), LFACE_FONT_INDEX);
!       /* We call Fquery_fontset, so we are not puzzled by alias names,
! 	 which may be used in LFACE. */
!       if (STRINGP (lf_fnt) &&
! 	  !NILP (Fequal (fontset_name, Fquery_fontset (lf_fnt, Qnil))))
! 	Finternal_set_lisp_face_attribute
! 	  ((XCAR (XCAR (lfaces))), QCfont, fontset_name, 0);
      }
  
    return Qnil;

[-- Attachment #3: Type: text/plain, Size: 242 bytes --]


-- 
Oliver Scholz               14 Floréal an 211 de la Révolution
Taunusstr. 25               Liberté, Egalité, Fraternité!
60329 Frankfurt a. M.       http://www.jungdemokratenhessen.de
Tel. (069) 97 40 99 42      http://www.jdjl.org

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-02 23:16             ` Oliver Scholz
@ 2003-05-03  2:48               ` Kenichi Handa
  2003-05-03 22:24                 ` Oliver Scholz
  0 siblings, 1 reply; 18+ messages in thread
From: Kenichi Handa @ 2003-05-03  2:48 UTC (permalink / raw)
  Cc: emacs-devel

In article <87isstx7le.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
>>  I should have got that idea from the start, sorry.  :-(

> I was just kidding.

And please don't take my "sorry" seriously.  :-p

> It was a good opportunity to read and understand
> yet another part of the C code. And I had fun doing it. So my time
> was well applied.

I'm very glad to hear that someone is looking at mule
related codes.

> O.k. Here's the new patch.

> It seems that free_realized_multibyte_face is not used anymore. But it
> is defined in xfaces.c, so I didn't touch it.

I'll check that patch next week and install it if I don't
find any problems.  Thank you.

---
Ken'ichi HANDA
handa@m17n.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-03  2:48               ` Kenichi Handa
@ 2003-05-03 22:24                 ` Oliver Scholz
  2003-05-05  8:33                   ` Kenichi Handa
  0 siblings, 1 reply; 18+ messages in thread
From: Oliver Scholz @ 2003-05-03 22:24 UTC (permalink / raw)
  Cc: emacs-devel

Kenichi Handa <handa@m17n.org> writes:

> In article <87isstx7le.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
[...]
>> O.k. Here's the new patch.
[...]
> I'll check that patch next week and install it if I don't
> find any problems.  Thank you.
[...]

I found a bug. Emacs crashes, if you evaluated the following code with
my patch applied:

(progn
  (set-face-font 'default "fontset-default")
  (set-fontset-font "fontset-default"
		    'ascii
		    '("helvetica" . "iso8859-1")))

The critical fault seems to take place in `set_lface_from_font_name'
in xfaces.c (called from `Finternal_set_lisp_face_attribute'):

  if (fontset >= 0)
    font_name = SDATA (fontset_ascii (fontset));

But fontset_ascii doesn't return a Lisp-String in this case.

Where is the proper place to fix this?

    Oliver
-- 
Oliver Scholz               15 Floréal an 211 de la Révolution
Taunusstr. 25               Liberté, Egalité, Fraternité!
60329 Frankfurt a. M.       http://www.jungdemokratenhessen.de
Tel. (069) 97 40 99 42      http://www.jdjl.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-03 22:24                 ` Oliver Scholz
@ 2003-05-05  8:33                   ` Kenichi Handa
  2003-05-06 13:48                     ` Oliver Scholz
  0 siblings, 1 reply; 18+ messages in thread
From: Kenichi Handa @ 2003-05-05  8:33 UTC (permalink / raw)
  Cc: emacs-devel

In article <87bryj8y94.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
> I found a bug. Emacs crashes, if you evaluated the following code with
> my patch applied:

> (progn
>   (set-face-font 'default "fontset-default")
>   (set-fontset-font "fontset-default"
> 		    'ascii
> 		    '("helvetica" . "iso8859-1")))

> The critical fault seems to take place in `set_lface_from_font_name'
> in xfaces.c (called from `Finternal_set_lisp_face_attribute'):

>   if (fontset >= 0)
>     font_name = SDATA (fontset_ascii (fontset));

Oops.  Currently, a fontset should have a font name
(i.e. string, not cons of (FAMILY . REGISTRY)) for ascii.
So, if (FAMILY . REGISTRY) is specified, it mast be
transformed to "-FAMILY-*-REGISTRY".  If FAMILY doesn't
contain '-', "*-" must be prepended to FAMILY in advance.
If REGISTRY doesn't contain '-', "-*" must be appended to
REGISTRY in advance.

One more thing to note.  Currently all ascii characters
should have the same font in a fontset.  So, for instance,
(set-fontset-font FONTSET '(?a . ?z) FONT_NAME) must be
inhibited or treated as (set-fontset-font FONTSET 'ascii
FONT_NAME).

These are the dirty parts originating in a bad interaction
between face and fontset.  Clearing them out is in my todo
list for a long time, but I've never had time to work on it.

---
Ken'ichi HANDA
handa@m17n.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-05  8:33                   ` Kenichi Handa
@ 2003-05-06 13:48                     ` Oliver Scholz
  2003-05-07  1:12                       ` Kenichi Handa
  0 siblings, 1 reply; 18+ messages in thread
From: Oliver Scholz @ 2003-05-06 13:48 UTC (permalink / raw)
  Cc: emacs-devel

Kenichi Handa <handa@m17n.org> writes:
[...]
> Oops.  Currently, a fontset should have a font name
> (i.e. string, not cons of (FAMILY . REGISTRY)) for ascii.
> So, if (FAMILY . REGISTRY) is specified, it mast be
> transformed to "-FAMILY-*-REGISTRY".  If FAMILY doesn't
> contain '-', "*-" must be prepended to FAMILY in advance.
> If REGISTRY doesn't contain '-', "-*" must be appended to
> REGISTRY in advance.
[...]
> These are the dirty parts originating in a bad interaction
> between face and fontset.  Clearing them out is in my todo
> list for a long time, but I've never had time to work on it.
[...]

If that is going to be reworked (I'd like to help if I can and if you
want), then maybe it is sufficient to put a fence around the problem
for now? I.e. raise an error for (set-fontset-font FONTSET 'ascii
CONS-CELL). That's what I do now in my version of fontset.c. For the
purpose of making fontsets customizable it is sufficient--I think--if
I can set the ASCII font with (set-fontset-font FONTSET 'ascii
FONTNAME).

If that's o.k., then I'll send a new patch together with my stuff for
customize, as soon as it is finished.

    Oliver
-- 
Oliver Scholz               16 Floréal an 211 de la Révolution
Taunusstr. 25               Liberté, Egalité, Fraternité!
60329 Frankfurt a. M.       http://www.jungdemokratenhessen.de
Tel. (069) 97 40 99 42      http://www.jdjl.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-06 13:48                     ` Oliver Scholz
@ 2003-05-07  1:12                       ` Kenichi Handa
  2003-05-25 12:17                         ` Oliver Scholz
  0 siblings, 1 reply; 18+ messages in thread
From: Kenichi Handa @ 2003-05-07  1:12 UTC (permalink / raw)
  Cc: emacs-devel

In article <u1xzctcdp.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
> If that is going to be reworked (I'd like to help if I can and if you
> want), then maybe it is sufficient to put a fence around the problem
> for now? I.e. raise an error for (set-fontset-font FONTSET 'ascii
> CONS-CELL). That's what I do now in my version of fontset.c. For the
> purpose of making fontsets customizable it is sufficient--I think--if
> I can set the ASCII font with (set-fontset-font FONTSET 'ascii
> FONTNAME).

Hmmm, ok, I agree.

> If that's o.k., then I'll send a new patch together with my stuff for
> customize, as soon as it is finished.

Thank you.

---
Ken'ichi HANDA
handa@m17n.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-07  1:12                       ` Kenichi Handa
@ 2003-05-25 12:17                         ` Oliver Scholz
  2003-06-10  2:16                           ` Kenichi Handa
  0 siblings, 1 reply; 18+ messages in thread
From: Oliver Scholz @ 2003-05-25 12:17 UTC (permalink / raw)
  Cc: emacs-devel

Kenichi Handa <handa@m17n.org> writes:

> In article <u1xzctcdp.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
>> If that is going to be reworked (I'd like to help if I can and if you
>> want), then maybe it is sufficient to put a fence around the problem
>> for now? I.e. raise an error for (set-fontset-font FONTSET 'ascii
>> CONS-CELL). That's what I do now in my version of fontset.c. For the
>> purpose of making fontsets customizable it is sufficient--I think--if
>> I can set the ASCII font with (set-fontset-font FONTSET 'ascii
>> FONTNAME).
>
> Hmmm, ok, I agree.
[...]

I changed my mind, while working on the customization stuff. I started
to implement it according to your previous suggestions. But I realized
that specifying a cons cell as FONTNAME argument to `set-fontset-font'
does not seem to work with non-ASCII charsets either. I tested it with
an Emacs without my modifications:

(create-fontset-from-fontset-spec 
 "-b&h-lucidatypewriter-medium-r-*-*-14-*-*-*-*-*-fontset-test")

(set-face-font 'default "fontset-test")

(set-fontset-font "fontset-test" 'latin-iso8859-1 '("misc-fixed" . "iso8859-1"))

Now when I type some umlauts like "äöü" Emacs still displays them in
b&h-lucidatypewriter.

But it works, when I specify a fontname:

(set-fontset-font "fontset-test" 'latin-iso8859-1
                  "-misc-fixed-*-iso8859-1")

Am I missing something?

It would, of course, be easy to change `set-fontset-font' to generate
a fontname string from such a cons cell, so that:
("misc-fixed" . "iso8859-1") ==> "-misc-fixed-*-iso8859-1". But as
far as I understand the code, this is not the way it is supposed to
work for non-ASCII fonts, therefore I ask.

    Oliver
-- 
6 Prairial an 211 de la Révolution
Liberté, Egalité, Fraternité!

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-05-25 12:17                         ` Oliver Scholz
@ 2003-06-10  2:16                           ` Kenichi Handa
  2003-06-10  2:47                             ` Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Kenichi Handa @ 2003-06-10  2:16 UTC (permalink / raw)
  Cc: emacs-devel

I'm very sorry for this late response.

In article <87isrzb4pt.fsf@ID-87814.user.dfncis.de>, Oliver Scholz <alkibiades@gmx.de> writes:
> I changed my mind, while working on the customization
> stuff. I started to implement it according to your
> previous suggestions. But I realized that specifying a
> cons cell as FONTNAME argument to `set-fontset-font' does
> not seem to work with non-ASCII charsets either. I tested
> it with an Emacs without my modifications:

> (create-fontset-from-fontset-spec
> "-b&h-lucidatypewriter-medium-r-*-*-14-*-*-*-*-*-fontset-test")

> (set-face-font 'default "fontset-test")

> (set-fontset-font "fontset-test" 'latin-iso8859-1
> '("misc-fixed" . "iso8859-1"))

> Now when I type some umlauts like "äöü" Emacs still
> displays them in b&h-lucidatypewriter.

> But it works, when I specify a fontname:

> (set-fontset-font "fontset-test" 'latin-iso8859-1
> "-misc-fixed-*-iso8859-1")

> Am I missing something?

If a font name that doesn't conforms to full XLFD is
specified, the font name is used as is, otherwise, the
family field and registry field are extracted from the font
name.  In the latter case, we faces the problem of which
family to prefer, a face family (b&h-lucidatypewriter) or a
fontset family (misc-fixed).

Currently, for a character of ASCII and Latin-1, emacs
prefers a face family, and for the other chars, emacs
prefers a fontset family.  It's a very kludgy way, and
should be fixed somehow, but currently I don't have a time
to think about it and I don't remember now why the code is
like that.  :-(

Please see the code of choose_face_font and try_font_list.

In choose_face_font, if you change the call of try_font_list
as this:

  nfonts = try_font_list (f, attrs, XCAR (pattern), XCDR (pattern), &fonts,
			  SINGLE_BYTE_CHAR_P (c));

the fontset family should be prefered.  Could you please try it?

---
Ken'ichi HANDA
handa@m17n.org

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: `set-fontset-font' and ascii characters
  2003-06-10  2:16                           ` Kenichi Handa
@ 2003-06-10  2:47                             ` Stefan Monnier
  0 siblings, 0 replies; 18+ messages in thread
From: Stefan Monnier @ 2003-06-10  2:47 UTC (permalink / raw)
  Cc: alkibiades

> Currently, for a character of ASCII and Latin-1, emacs
> prefers a face family, and for the other chars, emacs
> prefers a fontset family.  It's a very kludgy way, and
> should be fixed somehow, but currently I don't have a time
> to think about it and I don't remember now why the code is
> like that.  :-(

IIRC, it had to do with the fact that if the face says `courier'
and the fontset info specifies `symbols', the fontset info
should take precedence (it's when the font-registry info is not
enough to map charsets to fonts and needs to be supplemented
with font-family info).
But on the other hand, if your Emacs.font says "-misc-fixed-blabla",
the `misc-fixed' info coming from your fontset should not supercede
the `helvetica' info provided by `variable-pitch' face (for example).


	Stefan

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2003-06-10  2:47 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-27 10:22 `set-fontset-font' and ascii characters Oliver Scholz
2003-05-01  8:10 ` Kenichi Handa
2003-05-01 17:48   ` Oliver Scholz
2003-05-01 20:01     ` Oliver Scholz
2003-05-01 23:53       ` Kenichi Handa
2003-05-02  0:06         ` Kenichi Handa
2003-05-02  0:39         ` Oliver Scholz
2003-05-02  1:05           ` Kenichi Handa
2003-05-02 23:16             ` Oliver Scholz
2003-05-03  2:48               ` Kenichi Handa
2003-05-03 22:24                 ` Oliver Scholz
2003-05-05  8:33                   ` Kenichi Handa
2003-05-06 13:48                     ` Oliver Scholz
2003-05-07  1:12                       ` Kenichi Handa
2003-05-25 12:17                         ` Oliver Scholz
2003-06-10  2:16                           ` Kenichi Handa
2003-06-10  2:47                             ` Stefan Monnier
2003-05-02  7:06   ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).