emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] Changes to emacs/src/term.c,v


From: Miles Bader
Subject: [Emacs-diffs] Changes to emacs/src/term.c,v
Date: Fri, 01 Feb 2008 16:01:59 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Miles Bader <miles>     08/02/01 16:01:31

Index: src/term.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/term.c,v
retrieving revision 1.211
retrieving revision 1.212
diff -u -b -r1.211 -r1.212
--- src/term.c  8 Jan 2008 20:44:19 -0000       1.211
+++ src/term.c  1 Feb 2008 16:00:45 -0000       1.212
@@ -43,8 +43,11 @@
 #include "lisp.h"
 #include "termchar.h"
 #include "termopts.h"
+#include "buffer.h"
+#include "character.h"
 #include "charset.h"
 #include "coding.h"
+#include "composite.h"
 #include "keyboard.h"
 #include "frame.h"
 #include "disptab.h"
@@ -188,7 +191,6 @@
 
 #ifdef HAVE_GPM
 #include <sys/fcntl.h>
-#include "buffer.h"
 
 static void term_clear_mouse_face ();
 static void term_mouse_highlight (struct frame *f, int x, int y);
@@ -549,10 +551,12 @@
     }
 }
 
-/* Buffer to store the source and result of code conversion for terminal.  */
-static unsigned char *encode_terminal_buf;
-/* Allocated size of the above buffer.  */
-static int encode_terminal_bufsize;
+/* Buffers to store the source and result of code conversion for terminal.  */
+static unsigned char *encode_terminal_src;
+static unsigned char *encode_terminal_dst;
+/* Allocated sizes of the above buffers.  */
+static int encode_terminal_src_size;
+static int encode_terminal_dst_size;
 
 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes.
    Set CODING->produced to the byte-length of the resulting byte
@@ -570,37 +574,73 @@
   int nchars, nbytes, required;
   register int tlen = GLYPH_TABLE_LENGTH;
   register Lisp_Object *tbase = GLYPH_TABLE_BASE;
+  Lisp_Object charset_list;
 
   /* Allocate sufficient size of buffer to store all characters in
      multibyte-form.  But, it may be enlarged on demand if
-     Vglyph_table contains a string.  */
+     Vglyph_table contains a string or a composite glyph is
+     encountered.  */
   required = MAX_MULTIBYTE_LENGTH * src_len;
-  if (encode_terminal_bufsize < required)
+  if (encode_terminal_src_size < required)
     {
-      if (encode_terminal_bufsize == 0)
-       encode_terminal_buf = xmalloc (required);
+      if (encode_terminal_src_size == 0)
+       encode_terminal_src = xmalloc (required);
       else
-       encode_terminal_buf = xrealloc (encode_terminal_buf, required);
-      encode_terminal_bufsize = required;
+       encode_terminal_src = xrealloc (encode_terminal_src, required);
+      encode_terminal_src_size = required;
     }
 
-  buf = encode_terminal_buf;
+  charset_list = coding_charset_list (coding);
+
+  buf = encode_terminal_src;
   nchars = 0;
   while (src < src_end)
     {
+      if (src->type == COMPOSITE_GLYPH)
+       {
+         struct composition *cmp = composition_table[src->u.cmp_id];
+         int i;
+
+         nbytes = buf - encode_terminal_src;
+         required = MAX_MULTIBYTE_LENGTH * cmp->glyph_len;
+
+         if (encode_terminal_src_size < nbytes + required)
+           {
+             encode_terminal_src_size = nbytes + required;
+             encode_terminal_src = xrealloc (encode_terminal_src,
+                                             encode_terminal_src_size);
+             buf = encode_terminal_src + nbytes;
+           }
+
+         for (i = 0; i < cmp->glyph_len; i++)
+           {
+             int c = COMPOSITION_GLYPH (cmp, i);
+             
+             if (! char_charset (c, charset_list, NULL))
+               break;
+             buf += CHAR_STRING (c, buf);
+             nchars++;
+           }
+         if (i == 0)
+           {
+             /* The first character of the composition is not encodable.  */
+             *buf++ = '?';
+             nchars++;
+           }
+       }
       /* We must skip glyphs to be padded for a wide character.  */
-      if (! CHAR_GLYPH_PADDING_P (*src))
+      else if (! CHAR_GLYPH_PADDING_P (*src))
        {
+         int c;
+         Lisp_Object string;
+
+         string = Qnil;
          g = GLYPH_FROM_CHAR_GLYPH (src[0]);
 
          if (g < 0 || g >= tlen)
            {
              /* This glyph doesn't has an entry in Vglyph_table.  */
-             if (CHAR_VALID_P (src->u.ch, 0))
-               buf += CHAR_STRING (src->u.ch, buf);
-             else
-               *buf++ = SPACEGLYPH;
-             nchars++;
+             c = src->u.ch;
            }
          else
            {
@@ -609,65 +649,90 @@
              GLYPH_FOLLOW_ALIASES (tbase, tlen, g);
 
              if (GLYPH_SIMPLE_P (tbase, tlen, g))
-               {
-                 int c = FAST_GLYPH_CHAR (g);
+               /* We set the multi-byte form of a character in G
+                  (that should be an ASCII character) at WORKBUF.  */
+               c = FAST_GLYPH_CHAR (g);
+             else
+               /* We have a string in Vglyph_table.  */
+               string = tbase[g];
+           }
 
-                 if (CHAR_VALID_P (c, 0))
+         if (NILP (string))
+           {
+             nbytes = buf - encode_terminal_src;
+             if (encode_terminal_src_size < nbytes + MAX_MULTIBYTE_LENGTH)
+               {
+                 encode_terminal_src_size = nbytes + MAX_MULTIBYTE_LENGTH;
+                 encode_terminal_src = xrealloc (encode_terminal_src,
+                                                 encode_terminal_src_size);
+                 buf = encode_terminal_src + nbytes;
+               }
+             if (char_charset (c, charset_list, NULL))
+               {
+                 /* Store the multibyte form of C at BUF.  */
                    buf += CHAR_STRING (c, buf);
+                 nchars++;
+               }
                  else
-                   *buf++ = SPACEGLYPH;
+               {
+                 /* C is not encodable.  */
+                 *buf++ = '?';
                  nchars++;
+                 while (src + 1 < src_end && CHAR_GLYPH_PADDING_P (src[1]))
+                   {
+                     *buf++ = '?';
+                     nchars++;
+                     src++;
+                   }
+               }
                }
              else
                {
-                 /* We have a string in Vglyph_table.  */
-                 Lisp_Object string;
+             unsigned char *p = SDATA (string), *pend = p + SBYTES (string);
 
-                 string = tbase[g];
                  if (! STRING_MULTIBYTE (string))
                    string = string_to_multibyte (string);
-                 nbytes = buf - encode_terminal_buf;
-                 if (encode_terminal_bufsize < nbytes + SBYTES (string))
+             nbytes = buf - encode_terminal_src;
+             if (encode_terminal_src_size < nbytes + SBYTES (string))
                    {
-                     encode_terminal_bufsize = nbytes + SBYTES (string);
-                     encode_terminal_buf = xrealloc (encode_terminal_buf,
-                                                     encode_terminal_bufsize);
-                     buf = encode_terminal_buf + nbytes;
+                 encode_terminal_src_size = nbytes + SBYTES (string);
+                 encode_terminal_src = xrealloc (encode_terminal_src,
+                                                 encode_terminal_src_size);
+                 buf = encode_terminal_src + nbytes;
                    }
                  bcopy (SDATA (string), buf, SBYTES (string));
                  buf += SBYTES (string);
                  nchars += SCHARS (string);
                }
            }
-       }
       src++;
     }
 
-  nbytes = buf - encode_terminal_buf;
-  coding->src_multibyte = 1;
-  coding->dst_multibyte = 0;
-  if (SYMBOLP (coding->pre_write_conversion)
-      && ! NILP (Ffboundp (coding->pre_write_conversion)))
-    {
-      run_pre_write_conversin_on_c_str (&encode_terminal_buf,
-                                       &encode_terminal_bufsize,
-                                       nchars, nbytes, coding);
-      nchars = coding->produced_char;
-      nbytes = coding->produced;
-    }
-  required = nbytes + encoding_buffer_size (coding, nbytes);
-  if (encode_terminal_bufsize < required)
-    {
-      encode_terminal_bufsize = required;
-      encode_terminal_buf = xrealloc (encode_terminal_buf, required);
-    }
-
-  encode_coding (coding, encode_terminal_buf, encode_terminal_buf + nbytes,
-                nbytes, encode_terminal_bufsize - nbytes);
-  return encode_terminal_buf + nbytes;
+  if (nchars == 0)
+    {
+      coding->produced = 0;
+      return NULL;
+    }
+
+  nbytes = buf - encode_terminal_src;
+  coding->source = encode_terminal_src;
+  if (encode_terminal_dst_size == 0)
+    {
+      encode_terminal_dst_size = encode_terminal_src_size;
+      encode_terminal_dst = xmalloc (encode_terminal_dst_size);
+    }
+  coding->destination = encode_terminal_dst;
+  coding->dst_bytes = encode_terminal_dst_size;
+  encode_coding_object (coding, Qnil, 0, 0, nchars, nbytes, Qnil);
+  /* coding->destination may have been reallocated.  */
+  encode_terminal_dst = coding->destination;
+  encode_terminal_dst_size = coding->dst_bytes;
+
+  return (encode_terminal_dst);
 }
 
 
+
 /* An implementation of write_glyphs for termcap frames. */
 
 static void
@@ -1421,11 +1486,14 @@
 #ifdef static
 #define append_glyph append_glyph_term
 #define produce_stretch_glyph produce_stretch_glyph_term
+#define append_composite_glyph append_composite_glyph_term
+#define produce_composite_glyph produce_composite_glyph_term
 #endif
 
 static void append_glyph P_ ((struct it *));
 static void produce_stretch_glyph P_ ((struct it *));
-
+static void append_composite_glyph P_ ((struct it *));
+static void produce_composite_glyph P_ ((struct it *));
 
 /* Append glyphs to IT's glyph_row.  Called from produce_glyphs for
    terminal frames if IT->glyph_row != NULL.  IT->char_to_display is
@@ -1486,6 +1554,8 @@
      struct it *it;
 {
   /* If a hook is installed, let it do the work.  */
+
+  /* Nothing but characters are supported on terminal frames.  */
   xassert (it->what == IT_CHARACTER
           || it->what == IT_COMPOSITION
           || it->what == IT_STRETCH);
@@ -1496,11 +1566,11 @@
       goto done;
     }
 
-  /* Nothing but characters are supported on terminal frames.  For a
-     composition sequence, it->c is the first character of the
-     sequence.  */
-  xassert (it->what == IT_CHARACTER
-          || it->what == IT_COMPOSITION);
+  if (it->what == IT_COMPOSITION)
+    {
+      produce_composite_glyph (it);
+      goto done;
+    }
 
   /* Maybe translate single-byte characters to multibyte.  */
   it->char_to_display = it->c;
@@ -1544,28 +1614,24 @@
       it->pixel_width = nspaces;
       it->nglyphs = nspaces;
     }
-  else if (SINGLE_BYTE_CHAR_P (it->c))
+  else if (CHAR_BYTE8_P (it->c))
     {
       if (unibyte_display_via_language_environment
-         && (it->c >= 0240
-             || !NILP (Vnonascii_translation_table)))
+         && (it->c >= 0240))
        {
-         int charset;
-
          it->char_to_display = unibyte_char_to_multibyte (it->c);
-         charset = CHAR_CHARSET (it->char_to_display);
-         it->pixel_width = CHARSET_WIDTH (charset);
+         it->pixel_width = CHAR_WIDTH (it->char_to_display);
          it->nglyphs = it->pixel_width;
          if (it->glyph_row)
            append_glyph (it);
        }
       else
        {
-         /* Coming here means that it->c is from display table, thus we
-            must send the code as is to the terminal.  Although there's
-            no way to know how many columns it occupies on a screen, it
-            is a good assumption that a single byte code has 1-column
-            width.  */
+         /* Coming here means that it->c is from display table, thus
+            we must send the raw 8-bit byte as is to the terminal.
+            Although there's no way to know how many columns it
+            occupies on a screen, it is a good assumption that a
+            single byte code has 1-column width.  */
          it->pixel_width = it->nglyphs = 1;
          if (it->glyph_row)
            append_glyph (it);
@@ -1573,13 +1639,7 @@
     }
   else
     {
-      /* A multi-byte character.  The display width is fixed for all
-        characters of the set.  Some of the glyphs may have to be
-        ignored because they are already displayed in a continued
-        line.  */
-      int charset = CHAR_CHARSET (it->c);
-
-      it->pixel_width = CHARSET_WIDTH (charset);
+      it->pixel_width = CHAR_WIDTH (it->c);
       it->nglyphs = it->pixel_width;
 
       if (it->glyph_row)
@@ -1669,6 +1729,57 @@
 }
 
 
+/* Append glyphs to IT's glyph_row for the composition IT->cmp_id.
+   Called from produce_composite_glyph for terminal frames if
+   IT->glyph_row != NULL.  IT->face_id contains the character's
+   face.  */
+
+static void
+append_composite_glyph (it)
+     struct it *it;
+{
+  struct glyph *glyph;
+
+  xassert (it->glyph_row);
+  glyph = it->glyph_row->glyphs[it->area] + it->glyph_row->used[it->area];
+  if (glyph < it->glyph_row->glyphs[1 + it->area])
+    {
+      glyph->type = COMPOSITE_GLYPH;
+      glyph->pixel_width = it->pixel_width;
+      glyph->u.cmp_id = it->cmp_id;
+      glyph->face_id = it->face_id;
+      glyph->padding_p = 0;
+      glyph->charpos = CHARPOS (it->position);
+      glyph->object = it->object;
+
+      ++it->glyph_row->used[it->area];
+      ++glyph;
+    }
+}
+
+
+/* Produce a composite glyph for iterator IT.  IT->cmp_id is the ID of
+   the composition.  We simply produces components of the composition
+   assuming that that the terminal has a capability to layout/render
+   it correctly.  */
+
+static void
+produce_composite_glyph (it)
+     struct it *it;
+{
+  struct composition *cmp = composition_table[it->cmp_id];
+  int c;
+
+  xassert (cmp->glyph_len > 0);
+  c = COMPOSITION_GLYPH (cmp, 0);
+  it->pixel_width = CHAR_WIDTH (it->c);
+  it->nglyphs = 1;
+
+  if (it->glyph_row)
+    append_composite_glyph (it);
+}
+
+
 /* Get information about special display element WHAT in an
    environment described by IT.  WHAT is one of IT_TRUNCATION or
    IT_CONTINUATION.  Maybe produce glyphs for WHAT if IT has a
@@ -3270,7 +3381,8 @@
 
 #endif
 
-  encode_terminal_bufsize = 0;
+  encode_terminal_src_size = 0;
+  encode_terminal_dst_size = 0;
 
 #ifdef HAVE_GPM
   terminal->mouse_position_hook = term_mouse_position;




reply via email to

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