*** empty log message ***
[m17n/m17n-lib.git] / src / m17n-gui.c
index f751e14..287988c 100644 (file)
@@ -79,8 +79,6 @@
 #include "fontset.h"
 #include "face.h"
 
-static int win_initialized;
-
 #ifndef DLOPEN_SHLIB_EXT
 #define DLOPEN_SHLIB_EXT ".so"
 #endif
@@ -96,7 +94,7 @@ typedef struct
   /** Function to call just after loading the library.  */
   int (*init) ();
   /** Function to call to open a frame on the graphic device.  */
-  void *(*open) (MFrame *frame, MPlist *param);
+  int (*open) (MFrame *frame, MPlist *param);
   /** Function to call just before unloading the library.  */
   int (*fini) ();
 } MDeviceLibraryInterface;
@@ -106,7 +104,6 @@ typedef struct
 
 static MPlist *device_library_list;
 
-
 /** Close MFrame and free it.  */
 
 static void
@@ -154,19 +151,19 @@ null_device_close (MFrame *frame)
 {
 }
 
-void *
+static void *
 null_device_get_prop (MFrame *frame, MSymbol key)
 {
   return NULL;
 }
 
-void
+static void
 null_device_realize_face (MRealizedFace *rface)
 {
   rface->info = NULL;
 }
 
-void
+static void
 null_device_free_realized_face (MRealizedFace *rface)
 {
 }
@@ -207,11 +204,12 @@ null_device_fini ()
   return 0;
 }
 
-static void *
+static int
 null_device_open (MFrame *frame, MPlist *param)
 {
   MFace *face;
 
+  frame->device = NULL;
   frame->device_type = 0;
   frame->driver = &null_driver;
   frame->font_driver_list = mplist ();
@@ -222,7 +220,7 @@ null_device_open (MFrame *frame, MPlist *param)
   face = mface_copy (mface__default);
   mplist_push (param, Mface, face);
   M17N_OBJECT_UNREF (face);
-  return &null_device;
+  return 0;
 }
 
 static MDeviceLibraryInterface null_interface =
@@ -232,8 +230,6 @@ static MDeviceLibraryInterface null_interface =
 \f
 /* Internal API */
 
-MSymbol Mfreetype;
-
 /*** @} */ 
 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
 
@@ -245,18 +241,19 @@ m17n_init_win (void)
 {
   int mdebug_mask = MDEBUG_INIT;
 
-  if (win_initialized++)
+  if (m17n__gui_initialized++)
     return;
   m17n_init ();
   if (merror_code != MERROR_NONE)
-    return;
+    {
+      m17n__gui_initialized--;
+      return;
+    }
 
   MDEBUG_PUSH_TIME ();
 
-  Mx = msymbol ("x");
   Mgd = msymbol ("gd");
 
-  Mfreetype = msymbol ("freetype");
   Mfont = msymbol ("font");
   Mfont_width = msymbol ("font-width");
   Mfont_ascent = msymbol ("font-ascent");
@@ -269,14 +266,10 @@ m17n_init_win (void)
   Mdepth = msymbol ("depth");
   Mwidget = msymbol ("widget");
 
-  register_device_library (Mx, "libm17n-X");
-  register_device_library (Mgd, "libm17n-gd");
-
   MDEBUG_PUSH_TIME ();
   if (mfont__init () < 0)
     goto err;
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize font module."));
-  MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize win module."));
   if (mfont__fontset_init () < 0)
     goto err;
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize fontset module."));
@@ -291,60 +284,59 @@ m17n_init_win (void)
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input-win module."));
   mframe_default = NULL;
 
+  register_device_library (Mx, "libm17n-X");
+  register_device_library (Mgd, "libm17n-gd");
+  return;
+
  err:
   MDEBUG_POP_TIME ();
   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the m17n GUI module."));
   MDEBUG_POP_TIME ();
-  return;
 }
 
 void
 m17n_fini_win (void)
 {
   int mdebug_mask = MDEBUG_FINI;
+  MPlist *plist;
 
-  if (win_initialized > 1)
-    win_initialized--;
-  else
+  if (m17n__gui_initialized == 0
+      || --m17n__gui_initialized > 0)
+    return;
+
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PUSH_TIME ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize device modules."));
+  MPLIST_DO (plist, device_library_list)
     {
-      MPlist *plist;
+      MDeviceLibraryInterface *interface = MPLIST_VAL (plist);
 
-      win_initialized = 0;
-      MDEBUG_PUSH_TIME ();
-      MDEBUG_PUSH_TIME ();
-      MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize device modules."));
-      MPLIST_DO (plist, device_library_list)
+      if (interface->handle && interface->fini)
        {
-         MDeviceLibraryInterface *interface = MPLIST_VAL (plist);
-
-         if (interface->handle && interface->fini)
-           {
-             (*interface->fini) ();
-             dlclose (interface->handle);
-           }
-         free (interface->library);
-         free (interface);
+         (*interface->fini) ();
+         dlclose (interface->handle);
        }
-      M17N_OBJECT_UNREF (device_library_list);
+      free (interface->library);
+    }
 #ifdef HAVE_FREETYPE
-      if (null_interface.handle)
-       (*null_interface.fini) ();
+  if (null_interface.handle)
+    (*null_interface.fini) ();
 #endif /* not HAVE_FREETYPE */
-      MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input-gui module."));
-      minput__win_fini ();
-      MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize draw module."));
-      mdraw__fini ();
-      MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize face module."));
-      mface__fini ();
-      MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize fontset module."));
-      mfont__fontset_fini ();
-      MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize font module."));
-      mfont__fini ();
-      mframe_default = NULL;
-      MDEBUG_POP_TIME ();
-      MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the gui modules."));
-      MDEBUG_POP_TIME ();
-    }
+  M17N_OBJECT_UNREF (device_library_list);
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input-gui module."));
+  minput__win_fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize draw module."));
+  mdraw__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize face module."));
+  mface__fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize fontset module."));
+  mfont__fontset_fini ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize font module."));
+  mfont__fini ();
+  mframe_default = NULL;
+  MDEBUG_POP_TIME ();
+  MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the gui modules."));
+  MDEBUG_POP_TIME ();
   m17n_fini ();
 }
 
@@ -388,7 +380,7 @@ m17n_fini_win (void)
 
 MSymbol Mdevice, Mdisplay, Mscreen, Mdrawable, Mdepth, Mcolormap, Mwidget; 
 
-MSymbol Mx, Mgd;
+MSymbol Mgd;
 
 /*=*/
 
@@ -454,7 +446,7 @@ MSymbol Mfont_descent;
 
     <ul>
 
-    <li> #Mdrawable, the value type must be <tt>Drawable</tt>
+    <li> #Mdrawable, the value type must be <tt>Drawable</tt>.
 
     A parameter of key #Mdisplay must also be specified.  The
     created frame can be used for drawables whose root window and
@@ -499,6 +491,19 @@ MSymbol Mfont_descent;
 
     The created frame uses the specified colormap.
 
+    <li> #Mfont, the value must be #Mx, #Mfreetype, or #Mxft.
+
+    The created frame uses the specified font backend.  The value #Mx
+    instructs to use X core fonts, #Mfreetype to use local fonts
+    supported by FreeType fonts, and #Mxft to use local fonts via Xft
+    library.  You can specify this parameter more than once with
+    different values if you want to use multiple font backends.  This
+    is ignored if the specified font backend is not supported on the
+    device.
+    
+    When this parameter is not specified, all font backend supported
+    on the device are used.
+
     </ul>
 
     @return
@@ -512,18 +517,37 @@ MSymbol Mfont_descent;
     $PLIST ¤Ï @c NULL ¤Ç¤âÎɤ¤¡£
 
     $PLIST ¤Ë¸½¤ï¤ì¤ë¥­¡¼¤Î¤¦¤Á¤É¤ì¤¬Ç§¼±¤µ¤ì¤ë¤«¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à
-    ¤Ë°Í¸¤¹¤ë¡£¤·¤«¤·°Ê²¼¤Î¥­¡¼¤Ï¾ï¤Ëǧ¼±¤µ¤ì¤ë¡£
+    ¤Ë°Í¸¤¹¤ë¡£
+
+    °Ê²¼¤Î¥­¡¼¤Ï¾ï¤Ëǧ¼±¤µ¤ì¤ë¡£
 
     <ul>
 
-    <li> #Mface. ÃͤϠ<tt>(MFace *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+    <li> #Mdevice. ÃͤϠ#Mx, #Mgd, #Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+
+    Ãͤ¬ #Mx ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥àÍѤǤ¢¤ë¡£¤³
+    ¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô #MDrawWindow ¤Ï¡¢ @c Window ·¿¤Ç¤Ê
+    ¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤È¤â¤Ë²Äǽ¤Ç¤¢¤ê¡¢¤¹¤Ù¤Æ¤ÎGUI ´Ø
+    ¿ô¤¬»ÈÍѤǤ­¤ë¡£
+
+    Ãͤ¬ #Mgd ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï GD ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¥ª¥Ö¥¸¥§
+    ¥¯¥ÈÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô #MDrawWindow ¤Ï¡¢ 
+    @c gdImagePtr ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤Ï½ñ¤­½Ð¤·ÀìÍѤǤ¢¤ê¡¢
+    minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
+
+    Ãͤ¬ #Mnil ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï, null ¥Ç¥Ð¥¤¥¹ÍѤǤ¢¤ë¡£¤³¤Î¥Õ
+    ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤Ç¤­¤Ê¤¤¤Î¤Ç¡¢°ú¿ô #MDrawWindow ¤òɬÍפȤ¹¤ëmdraw_ 
+    ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤ä¡¢minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
+
+    <li> #Mface. ÃͤϠ#MFace ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
 
     ¤³¤ÎÃͤϥե졼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
 
     </ul>
 
-    ¤³¤ì¤Ë²Ã¤¨¤Æ¡¢m17n-X ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï°Ê²¼¤Î¥­¡¼¤âǧ¼±¤¹¤ë¡£¤³¤ì¤é¤Ï
-    ¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¡¢¥Õ¥ì¡¼¥à¤ÇÍøÍѤǤ­¤ë drawable ¤Î¿¼¤µ¤ò»ØÄꤹ¤ë¡£
+    ¤³¤ì¤é¤Î¥­¡¼¤Ë²Ã¤¨¡¢#Mdevice ¤Î¥­¡¼¤¬ #Mx ¤Ç¤¢¤ë¾ì¹ç¤Ë¸Â¤ê°Ê²¼¤Î¥­¡¼
+    ¤âǧ¼±¤µ¤ì¤ë¡£°Ê²¼¤Î¥­¡¼¤Ï¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¡¢¥Õ¥ì¡¼¥à¤ÇÍøÍѤǤ­¤ë 
+    drawable ¤Î¿¼¤µ¤ò»ØÄꤹ¤ë¡£
 
     <ul>
 
@@ -568,6 +592,19 @@ MSymbol Mfont_descent;
 
     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥«¥é¡¼¥Þ¥Ã¥×¤ò»ÈÍѤ¹¤ë¡£
 
+    <li> #Mfont. Ãͤϡ¢#Mx, #Mfreetype, #Mxft ¤Î¤¤¤º¤ì¤«¡£
+
+    À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï»ØÄꤷ¤¿¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ¹¤ë¡£Ãͤ¬ 
+    #Mx ¤Ç¤¢¤ì¤Ð X ¤Î¥³¥¢¥Õ¥©¥ó¥È¡¢#Mfreetype ¤Ç¤¢¤ì¤Ð FreeType ¤Ç¥µ¥Ý¡¼
+    ¥È¤µ¤ì¤Æ¤¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¡¢#Mxft ¤Ç¤¢¤ì¤Ð Xft ¥é¥¤¥Ö¥é¥ê·Ðͳ¤Ç
+    ÍѤ¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¤ò»ÈÍѤ¹¤ë¡£Ê£¿ô¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍÑ
+    ¤·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤òÊ£¿ô²ó¡¢°Û¤Ê¤ëÃͤǻØÄꤹ¤ë¤³¤È¤¬¤Ç
+    ¤­¤ë¡£»ØÄꤷ¤¿¥Ð¥Ã¥¯¥¨¥ó¥É¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¥Ç¥Ð¥¤¥¹¤Ç¤Ï¡¢¤³¤Î
+    ¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
+
+    ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬Ìµ¤¤¾ì¹ç¤Ë¤Ï¡¢¥Ç¥Ð¥¤¥¹¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î
+    ¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤òÍøÍѤ¹¤ë¡£
+
     </ul>
 
     @return
@@ -605,7 +642,7 @@ mframe (MPlist *plist)
       if (! interface->handle)
        {
          (*interface->init) ();
-         interface->handle = Mt;
+         interface->handle = (void *) 1;
        }
 #else  /* not HAVE_FREETYPE */
       MERROR (MERROR_WIN, NULL);
@@ -618,23 +655,22 @@ mframe (MPlist *plist)
        MERROR (MERROR_WIN, NULL);
       if (! interface->handle)
        {
-         interface->handle = dlopen (interface->library, RTLD_NOW);
-         if (! interface->handle)
-           MERROR (MERROR_WIN, NULL);
-         interface->init = dlsym (interface->handle, "device_init");
-         interface->open = dlsym (interface->handle, "device_open");
-         interface->fini = dlsym (interface->handle, "device_fini");
-         if (! interface->init || ! interface->open || ! interface->fini
+         if (! (interface->handle = dlopen (interface->library, RTLD_NOW))
+             || ! (interface->init = dlsym (interface->handle, "device_init"))
+             || ! (interface->open = dlsym (interface->handle, "device_open"))
+             || ! (interface->fini = dlsym (interface->handle, "device_fini"))
              || (*interface->init) () < 0)
            {
-             dlclose (interface->handle);
+             fprintf (stderr, "%s\n", (char *) dlerror ());
+             if (interface->handle)
+               dlclose (interface->handle);
              MERROR (MERROR_WIN, NULL);
            }
        }
     }
 
   M17N_OBJECT (frame, free_frame, MERROR_FRAME);
-  if (! (frame->device = (*interface->open) (frame, plist)))
+  if ((*interface->open) (frame, plist) < 0)
     {
       free (frame);
       MERROR (MERROR_WIN, NULL);