Skip to content

Commit

Permalink
8234393: [macos] printing ignores printer tray
Browse files Browse the repository at this point in the history
Reviewed-by: psadhukhan, prr
  • Loading branch information
vipinmenon authored and prsadhuk committed Oct 20, 2020
1 parent 3f9c8a3 commit 3ee0380
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -44,6 +44,7 @@
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaSizeName;
import javax.print.attribute.standard.PageRanges;
import javax.print.attribute.Attribute;

import sun.java2d.*;
import sun.print.*;
Expand All @@ -64,6 +65,8 @@ public final class CPrinterJob extends RasterPrinterJob {

private static Font defaultFont;

private String tray = null;

// This is the NSPrintInfo for this PrinterJob. Protect multi thread
// access to it. It is used by the pageDialog, jobDialog, and printLoop.
// This way the state of these items is shared across these calls.
Expand Down Expand Up @@ -179,6 +182,11 @@ protected void setAttributes(PrintRequestAttributeSet attributes) throws Printer
if (attributes == null) {
return;
}
Attribute attr = attributes.get(Media.class);
if (attr instanceof CustomMediaTray) {
CustomMediaTray customTray = (CustomMediaTray) attr;
tray = customTray.getChoiceName();
}

PageRanges pageRangesAttr = (PageRanges)attributes.get(PageRanges.class);
if (isSupportedValue(pageRangesAttr, attributes)) {
Expand Down Expand Up @@ -631,6 +639,10 @@ private String getPrinterName(){
return service.getName();
}

private String getPrinterTray() {
return tray;
}

private void setPrinterServiceFromNative(String printerName) {
// This is called from the native side.
PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
Expand Down
10 changes: 9 additions & 1 deletion src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -546,6 +546,7 @@ static JNF_MEMBER_CACHE(jm_getDestinationFile, sjc_CPrinterJob,
static JNF_MEMBER_CACHE(jm_getPageFormatArea, sjc_CPrinterJob, "getPageFormatArea", "(Ljava/awt/print/PageFormat;)Ljava/awt/geom/Rectangle2D;");
static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
static JNF_MEMBER_CACHE(jm_getPageable, sjc_CPrinterJob, "getPageable", "()Ljava/awt/print/Pageable;");
static JNF_MEMBER_CACHE(jm_getPrinterTray, sjc_CPrinterJob, "getPrinterTray", "()Ljava/lang/String;");

jboolean retVal = JNI_FALSE;

Expand All @@ -560,6 +561,13 @@ static JNF_MEMBER_CACHE(jm_getDestinationFile, sjc_CPrinterJob,
[printerView setFirstPage:firstPage lastPage:lastPage];

NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, jthis, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
jobject printerTrayObj = JNFCallObjectMethod(env, jthis, jm_getPrinterTray);
if (printerTrayObj != NULL) {
NSString *printerTray = JNFJavaToNSString(env, printerTrayObj);
if (printerTray != nil) {
[[printInfo printSettings] setObject:printerTray forKey:@"InputSlot"];
}
}

// <rdar://problem/4156975> passing jthis CPrinterJob as well, so we can extract the printer name from the current job
javaPageFormatToNSPrintInfo(env, jthis, page, printInfo);
Expand Down
4 changes: 2 additions & 2 deletions src/java.desktop/share/classes/sun/print/CustomMediaTray.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import javax.print.attribute.standard.Media;
import java.util.ArrayList;

class CustomMediaTray extends MediaTray {
public class CustomMediaTray extends MediaTray {
private static ArrayList<String> customStringTable = new ArrayList<>();
private static ArrayList<MediaTray> customEnumTable = new ArrayList<>();
private String choiceName;
Expand Down
Expand Up @@ -21,9 +21,9 @@
* questions.
*/
/*
* @bug 6357887 8165146
* @bug 6357887 8165146 8234393
* @summary Verifies if selected printertray is used
* @requires os.family == "linux"
* @requires (os.family == "linux" | os.family == "mac")
* @run main/manual TestMediaTraySelection
*/

Expand Down

1 comment on commit 3ee0380

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 3ee0380 Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.