diff --git a/make/sun/awt/FILES_c_unix.gmk b/make/sun/awt/FILES_c_unix.gmk index f85635f00fb2df2fb851c43ff5322201337386f6..3b4ad3f1c6b7401c36eaa7e06626f704ea4cba0b 100644 --- a/make/sun/awt/FILES_c_unix.gmk +++ b/make/sun/awt/FILES_c_unix.gmk @@ -125,7 +125,6 @@ FILES_2D_c = \ FourByteAbgrPre.c \ BufferedMaskBlit.c \ BufferedRenderPipe.c \ - RenderBuffer.c \ ShapeSpanIterator.c \ SpanClipRenderer.c \ awt_ImageRep.c \ diff --git a/make/sun/awt/FILES_c_windows.gmk b/make/sun/awt/FILES_c_windows.gmk index ccf21af9c7967dbaf625ceb0aef238f8f82f7ac8..c9eb3482ea676019432749c5f5bc1b150ecb216b 100644 --- a/make/sun/awt/FILES_c_windows.gmk +++ b/make/sun/awt/FILES_c_windows.gmk @@ -70,7 +70,6 @@ FILES_c = \ FourByteAbgrPre.c \ BufferedMaskBlit.c \ BufferedRenderPipe.c \ - RenderBuffer.c \ ShapeSpanIterator.c \ SpanClipRenderer.c \ SurfaceData.c \ diff --git a/make/sun/awt/mapfile-vers b/make/sun/awt/mapfile-vers index 9ab965e07fa0e87c3a7e3d61b1a6280f8a8a980b..06a1d5b974d58d43f2e32f23ae131d1cb3f17b1d 100644 --- a/make/sun/awt/mapfile-vers +++ b/make/sun/awt/mapfile-vers @@ -65,7 +65,6 @@ SUNWprivate_1.1 { Java_sun_awt_image_ShortComponentRaster_initIDs; Java_sun_java2d_pipe_BufferedMaskBlit_enqueueTile; Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans; - Java_sun_java2d_pipe_RenderBuffer_copyFromArray; Java_sun_java2d_pipe_SpanClipRenderer_eraseTile; Java_sun_java2d_pipe_SpanClipRenderer_fillTile; Java_sun_java2d_pipe_ShapeSpanIterator_addSegment; diff --git a/make/sun/awt/mapfile-vers-linux b/make/sun/awt/mapfile-vers-linux index a1e88de623cbbb765b76e41712d2f2e19e384c29..c1f9d133adfa8a95e1e1febba7bd48eb8e05e04e 100644 --- a/make/sun/awt/mapfile-vers-linux +++ b/make/sun/awt/mapfile-vers-linux @@ -117,7 +117,6 @@ SUNWprivate_1.1 { Java_sun_java2d_loops_MaskBlit_MaskBlit; Java_sun_java2d_loops_MaskFill_MaskFill; Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans; - Java_sun_java2d_pipe_RenderBuffer_copyFromArray; Java_sun_java2d_pipe_SpanClipRenderer_initIDs; sun_awt_image_GifImageDecoder_initIDs; diff --git a/src/share/classes/sun/font/TrueTypeFont.java b/src/share/classes/sun/font/TrueTypeFont.java index 13f0f6967b62249b9074f2d72d40008830f33744..7a87e81a0e2353658e676bfeb315a60e19573c80 100644 --- a/src/share/classes/sun/font/TrueTypeFont.java +++ b/src/share/classes/sun/font/TrueTypeFont.java @@ -552,17 +552,6 @@ public class TrueTypeFont extends FileFont { ByteBuffer os2_Table = getTableBuffer(os_2Tag); setStyle(os2_Table); setCJKSupport(os2_Table); - - ByteBuffer head_Table = getTableBuffer(headTag); - int upem = -1; - if (head_Table != null && head_Table.capacity() >= 18) { - ShortBuffer sb = head_Table.asShortBuffer(); - upem = sb.get(9) & 0xffff; - } - setStrikethroughMetrics(os2_Table, upem); - - ByteBuffer post_Table = getTableBuffer(postTag); - setUnderlineMetrics(post_Table, upem); } /* The array index corresponds to a bit offset in the TrueType @@ -1020,8 +1009,26 @@ public class TrueTypeFont extends FileFont { } public void getStyleMetrics(float pointSize, float[] metrics, int offset) { + + if (ulSize == 0f && ulPos == 0f) { + + ByteBuffer head_Table = getTableBuffer(headTag); + int upem = -1; + if (head_Table != null && head_Table.capacity() >= 18) { + ShortBuffer sb = head_Table.asShortBuffer(); + upem = sb.get(9) & 0xffff; + } + + ByteBuffer os2_Table = getTableBuffer(os_2Tag); + setStrikethroughMetrics(os2_Table, upem); + + ByteBuffer post_Table = getTableBuffer(postTag); + setUnderlineMetrics(post_Table, upem); + } + metrics[offset] = stPos * pointSize; metrics[offset+1] = stSize * pointSize; + metrics[offset+2] = ulPos * pointSize; metrics[offset+3] = ulSize * pointSize; } diff --git a/src/share/classes/sun/java2d/pipe/RenderBuffer.java b/src/share/classes/sun/java2d/pipe/RenderBuffer.java index 62026e490271cda78a81caf3bc83f7499ece0089..f0b8069a51217b7faadd6594a4078588ce007148 100644 --- a/src/share/classes/sun/java2d/pipe/RenderBuffer.java +++ b/src/share/classes/sun/java2d/pipe/RenderBuffer.java @@ -63,7 +63,7 @@ public class RenderBuffer { * (This value can be adjusted if the cost of JNI downcalls is reduced * in a future release.) */ - private static final int COPY_FROM_ARRAY_THRESHOLD = 28; + private static final int COPY_FROM_ARRAY_THRESHOLD = 6; protected final Unsafe unsafe; protected final long baseAddress; @@ -92,20 +92,6 @@ public class RenderBuffer { return baseAddress; } - /** - * Copies length bytes from the Java-level srcArray to the native - * memory located at dstAddr. Note that this method performs no bounds - * checking. Verification that the copy will not result in memory - * corruption should be done by the caller prior to invocation. - * - * @param srcArray the source array - * @param srcPos the starting position of the source array (in bytes) - * @param dstAddr pointer to the destination block of native memory - * @param length the number of bytes to copy from source to destination - */ - private static native void copyFromArray(Object srcArray, long srcPos, - long dstAddr, long length); - /** * The behavior (and names) of the following methods are nearly * identical to their counterparts in the various NIO Buffer classes. @@ -147,9 +133,9 @@ public class RenderBuffer { public RenderBuffer put(byte[] x, int offset, int length) { if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_BYTE; + long offsetInBytes = offset * SIZEOF_BYTE + Unsafe.ARRAY_BYTE_BASE_OFFSET; long lengthInBytes = length * SIZEOF_BYTE; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; @@ -178,9 +164,9 @@ public class RenderBuffer { public RenderBuffer put(short[] x, int offset, int length) { // assert (position() % SIZEOF_SHORT == 0); if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_SHORT; + long offsetInBytes = offset * SIZEOF_SHORT + Unsafe.ARRAY_SHORT_BASE_OFFSET; long lengthInBytes = length * SIZEOF_SHORT; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; @@ -215,9 +201,9 @@ public class RenderBuffer { public RenderBuffer put(int[] x, int offset, int length) { // assert (position() % SIZEOF_INT == 0); if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_INT; + long offsetInBytes = offset * SIZEOF_INT + Unsafe.ARRAY_INT_BASE_OFFSET; long lengthInBytes = length * SIZEOF_INT; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; @@ -246,9 +232,9 @@ public class RenderBuffer { public RenderBuffer put(float[] x, int offset, int length) { // assert (position() % SIZEOF_FLOAT == 0); if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_FLOAT; + long offsetInBytes = offset * SIZEOF_FLOAT + Unsafe.ARRAY_FLOAT_BASE_OFFSET; long lengthInBytes = length * SIZEOF_FLOAT; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; @@ -277,9 +263,9 @@ public class RenderBuffer { public RenderBuffer put(long[] x, int offset, int length) { // assert (position() % SIZEOF_LONG == 0); if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_LONG; + long offsetInBytes = offset * SIZEOF_LONG + Unsafe.ARRAY_LONG_BASE_OFFSET; long lengthInBytes = length * SIZEOF_LONG; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; diff --git a/src/share/classes/sun/java2d/pipe/RenderingEngine.java b/src/share/classes/sun/java2d/pipe/RenderingEngine.java index 1c189f7e0fba92564a77bed9657a4ddab9c50625..5a0163a612e50c021e897da03d9b7303a68bc9ae 100644 --- a/src/share/classes/sun/java2d/pipe/RenderingEngine.java +++ b/src/share/classes/sun/java2d/pipe/RenderingEngine.java @@ -95,6 +95,11 @@ public abstract class RenderingEngine { *
      *     java -Dsun.java2d.renderer=<classname>
      * 
+ * + * If no specific {@code RenderingEngine} is specified on the command + * or Ductus renderer is specified, it will attempt loading the + * sun.dc.DuctusRenderingEngine class using Class.forName as a fastpath; + * if not found, use the ServiceLoader. * If no specific {@code RenderingEngine} is specified on the command * line then the last one returned by enumerating all subclasses of * {@code RenderingEngine} known to the ServiceLoader is used. @@ -115,9 +120,21 @@ public abstract class RenderingEngine { reImpl = (RenderingEngine) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { + final String ductusREClass = "sun.dc.DuctusRenderingEngine"; String reClass = - System.getProperty("sun.java2d.renderer", - "sun.dc.DuctusRenderingEngine"); + System.getProperty("sun.java2d.renderer", ductusREClass); + if (reClass.equals(ductusREClass)) { + try { + Class cls = Class.forName(ductusREClass); + return cls.newInstance(); + } catch (ClassNotFoundException x) { + // not found + } catch (IllegalAccessException x) { + // should not reach here + } catch (InstantiationException x) { + // should not reach here + } + } ServiceLoader reLoader = ServiceLoader.loadInstalled(RenderingEngine.class); diff --git a/src/share/classes/sun/java2d/pisces/Stroker.java b/src/share/classes/sun/java2d/pisces/Stroker.java index 45e4ac7f051de78dce7a9133e05174586699de64..7ba8c1cb76a442f71a880f95d889b82415487636 100644 --- a/src/share/classes/sun/java2d/pisces/Stroker.java +++ b/src/share/classes/sun/java2d/pisces/Stroker.java @@ -181,7 +181,7 @@ public class Stroker extends LineSink { Transform4 transform) { this.lineWidth = lineWidth; this.lineWidth2 = lineWidth >> 1; - this.scaledLineWidth2 = (long)transform.m00*lineWidth2; + this.scaledLineWidth2 = ((long)transform.m00*lineWidth2) >> 16; this.capStyle = capStyle; this.joinStyle = joinStyle; this.miterLimit = miterLimit; @@ -243,8 +243,8 @@ public class Stroker extends LineSink { if (ilen == 0) { dx = dy = 0; } else { - dx = (int)( (ly*scaledLineWidth2)/ilen >> 16); - dy = (int)(-(lx*scaledLineWidth2)/ilen >> 16); + dx = (int)( (ly*scaledLineWidth2)/ilen); + dy = (int)(-(lx*scaledLineWidth2)/ilen); } } else { double dlx = x1 - x0; diff --git a/src/share/native/sun/java2d/pipe/RenderBuffer.c b/src/share/native/sun/java2d/pipe/RenderBuffer.c deleted file mode 100644 index fd6b5abd49601d1ac5fe6bfd20b8664ca43aa23a..0000000000000000000000000000000000000000 --- a/src/share/native/sun/java2d/pipe/RenderBuffer.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2005 Sun Microsystems, Inc. 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. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -#include "jni.h" -#include "jni_util.h" -#include "jlong.h" -#include - -#include "sun_java2d_pipe_RenderBuffer.h" - -/** - * Note: The code in this file is nearly identical to that in - * java/nio/Bits.c... - */ - -#define MBYTE 1048576 - -JNIEXPORT void JNICALL -Java_sun_java2d_pipe_RenderBuffer_copyFromArray - (JNIEnv *env, jclass rb, - jobject srcArray, jlong srcPos, jlong dstAddr, jlong length) -{ - jbyte *bytes; - size_t size; - - while (length > 0) { - /* - * Copy no more than one megabyte at a time, to allow for GC. - * (Probably not an issue for STR, since our buffer size is likely - * much smaller than a megabyte, but just in case...) - */ - size = (size_t)(length > MBYTE ? MBYTE : length); - - bytes = (*env)->GetPrimitiveArrayCritical(env, srcArray, NULL); - if (bytes == NULL) { - JNU_ThrowInternalError(env, "Unable to get array"); - return; - } - - memcpy(jlong_to_ptr(dstAddr), bytes + srcPos, size); - - (*env)->ReleasePrimitiveArrayCritical(env, srcArray, - bytes, JNI_ABORT); - - length -= size; - dstAddr += size; - srcPos += size; - } -} diff --git a/test/java/awt/PrintJob/EdgeTest/EdgeTest.java b/test/java/awt/PrintJob/EdgeTest/EdgeTest.java index 56dd2ddc03022c37f5ad32a0177a2fe29866677c..5e039e70b94f302c0243fcd6a9479c0bd8c50619 100644 --- a/test/java/awt/PrintJob/EdgeTest/EdgeTest.java +++ b/test/java/awt/PrintJob/EdgeTest/EdgeTest.java @@ -27,6 +27,7 @@ * @summary Verifies that (0, 0) is the upper-left corner of the page, not * the upper-left corner adjusted for the margins. * @author dpm + * @run main/manual EdgeTest */ import java.awt.*; @@ -43,7 +44,9 @@ public class EdgeTest extends Panel { } ); f.setVisible(true); - PrintJob pj = getToolkit().getPrintJob(f, "EdgeTest", null); + JobAttributes job = new JobAttributes(); + job.setDialog(JobAttributes.DialogType.NONE); + PrintJob pj = getToolkit().getPrintJob(f, "EdgeTest", job, null); if (pj != null) { Graphics g = pj.getGraphics(); Dimension d = pj.getPageDimension(); diff --git a/test/java/awt/PrintJob/MultipleEnd/MultipleEnd.java b/test/java/awt/PrintJob/MultipleEnd/MultipleEnd.java index 1f64d4fc3a45447836ab35f1fe7ff5761509b50d..c0d837d92fcb62eb61b723afe64dedd55540aac4 100644 --- a/test/java/awt/PrintJob/MultipleEnd/MultipleEnd.java +++ b/test/java/awt/PrintJob/MultipleEnd/MultipleEnd.java @@ -44,7 +44,10 @@ class MultipleEndFrame extends Frame { public MultipleEndFrame() { super("MultipleEnd"); setVisible(true); - PrintJob pj = getToolkit().getPrintJob(this, "MuiltipleEnd", null); + + JobAttributes job = new JobAttributes(); + job.setDialog(JobAttributes.DialogType.NONE); + PrintJob pj = getToolkit().getPrintJob(this, "MultipleEnd", job, null); if (pj != null) { pj.end(); pj.end(); diff --git a/test/java/awt/print/PrinterJob/Collate2DPrintingTest.java b/test/java/awt/print/PrinterJob/Collate2DPrintingTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f33a21cc316f21c61318c78d375c4a0e63ada375 --- /dev/null +++ b/test/java/awt/print/PrinterJob/Collate2DPrintingTest.java @@ -0,0 +1,252 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6362683 + * @summary Collation should work. + * @run main/manual Collate2DPrintingTest + */ +import java.awt.*; +import java.awt.event.*; +import java.awt.print.*; +import javax.print.attribute.standard.*; +import javax.print.attribute.*; +import javax.print.*; +import java.io.*; + +public class Collate2DPrintingTest + extends Frame implements Doc, Printable, ActionListener { + + Button print2D = new Button("2D Print"); + Button printMerlin = new Button("PrintService"); + PrinterJob pj = PrinterJob.getPrinterJob(); + PrintService defService = null; + HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet(); + + public Collate2DPrintingTest() { + + Panel butPanel = new Panel(); + butPanel.add(print2D); + butPanel.add(printMerlin); + print2D.addActionListener(this); + printMerlin.addActionListener(this); + addWindowListener (new WindowAdapter() { + public void windowClosing (WindowEvent e) { + dispose(); + } + }); + add("South", butPanel); + + defService = PrintServiceLookup.lookupDefaultPrintService(); + PrintService[] pservice; + if (defService == null) { + pservice = PrintServiceLookup.lookupPrintServices(null, null); + if (pservice.length == 0) { + throw new RuntimeException("No printer found. TEST ABORTED"); + } + defService = pservice[0]; + } + prSet.add(SheetCollate.COLLATED); + prSet.add(new Copies(2)); + pj.setPrintable(Collate2DPrintingTest.this); + setSize(300, 200); + setVisible(true); + } + + + public int print(Graphics g, PageFormat pf, int pageIndex) + throws PrinterException { + g.drawString("Page: " + pageIndex, 100, 100); + if (pageIndex == 2) { + return Printable.NO_SUCH_PAGE; + } else { + return Printable.PAGE_EXISTS; + } + } + + public void actionPerformed (ActionEvent ae) { + try { + if (ae.getSource() == print2D) { + if (pj.printDialog(prSet)) { + pj.print(prSet); + } + } else { + DocPrintJob pj = defService.createPrintJob(); + pj.print(this, prSet); + } + System.out.println ("DONE"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public DocAttributeSet getAttributes() { + return null; + } + + public DocFlavor getDocFlavor() { + DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; + return flavor; + } + + public Object getPrintData() { + return this; + } + + public Reader getReaderForText() { + return null; + } + + public InputStream getStreamForBytes() { + return null; + } + + public static void main( String[] args) { + + String[] instructions = + { + "You must have a printer available to perform this test", + "The print result should be collated." + }; + Sysout.createDialog( ); + Sysout.printInstructions( instructions ); + + new Collate2DPrintingTest(); + } +} + + +class Sysout { + private static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + } + +}// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog { + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + } + + }// TestDialog class diff --git a/test/java/awt/print/PrinterJob/PrtException.java b/test/java/awt/print/PrinterJob/PrtException.java new file mode 100644 index 0000000000000000000000000000000000000000..f4cfdb574716109cde8055777f003cecd71c6dc4 --- /dev/null +++ b/test/java/awt/print/PrinterJob/PrtException.java @@ -0,0 +1,78 @@ +/* + * Copyright 2001-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +/* + @test + @bug 4429544 + @summary This test should not throw a printer exception. Test has been modified to correspond with the behavior of 1.5 and above. + @run main PrtException +*/ + +import java.awt.*; +import java.awt.print.*; +import javax.print.*; + +public class PrtException implements Printable { + PrinterJob pj; + + public PrtException() { + + try{ + PrintService[] svc; + PrintService defService = PrintServiceLookup.lookupDefaultPrintService(); + if (defService == null) { + svc = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); + if (svc.length == 0) { + throw new RuntimeException("Printer is required for this test. TEST ABORTED"); + } + defService = svc[0]; + } + + System.out.println("PrintService found : "+defService); + pj = PrinterJob.getPrinterJob();; + pj.setPrintService(defService); + //pj.setPrintable(this); // commenting this line should not result in PrinterException + pj.print(); + } catch(PrinterException e ) { + e.printStackTrace(); + throw new RuntimeException(" PrinterException should not be thrown. TEST FAILED"); + } + System.out.println("TEST PASSED"); + } + + + public int print(Graphics g,PageFormat pf,int pageIndex) { + Graphics2D g2= (Graphics2D)g; + if(pageIndex>=1){ + return Printable.NO_SUCH_PAGE; + } + g2.translate(pf.getImageableX(), pf.getImageableY()); + g2.setColor(Color.black); + g2.drawString("Hello world.", 10, 10); + + return Printable.PAGE_EXISTS; + } + + public static void main(String arg[]) { + PrtException sp = new PrtException(); + } +} diff --git a/test/javax/print/CheckDupFlavor.java b/test/javax/print/CheckDupFlavor.java index 5317e503918e6d98a2b36aa1bc28f860ce5aca3d..db52def9a20ba59748d47281f52e2c7ea85d07b1 100644 --- a/test/javax/print/CheckDupFlavor.java +++ b/test/javax/print/CheckDupFlavor.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2004-2009 Sun Microsystems, Inc. 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 @@ -35,17 +35,19 @@ import java.util.ArrayList; public class CheckDupFlavor { public static void main(String[] args){ - PrintService pservice = - PrintServiceLookup.lookupDefaultPrintService(); - - if (pservice == null) { - System.out.println("No default PrintService found. Test ABORTED."); - return; + PrintService defService = PrintServiceLookup.lookupDefaultPrintService(); + PrintService[] pservice; + if (defService == null) { + pservice = PrintServiceLookup.lookupPrintServices(null, null); + if (pservice.length == 0) { + throw new RuntimeException("No printer found. TEST ABORTED"); + } + defService = pservice[0]; } - System.out.println("Default service = "+pservice); + System.out.println("PrintService = "+defService); - DocFlavor[] flavors = pservice.getSupportedDocFlavors(); + DocFlavor[] flavors = defService.getSupportedDocFlavors(); if (flavors==null) { System.out.println("No flavors supported. Test PASSED."); return; @@ -54,13 +56,13 @@ public class CheckDupFlavor { ArrayList flavorList = new ArrayList(); for (int i=0; i=0)) { + System.out.println("Not a Windows System. TEST ABORTED"); + return; + } + + PrintService pservice = PrintServiceLookup.lookupDefaultPrintService(); + if (pservice == null) { + throw new RuntimeException("A printer is required for this test."); + } + + System.out.println("Default Service is "+pservice); + ColorSupported psa = (ColorSupported)pservice.getAttribute(ColorSupported.class); + ArrayList cValues = new ArrayList(); + + if (pservice.isAttributeCategorySupported(Chromaticity.class)) { + Chromaticity[] values =(Chromaticity[]) + (pservice.getSupportedAttributeValues(Chromaticity.class, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null)); + if ((values != null) && (values.length > 0)) { + for (int i=0; i 0) { + System.out.println("found PrintService: "+ps[0]); + Copies c = new Copies(1); + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + aset.add(c); + boolean suppVal = ps[0].isAttributeValueSupported(c, flavor, null); + AttributeSet us = ps[0].getUnsupportedAttributes(flavor, aset); + if (suppVal || us == null) { + throw new RuntimeException("Copies should be unsupported value"); + } + + Object value = ps[0].getSupportedAttributeValues(Copies.class, + flavor, null); + + //Copies Supported + if(value instanceof CopiesSupported) { + throw new RuntimeException("Copies should have no supported values."); + } } - Copies c = new Copies(1); - PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); - aset.add(c); - boolean suppVal = ps.isAttributeValueSupported(c, flavor, null); - AttributeSet us = ps.getUnsupportedAttributes(flavor, aset); - if (suppVal || us == null) { - throw new RuntimeException("Copies should be unsupported value"); - } - - Object value = ps.getSupportedAttributeValues(Copies.class, flavor, null); - - //Copies Supported - if(value instanceof CopiesSupported) { - throw new RuntimeException("Copies should have no supported values."); - } } } diff --git a/test/javax/print/attribute/SidesPageRangesTest.java b/test/javax/print/attribute/SidesPageRangesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..cf48761613701f76fd0da5f509db229b25c7dafb --- /dev/null +++ b/test/javax/print/attribute/SidesPageRangesTest.java @@ -0,0 +1,122 @@ +/* + * Copyright 2003-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +/* + * @test + * @bug 4903366 + * @summary No crash should occur. + * @run main SidesPageRangesTest +*/ +import java.awt.*; +import javax.print.*; +import javax.print.attribute.standard.*; +import javax.print.attribute.*; +import java.io.*; +import java.util.Locale; +import java.net.URL; + +public class SidesPageRangesTest { + /** + * Constructor + */ + public SidesPageRangesTest() { + super(); + } + /** + * Starts the application. + */ + public static void main(java.lang.String[] args) { + SidesPageRangesTest pd = new SidesPageRangesTest(); + PrintService defService = null; + DocFlavor flavors[] = null; + PrintService[] pservice; + defService = PrintServiceLookup.lookupDefaultPrintService(); + if (defService == null) { + pservice = PrintServiceLookup.lookupPrintServices(null, null); + if (pservice.length == 0) { + throw new RuntimeException("Printer is required for this test. TEST ABORTED"); + } + defService = pservice[0]; + } + System.out.println("Default Print Service "+defService); + + + if (defService.isAttributeCategorySupported(PageRanges.class)) { + System.out.println("\nPageRanges Attribute category is supported"); + } else { + System.out.println("\nPageRanges Attribute category is not supported. terminating..."); + System.exit(1); + } + + flavors = defService.getSupportedDocFlavors(); + System.out.println("\nGetting Supported values for PageRanges for each supported DocFlavor"); + System.out.println("===============================================================\n"); + for (int y = 0; y < flavors.length; y ++) { + System.out.println("\n\n"); + + System.out.println("Doc Flavor: "+flavors[y]); + System.out.println("-----------------------------"); + + Object vals = defService.getSupportedAttributeValues(PageRanges.class, flavors[y], null); + if (vals == null) { + System.out.println("No supported values for PageRanges for this doc flavor. "); + } + + PageRanges[] pr = null; + if (vals instanceof PageRanges[]) { + pr = (PageRanges[]) vals; + for (int x = 0; x < pr.length; x ++) { + System.out.println("\nSupported Value "+pr[x]); + System.out.println("is "+pr[x]+" value supported? "+defService.isAttributeValueSupported(pr[x], flavors[y], null)); + + if (!defService.isAttributeValueSupported(pr[x], flavors[y], null)) { + throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues"); + } + } + } else if (vals instanceof PageRanges) { + System.out.println(vals); + System.out.println("is "+vals+" value supported? "+defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null)); + if (!defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null)) { + throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues"); + } + } + + // SIDES test + vals = defService.getSupportedAttributeValues(Sides.class, flavors[y], null); + if (vals == null) { + System.out.println("No supported values for Sides for this doc flavor. "); + } + + Sides[] s = null; + if (vals instanceof Sides[]) { + s = (Sides[]) vals; + for (int x = 0; x < s.length; x ++) { + System.out.println("\nSupported Value "+s[x]); + System.out.println("is "+s[x]+" value supported? "+defService.isAttributeValueSupported(s[x], flavors[y], null)); + if (!defService.isAttributeValueSupported(s[x], flavors[y], null)) { + throw new RuntimeException("Sides contradicts getSupportedAttributeValues"); + } + } + } + } + } +} diff --git a/test/javax/print/attribute/SupportedPrintableAreas.java b/test/javax/print/attribute/SupportedPrintableAreas.java new file mode 100644 index 0000000000000000000000000000000000000000..472a6f48e1405a53074803aed2acdbeca0022af7 --- /dev/null +++ b/test/javax/print/attribute/SupportedPrintableAreas.java @@ -0,0 +1,83 @@ +/* + * Copyright 2003-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 4762773 6289206 6324049 6362765 + * @summary Tests that get non-null return list of printable areas. + * @run main SupportedPrintableAreas + */ + + +import javax.print.*; +import javax.print.event.*; +import javax.print.attribute.*; +import javax.print.attribute.standard.*; + +public class SupportedPrintableAreas { + + public static void main(String[] args) { + PrintService[] svc; + PrintService printer = PrintServiceLookup.lookupDefaultPrintService(); + if (printer == null) { + svc = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); + if (svc.length == 0) { + throw new RuntimeException("Printer is required for this test. TEST ABORTED"); + } + printer = svc[0]; + } + System.out.println("PrintService found : "+printer); + + if (!printer.isAttributeCategorySupported(MediaPrintableArea.class)) { + return; + } + Object value = printer.getSupportedAttributeValues( + MediaPrintableArea.class, null, null); + if (!value.getClass().isArray()) { + throw new RuntimeException("unexpected value"); + } + + PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + value = printer.getSupportedAttributeValues( + MediaPrintableArea.class, null, aset); + if (!value.getClass().isArray()) { + throw new RuntimeException("unexpected value"); + } + + Media media = (Media)printer.getDefaultAttributeValue(Media.class); + aset.add(media); + value = printer.getSupportedAttributeValues( + MediaPrintableArea.class, null, aset); + if (!value.getClass().isArray()) { + throw new RuntimeException("unexpected value"); + } + + // test for 6289206 + aset.add(MediaTray.MANUAL); + value = printer.getSupportedAttributeValues( + MediaPrintableArea.class, null, aset); + if ((value != null) && !value.getClass().isArray()) { + throw new RuntimeException("unexpected value"); + } + } +} diff --git a/test/javax/print/attribute/autosense/PrintAutoSenseData.java b/test/javax/print/attribute/autosense/PrintAutoSenseData.java new file mode 100644 index 0000000000000000000000000000000000000000..b87807b7d182a899dec0942d5b839aba78ca0a46 --- /dev/null +++ b/test/javax/print/attribute/autosense/PrintAutoSenseData.java @@ -0,0 +1,152 @@ +/* + * Copyright 2001-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 4468109 + * @summary Test for printing AUTOSENSE DocFlavor. No exception should be thrown. + * @run main PrintAutoSenseData +*/ + +import java.io.*; +import javax.print.*; +import javax.print.attribute.*; +import javax.print.attribute.standard.*; +import java.net.URL; + +public class PrintAutoSenseData +{ + private DocFlavor flavor = DocFlavor.URL.AUTOSENSE; //represents the docflavor. + private PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor, null); + + + public PrintAutoSenseData() + { + if (service.length == 0) + { + System.out.println("No print service available..."); + return; + } + + System.out.println("selected PrintService: " + this.service[0]); + if (service[0].isDocFlavorSupported(flavor)) { + System.out.println("DocFlavor.URL.AUTOSENSE supported"); + } else { + System.out.println("DocFlavor.URL.AUTOSENSE not supported. Testing aborted !!"); + return; + } + + DocPrintJob job = service[0].createPrintJob(); + this.print(); + } + + // The print method prints sample file with DocFlavor.URL.AUTOSENSE. + void print() + { + String fileName = "./sample.txt"; + DocPrintJob job = service[0].createPrintJob(); + + // The representation class is a URL. + System.out.println("printing " + fileName + " using doc flavor: " + this.flavor); + System.out.println("Rep. class name: " + this.flavor.getRepresentationClassName() + " MimeType: " + this.flavor.getMimeType()); + + Doc doc = new URLDoc(fileName, this.flavor); + HashPrintRequestAttributeSet prSet = + new HashPrintRequestAttributeSet(); + prSet.add(new Destination(new File("./dest.prn").toURI())); + //print the document. + try { + job.print(doc, prSet); + } catch ( Exception e ) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + new PrintAutoSenseData(); + } + +} + +/* This class is for reading autosense data with URL representation class */ + +class URLDoc implements Doc +{ + protected String fileName = null; + protected DocFlavor flavor = null; + protected Object printData = null; + protected InputStream instream = null; + + public URLDoc(String filename, DocFlavor docFlavor) + { + this.fileName = filename; + this.flavor = docFlavor; + } + + public DocFlavor getDocFlavor() { + return DocFlavor.URL.AUTOSENSE; + } + + public DocAttributeSet getAttributes() + { + HashDocAttributeSet hset = new HashDocAttributeSet(); + return hset; + } + + public Object getPrintData() + { + if ( this.printData == null ) + { + this.printData = URLDoc.class.getResource(this.fileName); + System.out.println("getPrintData(): " + this.printData); + } + return this.printData; + } + + public Reader getReaderForText() + { + return null; + } + + public InputStream getStreamForBytes() + { + System.out.println("getStreamForBytes(): " + this.printData); + try + { + if ( (this.printData != null) && (this.printData instanceof URL) ) + { + this.instream = ((URL)this.printData).openStream(); + } + if (this.instream == null) + { + URL url = URLDoc.class.getResource(this.fileName); + this.instream = url.openStream(); + } + } + catch ( IOException ie ) + { + System.out.println("URLDoc: exception: " + ie.toString()); + } + return this.instream; + } +} diff --git a/test/sun/pisces/StrokeShapeTest.java b/test/sun/pisces/StrokeShapeTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d92c1d3f1285da7fee6b155da0f42cacacc329e7 --- /dev/null +++ b/test/sun/pisces/StrokeShapeTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +import java.awt.*; +import java.awt.geom.Ellipse2D; +import java.awt.geom.GeneralPath; +import java.awt.image.BufferedImage; +import java.io.File; + +import javax.imageio.ImageIO; + +/** + * @author chrisn@google.com (Chris Nokleberg) + * @author yamauchi@google.com (Hiroshi Yamauchi) + */ +public class StrokeShapeTest { + public static void main(String[] args) throws Exception { + BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setPaint(Color.WHITE); + g.fill(new Rectangle(image.getWidth(), image.getHeight())); + g.translate(25, 100); + + Stroke stroke = new BasicStroke(200, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + Shape shape = new Polygon(new int[] {0, 1500, 0}, new int[] {750, 0, -750}, 3); + + g.scale(.1, .1); + g.setPaint(Color.BLACK); + g.setStroke(stroke); + g.draw(shape); + g.setPaint(Color.RED); + g.fill(stroke.createStrokedShape(shape)); + + // To visually check it + //ImageIO.write(image, "PNG", new File(args[0])); + + boolean blackPixelFound = false; + outer: + for (int x = 0; x < 200; ++x) { + for (int y = 0; y < 200; ++y) { + if (image.getRGB(x, y) == Color.BLACK.getRGB()) { + blackPixelFound = true; + break outer; + } + } + } + if (blackPixelFound) { + throw new RuntimeException("The shape hasn't been filled in red."); + } + } +}