*** empty log message ***
[m17n/m17n-lib.git] / src / fontset.c
index fee964b..2f2ca55 100644 (file)
@@ -1,5 +1,5 @@
 /* fontset.c -- fontset 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
 
@@ -17,7 +17,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the m17n library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    02111-1307, USA.  */
 
 /***en
@@ -74,6 +74,8 @@
 #include "font.h"
 #include "fontset.h"
 
+static int mdebug_flag = MDEBUG_FONTSET;
+
 static M17NObjectArray fontset_table;
 
 struct MFontset
@@ -298,13 +300,15 @@ realize_fontset_elements (MFrame *frame, MRealizedFontset *realized)
 {
   MFontset *fontset = realized->fontset;
   MPlist *per_script, *per_charset, *font_group;
-  MPlist *plist, *pl, *p;
+  MPlist *plist, *p;
 
   realized->per_script = per_script = mplist ();
   /* The actual elements of per_script are realized on demand.  */
 #if 0
   MPLIST_DO (plist, fontset->per_script)
     {
+      MPlist *pl;
+
       per_lang = mplist ();
       per_script = mplist_add (per_script, MPLIST_KEY (plist), per_lang);
       MPLIST_DO (pl, MPLIST_PLIST (plist))
@@ -319,11 +323,11 @@ realize_fontset_elements (MFrame *frame, MRealizedFontset *realized)
 #endif
 
   realized->per_charset = per_charset = mplist ();
-  MPLIST_DO (pl, fontset->per_charset)
+  MPLIST_DO (plist, fontset->per_charset)
     {
       font_group = mplist ();
       per_charset = mplist_add (per_charset, MPLIST_KEY (plist), font_group);
-      MPLIST_DO (p, MPLIST_PLIST (pl))
+      MPLIST_DO (p, MPLIST_PLIST (plist))
        font_group = mplist_add (font_group, MPLIST_KEY (p), MPLIST_VAL (p));
     }
   realized->fallback = font_group = mplist ();
@@ -580,9 +584,15 @@ try_font_list (MFrame *frame, MFontList *font_list, MFont *request,
       /* Check if this font can display all glyphs.  */
       for (j = 0; j < *num; j++)
        {
-         int c = g[j].type == GLYPH_CHAR ? g[j].c : ' ';
+         int c = g[j].type == GLYPH_CHAR ? g[j].g.c : ' ';
+         MFLT *flt;
+         MCharTable *coverage;
+
          if (layouter != Mt
-             ? mfont__flt_encode_char (layouter, c) == MCHAR_INVALID_CODE
+             ? ((flt = mflt_get (layouter))
+                ? (coverage = mflt_coverage (flt),
+                   ! mchartable_lookup (coverage, c))
+                : 0)
              : ! mfont__has_char (frame, font, &font_list->object, c))
            break;
        }
@@ -590,6 +600,8 @@ try_font_list (MFrame *frame, MFontList *font_list, MFont *request,
        continue;
       if (j == *num || !all)
        {
+         MCharTable *coverage = NULL;
+
          /* We found a font that can display the requested range of
             glyphs.  */
          if (font->type == MFONT_TYPE_REALIZED)
@@ -602,15 +614,22 @@ try_font_list (MFrame *frame, MFontList *font_list, MFont *request,
              font_list->fonts[i].font = (MFont *) rfont;
            }
          rfont->layouter = layouter == Mt ? Mnil : layouter;
+         if (rfont->layouter)
+           {
+             MFLT *flt = mflt_get (rfont->layouter);
+
+             if (flt)
+               coverage = mflt_coverage (flt);
+           }
          *num = j;
          for (j = 0; j < *num; j++)
            {
-             int c = g[j].type == GLYPH_CHAR ? g[j].c : ' ';
+             int c = g[j].type == GLYPH_CHAR ? g[j].g.c : ' ';
 
-             g[j].code = (rfont->layouter
-                          ? mfont__flt_encode_char (rfont->layouter, c)
-                          : mfont__encode_char (frame, (MFont *) rfont,
-                                                &font_list->object, c));
+             g[j].g.code = (coverage
+                            ? (unsigned ) mchartable_lookup (coverage, c)
+                            : mfont__encode_char (frame, (MFont *) rfont,
+                                                  &font_list->object, c));
            }
          return rfont;
        }
@@ -735,6 +754,17 @@ mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
   MPlist *plist;
   MRealizedFont *rfont = NULL;
 
+  if (MDEBUG_FLAG ())
+    {
+      int i;
+
+      MDEBUG_PRINT1 (" [FONTSET] fontset looking up for %s:",
+                    script ? script->name : "none");
+      for (i = 0; i < *num; i++)
+       MDEBUG_PRINT1 (" U+%04X", g[i].g.c);
+      MDEBUG_PRINT ("\n");
+    }
+
   if (realized->tick != realized->fontset->tick)
     update_fontset_elements (realized);
 
@@ -742,17 +772,15 @@ mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
       && (per_charset = mplist_get (realized->per_charset, charset)) != NULL
       && (rfont = try_font_group (realized, &realized->request, per_charset,
                                  g, num, size)))
-    return rfont;
+    goto done;
 
   if (script != Mnil)
     {
       MFont request = realized->request;
 
       if (script != Mlatin)
-       /* These are not appropriate for non-Latin scripts.  */
-       request.property[MFONT_FOUNDRY]
-         = request.property[MFONT_FAMILY]
-         = request.property[MFONT_REGISTRY] = 0;
+       /* This is not appropriate for non-Latin scripts.  */
+       request.property[MFONT_REGISTRY] = 0;
 
       per_script = mplist_get (realized->per_script, script);
       if (! per_script)
@@ -773,9 +801,9 @@ mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
       if ((per_lang = mplist_get (per_script, language))
          && (rfont = try_font_group (realized, &request, per_lang,
                                      g, num, size)))
-       return rfont;
+       goto done;
 
-      if (per_lang)
+      if (per_lang && *num > 1)
        *num = 1;
       if (language == Mt)
        {
@@ -785,7 +813,7 @@ mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
                && (rfont = try_font_group (realized, &request,
                                            MPLIST_PLIST (plist),
                                            g, num, size)))
-             return rfont;
+             goto done;
        }
       else
        {
@@ -793,9 +821,9 @@ mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
          if ((per_lang = mplist_get (per_script, Mt))
              && (rfont = try_font_group (realized, &request, per_lang,
                                          g, num, size)))
-           return rfont;
+           goto done;
 
-         if (per_lang)
+         if (per_lang && *num > 1)
            *num = 1;
          /* Then try the above (3) */
          MPLIST_DO (plist, per_script)
@@ -804,10 +832,10 @@ mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
                && (rfont = try_font_group (realized, &request,
                                            MPLIST_PLIST (plist),
                                            g, num, size)))
-             return rfont;
+             goto done;
        }
       if (ignore_fallback)
-       return NULL;
+       goto done;
     }
 
   if (language != Mnil)
@@ -823,30 +851,25 @@ mfont__lookup_fontset (MRealizedFontset *realized, MGlyph *g, int *num,
        if ((per_lang = mplist_get (MPLIST_PLIST (plist), language))
            && (rfont = try_font_group (realized, &request, per_lang,
                                        g, num, size)))
-         return rfont;
+         goto done;
       }
 
   /* Try fallback fonts.  */
-  if ((rfont = try_font_group (realized, &realized->request,
-                              realized->fallback, g, num, size)))
-    return rfont;
-
-  return NULL;
-
-  /* At last try all fonts.  */
-  MPLIST_DO (per_script, realized->per_script)
+  rfont = try_font_group (realized, &realized->request,
+                         realized->fallback, g, num, size);
+ done:
+  if (MDEBUG_FLAG ())
     {
-      MPLIST_DO (per_lang, MPLIST_PLIST (per_script))
-       if ((rfont = try_font_group (realized, &realized->request,
-                                    MPLIST_PLIST (per_lang), g, num, size)))
-         return rfont;
+      if (rfont)
+       {
+         MSymbol family = mfont_get_prop (rfont->font, Mfamily);
+         MDEBUG_PRINT1 (" [FONTSET] found %s\n", family->name);
+       }
+      else
+       MDEBUG_PRINT (" [FONTSET] not found\n");
     }
-  MPLIST_DO (per_charset, realized->per_charset)
-    if ((rfont = try_font_group (realized, &realized->request,
-                                MPLIST_PLIST (per_charset), g, num, size)))
-      return rfont;
 
-  return NULL;
+  return rfont;
 }
 
 MRealizedFont *
@@ -1167,7 +1190,7 @@ mfontset_copy (MFontset *fontset, char *name)
     are removed from the group.
 
     If $LAYOUTER_NAME is not @c Mnil, it must be a symbol representing
-    a @ref flt (font layout table).  In that case, if $FONT is
+    a @ref mdbFLT (font layout table).  In that case, if $FONT is
     selected for drawing an M-text, that font layout table is used to
     generate a glyph code sequence from a character sequence.
 
@@ -1204,7 +1227,7 @@ mfontset_copy (MFontset *fontset, char *name)
     ¤¬Éé¤Ê¤é¤Ð¡¢ºÇÄã¤ÎÍ¥ÀèÅÙ¤ò»ý¤Ä¡£$HOW ¤¬ 0 ¤Ê¤é¤Ð¡¢$FONT 
     ¤Ï´ØÏ¢ÉÕ¤±¤é¤ì¤¿¤â¤Î¤ËÂФ¹¤ëÍ£°ì¤ÎÍøÍѲÄǽ¤Ê¥Õ¥©¥ó¥È¤È¤Ê¤ê¡¢Â¾¤Î¥Õ¥©¥ó¥È¤Ï¥°¥ë¡¼¥×¤«¤é¼è¤ê½ü¤«¤ì¤ë¡£
 
-    $LAYOUTER_NAME ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢@ref flt 
+    $LAYOUTER_NAME ¤Ï @c Mnil ¤Ç¤¢¤ë¤«¡¢@ref mdbFLT 
     ¡Ê¥Õ¥©¥ó¥È¥ì¥¤¥¢¥¦¥È¥Æ¡¼¥Ö¥ë¡Ë¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£¥·¥ó¥Ü¥ë¤Ç¤¢¤ì¤Ð¡¢$FONT ¤òÍѤ¤¤Æ
     M-text ¤òɽ¼¨¤¹¤ëºÝ¤Ë¤Ï¡¢¤½¤Î¥Õ¥©¥ó¥È¥ì¥¤¥¢¥¦¥È¥Æ¡¼¥Ö¥ë¤ò»È¤Ã¤Æʸ»úÎ󤫤饰¥ê¥Õ¥³¡¼¥ÉÎó¤òÀ¸À®¤¹¤ë¡£