Merge from emacs--devo--0
[bpt/emacs.git] / src / composite.c
index a17a52b..8e6a8e3 100644 (file)
@@ -1,10 +1,10 @@
 /* Composite sequence support.
    Copyright (C) 2001, 2002, 2003, 2004, 2005,
-                 2006 Free Software Foundation, Inc.
-   Copyright (C) 1999
+                 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H14PRO021
-   Copyright (C) 2003
+   Copyright (C) 2003, 2006
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H13PRO009
 
@@ -12,7 +12,7 @@ This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -158,6 +158,8 @@ EXFUN (Fremove_list_of_text_properties, 4);
 
 /* Temporary variable used in macros COMPOSITION_XXX.  */
 Lisp_Object composition_temp;
+
+extern int enable_font_backend;
 \f
 /* Return COMPOSITION-ID of a composition at buffer position
    CHARPOS/BYTEPOS and length NCHARS.  The `composition' property of
@@ -273,6 +275,22 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
   /* Check if the contents of COMPONENTS are valid if COMPONENTS is a
      vector or a list.  It should be a sequence of:
        char1 rule1 char2 rule2 char3 ...    ruleN charN+1  */
+
+#ifdef USE_FONT_BACKEND
+  if (enable_font_backend
+      && VECTORP (components)
+      && ASIZE (components) >= 2
+      && VECTORP (AREF (components, 0)))
+    {
+      /* COMPONENTS is a glyph-string.  */
+      int len = ASIZE (key);
+
+      for (i = 1; i < len; i++)
+       if (! VECTORP (AREF (key, i)))
+         goto invalid_composition;
+    }
+  else
+#endif  /* USE_FONT_BACKEND */
   if (VECTORP (components) || CONSP (components))
     {
       int len = XVECTOR (key)->size;
@@ -306,6 +324,12 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
                 : ((INTEGERP (components) || STRINGP (components))
                    ? COMPOSITION_WITH_ALTCHARS
                    : COMPOSITION_WITH_RULE_ALTCHARS));
+#ifdef USE_FONT_BACKEND
+  if (cmp->method == COMPOSITION_WITH_RULE_ALTCHARS
+      && VECTORP (components)
+      && ! INTEGERP (AREF (components, 0)))
+    cmp->method = COMPOSITION_WITH_GLYPH_STRING;
+#endif  /* USE_FONT_BACKEND */
   cmp->hash_index = hash_index;
   glyph_len = (cmp->method == COMPOSITION_WITH_RULE_ALTCHARS
               ? (XVECTOR (key)->size + 1) / 2
@@ -314,6 +338,14 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
   cmp->offsets = (short *) xmalloc (sizeof (short) * glyph_len * 2);
   cmp->font = NULL;
 
+#ifdef USE_FONT_BACKEND
+  if (cmp->method == COMPOSITION_WITH_GLYPH_STRING)
+    {
+      cmp->width = 1;          /* Should be fixed later.  */
+      cmp->glyph_len--;
+    }
+  else
+#endif /* USE_FONT_BACKEND */
   /* Calculate the width of overall glyphs of the composition.  */
   if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS)
     {
@@ -334,7 +366,7 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
       float leftmost = 0.0, rightmost;
 
       ch = XINT (key_contents[0]);
-      rightmost = CHAR_WIDTH (ch);
+      rightmost = ch != '\t' ? CHAR_WIDTH (ch) : 1;
 
       for (i = 1; i < glyph_len; i += 2)
        {
@@ -344,7 +376,7 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
 
          rule = XINT (key_contents[i]);
          ch = XINT (key_contents[i + 1]);
-         this_width = CHAR_WIDTH (ch);
+         this_width = ch != '\t' ? CHAR_WIDTH (ch) : 1;
 
          /* A composition rule is specified by an integer value
             that encodes global and new reference points (GREF and
@@ -505,7 +537,8 @@ update_compositions (from, to, check_mask)
         avoid it, in such a case, we change the property of the
         latter to the copy of it.  */
       if (from > BEGV
-         && find_composition (from - 1, -1, &start, &end, &prop, Qnil))
+         && find_composition (from - 1, -1, &start, &end, &prop, Qnil)
+         && COMPOSITION_VALID_P (start, end, prop))
        {
          min_pos = start;
          if (end > to)
@@ -518,7 +551,8 @@ update_compositions (from, to, check_mask)
          from = end;
        }
       else if (from < ZV
-              && find_composition (from, -1, &start, &from, &prop, Qnil))
+              && find_composition (from, -1, &start, &from, &prop, Qnil)
+              && COMPOSITION_VALID_P (start, from, prop))
        {
          if (from > to)
            max_pos = from;
@@ -533,6 +567,7 @@ update_compositions (from, to, check_mask)
          (to - 1).  */
       while (from < to - 1
             && find_composition (from, to, &start, &from, &prop, Qnil)
+            && COMPOSITION_VALID_P (start, from, prop)
             && from < to - 1)
        run_composition_function (start, from, prop);
     }
@@ -540,7 +575,8 @@ update_compositions (from, to, check_mask)
   if (check_mask & CHECK_TAIL)
     {
       if (from < to
-         && find_composition (to - 1, -1, &start, &end, &prop, Qnil))
+         && find_composition (to - 1, -1, &start, &end, &prop, Qnil)
+         && COMPOSITION_VALID_P (start, end, prop))
        {
          /* TO should be also at composition boundary.  But,
             insertion or deletion will make two compositions adjacent
@@ -557,7 +593,8 @@ update_compositions (from, to, check_mask)
          run_composition_function (start, end, prop);
        }
       else if (to < ZV
-              && find_composition (to, -1, &start, &end, &prop, Qnil))
+              && find_composition (to, -1, &start, &end, &prop, Qnil)
+              && COMPOSITION_VALID_P (start, end, prop))
        {
          run_composition_function (start, end, prop);
          max_pos = end;