--- espgs.orig/src/gdevdjet.c	2005-01-20 16:40:32.000000000 +0100
+++ espgs/src/gdevdjet.c	2005-02-16 00:36:53.148865936 +0100
@@ -99,6 +99,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);
@@ -111,11 +112,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,
@@ -200,6 +206,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)
@@ -261,8 +274,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,
@@ -370,6 +400,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
--- espgs.orig/src/unixinst.mak	2005-01-22 01:17:28.000000000 +0100
+++ espgs/src/unixinst.mak	2005-02-16 00:36:53.151865480 +0100
@@ -78,7 +78,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;\
--- espgs.orig/src/gdevdljm.c	2005-01-20 16:40:32.000000000 +0100
+++ espgs/src/gdevdljm.c	2005-02-16 00:36:53.154865024 +0100
@@ -105,6 +105,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. */
--- espgs.orig/src/gdevdljm.h	2005-01-20 16:40:32.000000000 +0100
+++ espgs/src/gdevdljm.h	2005-02-16 00:36:53.155864872 +0100
@@ -52,6 +52,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
@@ -106,6 +107,12 @@
   (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\
   (PCL_MODE3 |\
--- espgs.orig/src/gdevcdj.c	2005-01-20 16:40:32.000000000 +0100
+++ espgs/src/gdevcdj.c	2005-02-16 00:39:40.668399096 +0100
@@ -17,6 +17,16 @@
 /* $Id: gdevcdj.c,v 1.13 2002/11/13 23:33:05 dan Exp $*/
 /* HP 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
@@ -109,6 +119,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)
  ***/
 
 /*
@@ -177,6 +189,8 @@
 /* Margins are left, bottom, right, top. */
 #define DESKJET_MARGINS_LETTER   (float)0.25, (float)0.50, (float)0.25, (float)0.167
 #define DESKJET_MARGINS_A4       (float)0.125, (float)0.50, (float)0.143, (float)0.167
+#define DESKJET_505J_MARGINS     (float)0.125, (float)0.50, (float)0.125, (float)0.167
+#define DESKJET_505J_MARGINS_COLOR (float)0.125, (float)0.665, (float)0.125, (float)0.167
 #define LJET4_MARGINS  		 (float)0.26, (float)0.0, (float)0.0, (float)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);
@@ -523,6 +542,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);
 
@@ -571,6 +593,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);
@@ -583,6 +613,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);
@@ -682,6 +716,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);
 }
@@ -721,6 +760,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 };
@@ -747,6 +788,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;
@@ -1232,6 +1276,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)
@@ -1245,6 +1309,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)
@@ -2110,7 +2185,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)  {
@@ -2153,6 +2232,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 */
@@ -2279,7 +2376,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);
@@ -2360,7 +2459,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);
@@ -2544,6 +2646,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)
@@ -2613,7 +2722,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)
@@ -2642,13 +2754,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)
