changeset 91267:0fa5916e5871

(Ffont_shape_text): Avoid unnecessary composition.
author Kenichi Handa <handa@m17n.org>
date Fri, 21 Dec 2007 01:38:14 +0000
parents 3cd59392b3ec
children 7c927e348881
files src/font.c
diffstat 1 files changed, 26 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/font.c	Fri Dec 21 01:37:31 2007 +0000
+++ b/src/font.c	Fri Dec 21 01:38:14 2007 +0000
@@ -3581,13 +3581,18 @@
       EMACS_INT this_from = LGLYPH_FROM (g);
       EMACS_INT this_to = LGLYPH_TO (g) + 1;
       int j, k;
+      int need_composition = 0;
 
       metrics.lbearing = LGLYPH_LBEARING (g);
       metrics.rbearing = LGLYPH_RBEARING (g);
       metrics.ascent = LGLYPH_ASCENT (g);
       metrics.descent = LGLYPH_DESCENT (g);
       if (NILP (LGLYPH_ADJUSTMENT (g)))
-	metrics.width = LGLYPH_WIDTH (g);
+	{
+	  metrics.width = LGLYPH_WIDTH (g);
+	  if (XINT (LGLYPH_CHAR (g)) == 0 || metrics.width == 0)
+	    need_composition = 1;
+	}
       else
 	{
 	  metrics.width = LGLYPH_WADJUST (g);
@@ -3595,6 +3600,7 @@
 	  metrics.rbearing += LGLYPH_XOFF (g);
 	  metrics.ascent -= LGLYPH_YOFF (g);
 	  metrics.descent += LGLYPH_YOFF (g);
+	  need_composition = 1;
 	}
       for (j = i + 1; j < XINT (n); j++)
 	{
@@ -3603,6 +3609,7 @@
 	  g = LGSTRING_GLYPH (gstring, j);
 	  if (this_from != LGLYPH_FROM (g))
 	    break;
+	  need_composition = 1;
 	  x = metrics.width + LGLYPH_LBEARING (g) + LGLYPH_XOFF (g);
 	  if (metrics.lbearing > x)
 	    metrics.lbearing = x;
@@ -3621,20 +3628,25 @@
 	    metrics.width += LGLYPH_WADJUST (g);
 	}
 
-      gstr = Ffont_make_gstring (font_object, make_number (j - i));
-      LGSTRING_SET_WIDTH (gstr, metrics.width);
-      LGSTRING_SET_LBEARING (gstr, metrics.lbearing);
-      LGSTRING_SET_RBEARING (gstr, metrics.rbearing);
-      LGSTRING_SET_ASCENT (gstr, metrics.ascent);
-      LGSTRING_SET_DESCENT (gstr, metrics.descent);
-      for (k = i; i < j; i++)
-	LGSTRING_SET_GLYPH (gstr, i - k, LGSTRING_GLYPH (gstring, i));
-      from = make_number (start + this_from);
-      to = make_number (start + this_to);
-      if (NILP (string))
-	Fcompose_region_internal (from, to, gstr, Qnil);
+      if (need_composition)
+	{
+	  gstr = Ffont_make_gstring (font_object, make_number (j - i));
+	  LGSTRING_SET_WIDTH (gstr, metrics.width);
+	  LGSTRING_SET_LBEARING (gstr, metrics.lbearing);
+	  LGSTRING_SET_RBEARING (gstr, metrics.rbearing);
+	  LGSTRING_SET_ASCENT (gstr, metrics.ascent);
+	  LGSTRING_SET_DESCENT (gstr, metrics.descent);
+	  for (k = i; i < j; i++)
+	    LGSTRING_SET_GLYPH (gstr, i - k, LGSTRING_GLYPH (gstring, i));
+	  from = make_number (start + this_from);
+	  to = make_number (start + this_to);
+	  if (NILP (string))
+	    Fcompose_region_internal (from, to, gstr, Qnil);
+	  else
+	    Fcompose_string_internal (string, from, to, gstr, Qnil);
+	}
       else
-	Fcompose_string_internal (string, from, to, gstr, Qnil);
+	i = j;
     }
 
   return to;