src/windows/classes/sun/print/Win32PrintService.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2000, 2011, 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 --- 1,7 ---- /* ! * Copyright (c) 2000, 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
*** 26,40 **** package sun.print; import java.io.File; import java.net.URI; import java.net.URISyntaxException; ! import java.net.URL; ! ! import java.util.Vector; import java.util.HashMap; - import javax.print.DocFlavor; import javax.print.DocPrintJob; import javax.print.PrintService; import javax.print.ServiceUIFactory; import javax.print.attribute.Attribute; --- 26,37 ---- package sun.print; import java.io.File; import java.net.URI; import java.net.URISyntaxException; ! import java.util.ArrayList; import java.util.HashMap; import javax.print.DocFlavor; import javax.print.DocPrintJob; import javax.print.PrintService; import javax.print.ServiceUIFactory; import javax.print.attribute.Attribute;
*** 67,92 **** import javax.print.attribute.standard.PrinterStateReasons; import javax.print.attribute.standard.Severity; import javax.print.attribute.standard.Sides; import javax.print.attribute.standard.ColorSupported; import javax.print.attribute.standard.PrintQuality; - import javax.print.attribute.ResolutionSyntax; import javax.print.attribute.standard.PrinterResolution; import javax.print.attribute.standard.SheetCollate; import javax.print.event.PrintServiceAttributeListener; - import java.util.ArrayList; - - import sun.print.SunPrinterJobService; public class Win32PrintService implements PrintService, AttributeUpdater, SunPrinterJobService { ! public static MediaSize[] predefMedia; ! ! static { ! Class c = Win32MediaSize.class; ! } private static final DocFlavor[] supportedFlavors = { DocFlavor.BYTE_ARRAY.GIF, DocFlavor.INPUT_STREAM.GIF, DocFlavor.URL.GIF, --- 64,81 ---- import javax.print.attribute.standard.PrinterStateReasons; import javax.print.attribute.standard.Severity; import javax.print.attribute.standard.Sides; import javax.print.attribute.standard.ColorSupported; import javax.print.attribute.standard.PrintQuality; import javax.print.attribute.standard.PrinterResolution; import javax.print.attribute.standard.SheetCollate; import javax.print.event.PrintServiceAttributeListener; public class Win32PrintService implements PrintService, AttributeUpdater, SunPrinterJobService { ! public static MediaSize[] predefMedia = Win32MediaSize.getPredefMedia(); private static final DocFlavor[] supportedFlavors = { DocFlavor.BYTE_ARRAY.GIF, DocFlavor.INPUT_STREAM.GIF, DocFlavor.URL.GIF,
*** 308,333 **** return Win32MediaTray.AUTO; } public MediaSizeName findWin32Media(int dmIndex) { if (dmIndex >= 1 && dmIndex <= dmPaperToPrintService.length) { switch(dmIndex) { /* matching media sizes with indices beyond dmPaperToPrintService's length */ case DMPAPER_A2: return MediaSizeName.ISO_A2; case DMPAPER_A6: return MediaSizeName.ISO_A6; case DMPAPER_B6_JIS: return MediaSizeName.JIS_B6; default: - return dmPaperToPrintService[dmIndex - 1]; - } - } - return null; } private boolean addToUniqueList(ArrayList msnList, MediaSizeName mediaName) { MediaSizeName msn; for (int i=0; i< msnList.size(); i++) { msn = (MediaSizeName)msnList.get(i); --- 297,321 ---- return Win32MediaTray.AUTO; } public MediaSizeName findWin32Media(int dmIndex) { if (dmIndex >= 1 && dmIndex <= dmPaperToPrintService.length) { + return dmPaperToPrintService[dmIndex - 1]; + } switch(dmIndex) { /* matching media sizes with indices beyond dmPaperToPrintService's length */ case DMPAPER_A2: return MediaSizeName.ISO_A2; case DMPAPER_A6: return MediaSizeName.ISO_A6; case DMPAPER_B6_JIS: return MediaSizeName.JIS_B6; default: return null; } + } private boolean addToUniqueList(ArrayList msnList, MediaSizeName mediaName) { MediaSizeName msn; for (int i=0; i< msnList.size(); i++) { msn = (MediaSizeName)msnList.get(i);
*** 348,357 **** --- 336,346 ---- if (media == null) { return; } ArrayList msnList = new ArrayList(); + ArrayList<Win32MediaSize> trailingWmsList = new ArrayList<Win32MediaSize>(); ArrayList printableList = new ArrayList(); MediaSizeName mediaName; boolean added; boolean queryFailure = false; float[] prnArea;
*** 366,376 **** idList = new ArrayList(); for (int i=0; i < media.length; i++) { idList.add(Integer.valueOf(media[i])); } ! mediaSizes = getMediaSizes(idList, media); for (int i = 0; i < idList.size(); i++) { // match Win ID with our predefined ID using table mediaName = findWin32Media(((Integer)idList.get(i)).intValue()); // Verify that this standard size is the same size as that --- 355,366 ---- idList = new ArrayList(); for (int i=0; i < media.length; i++) { idList.add(Integer.valueOf(media[i])); } ! ArrayList<String> dmPaperNameList = new ArrayList<String>(); ! mediaSizes = getMediaSizes(idList, media, dmPaperNameList); for (int i = 0; i < idList.size(); i++) { // match Win ID with our predefined ID using table mediaName = findWin32Media(((Integer)idList.get(i)).intValue()); // Verify that this standard size is the same size as that
*** 385,405 **** --- 375,419 ---- Math.abs(win32Size.getY(1)-driverSize.getY(1)) > error) { mediaName = null; } } + boolean dmPaperIDMatched = (mediaName != null); // No match found, then we get the MediaSizeName out of the MediaSize // This requires 1-1 correspondence, lengths must be checked. if ((mediaName == null) && (idList.size() == mediaSizes.length)) { mediaName = mediaSizes[i].getMediaSizeName(); } // Add mediaName to the msnList + added = false; if (mediaName != null) { added = addToUniqueList(msnList, mediaName); } + if ((!dmPaperIDMatched || !added) && (idList.size() == dmPaperNameList.size())) { + /* The following block allows to add such media names to the list, whose sizes + * matched with media sizes predefined in JDK, while whose paper IDs did not, + * or whose sizes and paper IDs both did not match with any predefined in JDK. + */ + Win32MediaSize wms = Win32MediaSize.findMediaName(dmPaperNameList.get(i)); + if ((wms == null) && (idList.size() == mediaSizes.length)) { + wms = new Win32MediaSize(dmPaperNameList.get(i), (Integer)idList.get(i)); + mediaSizes[i] = new MediaSize(mediaSizes[i].getX(MediaSize.MM), + mediaSizes[i].getY(MediaSize.MM), MediaSize.MM, wms); + } + if ((wms != null) && (wms != mediaName)) { + if (!added) { + added = addToUniqueList(msnList, mediaName = wms); + } else { + trailingWmsList.add(wms); + } + } + } + } + for (Win32MediaSize wms : trailingWmsList) { + added = addToUniqueList(msnList, wms); } // init mediaSizeNames mediaSizeNames = new MediaSizeName[msnList.size()]; msnList.toArray(mediaSizeNames);
*** 586,596 **** } return null; } ! private MediaSize[] getMediaSizes(ArrayList idList, int[] media) { String prnPort = getPort(); int[] mediaSz = getAllMediaSizes(printer, prnPort); String[] winMediaNames = getAllMediaNames(printer, prnPort); MediaSizeName msn = null; MediaSize ms = null; --- 600,614 ---- } return null; } ! private MediaSize[] getMediaSizes(ArrayList idList, int[] media, ArrayList<String> dmPaperNameList) { ! if (dmPaperNameList == null) { ! dmPaperNameList = new ArrayList<String>(); ! } ! String prnPort = getPort(); int[] mediaSz = getAllMediaSizes(printer, prnPort); String[] winMediaNames = getAllMediaNames(printer, prnPort); MediaSizeName msn = null; MediaSize ms = null;
*** 625,648 **** ms = MediaSize.getMediaSizeForName(msn); } if (ms != null) { msList.add(ms); } else { ! Win32MediaSize wms = ! new Win32MediaSize(winMediaNames[i], media[i]); try { ms = new MediaSize(wid, ht, MediaSize.MM, wms); msList.add(ms); } catch(IllegalArgumentException e) { if (nMedia == media.length) { Integer remObj = Integer.valueOf(media[i]); idList.remove(idList.indexOf(remObj)); } } } - } MediaSize[] arr2 = new MediaSize[msList.size()]; msList.toArray(arr2); --- 643,669 ---- ms = MediaSize.getMediaSizeForName(msn); } if (ms != null) { msList.add(ms); + dmPaperNameList.add(winMediaNames[i]); } else { ! Win32MediaSize wms = Win32MediaSize.findMediaName(winMediaNames[i]); ! if (wms == null) { ! wms = new Win32MediaSize(winMediaNames[i], media[i]); ! } try { ms = new MediaSize(wid, ht, MediaSize.MM, wms); msList.add(ms); + dmPaperNameList.add(winMediaNames[i]); } catch(IllegalArgumentException e) { if (nMedia == media.length) { Integer remObj = Integer.valueOf(media[i]); idList.remove(idList.indexOf(remObj)); } } } } MediaSize[] arr2 = new MediaSize[msList.size()]; msList.toArray(arr2);
*** 1612,1621 **** --- 1633,1643 ---- class Win32MediaSize extends MediaSizeName { private static ArrayList winStringTable = new ArrayList(); private static ArrayList winEnumTable = new ArrayList(); + private static MediaSize[] predefMedia; private int dmPaperID; // driver ID for this paper. private Win32MediaSize(int x) { super(x);
*** 1625,1634 **** --- 1647,1668 ---- private synchronized static int nextValue(String name) { winStringTable.add(name); return (winStringTable.size()-1); } + public static synchronized Win32MediaSize findMediaName(String name) { + int nameIndex = winStringTable.indexOf(name); + if (nameIndex != -1) { + return (Win32MediaSize)winEnumTable.get(nameIndex); + } + return null; + } + + public static MediaSize[] getPredefMedia() { + return predefMedia; + } + public Win32MediaSize(String name, int dmPaper) { super(nextValue(name)); dmPaperID = dmPaper; winEnumTable.add(this); }
*** 1636,1657 **** private MediaSizeName[] getSuperEnumTable() { return (MediaSizeName[])super.getEnumValueTable(); } static { ! /* initialize Win32PrintService.predefMedia */ { Win32MediaSize winMedia = new Win32MediaSize(-1); // cannot call getSuperEnumTable directly because of static context MediaSizeName[] enumMedia = winMedia.getSuperEnumTable(); if (enumMedia != null) { ! Win32PrintService.predefMedia = new MediaSize[enumMedia.length]; for (int i=0; i<enumMedia.length; i++) { ! Win32PrintService.predefMedia[i] = ! MediaSize.getMediaSizeForName(enumMedia[i]); } } } } --- 1670,1690 ---- private MediaSizeName[] getSuperEnumTable() { return (MediaSizeName[])super.getEnumValueTable(); } static { ! /* initialize predefMedia */ { Win32MediaSize winMedia = new Win32MediaSize(-1); // cannot call getSuperEnumTable directly because of static context MediaSizeName[] enumMedia = winMedia.getSuperEnumTable(); if (enumMedia != null) { ! predefMedia = new MediaSize[enumMedia.length]; for (int i=0; i<enumMedia.length; i++) { ! predefMedia[i] = MediaSize.getMediaSizeForName(enumMedia[i]); } } } }