--- ghostscript-6.51/src/gdevcdj.c.gsj	Tue Jun  5 02:38:55 2001
+++ ghostscript-6.51/src/gdevcdj.c	Thu Jun 28 15:05:33 2001
@@ -20,6 +20,16 @@
 /*$RCSfile: gdevcdj.c,v $ $Revision: 1.4.2.1 $*/
 /* H-P and Canon colour printer drivers */
 
+/*
+ * HP DeskJet 505J Support (dj505j.dev)
+ *   -- taken from dj505j driver for Ghostscript 2.6.1 by Kazunori Asayama
+ * NEC PICTY180 (PC-PR101J/180) Support (picty180.dev)
+ * HP LaserJet 4V/4LJ Pro dither Suport (lj4dithp.dev)
+ *
+ *     Norihito Ohmori <ohmori@p.chiba-u.ac.jp>
+ *     April 15, 1999
+ */
+
 /****************************************************************
  * The code in this file was contributed by the authors whose names and/or
  * e-mail addresses appear below: Aladdin Enterprises takes no
@@ -112,6 +122,8 @@
  *    10 - bjc600:	BJC 600//4000 printers
  *** The BJC800 driver is based on the bjc600 one. By YA too.
  *    11 - bjc800:	BJC 800 printer
+ *    12 - dj505j:      HP DeskJet 505J
+ *    13 - pixty180:    NEC PICTY 180 (PC-PR101J/180)
  ***/
 
 /*
@@ -179,6 +191,8 @@
 /* Margins are left, bottom, right, top. */
 #define DESKJET_MARGINS_LETTER   0.25, 0.50, 0.25, 0.167
 #define DESKJET_MARGINS_A4       0.125, 0.50, 0.143, 0.167
+#define DESKJET_505J_MARGINS     0.125, 0.50, 0.125, 0.167
+#define DESKJET_505J_MARGINS_COLOR 0.125, 0.665, 0.125, 0.167
 #define LJET4_MARGINS  		 0.26, 0.0, 0.0, 0.0
 /* The PaintJet and DesignJet seem to have the same margins */
 /* regardless of paper size. */
@@ -221,15 +235,16 @@
 /* Printer types */
 #define DJ500C   0
 #define DJ550C   1
-#define PJXL300  2
-#define PJ180    3
-#define PJXL180  4
-#define DECLJ250 5
-#define DNJ650C  6
-#define LJ4DITH  7
-#define ESC_P	 8
-#define BJC600	 9
-#define BJC800	 10
+#define DJ505J   2
+#define PJXL300  3
+#define PJ180    4
+#define PJXL180  5
+#define DECLJ250 6
+#define DNJ650C  7
+#define LJ4DITH  8
+#define ESC_P	 9
+#define BJC600	 10
+#define BJC800	 11
 
 /* No. of ink jets (used to minimise head movements) */
 #define HEAD_ROWS_MONO 50
@@ -246,6 +261,7 @@
 /* Print-page, parameters and miscellaneous procedures */
 private dev_proc_open_device(dj500c_open);
 private dev_proc_open_device(dj550c_open);
+private dev_proc_open_device(dj505j_open);
 private dev_proc_open_device(dnj650c_open);
 private dev_proc_open_device(lj4dith_open);
 private dev_proc_open_device(pj_open);
@@ -257,8 +273,11 @@
 private dev_proc_print_page(declj250_print_page);
 private dev_proc_print_page(dj500c_print_page);
 private dev_proc_print_page(dj550c_print_page);
+private dev_proc_print_page(dj505j_print_page);
+private dev_proc_print_page(picty180_print_page);
 private dev_proc_print_page(dnj650c_print_page);
 private dev_proc_print_page(lj4dith_print_page);
+private dev_proc_print_page(lj4dithp_print_page);
 private dev_proc_print_page(pj_print_page);
 private dev_proc_print_page(pjxl_print_page);
 private dev_proc_print_page(pjxl300_print_page);
@@ -486,6 +505,9 @@
 cmyk_colour_procs(dj550c_open, cdj_get_params, cdj_put_params);
 #endif
 
+private gx_device_procs dj505j_procs =
+hp_colour_procs(dj505j_open, cdj_get_params, cdj_put_params);
+
 private gx_device_procs dnj650c_procs =
 hp_colour_procs(dnj650c_open, cdj_get_params, cdj_put_params);
 
@@ -534,6 +556,14 @@
 };
 #endif
 
+gx_device_cdj far_data gs_picty180_device =
+cdj_device(cdj550_procs, "picty180", 300, 300, BITSPERPIXEL,
+ 	   picty180_print_page, 0, 2, 1);
+
+gx_device_cdj far_data gs_dj505j_device =
+cdj_device(dj505j_procs, "dj505j", 300, 300, 1,
+ 	   dj505j_print_page, 4, 0, 1);
+ 
 gx_device_pj far_data gs_declj250_device =
 pj_device(pj_procs, "declj250", 180, 180, BITSPERPIXEL,
 	  declj250_print_page);
@@ -546,6 +576,10 @@
 cdj_device(lj4dith_procs, "lj4dith", 600, 600, 8,
 	   lj4dith_print_page, 4, 0, 1);
 
+gx_device_cdj far_data gs_lj4dithp_device =
+cdj_device(lj4dith_procs, "lj4dithp", 600, 600, 8,
+	   lj4dithp_print_page, 4, 0, 1);
+
 gx_device_pj far_data gs_pj_device =
 pj_device(pj_procs, "pj", 180, 180, BITSPERPIXEL,
 	  pj_print_page);
@@ -645,6 +679,11 @@
 }
 
 private int
+dj505j_open(gx_device *pdev)
+{ return hp_colour_open(pdev, DJ505J);
+}
+
+private int
 dnj650c_open(gx_device *pdev)
 { return hp_colour_open(pdev, DNJ650C);
 }
@@ -684,6 +723,8 @@
 {	/* Change the margins if necessary. */
   static const float dj_a4[4] = { DESKJET_MARGINS_A4 };
   static const float dj_letter[4] = { DESKJET_MARGINS_LETTER };
+  static const float dj_505j[4] = { DESKJET_505J_MARGINS };
+  static const float dj_505jc[4] = { DESKJET_505J_MARGINS_COLOR };
   static const float lj4_all[4] = { LJET4_MARGINS };
   static const float pj_all[4] = { PAINTJET_MARGINS };
   static const float dnj_all[4] = { DESIGNJET_MARGINS };
@@ -710,6 +751,9 @@
     m = (gdev_pcl_paper_size(pdev) == PAPER_SIZE_A4 ? dj_a4 :
 	 dj_letter);
     break;
+  case DJ505J:
+	m = pdev->color_info.num_components > 1 ? dj_505jc : dj_505j;
+    break;
   case DNJ650C:
     m = dnj_all;
     break;
@@ -1195,6 +1239,26 @@
   return hp_colour_print_page(pdev, prn_stream, DJ550C);
 }
 
+/* The Picty180C can compress (mode 9) */
+/* This printer need switching mode using PJL */
+private int
+picty180_print_page(gx_device_printer * pdev, FILE * prn_stream)
+{  int ret_code;
+  /* Ensure we're operating in PCL mode */
+  fputs("\033%-12345X@PJL ENTER LANGUAGE = PCLSLEEK\n", prn_stream);
+  ret_code =  hp_colour_print_page(pdev, prn_stream, DJ550C);
+  /* Reenter switch-configured language */
+  fputs("\033%-12345X", prn_stream);
+  return ret_code;
+}
+
+/* The DeskJet505J can compress  */
+private int
+dj505j_print_page(gx_device_printer * pdev, FILE * prn_stream)
+{
+  return hp_colour_print_page(pdev, prn_stream, DJ505J);
+}
+
 /* The DesignJet650C can compress (mode 1) */
 private int
 dnj650c_print_page(gx_device_printer * pdev, FILE * prn_stream)
@@ -1208,6 +1272,17 @@
   return hp_colour_print_page(pdev, prn_stream, LJ4DITH);
 }
 
+private int
+lj4dithp_print_page(gx_device_printer * pdev, FILE * prn_stream)
+{ int ret_code;
+  /* Ensure we're operating in PCL mode */
+  fputs("\033%-12345X@PJL\r\n@PJL ENTER LANGUAGE = PCL\r\n", prn_stream);
+  ret_code = hp_colour_print_page(pdev, prn_stream, LJ4DITH);
+  /* Reenter switch-configured language */
+  fputs("\033%-12345X", prn_stream);
+  return ret_code;
+}
+
 /* The PJXL300 can compress (modes 2 & 3) */
 private int
 pjxl300_print_page(gx_device_printer * pdev, FILE * prn_stream)
@@ -2073,7 +2148,11 @@
   }
   
   /* Initialize printer. */
-  if (ptype == BJC600 || ptype == BJC800) {
+  if (ptype == DJ505J) {
+    fputs("\033@",prn_stream); /* Reset printer */
+    fprintf(prn_stream,"\033_R%c%c", /* Set resolution */
+      (int)x_dpi & 0xff,((int)x_dpi >> 8) & 0xff);
+  } else if (ptype == BJC600 || ptype == BJC800) {
     bjc_init_page(pdev, prn_stream);
   } else {
       if (ptype == LJ4DITH)  {
@@ -2116,6 +2195,24 @@
     /* Select data compression */
     compression = 9;
     break;
+  case DJ505J:
+    /* Set depletion and shingling levels */
+    fprintf(prn_stream, "\033_D%c\033_E%c",
+      cdj->depletion, cdj->shingling);
+    /* Move to top left of printed area */
+    fwrite("\033_N\000", 4, 1, prn_stream);
+    fwrite("\033_J\xc4\xff", 5, 1, prn_stream);
+    /* Set number of planes ((-)1 is mono, (-)3 is (cmy)rgb, -4 is cmyk),
+     * and raster width, then start raster graphics */
+    fprintf(prn_stream, "\033_U%c%c",
+      (0xffff - num_comps + 1) & 0xff, ((0xffff - num_comps + 1) >> 8) & 0xff);
+    fprintf(prn_stream,
+      "\033_S%c%c", raster_width & 0xff, (raster_width >> 8) & 0xff);
+    /* set origin */
+    fwrite("\033_A\001", 4, 1, prn_stream);
+    compression = 1;
+    combined_escapes = 0;
+    break;
   case DNJ650C:
     if (pdev->x_pixels_per_inch == 600) {
         /* set resolution to 600dpi 1st through PJL command */
@@ -2242,7 +2339,9 @@
    * omission is that 'mode 9' compression is not supported, as this
    * mode can give both computational and PCL file size advantages. */
 
-  if (combined_escapes) {
+  if (ptype == DJ505J) {
+    fprintf(prn_stream, "\033_M%c", compression);
+  } else if (combined_escapes) {
     /* From now on, all escape commands start with \033*b, so we
      * combine them (if the printer supports this). */
     fputs("\033*b", prn_stream);
@@ -2322,7 +2421,10 @@
 	}
       /* Skip blank lines if any */
       if (num_blank_lines > 0) {
-	if (ptype == ESC_P) {
+        if (ptype == DJ505J) {
+          fprintf(prn_stream,"\033_Y%c%c",
+          num_blank_lines & 0xff, (num_blank_lines >> 8) & 0xff);
+	} else if (ptype == ESC_P) {
 	  ep_print_image(prn_stream, 'B', 0, num_blank_lines);
 	} else if (ptype == BJC600 || ptype == BJC800) {
 	    bjc_v_skip(num_blank_lines, pdev, prn_stream);
@@ -2506,6 +2608,13 @@
                  fputc('v', prn_stream);
              }
 	    break;
+	  case DJ505J:
+	    out_count = gdev_pcl_mode1compress((const byte *)
+					       plane_data[scan][i],
+					       (const byte *)
+					       plane_data[scan][i] + plane_size - 1,
+					       out_data);
+	    break;
 	  case PJ180:
 	  case DNJ650C:
 	    if (num_comps > 1)
@@ -2575,7 +2684,10 @@
 	    break;
 	  }
 	  if (output_plane) {
-	    if (combined_escapes)
+            if (ptype == DJ505J)
+	      fprintf(prn_stream, "\033_%c%c%c",
+		      "WVVV"[i], out_count & 0xff, (out_count >> 8) & 0xff);
+	    else if (combined_escapes)
 	      fprintf(prn_stream, "%d%c", out_count, "wvvv"[i]);
 	    else if (ptype == BJC600 || ptype == BJC800) {
 	      if (out_count)
@@ -2604,13 +2716,16 @@
   /* end raster graphics */
   if (ptype == BJC600 || ptype == BJC800) {
     bjc_finish_page(pdev, prn_stream);
-  }
+  } else if (ptype == DJ505J)
+    fputs("\033_C", prn_stream);
   else if (ptype != ESC_P) 
     fputs("\033*rbC\033E", prn_stream);
 
   /* eject page */
   if (ptype == PJ180)
     fputc('\f', prn_stream);
+  else if (ptype == DJ505J)
+    fputs("\f\033@", prn_stream);
   else if (ptype == DNJ650C)
     fputs ("\033*rC\033%0BPG;", prn_stream);
   else if (ptype == BJC600 || ptype == BJC800)
--- ghostscript-6.51/src/gdevdjet.c.gsj	Tue Jun  5 02:38:55 2001
+++ ghostscript-6.51/src/gdevdjet.c	Thu Jun 28 15:22:08 2001
@@ -118,6 +118,7 @@
 /* The device descriptors */
 private dev_proc_open_device(hpjet_open);
 private dev_proc_close_device(hpjet_close);
+private dev_proc_close_device(ljet4pjl_close);
 private dev_proc_print_page_copies(djet_print_page_copies);
 private dev_proc_print_page_copies(djet500_print_page_copies);
 private dev_proc_print_page_copies(fs600_print_page_copies);
@@ -130,11 +131,16 @@
 private dev_proc_print_page_copies(ljet4d_print_page_copies);
 private dev_proc_print_page_copies(lp2563_print_page_copies);
 private dev_proc_print_page_copies(oce9050_print_page_copies);
+private dev_proc_print_page_copies(ljet4pjl_print_page_copies);
 
 private const gx_device_procs prn_hp_procs =
 prn_params_procs(hpjet_open, gdev_prn_output_page, hpjet_close,
 		 gdev_prn_get_params, gdev_prn_put_params);
 
+private gx_device_procs prn_ljet4pjl_procs =
+prn_params_procs(hpjet_open, gdev_prn_output_page, ljet4pjl_close,
+		 gdev_prn_get_params, gdev_prn_put_params);
+
 const gx_device_printer gs_deskjet_device =
 prn_device_copies(prn_hp_procs, "deskjet",
 		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
@@ -219,6 +225,13 @@
 		  0, 0, 0, 0,		/* margins */
 		  1, oce9050_print_page_copies);
 
+const gx_device_printer gs_ljet4pjl_device =
+prn_device_copies(prn_ljet4pjl_procs, "ljet4pjl",
+	   DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	   X_DPI2, Y_DPI2,
+	   0, 0, 0, 0,			/* margins */
+	   1, ljet4pjl_print_page_copies);
+
 /* Open the printer, adjusting the margins if necessary. */
 private int
 hpjet_open(gx_device * pdev)
@@ -276,8 +289,25 @@
     return gdev_prn_close(pdev);
 }
 
+private int
+ljet4pjl_close(gx_device *pdev)
+{
+    gx_device_printer *const ppdev = (gx_device_printer *)pdev;
+    int code = gdev_prn_open_printer(pdev, 1);
+
+    if (code < 0)
+	return code;
+    if ( ppdev->Duplex_set >= 0 && ppdev->Duplex ) {
+        gdev_prn_open_printer(ppdev, 1);
+        fputs("\033&l0H", ppdev->file) ;
+    }
+    fputs("\033%-12345X", ppdev->file);
+    return gdev_prn_close(ppdev);
+}
+
 /* ------ Internal routines ------ */
 
+
 /* The DeskJet can compress (mode 2) */
 private int
 djet_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
@@ -385,6 +415,22 @@
 					dots_per_inch, PCL_LJ4D_FEATURES,
 					real_init);
 }
+ 
+/* LaserJet 4 series compresses, and it needs a special sequence to */
+/* allow it to specify coordinates at 600 dpi. */
+/* It too needs its coordinate system translated slightly. */
+private int
+ljet4pjl_print_page_copies(gx_device_printer *pdev, FILE *prn_stream,
+			int num_copies)
+{	int dots_per_inch = (int)pdev->y_pixels_per_inch;
+	char real_init[60];
+
+	sprintf(real_init, "\033&l-180u36Z\033*r0F\033&u%dD", dots_per_inch);
+	return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
+					dots_per_inch, PCL_LJ4PJL_FEATURES,
+					real_init);
+}
+
 /* The 2563B line printer can't compress */
 /* and doesn't support *p+ or *b vertical spacing. */
 private int
--- ghostscript-6.51/src/gdevlbp8.c.gsj	Tue Jun  5 02:38:55 2001
+++ ghostscript-6.51/src/gdevlbp8.c	Thu Jun 28 15:05:32 2001
@@ -43,6 +43,12 @@
     LIPS III driver: Kenji Okamoto (okamoto@okamoto.cias.osakafu-u.ac.jp)
 */
 
+/*
+
+   Modified by Norihito Ohmori (ohmori@flatout.org)
+   remove lips3.dev
+
+*/
 
 #define X_DPI 300
 #define Y_DPI 300
@@ -50,7 +56,9 @@
 
 /* The device descriptors */
 private dev_proc_print_page(lbp8_print_page);
+#if 0
 private dev_proc_print_page(lips3_print_page);
+#endif
 
 gx_device_printer far_data gs_lbp8_device =
   prn_device(prn_std_procs, "lbp8",
@@ -59,6 +67,7 @@
 	0.16, 0.2, 0.32, 0.21,		/* margins: left, bottom, right, top */
 	1, lbp8_print_page);
 
+#if 0
 const gx_device_printer far_data gs_lips3_device =
   prn_device(prn_std_procs, "lips3",
 	82,				/* width_10ths, 8.3" */
@@ -66,6 +75,7 @@
 	X_DPI, Y_DPI,
 	0.16, 0.27, 0.23, 0.27,		/* margins */
 	1, lips3_print_page);
+#endif
 
 /* ------ Internal routines ------ */
 
@@ -85,6 +95,7 @@
 
 static const char *lbp8_end = NULL;
 
+#if 0
 static const char lips3_init[] = {
   ESC, '<', /* soft reset */
   DCS, '0', 'J', ST, /* JOB END */
@@ -101,6 +112,7 @@
 static const char lips3_end[] = {
   DCS, '0', 'J', ST  /* JOB END */
 };
+#endif
 
 /* Send the page to the printer.  */
 private int
@@ -206,9 +218,11 @@
 			      lbp8_end, sizeof(lbp8_end));
 }
 
+#if 0
 /* Print a LIPS III page. */
 private int
 lips3_print_page(gx_device_printer *pdev, FILE *prn_stream)
 {	return can_print_page(pdev, prn_stream, lips3_init, sizeof(lips3_init),
 			      lips3_end, sizeof(lips3_end));
 }
+#endif
--- ghostscript-6.51/src/unixinst.mak.gsj	Thu Jun 28 15:05:31 2001
+++ ghostscript-6.51/src/unixinst.mak	Thu Jun 28 15:05:32 2001
@@ -95,7 +95,8 @@
 viewcmyk.ps viewgif.ps viewjpeg.ps viewmiff.ps \
 viewpcx.ps viewpbm.ps viewps2a.ps \
 winmaps.ps wftopfa.ps wrfont.ps zeroline.ps \
-pdf2dsc.ps pdfopt.ps ;\
+pdf2dsc.ps pdfopt.ps \
+dmp_init.ps dmp_site.ps gdevmjc.ps escp_24.src ;\
 	do if ( test -f $(PSLIBDIR)/$$f ); then $(INSTALL_DATA) $(PSLIBDIR)/$$f $(gsdatadir)/lib; fi;\
 	done'
 	$(SH) -c 'for f in $(PSLIBDIR)/gs_*.ps $(PSLIBDIR)/pdf*.ps;\
--- ghostscript-6.51/src/zfile.c.gsj	Thu Jun 28 15:05:31 2001
+++ ghostscript-6.51/src/zfile.c	Thu Jun 28 15:05:32 2001
@@ -688,6 +688,23 @@
     return (code < 0 ? NULL : file);
 }
 
+/* for dmprt searching current path */
+FILE *
+lib_fopen2(const char *bname)
+{ FILE *file = NULL;
+#define max_filename 129
+    /* We need a buffer to hold the expanded file name. */
+    char buffer[max_filename];
+    int code = lib_file_fopen(iodev_default, bname, "r", &file,
+			      buffer, max_filename);
+#undef max_filename
+    if ( code >= 0 ){
+      /* This is for VFlib vfontcap searching */
+      strcpy(bname, buffer);
+    }
+    return (code < 0 ? NULL : file);
+}
+
 /* Open a file stream on an OS file and create a file object, */
 /* using the search paths. */
 /* The startup code calls this to open the initialization file gs_init.ps. */
--- ghostscript-6.51/src/gdevdljm.c.gsj	Tue Jun  5 02:38:55 2001
+++ ghostscript-6.51/src/gdevdljm.c	Thu Jun 28 15:05:32 2001
@@ -123,6 +123,10 @@
 
     /* Initialize printer. */
     if (pdev->PageCount == 0) {
+	if (features & HACK__IS_A_LJET4PJL) {
+ 	    fputs("\033%-12345X@PJL\r\n@PJL ENTER LANGUAGE = PCL\r\n",
+  		  prn_stream);
+	}
 	fputs("\033E", prn_stream);	/* reset printer */
 	/* If the printer supports it, set the paper size */
 	/* based on the actual requested size. */
--- ghostscript-6.51/src/gdevdljm.h.gsj	Tue Jun  5 02:38:55 2001
+++ ghostscript-6.51/src/gdevdljm.h	Thu Jun 28 15:05:32 2001
@@ -71,6 +71,7 @@
 #define PCL_HAS_DUPLEX              64	/* <esc>&l<duplex>S supported */
 #define PCL_CAN_SET_PAPER_SIZE     128	/* <esc>&l<sizecode>A supported */
 #define PCL_CAN_PRINT_COPIES       256  /* <esc>&l<copies>X supported */
+#define HACK__IS_A_LJET4PJL	   512
 
 /* Shorthands for the most common spacing/compression combinations. */
 #define PCL_MODE0 PCL3_SPACING
@@ -124,6 +125,12 @@
 #define PCL_LJ4_FEATURES\
   (PCL_MODE3 |\
    PCL_CAN_SET_PAPER_SIZE | PCL_CAN_PRINT_COPIES)
+
+     /* H-P LaserJet 4 PL */
+#define PCL_LJ4PJL_FEATURES\
+  (PCL_MODE3 |\
+   PCL_CAN_SET_PAPER_SIZE | PCL_CAN_PRINT_COPIES | HACK__IS_A_LJET4PJL)
+
 
      /* H-P LaserJet 4d */
 #define PCL_LJ4D_FEATURES\
