< prev index next >

src/java.desktop/unix/classes/sun/print/CUPSPrinter.java

Print this page

208 
209         cupsMediaPrintables = new MediaPrintableArea[nPageSizes];
210         cupsMediaSNames = new MediaSizeName[nPageSizes];
211         cupsCustomMediaSNames = new CustomMediaSizeName[nPageSizes];
212 
213         CustomMediaSizeName msn;
214         MediaPrintableArea mpa;
215         float length, width, x, y, w, h;
216 
217         // initialize names and printables
218         for (int i=0; i<nPageSizes; i++) {
219             // media width and length
220             width = (float)(pageSizes[i*6]/PRINTER_DPI);
221             length = (float)(pageSizes[i*6+1]/PRINTER_DPI);
222             // media printable area
223             x = (float)(pageSizes[i*6+2]/PRINTER_DPI);
224             h = (float)(pageSizes[i*6+3]/PRINTER_DPI);
225             w = (float)(pageSizes[i*6+4]/PRINTER_DPI);
226             y = (float)(pageSizes[i*6+5]/PRINTER_DPI);
227 
228             msn = new CustomMediaSizeName(media[i*2], media[i*2+1],
229                                           width, length);
230 
231             // add to list of standard MediaSizeNames
232             if ((cupsMediaSNames[i] = msn.getStandardMedia()) == null) {
233                 // add custom if no matching standard media
234                 cupsMediaSNames[i] = msn;
235 
236                 // add this new custom msn to MediaSize array
237                 if ((width > 0.0) && (length > 0.0)) {
238                     try {
239                     new MediaSize(width, length,
240                                   Size2DSyntax.INCH, msn);
241                     } catch (IllegalArgumentException e) {
242                         /* PDF printer in Linux for Ledger paper causes
243                         "IllegalArgumentException: X dimension > Y dimension".
244                         We rotate based on IPP spec. */
245                         new MediaSize(length, width, Size2DSyntax.INCH, msn);
246                     }
247                 }
248             }
249 
250             // add to list of custom MediaSizeName
251             // for internal use of IPPPrintService
252             cupsCustomMediaSNames[i] = msn;
253 
254             mpa = null;
255             try {
256                 mpa = new MediaPrintableArea(x, y, w, h,
257                                              MediaPrintableArea.INCH);
258             } catch (IllegalArgumentException e) {
259                 if (width > 0 && length > 0) {
260                     mpa = new MediaPrintableArea(0, 0, width, length,
261                                              MediaPrintableArea.INCH);
262                 }
263             }
264             cupsMediaPrintables[i] = mpa;
265         }
266 
267         // initialize trays
268         cupsMediaTrays = new MediaTray[nTrays];
269 
270         MediaTray mt;
271         for (int i=0; i<nTrays; i++) {
272             mt = new CustomMediaTray(media[(nPageSizes+i)*2],
273                                      media[(nPageSizes+i)*2+1]);
274             cupsMediaTrays[i] = mt;
275         }
276 
277     }
278 
279     /**
280      * Get CUPS default printer using IPP.
281      * Returns 2 values - index 0 is printer name, index 1 is the uri.
282      */
283     static String[] getDefaultPrinter() {
284         // Try to get user/lpoptions-defined printer name from CUPS
285         // if not user-set, then go for server default destination
286         String[] printerInfo = new String[2];
287         printerInfo[0] = getCupsDefaultPrinter();
288 
289         if (printerInfo[0] != null) {
290             printerInfo[1] = null;
291             return printerInfo.clone();
292         }
293         try {

208 
209         cupsMediaPrintables = new MediaPrintableArea[nPageSizes];
210         cupsMediaSNames = new MediaSizeName[nPageSizes];
211         cupsCustomMediaSNames = new CustomMediaSizeName[nPageSizes];
212 
213         CustomMediaSizeName msn;
214         MediaPrintableArea mpa;
215         float length, width, x, y, w, h;
216 
217         // initialize names and printables
218         for (int i=0; i<nPageSizes; i++) {
219             // media width and length
220             width = (float)(pageSizes[i*6]/PRINTER_DPI);
221             length = (float)(pageSizes[i*6+1]/PRINTER_DPI);
222             // media printable area
223             x = (float)(pageSizes[i*6+2]/PRINTER_DPI);
224             h = (float)(pageSizes[i*6+3]/PRINTER_DPI);
225             w = (float)(pageSizes[i*6+4]/PRINTER_DPI);
226             y = (float)(pageSizes[i*6+5]/PRINTER_DPI);
227 
228             msn = CustomMediaSizeName.create(media[i*2], media[i*2+1],
229                                              width, length);
230 
231             // add to list of standard MediaSizeNames
232             if ((cupsMediaSNames[i] = msn.getStandardMedia()) == null) {
233                 // add custom if no matching standard media
234                 cupsMediaSNames[i] = msn;













235             }
236 
237             // add to list of custom MediaSizeName
238             // for internal use of IPPPrintService
239             cupsCustomMediaSNames[i] = msn;
240 
241             mpa = null;
242             try {
243                 mpa = new MediaPrintableArea(x, y, w, h,
244                                              MediaPrintableArea.INCH);
245             } catch (IllegalArgumentException e) {
246                 if (width > 0 && length > 0) {
247                     mpa = new MediaPrintableArea(0, 0, width, length,
248                                              MediaPrintableArea.INCH);
249                 }
250             }
251             cupsMediaPrintables[i] = mpa;
252         }
253 
254         // initialize trays
255         cupsMediaTrays = new MediaTray[nTrays];
256 
257         MediaTray mt;
258         for (int i=0; i<nTrays; i++) {
259             mt = CustomMediaTray.create(media[(nPageSizes+i)*2],
260                                         media[(nPageSizes+i)*2+1]);
261             cupsMediaTrays[i] = mt;
262         }
263 
264     }
265 
266     /**
267      * Get CUPS default printer using IPP.
268      * Returns 2 values - index 0 is printer name, index 1 is the uri.
269      */
270     static String[] getDefaultPrinter() {
271         // Try to get user/lpoptions-defined printer name from CUPS
272         // if not user-set, then go for server default destination
273         String[] printerInfo = new String[2];
274         printerInfo[0] = getCupsDefaultPrinter();
275 
276         if (printerInfo[0] != null) {
277             printerInfo[1] = null;
278             return printerInfo.clone();
279         }
280         try {
< prev index next >