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 Mar  6 05:10:03 2000
@@ -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/Imakefile.in
diff -u kit/Imakefile.in:1.49 kit/Imakefile.in:1.50
--- kit/Imakefile.in:1.49	Wed Aug 18 21:13:01 1999
+++ kit/Imakefile.in	Fri Mar  3 03:05:30 2000
@@ -1,4 +1,4 @@
-# $Id: Imakefile.in,v 1.49 1999/08/18 12:13:01 kazu Exp $
+# $Id: Imakefile.in,v 1.50 2000/03/02 18:05:30 nishida Exp $
 
 @SET_MAKE@
 srcdir=	@srcdir@
@@ -127,7 +127,7 @@
 
 distclean:: clean
 	-/bin/rm -f config.status config.log config.cache ctlwords.h
-	-/bin/rm -f scanner.c grammar.c tokdefs.h mgp.0 mgp2ps.0
+	-/bin/rm -f scanner.c grammar.c tokdefs.h mgp.0 mgp2ps.0 mgpembed.pl
 	-/bin/rm -f contrib/mgp2html.pl contrib/mgp2latex.pl
 	for i in $(SUBDIRS); do \
 		(cd $$i; if [ -f Makefile ]; then make distclean; fi); \
Index: kit/background.c
diff -u kit/background.c:1.12 kit/background.c:1.14
--- kit/background.c:1.12	Mon Dec 28 17:22:22 1998
+++ kit/background.c	Sun Mar  5 16:26:29 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: background.c,v 1.12 1998/12/28 08:22:22 itojun Exp $
+ * $Id: background.c,v 1.14 2000/03/05 07:26:29 nishida Exp $
  */
 
 #include <math.h>
@@ -83,8 +83,16 @@
 				y1 += step;
 				p += (dpy * step);
 			}
+#ifdef DITHERED_BGRAD
+			for (z = z1; z < z2; z+=3){
+				*(p + z * dpz) =     x1 * (30 + (y1 % 3)) / 32 & mask;
+				*(p + (z+1) * dpz) = x1 * (30 + ((y1 + 2) % 3)) / 32 & mask;
+				*(p + (z+2) * dpz) = x1 * (30 + ((y1 + 1) % 3)) / 32 & mask;
+			}
+#else
 			for (z = z1; z < z2; z++)
 				*(p + z * dpz) = x1 & mask;
+#endif
 		}
 	} else {
 		if (y1 > y2) {
@@ -106,8 +114,16 @@
 				s += dy;
 				x1 += step;
 			}
+#ifdef DITHERED_BGRAD
+			for (z = z1; z < z2; z+=3){
+				*(p + z * dpz) =     x1 * (30 + (y1 % 3)) / 32 & mask;
+				*(p + (z+1) * dpz) = x1 * (30 + ((y1 + 2) % 3)) / 32 & mask;
+				*(p + (z+2) * dpz) = x1 * (30 + ((y1 + 1) % 3)) / 32 & mask;
+			}
+#else
 			for (z = z1; z < z2; z++)
 				*(p + z * dpz) = x1 & mask;
+#endif
 		}
 	}
 }
Index: kit/configure
diff -u kit/configure:1.73 kit/configure:1.75
--- kit/configure:1.73	Wed Feb 23 00:28:55 2000
+++ kit/configure	Fri Mar  3 03:05:32 2000
@@ -1420,12 +1420,18 @@
 fi
 
 for i in /usr/pkg /usr/local; do
-	if test -f $i/include/png.h -a -f $i/lib/libpng.a; then
+	if test -f $i/include/png.h; then 
+		if test -f $i/lib/libpng.a ; then
+			DEPLIBS="$DEPLIBS $i/lib/libpng.a"
+		elif test -f $i/lib/libpng.so ; then
+			DEPLIBS="$DEPLIBS $i/lib/libpng.so"
+		else
+			break;
+		fi
 		LIBS="$LIBS -L$i/lib"
 		OPTFLAGS="$OPTFLAGS -I$i/include"
-		DEPLIBS="$DEPLIBS $i/lib/libpng.a"
 		echo $ac_n "checking for png_write_init in -lpng""... $ac_c" 1>&6
-echo "configure:1429: checking for png_write_init in -lpng" >&5
+echo "configure:1435: checking for png_write_init in -lpng" >&5
 ac_lib_var=`echo png'_'png_write_init | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1433,7 +1439,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lpng  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1437 "configure"
+#line 1443 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1444,7 +1450,7 @@
 png_write_init()
 ; return 0; }
 EOF
-if { (eval echo configure:1448: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1454: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1459,22 +1465,59 @@
 fi
 if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
   echo "$ac_t""yes" 1>&6
-    ac_tr_lib=HAVE_LIB`echo png | sed -e 's/[^a-zA-Z0-9_]/_/g' \
-    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
-  cat >> confdefs.h <<EOF
-#define $ac_tr_lib 1
+  LIBS="$LIBS -lpng"
+			 cat >> confdefs.h <<\EOF
+#define USE_PNG 1
 EOF
 
-  LIBS="-lpng $LIBS"
-
 else
   echo "$ac_t""no" 1>&6
+echo $ac_n "checking for png_read_init in -lpng""... $ac_c" 1>&6
+echo "configure:1477: checking for png_read_init in -lpng" >&5
+ac_lib_var=`echo png'_'png_read_init | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lpng -lz $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 1485 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char png_read_init();
+
+int main() {
+png_read_init()
+; return 0; }
+EOF
+if { (eval echo configure:1496: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
 fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
 
-		cat >> confdefs.h <<\EOF
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  LIBS="$LIBS -lpng -lz"
+			 cat >> confdefs.h <<\EOF
 #define USE_PNG 1
 EOF
 
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+fi
+
 		break
 	fi
 done
@@ -1484,7 +1527,7 @@
 # Uses ac_ vars as temps to allow command line to override cache and checks.
 # --without-x overrides everything else, but does not touch the cache.
 echo $ac_n "checking for X""... $ac_c" 1>&6
-echo "configure:1488: checking for X" >&5
+echo "configure:1531: checking for X" >&5
 
 # Check whether --with-x or --without-x was given.
 if test "${with_x+set}" = set; then
@@ -1546,12 +1589,12 @@
 
   # First, try using that file with no special directory specified.
 cat > conftest.$ac_ext <<EOF
-#line 1550 "configure"
+#line 1593 "configure"
 #include "confdefs.h"
 #include <$x_direct_test_include>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1555: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1598: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1620,14 +1663,14 @@
   ac_save_LIBS="$LIBS"
   LIBS="-l$x_direct_test_library $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1624 "configure"
+#line 1667 "configure"
 #include "confdefs.h"
 
 int main() {
 ${x_direct_test_function}()
 ; return 0; }
 EOF
-if { (eval echo configure:1631: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1674: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   LIBS="$ac_save_LIBS"
 # We can link X programs with no special library path.
@@ -1714,7 +1757,7 @@
 fi
 
 echo $ac_n "checking if --enable-gif option specified""... $ac_c" 1>&6
-echo "configure:1718: checking if --enable-gif option specified" >&5
+echo "configure:1761: checking if --enable-gif option specified" >&5
 # Check whether --enable-gif or --disable-gif was given.
 if test "${enable_gif+set}" = set; then
   enableval="$enable_gif"
@@ -1726,7 +1769,7 @@
 echo "$ac_t""$mgp_gif" 1>&6
 if test $mgp_gif = "yes"; then
 	echo $ac_n "checking for DGifOpenFileHandle in -lungif""... $ac_c" 1>&6
-echo "configure:1730: checking for DGifOpenFileHandle in -lungif" >&5
+echo "configure:1773: checking for DGifOpenFileHandle in -lungif" >&5
 ac_lib_var=`echo ungif'_'DGifOpenFileHandle | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1734,7 +1777,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lungif  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1738 "configure"
+#line 1781 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1745,7 +1788,7 @@
 DGifOpenFileHandle()
 ; return 0; }
 EOF
-if { (eval echo configure:1749: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1792: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1769,7 +1812,7 @@
 else
   echo "$ac_t""no" 1>&6
 echo $ac_n "checking for DGifOpenFileHandle in -lgif""... $ac_c" 1>&6
-echo "configure:1773: checking for DGifOpenFileHandle in -lgif" >&5
+echo "configure:1816: checking for DGifOpenFileHandle in -lgif" >&5
 ac_lib_var=`echo gif'_'DGifOpenFileHandle | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1777,7 +1820,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lgif  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1781 "configure"
+#line 1824 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1788,7 +1831,7 @@
 DGifOpenFileHandle()
 ; return 0; }
 EOF
-if { (eval echo configure:1792: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1835: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1812,7 +1855,7 @@
 else
   echo "$ac_t""no" 1>&6
 echo $ac_n "checking for DGifOpenFileName in -lungif""... $ac_c" 1>&6
-echo "configure:1816: checking for DGifOpenFileName in -lungif" >&5
+echo "configure:1859: checking for DGifOpenFileName in -lungif" >&5
 ac_lib_var=`echo ungif'_'DGifOpenFileName | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1820,7 +1863,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lungif -L$x_libraries -lX11 $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1824 "configure"
+#line 1867 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1831,7 +1874,7 @@
 DGifOpenFileName()
 ; return 0; }
 EOF
-if { (eval echo configure:1835: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1878: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1855,7 +1898,7 @@
 else
   echo "$ac_t""no" 1>&6
 echo $ac_n "checking for DGifOpenFilename in -lgif""... $ac_c" 1>&6
-echo "configure:1859: checking for DGifOpenFilename in -lgif" >&5
+echo "configure:1902: checking for DGifOpenFilename in -lgif" >&5
 ac_lib_var=`echo gif'_'DGifOpenFilename | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1863,7 +1906,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lgif -L$x_libraries -lX11 $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1867 "configure"
+#line 1910 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1874,7 +1917,7 @@
 DGifOpenFilename()
 ; return 0; }
 EOF
-if { (eval echo configure:1878: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1921: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1923,12 +1966,12 @@
 fi
 
 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:1927: checking for ANSI C header files" >&5
+echo "configure:1970: checking for ANSI C header files" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1932 "configure"
+#line 1975 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdarg.h>
@@ -1936,7 +1979,7 @@
 #include <float.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1940: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1983: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1953,7 +1996,7 @@
 if test $ac_cv_header_stdc = yes; then
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1957 "configure"
+#line 2000 "configure"
 #include "confdefs.h"
 #include <string.h>
 EOF
@@ -1971,7 +2014,7 @@
 if test $ac_cv_header_stdc = yes; then
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1975 "configure"
+#line 2018 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 EOF
@@ -1992,7 +2035,7 @@
   :
 else
   cat > conftest.$ac_ext <<EOF
-#line 1996 "configure"
+#line 2039 "configure"
 #include "confdefs.h"
 #include <ctype.h>
 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
@@ -2003,7 +2046,7 @@
 exit (0); }
 
 EOF
-if { (eval echo configure:2007: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2050: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   :
 else
@@ -2027,12 +2070,12 @@
 fi
 
 echo $ac_n "checking for sys/wait.h that is POSIX.1 compatible""... $ac_c" 1>&6
-echo "configure:2031: checking for sys/wait.h that is POSIX.1 compatible" >&5
+echo "configure:2074: checking for sys/wait.h that is POSIX.1 compatible" >&5
 if eval "test \"`echo '$''{'ac_cv_header_sys_wait_h'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2036 "configure"
+#line 2079 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -2048,7 +2091,7 @@
 s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;
 ; return 0; }
 EOF
-if { (eval echo configure:2052: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2095: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_header_sys_wait_h=yes
 else
@@ -2072,17 +2115,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:2076: checking for $ac_hdr" >&5
+echo "configure:2119: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2081 "configure"
+#line 2124 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2086: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2129: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2110,12 +2153,12 @@
 
 
 echo $ac_n "checking for working const""... $ac_c" 1>&6
-echo "configure:2114: checking for working const" >&5
+echo "configure:2157: checking for working const" >&5
 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2119 "configure"
+#line 2162 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -2164,7 +2207,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:2168: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2211: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_const=yes
 else
@@ -2185,21 +2228,21 @@
 fi
 
 echo $ac_n "checking for inline""... $ac_c" 1>&6
-echo "configure:2189: checking for inline" >&5
+echo "configure:2232: checking for inline" >&5
 if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_cv_c_inline=no
 for ac_kw in inline __inline__ __inline; do
   cat > conftest.$ac_ext <<EOF
-#line 2196 "configure"
+#line 2239 "configure"
 #include "confdefs.h"
 
 int main() {
 } $ac_kw foo() {
 ; return 0; }
 EOF
-if { (eval echo configure:2203: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2246: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_inline=$ac_kw; break
 else
@@ -2225,12 +2268,12 @@
 esac
 
 echo $ac_n "checking for pid_t""... $ac_c" 1>&6
-echo "configure:2229: checking for pid_t" >&5
+echo "configure:2272: checking for pid_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_pid_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2234 "configure"
+#line 2277 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
@@ -2258,12 +2301,12 @@
 fi
 
 echo $ac_n "checking for size_t""... $ac_c" 1>&6
-echo "configure:2262: checking for size_t" >&5
+echo "configure:2305: checking for size_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2267 "configure"
+#line 2310 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
@@ -2291,12 +2334,12 @@
 fi
 
 echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6
-echo "configure:2295: checking whether time.h and sys/time.h may both be included" >&5
+echo "configure:2338: checking whether time.h and sys/time.h may both be included" >&5
 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2300 "configure"
+#line 2343 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/time.h>
@@ -2305,7 +2348,7 @@
 struct tm *tp;
 ; return 0; }
 EOF
-if { (eval echo configure:2309: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2352: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_header_time=yes
 else
@@ -2326,12 +2369,12 @@
 fi
 
 echo $ac_n "checking for u_int""... $ac_c" 1>&6
-echo "configure:2330: checking for u_int" >&5
+echo "configure:2373: checking for u_int" >&5
 if eval "test \"`echo '$''{'ac_cv_type_u_int'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2335 "configure"
+#line 2378 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
@@ -2359,12 +2402,12 @@
 fi
 
 echo $ac_n "checking for u_char""... $ac_c" 1>&6
-echo "configure:2363: checking for u_char" >&5
+echo "configure:2406: checking for u_char" >&5
 if eval "test \"`echo '$''{'ac_cv_type_u_char'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2368 "configure"
+#line 2411 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
@@ -2393,7 +2436,7 @@
 
 
 echo $ac_n "checking for 8-bit clean memcmp""... $ac_c" 1>&6
-echo "configure:2397: checking for 8-bit clean memcmp" >&5
+echo "configure:2440: checking for 8-bit clean memcmp" >&5
 if eval "test \"`echo '$''{'ac_cv_func_memcmp_clean'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2401,7 +2444,7 @@
   ac_cv_func_memcmp_clean=no
 else
   cat > conftest.$ac_ext <<EOF
-#line 2405 "configure"
+#line 2448 "configure"
 #include "confdefs.h"
 
 main()
@@ -2411,7 +2454,7 @@
 }
 
 EOF
-if { (eval echo configure:2415: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2458: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_func_memcmp_clean=yes
 else
@@ -2429,12 +2472,12 @@
 test $ac_cv_func_memcmp_clean = no && LIBOBJS="$LIBOBJS memcmp.${ac_objext}"
 
 echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6
-echo "configure:2433: checking return type of signal handlers" >&5
+echo "configure:2476: checking return type of signal handlers" >&5
 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2438 "configure"
+#line 2481 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <signal.h>
@@ -2451,7 +2494,7 @@
 int i;
 ; return 0; }
 EOF
-if { (eval echo configure:2455: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2498: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_type_signal=void
 else
@@ -2472,12 +2515,12 @@
 for ac_func in poll strstr _setbufend
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2476: checking for $ac_func" >&5
+echo "configure:2519: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2481 "configure"
+#line 2524 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -2500,7 +2543,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:2504: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2547: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -2527,12 +2570,12 @@
 for ac_func in usleep strsep strdup mkstemp snprintf memcmp
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2531: checking for $ac_func" >&5
+echo "configure:2574: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2536 "configure"
+#line 2579 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -2555,7 +2598,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:2559: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2602: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
Index: kit/configure.in
diff -u kit/configure.in:1.70 kit/configure.in:1.72
--- kit/configure.in:1.70	Wed Feb 23 00:28:57 2000
+++ kit/configure.in	Fri Mar  3 03:05:33 2000
@@ -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.70 2000/02/22 15:28:57 nishida Exp $
+dnl $Id: configure.in,v 1.72 2000/03/02 18:05:33 nishida Exp $
 AC_INIT(image/imagetypes.c)
 
 dnl Checks for programs.
@@ -224,12 +224,23 @@
 fi
 
 for i in /usr/pkg /usr/local; do
-	if test -f $i/include/png.h -a -f $i/lib/libpng.a; then
+	if test -f $i/include/png.h; then 
+		if test -f $i/lib/libpng.a ; then
+			DEPLIBS="$DEPLIBS $i/lib/libpng.a"
+		elif test -f $i/lib/libpng.so ; then
+			DEPLIBS="$DEPLIBS $i/lib/libpng.so"
+		else
+			break;
+		fi
 		LIBS="$LIBS -L$i/lib"
 		OPTFLAGS="$OPTFLAGS -I$i/include"
-		DEPLIBS="$DEPLIBS $i/lib/libpng.a"
-		AC_CHECK_LIB(png, png_write_init)
-		AC_DEFINE(USE_PNG)
+		AC_CHECK_LIB(png, png_write_init, 
+			[LIBS="$LIBS -lpng"
+			 AC_DEFINE(USE_PNG)], 
+		[AC_CHECK_LIB(png, png_read_init, 
+			[LIBS="$LIBS -lpng -lz"
+			 AC_DEFINE(USE_PNG)],
+			[], [-lz])])
 		break
 	fi
 done
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 Mar  6 05:10:10 2000
@@ -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.164 kit/draw.c:1.169
--- kit/draw.c:1.164	Wed Feb 23 01:34:18 2000
+++ kit/draw.c	Sun Mar  5 16:26:30 2000
@@ -26,13 +26,13 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: draw.c,v 1.164 2000/02/22 16:34:18 nishida Exp $
+ * $Id: draw.c,v 1.169 2000/03/05 07:26:30 nishida Exp $
  */
 
 #include "mgp.h"
 
 /* state associated with the window - how should we treat this? */
-static struct ctrl *bg_ctl, *bg_ctl_last;
+static struct ctrl *bg_ctl, *bg_ctl_last, *bg_ctl_cache;
 static int bgindex = 0;
 struct render_state cache_state;
 
@@ -118,18 +118,15 @@
 static char *x_findseed __P((struct render_state *, char *));
 
 static void XClearPixmap __P((Display *, Drawable));
-static void XSetPixmapBackgroundPixmap __P((Display *, Drawable, Pixmap, 
-	int, int));
-static void XSetPixmapBackground __P((Display *, Drawable, u_long));
 static void cache_page __P((struct render_state *, int));
 static void cache_effect1 __P((void));
 static void cache_effect2 __P((void));
 static void set_from_cache __P((struct render_state *));
 static void pcache_process __P((int));
-static void regist_bgcache __P((XImageInfo *, Image *));
-static int check_bgcache __P((void));
-static int regist_bgpixmap __P((void));
-static void set_bgwindow __P((struct ctrl *));
+static void predraw __P((struct render_state *));
+static void set_background_pixmap __P((struct ctrl *));
+static void get_background_pixmap __P((struct ctrl *, struct render_state *));
+static void regist_background_pixmap __P((XImageInfo *, Image *));
 
 #define CHECK_CACHE {if (caching){caching = -1; return;}}
 
@@ -163,12 +160,17 @@
 	if (!repaint)
 		purgechild(state->page);
 
-	free_alloc_colors(&image_clr);
-	free_alloc_colors(&font_clr);
 	state->page = page;
 	state->line = 0;
 	state->cp = NULL;
 	state->phase = P_NONE;
+	free_alloc_colors(&image_clr);
+	free_alloc_colors(&font_clr);
+
+#ifdef COLOR_BUGFIX
+	colormap = XCopyColormapAndFree(display, colormap);
+#endif
+	predraw(state);
 }
 
 void
@@ -252,6 +254,13 @@
 {
 	state->ypos = 0;
 	state->have_mark = 0;
+	free_alloc_colors(&image_clr);
+	free_alloc_colors(&font_clr);
+
+#ifdef COLOR_BUGFIX
+	colormap = XCopyColormapAndFree(display, colormap);
+#endif
+	predraw(state);
 }
 
 /*
@@ -496,6 +505,7 @@
 		break;
 
 	case CTL_BACK:
+		back_color[caching] = cp->ctl_value;
 		bg_ctl = cp;	/*update later*/
 		break;
 
@@ -625,42 +635,38 @@
 
 	case CTL_LINESTART:
 		if (state->line == 0) {
+			/*
+			 * set background of target 
+			 */
 			if (bg_ctl) {
-				if (check_bgcache()){
-					if (!caching)  set_bgwindow(bg_ctl);
-					; /* same as the last time */
-				} else if (bg_ctl->ct_op == CTL_BIMAGE) {
-				    image_load(state, bg_ctl->ctm_fname,
-					bg_ctl->ctm_numcolor,
-					bg_ctl->ctm_ximagesize,
-					bg_ctl->ctm_yimagesize, 1,
-					bg_ctl->ctm_zoomflag, 0);
-				} else if (bg_ctl->ct_op == CTL_BGRAD) {
-					back_gradation(state,
-						&bg_ctl->ct_val.ctrl_grad);
-				} else if (bg_ctl->ct_op == CTL_BACK) {
-					if (!caching){
-						bg_ctl_last = bg_ctl;
-						XSetWindowBackground(display,
-							state->target, bg_ctl->ctl_value);
+				if (!caching){
+					/* target is window, so we need care bg_ctl_last */
+					if (bg_ctl_last && !ctlcmp(bg_ctl, bg_ctl_last)){
+						/* same as last time, we do nothing  */
+						;
 					} else {
-						XSetPixmapBackground(display,
-							state->target, bg_ctl->ctl_value);
+						/* we have to change background */
+						get_background_pixmap(bg_ctl, state);
+
+						/* set window background */
+						set_background_pixmap(bg_ctl);
+
+						bg_ctl_last = bg_ctl;
 					}
-					back_color[caching] = bg_ctl->ctl_value;
+					XClearWindow(display, state->target);
 				} else {
-					fprintf(stderr, "internal error: "
-						"bogus background\n");
-					cleanup(-1);
+					get_background_pixmap(bg_ctl, state);
+					bg_ctl_cache = bg_ctl;
+
+					XClearPixmap(display, state->target);
 				}
+			} else {
+				if (!caching)
+					XClearWindow(display, state->target);
+				else
+					XClearPixmap(display, state->target);
 			}
 
-			if (!caching) { 
-				XClearWindow(display, state->target);
-				bg_ctl_last = bg_ctl;
-			} else 
-				XClearPixmap(display, state->target);
-
 			if (t_fin)
 				timebar(state);
 		}
@@ -1610,8 +1616,8 @@
 		bw = bh = 0;	/* for lint */
 		goto end;
 	}
-	bh = bgcache[bgindex].image->height;
-	bw = bgcache[bgindex].image->width;
+	bh = bgpixmap[bgindex].image->height;
+	bw = bgpixmap[bgindex].image->width;
 	j = 0;
 	if (image->type == IBITMAP) {
   expand:
@@ -1624,7 +1630,7 @@
 	}
 	pl = image->pixlen;
 	p = image->data + image->width * j * pl;
-	bpl = bgcache[bgindex].image->pixlen;
+	bpl = bgpixmap[bgindex].image->pixlen;
 	pd = -1;
 	n = 0;	/* for lint */
 	trans = image->trans;
@@ -1632,19 +1638,21 @@
 	for ( ; j < image->height; j++) {
 		by = (y + j) % bh;
 		bx = x % bw;
-		b = bgcache[bgindex].image->data + (bgcache[bgindex].image->width * by + bx) * bpl;
+		b = bgpixmap[bgindex].image->data + 
+			(bgpixmap[bgindex].image->width * by + bx) * bpl;
 		for (i = 0; i < image->width; i++, p += pl, b += bpl, bx++) {
 			if (bx == bw) {
 				bx = 0;
-				b = bgcache[bgindex].image->data + 
-					bgcache[bgindex].image->width * by * bpl;
+				b = bgpixmap[bgindex].image->data + 
+					bgpixmap[bgindex].image->width * by * bpl;
 			}
 			if (memToVal(p, pl) != trans)
 				continue;
 			d = memToVal(b, bpl);
 			if (d != pd) {
 				pd = d;
-				n = obj_image_color(image, bgcache[bgindex].image, d, &inithist);
+				n = obj_image_color(image, 
+						bgpixmap[bgindex].image, d, &inithist);
 				if (n == -1)
 					goto expand;
 			}
@@ -1666,7 +1674,7 @@
 		fprintf(stderr, "  image=%dx%d+%d+%d",
 			image->width, image->height, x, y);
 		if (COMPLEX_BGIMAGE)
-			fprintf(stderr, "  bgcache[bgindex].image=%dx%d", bw, bh);
+			fprintf(stderr, "  bgpixmap[bgindex].image=%dx%d", bw, bh);
 		fprintf(stderr, "\n");
 	}
 	image->trans = -1;	/* XXX: need recalculation to redraw? */
@@ -1797,7 +1805,7 @@
 			int bpl;
 			XColor col;
 
-			bim = bgcache[bgindex].ximageinfo->ximage;
+			bim = bgpixmap[bgindex].ximageinfo->ximage;
 			bw = bim->width;
 			bh = bim->height;
 			ox = xpos;
@@ -1806,22 +1814,22 @@
 			by = oy % bh;
 			if (bw == 1) {
 				r = g = b = 0;
-				bpl = bgcache[bgindex].image->pixlen;
-				bp = bgcache[bgindex].image->data + by * bpl;
+				bpl = bgpixmap[bgindex].image->pixlen;
+				bp = bgpixmap[bgindex].image->data + by * bpl;
 				for (y = 0;
 				     y < height;
 				     y++, by++, bp += bpl) {
 					if (by == bh)
 						by = 0;
 					p = memToVal(bp, bpl);
-					if (TRUEP(bgcache[bgindex].image)) {
+					if (TRUEP(bgpixmap[bgindex].image)) {
 						r += TRUE_RED(p) << 8;
 						g += TRUE_GREEN(p) << 8;
 						b += TRUE_BLUE(p) << 8;
 					} else {
-						r += bgcache[bgindex].image->rgb.red[p];
-						g += bgcache[bgindex].image->rgb.green[p];
-						b += bgcache[bgindex].image->rgb.blue[p];
+						r += bgpixmap[bgindex].image->rgb.red[p];
+						g += bgpixmap[bgindex].image->rgb.green[p];
+						b += bgpixmap[bgindex].image->rgb.blue[p];
 					}
 					p = XGetPixel(bim, 0, by);
 					for (x = 0; x < width; x++)
@@ -1840,7 +1848,7 @@
 #if 0
 			fprintf(stderr, "bim=%dx%d, r=%x, g=%x, b=%x, "
 				"bcolor=%x\n",
-				bgcache[bgindex].image->width, bgcache[bgindex].image->height,
+				bgpixmap[bgindex].image->width, bgpixmap[bgindex].image->height,
 				col.red, col.green, col.blue, bcolor);
 #endif
 			} else {
@@ -2552,9 +2560,14 @@
 		r = (dir % 180 == 0) ? &dstwidth : &dstheight;
 
 		/* rely upon use X11 background image tiling. */
-		*p = 1;
 		*q = (float) 100.0;
+#ifndef DITHERED_BGRAD
+		*p = 1;
 		*r = 1;
+#else
+		*p = 3;
+		*r = 3;
+#endif
 	}
 
 	if (verbose) {
@@ -2594,33 +2607,17 @@
 		freeImage(image);
 	}
 
+#ifndef COLOR_BUGFIX
 	if (private) free_alloc_colors(&back_clr);
+#endif
 	ximageinfo = imageToXImage(display, screen, visual, depth, myimage,
 		private, 0, 1, verbose);
 	if (!ximageinfo) {
 		fprintf(stderr, "Cannot convert Image to XImage\n");
 		cleanup(-1);
 	}
-
-	mypixmap = ximageToPixmap(display, DefaultRootWindow(display),
-		ximageinfo);
-	if (mypixmap == None) {
-		fprintf(stderr, "Cannot create image in server\n");
-		cleanup(-1);
-	}
 
-	/* draw background */
-	if (!caching){ 
-		bg_ctl_last = bg_ctl;
-		XSetWindowBackgroundPixmap(display, state->target, mypixmap);
-	}
-
-	XSetPixmapBackgroundPixmap(display, state->target, 
-		mypixmap, ximageinfo->ximage->width, ximageinfo->ximage->height);
-
-	/* finish */
-	XFreePixmap(display, mypixmap);
-	regist_bgcache(ximageinfo, myimage);
+	regist_background_pixmap(ximageinfo, myimage);
 
 	XUndefineCursor(display, window);
 	XFlush(display);
@@ -2729,38 +2726,16 @@
 			freeImage(image);
 		}
 
+#ifndef COLOR_BUGFIX
 		if (private) free_alloc_colors(&back_clr);
+#endif
 		ximageinfo= imageToXImage(display, screen, visual, depth,
 				myimage, private, 0, 1, verbose);
 		if (ximageinfo == NULL) {
 			fprintf(stderr, "Cannot convert Image to XImage\n");
 			cleanup(-1);
 		}
-
-		mypixmap = ximageToPixmap(display,
-				RootWindow(display, screen), ximageinfo);
-		if (mypixmap == None) {
-			fprintf(stderr, "Cannot create image in server\n");
-			cleanup(-1);
-		}
-
-		if (!caching){
-			bg_ctl_last = bg_ctl;
-			XSetWindowBackgroundPixmap(display, state->target, mypixmap);
-		} 
-
-		XSetPixmapBackgroundPixmap(display, state->target, mypixmap,
-			ximageinfo->ximage->width, ximageinfo->ximage->height);
-
-		XFreePixmap(display, mypixmap);
-		strcpy(backfile, filename);
-		backnumcolor = numcolor;
-		backzoom = zoomflag;
-		backx = ximagesize;
-		backy = yimagesize;
-
-		regist_bgcache(ximageinfo, myimage);
-
+		regist_background_pixmap(ximageinfo, myimage);
 		goto end;
 	}
 
@@ -3673,20 +3648,21 @@
 			Pixel d;
 
 			/* XXX: use background color of center position */
-			x = (obj->x + image->width/2) % bgcache[bgindex].image->width;
-			y = (state->ypos + image->height/2) % bgcache[bgindex].image->height;
-			bpl = bgcache[bgindex].image->pixlen;
-			p = bgcache[bgindex].image->data 
-				+ (bgcache[bgindex].image->width * y + x) * bpl;
+			x = (obj->x + image->width/2) % bgpixmap[bgindex].image->width;
+			y = (state->ypos + image->height/2) 
+					% bgpixmap[bgindex].image->height;
+			bpl = bgpixmap[bgindex].image->pixlen;
+			p = bgpixmap[bgindex].image->data 
+				+ (bgpixmap[bgindex].image->width * y + x) * bpl;
 			d = memToVal(p, bpl);
-			if (bgcache[bgindex].image->type == ITRUE) {
+			if (bgpixmap[bgindex].image->type == ITRUE) {
 				back.red   = TRUE_RED(d) << 8;
 				back.green = TRUE_GREEN(d) << 8;
 				back.blue  = TRUE_BLUE(d) << 8;
 			} else {
-				back.red   = bgcache[bgindex].image->rgb.red  [d];
-				back.green = bgcache[bgindex].image->rgb.green[d];
-				back.blue  = bgcache[bgindex].image->rgb.blue [d];
+				back.red   = bgpixmap[bgindex].image->rgb.red  [d];
+				back.green = bgpixmap[bgindex].image->rgb.green[d];
+				back.blue  = bgpixmap[bgindex].image->rgb.blue [d];
 			}
 		}
 		for (i = 0; i < image->rgb.used; i++) {
@@ -3826,6 +3802,7 @@
 
 	cp = NULL;
 	for (cp = state->xfont; cp; cp = cp->ct_next) {
+		if (!cp->ctc2_value2) continue;
 		if (strcmp(cp->ctc2_value2, registry) == 0)
 			break;
 	}
@@ -3858,111 +3835,6 @@
 	return "*-*-*";		/*anything, canonicalized*/
 }
 
-static void 
-XSetPixmapBackground(display, target, bgcolor)
-	Display *display;
-	Drawable target;
-	u_long	bgcolor;
-{
-	int	i;
-
-	if ((i = regist_bgpixmap()) < 0) return;
-
-	XSetForeground(display, gc_cache, bgcolor);
-	XFillRectangle(display, bgpixmap[i].pixmap,
-		gc_cache, 0, 0, window_width, window_height);
-}
-
-static void 
-XSetPixmapBackgroundPixmap(display, target, pixmap, width, height)
-	Display *display;
-	Drawable target;
-	Pixmap	pixmap;
-	int	width, height;
-{
-	int	x, y, i;
-
-	if ((i = regist_bgpixmap()) < 0) return;
-
-	for (y = 0; y < window_height; y += height)
-		for (x = 0; x < window_width; x += width){
-			XCopyArea(display, pixmap, bgpixmap[i].pixmap, gc_cache, 0, 0,
-				width, height, x, y);
-		}
-}
-
-static int
-regist_bgpixmap()
-{
-	int	i, j;
-
-	for (i = 0; i < MAXBGPIXMAP; i ++){
-		if (bgpixmap[i].ctl && ctlcmp(bg_ctl, bgpixmap[i].ctl) == 0) 
-			return -1;
-	}
-
-	/* search empty slot */	
-	for (i = 0; i < MAXBGPIXMAP; i ++){
-		if (bgpixmap[i].ctl == NULL)
-			break;
-	}
-	if (i == MAXBGPIXMAP){
-		for (j = 0; j < MAXBGPIXMAP -1; j ++){	
-			bgpixmap[j].ctl = bgpixmap[j+1].ctl;	
-			bgpixmap[j].pixmap = bgpixmap[j+1].pixmap;	
-		}
-		i = 0;
-	}
-	bgpixmap[i].ctl = bg_ctl;
-
-	return i;
-}
-
-static void
-set_bgwindow(ctl)
-	struct ctrl *ctl;
-{
-	int	i;
-
-	if (!ctl || !ctlcmp(bg_ctl_last, ctl)) return; 	
-
-	bg_ctl_last = ctl;
-	if (ctl->ct_op == CTL_BIMAGE || ctl->ct_op == CTL_BGRAD) {
-		for (i = 0; i < MAXBGPIXMAP; i ++){
-			if (bgpixmap[i].ctl && ctlcmp(bg_ctl, bgpixmap[i].ctl) == 0) {
-				XSetWindowBackgroundPixmap(display, window, bgpixmap[i].pixmap);
-				return;
-			}
-		}
-	} else {
-		if (ctl->ct_op == CTL_BACK) 
-			XSetWindowBackground(display, window, ctl->ctl_value);
-		else {
-			fprintf(stderr, "internal error: set_bgwindow()\n"); 
-			cleanup(-1);
-		}
-	}
-}
-
-static void 
-XClearPixmap(display, target)
-	Display *display;
-	Drawable target;
-{
-	int	i;
-
-	for (i = 0; i < MAXBGPIXMAP; i ++){
-		if (bgpixmap[i].ctl && ctlcmp(bg_ctl, bgpixmap[i].ctl) == 0){ 
-			XCopyArea(display, bgpixmap[i].pixmap, cachewin, gc_cache, 
-				0, 0, window_width, window_height, 0, 0);
-			return;
-		}
-	}
-
-	fprintf(stderr, "internal error: XClearPixmap()\n"); 
-	cleanup(-1);
-}
-
 /* cache specified page */
 static void
 cache_page(state, page)
@@ -4011,7 +3883,8 @@
 
 	XSetForeground(display, gcfore, fore_color[0]);
 	XSetBackground(display, gcfore, back_color[0]);
-	set_bgwindow(bgcache[bgindex].ctl);
+	bg_ctl = bg_ctl_last = bg_ctl_cache;
+	set_background_pixmap(bg_ctl);
 
 	switch(cache_effect){
 		case 1:
@@ -4029,61 +3902,25 @@
 }
 
 void
-reset_cache_bgimage()
+reset_background_pixmap()
 {
 	int	i = 0;
 
 	bg_ctl_last = NULL;
 
-	for (i = 0; i < MAXBGCACHE; i ++) {
-		if (bgcache[i].image){
-			freeXImage(bgcache[i].image, bgcache[i].ximageinfo);
-			freeImage(bgcache[i].image);
-		}
-		bgcache[i].ctl = NULL;
-		bgcache[i].image = NULL;
-		bgcache[i].ximageinfo = NULL;
+	for (i = 0; i < MAXBGPIXMAP; i ++) {
+		if (bgpixmap[i].image){
+			XFreePixmap(display, bgpixmap[i].pixmap); 
+			freeXImage(bgpixmap[i].image, bgpixmap[i].ximageinfo);
+			freeImage(bgpixmap[i].image);
+		}
+		bgpixmap[i].ctl = NULL;
+		bgpixmap[i].image = NULL;
+		bgpixmap[i].ximageinfo = NULL;
 	}
 }
 
 static void
-regist_bgcache(ximageinfo, image)
-XImageInfo	*ximageinfo;
-Image	*image;
-{
-	int	i;
-	/* search empty slot */	
-	for (i = 0; i < MAXBGCACHE; i ++){
-		if (bgcache[i].ctl == NULL)
-			break;
-	}
-	if (i == MAXBGCACHE){
-		/* no empty slot, we need to make one  */
-		freeXImage(bgcache[0].image, bgcache[0].ximageinfo);
-		freeImage(bgcache[0].image);
-		i = 0;
-	}
-
-	bgcache[i].ctl = bg_ctl;
-	bgcache[i].image = image;
-	bgcache[i].ximageinfo = ximageinfo;
-	bgindex = i;
-}
-
-static int
-check_bgcache()
-{
-	int	i;
-	for (i = 0; i < MAXBGCACHE; i ++){
-		if (bgcache[i].ctl && ctlcmp(bg_ctl, bgcache[i].ctl) == 0) { 
-			bgindex = i;
-			return 1;
-		}
-	}
-	return 0;
-}
-
-static void
 cache_effect1()
 {
 	int x, step;
@@ -4143,4 +3980,167 @@
 	cache_effect = pcache.effect;
 	cache_value  =  pcache.value;
 	pcache.flag  = 0;
+}
+
+
+/*
+	predraw: if this page contains texts only, 
+			   draw page in pixmap once, then copy to window.
+*/
+static void
+predraw(state)
+	struct render_state *state;
+{
+	if (!caching && cached_page != state->page 
+			&& page_attribute[state->page].pg_text){
+		cache_page(&cache_state, state->page);
+		set_from_cache(state);
+		pcache_process(state->page);
+	}
+}
+
+
+static void
+get_background_pixmap(ctl, state)
+	struct ctrl *ctl;
+	struct render_state *state;
+{
+	int	i;
+
+	/*
+	 * check if background is already cached
+	 */
+	for (i = 0; i < MAXBGPIXMAP; i ++){
+		if (bgpixmap[i].ctl && ctlcmp(ctl, bgpixmap[i].ctl) == 0){
+			bgindex = i;
+			return;			
+		}
+	}
+
+	if (i == MAXBGPIXMAP){
+		/* this background is not cached, we have to generate one */
+		switch(ctl->ct_op){
+		case CTL_BIMAGE: 
+			image_load(state, ctl->ctm_fname, ctl->ctm_numcolor,
+						ctl->ctm_ximagesize, ctl->ctm_yimagesize, 1,
+						ctl->ctm_zoomflag, 0);
+			break;
+		case CTL_BGRAD:
+			back_gradation(state, &ctl->ct_val.ctrl_grad);
+			break;
+		case CTL_BACK:
+		default:
+			break;
+		}
+	}
+}
+
+static void
+regist_background_pixmap(ximageinfo, image)
+	XImageInfo	*ximageinfo;
+	Image		*image;
+{
+	Pixmap	pixmap;
+	int	i, j;
+
+	/* search empty slot */	
+	for (i = 0; i < MAXBGPIXMAP; i ++){
+		if (bgpixmap[i].ctl == NULL)
+			break;
+	}
+
+	if (i == MAXBGPIXMAP){
+		/* no empty slot, we need to make one  */
+		XFreePixmap(display, bgpixmap[MAXBGPIXMAP -1].pixmap); 
+		freeXImage(bgpixmap[MAXBGPIXMAP -1].image, 
+					bgpixmap[MAXBGPIXMAP -1].ximageinfo);
+		freeImage(bgpixmap[MAXBGPIXMAP -1].image);
+		for (j = MAXBGPIXMAP -2; j >= 0; j --){
+			bgpixmap[j +1].ctl = bgpixmap[j].ctl;
+			bgpixmap[j +1].pixmap = bgpixmap[j].pixmap;
+			bgpixmap[j +1].image = bgpixmap[j].image;
+			bgpixmap[j +1].ximageinfo = bgpixmap[j].ximageinfo;
+		}
+		i = 0;
+	}
+
+	pixmap = ximageToPixmap(display, 
+			RootWindow(display, screen), ximageinfo);
+	bgpixmap[i].ctl = bg_ctl;
+	bgpixmap[i].pixmap = pixmap;
+	bgpixmap[i].image = image;
+	bgpixmap[i].ximageinfo = ximageinfo;
+	bgindex = i;
+}
+
+static void
+set_background_pixmap(ctl)
+	struct ctrl *ctl;
+{
+	int	i;
+
+	switch(ctl->ct_op){
+	case CTL_BIMAGE: 
+	case CTL_BGRAD:
+		for (i = 0; i < MAXBGPIXMAP; i ++){
+			if (bgpixmap[i].ctl && ctlcmp(ctl, bgpixmap[i].ctl) == 0)
+				break;	
+		}
+		if (i == MAXBGPIXMAP){
+			fprintf(stderr, "fatal error in set_background_image()\n");
+			cleanup(-1);
+		}
+		XSetWindowBackgroundPixmap(display, window, bgpixmap[i].pixmap);
+		break;
+	case CTL_BACK:
+		XSetWindowBackground(display, window, ctl->ctl_value);
+		break;
+	default:
+		fprintf(stderr, "fatal error in set_background_image()\n");
+		cleanup(-1);
+		break;
+	}
+}
+
+/*
+ * Clear target pixmap 
+ */
+static void
+XClearPixmap(display, target)
+	Display *display;
+	Drawable target;
+{
+	int	i; 
+	int x, y, width, height;
+	XImage *xim;
+
+	switch(bg_ctl->ct_op){
+	case CTL_BIMAGE: 
+	case CTL_BGRAD:
+		for (i = 0; i < MAXBGPIXMAP; i ++){
+			if (bgpixmap[i].ctl && ctlcmp(bg_ctl, bgpixmap[i].ctl) == 0)
+				break;	
+		}
+		if (i == MAXBGPIXMAP){
+			fprintf(stderr, "fatal error in set_background_image()\n");
+			cleanup(-1);
+		}
+
+		xim = bgpixmap[i].ximageinfo->ximage;
+		for (y = 0; y < window_height; y += xim->height)
+			for (x = 0; x < window_width; x += xim->width)
+				XPutImage(display, target, gc_cache, 
+					xim, 0, 0, x, y, 
+					xim->width, xim->height);
+		break;
+	case CTL_BACK:
+		XSetForeground(display, gc_cache, bg_ctl->ctl_value);
+		XFillRectangle(display, target,
+			gc_cache, 0, 0, window_width, window_height);
+		break;
+	default:
+		fprintf(stderr, "fatal error in set_background_image()\n");
+		cleanup(-1);
+		break;
+	}
 }
Index: kit/font.c
diff -u kit/font.c:1.24 kit/font.c:1.25
--- kit/font.c:1.24	Sun Jul  4 00:52:41 1999
+++ kit/font.c	Fri Mar  3 03:05:35 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: font.c,v 1.24 1999/07/03 15:52:41 nishida Exp $
+ * $Id: font.c,v 1.25 2000/03/02 18:05:35 nishida Exp $
  */
 
 #include "mgp.h"
@@ -378,6 +378,10 @@
 	char *fontname;
 {
 	static char *prev_vfcap;
+
+	if ((mgp_flag & FL_NOVFLIB)) {
+		return;
+	}
 
 	if (prev_vfcap != vfcap_name) {
 		/*
Index: kit/globals.c
diff -u kit/globals.c:1.40 kit/globals.c:1.41
--- kit/globals.c:1.40	Fri Sep 10 16:13:50 1999
+++ kit/globals.c	Sun Mar  5 16:26:33 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: globals.c,v 1.40 1999/09/10 07:13:50 itojun Exp $
+ * $Id: globals.c,v 1.41 2000/03/05 07:26:33 nishida Exp $
  */
 
 #include "mgp.h"
@@ -69,7 +69,6 @@
 Pixmap cachewin;
 Pixmap cachetmp;
 struct bgpixmap bgpixmap[MAXBGPIXMAP];
-struct bgcache bgcache[MAXBGCACHE];
 Colormap colormap;
 int free_clr_num;
 u_long *free_clr = NULL;
Index: kit/mgp.c
diff -u kit/mgp.c:1.108 kit/mgp.c:1.110
--- kit/mgp.c:1.108	Mon Dec  6 02:28:42 1999
+++ kit/mgp.c	Sun Mar  5 16:26:34 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: mgp.c,v 1.108 1999/12/05 17:28:42 nishida Exp $
+ * $Id: mgp.c,v 1.110 2000/03/05 07:26:34 nishida Exp $
  */
 
 static char *mgp_version = "1.06a (990728)";
@@ -732,7 +732,12 @@
 
 		if (t_fin)
 			timebar(&state);
+#if 0 /* last page reload bug fix? */
 		if (state.cp && state.cp->ct_op == CTL_PAUSE) {
+#else
+		if ((state.cp && state.cp->ct_op == CTL_PAUSE) 
+			|| (state.page == maxpage)){ 
+#endif 
 			if (tsfile) {
 				int fd;
 				fd = open(tsfile, O_WRONLY|O_TRUNC|O_CREAT,
@@ -955,7 +960,7 @@
 reload:
 					pl_off(&state);
 					cached_page = 0;
-					reset_cache_bgimage();
+					reset_background_pixmap();
 					draw_reinit(&state);
 					cleanup_file();
 					load_file(mgp_fname);
@@ -1090,9 +1095,9 @@
 				state.height = e.xconfigure.height;
 				if (mgp_flag & FL_FRDCACHE) {
 					cached_page = 0;
-					reset_cache_pixmap();
+					reset_background_pixmap();
 				}
-				reset_cache_bgimage();
+				reset_background_pixmap();
 				draw_reinit(&state);	/*notify*/
 				lastcp = state.cp;
 				state_goto(&state, state.page, 1);
Index: kit/mgp.h
diff -u kit/mgp.h:1.115 kit/mgp.h:1.118
--- kit/mgp.h:1.115	Sat Dec 18 04:21:16 1999
+++ kit/mgp.h	Sun Mar  5 16:26:36 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: mgp.h,v 1.115 1999/12/17 19:21:16 nishida Exp $
+ * $Id: mgp.h,v 1.118 2000/03/05 07:26:36 nishida Exp $
  */
 
 #include <stdio.h>
@@ -132,7 +132,7 @@
 #define MAXTAB		32
 #define MAXSTYLE	100
 #define MAXFONTDEF	100
-#define MAXBGCACHE	2
+
 #define MAXBGPIXMAP	2
 
 #define SP_NONE		0
@@ -343,6 +343,7 @@
 	u_int pg_linenum;
 	u_int pg_b_numcolor;	/* background gradation number of colors */
 	u_int pg_b_dir;		/* background gradation deg */
+	u_int pg_text;		/* this page is text only */
 };
 extern struct page_attribute page_attribute[MAXPAGE];
 
@@ -485,15 +486,11 @@
 	long	*colors;
 };
 
-struct bgcache {
-	struct ctrl *ctl;
-	Image *image;
-	XImageInfo *ximageinfo;
-};
-
 struct bgpixmap {
 	struct ctrl *ctl;
 	Pixmap	pixmap;
+	Image *image;
+	XImageInfo *ximageinfo;
 };
 
 /*
@@ -527,7 +524,6 @@
 extern Pixmap cachewin;
 extern Pixmap cachetmp;
 extern struct bgpixmap bgpixmap[MAXBGPIXMAP];
-extern struct bgcache bgcache[MAXBGCACHE];
 extern Colormap colormap;
 extern struct alloc_color image_clr;
 extern struct alloc_color back_clr;
@@ -709,4 +705,9 @@
 #endif
 #ifdef VFLIB
 #define RASTERLIB
+#endif
+
+#if 1
+#define DITHERED_BGRAD
+#define COLOR_BUGFIX
 #endif
Index: kit/parse.c
diff -u kit/parse.c:1.81 kit/parse.c:1.82
--- kit/parse.c:1.81	Mon Dec  6 02:28:44 1999
+++ kit/parse.c	Sun Mar  5 16:26:37 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: parse.c,v 1.81 1999/12/05 17:28:44 nishida Exp $
+ * $Id: parse.c,v 1.82 2000/03/05 07:26:37 nishida Exp $
  */
 
 #include "mgp.h"
@@ -691,7 +691,7 @@
 secondpass()
 {
 	u_int page;
-	u_int l;
+	u_int l, text;
 	struct ctrl **ch;
 	struct ctrl *cp;
 	struct ctrl *cp1;
@@ -719,6 +719,7 @@
 	 * split GAP into VGAP and HGAP.
 	 */
 	for (page = 1; page <= maxpage; page++) {
+		text = 1;
 		for (l = 0; l <= page_attribute[page].pg_linenum; l++) {
 			for (cp = page_control[page][l];
 			     cp;
@@ -730,10 +731,19 @@
 					cp1->ct_next = cp->ct_next;
 					cp->ct_next = cp1->ct_next;
 				}
-			}
+
+				/*
+				 * check if this page contains only texts
+				 */
+				if (cp->ct_op == CTL_BIMAGE || cp->ct_op == CTL_BGRAD ||
+					cp->ct_op == CTL_IMAGE || cp->ct_op == CTL_PAUSE) 
+						text = 0; 
+				}
 		}
+		page_attribute[page].pg_text = text;
 	}
 
+
 	/* CTL_PREFIX in tab_control should be CTL_TABPREFIX. */
 	for (l = 0; l < MAXTAB + MAXSTYLE; l++) {
 		for (cp = tab_control[l]; cp; cp = cp->ct_next) {
@@ -1229,7 +1239,7 @@
 					cp1 = find_font(cp->ctc_value);
 					if (!cp1) {
 						fprintf(stderr,
-"page %d line %d: font def for \"%s\" not found: ignored\n",
+			"page %d line %d: font def for \"%s\" not found: ignored\n",
 							page, l, cp->ctc_value);
 						continue;
 					}
Index: kit/tfont.c
diff -u kit/tfont.c:1.33 kit/tfont.c:1.34
--- kit/tfont.c:1.33	Wed Jul 28 02:05:08 1999
+++ kit/tfont.c	Fri Mar  3 03:24:52 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: tfont.c,v 1.33 1999/07/27 17:05:08 nishida Exp $
+ * $Id: tfont.c,v 1.34 2000/03/02 18:24:52 nishida Exp $
  */
 
 #include "mgp.h"
@@ -284,14 +284,21 @@
 			if (!freetypefont0 || !freetypefont0[0])
 				continue;
 			fontname = freetypefont0;
+			/* already loaded? */
+			for (i = 0; i < tffontcnt; i ++) {
+				if (!strcmp(fontname, tfloadedfont[i])){
+					tfcuridx = i;
+					if (verbose) 
+						fprintf(stderr, "font \"%s\" already loaded: %d\n", 
+							fontname, tffontcnt);
+					goto cached;
+				}
+			}
 			break;
 		}
 
 		/* Load face */
-		if (verbose) {
-			fprintf(stderr, "trying to open font \"%s\"\n",
-				fontname);
-		}
+		if (verbose) fprintf(stderr, "trying to open font \"%s\"\n", fontname);
 		error = TT_Open_Face(engine, fontname, &tface);
 		if (!error)
 			break;
@@ -350,6 +357,7 @@
 		goto fail2;
 	}
 
+cached:
 	if (charset16)
 		tf_mcurname = tfloadedfont[tfcuridx];
 	else
Index: kit/x11.c
diff -u kit/x11.c:1.25 kit/x11.c:1.27
--- kit/x11.c:1.25	Sun Jul  4 00:52:47 1999
+++ kit/x11.c	Sun Mar  5 16:26:39 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: x11.c,v 1.25 1999/07/03 15:52:47 nishida Exp $
+ * $Id: x11.c,v 1.27 2000/03/05 07:26:39 nishida Exp $
  */
 
 #include "mgp.h"
@@ -238,9 +238,6 @@
 	maskpix = XCreatePixmap(display, window, xa.width, xa.height, depth);
 	cachewin = XCreatePixmap(display, window, xa.width, xa.height, depth);
 	cachetmp = XCreatePixmap(display, window, xa.width, xa.height, depth);
-	for (i = 0; i < MAXBGCACHE; i ++)
-		bgpixmap[i].pixmap = 
-			XCreatePixmap(display, window, xa.width, xa.height, depth);
 	gc_cache = XCreateGC(display, window, 0, 0);
 
 	for (pc = &gcconf[0]; pc->gc; pc++) {
@@ -382,7 +379,9 @@
 free_alloc_colors(clr) 
 struct  alloc_color *clr;
 {   
+#ifndef COLOR_BUGFIX
 	if (!(mgp_flag & FL_PRIVATE)) return;
+#endif
 	if (clr->num){
 		XFreeColors(display, colormap, clr->colors, clr->num, 0);
 		free(clr->colors);
@@ -399,7 +398,9 @@
 {
 	u_int   i;
  
+#ifndef COLOR_BUGFIX
 	if (!(mgp_flag & FL_PRIVATE)) return;
+#endif
 	if (!clr->num)
 		clr->colors = (long *)malloc(sizeof(u_long) * num);
 	else
@@ -417,12 +418,6 @@
 
 	XFreePixmap(display, cachewin);
 	XFreePixmap(display, cachetmp);
-	for (i = 0; i < MAXBGCACHE; i ++)
-		XFreePixmap(display, bgpixmap[i].pixmap);
-
 	cachewin = XCreatePixmap(display, window, xa.width, xa.height, depth);
 	cachetmp = XCreatePixmap(display, window, xa.width, xa.height, depth);
-	for (i = 0; i < MAXBGCACHE; i ++)
-	bgpixmap[i].pixmap = 
-		XCreatePixmap(display, window, xa.width, xa.height, depth);
 }
Index: kit/x11dummy.c
diff -u kit/x11dummy.c:1.12 kit/x11dummy.c:1.13
--- kit/x11dummy.c:1.12	Sun May 16 00:50:36 1999
+++ kit/x11dummy.c	Sat Mar  4 11:37:48 2000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 /*
- * $Id: x11dummy.c,v 1.12 1999/05/15 15:50:36 nishida Exp $
+ * $Id: x11dummy.c,v 1.13 2000/03/04 02:37:48 nishida Exp $
  */
 
 #include "mgp.h"
@@ -138,7 +138,9 @@
 free_alloc_colors(clr)
 struct  alloc_color *clr;
 {  
+#ifdef COLOR_BUGFIX
 	if (!(mgp_flag & FL_PRIVATE)) return;
+#endif
 	if (clr->num){
 		XFreeColors(display, colormap, clr->colors, clr->num, 0);
 		free(clr->colors);
@@ -155,7 +157,9 @@
 {
 	u_int   i;
 
+#ifdef COLOR_BUGFIX
 	if (!(mgp_flag & FL_PRIVATE)) return;
+#endif
 	if (!clr->num)
 		clr->colors = (long *)malloc(sizeof(u_long) * num);
 	else
Index: kit/image/Imakefile.in
diff -u kit/image/Imakefile.in:1.9 kit/image/Imakefile.in:1.10
--- kit/image/Imakefile.in:1.9	Tue Feb 15 03:45:36 2000
+++ kit/image/Imakefile.in	Thu Mar  2 01:01:49 2000
@@ -4,13 +4,13 @@
 	value.c misc.c rotate.c rle.c rlelib.c smooth.c halftone.c clip.c\
 	dither.c xbitmap.c xpixmap.c pbm.c pcx.c xwd.c mac.c jpeg.c g3.c\
 	path.c sunraster.c mcidas.c fbm.c faces.c cmuwmraster.c bright.c\
-	img.c mc_tables.c window.c
+	img.c mc_tables.c window.c png.c
 
 OBJS=	imagetypes.o gif.o send.o zio.o zoom.o new.o compress.o reduce.o\
 	value.o misc.o rotate.o rle.o rlelib.o smooth.o halftone.o clip.o\
 	dither.o xbitmap.o xpixmap.o pbm.o pcx.o xwd.o mac.o jpeg.o g3.o\
 	path.o sunraster.o mcidas.o fbm.o faces.o cmuwmraster.o bright.o\
-	img.o mc_tables.o window.o
+	img.o mc_tables.o window.o png.o
 
 DEFS=	@DEFS@
 OPTFLAGS=@OPTFLAGS@
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 Mar  6 05:10:26 2000
@@ -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/image/imagetypes.c
diff -u kit/image/imagetypes.c:1.5 kit/image/imagetypes.c:1.6
--- kit/image/imagetypes.c:1.5	Sat Aug 28 04:02:56 1999
+++ kit/image/imagetypes.c	Thu Mar  2 01:01:50 2000
@@ -29,6 +29,9 @@
 #ifdef USE_GIF
   { gifIdent,       gifLoad,       "GIF Image" },
 #endif
+#ifdef USE_PNG
+  { pngIdent,       pngLoad,       "PNG Image" },
+#endif
   { rleIdent,       rleLoad,       "Utah RLE Image" },
   { jpegIdent,      jpegLoad,      "JFIF-style JPEG Image" },
   { xwdIdent,       xwdLoad,       "X Window Dump" },
Index: kit/image/imagetypes.h
diff -u kit/image/imagetypes.h:1.3 kit/image/imagetypes.h:1.4
--- kit/image/imagetypes.h:1.3	Sat Aug 28 04:02:58 1999
+++ kit/image/imagetypes.h	Thu Mar  2 01:01:51 2000
@@ -40,4 +40,7 @@
 int cmuwmIdent();
 int mcidasIdent();
 int jpegIdent();
-
+#ifdef USE_PNG
+int pngIdent();
+int pngLoad();
+#endif
Index: kit/image/png.c
diff -u /dev/null kit/image/png.c:1.4
--- /dev/null	Mon Mar  6 05:10:30 2000
+++ kit/image/png.c	Thu Mar  2 19:57:39 2000
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 1999 and 2000 WIDE Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * $Id: png.c,v 1.4 2000/03/02 10:57:39 nishida Exp $
+ */
+#ifdef USE_PNG
+#include <png.h>
+
+#if 1
+#define PNG_ALPHA_CHANNEL
+#endif
+
+#ifdef PNG_ALPHA_CHANNEL
+#include "../mgp.h"
+#else 
+#include "image.h"
+#endif
+
+#define PNG_CHECK_BYTES 4
+
+int 
+pngIdent(char *fullname, char *name) {}
+    
+Image *
+pngLoad(fullname, name, verbose)
+    char *fullname, *name;
+	unsigned int verbose;
+{
+	FILE *fp;
+	png_structp 	png_ptr; 
+	png_infop 		info_ptr; 
+	png_uint_32 	width, height;
+	png_bytep 		*row_pointers;
+	int 			bitdepth, colortype, row, is_png, alpha_flag = 0;
+	char 			header[PNG_CHECK_BYTES], *destptr;
+	Image			*image;
+#ifdef PNG_ALPHA_CHANNEL
+	int				alpha_red, alpha_green, alpha_blue, ialpha;
+	int				x, len;
+	float			alpha;
+	char			*p;
+	XColor  		xcol;
+#endif
+
+	if (!(fp = fopen(fullname, "rb"))) return NULL;
+	if (fread(header, 1, sizeof(header), fp) != sizeof(header)) return NULL;
+
+	is_png = !png_sig_cmp(header, 0, sizeof(header));
+	if (!is_png){
+		if (verbose) fprintf(stderr, "pngLoad: this is not png file\n");
+		return NULL;
+	}
+
+	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
+				(png_voidp)NULL, NULL, NULL);
+	if (!png_ptr) return NULL;
+							   
+	info_ptr = png_create_info_struct(png_ptr);
+	if (!info_ptr) {
+		png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
+		return NULL;
+	}
+
+	if (setjmp(png_ptr->jmpbuf)) {
+		png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+		fclose(fp);
+		return NULL;
+	}
+
+	png_init_io(png_ptr, fp);
+	png_set_sig_bytes(png_ptr, sizeof(header));
+
+	png_read_info(png_ptr, info_ptr);
+	png_get_IHDR(png_ptr, info_ptr, &width, &height,
+			&bitdepth, &colortype, NULL, NULL, NULL);
+
+	if (verbose){
+		fprintf(stderr, "pngLoad: [%s] width %d height %d depth %d color %d\n", 
+			fullname, width, height, bitdepth, colortype);
+	}
+
+	/* 
+		currently, the alpha channel is not supported.. 
+	*/
+#ifndef PNG_ALPHA_CHANNEL
+	if (colortype & PNG_COLOR_MASK_ALPHA){
+		if (verbose) fprintf(stderr, "pngLoad: strip off alpha channel\n");
+		png_set_strip_alpha(png_ptr);
+	}
+#endif
+
+	/*
+		strip the 16 bit pixels down to 8bit.
+	*/
+	if (bitdepth == 16){
+		png_set_strip_16(png_ptr);
+	}
+
+	if (colortype == PNG_COLOR_TYPE_GRAY ||
+			colortype == PNG_COLOR_TYPE_GRAY_ALPHA){
+				png_set_gray_to_rgb(png_ptr); 
+				png_read_update_info(png_ptr, info_ptr);
+	}
+
+	if (colortype == PNG_COLOR_TYPE_PALETTE && bitdepth <= 8){
+		if (verbose) fprintf(stderr, "pngLoad: palette to rgb\n");
+		png_set_palette_to_rgb(png_ptr);
+		png_read_update_info(png_ptr, info_ptr);
+	} 
+
+	if (colortype == PNG_COLOR_TYPE_GRAY && bitdepth < 8){
+		png_set_gray_1_2_4_to_8(png_ptr);
+	}
+
+	if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)){
+		if (verbose) 
+			fprintf(stderr, "pngLoad: add tRNS info to alpha channel\n");
+		png_set_tRNS_to_alpha(png_ptr);
+		alpha_flag = 1;
+#ifndef PNG_ALPHA_CHANNEL
+		png_set_strip_alpha(png_ptr);
+#endif
+	}
+
+	image = newTrueImage(width, height);
+
+	row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * height);
+	for (row = 0; row < height; row++) {
+			row_pointers[row] = 
+				(png_bytep)malloc(png_get_rowbytes(png_ptr, info_ptr));
+	}
+	png_read_image(png_ptr, row_pointers);
+
+	destptr = image->data;
+
+#ifndef PNG_ALPHA_CHANNEL
+	for (row = 0; row < height; row++) {
+		memcpy(destptr + width * row * 3, row_pointers[row], width * 3);
+	}
+#else
+	xcol.pixel = back_color[caching]; 
+	xcol.flags = DoRed|DoGreen|DoBlue;
+	XQueryColor(display, colormap, &xcol);
+
+	alpha_red = xcol.red >> 8;
+	alpha_green = xcol.green >> 8;
+	alpha_blue = xcol.blue >> 8;
+
+	if (!(colortype & PNG_COLOR_MASK_ALPHA) && !alpha_flag){
+		for (row = 0; row < height; row++) {
+			memcpy(destptr + width * row * 3, row_pointers[row], width * 3);
+		}
+	} else {
+		/*  
+			alpha channel processing 
+		*/
+		for (row = 0; row < height; row++) {
+			len = png_get_rowbytes(png_ptr, info_ptr);
+			p = destptr + width * row * 3;
+
+			for (x = 0; x < len; x+= 4){
+				ialpha =  (u_int)(row_pointers[row][x+3]);
+	
+				if (!ialpha) {
+					/* this pixel is transparent */
+					*(p++) = alpha_red;
+					*(p++) = alpha_green;
+					*(p++) = alpha_blue;
+				} else {
+				if (ialpha == 255){
+					/* this pixel is opacity */
+					*(p++) = row_pointers[row][x];
+					*(p++) = row_pointers[row][x+1];
+					*(p++) = row_pointers[row][x+2];
+				} else {
+					alpha =  (u_int)(row_pointers[row][x+3]) / 255.0;
+					*(p++) = row_pointers[row][x] * alpha 
+								+ alpha_red * (1.0 - alpha);
+					*(p++) = row_pointers[row][x+1] * alpha
+								+ alpha_green * (1.0 - alpha);
+					*(p++) = row_pointers[row][x+2] * alpha
+								+ alpha_blue * (1.0 - alpha);
+				}
+				}
+			}
+		}
+	}
+#endif
+
+	for (row = 0; row < height; row++) free (row_pointers[row]);
+	free(row_pointers); 
+	png_read_end(png_ptr, info_ptr);
+	png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+	fclose(fp);
+
+	return image;
+}
+
+#endif
Index: kit/sample/cloud.gif
Index: kit/sample/dad.gif
Index: kit/sample/gradation.mgp
diff -u kit/sample/gradation.mgp:1.7 kit/sample/gradation.mgp:1.8
--- kit/sample/gradation.mgp:1.7	Sat Sep  5 06:09:12 1998
+++ kit/sample/gradation.mgp	Sat Mar  4 01:23:04 2000
@@ -33,7 +33,7 @@
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %page
-%bgrad
+%bgrad 0 0 128 90 1 "black" "blue"
 
 Principles of drawing gradation background
 
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
