1 /*
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1329 flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1330 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
1331 !isIPPSupportedImages(flavor.getMimeType())) {
1332 return attr == Chromaticity.COLOR;
1333 } else {
1334 return false;
1335 }
1336 } else if (attr.getCategory() == Copies.class) {
1337 return (flavor == null ||
1338 !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
1339 flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
1340 flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
1341 isSupportedCopies((Copies)attr);
1342
1343 } else if (attr.getCategory() == Destination.class) {
1344 if (flavor == null ||
1345 flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1346 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
1347 URI uri = ((Destination)attr).getURI();
1348 if ("file".equals(uri.getScheme()) &&
1349 !(uri.getSchemeSpecificPart().equals(""))) {
1350 return true;
1351 }
1352 }
1353 return false;
1354 } else if (attr.getCategory() == Media.class) {
1355 if (attr instanceof MediaSizeName) {
1356 return isSupportedMedia((MediaSizeName)attr);
1357 }
1358 if (attr instanceof MediaTray) {
1359 return isSupportedMediaTray((MediaTray)attr);
1360 }
1361 } else if (attr.getCategory() == PageRanges.class) {
1362 if (flavor != null &&
1363 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1364 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
1365 return false;
1366 }
1367 } else if (attr.getCategory() == SheetCollate.class) {
1368 if (flavor != null &&
1369 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1486 } else if (category == Fidelity.class) {
1487 return Fidelity.FIDELITY_FALSE;
1488 } else if (category == Finishings.class) {
1489 return Finishings.NONE;
1490 } else if (category == JobName.class) {
1491 return new JobName("Java Printing", null);
1492 } else if (category == JobSheets.class) {
1493 if (attribClass != null &&
1494 attribClass.getStringValue().equals("none")) {
1495 return JobSheets.NONE;
1496 } else {
1497 return JobSheets.STANDARD;
1498 }
1499 } else if (category == Media.class) {
1500 if (defaultMediaIndex == -1) {
1501 defaultMediaIndex = 0;
1502 }
1503 if (mediaSizeNames.length == 0) {
1504 String defaultCountry = Locale.getDefault().getCountry();
1505 if (defaultCountry != null &&
1506 (defaultCountry.equals("") ||
1507 defaultCountry.equals(Locale.US.getCountry()) ||
1508 defaultCountry.equals(Locale.CANADA.getCountry()))) {
1509 return MediaSizeName.NA_LETTER;
1510 } else {
1511 return MediaSizeName.ISO_A4;
1512 }
1513 }
1514
1515 if (attribClass != null) {
1516 String name = attribClass.getStringValue();
1517 if (isCupsPrinter) {
1518 return mediaSizeNames[defaultMediaIndex];
1519 } else {
1520 for (int i=0; i< mediaSizeNames.length; i++) {
1521 if (mediaSizeNames[i].toString().indexOf(name) != -1) {
1522 defaultMediaIndex = i;
1523 return mediaSizeNames[defaultMediaIndex];
1524 }
1525 }
1526 }
1527 }
1528 return mediaSizeNames[defaultMediaIndex];
1529
1530 } else if (category == MediaPrintableArea.class) {
1531 MediaPrintableArea[] mpas;
1532 if ((cps != null) &&
1533 ((mpas = cps.getMediaPrintableArea()) != null)) {
1534 if (defaultMediaIndex == -1) {
1535 // initializes value of defaultMediaIndex
1536 getDefaultAttributeValue(Media.class);
1537 }
1538 return mpas[defaultMediaIndex];
1539 } else {
1540 String defaultCountry = Locale.getDefault().getCountry();
1541 float iw, ih;
1542 if (defaultCountry != null &&
1543 (defaultCountry.equals("") ||
1544 defaultCountry.equals(Locale.US.getCountry()) ||
1545 defaultCountry.equals(Locale.CANADA.getCountry()))) {
1546 iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 0.5f;
1547 ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 0.5f;
1548 } else {
1549 iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 0.5f;
1550 ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 0.5f;
1551 }
1552 return new MediaPrintableArea(0.25f, 0.25f, iw, ih,
1553 MediaPrintableArea.INCH);
1554 }
1555 } else if (category == NumberUp.class) {
1556 return new NumberUp(1); // for CUPS this is always 1
1557 } else if (category == OrientationRequested.class) {
1558 if (attribClass != null) {
1559 switch (attribClass.getIntValue()) {
1560 default:
1561 case 3: return OrientationRequested.PORTRAIT;
1562 case 4: return OrientationRequested.LANDSCAPE;
1563 case 5: return OrientationRequested.REVERSE_LANDSCAPE;
|
1 /*
2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1329 flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1330 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
1331 !isIPPSupportedImages(flavor.getMimeType())) {
1332 return attr == Chromaticity.COLOR;
1333 } else {
1334 return false;
1335 }
1336 } else if (attr.getCategory() == Copies.class) {
1337 return (flavor == null ||
1338 !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
1339 flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
1340 flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
1341 isSupportedCopies((Copies)attr);
1342
1343 } else if (attr.getCategory() == Destination.class) {
1344 if (flavor == null ||
1345 flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1346 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
1347 URI uri = ((Destination)attr).getURI();
1348 if ("file".equals(uri.getScheme()) &&
1349 !uri.getSchemeSpecificPart().isEmpty()) {
1350 return true;
1351 }
1352 }
1353 return false;
1354 } else if (attr.getCategory() == Media.class) {
1355 if (attr instanceof MediaSizeName) {
1356 return isSupportedMedia((MediaSizeName)attr);
1357 }
1358 if (attr instanceof MediaTray) {
1359 return isSupportedMediaTray((MediaTray)attr);
1360 }
1361 } else if (attr.getCategory() == PageRanges.class) {
1362 if (flavor != null &&
1363 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1364 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
1365 return false;
1366 }
1367 } else if (attr.getCategory() == SheetCollate.class) {
1368 if (flavor != null &&
1369 !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
1486 } else if (category == Fidelity.class) {
1487 return Fidelity.FIDELITY_FALSE;
1488 } else if (category == Finishings.class) {
1489 return Finishings.NONE;
1490 } else if (category == JobName.class) {
1491 return new JobName("Java Printing", null);
1492 } else if (category == JobSheets.class) {
1493 if (attribClass != null &&
1494 attribClass.getStringValue().equals("none")) {
1495 return JobSheets.NONE;
1496 } else {
1497 return JobSheets.STANDARD;
1498 }
1499 } else if (category == Media.class) {
1500 if (defaultMediaIndex == -1) {
1501 defaultMediaIndex = 0;
1502 }
1503 if (mediaSizeNames.length == 0) {
1504 String defaultCountry = Locale.getDefault().getCountry();
1505 if (defaultCountry != null &&
1506 (defaultCountry.isEmpty() ||
1507 defaultCountry.equals(Locale.US.getCountry()) ||
1508 defaultCountry.equals(Locale.CANADA.getCountry()))) {
1509 return MediaSizeName.NA_LETTER;
1510 } else {
1511 return MediaSizeName.ISO_A4;
1512 }
1513 }
1514
1515 if (attribClass != null) {
1516 String name = attribClass.getStringValue();
1517 if (isCupsPrinter) {
1518 return mediaSizeNames[defaultMediaIndex];
1519 } else {
1520 for (int i=0; i< mediaSizeNames.length; i++) {
1521 if (mediaSizeNames[i].toString().indexOf(name) != -1) {
1522 defaultMediaIndex = i;
1523 return mediaSizeNames[defaultMediaIndex];
1524 }
1525 }
1526 }
1527 }
1528 return mediaSizeNames[defaultMediaIndex];
1529
1530 } else if (category == MediaPrintableArea.class) {
1531 MediaPrintableArea[] mpas;
1532 if ((cps != null) &&
1533 ((mpas = cps.getMediaPrintableArea()) != null)) {
1534 if (defaultMediaIndex == -1) {
1535 // initializes value of defaultMediaIndex
1536 getDefaultAttributeValue(Media.class);
1537 }
1538 return mpas[defaultMediaIndex];
1539 } else {
1540 String defaultCountry = Locale.getDefault().getCountry();
1541 float iw, ih;
1542 if (defaultCountry != null &&
1543 (defaultCountry.isEmpty() ||
1544 defaultCountry.equals(Locale.US.getCountry()) ||
1545 defaultCountry.equals(Locale.CANADA.getCountry()))) {
1546 iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 0.5f;
1547 ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 0.5f;
1548 } else {
1549 iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 0.5f;
1550 ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 0.5f;
1551 }
1552 return new MediaPrintableArea(0.25f, 0.25f, iw, ih,
1553 MediaPrintableArea.INCH);
1554 }
1555 } else if (category == NumberUp.class) {
1556 return new NumberUp(1); // for CUPS this is always 1
1557 } else if (category == OrientationRequested.class) {
1558 if (attribClass != null) {
1559 switch (attribClass.getIntValue()) {
1560 default:
1561 case 3: return OrientationRequested.PORTRAIT;
1562 case 4: return OrientationRequested.LANDSCAPE;
1563 case 5: return OrientationRequested.REVERSE_LANDSCAPE;
|