*** empty log message ***
[m17n/m17n-lib.git] / src / draw.c
index 671acc8..c65da26 100644 (file)
@@ -1,5 +1,5 @@
 /* draw.c -- drawing module.
-   Copyright (C) 2003, 2004
+   Copyright (C) 2003, 2004, 2005, 2006
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H15PRO112
 
@@ -440,7 +440,11 @@ compose_glyph_string (MFrame *frame, MText *mt, int from, int to,
                                                   NULL, prev->c)
                        != MCHAR_INVALID_CODE));
                   start--, prev--)
-               prev->code = code;
+               if (prev->rface->rfont != this->rface->rfont)
+                 {
+                   prev->rface->rfont = this->rface->rfont;
+                   prev->code = code;
+                 }
 
              for (g++;
                   (g->type == GLYPH_CHAR
@@ -601,7 +605,10 @@ layout_glyphs (MFrame *frame, MGlyphString *gstring, int from, int to,
          if (base->left_padding && base->lbearing < 0)
            {
              base->xoff = - base->lbearing;
-             base->width += base->xoff;
+             if (base->rbearing < 0)
+               base->width = base->rbearing - base->lbearing;
+             else
+               base->width += base->xoff;
              base->rbearing += base->xoff;
              base->lbearing = 0;
            }
@@ -609,9 +616,8 @@ layout_glyphs (MFrame *frame, MGlyphString *gstring, int from, int to,
            {
              base->width = base->rbearing;
            }
-         lbearing = (base->xoff + base->lbearing < 0
-                     ? base->xoff + base->lbearing : 0);
-         rbearing = base->xoff + base->rbearing;
+         lbearing = base->lbearing;
+         rbearing = base->rbearing;
        }
       else
        {
@@ -713,6 +719,12 @@ layout_glyphs (MFrame *frame, MGlyphString *gstring, int from, int to,
              base[i].pos = begin;
              base[i].to = end;
            }
+         if (base->left_padding && lbearing < 0)
+           {
+             base->xoff -= lbearing;
+             base->width -= lbearing;
+             lbearing = 0;
+           }
        }
 
       g_physical_ascent = MAX (g_physical_ascent, base->ascent);
@@ -1572,9 +1584,15 @@ truncate_gstring (MFrame *frame, MText *mt, MGlyphString *gstring)
        pos = gstring->to;
     }
   else if (i == 0)
-    pos++;
-  compose_glyph_string (frame, mt, gstring->from, pos, gstring);
-  layout_glyph_string (frame, gstring);
+    {
+      g = find_glyph_in_gstring (gstring, gstring->from, 1);
+      pos = g->to;
+    }
+  if (pos < gstring->to)
+    {
+      compose_glyph_string (frame, mt, gstring->from, pos, gstring);
+      layout_glyph_string (frame, gstring);
+    }
 }