(MDisplayInfo): New member altgr_mask.
[m17n/m17n-lib.git] / src / m17n-X.c
index acb0904..09f57ca 100644 (file)
@@ -1,5 +1,5 @@
 /* m17n-X.c -- implementation of the GUI API on X Windows.
-   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
 
@@ -84,6 +84,7 @@ typedef struct
   int alt_mask;
   int super_mask;
   int hyper_mask;
+  int altgr_mask;
 
   Atom MULE_BASELINE_OFFSET;
   Atom AVERAGE_WIDTH;
@@ -258,6 +259,9 @@ find_modifier_bits (MDisplayInfo *disp_info)
   KeyCode super_r = XKeysymToKeycode (display, XK_Super_R);
   KeyCode hyper_l = XKeysymToKeycode (display, XK_Hyper_L);
   KeyCode hyper_r = XKeysymToKeycode (display, XK_Hyper_R);
+#ifdef XK_XKB_KEYS
+  KeyCode altgr = XKeysymToKeycode (display, XK_ISO_Level3_Shift);
+#endif
   int i, j;
 
   mods = XGetModifierMapping (display);
@@ -278,6 +282,10 @@ find_modifier_bits (MDisplayInfo *disp_info)
          disp_info->super_mask |= (1 << i);
        else if (code == hyper_l || code == hyper_r)
          disp_info->hyper_mask |= (1 << i);
+#ifdef XK_XKB_KEYS
+       else if (code == altgr)
+         disp_info->altgr_mask |= (1 << i);
+#endif
       }
 
   /* If meta keys are not in any modifier, use alt keys as meta
@@ -657,12 +665,11 @@ xfont_open (MFrame *frame, MFont *font, MFont *spec, MRealizedFont *rfont)
       font->type = MFONT_TYPE_FAILURE;
       return NULL;
     }
-  MDEBUG_PRINT1 (" [XFONT] o %s\n", name);
-  free (name);
   M17N_OBJECT (x_rfont, close_xfont, MERROR_FONT_X);
   x_rfont->display = display;
   x_rfont->xfont = xfont;
   MSTRUCT_CALLOC (rfont, MERROR_FONT_X);
+  rfont->id = msymbol (name);
   rfont->spec = this;
   rfont->spec.type = MFONT_TYPE_REALIZED;
   rfont->spec.source = MFONT_SOURCE_X;
@@ -688,6 +695,8 @@ xfont_open (MFrame *frame, MFont *font, MFont *spec, MRealizedFont *rfont)
   rfont->fontp = xfont;
   rfont->next = MPLIST_VAL (frame->realized_font_list);
   MPLIST_VAL (frame->realized_font_list) = rfont;
+  MDEBUG_PRINT1 (" [XFONT] o %s\n", name);
+  free (name);
   return rfont;
 }
 
@@ -1055,11 +1064,19 @@ static int xft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
                          MFLTGlyphString *in, int from, int to,
                          MFLTGlyphString *out,
                          MFLTGlyphAdjustment *adjustment);
+static int xft_try_otf (MFLTFont *font, MFLTOtfSpec *spec,
+                       MFLTGlyphString *in, int from, int to);
+static int xft_iterate_otf_feature (struct _MFLTFont *font, MFLTOtfSpec *spec,
+                                   int from, int to, unsigned char *table);
+
 
 static MFontDriver xft_driver =
   { NULL, xft_open,
     xft_find_metric, xft_has_char, xft_encode_char, xft_render, NULL, NULL,
-    xft_check_capability, NULL, NULL, xft_check_otf, xft_drive_otf
+    xft_check_capability, NULL, NULL, xft_check_otf, xft_drive_otf, xft_try_otf,
+#ifdef HAVE_OTF
+    xft_iterate_otf_feature
+#endif /* HAVE_OTF */
   };
 
 static void
@@ -1156,6 +1173,7 @@ xft_open (MFrame *frame, MFont *font, MFont *spec, MRealizedFont *rfont)
   rfont_xft->info = rfont->info;
   M17N_OBJECT_REF (rfont->info);
   MSTRUCT_CALLOC (rfont, MERROR_FONT_X);
+  rfont->id = font->file;
   rfont->spec = *spec;
   rfont->spec.size = size;
   rfont->frame = frame;
@@ -1206,7 +1224,7 @@ xft_find_metric (MRealizedFont *rfont, MGlyphString *gstring,
            g->g.descent = (extents.height - extents.y) << 6;
          }
        g->g.yadv = 0;
-       g->g.measured = 0;
+       g->g.measured = 1;
       }
 }
 
@@ -1370,6 +1388,30 @@ xft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
   return result;
 }
 
+static int
+xft_try_otf (MFLTFont *font, MFLTOtfSpec *spec,
+            MFLTGlyphString *in, int from, int to)
+{
+  return xft_drive_otf (font, spec, in, from, to, NULL, NULL);
+}
+
+#ifdef HAVE_OTF
+
+static int
+xft_iterate_otf_feature (struct _MFLTFont *font, MFLTOtfSpec *spec,
+                        int from, int to, unsigned char *table)
+{
+  MRealizedFont *rfont = ((MFLTFontForRealized *) font)->rfont;
+  MRealizedFontXft *rfont_xft = rfont->info;
+  int result;
+      
+  rfont->info = rfont_xft->info;
+  result = mfont__ft_driver.iterate_otf_feature (font, spec, from, to, table);
+  rfont->info = rfont_xft;
+  return result;
+}
+#endif /* HAVE_OTF */
+
 #endif /* HAVE_XFT2 */
 
 \f
@@ -1983,6 +2025,10 @@ mwin__parse_event (MFrame *frame, void *arg, int *modifiers)
     return Mnil;
   if (keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
     return Mnil;
+#ifdef XK_XKB_KEYS
+  if ((keysym & 0xff00) == 0xfe00)
+    return Mnil;
+#endif
   if (len == 1 && keysym >= XK_space && keysym <= XK_asciitilde)
     {
       int c = keysym;
@@ -2011,7 +2057,10 @@ mwin__parse_event (MFrame *frame, void *arg, int *modifiers)
     *modifiers |= MINPUT_KEY_SUPER_MODIFIER;
   if (((XKeyEvent *) event)->state & disp_info->hyper_mask)
     *modifiers |= MINPUT_KEY_HYPER_MODIFIER;
-
+#ifdef XK_XKB_KEYS
+  if (((XKeyEvent *) event)->state & disp_info->altgr_mask)
+    *modifiers |= MINPUT_KEY_ALTGR_MODIFIER;
+#endif
   return key;
 }
 
@@ -2577,7 +2626,7 @@ xim_lookup (MInputContext *ic, MSymbol key, void *arg, MText *mt)
 /*** @addtogroup m17nInputMethodWin */
 
 /*** @{ */
-
+/*=*/
 /***en
     @brief Input method driver for XIM.
 
@@ -2635,9 +2684,9 @@ xim_lookup (MInputContext *ic, MSymbol key, void *arg, MText *mt)
 MInputDriver minput_xim_driver =
   { xim_open_im, xim_close_im, xim_create_ic, xim_destroy_ic,
     xim_filter, xim_lookup, NULL };
-
+/*=*/
 /*** @} */ 
-
+/*=*/
 #else  /* not HAVE_X11 */
 
 int device_open () { return -1; }