--- old/src/windows/classes/sun/print/Win32PrintService.java 2013-02-08 18:28:55.959377300 +0400 +++ new/src/windows/classes/sun/print/Win32PrintService.java 2013-02-08 18:28:55.447377300 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -28,11 +28,8 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; - -import java.util.Vector; +import java.util.ArrayList; import java.util.HashMap; - import javax.print.DocFlavor; import javax.print.DocPrintJob; import javax.print.PrintService; @@ -69,13 +66,9 @@ 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 { @@ -310,7 +303,9 @@ public MediaSizeName findWin32Media(int dmIndex) { if (dmIndex >= 1 && dmIndex <= dmPaperToPrintService.length) { - switch(dmIndex) { + return dmPaperToPrintService[dmIndex - 1]; + } + switch(dmIndex) { /* matching media sizes with indices beyond dmPaperToPrintService's length */ case DMPAPER_A2: @@ -320,11 +315,8 @@ case DMPAPER_B6_JIS: return MediaSizeName.JIS_B6; default: - return dmPaperToPrintService[dmIndex - 1]; - } + return null; } - - return null; } private boolean addToUniqueList(ArrayList msnList, MediaSizeName mediaName) { @@ -368,7 +360,8 @@ idList.add(Integer.valueOf(media[i])); } - mediaSizes = getMediaSizes(idList, media); + ArrayList dmPaperNameList = new ArrayList(); + mediaSizes = getMediaSizes(idList, media, dmPaperNameList); for (int i = 0; i < idList.size(); i++) { // match Win ID with our predefined ID using table @@ -397,6 +390,21 @@ // Add mediaName to the msnList if (mediaName != null) { added = addToUniqueList(msnList, mediaName); + /* 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. + */ + if (!added && (idList.size() == dmPaperNameList.size())) { + 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) { + mediaName = wms; + added = addToUniqueList(msnList, mediaName); + } + } } } @@ -588,7 +596,11 @@ } - private MediaSize[] getMediaSizes(ArrayList idList, int[] media) { + private MediaSize[] getMediaSizes(ArrayList idList, int[] media, ArrayList dmPaperNameList) { + if (dmPaperNameList == null) { + dmPaperNameList = new ArrayList(); + } + String prnPort = getPort(); int[] mediaSz = getAllMediaSizes(printer, prnPort); String[] winMediaNames = getAllMediaNames(printer, prnPort); @@ -607,40 +619,43 @@ wid = mediaSz[i*2]/10f; ht = mediaSz[i*2+1]/10f; - // Make sure to validate wid & ht. - // HP LJ 4050 (german) causes IAE in Sonderformat paper, wid & ht - // returned is not constant. - if ((wid <= 0) || (ht <= 0)) { - //Remove corresponding ID from list - if (nMedia == media.length) { - Integer remObj = Integer.valueOf(media[i]); - idList.remove(idList.indexOf(remObj)); + // Make sure to validate wid & ht. + // HP LJ 4050 (german) causes IAE in Sonderformat paper, wid & ht + // returned is not constant. + if ((wid <= 0) || (ht <= 0)) { + //Remove corresponding ID from list + if (nMedia == media.length) { + Integer remObj = Integer.valueOf(media[i]); + idList.remove(idList.indexOf(remObj)); + } + continue; } - continue; - } - // Find matching media using dimensions. - // This call matches only with our own predefined sizes. - msn = findMatchingMediaSizeNameMM(wid, ht); - if (msn != null) { - 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)); - } + // Find matching media using dimensions. + // This call matches only with our own predefined sizes. + msn = findMatchingMediaSizeNameMM(wid, ht); + if (msn != null) { + 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()]; @@ -1627,6 +1642,14 @@ 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 Win32MediaSize(String name, int dmPaper) { super(nextValue(name)); dmPaperID = dmPaper;