[OpenJDK 2D-Dev] [9] RFR JDK-6574279: validatePage from PrinterJob returns argument under linux

Prasanta Sadhukhan prasanta.sadhukhan at oracle.com
Thu Aug 4 12:15:32 UTC 2016


I will override in PSPrinterJob but
1662             MediaPrintableArea mpa =
1663                         (MediaPrintableArea)getPrintService().
1664 getDefaultAttributeValue(MediaPrintableArea.class);

is returning imageable area of default media of chosen printer from CUPS 
[ all supported media printable area is obtained from 
CUPSPrinter#getPageSizes(printer) & then initMedia() populates 
cupsMediaPrintables which is returned in getMediaPrintableArea()]
as IPPPrintService#getDefaultAttributeValue() does
----------
if (category == MediaPrintableArea.class) {
             MediaPrintableArea[] mpas;
              if ((cps != null)  &&
                  ((mpas = *cps.getMediaPrintableArea()*) != null)) {
                  if (defaultMediaIndex == -1) {
                      // initializes value of defaultMediaIndex
                      getDefaultAttributeValue(Media.class);
                  }
                  return mpas[*defaultMediaIndex*];
              }
--------------
by which mpas[defaultMediaIndex] returns default media printable area.
In else block, we instantiate mpa of Letter for US locale and A4 for 
other locales so I was not checking for null as in both if and else 
block , I was getting MediaPrintableArea instance.

Regarding considering equal margins, I am not sure if there was any way 
I could get right and left margin separately.
Please let me know if there is any way you know of.

Regards
Prasanta
On 8/4/2016 2:32 AM, Philip Race wrote:
> High-level question. Why is this not an over-ride in PSPrinterJob ?
>
>
> I'm afraid I did not get much past the first line of the change :
> 1662             MediaPrintableArea mpa =
> 1663 (MediaPrintableArea)getPrintService().
> 1664 getDefaultAttributeValue(MediaPrintableArea.class);
>
> Read the docs for MediaPrintableArea :-
> ---
> To query for the printable area, a client must supply a suitable context.
> Without specifying at the very least the size of the media being used
> no meaningful value for printable area can be obtained.
> ---
>
> .. not to mention you assume a non-null return.
>
> and then you use new Paper() .. which is a constructor which
> knows nothing about the printer. It is *speced* to return
> US letter with one inch margins.
>
> Another reason why this seems like it should be a sub-class over-ride.
>
>
> Also this looks wrong ---
> 1672             if ((imgX*2) + imgWid > wid) {
> 1673                 imgWid = wid - imgX*2;
> 1674             }
>
> You can't assume equal margins.
>
> -phil.
>
> On 7/12/16, 5:05 AM, Prasanta Sadhukhan wrote:
>> Hi All,
>>
>> Please review a fix for an issue where it is seen that if user sets 
>> invalid imageablearea via Paper.setImageableArea and
>> then calls PrinterJob.validatePage() in linux, then it does not get a 
>> valid pageformat
>>
>> Bug: https://bugs.openjdk.java.net/browse/JDK-6574279
>> webrev: http://cr.openjdk.java.net/~psadhukhan/6574279/webrev.00/
>>
>> Fix is to check for margin as noted via CUPS ppdPageSize() and then 
>> calculate to find the valid margin in validatePaper()
>> similar to what we do in native validatePaper() in windows.
>>
>> Regards
>> Prasanta

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20160804/21d1143e/attachment.html>


More information about the 2d-dev mailing list