use of javax.print.DocFlavor in project jdk8u_jdk by JetBrains.
the class IPPPrintService method getSupportedDocFlavors.
public synchronized DocFlavor[] getSupportedDocFlavors() {
if (supportedDocFlavors != null) {
int len = supportedDocFlavors.length;
DocFlavor[] copyflavors = new DocFlavor[len];
System.arraycopy(supportedDocFlavors, 0, copyflavors, 0, len);
return copyflavors;
}
initAttributes();
if ((getAttMap != null) && getAttMap.containsKey("document-format-supported")) {
AttributeClass attribClass = (AttributeClass) getAttMap.get("document-format-supported");
if (attribClass != null) {
String mimeType;
boolean psSupported = false;
String[] docFlavors = attribClass.getArrayOfStringValues();
DocFlavor[] flavors;
HashSet docList = new HashSet();
int j;
String hostEnc = DocFlavor.hostEncoding.toLowerCase(Locale.ENGLISH);
boolean addHostEncoding = !hostEnc.equals("utf-8") && !hostEnc.equals("utf-16") && !hostEnc.equals("utf-16be") && !hostEnc.equals("utf-16le") && !hostEnc.equals("us-ascii");
for (int i = 0; i < docFlavors.length; i++) {
for (j = 0; j < allDocFlavors.length; j++) {
flavors = (DocFlavor[]) allDocFlavors[j];
mimeType = flavors[0].getMimeType();
if (mimeType.startsWith(docFlavors[i])) {
docList.addAll(Arrays.asList(flavors));
if (mimeType.equals("text/plain") && addHostEncoding) {
docList.add(Arrays.asList(textPlainHost));
} else if (mimeType.equals("text/html") && addHostEncoding) {
docList.add(Arrays.asList(textHtmlHost));
} else if (mimeType.equals("image/png")) {
pngImagesAdded = true;
} else if (mimeType.equals("image/gif")) {
gifImagesAdded = true;
} else if (mimeType.equals("image/jpeg")) {
jpgImagesAdded = true;
} else if (mimeType.indexOf("postscript") != -1) {
psSupported = true;
}
break;
}
}
// Not added? Create new DocFlavors
if (j == allDocFlavors.length) {
// make new DocFlavors
docList.add(new DocFlavor.BYTE_ARRAY(docFlavors[i]));
docList.add(new DocFlavor.INPUT_STREAM(docFlavors[i]));
docList.add(new DocFlavor.URL(docFlavors[i]));
}
}
// and Pageable/Printable flavors
if (psSupported || isCupsPrinter) {
/*
Always add Pageable and Printable for CUPS
since it uses Filters to convert from Postscript
to device printer language.
*/
docList.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
docList.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
docList.addAll(Arrays.asList(imageJPG));
docList.addAll(Arrays.asList(imagePNG));
docList.addAll(Arrays.asList(imageGIF));
}
supportedDocFlavors = new DocFlavor[docList.size()];
docList.toArray(supportedDocFlavors);
int len = supportedDocFlavors.length;
DocFlavor[] copyflavors = new DocFlavor[len];
System.arraycopy(supportedDocFlavors, 0, copyflavors, 0, len);
return copyflavors;
}
}
return null;
}
Aggregations