*** empty log message ***
[m17n/m17n-lib.git] / src / m17n-X.c
index c821e72..6bb05a0 100644 (file)
@@ -810,12 +810,12 @@ xfont_encode_char (MRealizedFont *rfont, int c, unsigned code)
   unsigned min_byte1, max_byte1, min_byte2, max_byte2;
   int all_chars_exist;
 
-  if (rfont->status < 0)
-    return -1;
+  if (rfont->status < 0 || code >= 0x10000)
+    return MCHAR_INVALID_CODE;
   if (rfont->status == 0)
     {
       if (xfont_open (rfont) < 0)
-       return -1;
+       return MCHAR_INVALID_CODE;
     }
   xfont = (MXFontInfo *) rfont->info;
   f = xfont->f;
@@ -829,9 +829,10 @@ xfont_encode_char (MRealizedFont *rfont, int c, unsigned code)
     {
       XCharStruct *pcm;
 
+      if (code < min_byte2 || code > max_byte2)
+       return MCHAR_INVALID_CODE;
       if (all_chars_exist)
-       return ((code >= min_byte2 && code <= max_byte2)
-               ? code : MCHAR_INVALID_CODE);
+       return code;
       pcm = f->per_char + (code - min_byte2);
       return ((pcm->width > 0 || pcm->rbearing != pcm->lbearing)
              ? code : MCHAR_INVALID_CODE);
@@ -841,10 +842,12 @@ xfont_encode_char (MRealizedFont *rfont, int c, unsigned code)
       unsigned byte1 = code >> 8, byte2 = code & 0xFF;
       XCharStruct *pcm;
 
+      if (byte1 < min_byte1 || byte1 > max_byte1
+         || byte2 < min_byte2 || byte2 > max_byte2)
+       return MCHAR_INVALID_CODE;
+
       if (all_chars_exist)
-       return ((byte1 >= min_byte1 && byte1 <= max_byte1
-                && byte2 >= min_byte2 && byte2 <= max_byte2)
-               ? code : MCHAR_INVALID_CODE);
+       return code;
       pcm = f->per_char + ((byte1 - min_byte1) * (max_byte2 - min_byte2 + 1)
                           + (byte2 - min_byte2));
       return ((pcm->width > 0 || pcm->rbearing != pcm->lbearing)
@@ -885,9 +888,7 @@ xfont_render (MDrawWindow win, int x, int y, MGlyphString *gstring,
 
   if (region)
     gc = set_region (rface->frame, gc, region);
-  XSetFont (display, gc, ((MXFontInfo *) (rface->rfont->info))->f->fid);
-
-  if (from->code == MCHAR_INVALID_CODE)
+  if (! rface->rfont || from->code == MCHAR_INVALID_CODE)
     {
       int x0 = x;
 
@@ -901,6 +902,7 @@ xfont_render (MDrawWindow win, int x, int y, MGlyphString *gstring,
       return;
     }
 
+  XSetFont (display, gc, ((MXFontInfo *) (rface->rfont->info))->f->fid);
   code = (XChar2b *) alloca (sizeof (XChar2b) * (to - from));
   for (i = 0, g = from; g < to; i++, g++)
     {
@@ -1846,14 +1848,16 @@ mwin__create_window (MFrame *frame, MDrawWindow parent)
   Window win;
   XWMHints wm_hints = { InputHint, False };
   XClassHint class_hints = { "M17N-IM", "m17n-im" };
-  XWindowAttributes win_attrs;
   XSetWindowAttributes set_attrs;
   unsigned long mask;
+  XGCValues values;
+  GCInfo *info = frame->rface->info;
 
   if (! parent)
     parent = (MDrawWindow) RootWindow (display, FRAME_SCREEN (frame));
-  XGetWindowAttributes (display, (Window) parent, &win_attrs);
-  set_attrs.background_pixel = win_attrs.backing_pixel;
+  mask = GCForeground;
+  XGetGCValues (display, info->gc[GC_INVERSE], mask, &values);
+  set_attrs.background_pixel = values.foreground;
   set_attrs.backing_store = Always;
   set_attrs.override_redirect = True;
   set_attrs.save_under = True;
@@ -2008,6 +2012,7 @@ mwin__adjust_window (MFrame *frame, MDrawWindow win,
     }
   if (mask)
     XConfigureWindow (display, (Window) win, mask, &values);
+  XClearWindow (display, (Window) win);
 }
 
 MSymbol
@@ -2155,7 +2160,7 @@ MSymbol Mdisplay, Mscreen, Mdrawable, Mdepth, Mwidget, Mcolormap;
     same one as that of the function minput_filter ().  The argument
     $KEY is ignored.  */
 
-/***ja
+/***oldja
     @brief XIMÍÑÆþÎϥɥ饤¥Ð
 
     ÆþÎϥɥ饤¥Ð #minput_xim_driver ¤Ï #Mxim ¤ò̾Á°¤È¤·¤Æ»ý¤Ä³°Éô