[gs-cvs] gs/src

Raph Levien raph at ghostscript.com
Wed Apr 6 09:45:20 PDT 2005


Update of /cvs/ghostscript/gs/src
In directory casper2:/tmp/cvs-serv31825/src

Modified Files:
	zmedia2.c gdevdjet.c 
Log Message:
Conveys input tray selection info (/ManualFeed and /MediaPosition)
setpagedevice requests to PCL devices. Fixes bug #687899.

DETAILS

1. The behavior of MediaPosition is changed significantly. Previously,
   it was ignored (i.e. omitted altogether from setpd merging). Just
   adding it to setpd merging would not be good - if set at the PS
   level, then it would get checked for equality at the C level (by
   zmatchmedia), and fail horribly if it didn't match. In accordance
   with the PLRM3 text (it will be honored provided it can satisfy the
   normal media matching), in the new version a mismatch simply adds a
   .001 penalty to the matching score.

2. The ljet4 device now contains ManualFeed and MediaPosition fields,
   with appropriate putparams logic to set them.

3. The MediaPosition and ManualFeed strings now create an ESC & l H
   init string, according to the following logic. ManualFeed sends
   ESC & l 2 H; if ManualFeed is false (or not set), then MediaPosition
   0 sends ESC & l 5 H, and MediaPosition1 sends ESC & l 1 H. If none
   of these are set, then no extra init string is generated.

   Obviously, for this feature to be useful, there needs to be an
InputAttributes dictionary in effect, for which the PageSize of
positions 0 and 1 match the PageSize of the setpagedevice request.
[Actually, if only ManualFeed is desired, then there is no need to
fiddle with InputAttributes].

   I think these changes bring our media selection more in line with
what Adobe intended, and could be useful for embedded PS projects as
well. I believe the risk of unwanted changes is small, but considering
the delicacy of the setpagedevice logic, review and testing is
warranted.


Index: zmedia2.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/zmedia2.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- zmedia2.c	13 Feb 2005 21:31:07 -0000	1.17
+++ zmedia2.c	6 Apr 2005 16:45:18 -0000	1.18
@@ -55,6 +55,7 @@
     os_ptr pkeys = op;		/* *const */
     int policy_default;
     float best_mismatch = (float)max_long;	/* adhoc */
+    float mepos_penalty;
     float mbest = best_mismatch;
     match_record_t match;
     ref no_priority;
@@ -120,8 +121,7 @@
 	 ) {
 	if (r_has_type(&aelt.dict, t_dictionary) &&
 	    r_has_attr(dict_access_ref(&aelt.dict), a_read) &&
-	    r_has_type(&aelt.key, t_integer) &&
-	    (mepos < 0 || aelt.key.value.intval == mepos)
+	    r_has_type(&aelt.key, t_integer)
 	    ) {
 	    bool match_all;
 	    uint ki, pi;
@@ -179,6 +179,10 @@
 		} else if (!obj_eq(imemory, prvalue, pmvalue))
 		    goto no;
 	    }
+
+	    mepos_penalty = (mepos < 0 || aelt.key.value.intval == mepos) ?
+		0 : .001;
+
 	    /* We have a match. Save the match in case no better match is found */
 	    if (r_has_type(&match.match_key, t_null)) 
 		match.match_key = aelt.key;
@@ -187,13 +191,13 @@
 	     * regardless of priority. If the match is the same, then update 
 	     * to the current only if the key value is lower.
 	     */
-	    if (best_mismatch <= mbest) {
-		if (best_mismatch < mbest  ||
+	    if (best_mismatch + mepos_penalty <= mbest) {
+		if (best_mismatch + mepos_penalty < mbest  ||
 		    (r_has_type(&match.match_key, t_integer) &&
 		     match.match_key.value.intval > aelt.key.value.intval)) {
 		    reset_match(&match);
 		    match.match_key = aelt.key;
-		    mbest = best_mismatch;
+		    mbest = best_mismatch + mepos_penalty;
 		}
 	    }
 	    /* In case of a tie, see if the new match has priority. */

Index: gdevdjet.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevdjet.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- gdevdjet.c	29 Jan 2004 18:19:41 -0000	1.11
+++ gdevdjet.c	6 Apr 2005 16:45:18 -0000	1.12
@@ -111,94 +111,113 @@
 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_get_params(hpjet_get_params);
+private dev_proc_put_params(hpjet_put_params);
 
 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);
+		 hpjet_get_params, hpjet_put_params);
 
-const gx_device_printer gs_deskjet_device =
-prn_device_copies(prn_hp_procs, "deskjet",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI, Y_DPI,
-		  0, 0, 0, 0,		/* margins filled in by hpjet_open */
-		  1, djet_print_page_copies);
+typedef struct gx_device_hpjet_s gx_device_hpjet;
 
-const gx_device_printer gs_djet500_device =
-prn_device_copies(prn_hp_procs, "djet500",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI, Y_DPI,
-		  0, 0, 0, 0,		/* margins filled in by hpjet_open */
-		  1, djet500_print_page_copies);
+struct gx_device_hpjet_s {
+    gx_device_common;
+    gx_prn_device_common;
+    int MediaPosition;
+    bool MediaPosition_set;
+    bool ManualFeed;
+    bool ManualFeed_set;
+};
 
-const gx_device_printer gs_fs600_device =
-prn_device_copies(prn_hp_procs, "fs600",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI2, Y_DPI2,
-		  0.23, 0.0, 0.23, 0.04,      /* margins */
-		  1, fs600_print_page_copies);
+#define HPJET_DEVICE(procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page_copies)\
+  { prn_device_std_margins_body_copies(gx_device_hpjet, procs, dname, \
+        w10, h10, xdpi, ydpi, lm, tm, lm, bm, rm, tm, color_bits, \
+        print_page_copies), \
+    0, false, false, false }
 
-const gx_device_printer gs_laserjet_device =
-prn_device_copies(prn_hp_procs, "laserjet",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI, Y_DPI,
-		  0.05, 0.25, 0.55, 0.25,	/* margins */
-		  1, ljet_print_page_copies);
+const gx_device_hpjet gs_deskjet_device =
+HPJET_DEVICE(prn_hp_procs, "deskjet",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI, Y_DPI,
+	     0, 0, 0, 0,		/* margins filled in by hpjet_open */
+	     1, djet_print_page_copies);
 
-const gx_device_printer gs_ljetplus_device =
-prn_device_copies(prn_hp_procs, "ljetplus",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI, Y_DPI,
-		  0.05, 0.25, 0.55, 0.25,	/* margins */
-		  1, ljetplus_print_page_copies);
+const gx_device_hpjet gs_djet500_device =
+HPJET_DEVICE(prn_hp_procs, "djet500",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI, Y_DPI,
+	     0, 0, 0, 0,		/* margins filled in by hpjet_open */
+	     1, djet500_print_page_copies);
 
-const gx_device_printer gs_ljet2p_device =
-prn_device_copies(prn_hp_procs, "ljet2p",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI, Y_DPI,
-		  0.20, 0.25, 0.25, 0.25,	/* margins */
-		  1, ljet2p_print_page_copies);
+const gx_device_hpjet gs_fs600_device =
+HPJET_DEVICE(prn_hp_procs, "fs600",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI2, Y_DPI2,
+	     0.23, 0.0, 0.23, 0.04,      /* margins */
+	     1, fs600_print_page_copies);
 
-const gx_device_printer gs_ljet3_device =
-prn_device_copies(prn_hp_procs, "ljet3",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI, Y_DPI,
-		  0.20, 0.25, 0.25, 0.25,	/* margins */
-		  1, ljet3_print_page_copies);
+const gx_device_hpjet gs_laserjet_device =
+HPJET_DEVICE(prn_hp_procs, "laserjet",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI, Y_DPI,
+	     0.05, 0.25, 0.55, 0.25,	/* margins */
+	     1, ljet_print_page_copies);
 
-const gx_device_printer gs_ljet3d_device =
-prn_device_copies(prn_hp_procs, "ljet3d",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI, Y_DPI,
-		  0.20, 0.25, 0.25, 0.25,	/* margins */
-		  1, ljet3d_print_page_copies);
+const gx_device_hpjet gs_ljetplus_device =
+HPJET_DEVICE(prn_hp_procs, "ljetplus",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI, Y_DPI,
+	     0.05, 0.25, 0.55, 0.25,	/* margins */
+	     1, ljetplus_print_page_copies);
 
-const gx_device_printer gs_ljet4_device =
-prn_device_copies(prn_hp_procs, "ljet4",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI2, Y_DPI2,
-		  0, 0, 0, 0,		/* margins */
-		  1, ljet4_print_page_copies);
+const gx_device_hpjet gs_ljet2p_device =
+HPJET_DEVICE(prn_hp_procs, "ljet2p",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI, Y_DPI,
+	     0.20, 0.25, 0.25, 0.25,	/* margins */
+	     1, ljet2p_print_page_copies);
 
-const gx_device_printer gs_ljet4d_device =
-prn_device_copies(prn_hp_procs, "ljet4d",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI2, Y_DPI2,
-		  0, 0, 0, 0,		/* margins */
-		  1, ljet4d_print_page_copies);
+const gx_device_hpjet gs_ljet3_device =
+HPJET_DEVICE(prn_hp_procs, "ljet3",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI, Y_DPI,
+	     0.20, 0.25, 0.25, 0.25,	/* margins */
+	     1, ljet3_print_page_copies);
 
-const gx_device_printer gs_lp2563_device =
-prn_device_copies(prn_hp_procs, "lp2563",
-		  DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
-		  X_DPI, Y_DPI,
-		  0, 0, 0, 0,		/* margins */
-		  1, lp2563_print_page_copies);
+const gx_device_hpjet gs_ljet3d_device =
+HPJET_DEVICE(prn_hp_procs, "ljet3d",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI, Y_DPI,
+	     0.20, 0.25, 0.25, 0.25,	/* margins */
+	     1, ljet3d_print_page_copies);
 
-const gx_device_printer gs_oce9050_device =
-prn_device_copies(prn_hp_procs, "oce9050",
-		  24 * 10, 24 * 10,	/* 24 inch roll (can print 32" also) */
-		  400, 400,		/* 400 dpi */
-		  0, 0, 0, 0,		/* margins */
-		  1, oce9050_print_page_copies);
+const gx_device_hpjet gs_ljet4_device =
+HPJET_DEVICE(prn_hp_procs, "ljet4",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI2, Y_DPI2,
+	     0, 0, 0, 0,		/* margins */
+	     1, ljet4_print_page_copies);
+
+const gx_device_hpjet gs_ljet4d_device =
+HPJET_DEVICE(prn_hp_procs, "ljet4d",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI2, Y_DPI2,
+	     0, 0, 0, 0,		/* margins */
+	     1, ljet4d_print_page_copies);
+
+const gx_device_hpjet gs_lp2563_device =
+HPJET_DEVICE(prn_hp_procs, "lp2563",
+	     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
+	     X_DPI, Y_DPI,
+	     0, 0, 0, 0,		/* margins */
+	     1, lp2563_print_page_copies);
+
+const gx_device_hpjet gs_oce9050_device =
+HPJET_DEVICE(prn_hp_procs, "oce9050",
+	     24 * 10, 24 * 10,	/* 24 inch roll (can print 32" also) */
+	     400, 400,		/* 400 dpi */
+	     0, 0, 0, 0,		/* margins */
+	     1, oce9050_print_page_copies);
 
 /* Open the printer, adjusting the margins if necessary. */
 private int
@@ -263,23 +282,47 @@
 
 /* ------ Internal routines ------ */
 
+/* Make an init string that contains paper tray selection. The resulting
+   init string is stored in buf, so make sure that buf is at least 5
+   bytes larger than str. */
+private void
+hpjet_make_init(gx_device_printer *pdev, char *buf, const char *str)
+{
+    gx_device_hpjet *dev = (gx_device_hpjet *)pdev;
+    int paper_source = -1;
+    int paper_source_tab[] = { 5, 1 };
+
+    if (dev->ManualFeed_set && dev->ManualFeed) paper_source = 2;
+    else if (dev->MediaPosition_set && dev->MediaPosition >= 0 &&
+	     dev->MediaPosition < countof(paper_source_tab))
+	paper_source = paper_source_tab[dev->MediaPosition];
+    if (paper_source >= 0)
+	sprintf(buf, "%s\033&l%dH", str, paper_source);
+    else
+	sprintf(buf, "%s", str);
+}
+
 /* The DeskJet can compress (mode 2) */
 private int
 djet_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
 		       int num_copies)
 {
+    char init[80];
+
+    hpjet_make_init(pdev, init, "\033&k1W\033*b2M");
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					300, PCL_DJ_FEATURES,
-					"\033&k1W\033*b2M");
+					300, PCL_DJ_FEATURES, init);
 }
 /* The DeskJet500 can compress (modes 2&3) */
 private int
 djet500_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
 			  int num_copies)
 {
+    char init[80];
+
+    hpjet_make_init(pdev, init, "\033&k1W");
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					300, PCL_DJ500_FEATURES,
-					"\033&k1W");
+					300, PCL_DJ500_FEATURES, init);
 }
 /* The Kyocera FS-600 laser printer (and perhaps other printers */
 /* which use the PeerlessPrint5 firmware) doesn't handle        */
@@ -289,30 +332,36 @@
 			int num_copies)
 {
     int dots_per_inch = (int)pdev->y_pixels_per_inch;
-    char real_init[60];
+    char base_init[60];
+    char init[80];
 
-    sprintf(real_init, "\033*r0F\033&u%dD", dots_per_inch);
+    sprintf(base_init, "\033*r0F\033&u%dD", dots_per_inch);
+    hpjet_make_init(pdev, init, base_init);
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
 					dots_per_inch, PCL_FS600_FEATURES,
-					real_init);
+					init);
 }
 /* The LaserJet series II can't compress */
 private int
 ljet_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
 		       int num_copies)
 {
+    char init[80];
+
+    hpjet_make_init(pdev, init, "\033*b0M");
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					300, PCL_LJ_FEATURES,
-					"\033*b0M");
+					300, PCL_LJ_FEATURES, init);
 }
 /* The LaserJet Plus can't compress */
 private int
 ljetplus_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
 			   int num_copies)
 {
+    char init[80];
+
+    hpjet_make_init(pdev, init, "\033*b0M");
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					300, PCL_LJplus_FEATURES,
-					"\033*b0M");
+					300, PCL_LJplus_FEATURES, init);
 }
 /* LaserJet series IIp & IId compress (mode 2) */
 /* but don't support *p+ or *b vertical spacing. */
@@ -320,9 +369,11 @@
 ljet2p_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
 			 int num_copies)
 {
+    char init[80];
+
+    hpjet_make_init(pdev, init, "\033*r0F\033*b2M");
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					300, PCL_LJ2p_FEATURES,
-					"\033*r0F\033*b2M");
+					300, PCL_LJ2p_FEATURES, init);
 }
 /* All LaserJet series IIIs (III,IIId,IIIp,IIIsi) compress (modes 2&3) */
 /* They also need their coordinate system translated slightly. */
@@ -330,18 +381,22 @@
 ljet3_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
 			int num_copies)
 {
+    char init[80];
+
+    hpjet_make_init(pdev, init, "\033&l-180u36Z\033*r0F");
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					300, PCL_LJ3_FEATURES,
-					"\033&l-180u36Z\033*r0F");
+					300, PCL_LJ3_FEATURES, init);
 }
 /* LaserJet IIId is same as LaserJet III, except for duplex */
 private int
 ljet3d_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
 			 int num_copies)
 {
+    char init[80];
+
+    hpjet_make_init(pdev, init, "\033&l-180u36Z\033*r0F");
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					300, PCL_LJ3D_FEATURES,
-					"\033&l-180u36Z\033*r0F");
+					300, PCL_LJ3D_FEATURES, init);
 }
 /* LaserJet 4 series compresses, and it needs a special sequence to */
 /* allow it to specify coordinates at 600 dpi. */
@@ -351,24 +406,28 @@
 			int num_copies)
 {
     int dots_per_inch = (int)pdev->y_pixels_per_inch;
-    char real_init[60];
+    char base_init[60];
+    char init[80];
 
-    sprintf(real_init, "\033&l-180u36Z\033*r0F\033&u%dD", dots_per_inch);
+    sprintf(base_init, "\033&l-180u36Z\033*r0F\033&u%dD", dots_per_inch);
+    hpjet_make_init(pdev, init, base_init);
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
 					dots_per_inch, PCL_LJ4_FEATURES,
-					real_init);
+					init);
 }
 private int
 ljet4d_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];
+    char base_init[60];
+    char init[80];
 
-    sprintf(real_init, "\033&l-180u36Z\033*r0F\033&u%dD", dots_per_inch);
+    sprintf(base_init, "\033&l-180u36Z\033*r0F\033&u%dD", dots_per_inch);
+    hpjet_make_init(pdev, init, base_init);
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
 					dots_per_inch, PCL_LJ4D_FEATURES,
-					real_init);
+					init);
 }
 /* The 2563B line printer can't compress */
 /* and doesn't support *p+ or *b vertical spacing. */
@@ -376,9 +435,11 @@
 lp2563_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
 			 int num_copies)
 {
+    char init[80];
+
+    hpjet_make_init(pdev, init, "\033*b0M");
     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					300, PCL_LP2563B_FEATURES,
-					"\033*b0M");
+					300, PCL_LP2563B_FEATURES, init);
 }
 /* The Oce line printer has TIFF compression */
 /* and doesn't support *p+ or *b vertical spacing. */
@@ -387,6 +448,7 @@
 			  int num_copies)
 {
     int code;
+    char init[80];
 
     /* Switch to HP_RTL. */
     fputs("\033%1B", prn_stream);	/* Enter HPGL/2 mode */
@@ -394,9 +456,10 @@
     fputs("IN;", prn_stream);	/* Initialize (start plot) */
     fputs("\033%1A", prn_stream);	/* Enter PCL mode */
 
+    hpjet_make_init(pdev, init, "\033*b0M");
+
     code = dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
-					400, PCL_OCE9050_FEATURES,
-					"\033*b3M");
+					400, PCL_OCE9050_FEATURES, init);
 
     /* Return to HPGL/2 mode. */
     fputs("\033%1B", prn_stream);	/* Enter HPGL/2 mode */
@@ -408,3 +471,53 @@
     }
     return code;
 }
+
+private int
+hpjet_get_params(gx_device *pdev, gs_param_list *plist)
+{
+    gx_device_hpjet *dev = (gx_device_hpjet *)pdev;
+    int code = gdev_prn_get_params(dev, plist);
+
+    if (code >= 0)
+	code = param_write_bool(plist, "ManualFeed", &dev->ManualFeed);
+    return code;
+}
+
+private int
+hpjet_put_params(gx_device *pdev, gs_param_list *plist)
+{
+    gx_device_hpjet *dev = (gx_device_hpjet *)pdev;
+    int code;
+    bool ManualFeed;
+    bool ManualFeed_set = false;
+    int MediaPosition;
+    bool MediaPosition_set = false;
+
+    code = param_read_bool(plist, "ManualFeed", &ManualFeed);
+    if (code == 0) ManualFeed_set = true;
+    if (code >= 0) {
+	code = param_read_int(plist, "%MediaSource", &MediaPosition);
+	if (code == 0) MediaPosition_set = true;
+	else if (code < 0) {
+	    if (param_read_null(plist, "%MediaSource") == 0) {
+		code = 0;
+	    }
+	}
+    }
+
+    if (code >= 0)
+	code = gdev_prn_put_params(pdev, plist);
+
+    if (code >= 0) {
+	if (ManualFeed_set) {
+	    dev->ManualFeed = ManualFeed;
+	    dev->ManualFeed_set = true;
+	}
+	if (MediaPosition_set) {
+	    dev->MediaPosition = MediaPosition;
+	    dev->MediaPosition_set = true;
+	}
+    }
+
+    return code;
+}



More information about the gs-cvs mailing list