diff --git a/src/share/classes/java/awt/color/ICC_Profile.java b/src/share/classes/java/awt/color/ICC_Profile.java index b459f63b16d40ae5c98bcceb344f35b226781026..c1534249f391a14a30d261e81b3810920a27ffda 100644 --- a/src/share/classes/java/awt/color/ICC_Profile.java +++ b/src/share/classes/java/awt/color/ICC_Profile.java @@ -37,6 +37,7 @@ package java.awt.color; import sun.java2d.cmm.PCMM; import sun.java2d.cmm.CMSManager; +import sun.java2d.cmm.ProfileDataVerifier; import sun.java2d.cmm.ProfileDeferralMgr; import sun.java2d.cmm.ProfileDeferralInfo; import sun.java2d.cmm.ProfileActivator; @@ -775,6 +776,8 @@ public class ICC_Profile implements Serializable { ProfileDeferralMgr.activateProfiles(); } + ProfileDataVerifier.verify(data); + try { theID = CMSManager.getModule().loadProfile(data); } catch (CMMException c) { diff --git a/src/share/classes/sun/java2d/cmm/ProfileDataVerifier.java b/src/share/classes/sun/java2d/cmm/ProfileDataVerifier.java new file mode 100644 index 0000000000000000000000000000000000000000..e6100bbefd41153bf62223d91925d14610112be4 --- /dev/null +++ b/src/share/classes/sun/java2d/cmm/ProfileDataVerifier.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package sun.java2d.cmm; + +public class ProfileDataVerifier { + /** + * Throws an IllegalArgumentException if the data does not correspond + * to a valid ICC Profile. + * + * @param data the specified profile data. + */ + public static void verify(byte[] data) { + if (data == null) { + throw new IllegalArgumentException("Invalid ICC Profile Data"); + } + + if (data.length < TOC_OFFSET) { + // not enough data for profile header + throw new IllegalArgumentException("Invalid ICC Profile Data"); + } + + // check profile size + final int size = readInt32(data, 0); + final int tagCount = readInt32(data, HEADER_SIZE); + + if (tagCount < 0 || tagCount > MAX_TAG_COUNT) { + throw new IllegalArgumentException("Invalid ICC Profile Data"); + } + + if (size < (TOC_OFFSET + (tagCount * TOC_RECORD_SIZE)) || + size > data.length) + { + throw new IllegalArgumentException("Invalid ICC Profile Data"); + } + + final int sig = readInt32(data, 36); + + if (PROFILE_FILE_SIGNATURE != sig) { + throw new IllegalArgumentException("Invalid ICC Profile Data"); + } + + // verify table of content + for (int i = 0; i < tagCount; i++) { + final int tag_offset = getTagOffset(i, data); + final int tag_size = getTagSize(i, data); + + if (tag_offset < TOC_OFFSET || tag_offset > size) { + throw new IllegalArgumentException("Invalid ICC Profile Data"); + } + + if (tag_size < 0 || + tag_size > (Integer.MAX_VALUE - tag_offset) || + tag_size + tag_offset > size) + { + throw new IllegalArgumentException("Invalid ICC Profile Data"); + } + } + } + + private static int getTagOffset(int idx, byte[] data) { + final int pos = TOC_OFFSET + idx * TOC_RECORD_SIZE + 4; + return readInt32(data, pos); + } + + private static int getTagSize(int idx, byte[] data) { + final int pos = TOC_OFFSET + idx * TOC_RECORD_SIZE + 8; + return readInt32(data, pos); + } + + private static int readInt32(byte[] data, int off) { + int res = 0; + for (int i = 0; i < 4; i++) { + res = res << 8; + + res |= (0xff & data[off++]); + } + return res; + } + + /** + * Lcms limit for the number of tags: 100 + * Kcms limit for the number of tags: N/A + */ + private static final int MAX_TAG_COUNT = 100; + + private static final int HEADER_SIZE = 128; + private static final int TOC_OFFSET = HEADER_SIZE + 4; + private static final int TOC_RECORD_SIZE = 12; + + private static final int PROFILE_FILE_SIGNATURE = 0x61637370; +} diff --git a/src/share/native/sun/font/layout/KernTable.cpp b/src/share/native/sun/font/layout/KernTable.cpp index 13ddd0f3b32ab8416588d6e0d4ae56feabbb7b60..2d946513fb824d7c3c9e9be6baaf7ed69a4d5fe3 100644 --- a/src/share/native/sun/font/layout/KernTable.cpp +++ b/src/share/native/sun/font/layout/KernTable.cpp @@ -96,7 +96,7 @@ LE_CORRECT_SIZE(KernTableHeader, KERN_TABLE_HEADER_SIZE) * TODO: respect header flags */ KernTable::KernTable(const LETableReference& base, LEErrorCode &success) - : pairs(), pairsSwapped(NULL), fTable(base) + : pairsSwapped(NULL), fTable(base) { if(LE_FAILURE(success) || (fTable.isEmpty())) { #if DEBUG @@ -143,32 +143,36 @@ KernTable::KernTable(const LETableReference& base, LEErrorCode &success) #endif if(LE_SUCCESS(success) && nPairs>0) { - // pairs is an instance member, and table is on the stack. - // set 'pairs' based on table.getAlias(). This will range check it. - - pairs = LEReferenceToArrayOf(fTable, // based on overall table - success, - (const PairInfo*)table.getAlias(), // subtable 0 + .. - KERN_SUBTABLE_0_HEADER_SIZE, // .. offset of header size - nPairs); // count - } - if (LE_SUCCESS(success) && pairs.isValid()) { - pairsSwapped = (PairInfo*)(malloc(nPairs*sizeof(PairInfo))); - PairInfo *p = (PairInfo*)pairsSwapped; - for (int i = 0; LE_SUCCESS(success) && i < nPairs; i++, p++) { - memcpy(p, pairs.getAlias(i,success), KERN_PAIRINFO_SIZE); - p->key = SWAPL(p->key); + // pairsSwapped is an instance member, and table is on the stack. + // set 'pairsSwapped' based on table.getAlias(). This will range check it. + + pairsSwapped = (PairInfo*)(fTable.getFont()->getKernPairs()); + if (pairsSwapped == NULL) { + LEReferenceToArrayOfpairs = + LEReferenceToArrayOf(fTable, // based on overall table + success, + (const PairInfo*)table.getAlias(), // subtable 0 + .. + KERN_SUBTABLE_0_HEADER_SIZE, // .. offset of header size + nPairs); // count + if (LE_SUCCESS(success) && pairs.isValid()) { + pairsSwapped = (PairInfo*)(malloc(nPairs*sizeof(PairInfo))); + PairInfo *p = (PairInfo*)pairsSwapped; + for (int i = 0; LE_SUCCESS(success) && i < nPairs; i++, p++) { + memcpy(p, pairs.getAlias(i,success), KERN_PAIRINFO_SIZE); + p->key = SWAPL(p->key); + } + fTable.getFont()->setKernPairs((void*)pairsSwapped); // store it } - fTable.getFont()->setKernPairs((void*)pairsSwapped); // store it + } } #if 0 - fprintf(stderr, "coverage: %0.4x nPairs: %d pairs %p\n", coverage, nPairs, pairs.getAlias()); + fprintf(stderr, "coverage: %0.4x nPairs: %d pairs %p\n", coverage, nPairs, pairsSwapped); fprintf(stderr, " searchRange: %d entrySelector: %d rangeShift: %d\n", searchRange, entrySelector, rangeShift); fprintf(stderr, "[[ ignored font table entries: range %d selector %d shift %d ]]\n", SWAPW(table->searchRange), SWAPW(table->entrySelector), SWAPW(table->rangeShift)); #endif #if DEBUG - fprintf(stderr, "coverage: %0.4x nPairs: %d pairs 0x%x\n", coverage, nPairs, pairs); + fprintf(stderr, "coverage: %0.4x nPairs: %d pairs 0x%x\n", coverage, nPairs, pairsSwapped); fprintf(stderr, " searchRange(pairs): %d entrySelector: %d rangeShift(pairs): %d\n", searchRange, entrySelector, rangeShift); @@ -182,7 +186,7 @@ KernTable::KernTable(const LETableReference& base, LEErrorCode &success) ids[id] = (char)i; } } - PairInfo *p = pairs; + PairInfo *p = pairsSwapped; for (int i = 0; i < nPairs; ++i, p++) { le_uint32 k = p->key; le_uint16 left = (k >> 16) & 0xffff; diff --git a/src/share/native/sun/font/layout/KernTable.h b/src/share/native/sun/font/layout/KernTable.h index 1cc4f872d3be54b72e4a50daed116376bdbfee44..c667a18c05649293b43b183019f32722e621f22b 100644 --- a/src/share/native/sun/font/layout/KernTable.h +++ b/src/share/native/sun/font/layout/KernTable.h @@ -57,7 +57,6 @@ class U_LAYOUT_API KernTable private: le_uint16 coverage; le_uint16 nPairs; - LEReferenceToArrayOf pairs; PairInfo *pairsSwapped; const LETableReference &fTable; le_uint16 searchRange; diff --git a/src/share/native/sun/font/layout/LayoutEngine.cpp b/src/share/native/sun/font/layout/LayoutEngine.cpp index 6690316f32d2495946efe2c438187e2860b3c8f7..30fb0bbede59bf1297d061f8cc9fe7d1a1145de7 100644 --- a/src/share/native/sun/font/layout/LayoutEngine.cpp +++ b/src/share/native/sun/font/layout/LayoutEngine.cpp @@ -569,7 +569,6 @@ void LayoutEngine::reset() { if(fGlyphStorage!=NULL) { fGlyphStorage->reset(); - fGlyphStorage = NULL; } } diff --git a/src/solaris/classes/sun/print/UnixPrintServiceLookup.java b/src/solaris/classes/sun/print/UnixPrintServiceLookup.java index 9fcbb86c75677daa46d7450bc03426734121ba3e..c682634b7b66579219808601d9425d8ce3570fc1 100644 --- a/src/solaris/classes/sun/print/UnixPrintServiceLookup.java +++ b/src/solaris/classes/sun/print/UnixPrintServiceLookup.java @@ -362,10 +362,33 @@ public class UnixPrintServiceLookup extends PrintServiceLookup */ private PrintService getServiceByName(PrinterName nameAttr) { String name = nameAttr.getValue(); - PrintService printer = null; if (name == null || name.equals("") || !checkPrinterName(name)) { return null; } + /* check is all printers are already available */ + if (printServices != null) { + for (PrintService printService : printServices) { + if (printService.getName().equals(name)) { + return printService; + } + } + } + /* take CUPS into account first */ + if (CUPSPrinter.isCupsRunning()) { + try { + return new IPPPrintService(name, + new URL("http://"+ + CUPSPrinter.getServer()+":"+ + CUPSPrinter.getPort()+"/"+ + name)); + } catch (Exception e) { + IPPPrintService.debug_println(debugPrefix+ + " getServiceByName Exception "+ + e); + } + } + /* fallback if nothing not having a printer at this point */ + PrintService printer = null; if (isMac() || isSysV()) { printer = getNamedPrinterNameSysV(name); } else { diff --git a/src/windows/classes/sun/awt/windows/WPrinterJob.java b/src/windows/classes/sun/awt/windows/WPrinterJob.java index 250d8c722034ec872a36ce61d5a6a290497aedcd..897e8f1baf1eaf2278811e0d112cd1ca46349b71 100644 --- a/src/windows/classes/sun/awt/windows/WPrinterJob.java +++ b/src/windows/classes/sun/awt/windows/WPrinterJob.java @@ -1269,11 +1269,13 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { mLastFontFamily = null; } + private boolean defaultCopies = true; /** * Set the number of copies to be printed. */ public void setCopies(int copies) { super.setCopies(copies); + defaultCopies = false; mAttCopies = copies; setNativeCopies(copies); } @@ -1529,8 +1531,9 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { } /* SheetCollate */ - private final boolean getCollateAttrib() { - return (mAttCollate == 1); + private final int getCollateAttrib() { + // -1 means unset, 0 uncollated, 1 collated. + return mAttCollate; } private void setCollateAttrib(Attribute attr) { @@ -1553,6 +1556,10 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { int orient = PageFormat.PORTRAIT; OrientationRequested orientReq = (attributes == null) ? null : (OrientationRequested)attributes.get(OrientationRequested.class); + if (orientReq == null) { + orientReq = (OrientationRequested) + myService.getDefaultAttributeValue(OrientationRequested.class); + } if (orientReq != null) { if (orientReq == OrientationRequested.REVERSE_LANDSCAPE) { orient = PageFormat.REVERSE_LANDSCAPE; @@ -1573,7 +1580,11 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { /* Copies and Page Range. */ private final int getCopiesAttrib() { - return getCopiesInt(); + if (defaultCopies) { + return 0; + } else { + return getCopiesInt(); + } } private final void setRangeCopiesAttribute(int from, int to, @@ -1584,6 +1595,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { attributes.add(new PageRanges(from, to)); setPageRange(from, to); } + defaultCopies = false; attributes.add(new Copies(copies)); /* Since this is called from native to tell Java to sync * up with native, we don't call this class's own setCopies() diff --git a/src/windows/classes/sun/print/Win32PrintService.java b/src/windows/classes/sun/print/Win32PrintService.java index bef2213e66492870ee6991e0d483679fbb0a4e60..ace33268b471b9c33d27c1b4d8afb12be32ba493 100644 --- a/src/windows/classes/sun/print/Win32PrintService.java +++ b/src/windows/classes/sun/print/Win32PrintService.java @@ -180,6 +180,9 @@ public class Win32PrintService implements PrintService, AttributeUpdater, private static final int DMDUP_VERTICAL = 2; private static final int DMDUP_HORIZONTAL = 3; private static final int DMCOLLATE_TRUE = 1; + private static final int DMCOLOR_MONOCHROME = 1; + private static final int DMCOLOR_COLOR = 2; + // media sizes with indices above dmPaperToPrintService' length private static final int DMPAPER_A2 = 66; @@ -1041,6 +1044,7 @@ public class Win32PrintService implements PrintService, AttributeUpdater, int defOrient = defaults[5]; int defSides = defaults[6]; int defCollate = defaults[7]; + int defColor = defaults[8]; if (category == Copies.class) { if (defCopies > 0) { @@ -1049,11 +1053,10 @@ public class Win32PrintService implements PrintService, AttributeUpdater, return new Copies(1); } } else if (category == Chromaticity.class) { - int caps = getPrinterCapabilities(); - if ((caps & DEVCAP_COLOR) == 0) { - return Chromaticity.MONOCHROME; - } else { + if (defColor == DMCOLOR_COLOR) { return Chromaticity.COLOR; + } else { + return Chromaticity.MONOCHROME; } } else if (category == JobName.class) { return new JobName("Java Printing", null); diff --git a/src/windows/native/sun/windows/WPrinterJob.cpp b/src/windows/native/sun/windows/WPrinterJob.cpp index 37075266d34c7879edcfcb0d0f23283beb7e983b..14f43a120b1ab2d5368e7fbe4d5e0ffccf05ece0 100644 --- a/src/windows/native/sun/windows/WPrinterJob.cpp +++ b/src/windows/native/sun/windows/WPrinterJob.cpp @@ -750,7 +750,7 @@ Java_sun_print_Win32PrintService_getCapabilities(JNIEnv *env, #define GETDEFAULT_ERROR -50 -#define NDEFAULT 8 +#define NDEFAULT 9 JNIEXPORT jintArray JNICALL Java_sun_print_Win32PrintService_getDefaultSettings(JNIEnv *env, @@ -859,6 +859,11 @@ Java_sun_print_Win32PrintService_getDefaultSettings(JNIEnv *env, defIndices[7] = pDevMode->dmCollate; } + if (pDevMode->dmFields & DM_COLOR) { + defIndices[8] = pDevMode->dmColor; + } + + GlobalFree(pDevMode); ::ClosePrinter(hPrinter); diff --git a/src/windows/native/sun/windows/awt_PrintControl.cpp b/src/windows/native/sun/windows/awt_PrintControl.cpp index 2361497144a174fd05502525bb0b5a613c870987..c3ee99d6af3749bc58a772315eec4c2557d439ac 100644 --- a/src/windows/native/sun/windows/awt_PrintControl.cpp +++ b/src/windows/native/sun/windows/awt_PrintControl.cpp @@ -252,7 +252,7 @@ void AwtPrintControl::initIDs(JNIEnv *env, jclass cls) AwtPrintControl::getCopiesID = env->GetMethodID(cls, "getCopiesAttrib", "()I"); AwtPrintControl::getCollateID = - env->GetMethodID(cls, "getCollateAttrib","()Z"); + env->GetMethodID(cls, "getCollateAttrib","()I"); AwtPrintControl::getOrientID = env->GetMethodID(cls, "getOrientAttrib", "()I"); AwtPrintControl::getFromPageID = @@ -690,12 +690,6 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env, pd.Flags = PD_ENABLEPRINTHOOK | PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE; pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintDlgHook; - if (env->CallBooleanMethod(printCtrl, AwtPrintControl::getCollateID)) { - pd.Flags |= PD_COLLATE; - } - - pd.nCopies = (WORD)env->CallIntMethod(printCtrl, - AwtPrintControl::getCopiesID); pd.nFromPage = (WORD)env->CallIntMethod(printCtrl, AwtPrintControl::getFromPageID); pd.nToPage = (WORD)env->CallIntMethod(printCtrl, @@ -729,37 +723,52 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env, DEVMODE *devmode = (DEVMODE *)::GlobalLock(pd.hDevMode); DASSERT(!IsBadWritePtr(devmode, sizeof(DEVMODE))); - devmode->dmFields |= DM_COPIES | DM_COLLATE | DM_ORIENTATION | - DM_PAPERSIZE | DM_PRINTQUALITY | DM_COLOR | DM_DUPLEX; - - devmode->dmCopies = pd.nCopies; + WORD copies = (WORD)env->CallIntMethod(printCtrl, + AwtPrintControl::getCopiesID); + if (copies > 0) { + devmode->dmFields |= DM_COPIES; + devmode->dmCopies = copies; + } jint orient = env->CallIntMethod(printCtrl, AwtPrintControl::getOrientID); - if (orient == 0) { + if (orient == 0) { // PageFormat.LANDSCAPE == 0 + devmode->dmFields |= DM_ORIENTATION; devmode->dmOrientation = DMORIENT_LANDSCAPE; - } else if (orient == 1) { + } else if (orient == 1) { // PageFormat.PORTRAIT == 1 + devmode->dmFields |= DM_ORIENTATION; devmode->dmOrientation = DMORIENT_PORTRAIT; } - devmode->dmCollate = (pd.Flags & PD_COLLATE) ? DMCOLLATE_TRUE - : DMCOLLATE_FALSE; + // -1 means unset, so we'll accept the printer default. + int collate = env->CallIntMethod(printCtrl, + AwtPrintControl::getCollateID); + if (collate == 1) { + devmode->dmFields |= DM_COLLATE; + devmode->dmCollate = DMCOLLATE_TRUE; + } else if (collate == 0) { + devmode->dmFields |= DM_COLLATE; + devmode->dmCollate = DMCOLLATE_FALSE; + } int quality = env->CallIntMethod(printCtrl, AwtPrintControl::getQualityID); if (quality) { + devmode->dmFields |= DM_PRINTQUALITY; devmode->dmPrintQuality = quality; } int color = env->CallIntMethod(printCtrl, AwtPrintControl::getColorID); if (color) { + devmode->dmFields |= DM_COLOR; devmode->dmColor = color; } int sides = env->CallIntMethod(printCtrl, AwtPrintControl::getSidesID); if (sides) { + devmode->dmFields |= DM_DUPLEX; devmode->dmDuplex = (int)sides; } @@ -771,6 +780,7 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env, double newWid = 0.0, newHt = 0.0; if (wid_ht != NULL && wid_ht[0] != 0 && wid_ht[1] != 0) { + devmode->dmFields |= DM_PAPERSIZE; devmode->dmPaperSize = AwtPrintControl::getNearestMatchingPaper( printName, portName, diff --git a/test/java/awt/font/TextLayout/KerningLeak.java b/test/java/awt/font/TextLayout/KerningLeak.java new file mode 100644 index 0000000000000000000000000000000000000000..fb8448c3a4eb648669a196f9d70a1e330c5cde25 --- /dev/null +++ b/test/java/awt/font/TextLayout/KerningLeak.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 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. + */ + +/** + * @bug 8015334 + * @summary Memory leak with kerning. + */ + +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.font.TextAttribute; +import java.util.HashMap; +import java.util.Map; +import javax.swing.JLabel; +import javax.swing.SwingUtilities; + +public class KerningLeak { + + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + leak(); + } + }); + } + + private static void leak() { + Map textAttributes = new HashMap<>(); + textAttributes.put(TextAttribute.FAMILY, "Sans Serif"); + textAttributes.put(TextAttribute.SIZE, 12); + textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON); + Font font = Font.getFont(textAttributes); + JLabel label = new JLabel(); + int dummy = 0; + for (int i = 0; i < 500; i++) { + if (i % 10 == 0) System.out.println("Starting iter " + (i+1)); + for (int j = 0; j <1000; j++) { + FontMetrics fm = label.getFontMetrics(font); + dummy += SwingUtilities.computeStringWidth(fm, Integer.toString(j)); + } + } + System.out.println("done " + dummy); + } +} diff --git a/test/javax/print/PrintServiceLookup/GetPrintServices.java b/test/javax/print/PrintServiceLookup/GetPrintServices.java new file mode 100644 index 0000000000000000000000000000000000000000..f8373a6383a5bd9f2b7362632cd96647c04b2f1f --- /dev/null +++ b/test/javax/print/PrintServiceLookup/GetPrintServices.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013, 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.PrintService; +import javax.print.PrintServiceLookup; +import javax.print.attribute.AttributeSet; +import javax.print.attribute.HashAttributeSet; +import javax.print.attribute.standard.PrinterName; + +/* + * @test + * @bug 8013810 + * @summary Test that print service returned without filter are of the same class as with name filter + */ +public class GetPrintServices { + + public static void main(String[] args) throws Exception { + for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) { + String serviceName = service.getName(); + PrintService serviceByName = lookupByName(serviceName); + if (!service.equals(serviceByName)) { + throw new RuntimeException("NOK " + serviceName + + " expected: " + service.getClass().getName() + + " got: " + serviceByName.getClass().getName()); + } + } + System.out.println("Test PASSED"); + } + + private static PrintService lookupByName(String name) { + AttributeSet attributes = new HashAttributeSet(); + attributes.add(new PrinterName(name, null)); + for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) { + return service; + } + return null; + } +} diff --git a/test/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java b/test/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java index 89bd29af05675b535b59bc2589f665ec25233f13..12418c0ed2a3f01277e6abaf97acf814265748a6 100644 --- a/test/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java +++ b/test/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java @@ -23,7 +23,7 @@ /** * @test - * @bug 6476665 7033534 + * @bug 6476665 7033534 6830714 * @summary Verifies color conversion of Component Color Model based images * @run main ColConvCCMTest */ @@ -57,9 +57,9 @@ public class ColConvCCMTest extends ColConvTest { final static double [] ACCURACY = { // Accuracy for color conversions 2.5, // sRGB - 6.5, // LINEAR_RGB + (isOpenProfile() ? 45.0 : 10.1), // LINEAR_RGB 10.5, // GRAY - 45.5, // PYCC + (isOpenProfile() ? 207 : 45.5), // PYCC 47.5 // CIEXYZ }; diff --git a/test/sun/java2d/cmm/ColorConvertOp/ColConvDCMTest.java b/test/sun/java2d/cmm/ColorConvertOp/ColConvDCMTest.java index b9f85c72519d61722dd77c4cdea81742007a365f..9ad05689942f9ca242e0dfd0caa59752ba21542a 100644 --- a/test/sun/java2d/cmm/ColorConvertOp/ColConvDCMTest.java +++ b/test/sun/java2d/cmm/ColorConvertOp/ColConvDCMTest.java @@ -62,7 +62,11 @@ public class ColConvDCMTest extends ColConvTest { ColorSpace.CS_LINEAR_RGB, }; - final static double ACCURACY = 2.5; + final static double [] ACCURACY = { + // Accuracy for color conversions + 2.5, // sRGB + (isOpenProfile() ? 45.0 : 2.5), // LINEAR_RGB + }; final static String [] gldImgNames = { "SRGB.png", "SRGB555.png", "SRGB565.png", "LRGB.png", "LRGB555.png", @@ -142,7 +146,7 @@ public class ColConvDCMTest extends ColConvTest { if (!testImage(imgTypes[i][0], imgTypes[i][1], imgTypes[i][2], imgTypes[i][3], cSpaces[imgTypes[i][4]], gldImage, - ACCURACY)) + ACCURACY[imgTypes[i][4]])) { throw new RuntimeException( "Invalid result of the ColorConvertOp for " + @@ -154,7 +158,8 @@ public class ColConvDCMTest extends ColConvTest { if (!testSubImage(SI_X, SI_Y, SI_W, SI_H, imgTypes[i][0], imgTypes[i][1], imgTypes[i][2], imgTypes[i][3], - cSpaces[imgTypes[i][4]], gldImage, ACCURACY)) + cSpaces[imgTypes[i][4]], gldImage, + ACCURACY[imgTypes[i][4]])) { throw new RuntimeException( "Invalid result of the ColorConvertOp for " + diff --git a/test/sun/java2d/cmm/ColorConvertOp/ColConvTest.java b/test/sun/java2d/cmm/ColorConvertOp/ColConvTest.java index db3719134f18febb752fecb9298f0924eaf410a0..b3f1c2e4da2f0bef9f4eb49463585ce42141ac34 100644 --- a/test/sun/java2d/cmm/ColorConvertOp/ColConvTest.java +++ b/test/sun/java2d/cmm/ColorConvertOp/ColConvTest.java @@ -22,6 +22,7 @@ */ import java.awt.color.ColorSpace; +import java.awt.color.ICC_Profile; import java.awt.image.BufferedImage; import java.awt.image.DataBuffer; @@ -126,4 +127,33 @@ public abstract class ColConvTest implements Runnable { public boolean isPassed() { return passed; } + + private static Boolean isOpenProfile = null; + + public static boolean isOpenProfile() { + if (isOpenProfile == null) { + ICC_Profile p = ICC_Profile.getInstance(ColorSpace.CS_sRGB); + + byte[] h = p.getData(ICC_Profile.icSigHead); + + if (h == null || h.length < 128) { + throw new RuntimeException("Test failed: invalid sRGB header"); + } + + final byte[] lcmsID = new byte[] { + (byte)0x6c, // l + (byte)0x63, // c + (byte)0x6d, // m + (byte)0x73, // s + }; + + int off = ICC_Profile.icHdrCmmId; + + isOpenProfile = ((h[off + 0] == lcmsID[0]) + && (h[off + 1] == lcmsID[1]) + && (h[off + 2] == lcmsID[2]) + && (h[off + 3] == lcmsID[3])); + } + return isOpenProfile; + } }