(analyse_bidi_level): Adjust a type (FriBidiParType).
[m17n/m17n-lib.git] / src / draw.c
index c8bc8d5..bc302b1 100644 (file)
@@ -1,5 +1,5 @@
 /* draw.c -- drawing module.
 /* draw.c -- drawing module.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H15PRO112
 
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H15PRO112
 
@@ -109,7 +109,7 @@ analyse_bidi_level (MGlyphString *gstring)
   MGlyph *g;
   int i;
 #ifdef HAVE_FRIBIDI
   MGlyph *g;
   int i;
 #ifdef HAVE_FRIBIDI
-  FriBidiCharType base = bidi_sensitive ? FRIBIDI_TYPE_RTL : FRIBIDI_TYPE_LTR;
+  FriBidiParType base = bidi_sensitive ? FRIBIDI_TYPE_RTL : FRIBIDI_TYPE_LTR;
   FriBidiChar *logical = alloca (sizeof (FriBidiChar) * len);
   FriBidiLevel *levels;
   FriBidiStrIndex *indices;
   FriBidiChar *logical = alloca (sizeof (FriBidiChar) * len);
   FriBidiLevel *levels;
   FriBidiStrIndex *indices;
@@ -225,9 +225,10 @@ visual_order (MGlyphString *gstring)
   for (i = 1; i < gstring->used - 1; i++)
     {
       MGlyph *g = gstring->glyphs + i;
   for (i = 1; i < gstring->used - 1; i++)
     {
       MGlyph *g = gstring->glyphs + i;
+      int level = g->bidi_level;
 
       for (j = i; g->g.from == gstring->glyphs[j + 1].g.from; j++);
 
       for (j = i; g->g.from == gstring->glyphs[j + 1].g.from; j++);
-      if (j > i)
+      if ((level % 2) && j > i)
        {
          memcpy (glyphs + i, gstring->glyphs + i,
                  sizeof (MGlyph) * (j - i + 1));
        {
          memcpy (glyphs + i, gstring->glyphs + i,
                  sizeof (MGlyph) * (j - i + 1));
@@ -238,29 +239,11 @@ visual_order (MGlyphString *gstring)
     }
 }
 
     }
 }
 
-#if 0
-static void
-reorder_combining_chars (MGlyphString *gstring, int from, int to)
+static MSymbol
+font_id (MFLTFont *font)
 {
 {
-  MGlyph *g, *gbeg = MGLYPH (from + 1), *gend = MGLYPH (to), temp;
-  int reordered = 1;
-  
-  while (reordered)
-    {
-      reordered = 0;
-      for (g = gbeg; g != gend; g++)
-       if (COMBINING_CODE_CLASS (g->combining_code) > 0
-           && (COMBINING_CODE_CLASS (g[-1].combining_code)
-               > COMBINING_CODE_CLASS (g->combining_code)))
-         {
-           reordered = 1;
-           temp = *g;
-           *g = g[-1];
-           g[-1] = temp;
-         }
-    }
+  return ((MFLTFontForRealized *) font)->rfont->id;
 }
 }
-#endif
 
 static int
 run_flt (MGlyphString *gstring, int from, int to, MRealizedFace *rface)
 
 static int
 run_flt (MGlyphString *gstring, int from, int to, MRealizedFace *rface)
@@ -272,6 +255,7 @@ run_flt (MGlyphString *gstring, int from, int to, MRealizedFace *rface)
   MFLT *flt;
   int from_pos = MGLYPH (from)->g.from;
   int len = to - from;
   MFLT *flt;
   int from_pos = MGLYPH (from)->g.from;
   int len = to - from;
+  int catcode;
   int i;
 
   flt = mflt_get (layouter);
   int i;
 
   flt = mflt_get (layouter);
@@ -289,6 +273,9 @@ run_flt (MGlyphString *gstring, int from, int to, MRealizedFace *rface)
   font.font.drive_otf = rfont->driver->drive_otf;
   font.font.internal = NULL;
   font.rfont = rfont;
   font.font.drive_otf = rfont->driver->drive_otf;
   font.font.internal = NULL;
   font.rfont = rfont;
+  mflt_font_id = font_id;
+  mflt_iterate_otf_feature = rfont->driver->iterate_otf_feature;
+  mflt_try_otf = rfont->driver->try_otf;
   for (i = 0; i < 3; i++)
     {
       to = mflt_run (&flt_gstr, from, to, &font.font, flt);
   for (i = 0; i < 3; i++)
     {
       to = mflt_run (&flt_gstr, from, to, &font.font, flt);
@@ -300,7 +287,7 @@ run_flt (MGlyphString *gstring, int from, int to, MRealizedFace *rface)
     }
   if (from + len != to)
     gstring->used += to - (from + len);
     }
   if (from + len != to)
     gstring->used += to - (from + len);
-  for (i = from; i < to; i++)
+  for (i = from, catcode = -1; i < to; i++)
     {
       MGlyph *g = MGLYPH (i);
 
     {
       MGlyph *g = MGLYPH (i);
 
@@ -315,6 +302,17 @@ run_flt (MGlyphString *gstring, int from, int to, MRealizedFace *rface)
       g->g.xoff >>= 6;
       g->g.yoff >>= 6;
       g->rface = rface;
       g->g.xoff >>= 6;
       g->g.yoff >>= 6;
       g->rface = rface;
+      if (catcode < 0 || g->g.from != g[-1].g.from)
+       {
+         MSymbol category = mchar_get_prop (g->g.c, Mcategory);
+
+         catcode = (category == McatCf
+                    ? GLYPH_CATEGORY_FORMATTER
+                    : category != Mnil && MSYMBOL_NAME (category)[0] == 'M'
+                    ? GLYPH_CATEGORY_MODIFIER
+                    : GLYPH_CATEGORY_NORMAL);
+       }
+      g->category = catcode;
     }
   return to;
 }
     }
   return to;
 }
@@ -464,7 +462,7 @@ compose_glyph_string (MFrame *frame, MText *mt, int from, int to,
                {
                  MSymbol category = mchar_get_prop (g[-1].g.c, Mcategory);
 
                {
                  MSymbol category = mchar_get_prop (g[-1].g.c, Mcategory);
 
-                 if (MSYMBOL_NAME (category)[0] != 'Z')
+                 if (category != Mnil && MSYMBOL_NAME (category)[0] != 'Z')
                    this_script = script;
                }
            }
                    this_script = script;
                }
            }
@@ -486,6 +484,8 @@ compose_glyph_string (MFrame *frame, MText *mt, int from, int to,
                    break;
                  }
            }
                    break;
                  }
            }
+         if (this_script == Minherited || this_script == Mcommon)
+           this_script = (MSymbol) mchar_get_prop (c, Mblock);
        }
 
       pos = g->g.from;
        }
 
       pos = g->g.from;
@@ -549,7 +549,6 @@ compose_glyph_string (MFrame *frame, MText *mt, int from, int to,
 
              for (g++;
                   (g->type == GLYPH_CHAR
 
              for (g++;
                   (g->type == GLYPH_CHAR
-                   && g->g.from != gstring->control.cursor_pos
                    && g->rface->layouter == this->rface->layouter
                    && (g->rface->rfont == this->rface->rfont
                        || (g->category == GLYPH_CATEGORY_FORMATTER
                    && g->rface->layouter == this->rface->layouter
                    && (g->rface->rfont == this->rface->rfont
                        || (g->category == GLYPH_CATEGORY_FORMATTER
@@ -1516,6 +1515,7 @@ get_gstring (MFrame *frame, MText *mt, int pos, int to, MDrawControl *control)
              || memcmp (control, &gstring->control,
                         (char *) (&control->with_cursor)
                         - (char *) (control))
              || memcmp (control, &gstring->control,
                         (char *) (&control->with_cursor)
                         - (char *) (control))
+             || control->cursor_pos != gstring->control.cursor_pos
              || control->cursor_width != gstring->control.cursor_width
              || control->cursor_bidi != gstring->control.cursor_bidi)
            {
              || control->cursor_width != gstring->control.cursor_width
              || control->cursor_bidi != gstring->control.cursor_bidi)
            {
@@ -1749,7 +1749,11 @@ mdraw__init ()
   MbidiS = msymbol ("S");
   MbidiNSM = msymbol ("NSM");
 #ifdef HAVE_FRIBIDI
   MbidiS = msymbol ("S");
   MbidiNSM = msymbol ("NSM");
 #ifdef HAVE_FRIBIDI
+#if FRIBIDI_INTERFACE_VERSION < 3
   fribidi_set_mirroring (TRUE);
   fribidi_set_mirroring (TRUE);
+#else
+  fribidi_set_mirroring (1);
+#endif
 #endif
 
   M_break_at_space = msymbol ("bs");
 #endif
 
   M_break_at_space = msymbol ("bs");
@@ -1758,6 +1762,8 @@ mdraw__init ()
   M_kinsoku_bol = msymbol ("kb");
   M_kinsoku_eol = msymbol ("ke");
 
   M_kinsoku_bol = msymbol ("kb");
   M_kinsoku_eol = msymbol ("ke");
 
+  mflt_enable_new_feature = 1;
+
   return 0;
 }
 
   return 0;
 }
 
@@ -1964,7 +1970,7 @@ mdraw_text (MFrame *frame, MDrawWindow win, int x, int y,
 
     @return
     ½èÍý¤¬À®¸ù¤·¤¿¾ì¹ç¡¢mdraw_image_text () ¤Ï 0 
 
     @return
     ½èÍý¤¬À®¸ù¤·¤¿¾ì¹ç¡¢mdraw_image_text () ¤Ï 0 
-    ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #m_errro ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
+    ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
 
     @latexonly \IPAlabel{mdraw_image_text} @endlatexonly   */
 
 
     @latexonly \IPAlabel{mdraw_image_text} @endlatexonly   */
 
@@ -2000,7 +2006,7 @@ mdraw_image_text (MFrame *frame, MDrawWindow win, int x, int y,
     this function also follows what specified in the drawing control
     object $CONTROL.
 
     this function also follows what specified in the drawing control
     object $CONTROL.
 
-    For instance, if <two_dimensional> of $CONTROL is nonzero, this
+    For instance, if \<two_dimensional\> of $CONTROL is nonzero, this
     function draw an M-text 2-dimensionally, i.e., newlines in M-text
     breaks lines and the following characters are drawn in the next
     line.  See the documentation of the structure @ MDrawControl for
     function draw an M-text 2-dimensionally, i.e., newlines in M-text
     breaks lines and the following characters are drawn in the next
     line.  See the documentation of the structure @ MDrawControl for
@@ -2016,7 +2022,7 @@ mdraw_image_text (MFrame *frame, MDrawWindow win, int x, int y,
     ¥Æ¥­¥¹¥È¤ÎÉÁ²èÊýË¡¤Ï mdraw_text () ¤È¤Û¤ÜƱ¤¸¤Ç¤¢¤ë¤¬¡¢¤³¤Î´Ø¿ô¤ÏÉÁ²èÀ©¸æÍѤΥª¥Ö¥¸¥§¥¯¥È
     $CONTROL ¤Î»Ø¼¨¤Ë¤â½¾¤¦ÅÀ¤¬°Û¤Ê¤Ã¤Æ¤¤¤ë¡£
 
     ¥Æ¥­¥¹¥È¤ÎÉÁ²èÊýË¡¤Ï mdraw_text () ¤È¤Û¤ÜƱ¤¸¤Ç¤¢¤ë¤¬¡¢¤³¤Î´Ø¿ô¤ÏÉÁ²èÀ©¸æÍѤΥª¥Ö¥¸¥§¥¯¥È
     $CONTROL ¤Î»Ø¼¨¤Ë¤â½¾¤¦ÅÀ¤¬°Û¤Ê¤Ã¤Æ¤¤¤ë¡£
 
-    ¤¿¤È¤¨¤Ð $CONTROL ¤Î <two_dimensional> ¤¬¥¼¥í¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï 
+    ¤¿¤È¤¨¤Ð $CONTROL ¤Î \<two_dimensional\> ¤¬¥¼¥í¤Ç¤Ê¤±¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï 
     M-text ¤ò2¼¡¸µÅª¤ËÉÁ¤¯¡£¤¹¤Ê¤ï¤Á M-text Ãæ¤Î²þ¹Ô¤Ç¹Ô¤ò²þ¤á¡¢Â³¤¯Ê¸»ú¤Ï¼¡¤Î¹Ô¤ËÉÁ¤¯¡£¾ÜºÙ¤Ï¹½Â¤ÂÎ
     @ MDrawControl ¤ÎÀâÌÀ¤ò»²¾È¤¹¤ë¤³¤È¡£*/
 
     M-text ¤ò2¼¡¸µÅª¤ËÉÁ¤¯¡£¤¹¤Ê¤ï¤Á M-text Ãæ¤Î²þ¹Ô¤Ç¹Ô¤ò²þ¤á¡¢Â³¤¯Ê¸»ú¤Ï¼¡¤Î¹Ô¤ËÉÁ¤¯¡£¾ÜºÙ¤Ï¹½Â¤ÂÎ
     @ MDrawControl ¤ÎÀâÌÀ¤ò»²¾È¤¹¤ë¤³¤È¡£*/
 
@@ -2832,7 +2838,8 @@ int mdraw_line_break_option;
     character, and incremented each time when a long line is broken
     because of the width limit.
 
     character, and incremented each time when a long line is broken
     because of the width limit.
 
-    @return This function returns a character position to break the
+    @return 
+    This function returns a character position to break the
     line.
 */
 
     line.
 */