Print debug information to mdebug__output instead of stderr.
[m17n/m17n-lib.git] / src / face.c
index fc950ae..d2ebdb1 100644 (file)
@@ -1,5 +1,5 @@
 /* face.c -- face module.
-   Copyright (C) 2003, 2004
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H15PRO112
 
@@ -33,8 +33,8 @@
     #Mfoundry, #Mfamily, #Mweight, #Mstyle, #Mstretch, #Madstyle,
     #Msize, #Mfontset, #Mratio, #Mhook_func, #Mhook_arg
 
-    "The face property that belongs to face F and whose key is @c xxx"
-    may be shortened to "the xxx property of F".
+    The notation "xxx property of F" means the face property that
+    belongs to face F and whose key is @c Mxxx.
 
     The M-text drawing functions first search an M-text for the text
     property whose key is the symbol #Mface, then draw the M-text
@@ -702,15 +702,15 @@ mface__realize (MFrame *frame, MFace **faces, int num, int size, MFont *font)
                                                font);
       rfont = NULL;
       mfont__set_spec_from_face (&spec, &merged_face);
-      mfont_put_prop (&spec, Mregistry, Miso8859_1);
-      spec.source = MFONT_SOURCE_X;
+      mfont_put_prop (&spec, Mregistry, Municode_bmp);
+      spec.source = MFONT_SOURCE_FT;
       font = mfont__select (frame, &spec, 0);
       if (font)
        rfont = mfont__open (frame, font, &spec);
       if (! rfont)
        {
-         mfont_put_prop (&spec, Mregistry, Municode_bmp);
-         spec.source = MFONT_SOURCE_FT;
+         mfont_put_prop (&spec, Mregistry, Miso8859_1);
+         spec.source = MFONT_SOURCE_X;
          font = mfont__select (frame, &spec, 0);
          if (font)
            rfont = mfont__open (frame, font, &spec);
@@ -729,29 +729,32 @@ mface__realize (MFrame *frame, MFace **faces, int num, int size, MFont *font)
       rface->layouter = rfont->layouter;
       rfont->layouter = Mnil;
       work_gstring.glyphs[0].rface = rface;
-      work_gstring.glyphs[0].code = MCHAR_INVALID_CODE;
+      work_gstring.glyphs[0].g.code = MCHAR_INVALID_CODE;
+      work_gstring.glyphs[0].g.measured = 0;
       mfont__get_metric (&work_gstring, 0, 1);
-      rface->ascent = work_gstring.glyphs[0].ascent;
-      rface->descent = work_gstring.glyphs[0].descent;
-      work_gstring.glyphs[0].code
+      rface->ascent = work_gstring.glyphs[0].g.ascent;
+      rface->descent = work_gstring.glyphs[0].g.descent;
+      work_gstring.glyphs[0].g.code
        = mfont__encode_char (frame, (MFont *) rfont, NULL, ' ');
-      if (work_gstring.glyphs[0].code != MCHAR_INVALID_CODE)
+      if (work_gstring.glyphs[0].g.code != MCHAR_INVALID_CODE)
        {
+         work_gstring.glyphs[0].g.measured = 0;
          mfont__get_metric (&work_gstring, 0, 1);
-         rface->space_width = work_gstring.glyphs[0].width;
+         rface->space_width = work_gstring.glyphs[0].g.xadv;
        }
       else
        rface->space_width = rfont->spec.size / 10;
       if (rfont->average_width)
-       rface->average_width = rfont->average_width;
+       rface->average_width = rfont->average_width >> 6;
       else
        {
-         work_gstring.glyphs[0].code
+         work_gstring.glyphs[0].g.code
            = mfont__encode_char (frame, (MFont *) rfont, NULL, 'x');
-         if (work_gstring.glyphs[0].code != MCHAR_INVALID_CODE)
+         if (work_gstring.glyphs[0].g.code != MCHAR_INVALID_CODE)
            {
+             work_gstring.glyphs[0].g.measured = 0;
              mfont__get_metric (&work_gstring, 0, 1);
-             rface->average_width = work_gstring.glyphs[0].width;
+             rface->average_width = work_gstring.glyphs[0].g.xadv;
            }
          else
            rface->average_width = rface->space_width;
@@ -818,7 +821,7 @@ mface__for_chars (MSymbol script, MSymbol language, MSymbol charset,
       if (! rfont)
        {
          for (; from_g < to_g && from_g->rface->font; from_g++)
-           from_g->code = MCHAR_INVALID_CODE;
+           from_g->g.code = MCHAR_INVALID_CODE;
        }
       else
        {
@@ -833,28 +836,33 @@ mface__for_chars (MSymbol script, MSymbol language, MSymbol charset,
              new->layouter = rfont->layouter;
              rfont->layouter = Mnil;
              new->non_ascii_list = NULL;
-             new->ascent = rfont->ascent;
-             new->descent = rfont->descent;
+             new->ascent = rfont->ascent >> 6;
+             new->descent = rfont->descent >> 6;
            } 
          for (; from_g < to_g && from_g->rface->font; from_g++)
            {
              from_g->rface = new;
              if (new->layouter)
                {
-                 from_g->code = mfont__flt_encode_char (new->layouter, 
-                                                        from_g->c);
-                 if (from_g->code == MCHAR_INVALID_CODE)
+                 MFLT *flt = mflt_get (new->layouter);
+                 MCharTable *coverage;
+
+                 if (! flt
+                     || ((coverage = mflt_coverage (flt))
+                         && ! (from_g->g.code
+                               = (unsigned) mchartable_lookup (coverage,
+                                                               from_g->g.c))))
                    {
                      from_g->rface = rface;
-                     from_g->code = mfont__encode_char (rfont->frame, 
-                                                        (MFont *) rfont,
-                                                        NULL, from_g->c);
+                     from_g->g.code = mfont__encode_char (rfont->frame, 
+                                                          (MFont *) rfont,
+                                                          NULL, from_g->g.c);
                    }
                }
              else
-               from_g->code = mfont__encode_char (rfont->frame, 
-                                                  (MFont *) rfont,
-                                                  NULL, from_g->c);
+               from_g->g.code = mfont__encode_char (rfont->frame, 
+                                                    (MFont *) rfont,
+                                                    NULL, from_g->g.c);
            }
        }
       return from_g;
@@ -865,10 +873,10 @@ mface__for_chars (MSymbol script, MSymbol language, MSymbol charset,
       for (i = 0; i < num; i++)
        {
          unsigned code = mfont__encode_char (rfont->frame, (MFont *) rfont,
-                                             NULL, from_g[i].c);
+                                             NULL, from_g[i].g.c);
          if (code == MCHAR_INVALID_CODE)
            break;
-         from_g[i].code = code;
+         from_g[i].g.code = code;
        }
       if (i == num || from_g[i].rface->font)
        return from_g + i;
@@ -883,7 +891,7 @@ mface__for_chars (MSymbol script, MSymbol language, MSymbol charset,
     }
   else
     {
-      from_g->code = MCHAR_INVALID_CODE;
+      from_g->g.code = MCHAR_INVALID_CODE;
       num = 1;
       rfont = NULL;
       layouter = Mnil;
@@ -919,8 +927,8 @@ mface__for_chars (MSymbol script, MSymbol language, MSymbol charset,
              new->non_ascii_list = NULL;
              if (rfont)
                {
-                 new->ascent = rfont->ascent;
-                 new->descent = rfont->descent;
+                 new->ascent = rfont->ascent >> 6;
+                 new->descent = rfont->descent >> 6;
                }
            }
          while (g < from_g)
@@ -1015,13 +1023,13 @@ MSymbol Mbackground;
     @brief Key of a face property specifying video mode.
 
     The variable #Mvideomode is used as a key of face property.  The
-    property value must be #Mnormal, #Mreverse, or #Mnil.
+    property value must be @b Mnormal, @b Mreverse, or #Mnil.
 
-    #Mnormal means that an M-text is drawn in normal video mode
+    @b Mnormal means that an M-text is drawn in normal video mode
     (i.e. the foreground is drawn by foreground color, the background
     is drawn by background color).
 
-    #Mreverse means that an M-text is drawn in reverse video mode
+    @b Mreverse means that an M-text is drawn in reverse video mode
     (i.e. the foreground is drawn by background color, the background
     is drawn by foreground color).
 
@@ -1030,12 +1038,12 @@ MSymbol Mbackground;
     @brief ¥Ó¥Ç¥ª¥â¡¼¥É¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¡¼¤Î¥­¡¼.
 
     ÊÑ¿ô #Mvideomode ¤Ï¥Õ¥§¡¼¥¹¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢
-    #Mnormal, #Mreverse, #Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    @b Mnormal, @b Mreverse, #Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
 
-    #Mnormal ¤Î¾ì¹ç¤Ï¡¢M-text 
+    @b Mnormal ¤Î¾ì¹ç¤Ï¡¢M-text 
     ¤òɸ½à¤Î¥Ó¥Ç¥ª¥â¡¼¥É¡ÊÁ°·Ê¤òÁ°·Ê¿§¤Ç¡¢ÇطʤòÇØ·Ê¿§¤Ç¡Ë¤Çɽ¼¨¤¹¤ë¡£
 
-    #Mreverse ¤Î¾ì¹ç¤Ï¥ê¥Ð¡¼¥¹¥Ó¥Ç¥ª¥â¡¼¥É¤Ç¡ÊÁ°·Ê¤òÇØ·Ê¿§¤Ç¡¢ÇطʤòÁ°·Ê¿§¤Ç¡Ëɽ¼¨¤¹¤ë¡£
+    @b Mreverse ¤Î¾ì¹ç¤Ï¥ê¥Ð¡¼¥¹¥Ó¥Ç¥ª¥â¡¼¥É¤Ç¡ÊÁ°·Ê¤òÇØ·Ê¿§¤Ç¡¢ÇطʤòÁ°·Ê¿§¤Ç¡Ëɽ¼¨¤¹¤ë¡£
 
     #Mnil ¤Î¾ì¹ç¤Ï¥Ó¥Ç¥ª¥â¡¼¥É¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
     */
@@ -1168,7 +1176,6 @@ MSymbol Mhook_arg;
 /***en @name Variables: Possible values of #Mvideomode property of face */
 /***ja @name ÊÑ¿ô¡§  ¥Õ¥§¡¼¥¹¤Î #Mvideomode ¥×¥í¥Ñ¥Æ¥£¤Î²Äǽ¤ÊÃÍ */
 /*** @{ */
-/*=*/
 
 /***en
     See the documentation of the variable #Mvideomode.  */ 
@@ -1189,14 +1196,14 @@ MSymbol Mreverse;
     @brief Normal video face.
 
     The variable #mface_normal_video points to a face that has the
-    #Mvideomode property with value #Mnormal.  The other properties
+    #Mvideomode property with value @b Mnormal.  The other properties
     are not specified.  An M-text drawn with this face appear normal
     colors (i.e. the foreground is drawn by foreground color, and
     background is drawn by background color).  */
 /***ja
     @brief É¸½à¥Ó¥Ç¥ª¥Õ¥§¡¼¥¹.
 
-    ÊÑ¿ô #mface_normal_video ¤Ï #Mvideomode ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ #Mnormal 
+    ÊÑ¿ô #mface_normal_video ¤Ï #Mvideomode ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ @b Mnormal 
     ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
     ¤³¤Î¥Õ¥§¡¼¥¹¤Çɽ¼¨¤µ¤ì¤ëM-text 
     ¤Ïɸ½à¤Î¿§ (¤¹¤Ê¤ï¤ÁÁ°·Ê¤ÏÁ°·Ê¿§¡¢ÇطʤÏÇØ·Ê¿§¡Ë¤ÇÉÁ¤«¤ì¤ë¡£  */
@@ -1207,7 +1214,7 @@ MFace *mface_normal_video;
     @brief Reverse video face.
 
     The variable #mface_reverse_video points to a face that has the
-    #Mvideomode property with value #Mreverse.  The other properties
+    #Mvideomode property with value @b Mreverse.  The other properties
     are not specified.  An M-text drawn with this face appear in
     reversed colors (i.e. the foreground is drawn by background
     color, and background is drawn by foreground color).  */
@@ -1215,7 +1222,7 @@ MFace *mface_normal_video;
     @brief ¥ê¥Ð¡¼¥¹¥Ó¥Ç¥ª¥Õ¥§¡¼¥¹.
 
     ÊÑ¿ô #mface_reverse_video ¤Ï #Mvideomode ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬ 
-    #Mreverse ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
+    @b Mreverse ¤Ç¤¢¤ë¥Õ¥§¡¼¥¹¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£Â¾¤Î¥×¥í¥Ñ¥Æ¥£¤Ï»ØÄꤵ¤ì¤Ê¤¤¡£
     ¤³¤Î¥Õ¥§¡¼¥¹¤Çɽ¼¨¤µ¤ì¤ëM-text 
     ¤ÏÁ°·Ê¿§¤ÈÇØ·Ê¿§¤¬Æþ¤ìÂؤï¤Ã¤Æ (¤¹¤Ê¤ï¤ÁÁ°·Ê¤ÏÇØ·Ê¿§¡¢ÇطʤÏÁ°·Ê¿§¡ËÉÁ¤«¤ì¤ë¡£  */
 
@@ -1674,7 +1681,8 @@ mface_copy (MFace *face)
 
     The mface_equal () function compares faces $FACE1 and $FACE2.
 
-    @return If two faces have the same property values, return 1.
+    @return
+    If two faces have the same property values, return 1.
     Otherwise return 0.  */
 
 int
@@ -1844,7 +1852,7 @@ mface_get_prop (MFace *face, MSymbol key)
     {
       if (key == Mhook_func)
        /* This unsafe code is for backward compatiblity.  */
-       return *(void **) &face->hook;
+       return (void *) face->hook;
       MERROR (MERROR_FACE, NULL);
     }
   return face->property[index];
@@ -1858,6 +1866,11 @@ mface_get_prop (MFace *face, MSymbol key)
     The mface_get_hook () function returns the hook function of face
     $FACE.  */
 
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î¥Õ¥Ã¥¯´Ø¿ô¤òÆÀ¤ë.
+
+    ´Ø¿ô mface_get_hook () ¤Ï¥Õ¥§¡¼¥¹ $FACE ¤Î¥Õ¥Ã¥¯´Ø¿ô¤òÊÖ¤¹¡£ */
+
 MFaceHookFunc
 mface_get_hook (MFace *face)
 {
@@ -1924,9 +1937,9 @@ mface_put_prop (MFace *face, MSymbol key, void *val)
   if (key == Mhook_func)
     {
       /* This unsafe code is for backward compatiblity.  */
-      if (*(void **) &face->hook == val)
+      if (face->hook == (MFaceHookFunc) val)
        return 0;
-      *(void **) &face->hook = val;
+      face->hook = (MFaceHookFunc) val;
     }
   else
     {
@@ -1968,6 +1981,12 @@ mface_put_prop (MFace *face, MSymbol key, void *val)
     The mface_set_hook () function sets the hook function of face
     $FACE to $FUNC.  */
 
+/***ja
+    @brief ¥Õ¥§¡¼¥¹¤Î¥Õ¥Ã¥¯´Ø¿ô¤òÀßÄꤹ¤ë.
+
+    ´Ø¿ô mface_set_hook () ¤Ï¡¢¥Õ¥§¡¼¥¹ $FACE ¤Î¥Õ¥Ã¥¯´Ø¿ô¤ò$FUNC ¤ËÀß
+    Äꤹ¤ë¡£  */
+
 int
 mface_put_hook (MFace *face, MFaceHookFunc func)
 {
@@ -2032,9 +2051,10 @@ mface_update (MFrame *frame, MFace *face)
 /***en
     @brief Dump a face.
 
-    The mdebug_dump_face () function prints face $FACE in a human readable
-    way to the stderr.  $INDENT specifies how many columns to indent
-    the lines but the first one.
+    The mdebug_dump_face () function prints face $FACE in a human
+    readable way to the stderr or to what specified by the environment
+    variable MDEBUG_OUTPUT_FILE.  $INDENT specifies how many columns
+    to indent the lines but the first one.
 
     @return
     This function returns $FACE.  */
@@ -2042,8 +2062,9 @@ mface_update (MFrame *frame, MFace *face)
 /***ja
     @brief ¥Õ¥§¡¼¥¹¤ò¥À¥ó¥×¤¹¤ë.
 
-    ´Ø¿ô mdebug_dump_face () ¤Ï¥Õ¥§¡¼¥¹ $FACE ¤ò stderr 
-    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+    ´Ø¿ô mdebug_dump_face () ¤Ï¥Õ¥§¡¼¥¹ $FACE ¤òɸ½à¥¨¥é¡¼½ÐÎϤ⤷¤¯¤Ï
+    ´Ä¶­ÊÑ¿ô MDEBUG_DUMP_FONT ¤Ç»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õ
+    ºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
 
     @return
     ¤³¤Î´Ø¿ô¤Ï $FACE ¤òÊÖ¤¹¡£  */
@@ -2057,15 +2078,17 @@ mdebug_dump_face (MFace *face, int indent)
   memset (prefix, 32, indent);
   prefix[indent] = 0;
   mfont__set_spec_from_face (&spec, face);
-  fprintf (stderr, "(face font:\"");
+  fprintf (mdebug__output, "(face font:\"");
   mdebug_dump_font (&spec);
-  fprintf (stderr, "\"\n %s  fore:%s back:%s", prefix,
+  fprintf (mdebug__output, "\"\n %s  fore:%s back:%s", prefix,
           msymbol_name ((MSymbol) face->property[MFACE_FOREGROUND]),
           msymbol_name ((MSymbol) face->property[MFACE_BACKGROUND]));
   if (face->property[MFACE_FONTSET])
-    fprintf (stderr, " non-default-fontset");
-  fprintf (stderr, " hline:%s", face->property[MFACE_HLINE] ? "yes" : "no");
-  fprintf (stderr, " box:%s)", face->property[MFACE_BOX] ? "yes" : "no");
+    fprintf (mdebug__output, " non-default-fontset");
+  fprintf (mdebug__output, " hline:%s",
+          face->property[MFACE_HLINE] ? "yes" : "no");
+  fprintf (mdebug__output, " box:%s)",
+          face->property[MFACE_BOX] ? "yes" : "no");
   return face;
 }