Index: kit/CHANGELOG
diff -u kit/CHANGELOG:1.9 kit/CHANGELOG:removed
--- kit/CHANGELOG:1.9	Sat Sep  5 00:11:21 1998
+++ kit/CHANGELOG	Mon May 23 05:10:01 2005
@@ -1,51 +0,0 @@
-CHANGELOG for magicpoint
-$Id: CHANGELOG,v 1.9 1998/09/04 15:11:21 onoe Exp $
-
-Fri Sep  5 1998  onoe@sm.sony.co.jp
-	* handle key inputs from invoked terminal as pressed on Xserver,
-	  even if the Xserver is running on a remote host.
-
-Mon Aug 26 1998  itojun@iijlab.net
-	* new copyright. (BSDish copyright without clause 3)
-
-Mon Aug 25 1998  itojun@iijlab.net
-	* print.c: better x11/freetype/vflib -> postscript font mapping.
-
-Mon Aug 23 1998  kato@wide.ad.jp
-	* embedded image support (added mgpembed.pl and embed.c)
-
-Mon Aug 22 1998  itojun@iijlab.net
-	* added contrib/xmindpath, MindPath PocketPoint user-level driver.
-
-Fri Jul 10 11:57:59 JST 1998  itojun@iijlab.net
-	* cache gs-generated image file.
-	  Suggested by: luigi@FreeBSD.org
-
-Mon Jul  6 11:38:32 JST 1998  itojun@iijlab.net
-	* capable of handling GB2312 and KSC5601 encoding.
-	  they must be encoded by using iso-2022 like escape sequences.
-	  EUC-cn or EUC-kr does not work.
-	* -x option is added.
-
-Thu Jul  2 18:04:16 JST 1998  itojun@iijlab.net
-	* eliminate gsview.
-	* revamp "xfont" directive. (see SYNTAX for detail)
-
-Thu Jun 25 13:10:28 JST 1998  itojun@iijlab.net
-	* print.c: color postscript support by "mgp2ps -c".
-
-changes between 1.02a and 1.03a:
-	* To allow color name that has space inbetween ("dark blue"), 
-	  color name after directives SHOULD come with doublequote.
-	  Therefore,
-		%fore blue
-	  should be
-		%fore "blue"
-	  At this moment, doublequote can be ommitted for backward
-	  compatibility.  We may require to have doublequote in the future.
-	  Font names and other string parameter obeys the same rule.
-	* %image is now capable of rendering encapsulated postscript files
-	  (*.eps).
-		%image foo.eps
-	  should work fine.
-	  By using -X option, you can specify device name for ghostscript.
Index: kit/SYNTAX
diff -u kit/SYNTAX:1.40 kit/SYNTAX:1.41
--- kit/SYNTAX:1.40	Wed Sep  8 01:57:42 2004
+++ kit/SYNTAX	Fri May 20 01:30:03 2005
@@ -1,4 +1,4 @@
-$Id: SYNTAX,v 1.40 2004/09/07 16:57:42 nishida Exp $
+$Id: SYNTAX,v 1.41 2005/05/19 16:30:03 nishida Exp $
 
 placement restriction for directives:
 		.mgprc		preamble	main pages
@@ -140,8 +140,11 @@
 	however, we have no escape sequence to designate the it...
 
 
-	if you have installed magicpoint with Xft2 enabled, %xfont will accept
+	If you have installed magicpoint with Xft2 enabled, %xfont will accept
 	"FONTNAME", "FONTNAME:STYLE", and "FONTNAME:style=STYLE".
+	Note that if you specify "FONTNAME" and it contains '-', it will be
+	interpreted as XLFD.  In such a case, you should use "FONTNAME:STYLE"
+	or "FONTNAME:style=STYLE".
 
 %vfont "font"
 	<font> :: use VFlib's <font> to draw Kanji characters.
Index: kit/configure.in
diff -u kit/configure.in:1.95 kit/configure.in:1.96
--- kit/configure.in:1.95	Wed Feb  9 13:00:50 2005
+++ kit/configure.in	Mon May 16 18:47:03 2005
@@ -3,7 +3,7 @@
 dnl independent (using srcdir), however, xmkmf and Imake.tmpl do not
 dnl allow us to switch compilation directory.
 dnl
-dnl $Id: configure.in,v 1.95 2005/02/09 04:00:50 nishida Exp $
+dnl $Id: configure.in,v 1.96 2005/05/16 09:47:03 nishida Exp $
 AC_INIT(image/imagetypes.c)
 
 dnl Checks for programs.
@@ -312,7 +312,7 @@
 		LIBS="$LIBS -L$i/lib"
 		OPTFLAGS="$OPTFLAGS -I$i/include"
 		AC_CHECK_LIB(mng, mng_initialize, 
-			[LIBS="$LIBS -Wl,-rpath,$i/lib -lmng"
+			[LIBS="$LIBS -lmng"
 			 AC_DEFINE(MNG)], 
 		[AC_CHECK_LIB(mng, mng_readdisplay,
 			[LIBS="$LIBS -lmng -ljpeg"
@@ -391,6 +391,8 @@
 		[LIBS="$LIBS -liconv"; AC_DEFINE(HAVE_ICONV)])])])
 fi
 
+AC_CHECK_HEADERS(fontconfig/fontconfig.h)
+
 AC_MSG_CHECKING(if gif handling is enabled)
 AC_ARG_ENABLE(gif,
 	[  --enable-gif            compile gif support in (need libungif).],
Index: kit/ctlwords.pl
diff -u kit/ctlwords.pl:1.2 kit/ctlwords.pl:removed
--- kit/ctlwords.pl:1.2	Sat Sep  5 06:05:08 1998
+++ kit/ctlwords.pl	Mon May 23 05:10:01 2005
@@ -1,12 +0,0 @@
-#! /usr/bin/perl
-$counter = 0;	# 0 origin
-print "/* generated by ctlwords.awk. do not edit by hand. */\n";
-
-while (<>) {
-	next if (!/^\/\*CTL\*\//);
-	next if ($_ !~ /(CTL_[A-Z0-9]+)/);
-
-	$word = $1;
-	print "#define $word\t$counter\n";
-	$counter++;
-}
Index: kit/draw.c
diff -u kit/draw.c:1.225 kit/draw.c:1.227
--- kit/draw.c:1.225	Fri Jan 28 00:33:06 2005
+++ kit/draw.c	Fri May 20 01:30:03 2005
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: draw.c,v 1.225 2005/01/27 15:33:06 nishida Exp $
+ * $Id: draw.c,v 1.227 2005/05/19 16:30:03 nishida Exp $
  */
 
 #include "mgp.h"
@@ -65,10 +65,7 @@
 static void process_direc __P((struct render_state *, int *));
 
 static int set_position __P((struct render_state *));
-static void draw_line_start __P((struct render_state *));
-void draw_line_itemsize __P((struct render_state *, int, int, int));
 static void draw_line_output __P((struct render_state *, char *));
-static void draw_line_end __P((struct render_state *));
 static void cutin __P((struct render_state *, int, int, int));
 #if 0
 static void shrink __P((char *, u_int));
@@ -573,6 +570,13 @@
 
 	case CTL_FORE:
 		fore_color[caching] = cp->ctl_value;
+#ifdef USE_M17N
+		if (! (mgp_flag & FL_NOM17N))
+		  {
+		    M17N_set_color (cp->ctl_value);
+		    break;
+		  }
+#endif
 		XSetForeground(display, gcfore, fore_color[caching]);
 		break;
 
@@ -628,6 +632,13 @@
 #endif /*FREETYPE*/
 
 	case CTL_XFONT2:
+#ifdef USE_M17N
+		if (! (mgp_flag & FL_NOM17N))
+		  {
+		    M17N_set_font (cp->ctc2_value1, cp->ctc2_value2);
+		    break;
+		  }
+#endif
 		x_registerseed(state, cp->ctc2_value1, cp->ctc2_value2);
 		break;
 
@@ -718,6 +729,15 @@
 		p = (state->tabprefix) ? state->tabprefix : state->curprefix;
 		if (!p)
 			break;
+#ifdef USE_M17N
+		if (! (mgp_flag & FL_NOM17N))
+		  {
+		    cp->ct_op = CTL_TEXT;
+		    cp->ctc_value = p;
+		    M17N_draw_string (state, cp);
+		    break;
+		  }
+#endif
 		draw_line_output(state, p);
 		break;
 	    }
@@ -729,6 +749,13 @@
 			state->align = AL_LEFTFILL1;
 			state->leftfillpos = state->linewidth;
 		}
+#ifdef USE_M17N
+		if (! (mgp_flag & FL_NOM17N))
+		  {
+		    M17N_draw_string (state, cp);
+		    break;
+		  }
+#endif
 		draw_line_output(state, cp->ctc_value);
 		break;
 
@@ -952,7 +979,7 @@
 	return x;
 }
 
-static void
+void
 draw_line_start(state)
 	struct render_state *state;
 {
@@ -1003,17 +1030,10 @@
 	struct render_state *state;
 	char *data;
 {
-#ifdef USE_M17N
-	if (mgp_flag & FL_NOM17N)
-		draw_string(state, data);
-	else
-		M17N_draw_string(state, data);
-#else
 	draw_string(state, data);
-#endif
 }
 
-static void
+void
 draw_line_end(state)
 	struct render_state *state;
 {
@@ -1313,12 +1333,6 @@
 	enum { MODE_UNKNOWN, MODE_X, MODE_VFLIB, MODE_FREETYPE }
 		mode = MODE_UNKNOWN;
 	char *p0;
-#ifdef USE_M17N
-	if (!(mgp_flag & FL_NOM17N)){
-		p0 = M17N_draw_fragment(state, p, len);
-		if (p0) return p0;
-	}
-#endif
 #ifdef USE_XFT2
 	if (!(mgp_flag & FL_NOXFT)){
 		p0 = xft_draw_fragment(state, p, len, registry, charset16);
@@ -4140,6 +4154,10 @@
 	for (p = seed; *p; p++) {
 		if (*p == '-')
 			hyphen++;
+		if (*p == ':') {
+			hyphen = 0;
+			break;
+		}
 	}
 	switch (hyphen) {
 	case 0:
@@ -4870,11 +4888,23 @@
 		return last_xftfont;
 	}
 
-	/*
-	 * if xfont contains "-", we believe this is a conventional xfont name 
-	 * and try to convert it for xft
-	 */
-	if ((p = strchr(xfont, '-')) != NULL) {
+	if ((p = strchr(xfont, ':')) != NULL) {
+		/*
+		 * if xfont contsins ":", we believe this is a Xft font name
+		 * with the style expression.
+		 */
+		p2 = p + 1;
+		/* allow to use ":style=" syntax */
+		if ((strstr(p2, "style=") != NULL) || (strstr(p2, "STYLE=") != NULL)) 
+			p2 += 6;
+		*p = '\0';
+		strlcpy(font, xfont, sizeof(font));
+		strlcpy(style, p2, sizeof(style));
+	} else if ((p = strchr(xfont, '-')) != NULL) {
+		/*
+		 * if xfont contains "-", we believe this is a conventional
+		 * xfont name and try to convert it for xft
+		 */
 		*p++ = 0;
 		strlcpy(font, xfont, sizeof(font));
 		if (strncmp(p, "bold-i", 6) == 0)
@@ -4883,17 +4913,8 @@
 			strlcpy(style, "Bold", sizeof(style));
 		else if ((p = strchr(p, '-')) != NULL && p[1] == 'i')
 			strlcpy(style, "Italic", sizeof(style));
-	} else if ((p = strchr(xfont, ':')) == NULL)
-		strlcpy(font, xfont, sizeof(font));
-	else {
-		p2 = p +1;
-		/* allow to use ":style=" syntax */ 
-		if ((strstr(p2, "style=") != NULL) || (strstr(p2, "STYLE=") != NULL)) 
-			p2 += 6;
-		*p = '\0';
+	} else 
 		strlcpy(font, xfont, sizeof(font));
-		strlcpy(style, p2, sizeof(style));
-	}
 	if (style[0]) {
 		xftfont = XftFontOpen(display, screen,
 		    XFT_FAMILY, XftTypeString, font,
@@ -4925,10 +4946,11 @@
 }
 #endif
 #ifdef USE_M17N
-obj_new_mtext(state, x, y, mt, drawframe, ascent, descent)
+obj_new_mtext(state, x, y, mt, from, to, drawframe, ascent, descent)
 	struct render_state *state;
 	int x, y;
 	MText *mt;
+	int from, to;
 	MFrame *drawframe;	
 	int ascent, descent;
 {
@@ -4944,8 +4966,10 @@
 	obj->descent = descent;
 	obj->vertloc = VL_BASE;
 	obj->data.m17ntext.mt = mt;
+	m17n_object_ref (mt);
 	obj->data.m17ntext.drawframe = drawframe;
-	obj->data.m17ntext.len = mtext_len(mt);
+	obj->data.m17ntext.from = from;
+	obj->data.m17ntext.to = to;
 	return 1;
 }
 #endif
Index: kit/m17n.c
diff -u kit/m17n.c:1.6 kit/m17n.c:1.8
--- kit/m17n.c:1.6	Sun May  1 00:05:03 2005
+++ kit/m17n.c	Fri May 20 00:58:30 2005
@@ -1,5 +1,8 @@
 /*
  * Copyright (C) 1997 and 1998 WIDE Project.  All rights reserved.
+ * Copyright (C) 2005
+ *   National Institute of Advanced Industrial Science and Technology (AIST)
+ *   Registration Number H16PRO276
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,37 +29,53 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: m17n.c,v 1.6 2005/04/30 15:05:03 nishida Exp $ 
+ * $Id: m17n.c,v 1.8 2005/05/19 15:58:30 nishida Exp $ 
  */
 
 #ifdef USE_M17N
 #include "mgp.h"
-#define M17N_MAX_CACHE 100
 
-static void M17N_format_line();
+#ifdef HAVE_FONTCONFIG_FONTCONFIG_H
+/* This is to parse Xft font name pattern.  */
+#include <fontconfig/fontconfig.h>
+#endif
+
+/* Prototypes for internal functions.  They start with "M17N__".  */
+
+static int M17N__line_break __P ((MText *, int, int, int ,int, int));
+static void M17N__format_line __P ((int, int, int *, int *));
+static MText *M17N__gen_mtext __P ((u_char *));
+static void M17N__define_font __P ((struct ctrl *));
+static MFont *M17N__get_font __P ((char *, char *, int));
+
+/* The following two variables are set by M17N_draw_string and
+   referred by M17N__format_line ().  */
+
+/* Width remaining for the first line of a drawning text.  */
+static int first_width;
+/* Width of the currently drawing area.  */
+static int area_width;
 
 static MDrawControl control;
-static MText *mt;
-static MFace *face_size;
-static MFace *face_color;
-static MFace *face_other;
-static MSymbol lang;
+static MFontset *fontset;
+static MFace *faces[2];
+static MSymbol languages[2];
 /* M-text containing a single space.  It is used to get normal
    ascent/descent of an ASCII font selected for the current set of
    faces.  */
 static MText *space;
-static struct render_state *current_state;
-static int current_linewidth; 
-static int current_indent; 
+
+static MSymbol Miso8859_1, Municode_bmp, Mjisx0208, Mgb2312, Mksc5601;
+static MSymbol Mlatin, Mhan, Mhangul, Mkatakana, Mhiragana;
 
 static int kinsoku_range [][2] = {
-	0x3041, 0x30FF,		/* Kana */
-	0x2E80, 0x2FDF,		/* radical */
-	0x3400, 0x4DB5,		/* CJK Ideograph Extention A */
-	0x4E00, 0x9FAF,		/* CJK Ideograph */  
-	0XF900, 0xFAFF,		/* CJK COMPATIBILITY IDEOGRAPH */
-	0X20000, 0x2A6D6,	/* CJK Ideograph Extention B */
-	0x2F800, 0x2FA1D	/* CJK COMPATIBILITY IDEOGRAPH */		
+  {0x3041, 0x30FF},		/* Kana */
+  {0x2E80, 0x2FDF},		/* radical */
+  {0x3400, 0x4DB5},		/* CJK Ideograph Extention A */
+  {0x4E00, 0x9FAF},		/* CJK Ideograph */  
+  {0XF900, 0xFAFF},		/* CJK COMPATIBILITY IDEOGRAPH */
+  {0X20000, 0x2A6D6},		/* CJK Ideograph Extention B */
+  {0x2F800, 0x2FA1D}		/* CJK COMPATIBILITY IDEOGRAPH */		
 };
 
 static int kinsoku_list [] = {
@@ -76,8 +95,10 @@
 static MCharTable *kinsoku_table;
 static MSymbol Mkinsoku;
 
+/* Find a linebreak position.  Set in control.line_break */
+
 static int
-m17n_line_break (mt, pos, from, to, line, y)
+M17N__line_break (mt, pos, from, to, line, y)
      MText *mt;
      int pos, from, to;
      int line, y;
@@ -96,70 +117,47 @@
 	return pos;
 }
 
-void
-M17N_init()
-{
-	int i;
-	M17N_INIT();
+/* Decide the width and indentation of the LINEth line.  Set in
+   control.format.  */
 
-	space = mtext_from_data (" ", 1, MTEXT_FORMAT_US_ASCII);
-#if 0
-	face_other = mface ();
-	// default fontset is not truetype
-//	mface_put_prop (face_other, Mfontset, mfontset ("truetype"));
-	mface_put_prop (face_other, Mfontset, mfontset ("default"));
-#endif
-	memset (&control, 0, sizeof control);
-	control.two_dimensional = 1;
-	control.enable_bidi = 1;
-	control.ignore_formatting_char = 1;
-	control.disable_caching = 0;
-	control.max_line_width = 0;
-	control.anti_alias = 1;
-	control.format = M17N_format_line; 
-//	control.line_break = mdraw_default_line_break; 
-	control.line_break = m17n_line_break; 
-
-	/* Generate kinsoku_char_table.  */
-	Mkinsoku = msymbol ("kinsoku");
-	kinsoku_table = mchartable (Msymbol, Mnil);
-	for (i = 0; i < (sizeof(kinsoku_range) / sizeof(kinsoku_range[0])); i++)
-		mchartable_set_range (kinsoku_table, kinsoku_range[i][0],
-			kinsoku_range[i][1], Mt);
-	for (i = 0; i < (sizeof kinsoku_list / sizeof (int)); i++)
-		mchartable_set (kinsoku_table, kinsoku_list[i], Mkinsoku);
+static void
+M17N__format_line(line, y, indent, width)
+	int line, y, *indent, *width;
+{
+  *width = line == 0 ? first_width : area_width;
+  *indent = 0;
 }
 
-#define MAXCACHEDMTEXT 40
-MText *
-M17N_gen_mtext (p)
+/* Return an M-text generated from the byte sequence at P.  */
+
+static MText *
+M17N__gen_mtext (p)
 	u_char *p;
 {
-	static MText *cached_mt[MAXCACHEDMTEXT]; 
-	static u_char *cached_txt[MAXCACHEDMTEXT][BUFSIZ]; 
-	static int cached_txt_len[MAXCACHEDMTEXT]; 
-	static int cached_count;
 	MSymbol coding;
 	MText *mt = 0;
-	int i, len = strlen (p);
+	int i, len = strlen ((char *) p);
 
-	if (len == 0) return;
-	for (i = 0; i < cached_count; i ++)
-		if ((len == cached_txt_len[i]) && 
-				!memcmp((void *)p, (void *)cached_txt[i], cached_txt_len[i])){
-			m17n_object_ref(cached_mt[i]);
-		   	return cached_mt[i];
-		}
+	if (len == 0) return NULL;
 
 	if (!mt && mgp_charset[0] != '\0') {
 		coding = mconv_resolve_coding (msymbol (mgp_charset));
 		if (coding) mt = mconv_decode_buffer (coding, p, len);
 	}
-	if (strchr (p, '\033')) {
+	if (strchr ((char *) p, '\033')) {
 		/* Try ISO-2022 encoding.  */
 		coding = mconv_resolve_coding (msymbol ("iso-2022-7bit"));
 		if (coding) mt = mconv_decode_buffer (coding, p, len);
 	}
+	if (!mt)
+	  {
+	    /* Check ASCII only.  */
+	    for (i = 0; i < len; i++)
+	      if (p[i] >= 0x80)
+		break;
+	    if (i == len)
+	      mt = mtext_from_data (p, len, MTEXT_FORMAT_US_ASCII);
+	  }
 	if (!mt) {
 		/* Try UTF-8.  */
 		coding = mconv_resolve_coding (msymbol ("utf-8"));
@@ -176,285 +174,450 @@
 		exit(1);
 	}
 
-	bzero(cached_txt[cached_count], BUFSIZ);
-	if (cached_mt[cached_count]) 
-		m17n_object_unref(cached_mt[cached_count]);
-	strcpy((char *)cached_txt[cached_count], p); 
-	cached_txt_len[cached_count] = strlen(p);
-	cached_mt[cached_count] = mt;   	
-	cached_count = (cached_count + 1) % MAXCACHEDMTEXT;	
-	m17n_object_ref(mt);
-
 	return mt;
 }
 
-void
-M17N_set_size(size)
-	int size;
+
+/* Return a font matching SEED and REGISTRY.  If no such font is found
+   and RECORD is nonzero, create a new font and remember it.  */
+
+MFont *
+M17N__get_font (seed, registry, record)
+     char *seed;
+     char *registry;
+     int record;
 {
-	static MFace *msize[M17N_MAX_CACHE];
-	static int msize_num = 0;
-	int i, targetsize;
-	int delta, mindelta, mindelta_i;
-
-	targetsize = size * 10;
-
-	mindelta = -1;
-	for (i = 0; i < msize_num; i ++){
-		if (msize[i]){
-			delta = abs((int)mface_get_prop(msize[i], Msize) - targetsize);
-			if (!delta){
-				face_size = msize[i];
-				return;
-			} else {
-				if (mindelta < 0){ mindelta = delta; mindelta_i = i; }
-				else if (mindelta > delta) { mindelta = delta; mindelta_i = i; }
-			}
-		}
-	}
-
-	/* If msize_num exceeds limit, choose the closest size */
-	if (msize_num == M17N_MAX_CACHE) {
-		face_size = msize[mindelta_i];
-		return;
-	}
-
-	/* create new face */
-	msize[msize_num] = mface();
-	mface_put_prop (msize[msize_num], Msize, (void *) targetsize);
-	face_size = msize[msize_num];
-	msize_num ++;
-	return;
+  static MPlist *font_list;
+  MPlist *plist;
+  MSymbol sym_seed, sym_registry;
+  MSymbol family, weight, slant;
+  MFont *font;
+  char *p;
+
+  if (! font_list)
+    font_list = mplist ();
+
+  sym_seed = msymbol (seed);
+  if (strncmp (registry, "iso8859", 7) == 0)
+    sym_registry = msymbol (registry);
+  else if (strncmp (registry, "jisx0208", 8) == 0)
+    sym_registry = Mjisx0208;
+  else if (strncmp (registry, "gb2312", 6) == 0)
+    sym_registry = Mgb2312;
+  else if (strncmp (registry, "ksc5601", 7) == 0)
+    sym_registry = Mksc5601;
+  else
+    sym_registry = msymbol (registry);
+
+  for (plist = mplist_find_by_key (font_list, sym_seed); plist;
+       plist = mplist_find_by_key (plist, sym_seed))
+    {
+      font = mplist_value (plist);
+      if (mfont_get_prop (font, Mregistry) == sym_registry)
+	return font;
+    }
+
+  if (! record)
+    return NULL;
+
+  family = weight = slant = Mnil;
+  if ((p = strchr (seed, '-')) != NULL)
+    {
+      /* Should be XLFD of format FAMILY-WEIGHT[-SLANT] */
+      char *copy = alloca (strlen (seed) + 1);
+
+      strcpy (copy, seed);
+      copy[p - seed] = '\0';
+      family = msymbol (copy);
+      copy += p + 1 - seed;
+      p = strchr (copy, '-');
+      if (! p)
+	weight = msymbol (copy);
+      else
+	{
+	  *p = 0;
+	  weight = msymbol (copy);
+	  slant = msymbol (p + 1);
+	}
+    }
+  else if (strchr (seed, ':'))
+    {
+      /* Should be Xft (i.e. Fontconfig) pattern.  */
+#ifdef HAVE_FONTCONFIG_FONTCONFIG_H
+      FcPattern *pat = FcNameParse ((FcChar8 *) seed);
+      FcChar8 *p;
+      int i;
+
+      if (pat)
+	{
+	  if (FcPatternGetString (pat, FC_FAMILY, 0, &p) == FcResultMatch)
+	    family = msymbol ((char *) p);
+	  if (FcPatternGetInteger (pat, FC_WEIGHT, 0, &i) == FcResultMatch)
+	    weight = (i < FC_WEIGHT_EXTRALIGHT ? msymbol ("ultralight")
+		      : i < FC_WEIGHT_LIGHT ? msymbol ("extralight")
+		      : i < FC_WEIGHT_REGULAR ? msymbol ("light")
+		      : i < FC_WEIGHT_MEDIUM ? msymbol ("regular")
+		      : i < FC_WEIGHT_DEMIBOLD ? msymbol ("medium")
+		      : i < FC_WEIGHT_BOLD ? msymbol ("demibold")
+		      : i < FC_WEIGHT_EXTRABOLD ? msymbol ("bold")
+		      : i < FC_WEIGHT_ULTRABOLD ? msymbol ("extrabold")
+		      : i < FC_WEIGHT_BLACK ? msymbol ("ultrabold")
+		      : msymbol ("black"));
+	  if (FcPatternGetInteger (pat, FC_SLANT, 0, &i) == FcResultMatch)
+	    slant = (i < FC_SLANT_ITALIC ? msymbol ("r")
+		     : i < FC_SLANT_OBLIQUE ? msymbol ("i")
+		     : msymbol ("o"));
+	  FcPatternDestroy (pat);
+	}
+      else
+#endif
+	/* Treat the seed as family name.  */
+	family = msymbol (seed);
+    }
+  else
+    /* Treat the name as family name.  */
+    family = msymbol (seed);	
+
+  font = mfont ();
+  mfont_put_prop (font, Mfamily, family);
+  mfont_put_prop (font, Mweight, weight);
+  mfont_put_prop (font, Mstyle, slant);
+  mfont_put_prop (font, Mregistry, sym_registry);
+  mplist_push (font_list, sym_seed, font);
+  return font;
 }
 
+/* Pre-define the font set in CP.   */
+
 void
-M17N_set_color(color)
-	u_long color;
+M17N__define_font (cp)
+     struct ctrl *cp;
 {
-	static u_long mcolor_val[M17N_MAX_CACHE];
-	static MFace *mcolor[M17N_MAX_CACHE];
-	static int mcolor_num = 0;
-	int i, delta, mindelta, mindelta_i;
-	char color_string[20];
-	XColor xcolor;
-
-	for (i = 0; i < mcolor_num; i ++){
-		delta = abs(mcolor_val[i] - color);
-		if (!delta){
-			face_color = mcolor[i];
-			return;
-		} else {
-			if (mindelta < 0){ mindelta = delta; mindelta_i = i; }
-			else if (mindelta > delta) { mindelta = delta; mindelta_i = i; }
-		}
-	}
-
-	/* If mcolor_num exceeds limit, choose the closest color */
-	if (mcolor_num == M17N_MAX_CACHE) {
-		face_color = mcolor[mindelta_i];
-		return;
-	}
-
-	/* create new face */
-	xcolor.pixel = color;  
-	XQueryColor(display, colormap, &xcolor);
-	sprintf(color_string, "#%04X%04X%04X\0", xcolor.red, xcolor.green, xcolor.blue); 
-	mcolor[mcolor_num] = mface();
-	mcolor_val[mcolor_num] = color;
-	mface_put_prop(mcolor[mcolor_num], Mforeground, msymbol(color_string));
-	face_color = mcolor[mcolor_num];
-	mcolor_num ++;
-	return;
+  MSymbol family, registry;
+  MPlist *plist, *pl;
+  MFont *font, *recorded;
+  
+  for (; cp && cp->ct_op != CTL_XFONT2; cp = cp->ct_next);
+  if (! cp)
+    return;
+
+  recorded = M17N__get_font (cp->ctc2_value1, cp->ctc2_value2, 1);
+  family = mfont_get_prop (recorded, Mfamily);
+  registry = mfont_get_prop (recorded, Mregistry);
+  if (registry == Miso8859_1)
+    {
+      /* This may be a TTF, in which case, we may be able to use it
+	 for any scripts.  */
+      plist = mfontset_lookup (fontset, Mt, Mnil, Mnil);
+    }
+  else
+    {
+      plist = mplist ();
+      if (registry == Mjisx0208 || registry == Mgb2312)
+	mplist_put (plist, Mhan, NULL);
+      else if (registry == Mksc5601)
+	mplist_put (plist, Mhangul, NULL);
+      else if (strncmp (msymbol_name (registry), "iso8859-", 8) == 0)
+	mplist_put (plist, Mlatin, NULL);
+    }
+  font = mfont ();
+  mfont_put_prop (font, Mfamily, family);
+  for (pl = plist; mplist_key (pl) != Mnil; pl = mplist_next (pl))
+    {
+      MSymbol script = mplist_key (pl);
+      MPlist *p = mfontset_lookup (fontset, script, Mt, Mnil);
+      MPlist *p0;
+      
+      for (p0 = p; mplist_key (p0) != Mnil; p0 = mplist_next (p0))
+	{
+	  MSymbol lang = mplist_key (p0);
+
+	  mfont_put_prop (font, Mregistry, registry);
+	  mfontset_modify_entry (fontset, script, lang, Mnil, font, Mnil, -1);
+	  if (registry == Miso8859_1)
+	    {
+	      mfont_put_prop (font, Mregistry, Municode_bmp);
+	      mfontset_modify_entry (fontset, script, lang, Mnil, font,
+				     Mnil, -1);
+	    }
+	}
+      m17n_object_unref (p);
+    }
+  m17n_object_unref (plist);
+
+  mfont_put_prop (font, Mregistry, registry);
+  mfontset_modify_entry (fontset, Mnil, Mnil, Mnil, font, Mnil, -1);
+  if (registry == Miso8859_1)
+    {
+      mfont_put_prop (font, Mregistry, Municode_bmp);
+      mfontset_modify_entry (fontset, Mnil, Mnil, Mnil, font, Mnil, -1);
+    }
 }
 
-char *
-M17N_draw_fragment(state, p, len)
-	struct render_state *state;
-	u_char *p;
-	u_int len;
+
+/* Internal API (functions called from the other files) */
+
+void
+M17N_init()
 {
-	static MFrame *drawframe;
-	static MFace  *drawface;
-	static MPlist *plist;
-	MFace *faces[256];
-	MText *mt;
-	MDrawGlyphInfo info;
-	MDrawMetric rect;
-	int ascent = 0, descent = 0, i, n, flheight = 0;
-	char tmptext[10000];
-	Bool flag_s, flag_c, flag_o;
-
-	if (!drawface) drawface = mface();
-	if (!plist){
-		plist = mplist ();
-		mplist_add(plist, Mdisplay, display);
-		drawframe = mframe (plist);
-	}
-	M17N_set_size(char_size[caching]);
-	M17N_set_color(fore_color[caching]); 
-
-	if (len >= 10000) len = 9999; 
-	strncpy(tmptext, p, len);
-	tmptext[len] = 0;
-	mt = M17N_gen_mtext(tmptext);
-
-	/* check if the faces attached Mface are already cached */
-	flag_s = flag_c = flag_o = True;
-	n = mtext_get_prop_values (mt, 0, Mface, (void **) faces, 256);
-	for (i = 0; i < n; i ++){
-		if (faces[i] == face_size)  flag_s = False;
-		if (faces[i] == face_color) flag_c = False;
-		if (faces[i] == face_other) flag_o = False;
-	}
-
-	/* if faces are not cached, push them to Mface */
-	if (flag_s) mtext_push_prop (mt, 0, mtext_len(mt), Mface, face_size);
-	if (flag_c) mtext_push_prop (mt, 0, mtext_len(mt), Mface, face_color);
-	if (flag_o) mtext_push_prop (mt, 0, mtext_len(mt), Mface, face_other);
-	if (lang) mtext_push_prop (mt, 0, mtext_len(mt), Mlanguage, lang);
-
-	current_linewidth = state->width - state->leftfillpos / 2 - state->linewidth;
-	current_indent = state->leftfillpos;
-
-	/* Compare the normal ascent/descent and the physical
-	   ascent/descent of this M-text, and use the bigger ones.  */
-	mdraw_text_extents(drawframe, space, 0, 1,
-			   &control, NULL, &rect, NULL);
-	ascent = - rect.y, descent = rect.height + rect.y;
-	mdraw_text_extents(drawframe, mt, 0, 1, &control, &rect, NULL, NULL);
-	flheight = rect.height + rect.y;
-	mdraw_text_extents(drawframe, mt, 0, mtext_len(mt), 
-			   &control, &rect, NULL, NULL);
-	if (ascent < - rect.y)
-	  ascent = - rect.y;
-	if (descent < rect.height + rect.y)
-	  descent = rect.height + rect.y;
-	if (rect.width > 0)
-	  state->brankline = 0;
+	int i;
+	M17N_INIT();
+
+	space = mtext_from_data (" ", 1, MTEXT_FORMAT_US_ASCII);
+	fontset = mfontset ("default");
+	memset (&control, 0, sizeof control);
+	control.two_dimensional = 1;
+	control.enable_bidi = 1;
+	control.ignore_formatting_char = 1;
+	control.disable_caching = 0;
+	control.max_line_width = 0;
+	control.anti_alias = 1;
+	control.format = M17N__format_line; 
+	control.line_break = M17N__line_break; 
 
-	draw_line_itemsize(state, ascent, descent, flheight);
-	if (obj_new_mtext(state, state->linewidth, state->charoff, mt, 
-				drawframe, ascent, descent)){
-		state->linewidth += rect.width;
-		return p + len;
-	} else
-		return NULL;
+	/* Generate kinsoku_char_table.  */
+	Mkinsoku = msymbol ("kinsoku");
+	kinsoku_table = mchartable (Msymbol, Mnil);
+	for (i = 0; i < (sizeof(kinsoku_range) / sizeof(kinsoku_range[0])); i++)
+		mchartable_set_range (kinsoku_table, kinsoku_range[i][0],
+			kinsoku_range[i][1], Mt);
+	for (i = 0; i < (sizeof kinsoku_list / sizeof (int)); i++)
+		mchartable_set (kinsoku_table, kinsoku_list[i], Mkinsoku);
+
+	Miso8859_1 = msymbol ("iso8859-1");
+	Municode_bmp = msymbol ("unicode-bmp");
+	Mjisx0208 = msymbol ("jisx0208.1983-0");
+	Mgb2312 = msymbol ("gb2312.1980-0");
+	Mksc5601 = msymbol ("ksc5601.1987-0");
+
+	Mlatin = msymbol ("latin");
+	Mhan = msymbol ("han");
+	Mhangul = msymbol ("hangul");
+	Mkatakana = msymbol ("katakana");
+	Mhiragana = msymbol ("hiragana");
+
+	for (i = 0; i < MAXFONTDEF; i++)
+	  if (fontdef_control[i])
+	    M17N__define_font (fontdef_control[i]);
 }
 
+/* Set font-oriented properties (family, weight, slant) of the current
+   face to what specified in SEED.  */
+
 void
-M17N_draw_object(obj, target, x, y)
-	struct render_object *obj;
-	Drawable target;	
-	int x, y;
+M17N_set_font (seed, registry)
+     char *seed;
+     char *registry;
 {
-	MFace *faces[256];
-	int i, n;			
+  MFont *font = M17N__get_font (seed, registry, 0);
+  MFace *face = faces[caching];
 
-	mdraw_text_with_control (
-		obj->data.m17ntext.drawframe, 
-		(MDrawWindow) target, x, y,
-		obj->data.m17ntext.mt, 0, 
-		obj->data.m17ntext.len, &control);
+  if (! font)
+    return;
+  if (! faces[caching])
+    face = faces[caching] = mface ();
+  mface_put_prop (face, Mfamily, (MSymbol)  mfont_get_prop (font, Mfamily));
+  mface_put_prop (face, Mweight, mfont_get_prop (font, Mweight));
+  mface_put_prop (face, Mstyle, mfont_get_prop (font, Mstyle));
+}
 
-	/* detach extra properties */
-	n = mtext_get_prop_values (obj->data.m17ntext.mt, 0, Mface, (void **) faces, 256);
-	for (i = n; i > 3; i --){
-		mtext_pop_prop (obj->data.m17ntext.mt, 0, 
-			obj->data.m17ntext.len, Mface);
-	}
+void
+M17N_set_color (color)
+     u_long color;
+{
+  MFace *face = faces[caching];
+  char color_string[20];
+  XColor xcolor;
+
+  if (! faces[caching])
+    face = faces[caching] = mface ();
+
+  xcolor.pixel = color;  
+  XQueryColor (display, colormap, &xcolor);
+  sprintf (color_string, "#%04X%04X%04X",
+	   xcolor.red, xcolor.green, xcolor.blue); 
+  mface_put_prop (face, Mforeground, msymbol (color_string));
 }
 
+/* Calculate the extents of text pointed by CP and update STATE.  */
+
 void
-M17N_draw_string(state, data)
+M17N_draw_string (state, cp)
 	struct render_state *state;
-	char *data;
+	struct ctrl *cp;
 {
-	char *p = data;
-	char *registry = NULL;
-	int charset16 = 0;
-
-	if (strlen(p))
-		M17N_draw_fragment(state, p, strlen(p));
+  MText *mt;
+  static MFrame *drawframe;
+  static MPlist *plist;
+  MDrawGlyphInfo info;
+  MDrawMetric rect_sp, rect;
+  int ascent = 0, descent = 0;
+  int nchars;
+  int i, c;
+
+  if (cp->ct_flag == 0)
+    {
+      /* cp->ctc_value points a raw byte sequence.  */
+      mt = M17N__gen_mtext ((u_char *) cp->ctc_value);
+      cp->ctc_value = (char *) mt;
+      cp->ct_flag = 1;
+    }
+  else
+    {
+      /* cp->ctc_valus points an M-text. */
+      mt = (MText *) cp->ctc_value;
+    }
+  if (! mt)
+    return;
+
+  nchars = mtext_len (mt);
+  if (! plist)
+    {
+      plist = mplist ();
+      mplist_add (plist, Mdisplay, display);
+      drawframe = mframe (plist);
+    }
+
+  if (! mtext_get_prop (mt, 0, Mface))
+    {
+      MFace *face;
+
+      if (! faces[caching])
+	faces[caching] = mface ();
+      face = mface_copy (faces[caching]);
+      mface_put_prop (face, Msize, (void *) (char_size[caching] * 10));
+      mtext_push_prop (mt, 0, nchars, Mface, face);
+      if (languages[caching])
+	mtext_push_prop (mt, 0, nchars, Mlanguage, languages[caching]);
+      m17n_object_unref (face);
+    }
+
+  /* Compare the normal ascent/descent and the physical ascent/descent
+     of this M-text, and use the bigger ones.  */
+  mdraw_text_extents(drawframe, space, 0, 1, &control, NULL, NULL, &rect_sp);
+  rect_sp.height += rect_sp.y;	/* calculate descent */
+
+  area_width = state->width - state->leftfillpos / 2;
+  first_width = area_width - state->linewidth;
+  mdraw_glyph_info (drawframe, mt, 0, 0, &control, &info);
+  if (info.line_to == nchars)
+    {
+      /* All text can be drawn on the current line.  */
+      mdraw_text_extents (drawframe, mt, 0, nchars, &control,
+			  NULL, NULL, &rect);
+      rect.height += rect.y; /* calculate descent */
+      ascent = rect_sp.y < rect.y ? - rect_sp.y : - rect.y;
+      descent = rect_sp.height > rect.height ? rect_sp.height : rect.height;
+      for (i = 0; state->brankline && i < nchars; i++)
+	if ((c = mtext_ref_char (mt, i)) != ' ' && c != '\t')
+	  state->brankline = 0;
+      draw_line_itemsize(state, ascent, descent, 0);
+      obj_new_mtext (state, state->linewidth, state->charoff,
+		     mt, 0, nchars, drawframe, ascent, descent);
+      state->linewidth += rect.width;
+    }
+  else
+    {    
+      int i, c;
+      MDrawGlyphInfo info2;
+      /* We need a line break.  Check if there's a room for at least
+	 one fragment on the current line.  */
+
+      /* Skip the leading spaces.  */
+      for (i = 0; i < nchars && mtext_ref_char (mt, 0) == ' '; i++);
+      for (; i < nchars; i++)
+	{
+	  if ((c = mtext_ref_char (mt, i)) == ' ')
+	    break;
+	  else if (mchartable_lookup (kinsoku_table, c) == Mt)
+	    {
+	      i++;
+	      break;
+	    }
+	}
+      mdraw_glyph_info (drawframe, mt, 0, i - 1, &control, &info2);
+      if (info2.line_from > 0)
+	{
+	  /* No room even for one fragment.  Break the line before
+	     drawing anything.  */
+	  draw_line_end (state);
+	  draw_line_start (state);
+	  state->linewidth = state->leftfillpos;
+	  first_width = area_width;
+	  mdraw_clear_cache (mt);
+	  mdraw_glyph_info (drawframe, mt, 0, 0, &control, &info);
+	}
+
+      while (1)
+	{
+	  for (i = info.line_to; i > info.line_from; i--)
+	    if ((c = mtext_ref_char (mt, i - 1)) != ' ' && c != '\t')
+	      {
+		state->brankline = 0;
+		break;
+	      }
+	  if (i == info.line_from)
+	    i = info.line_to;
+
+	  mdraw_text_extents (drawframe, mt, info.line_from, i,
+			      &control, NULL, NULL, &rect);
+	  rect.height += rect.y; /* calculate descent */
+	  ascent = rect_sp.y < rect.y ? - rect_sp.y : - rect.y;
+	  descent = rect_sp.height > rect.height ? rect_sp.height : rect.height;
+	  draw_line_itemsize (state, ascent, descent, 0);
+	  obj_new_mtext (state, state->linewidth, state->charoff,
+			 mt, info.line_from, i, drawframe, ascent, descent);
+	  state->linewidth += rect.width;
+	  if (info.line_to >= nchars)
+	    break;
+	  draw_line_end (state);
+	  draw_line_start (state);
+	  state->linewidth = state->leftfillpos;
+	  mdraw_glyph_info (drawframe, mt, info.line_to, info.line_to,
+			    &control, &info);
+	}
+    }
 }
 
-static void
-M17N_format_line(line, y, indent, width)
-	int line, y, *indent, *width;
+/* Draw the M-text stored in OBJ on TARGET at the coordinate (X Y).  */
+
+void
+M17N_draw_object(obj, target, x, y)
+	struct render_object *obj;
+	Drawable target;	
+	int x, y;
 {
-	*indent = 0; // we don't need to set this.
-	*width = current_linewidth;
+	control.format = NULL;
+	mdraw_text_with_control (
+		obj->data.m17ntext.drawframe, 
+		(MDrawWindow) target, x, y,
+		obj->data.m17ntext.mt,
+		obj->data.m17ntext.from, obj->data.m17ntext.to, &control);
+	control.format = M17N__format_line;
 }
 
 
-#define M17NMAXKEY 3
-#define M17NMAXVAL 128
+/* Update faces[caching] or languages[caching] according to KEY and
+   VALUE.  */
+
 void
 M17N_process_direc(key, value)
 	char *key, *value;
 {
-	static u_char *mfontset_val[M17N_MAX_CACHE];
-	static u_char *mfamily_val[M17N_MAX_CACHE];
-	static MFace *mfontset_face[M17N_MAX_CACHE];
-	static MFace *mfamily_face[M17N_MAX_CACHE];
-	static int mfontset_num = 0;
-	static int mfamily_num = 0;
-	static MFace *last_used; 
+  MSymbol key_sym = msymbol (key);
+  MFace *face = faces[caching];
 
-	char *keywords[M17NMAXKEY] = {"fontset", "family", "language"};
-	int i;
+  if (! faces[caching])
+    face = faces[caching] = mface ();
 
-	for (i = 0; i < M17NMAXKEY; i ++) {
-		if (!strcmp(key, keywords[i])) {
-			break;
-		}
-	}
-	switch(i){
-	case 0: 
-		for (i = 0; i < mfontset_num; i ++){
-			if (strlen(mfontset_val[i]) == strlen(value) &&
-				!(strcmp(mfontset_val[i], value))){
-				face_other = mfontset_face[i];
-				goto done;
-			}
-		}
-		if (mfontset_num == M17N_MAX_CACHE){
-			face_other = mfontset_face[0]; // adhoc
-			goto done;
-		} 
-		mfontset_face[mfontset_num] = mface();
-		mface_put_prop (mfontset_face[mfontset_num], Mfontset, mfontset (value));
-		face_other = mfontset_face[mfontset_num];
-		mfontset_val[mfontset_num] = strdup(value);
-		mfontset_num ++;
-		goto done;
-		break;
-	case 1: 
-		for (i = 0; i < mfamily_num; i ++){
-			if (strlen(mfamily_val[i]) == strlen(value) &&
-				!(strcmp(mfamily_val[i], value))){
-				face_other = mfamily_face[i];
-				goto done;
-			}
-		}
-		if (mfamily_num == M17N_MAX_CACHE){
-			face_other = mfamily_face[0]; // adhoc
-			goto done;
-		} 
-		mfamily_face[mfamily_num] = mface();
-		mface_put_prop (mfamily_face[mfamily_num], Mfamily, msymbol (value));
-		face_other = mfamily_face[mfamily_num];
-		mfamily_val[mfamily_num] = strdup(value);
-		mfamily_num ++;
-		goto done;
-		break;
-	case 2: 
-		lang = msymbol(value);
-		break;
-	default:
-		fprintf(stderr, "unknown keyword:%s for m17n-lib\n", key);	
-	}
-done:
-	last_used = face_other;
-	return;
+  if (key_sym == Mfoundry || key_sym == Mfamily || key_sym == Mweight
+      || key_sym == Mstyle || key_sym == Mstretch || key_sym == Madstyle)
+    mface_put_prop (face, key_sym, value ? msymbol (value) : Mnil);
+  else if (key_sym == Mfontset)
+    mface_put_prop (face, key_sym, value ? mfontset (value) : fontset);
+  else if (key_sym == Mratio)
+    mface_put_prop (face, key_sym, value ? (void *) atoi (value) : (void *) 1); 
+  else if (key_sym == Mlanguage)
+    languages[caching] = value ? msymbol (value) : Mnil;
 }
 #endif
Index: kit/mgp.h
diff -u kit/mgp.h:1.140 kit/mgp.h:1.141
--- kit/mgp.h:1.140	Wed Sep  8 01:57:42 2004
+++ kit/mgp.h	Mon May 16 18:47:03 2005
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: mgp.h,v 1.140 2004/09/07 16:57:42 nishida Exp $
+ * $Id: mgp.h,v 1.141 2005/05/16 09:47:03 nishida Exp $
  */
 
 #include <stdio.h>
@@ -531,7 +531,7 @@
 		struct {
 			MText *mt;
 			MFrame *drawframe;
-			int len;
+			int from, to;
 		} m17ntext;
 #endif
 	} data;
@@ -735,6 +735,14 @@
 extern void timebar __P((struct render_state *));
 extern void draw_reinit __P((struct render_state *));
 extern int get_regid __P((char *));
+extern void draw_line_itemsize __P((struct render_state *, int, int, int));
+extern void draw_line_start __P((struct render_state *));
+extern void draw_line_end __P ((struct render_state *));
+
+#ifdef USE_M17N
+extern int obj_new_mtext __P((struct render_state *, int, int,
+			      MText *, int, int, MFrame *, int, int));
+#endif
 
 /*parse.c*/
 extern void load_file __P((char *));
@@ -829,12 +837,11 @@
 #endif
 
 #ifdef USE_M17N
-void M17N_init __P((void));
-void M17N_set_size __P((int));
-void M17N_set_color __P((u_long));
-MText * M17N_gen_mtext __P((u_char *));
-void M17N_process_direc __P((char *, char *));
-void M17N_draw_string __P((struct render_state *, char *));
-char * M17N_draw_fragment __P((struct render_state *, u_char *, u_int));
-void M17N_draw_object __P((struct render_object *, Drawable, int, int));
+/*m17n.c*/
+extern void M17N_init __P((void));
+extern void M17N_set_font __P((char *, char *));
+extern void M17N_set_color __P((u_long));
+extern void M17N_process_direc __P((char *, char *));
+extern void M17N_draw_string __P((struct render_state *, struct ctrl *cp));
+extern void M17N_draw_object __P((struct render_object *, Drawable, int, int));
 #endif
Index: kit/parse.c
diff -u kit/parse.c:1.98 kit/parse.c:1.100
--- kit/parse.c:1.98	Thu Jul  8 15:09:54 2004
+++ kit/parse.c	Fri May 20 12:45:23 2005
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: parse.c,v 1.98 2004/07/08 06:09:54 nishida Exp $
+ * $Id: parse.c,v 1.100 2005/05/20 03:45:23 nishida Exp $
  */
 
 #include "mgp.h"
@@ -975,23 +975,27 @@
 	tmpstr[5]->ctc2_value1 = strdup("k14");
 	tmpstr[5]->ctc2_value2 = strdup("jisx0208.1983-*");
 #ifdef USE_M17N
-	tmpstr[6] = ctlalloc1(CTL_M17N);
-	tmpstr[6]->ctc2_value1 = strdup("fontset");
-	tmpstr[6]->ctc2_value2 = strdup("default");
-	tmpstr[7] = ctlalloc1(CTL_M17N);
-	tmpstr[7]->ctc2_value1 = strdup("family");
-	tmpstr[7]->ctc2_value2 = strdup("default");
-	tmpstr[8] = ctlalloc1(CTL_M17N);
-	tmpstr[8]->ctc2_value1 = strdup("language");
-	tmpstr[8]->ctc2_value2 = strdup("default");
-#else
-	tmpstr[6] = ctlalloc1(CTL_NOOP);	
-	tmpstr[6]->ctc_value = strdup("");
-	tmpstr[7] = ctlalloc1(CTL_NOOP);	
-	tmpstr[7]->ctc_value = strdup("");
-	tmpstr[8] = ctlalloc1(CTL_NOOP);	
-	tmpstr[8]->ctc_value = strdup("");
+	if (! (mgp_flag & FL_NOM17N)) {
+		tmpstr[6] = ctlalloc1(CTL_M17N);
+		tmpstr[6]->ctc2_value1 = strdup("fontset");
+		tmpstr[6]->ctc2_value2 = NULL;
+		tmpstr[7] = ctlalloc1(CTL_M17N);
+		tmpstr[7]->ctc2_value1 = strdup("family");
+		tmpstr[7]->ctc2_value2 = NULL;
+		tmpstr[8] = ctlalloc1(CTL_M17N);
+		tmpstr[8]->ctc2_value1 = strdup("language");
+		tmpstr[8]->ctc2_value2 = NULL;
+	} else
 #endif
+	{
+		tmpstr[6] = ctlalloc1(CTL_NOOP);	
+		tmpstr[6]->ctc_value = strdup("");
+		tmpstr[7] = ctlalloc1(CTL_NOOP);	
+		tmpstr[7]->ctc_value = strdup("");
+		tmpstr[8] = ctlalloc1(CTL_NOOP);	
+		tmpstr[8]->ctc_value = strdup("");
+	}
+
 	tmplong[0] = ctlalloc1(CTL_FORE);
 	get_color(DEFAULT_FORE, &tmplong[0]->ctl_value);
 	tmplong[1] = ctlalloc1(CTL_BACK);
Index: kit/image/gif.h
diff -u kit/image/gif.h:1.2 kit/image/gif.h:removed
--- kit/image/gif.h:1.2	Mon Dec 28 17:23:03 1998
+++ kit/image/gif.h	Mon May 23 05:10:01 2005
@@ -1,72 +0,0 @@
-/* gif.h:
- *
- * gifin.h
- * kirk johnson
- * november 1989
- * external interface to gifin.c
- *
- * Copyright 1989 Kirk L. Johnson (see the included file
- * "kljcpyrght.h" for complete copyright information)
- */
-
-/*
- * gifin return codes
- */
-#define GIFIN_SUCCESS       0   /* success */
-#define GIFIN_DONE          1   /* no more images */
-
-#define GIFIN_ERR_BAD_SD   -1   /* bad screen descriptor */
-#define GIFIN_ERR_BAD_SEP  -2   /* bad image separator */
-#define GIFIN_ERR_BAD_SIG  -3   /* bad signature */
-#define GIFIN_ERR_EOD      -4   /* unexpected end of raster data */
-#define GIFIN_ERR_EOF      -5   /* unexpected end of input stream */
-#define GIFIN_ERR_FAO      -6   /* file already open */
-#define GIFIN_ERR_IAO      -7   /* image already open */
-#define GIFIN_ERR_NFO      -8   /* no file open */
-#define GIFIN_ERR_NIO      -9   /* no image open */
-
-/*
- * colormap indices 
- */
-
-#define GIF_RED  0
-#define GIF_GRN  1
-#define GIF_BLU  2
-
-/*
- * typedef BYTE for convenience
- */
-
-typedef unsigned char BYTE;
-
-static int gifin_open_file();
-static int gifin_open_image();
-static int gifin_get_pixel();
-#if 0
-static int gifin_close_image();
-#endif
-static int gifin_close_file();
-static int gifin_load_cmap();
-static int gifin_skip_extension();
-static int gifin_read_data_block();
-static int gifin_push_string();
-static void gifin_add_string();
-static void gifin_fatal();
-
-/* #defines, typedefs, and such
- */
-
-#define GIF_SIG      "GIF87a"
-#define GIF_SIG_89   "GIF89a"
-#define GIF_SIG_LEN  6          /* GIF signature length */
-#define GIF_SD_SIZE  7          /* GIF screen descriptor size */
-#define GIF_ID_SIZE  9          /* GIF image descriptor size */
-
-#define GIF_SEPARATOR   ','     /* GIF image separator */
-#define GIF_EXTENSION   '!'     /* GIF extension block marker */
-#define GIF_TERMINATOR  ';'     /* GIF terminator */
-
-#define STAB_SIZE  4096         /* string table size */
-#define PSTK_SIZE  4096         /* pixel stack size */
-
-#define NULL_CODE  -1           /* string table null code */
Index: kit/sample/cloud.gif
Index: kit/sample/dad.gif
Index: kit/sample/dns-jp.mgp
diff -u kit/sample/dns-jp.mgp:1.5 kit/sample/dns-jp.mgp:removed
--- kit/sample/dns-jp.mgp:1.5	Fri Sep  4 21:33:18 1998
+++ kit/sample/dns-jp.mgp	Mon May 23 05:10:01 2005
@@ -1,130 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%
-%%	This file is automatically created from the file
-%%	main.pre modified at Fri Jan 23 14:31:24 1998
-%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%
-%include "default.mgp"
-%% "noop" cancels definitions in default.mgp
-%default 1 left, size 7, fore "light yellow", back "blue4", font "standard", ccolor "white", vgap 35
-%default 2 noop
-%default 3 fore "white", bar "gray70", vgap 10
-%default 4 noop
-%tab 1 noop
-%tab 2 noop
-%tab 3 noop
-%%%
-%page
-%nodefault
-%fore "red", back "blue4", size 9, vgap 15
-%center, fore "yellow", font "thick"
-%ccolor "white"
-
-
-
-Root DNS `M' $B$K$D$$$F(B
-
-%size 6, fore "red", font "thick"
-$B2CF#(B   $BO/(B
-
-%size 5, fore "white", font "standard"
-$BEl5~Bg3XBg7?7W;;5!%;%s%?!<(B
-
-
-%font "typewriter"
-kato@wide.ad.jp
-%font "standard"
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%page
-
-%back "blue4"
-  $B7P0^(B (1)
-%fore "red", size 6, font "thick"
-   $B!y(B Root DNS
-%fore "white", size 5, font "standard"
-       $B!&(B $B#9Bf$G1?MQ(B
-%fore "white", size 5, font "standard"
-          $B!](B $B#8Bf$,(B US
-          $B!](B Stockholm $B$K#1Bf(B
-%fore "white", size 5, font "standard"
-       $B!&(B $B:GBg$G#1#3Bf(B
-%fore "white", size 5, font "standard"
-          $B!](B $B%Q%1%C%HD9$N@)Ls(B
-%fore "red", size 6, font "thick"
-   $B!y(B Root DNS $B$N1?MQ4p=`(B
-%fore "white", size 5, font "standard"
-       $B!&(B RFC 2010
-       $B!&(B gTLD $B$H$N4X78(B
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%page
-
-%back "blue4"
-  $B7P0^(B (2)
-%fore "red", size 6, font "thick"
-   $B!y(B IEPG $B$G3HD%$r8!F$(B
-   $B!y(B $B%h!<%m%C%QCO0h(B
-%fore "white", size 5, font "standard"
-       $B!&(B LINX $B$K?7@_(B : 1997 $BG/(B 4 $B7n(B
-%fore "white", size 5, font "standard"
-          $B!](B RIPE/NCC $B$,4IM}(B
-          $B!](B `K'
-%fore "red", size 6, font "thick"
-   $B!y(B $B%"%8%"B@J?MNCO0h(B
-%fore "white", size 5, font "standard"
-       $B!&(B NSPIXP-2 $B!'(B 1997 $BG/(B 8 $B7n(B
-%fore "white", size 5, font "standard"
-          $B!](B WIDE $B$,4IM}(B
-          $B!](B `M'
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%page
-
-%back "blue4"
-  `M'
-%fore "red", size 6, font "thick"
-   $B!y(B $B9=@.(B
-%fore "white", size 5, font "standard"
-       $B!&(B $B#2Bf$N(B PentiumPro 200MHz
-       $B!&(B Primary/Backup$B!"(B $B<+F0@Z$jBX$((B
-%fore "red", size 6, font "thick"
-   $B!y(B Root-only $B%5!<%P(B
-%fore "white", size 5, font "standard"
-       $B!&(B 
-%cont, font "typewriter"
-202.12.27.33
-%font "standard"
-       $B!&(B 400 $B!A(B 500 query/sec
-%fore "red", size 6, font "thick"
-   $B!y(B $B1?MQ4IM}(B
-%fore "white", size 5, font "standard"
-       $B!&(B WIDE $B$*$h$S(B ISP $BM-;V(B
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%page
-
-%back "blue4"
-  $B$*4j$$(B
-%fore "red", size 6, font "thick"
-   $B!y(B $B:G?7$N(B root.cache $B$NF~$l49$((B
-%fore "white", size 5, font "standard"
-       $B!&(B 
-%cont, font "typewriter"
-1997082200
-%fore "red", size 6, font "thick"
-   $B!y(B Named $B$N99?7(B
-%fore "white", size 5, font "standard"
-       $B!&(B 4.9.6/8.8.1
-%fore "red", size 6, font "thick"
-   $B!y(B $BM7$P$J$$$G!'(B
-%fore "white", size 5, font "standard"
-       $B!&(B 
-%cont, font "typewriter"
-ping/traceroute
-%font "standard"
-       $B!&(B 
-%cont, font "typewriter"
-telnet/spray/...
-%fore "red", size 6, font "thick"
-   $B!y(B Thanks to
-%fore "white", size 5, font "standard"
-       $B!&(B $BF|K\(B Cisco/$BB?$/$N(B ISP
-       $B!&(B `M' $B4IM}%0%k!<%W(B
Index: kit/sample/mgp-old1.gif
Index: kit/sample/mgp-old2.gif
Index: kit/sample/mgp-old3.gif
Index: kit/sample/mgp1.gif
Index: kit/sample/mgp2.gif
Index: kit/sample/mgp3.gif
Index: kit/sample/v6header.gif
