Merge from emacs--devo--0
[bpt/emacs.git] / src / composite.c
index 17144f2..d44acf2 100644 (file)
@@ -1,8 +1,10 @@
 /* Composite sequence support.
-   Copyright (C) 1999 Electrotechnical Laboratory, JAPAN.
-     Licensed to the Free Software Foundation.
-   Copyright (C) 2001 Free Software Foundation, Inc.
-   Copyright (C) 2003
+   Copyright (C) 2001, 2002, 2003, 2004, 2005,
+                 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, 2006
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H13PRO009
 
@@ -20,8 +22,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #include <config.h>
 #include "lisp.h"
@@ -156,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
@@ -271,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;
@@ -304,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
@@ -312,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)
     {
@@ -332,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)
        {
@@ -342,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
@@ -628,8 +662,8 @@ DEFUN ("compose-region-internal", Fcompose_region_internal,
 Compose text in the region between START and END.
 Optional 3rd and 4th arguments are COMPONENTS and MODIFICATION-FUNC
 for the composition.  See `compose-region' for more detail.  */)
-     (start, end, components, mod_func)
-     Lisp_Object start, end, components, mod_func;
+     (start, end, components, modification_func)
+     Lisp_Object start, end, components, modification_func;
 {
   validate_region (&start, &end);
   if (!NILP (components)
@@ -638,7 +672,7 @@ for the composition.  See `compose-region' for more detail.  */)
       && !STRINGP (components))
     CHECK_VECTOR (components);
 
-  compose_text (XINT (start), XINT (end), components, mod_func, Qnil);
+  compose_text (XINT (start), XINT (end), components, modification_func, Qnil);
   return Qnil;
 }
 
@@ -649,8 +683,8 @@ DEFUN ("compose-string-internal", Fcompose_string_internal,
 Compose text between indices START and END of STRING.
 Optional 4th and 5th arguments are COMPONENTS and MODIFICATION-FUNC
 for the composition.  See `compose-string' for more detail.  */)
-     (string, start, end, components, mod_func)
-     Lisp_Object string, start, end, components, mod_func;
+     (string, start, end, components, modification_func)
+     Lisp_Object string, start, end, components, modification_func;
 {
   CHECK_STRING (string);
   CHECK_NUMBER (start);
@@ -661,7 +695,7 @@ for the composition.  See `compose-string' for more detail.  */)
       || XINT (end) > SCHARS (string))
     args_out_of_range (start, end);
 
-  compose_text (XINT (start), XINT (end), components, mod_func, string);
+  compose_text (XINT (start), XINT (end), components, modification_func, string);
   return string;
 }