From 347dd4d05c07bf21d2258baa45dd1119e5d56906 Mon Sep 17 00:00:00 2001 From: vtstydev Date: Thu, 7 Dec 2023 10:53:53 +0200 Subject: [PATCH 01/11] More correct way to take in consideration nonzero PHYSICALOFFSETX,PHYSICALOFFSETY of device for banded-raster printing loop --- .../share/classes/sun/print/RasterPrinterJob.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java index 0cf9c16f166a0..d19d28dcbc22a 100644 --- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java @@ -2396,6 +2396,7 @@ protected int printPage(Pageable document, int pageIndex) * the page on the next iteration of the loop. */ bandGraphics.setTransform(uniformTransform); + bandGraphics.translate(-deviceAddressableX,deviceAddressableY); bandGraphics.transform(deviceTransform); deviceTransform.translate(0, -bandHeight); @@ -2418,12 +2419,12 @@ protected int printPage(Pageable document, int pageIndex) * We also need to translate by the adjusted amount * so that printing appears in the correct place. */ - int bandX = deviceLeft - deviceAddressableX; + int bandX = deviceLeft; if (bandX < 0) { bandGraphics.translate(bandX/xScale,0); bandX = 0; } - int bandY = deviceTop + bandTop - deviceAddressableY; + int bandY = deviceTop; if (bandY < 0) { bandGraphics.translate(0,bandY/yScale); bandY = 0; @@ -2434,7 +2435,7 @@ protected int printPage(Pageable document, int pageIndex) painterGraphics.setDelegate((Graphics2D) bandGraphics.create()); painter.print(painterGraphics, origPage, pageIndex); painterGraphics.dispose(); - printBand(data, bandX, bandY, bandWidth, bandHeight); + printBand(data, bandX, bandTop+bandY, bandWidth, bandHeight); } } From 62168fb3a4fe9f0246986283ed8c08740a40a924 Mon Sep 17 00:00:00 2001 From: vtstydev Date: Thu, 25 Jan 2024 12:55:28 +0200 Subject: [PATCH 02/11] Add test for comparing offsets of images --- .../ImagePrinting/AlphaPrintingOffsets.java | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java new file mode 100644 index 0000000000000..127e89ca104c9 --- /dev/null +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2007, 2022, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.Sides; +import javax.swing.*; +import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.print.*; +import java.awt.print.PrinterException; + +import static java.awt.print.PageFormat.*; + +/* + * @test + * @bug 8307246 + * @key printer + * @library ../../../regtesthelpers + * @build PassFailJFrame + * @summary Test for comparing offsets of images drew with opaque and translucent colors printed in all orientations + * @run main/manual AlphaPrintingOffsets + */ + +public class AlphaPrintingOffsets { + private static final String INSTRUCTIONS = + "This test prints 6 pages with same image except text messages. \n" + + "Tested bug occurs only on-paper printing so you mustn't use PDF printer\n" + + "1.Java print dialog should appear.\n" + + "2. Press the Print button on the Java Print dialog.\n"+ + "3. Check that 6 pages have the same image except text messages.\n"+ + "If so, press PASS, else press FAIL."; + + public static void main(String[] args) throws Exception { + if (PrinterJob.lookupPrintServices().length > 0) { + + PassFailJFrame.builder().instructions(INSTRUCTIONS) + .testUI(() -> createTestUI()).build().awaitAndCheck(); + + } + else { + System.out.println("Printer not configured or available." + + " Test cannot continue."); + PassFailJFrame.forcePass(); + } + + } + + public static JFrame createTestUI() { + JFrame testUI = new JFrame("Print images"); + testUI.setSize(1,1); + testUI.addWindowListener(new WindowAdapter() { + @Override + public void windowOpened(WindowEvent e) { + super.windowOpened(e); + print(); + } + + @Override + public void windowActivated(WindowEvent e) { + super.windowActivated(e); + testUI.setVisible(false); + } + }); + + return testUI; + } + + private static void print() { + PrinterJob printerJob = PrinterJob.getPrinterJob(); + PageFormat pageFormatP = printerJob.defaultPage(); + + Paper paper = pageFormatP.getPaper(); + paper.setImageableArea(0,0,paper.getWidth(),paper.getHeight()); + pageFormatP.setPaper(paper); + + PageFormat pageFormatL = (PageFormat) pageFormatP.clone(); + PageFormat pageFormatRL = (PageFormat) pageFormatP.clone(); + + pageFormatL.setOrientation(LANDSCAPE); + pageFormatRL.setOrientation(REVERSE_LANDSCAPE); + + Printable printableOpaque = new CustomPrintable(255); + Printable printableTransparent = new CustomPrintable(254); + + Book book = new Book(); + book.append(printableOpaque, pageFormatP); + book.append(printableTransparent, pageFormatP); + book.append(printableOpaque, pageFormatL); + book.append(printableTransparent, pageFormatL); + book.append(printableOpaque, pageFormatRL); + book.append(printableTransparent, pageFormatRL); + printerJob.setPageable(book); + + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + aset.add(Sides.ONE_SIDED); + + if (printerJob.printDialog()) { + try { + printerJob.print(aset); + } catch (PrinterException e) { + e.printStackTrace(); + throw new RuntimeException("Exception whilst printing."); + } + } + else { + throw new RuntimeException("Test failed : " + + "User selected 'Cancel' button on the print dialog"); + } + } +} + +class CustomPrintable implements Printable { + private static final int THICKNESS = 10; + private static final int MARGIN = 15; + private static final int SMALL_RECTANGLE_SIZE = 5; + private int alphaValue; + + public CustomPrintable(int alpha) { + alphaValue=alpha; + } + + private static String getOrientStr(int orient) { + switch (orient) { + case PORTRAIT: return "PORTRAIT"; + case LANDSCAPE: return "LANDSCAPE"; + case REVERSE_LANDSCAPE: return "REVERSE_LANDSCAPE"; + default : return "BAD Orientation"; + } + } + + @Override + public int print(Graphics g, PageFormat pageFormat, int pageIndex) { + + if (pageIndex > 5) { + return Printable.NO_SUCH_PAGE; + } + + drawRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), + pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); + + drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), + pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); + + drawMsg(g,300,300, pageFormat.getOrientation()); + return Printable.PAGE_EXISTS; + } + + private void drawRectangle(Graphics g, double x, double y, double width, double height) { + Graphics2D g2d = (Graphics2D) g; + g2d.setStroke(new BasicStroke(THICKNESS)); + + // Draw rectangle with thick border lines + g2d.drawRect((int) x+MARGIN, (int) y+MARGIN, (int) width-MARGIN*2, (int) height-MARGIN*2); + } + + private void drawSmallRectangle(Graphics g, double x, double y, double width, double height) { + Graphics2D g2d = (Graphics2D) g; + Color originalColor = g2d.getColor(); + + g2d.setColor(new Color(0,0,0,alphaValue)); + // Calculate the position to center the smaller rectangle + double centerX = x + (width - SMALL_RECTANGLE_SIZE) / 2; + double centerY = y + (height - SMALL_RECTANGLE_SIZE) / 2; + + g2d.fillRect((int) centerX, (int) centerY, SMALL_RECTANGLE_SIZE, SMALL_RECTANGLE_SIZE); + + g2d.setColor(originalColor); + } + + private void drawMsg(Graphics g, int x, int y, int orient) { + Graphics2D g2d = (Graphics2D) g; + + String msg = "Orient= " + getOrientStr(orient); + msg += " Color=" + (alphaValue != 255 ? " ALPHA" : " OPAQUE"); + g2d.drawString(msg, x, y); + } +} From 57659d33b739b8b184a69a56f20d7bad24292140 Mon Sep 17 00:00:00 2001 From: vtstydev Date: Mon, 29 Jan 2024 08:14:20 +0200 Subject: [PATCH 03/11] Fix header and imports section in AlphaPrintingOffsets --- .../ImagePrinting/AlphaPrintingOffsets.java | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index 127e89ca104c9..df46c07076471 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -21,17 +21,26 @@ * questions. */ -import javax.print.attribute.HashPrintRequestAttributeSet; -import javax.print.attribute.PrintRequestAttributeSet; -import javax.print.attribute.standard.Sides; -import javax.swing.*; -import java.awt.*; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.awt.print.*; +import java.awt.print.Book; +import java.awt.print.PageFormat; +import static java.awt.print.PageFormat.LANDSCAPE; +import static java.awt.print.PageFormat.PORTRAIT; +import static java.awt.print.PageFormat.REVERSE_LANDSCAPE; +import java.awt.print.Paper; +import java.awt.print.Printable; import java.awt.print.PrinterException; +import java.awt.print.PrinterJob; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.Sides; +import javax.swing.JFrame; -import static java.awt.print.PageFormat.*; /* * @test @@ -39,7 +48,7 @@ * @key printer * @library ../../../regtesthelpers * @build PassFailJFrame - * @summary Test for comparing offsets of images drew with opaque and translucent colors printed in all orientations + * @summary Test for comparing offsets of images drawn with opaque and translucent colors printed in all orientations * @run main/manual AlphaPrintingOffsets */ @@ -48,8 +57,8 @@ public class AlphaPrintingOffsets { "This test prints 6 pages with same image except text messages. \n" + "Tested bug occurs only on-paper printing so you mustn't use PDF printer\n" + "1.Java print dialog should appear.\n" + - "2. Press the Print button on the Java Print dialog.\n"+ - "3. Check that 6 pages have the same image except text messages.\n"+ + "2. Press the Print button on the Java Print dialog.\n" + + "3. Check that 6 pages have the same image except text messages.\n" + "If so, press PASS, else press FAIL."; public static void main(String[] args) throws Exception { @@ -58,8 +67,7 @@ public static void main(String[] args) throws Exception { PassFailJFrame.builder().instructions(INSTRUCTIONS) .testUI(() -> createTestUI()).build().awaitAndCheck(); - } - else { + } else { System.out.println("Printer not configured or available." + " Test cannot continue."); PassFailJFrame.forcePass(); @@ -69,7 +77,7 @@ public static void main(String[] args) throws Exception { public static JFrame createTestUI() { JFrame testUI = new JFrame("Print images"); - testUI.setSize(1,1); + testUI.setSize(1, 1); testUI.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { @@ -92,7 +100,7 @@ private static void print() { PageFormat pageFormatP = printerJob.defaultPage(); Paper paper = pageFormatP.getPaper(); - paper.setImageableArea(0,0,paper.getWidth(),paper.getHeight()); + paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); pageFormatP.setPaper(paper); PageFormat pageFormatL = (PageFormat) pageFormatP.clone(); @@ -123,8 +131,7 @@ private static void print() { e.printStackTrace(); throw new RuntimeException("Exception whilst printing."); } - } - else { + } else { throw new RuntimeException("Test failed : " + "User selected 'Cancel' button on the print dialog"); } @@ -138,15 +145,19 @@ class CustomPrintable implements Printable { private int alphaValue; public CustomPrintable(int alpha) { - alphaValue=alpha; + alphaValue = alpha; } private static String getOrientStr(int orient) { switch (orient) { - case PORTRAIT: return "PORTRAIT"; - case LANDSCAPE: return "LANDSCAPE"; - case REVERSE_LANDSCAPE: return "REVERSE_LANDSCAPE"; - default : return "BAD Orientation"; + case PORTRAIT: + return "PORTRAIT"; + case LANDSCAPE: + return "LANDSCAPE"; + case REVERSE_LANDSCAPE: + return "REVERSE_LANDSCAPE"; + default: + return "BAD Orientation"; } } @@ -163,7 +174,7 @@ public int print(Graphics g, PageFormat pageFormat, int pageIndex) { drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); - drawMsg(g,300,300, pageFormat.getOrientation()); + drawMsg(g, 300, 300, pageFormat.getOrientation()); return Printable.PAGE_EXISTS; } @@ -172,14 +183,14 @@ private void drawRectangle(Graphics g, double x, double y, double width, double g2d.setStroke(new BasicStroke(THICKNESS)); // Draw rectangle with thick border lines - g2d.drawRect((int) x+MARGIN, (int) y+MARGIN, (int) width-MARGIN*2, (int) height-MARGIN*2); + g2d.drawRect((int) x + MARGIN, (int) y + MARGIN, (int) width - MARGIN * 2, (int) height - MARGIN * 2); } private void drawSmallRectangle(Graphics g, double x, double y, double width, double height) { Graphics2D g2d = (Graphics2D) g; Color originalColor = g2d.getColor(); - g2d.setColor(new Color(0,0,0,alphaValue)); + g2d.setColor(new Color(0, 0, 0, alphaValue)); // Calculate the position to center the smaller rectangle double centerX = x + (width - SMALL_RECTANGLE_SIZE) / 2; double centerY = y + (height - SMALL_RECTANGLE_SIZE) / 2; From feb68758d15383619376f5684c3666991b09c1e0 Mon Sep 17 00:00:00 2001 From: vtstydev Date: Thu, 1 Feb 2024 08:34:18 +0200 Subject: [PATCH 04/11] Done requested fixes --- .../classes/sun/print/RasterPrinterJob.java | 4 +- .../ImagePrinting/AlphaPrintingOffsets.java | 58 +++++++++++++------ 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java index d19d28dcbc22a..1c9e4bd0c134c 100644 --- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java @@ -2153,7 +2153,7 @@ protected int printPage(Pageable document, int pageIndex) * because we do not want it adjusted by the page orientation. */ Paper paper = page.getPaper(); - // if non-portrait and 270 degree landscape rotation + // if non-portraitgit status and 270 degree landscape rotation if (page.getOrientation() != PageFormat.PORTRAIT && landscapeRotates270) { @@ -2396,7 +2396,7 @@ protected int printPage(Pageable document, int pageIndex) * the page on the next iteration of the loop. */ bandGraphics.setTransform(uniformTransform); - bandGraphics.translate(-deviceAddressableX,deviceAddressableY); + bandGraphics.translate(-deviceAddressableX, deviceAddressableY); bandGraphics.transform(deviceTransform); deviceTransform.translate(0, -bandHeight); diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index df46c07076471..8f64d574f977a 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -40,37 +40,52 @@ import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.Sides; import javax.swing.JFrame; - +import jtreg.SkippedException; /* * @test * @bug 8307246 * @key printer * @library ../../../regtesthelpers + * @library /test/lib * @build PassFailJFrame + * @build jtreg.SkippedException * @summary Test for comparing offsets of images drawn with opaque and translucent colors printed in all orientations - * @run main/manual AlphaPrintingOffsets + * @run main/manual AlphaPrintingOffsets testAlpha */ public class AlphaPrintingOffsets { private static final String INSTRUCTIONS = - "This test prints 6 pages with same image except text messages. \n" + "Tested bug occurs only on-paper printing so you mustn't use PDF printer\n" + "1.Java print dialog should appear.\n" + "2. Press the Print button on the Java Print dialog.\n" + - "3. Check that 6 pages have the same image except text messages.\n" + + "3. Please check the page margin rectangle are properly drawn and visible on all sides on all pages.\n" + "If so, press PASS, else press FAIL."; + private static boolean isAlphaTestModeSet = false; + + public static boolean getAlphaTestModeSet() { + return isAlphaTestModeSet; + } + public static void main(String[] args) throws Exception { if (PrinterJob.lookupPrintServices().length > 0) { - PassFailJFrame.builder().instructions(INSTRUCTIONS) + String instructionsHeader = "This test prints 6 pages with same image except text messages. \n"; + if (args.length > 0) + isAlphaTestModeSet = args[0].equals("testAlpha"); + + if(isAlphaTestModeSet) + instructionsHeader = "This test prints 2 pages with same image except text messages. \n"; + + PassFailJFrame.builder().instructions(instructionsHeader + INSTRUCTIONS) .testUI(() -> createTestUI()).build().awaitAndCheck(); } else { System.out.println("Printer not configured or available." + " Test cannot continue."); - PassFailJFrame.forcePass(); + throw new SkippedException("Printer not configured or available." + + " Test cannot continue."); } } @@ -112,15 +127,23 @@ private static void print() { Printable printableOpaque = new CustomPrintable(255); Printable printableTransparent = new CustomPrintable(254); - Book book = new Book(); - book.append(printableOpaque, pageFormatP); - book.append(printableTransparent, pageFormatP); - book.append(printableOpaque, pageFormatL); - book.append(printableTransparent, pageFormatL); - book.append(printableOpaque, pageFormatRL); - book.append(printableTransparent, pageFormatRL); - printerJob.setPageable(book); - + Book bookNoAlphaTest = new Book(); + bookNoAlphaTest.append(printableOpaque, pageFormatP); + bookNoAlphaTest.append(printableTransparent, pageFormatP); + bookNoAlphaTest.append(printableOpaque, pageFormatL); + bookNoAlphaTest.append(printableTransparent, pageFormatL); + bookNoAlphaTest.append(printableOpaque, pageFormatRL); + bookNoAlphaTest.append(printableTransparent, pageFormatRL); + + Book bookAlphaTest = new Book(); + bookAlphaTest.append(printableTransparent, pageFormatL); + bookAlphaTest.append(printableTransparent, pageFormatRL); + + if(isAlphaTestModeSet) + printerJob.setPageable(bookAlphaTest); + else + printerJob.setPageable(bookNoAlphaTest); + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Sides.ONE_SIDED); @@ -171,8 +194,9 @@ public int print(Graphics g, PageFormat pageFormat, int pageIndex) { drawRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); - drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), - pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); + if(AlphaPrintingOffsets.getAlphaTestModeSet()) + drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), + pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); drawMsg(g, 300, 300, pageFormat.getOrientation()); return Printable.PAGE_EXISTS; From 2d9e3d3bb45227cb6bdf759b3bd07f814217724c Mon Sep 17 00:00:00 2001 From: vtstydev Date: Thu, 1 Feb 2024 08:43:58 +0200 Subject: [PATCH 05/11] Remove trailing workspaces --- src/java.desktop/share/classes/sun/print/RasterPrinterJob.java | 2 +- .../print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java index 1c9e4bd0c134c..bc56026d9bcbf 100644 --- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java @@ -2153,7 +2153,7 @@ protected int printPage(Pageable document, int pageIndex) * because we do not want it adjusted by the page orientation. */ Paper paper = page.getPaper(); - // if non-portraitgit status and 270 degree landscape rotation + // if non-portrait status and 270 degree landscape rotation if (page.getOrientation() != PageFormat.PORTRAIT && landscapeRotates270) { diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index 8f64d574f977a..002ad0f8b94b9 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -74,10 +74,8 @@ public static void main(String[] args) throws Exception { String instructionsHeader = "This test prints 6 pages with same image except text messages. \n"; if (args.length > 0) isAlphaTestModeSet = args[0].equals("testAlpha"); - if(isAlphaTestModeSet) instructionsHeader = "This test prints 2 pages with same image except text messages. \n"; - PassFailJFrame.builder().instructions(instructionsHeader + INSTRUCTIONS) .testUI(() -> createTestUI()).build().awaitAndCheck(); @@ -143,7 +141,6 @@ private static void print() { printerJob.setPageable(bookAlphaTest); else printerJob.setPageable(bookNoAlphaTest); - PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Sides.ONE_SIDED); From 368811b12a2e23b3ab7c055be95fa30feff2bd9b Mon Sep 17 00:00:00 2001 From: vtstydev Date: Thu, 1 Feb 2024 11:44:52 +0200 Subject: [PATCH 06/11] Done requested fixes 2 --- .../classes/sun/print/RasterPrinterJob.java | 4 +- .../ImagePrinting/AlphaPrintingOffsets.java | 51 ++++++++++--------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java index bc56026d9bcbf..6b75a42f670e1 100644 --- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java @@ -2153,7 +2153,7 @@ protected int printPage(Pageable document, int pageIndex) * because we do not want it adjusted by the page orientation. */ Paper paper = page.getPaper(); - // if non-portrait status and 270 degree landscape rotation + // if non-portrait and 270 degree landscape rotation if (page.getOrientation() != PageFormat.PORTRAIT && landscapeRotates270) { @@ -2435,7 +2435,7 @@ protected int printPage(Pageable document, int pageIndex) painterGraphics.setDelegate((Graphics2D) bandGraphics.create()); painter.print(painterGraphics, origPage, pageIndex); painterGraphics.dispose(); - printBand(data, bandX, bandTop+bandY, bandWidth, bandHeight); + printBand(data, bandX, bandTop + bandY, bandWidth, bandHeight); } } diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index 002ad0f8b94b9..48c5d92a93b73 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -51,7 +51,7 @@ * @build PassFailJFrame * @build jtreg.SkippedException * @summary Test for comparing offsets of images drawn with opaque and translucent colors printed in all orientations - * @run main/manual AlphaPrintingOffsets testAlpha + * @run main/manual AlphaPrintingOffsets */ public class AlphaPrintingOffsets { @@ -62,7 +62,7 @@ public class AlphaPrintingOffsets { "3. Please check the page margin rectangle are properly drawn and visible on all sides on all pages.\n" + "If so, press PASS, else press FAIL."; - private static boolean isAlphaTestModeSet = false; + private static boolean isAlphaTestModeSet = true; public static boolean getAlphaTestModeSet() { return isAlphaTestModeSet; @@ -71,11 +71,13 @@ public static boolean getAlphaTestModeSet() { public static void main(String[] args) throws Exception { if (PrinterJob.lookupPrintServices().length > 0) { - String instructionsHeader = "This test prints 6 pages with same image except text messages. \n"; - if (args.length > 0) - isAlphaTestModeSet = args[0].equals("testAlpha"); - if(isAlphaTestModeSet) - instructionsHeader = "This test prints 2 pages with same image except text messages. \n"; + String instructionsHeader = "This test prints 6 pages with page margin rectangle and a text message. \n"; + if (args.length > 0) { + isAlphaTestModeSet = !args[0].equals("testOpaque"); + } + if (isAlphaTestModeSet) { + instructionsHeader = "This test prints 2 pages with page margin rectangle and a text message. \n"; + } PassFailJFrame.builder().instructions(instructionsHeader + INSTRUCTIONS) .testUI(() -> createTestUI()).build().awaitAndCheck(); @@ -122,25 +124,25 @@ private static void print() { pageFormatL.setOrientation(LANDSCAPE); pageFormatRL.setOrientation(REVERSE_LANDSCAPE); - Printable printableOpaque = new CustomPrintable(255); Printable printableTransparent = new CustomPrintable(254); - - Book bookNoAlphaTest = new Book(); - bookNoAlphaTest.append(printableOpaque, pageFormatP); - bookNoAlphaTest.append(printableTransparent, pageFormatP); - bookNoAlphaTest.append(printableOpaque, pageFormatL); - bookNoAlphaTest.append(printableTransparent, pageFormatL); - bookNoAlphaTest.append(printableOpaque, pageFormatRL); - bookNoAlphaTest.append(printableTransparent, pageFormatRL); - - Book bookAlphaTest = new Book(); - bookAlphaTest.append(printableTransparent, pageFormatL); - bookAlphaTest.append(printableTransparent, pageFormatRL); - - if(isAlphaTestModeSet) + + if (isAlphaTestModeSet) { + Book bookAlphaTest = new Book(); + bookAlphaTest.append(printableTransparent, pageFormatL); + bookAlphaTest.append(printableTransparent, pageFormatRL); printerJob.setPageable(bookAlphaTest); - else + } + else { + Printable printableOpaque = new CustomPrintable(255); + Book bookNoAlphaTest = new Book(); + bookNoAlphaTest.append(printableOpaque, pageFormatP); + bookNoAlphaTest.append(printableTransparent, pageFormatP); + bookNoAlphaTest.append(printableOpaque, pageFormatL); + bookNoAlphaTest.append(printableTransparent, pageFormatL); + bookNoAlphaTest.append(printableOpaque, pageFormatRL); + bookNoAlphaTest.append(printableTransparent, pageFormatRL); printerJob.setPageable(bookNoAlphaTest); + } PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Sides.ONE_SIDED); @@ -191,9 +193,10 @@ public int print(Graphics g, PageFormat pageFormat, int pageIndex) { drawRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); - if(AlphaPrintingOffsets.getAlphaTestModeSet()) + if (AlphaPrintingOffsets.getAlphaTestModeSet()) { drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); + } drawMsg(g, 300, 300, pageFormat.getOrientation()); return Printable.PAGE_EXISTS; From 40bf6ff3655c8f61f9d280312651f9c67636ea5a Mon Sep 17 00:00:00 2001 From: vtstydev Date: Thu, 1 Feb 2024 13:28:55 +0200 Subject: [PATCH 07/11] Remove trailing whitespace --- .../awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index 48c5d92a93b73..3b9b35b7c226d 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -125,7 +125,6 @@ private static void print() { pageFormatRL.setOrientation(REVERSE_LANDSCAPE); Printable printableTransparent = new CustomPrintable(254); - if (isAlphaTestModeSet) { Book bookAlphaTest = new Book(); bookAlphaTest.append(printableTransparent, pageFormatL); From 514b03f32fcd575b43e88b3dd88a63d80c3ac726 Mon Sep 17 00:00:00 2001 From: vtstydev Date: Fri, 9 Feb 2024 11:31:57 +0200 Subject: [PATCH 08/11] Done requested fixes 3 --- .../ImagePrinting/AlphaPrintingOffsets.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index 3b9b35b7c226d..507708683cdaa 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -56,29 +56,27 @@ public class AlphaPrintingOffsets { private static final String INSTRUCTIONS = - "Tested bug occurs only on-paper printing so you mustn't use PDF printer\n" + + "Tested bug occurs only on-paper printing so you mustn't use PDF printer\n\n" + "1.Java print dialog should appear.\n" + "2. Press the Print button on the Java Print dialog.\n" + "3. Please check the page margin rectangle are properly drawn and visible on all sides on all pages.\n" + - "If so, press PASS, else press FAIL."; + "If so, press PASS, else press FAIL.\n\n" + + "Also you may run this test in paper-saving mode. Due to tested bug affects pages printed with transparency in LANDSCAPE and REVERSE_LANDSCAPE orientations " + + "there is an option to print only 2 pages affected. To do it pass PaperSavingMode parameter."; - private static boolean isAlphaTestModeSet = true; - - public static boolean getAlphaTestModeSet() { - return isAlphaTestModeSet; - } + private static boolean isPaperSavingMode = false; public static void main(String[] args) throws Exception { if (PrinterJob.lookupPrintServices().length > 0) { String instructionsHeader = "This test prints 6 pages with page margin rectangle and a text message. \n"; if (args.length > 0) { - isAlphaTestModeSet = !args[0].equals("testOpaque"); + isPaperSavingMode = args[0].equals("PaperSavingMode"); } - if (isAlphaTestModeSet) { + if (isPaperSavingMode) { instructionsHeader = "This test prints 2 pages with page margin rectangle and a text message. \n"; } - PassFailJFrame.builder().instructions(instructionsHeader + INSTRUCTIONS) + PassFailJFrame.builder().rows(15).instructions(instructionsHeader + INSTRUCTIONS) .testUI(() -> createTestUI()).build().awaitAndCheck(); } else { @@ -125,22 +123,22 @@ private static void print() { pageFormatRL.setOrientation(REVERSE_LANDSCAPE); Printable printableTransparent = new CustomPrintable(254); - if (isAlphaTestModeSet) { - Book bookAlphaTest = new Book(); - bookAlphaTest.append(printableTransparent, pageFormatL); - bookAlphaTest.append(printableTransparent, pageFormatRL); - printerJob.setPageable(bookAlphaTest); + if (isPaperSavingMode) { + Book bookPageSavingTest = new Book(); + bookPageSavingTest.append(printableTransparent, pageFormatL); + bookPageSavingTest.append(printableTransparent, pageFormatRL); + printerJob.setPageable(bookPageSavingTest); } else { Printable printableOpaque = new CustomPrintable(255); - Book bookNoAlphaTest = new Book(); - bookNoAlphaTest.append(printableOpaque, pageFormatP); - bookNoAlphaTest.append(printableTransparent, pageFormatP); - bookNoAlphaTest.append(printableOpaque, pageFormatL); - bookNoAlphaTest.append(printableTransparent, pageFormatL); - bookNoAlphaTest.append(printableOpaque, pageFormatRL); - bookNoAlphaTest.append(printableTransparent, pageFormatRL); - printerJob.setPageable(bookNoAlphaTest); + Book bookDefaultTest = new Book(); + bookDefaultTest.append(printableOpaque, pageFormatP); + bookDefaultTest.append(printableTransparent, pageFormatP); + bookDefaultTest.append(printableOpaque, pageFormatL); + bookDefaultTest.append(printableTransparent, pageFormatL); + bookDefaultTest.append(printableOpaque, pageFormatRL); + bookDefaultTest.append(printableTransparent, pageFormatRL); + printerJob.setPageable(bookDefaultTest); } PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Sides.ONE_SIDED); @@ -192,10 +190,8 @@ public int print(Graphics g, PageFormat pageFormat, int pageIndex) { drawRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); - if (AlphaPrintingOffsets.getAlphaTestModeSet()) { - drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), - pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); - } + drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), + pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); drawMsg(g, 300, 300, pageFormat.getOrientation()); return Printable.PAGE_EXISTS; From 47b2222c4485c9a864cf0768b1ef90994a7a0064 Mon Sep 17 00:00:00 2001 From: vtstydev Date: Mon, 12 Feb 2024 14:28:56 +0200 Subject: [PATCH 09/11] Done requested fixes 4 --- .../PrinterJob/ImagePrinting/AlphaPrintingOffsets.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index 507708683cdaa..c3ca2256b0355 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -40,16 +40,13 @@ import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.Sides; import javax.swing.JFrame; -import jtreg.SkippedException; /* * @test * @bug 8307246 * @key printer * @library ../../../regtesthelpers - * @library /test/lib * @build PassFailJFrame - * @build jtreg.SkippedException * @summary Test for comparing offsets of images drawn with opaque and translucent colors printed in all orientations * @run main/manual AlphaPrintingOffsets */ @@ -80,10 +77,8 @@ public static void main(String[] args) throws Exception { .testUI(() -> createTestUI()).build().awaitAndCheck(); } else { - System.out.println("Printer not configured or available." - + " Test cannot continue."); - throw new SkippedException("Printer not configured or available." - + " Test cannot continue."); + System.out.println("Test failed : Printer not configured or available."); + throw new RuntimeException("Test failed : Printer not configured or available."); } } From 018b2289f316e44b66b76e39bbb2612f6b1c88e6 Mon Sep 17 00:00:00 2001 From: vtstydev Date: Tue, 13 Feb 2024 14:00:13 +0200 Subject: [PATCH 10/11] Done requested fixes 5 --- .../classes/sun/print/RasterPrinterJob.java | 2 +- .../ImagePrinting/AlphaPrintingOffsets.java | 153 ++++++++++-------- 2 files changed, 84 insertions(+), 71 deletions(-) diff --git a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java index 6b75a42f670e1..9ec48d6923b9b 100644 --- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2023, 2024, 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 diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index c3ca2256b0355..e9ca2f0ae2c91 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -29,9 +29,6 @@ import java.awt.event.WindowEvent; import java.awt.print.Book; import java.awt.print.PageFormat; -import static java.awt.print.PageFormat.LANDSCAPE; -import static java.awt.print.PageFormat.PORTRAIT; -import static java.awt.print.PageFormat.REVERSE_LANDSCAPE; import java.awt.print.Paper; import java.awt.print.Printable; import java.awt.print.PrinterException; @@ -41,44 +38,58 @@ import javax.print.attribute.standard.Sides; import javax.swing.JFrame; +import static java.awt.print.PageFormat.LANDSCAPE; +import static java.awt.print.PageFormat.PORTRAIT; +import static java.awt.print.PageFormat.REVERSE_LANDSCAPE; + /* * @test * @bug 8307246 * @key printer * @library ../../../regtesthelpers * @build PassFailJFrame - * @summary Test for comparing offsets of images drawn with opaque and translucent colors printed in all orientations + * @summary Test for comparing offsets of images drawn with opaque + * and translucent colors printed in all orientations * @run main/manual AlphaPrintingOffsets */ public class AlphaPrintingOffsets { private static final String INSTRUCTIONS = - "Tested bug occurs only on-paper printing so you mustn't use PDF printer\n\n" + - "1.Java print dialog should appear.\n" + + "Tested bug occurs only on-paper printing " + + "so you mustn't use PDF printer\n\n" + + "1. Java print dialog should appear.\n" + "2. Press the Print button on the Java Print dialog.\n" + - "3. Please check the page margin rectangle are properly drawn and visible on all sides on all pages.\n" + + "3. Please check the page margin rectangle are properly " + + "drawn and visible on all sides on all pages.\n" + "If so, press PASS, else press FAIL.\n\n" + - "Also you may run this test in paper-saving mode. Due to tested bug affects pages printed with transparency in LANDSCAPE and REVERSE_LANDSCAPE orientations " + - "there is an option to print only 2 pages affected. To do it pass PaperSavingMode parameter."; + "Also you may run this test in paper-saving mode. Due " + + "to tested bug affects pages printed with transparency " + + "in LANDSCAPE and REVERSE_LANDSCAPE orientations there " + + "is an option to print only 2 pages affected. " + + "To do it pass PaperSavingMode parameter."; private static boolean isPaperSavingMode = false; public static void main(String[] args) throws Exception { if (PrinterJob.lookupPrintServices().length > 0) { - String instructionsHeader = "This test prints 6 pages with page margin rectangle and a text message. \n"; + String instructionsHeader = "This test prints 6 pages with page " + + "margin rectangle and a text message. \n"; if (args.length > 0) { isPaperSavingMode = args[0].equals("PaperSavingMode"); } if (isPaperSavingMode) { - instructionsHeader = "This test prints 2 pages with page margin rectangle and a text message. \n"; + instructionsHeader = "This test prints 2 pages with page " + + "margin rectangle and a text message. \n"; } - PassFailJFrame.builder().rows(15).instructions(instructionsHeader + INSTRUCTIONS) - .testUI(() -> createTestUI()).build().awaitAndCheck(); + PassFailJFrame.builder().instructions(instructionsHeader + INSTRUCTIONS) + .rows(15).testUI(() -> createTestUI()).build().awaitAndCheck(); } else { - System.out.println("Test failed : Printer not configured or available."); - throw new RuntimeException("Test failed : Printer not configured or available."); + System.out.println("Test failed : " + + "Printer not configured or available."); + throw new RuntimeException("Test failed : " + + "Printer not configured or available."); } } @@ -146,79 +157,81 @@ private static void print() { throw new RuntimeException("Exception whilst printing."); } } else { - throw new RuntimeException("Test failed : " - + "User selected 'Cancel' button on the print dialog"); + throw new RuntimeException("Test failed : " + + "User selected 'Cancel' button on the print dialog"); } } -} -class CustomPrintable implements Printable { - private static final int THICKNESS = 10; - private static final int MARGIN = 15; - private static final int SMALL_RECTANGLE_SIZE = 5; - private int alphaValue; + static class CustomPrintable implements Printable { + private static final int THICKNESS = 10; + private static final int MARGIN = 15; + private static final int SMALL_RECTANGLE_SIZE = 5; + private final int alphaValue; - public CustomPrintable(int alpha) { - alphaValue = alpha; - } + public CustomPrintable(int alpha) { + alphaValue = alpha; + } - private static String getOrientStr(int orient) { - switch (orient) { - case PORTRAIT: - return "PORTRAIT"; - case LANDSCAPE: - return "LANDSCAPE"; - case REVERSE_LANDSCAPE: - return "REVERSE_LANDSCAPE"; - default: - return "BAD Orientation"; + private String getOrientStr(int orient) { + switch (orient) { + case PORTRAIT: + return "PORTRAIT"; + case LANDSCAPE: + return "LANDSCAPE"; + case REVERSE_LANDSCAPE: + return "REVERSE_LANDSCAPE"; + default: + return "BAD Orientation"; + } } - } - @Override - public int print(Graphics g, PageFormat pageFormat, int pageIndex) { + @Override + public int print(Graphics g, PageFormat pageFormat, int pageIndex) { - if (pageIndex > 5) { - return Printable.NO_SUCH_PAGE; - } + if (pageIndex > 5) { + return Printable.NO_SUCH_PAGE; + } - drawRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), - pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); + drawRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), + pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); - drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), - pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); + drawSmallRectangle(g, pageFormat.getImageableX(), pageFormat.getImageableY(), + pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); - drawMsg(g, 300, 300, pageFormat.getOrientation()); - return Printable.PAGE_EXISTS; - } + drawMsg(g, 300, 300, pageFormat.getOrientation()); + return Printable.PAGE_EXISTS; + } - private void drawRectangle(Graphics g, double x, double y, double width, double height) { - Graphics2D g2d = (Graphics2D) g; - g2d.setStroke(new BasicStroke(THICKNESS)); + private void drawRectangle(Graphics g, double x, double y, double width, double height) { + Graphics2D g2d = (Graphics2D) g; + g2d.setStroke(new BasicStroke(THICKNESS)); - // Draw rectangle with thick border lines - g2d.drawRect((int) x + MARGIN, (int) y + MARGIN, (int) width - MARGIN * 2, (int) height - MARGIN * 2); - } + // Draw rectangle with thick border lines + g2d.drawRect((int) x + MARGIN, (int) y + MARGIN, + (int) width - MARGIN * 2, (int) height - MARGIN * 2); + } - private void drawSmallRectangle(Graphics g, double x, double y, double width, double height) { - Graphics2D g2d = (Graphics2D) g; - Color originalColor = g2d.getColor(); + private void drawSmallRectangle(Graphics g, double x, double y, double width, double height) { + Graphics2D g2d = (Graphics2D) g; + Color originalColor = g2d.getColor(); - g2d.setColor(new Color(0, 0, 0, alphaValue)); - // Calculate the position to center the smaller rectangle - double centerX = x + (width - SMALL_RECTANGLE_SIZE) / 2; - double centerY = y + (height - SMALL_RECTANGLE_SIZE) / 2; + g2d.setColor(new Color(0, 0, 0, alphaValue)); + // Calculate the position to center the smaller rectangle + double centerX = x + (width - SMALL_RECTANGLE_SIZE) / 2; + double centerY = y + (height - SMALL_RECTANGLE_SIZE) / 2; - g2d.fillRect((int) centerX, (int) centerY, SMALL_RECTANGLE_SIZE, SMALL_RECTANGLE_SIZE); + g2d.fillRect((int) centerX, (int) centerY, SMALL_RECTANGLE_SIZE, SMALL_RECTANGLE_SIZE); - g2d.setColor(originalColor); - } + g2d.setColor(originalColor); + } - private void drawMsg(Graphics g, int x, int y, int orient) { - Graphics2D g2d = (Graphics2D) g; + private void drawMsg(Graphics g, int x, int y, int orient) { + Graphics2D g2d = (Graphics2D) g; - String msg = "Orient= " + getOrientStr(orient); - msg += " Color=" + (alphaValue != 255 ? " ALPHA" : " OPAQUE"); - g2d.drawString(msg, x, y); + String msg = "Orient= " + getOrientStr(orient); + msg += " Color=" + (alphaValue != 255 ? " ALPHA" : " OPAQUE"); + g2d.drawString(msg, x, y); + } } } + From e124a2ddbac6807e25f941438c2935a2f9c10946 Mon Sep 17 00:00:00 2001 From: vtstydev Date: Wed, 14 Feb 2024 11:26:03 +0200 Subject: [PATCH 11/11] Done requested fixes 6 --- .../classes/sun/print/RasterPrinterJob.java | 2 +- .../ImagePrinting/AlphaPrintingOffsets.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java index 9ec48d6923b9b..fc47c25806c65 100644 --- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 diff --git a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java index e9ca2f0ae2c91..4cb5c49701e2c 100644 --- a/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java +++ b/test/jdk/java/awt/print/PrinterJob/ImagePrinting/AlphaPrintingOffsets.java @@ -55,7 +55,7 @@ public class AlphaPrintingOffsets { private static final String INSTRUCTIONS = - "Tested bug occurs only on-paper printing " + + "Tested bug occurs only on-paper printing " + "so you mustn't use PDF printer\n\n" + "1. Java print dialog should appear.\n" + "2. Press the Print button on the Java Print dialog.\n" + @@ -82,14 +82,15 @@ public static void main(String[] args) throws Exception { instructionsHeader = "This test prints 2 pages with page " + "margin rectangle and a text message. \n"; } - PassFailJFrame.builder().instructions(instructionsHeader + INSTRUCTIONS) - .rows(15).testUI(() -> createTestUI()).build().awaitAndCheck(); + PassFailJFrame.builder() + .instructions(instructionsHeader + INSTRUCTIONS) + .rows(15) + .testUI(() -> createTestUI()) + .build() + .awaitAndCheck(); } else { - System.out.println("Test failed : " + - "Printer not configured or available."); - throw new RuntimeException("Test failed : " + - "Printer not configured or available."); + throw new RuntimeException("Test failed : Printer not configured or available."); } } @@ -134,8 +135,7 @@ private static void print() { bookPageSavingTest.append(printableTransparent, pageFormatL); bookPageSavingTest.append(printableTransparent, pageFormatRL); printerJob.setPageable(bookPageSavingTest); - } - else { + } else { Printable printableOpaque = new CustomPrintable(255); Book bookDefaultTest = new Book(); bookDefaultTest.append(printableOpaque, pageFormatP);