We match the CUPS returned media to standard media here
http://hg.openjdk.java.net/jdk9/client/jdk/file/03c248ab7484/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java#l218
As per getPageSizes(), it returns the size of the media as
mentioned(including margin) but the testcase actually sets imageablearea
to (0,0,paperwidth,paperheight) which matches one of the many page size(s)
as I earlier mentioned, (0,0,8.26",11.69") is within supported mpa of a
paper size 0,0,11.69",16.52" (which is one of the pagesize returned by
getPageSizes()) so it means 0,0,8",11" comes out to be supported mpa
and so it was allowed (eventhough printer cannot print from 0,0)
so we should also take care of the printer-allowable (hardware) margin
which in windows was taken care of by GetDeviceCaps(printDC,
PHYSICALOFFSETX) function so I had to add getHWMargin() in linux here in
this fix.
Modified webrev which passes JPRT is here
http://cr.openjdk.java.net/~psadhukhan/6574279/webrev.04/
Regards
Prasanta
On 8/19/2016 3:56 AM, Philip Race wrote:
PS as I just mentioned in another review thread, I have
a suspicion that the Media and MPA for CUPS are never matched
to "standard" (pre-defined in API) ones. I don't know how much this
matters - A4
when sent to printing should (he says) get matched on size
to the right media but you should check that, but this also
may mean that if you try to get the MPA for the "standard"
MediaSizeName.ISO_A4
none will be found .. all this sets back this fix until you work
through that
but I don't think the fix can be completely right until we have an
understanding
and resolution on that.
-phil.
On 8/17/16, 12:07 PM, Phil Race wrote:
The cups docs say you can get physical margins as described here :
http://opensource.apple.com//source/cups/cups-62/doc/spm.shtml?txt#CUPS_API
------------------------
PPD files specify all of the available pages sizes and the physical
margins associated with them. ...
ppd_sizet_ size = ppdPageSize(ppd, "/size/"); ...
The|||ppd_size_t| structure contains the width, length, and margin
information:
typedef struct /**** Page Sizes ****/
{
int marked; /* Page size selected? */
char name[41]; /* Media size option */
float width, /* Width of media in points */
length, /* Length of media in points */
left, /* Left printable margin in points */
bottom, /* Bottom printable margin in points */
right, /* Right printable margin in points */
top; /* Top printable margin in points */
} ppd_size_t;
--------------------
Moreover we are *already* calling that code : See
Java_sun_print_CUPSPrinter_getPageSizes Does that not work ? Perhaps
the gap is that CUPSPrinter.java does not tie the MPA to the Media it
has created. Not sure of the best way to do this. Maybe the windows
code solves this differently but a simple HashMap may work here.
You'll have to investigate. A few specific comments on the code :-
484 if (option != NULL && option->num_choices > 0) { we are expecting
an array of 4 elements here so may be >=4 is what we should require ?
500 JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
comment seems to be a copy from an earlier line .. this is about
allocating an array 516 @Override 517 protected void
validatePaper(Paper origPaper, Paper newPaper) { 518 if
(!(getPrintService() instanceof IPPPrintService)) { 519
super.validatePaper(origPaper, newPaper); 520 return;
Hmm. IPPPrintService is Unix only whereas PSPrinterJob is shared
code .. so I will bet you didn't try yet to compile this on Windows.
-phil. On 8/16/16, 4:47 AM, Prasanta Sadhukhan wrote:
Hi All,
On 8/11/2016 2:08 PM, Prasanta Sadhukhan wrote:
Hi Phil,
On 8/11/2016 3:05 AM, Phil Race wrote:
There does not seem to be a link to the new webrev in here. Is it
this : http://cr.openjdk.java.net/~psadhukhan/6574279/webrev.01/ ?
> to default Paper (Letter in US, A4 otherwise) imageable area I
don't think that will ever be A4. Where is that coming from ? And
you still have not fixed the problem with how you retrieve the MPA
:- 512 MediaPrintableArea mpa = (MediaPrintableArea)
513
getPrintService().getDefaultAttributeValue(MediaPrintableArea.class);
It is not supposed to be the MPA of the *default* paper. You want
the MPA of *this* paper. Only if origPaper is not a supported
paper do you go look for the default paper.
As you suggested, I have modified to check if mpa of origPaper is
amongst supported mpa(s) of the printer, if not, then go for mpa of
default paper. However, it seems among 61 mpas returned by
CUPSPrinter , origPaper of 0,0,8.26",11.69" is within supported mpa
of a paper size 0,0,11.69",16.52" so it means 0,0,8",11" comes out
to be supported mpa. Can you please comment on this modified webrev
on what more we can do?
http://cr.openjdk.java.net/~psadhukhan/6574279/webrev.02/ I guess
we need to find out the physical limitation of printer via CUPS
same what we do in windows via GetDeviceCaps(printDC,
PHYSICALOFFSETX); and use that in calculation for valid margin but
I could not find equivalent cups function. Can you suggest anyways?
I tried calling ppdFindOption(ppd, "HWMargins") in CUPS but it
returns null although my printer ppd file has this line *%=== Custom
Paper Support ================= *LeadingEdge Short: "" *LeadingEdge
Long: "" *DefaultLeadingEdge: Short *MaxMediaWidth: "865"
*MaxMediaHeight: "1701" **HWMargins: 12 12 12 12 *Anyways, I
have updated the webrev to take care of the review comments and also
get HWMargin (if the above ppdFindOption return null then fall back
to custom margin as reported via ppd_file_t structure
https://www.cups.org/doc/api-ppd.html#ppd_file_s)
http://cr.openjdk.java.net/~psadhukhan/6574279/webrev.03/ Please
review. Tested in ubuntu and solaris11. Regards Prasanta
Regards Prasanta
-phil. On 08/05/2016 03:20 AM, Prasanta Sadhukhan wrote:
On 8/4/2016 5:45 PM, Prasanta Sadhukhan wrote:
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.
I have modified to do the change in PSPrinterJob. Regarding the
equal margin, we do the same in
http://hg.openjdk.java.net/jdk9/client/jdk/file/abb2a39948fe/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java#l688
http://cr.openjdk.java.net/~psadhukhan/6574279/webrev.01/
That does not seem to be the same case as this. -phil.
Regards Prasanta
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