Bug 690182 - Tray selection (MediaSource) on PCL 4/5 drivers does not work and so an ugly Perl workaround in Foomatic is needed
Summary: Tray selection (MediaSource) on PCL 4/5 drivers does not work and so an ugly ...
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Printer Driver (show other bugs)
Version: 8.63
Hardware: All All
: P4 normal
Assignee: Ray Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-25 01:44 UTC by Till Kamppeter
Modified: 2021-10-09 12:15 UTC (History)
2 users (show)

See Also:
Customer:
Word Size: ---


Attachments
pcl-input-slot-fix.patch (1.45 KB, patch)
2008-11-25 01:46 UTC, Till Kamppeter
Details | Diff
pclMediaPosition.patch (1008 bytes, patch)
2009-01-30 13:40 UTC, jason r. totten
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Till Kamppeter 2008-11-25 01:44:21 UTC
According to the source code the drivers for PCL 4, 5, and 5e (laserjet,
lj4dith, lj4dithp, ljet2p, ljet3, ljet3d, ljet4, ljet4d, ljet4pjl, ljetplus)
support tray selection (source file base/gdevdjet.c). In reality this does not
work. If I supply the "-dMediaPosition=..." or "-d%MediaSource=..." options with
small integer numbers (0, 1, 2, ...) on the command line, nothing changes in the
output file.

The attached patch fixes the problem. With the patch applied I can supply the
"-dMediaPosition=..." with the integer numbers listed in the PCL documentation
and appropriate trays get selected.

Cited from PCL 5 documentation:

------------------------------------------------------------------------------
Designates one of four paper sources for paper feed.
  <ESC>&l#H
        #=    0 - Print current page (paper source remains unchanged)
              1 - Feed paper from main paper source
              2 - Feed paper from manual input
              3 - Feed envelope from manual input
              4 - Feed paper from alternate paper source
              5 - Feed from optional large paper source
              6 - Feed envelope from envelope feeder *
              7 - Autoselect
              8 - Feed paper from Tray 1 (right side tray)
            20 - 39 - High Capacity Input (HCI) Trays 2-21
------------------------------------------------------------------------------

The reason why I did not upload it directly is a possible interface change, but
perhaps this is no problem as it did not work before, anyway.

The changes now are that the paper tray selection is now directly taken from the
setapgedevice dictionary variable /MediaPosition and not from /%MediaSource any
more (like it was all the time done by the PCL-XL drivers pxlmono and pxlcolor,
base/gdevpx.c). In addition, the old hpjet_make_init() function restricted the
tray selection artificially to the main tray and the large capacity tray with
the latter as default. On real printers there are many more tray options
available. Interface change here is that the choices "0" and "1" for
/MediaPosition have other meanings now (Default and Main instead of Large
Capacity and Main), but this can be simply worked around by setting the large
capacity tray as default in the printer's front panel menus.

The big advantage of the change is that I can get rid of the ugly Perl
workarounds in Foomatic. Now I can control trays by a decent "InputSlot" option
which controls the Ghostscript command line option "-dMediaPosition=...".
Comment 1 Till Kamppeter 2008-11-25 01:46:40 UTC
Created attachment 4622 [details]
pcl-input-slot-fix.patch

Patch to allow paper tray selection via "-dMediaPosition=..." in PCL 4/5
drivers
Comment 2 Till Kamppeter 2008-11-25 01:53:12 UTC
I also did not find any documentation for these drivers, so there cannot be
broken any documented behavior.
Comment 3 Till Kamppeter 2008-11-25 09:26:07 UTC
Patch committed to the Subversion Repository as revision 9241. Needs review
whether it does not have any unwished side effects. Henrys recommended for
getting this checked by Ray.
Comment 4 Ray Johnston 2008-12-04 10:10:21 UTC
Thanks for the patch!
Comment 5 jason r. totten 2009-01-30 13:14:05 UTC
Quick suggestion - I found this bug here after finding it and fixing it in the
code. (How sad I was that the order wasn't the other way around) - I believe we
could make this a little better by requiring it to be a valid PCL5/6 tray
option, and it's pretty straightforward. 
In hpjet_make_init we just set up an array full of the options, then loop
through and only set it if our value passed in is a match, otherwise - don't put
the parameter in the output file.

I'll edit the patch, but I'm pasting this here as well first.

------
static 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;
    /* valid PCL5/6 Trays */
    int paper_valid_trays[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 };

    if (dev->ManualFeed_set && dev->ManualFeed) paper_source = 2;
    else if (dev->MediaPosition_set && dev->MediaPosition >= 0 ){
           int i;
           for (i = 0; i < countof(paper_valid_trays); i++){
              if (dev->MediaPosition == paper_valid_trays[i]){
                paper_source = dev->MediaPosition;
                break;
              }
           }
    }

    if (paper_source >= 0)....
Comment 6 jason r. totten 2009-01-30 13:22:55 UTC
shoot. I've not created a patch via SVN before - I'll try to get it in here soon.
Comment 7 jason r. totten 2009-01-30 13:40:17 UTC
Created attachment 4771 [details]
pclMediaPosition.patch

forcing valid tray selection...
Comment 8 jason r. totten 2009-01-30 13:41:01 UTC
Patch attached.
Comment 9 Till Kamppeter 2010-06-30 20:06:17 UTC
jason r. totten, thank you for your suggestion, but I would rather not force the tray values, as there can be non-HP printers which use PCL and they do not have necessarily the same scheme of tray numbers. Controlling the selection by only offering the correct ones for the printer currently in use, for example via a PPD file is the better alternative in my opinion.
Comment 10 Till Kamppeter 2010-06-30 20:07:38 UTC
Closing the bug again ...
Comment 11 Hin-Tak Leung 2012-05-19 23:57:14 UTC
(In reply to comment #1)
> Created an attachment (id=4622) [details]
> pcl-input-slot-fix.patch

While working on bug 692914 (which does MediaSource/MediaType for the pxl driver, rather than pcl5), I looked at related code elsewhere and realize this patch introduced a bug - the 

...
param_write_int(plist, "MediaPosition", &dev->MediaPosition);
...

chunk (copying media position from the driver back to the language core) should not be there, as it is clearly stated in the documentation that this information should only go one-way, from the language core to the driver; if that code is included, the code should be conditional on it being set previously, i.e.

...
if (dev->MediaPosition_set)
 code = param_write_int(plist, "MediaPosition", &dev->MediaPosition);
...

otherwise there is a danger of copying an unintialized value of bogus MediaPosition (=0, mostly) where none had ever been specified, into the language core and that bogus value gets copied back in the next invocation of param_read()  .
Comment 12 Peter Cherepanov 2021-01-04 02:20:39 UTC
Valgrind finds no uninitialized variables in
 
valgrind ~/ghostpdl/debugbin/gs -sDEVICE=ljet4 -o /dev/null -c currentpagedevice setpagedevice

What's wrong with 0 as an initial value for /MediaPosition ?
Comment 13 Ken Sharp 2021-10-09 12:15:18 UTC
This has been idle for 9 years. If there is a genuine bug (comment #11) please open a new bug report for it.