Search in sources :

Example 11 with DocFlavor

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;
}
Also used : DocFlavor(javax.print.DocFlavor) HashSet(java.util.HashSet)

Aggregations

DocFlavor (javax.print.DocFlavor)11 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 PrintService (javax.print.PrintService)4 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)4 DocPrintJob (javax.print.DocPrintJob)3 PrintException (javax.print.PrintException)3 SimpleDoc (javax.print.SimpleDoc)3 StreamPrintServiceFactory (javax.print.StreamPrintServiceFactory)3 java.awt.print (java.awt.print)2 BufferedInputStream (java.io.BufferedInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 URL (java.net.URL)2 StreamPrintService (javax.print.StreamPrintService)2 PrinterIsAcceptingJobs (javax.print.attribute.standard.PrinterIsAcceptingJobs)2 BufferedImage (java.awt.image.BufferedImage)1 PageFormat (java.awt.print.PageFormat)1 Printable (java.awt.print.Printable)1 PrinterException (java.awt.print.PrinterException)1