javax.print.DocFlavor Java Examples

The following examples show how to use javax.print.DocFlavor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnixPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void initSupportedDocFlavors() {
    String hostEnc = DocFlavor.hostEncoding.toLowerCase(Locale.ENGLISH);
    if (!hostEnc.equals("utf-8") && !hostEnc.equals("utf-16") &&
        !hostEnc.equals("utf-16be") && !hostEnc.equals("utf-16le") &&
        !hostEnc.equals("us-ascii")) {

        int len = supportedDocFlavorsInit.length;
        DocFlavor[] flavors =
            new DocFlavor[len + supportedHostDocFlavors.length];
        // copy host encoding flavors
        System.arraycopy(supportedHostDocFlavors, 0, flavors,
                         len, supportedHostDocFlavors.length);
        System.arraycopy(supportedDocFlavorsInit, 0, flavors, 0, len);

        supportedDocFlavors = flavors;
    } else {
        supportedDocFlavors = supportedDocFlavorsInit;
    }
}
 
Example #2
Source File: Win32PrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public DocFlavor[] getSupportedDocFlavors() {
    int len = supportedFlavors.length;
    DocFlavor[] supportedDocFlavors;
    int caps = getPrinterCapabilities();
    // doc flavors supported
    // if PostScript is supported
    if ((caps & DEVCAP_POSTSCRIPT) != 0) {
        supportedDocFlavors = new DocFlavor[len+3];
        System.arraycopy(supportedFlavors, 0, supportedDocFlavors, 0, len);
        supportedDocFlavors[len] = DocFlavor.BYTE_ARRAY.POSTSCRIPT;
        supportedDocFlavors[len+1] = DocFlavor.INPUT_STREAM.POSTSCRIPT;
        supportedDocFlavors[len+2] = DocFlavor.URL.POSTSCRIPT;
    } else {
        supportedDocFlavors = new DocFlavor[len];
        System.arraycopy(supportedFlavors, 0, supportedDocFlavors, 0, len);
    }
    return supportedDocFlavors;
}
 
Example #3
Source File: Win32PrintService.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean isDocFlavorSupported(DocFlavor flavor) {
    /* To avoid a native query which may be time-consuming
     * do not invoke native unless postscript support is being queried.
     * Instead just check the ones we 'always' support
     */
    DocFlavor[] supportedDocFlavors;
    if (isPostScriptFlavor(flavor)) {
        supportedDocFlavors = getSupportedDocFlavors();
    } else {
        supportedDocFlavors = supportedFlavors;
    }
    for (int f=0; f<supportedDocFlavors.length; f++) {
        if (flavor.equals(supportedDocFlavors[f])) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: StreamPrintServiceFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static ArrayList getFactories(DocFlavor flavor, String outType) {

        if (flavor == null && outType == null) {
            return getAllFactories();
        }

        ArrayList list = new ArrayList();
        Iterator iterator = getAllFactories().iterator();
        while (iterator.hasNext()) {
            StreamPrintServiceFactory factory =
                (StreamPrintServiceFactory)iterator.next();
            if ((outType == null ||
                 outType.equalsIgnoreCase(factory.getOutputFormat())) &&
                (flavor == null ||
                 isMember(flavor, factory.getSupportedDocFlavors()))) {
                list.add(factory);
            }
        }

        return list;
    }
 
Example #5
Source File: StreamPrintServiceFactory.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private static ArrayList getFactories(DocFlavor flavor, String outType) {

        if (flavor == null && outType == null) {
            return getAllFactories();
        }

        ArrayList list = new ArrayList();
        Iterator iterator = getAllFactories().iterator();
        while (iterator.hasNext()) {
            StreamPrintServiceFactory factory =
                (StreamPrintServiceFactory)iterator.next();
            if ((outType == null ||
                 outType.equalsIgnoreCase(factory.getOutputFormat())) &&
                (flavor == null ||
                 isMember(flavor, factory.getSupportedDocFlavors()))) {
                list.add(factory);
            }
        }

        return list;
    }
 
Example #6
Source File: UnixPrintService.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void initSupportedDocFlavors() {
    String hostEnc = DocFlavor.hostEncoding.toLowerCase(Locale.ENGLISH);
    if (!hostEnc.equals("utf-8") && !hostEnc.equals("utf-16") &&
        !hostEnc.equals("utf-16be") && !hostEnc.equals("utf-16le") &&
        !hostEnc.equals("us-ascii")) {

        int len = supportedDocFlavorsInit.length;
        DocFlavor[] flavors =
            new DocFlavor[len + supportedHostDocFlavors.length];
        // copy host encoding flavors
        System.arraycopy(supportedHostDocFlavors, 0, flavors,
                         len, supportedHostDocFlavors.length);
        System.arraycopy(supportedDocFlavorsInit, 0, flavors, 0, len);

        supportedDocFlavors = flavors;
    } else {
        supportedDocFlavors = supportedDocFlavorsInit;
    }
}
 
Example #7
Source File: Win32PrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean isDocFlavorSupported(DocFlavor flavor) {
    /* To avoid a native query which may be time-consuming
     * do not invoke native unless postscript support is being queried.
     * Instead just check the ones we 'always' support
     */
    DocFlavor[] supportedDocFlavors;
    if (isPostScriptFlavor(flavor)) {
        supportedDocFlavors = getSupportedDocFlavors();
    } else {
        supportedDocFlavors = supportedFlavors;
    }
    for (int f=0; f<supportedDocFlavors.length; f++) {
        if (flavor.equals(supportedDocFlavors[f])) {
            return true;
        }
    }
    return false;
}
 
Example #8
Source File: PrintServiceStub.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #9
Source File: RasterPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected static PrintService lookupDefaultPrintService() {
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    /* Pageable implies Printable so checking both isn't strictly needed */
    if (service != null &&
        service.isDocFlavorSupported(
                            DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
        service.isDocFlavorSupported(
                            DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
        return service;
    } else {
       PrintService []services =
         PrintServiceLookup.lookupPrintServices(
                            DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
       if (services.length > 0) {
           return services[0];
       }
    }
    return null;
}
 
Example #10
Source File: PrinterOutputStream.java    From escpos-coffee with MIT License 6 votes vote down vote up
/**
 * creates one instance of PrinterOutputStream.
 * <p>
 * Create one print based on print service. Start print job linked (this)
 * output stream.
 *
 * @param printService value used to create the printer job
 * @exception IOException if an I/O error occurs.
 * @see #getPrintServiceByName(java.lang.String)
 * @see #getDefaultPrintService()
 */
public PrinterOutputStream(PrintService printService) throws IOException {

    UncaughtExceptionHandler uncaughtException = (Thread t, Throwable e) -> {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage(),e);
    };

    pipedInputStream = new PipedInputStream();
    super.connect(pipedInputStream);

    Runnable runnablePrint = () -> {
        try {
            DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE;
            Doc d = new SimpleDoc(pipedInputStream, df, null);

            DocPrintJob job = printService.createPrintJob();
            job.print(d, null);
        } catch (PrintException ex) {
            throw new RuntimeException(ex);
        }
    };

    threadPrint = new Thread(runnablePrint);
    threadPrint.setUncaughtExceptionHandler(uncaughtException);
    threadPrint.start();
}
 
Example #11
Source File: RasterPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected static PrintService lookupDefaultPrintService() {
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    /* Pageable implies Printable so checking both isn't strictly needed */
    if (service != null &&
        service.isDocFlavorSupported(
                            DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
        service.isDocFlavorSupported(
                            DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
        return service;
    } else {
       PrintService []services =
         PrintServiceLookup.lookupPrintServices(
                            DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
       if (services.length > 0) {
           return services[0];
       }
    }
    return null;
}
 
Example #12
Source File: Win32PrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isPostScriptFlavor(DocFlavor flavor) {
    if (flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT) ||
        flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
        flavor.equals(DocFlavor.URL.POSTSCRIPT)) {
        return true;
    }
    else {
        return false;
    }
}
 
Example #13
Source File: PrintServiceLookupProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public MultiDocPrintService[]
    getMultiDocPrintServices(DocFlavor[] flavors,
                             AttributeSet attributes) {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
      security.checkPrintJobAccess();
    }
    return new MultiDocPrintService[0];
}
 
Example #14
Source File: Win32PrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
                                             AttributeSet attributes) {

    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor +
                                           "is not supported");
    }

    if (attributes == null) {
        return null;
    }

    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute []attrs = attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            }
            else if (!isAttributeValueSupported(attr, flavor, attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
 
Example #15
Source File: Win32PrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isAutoSense(DocFlavor flavor) {
    if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
        flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
        flavor.equals(DocFlavor.URL.AUTOSENSE)) {
        return true;
    }
    else {
        return false;
    }
}
 
Example #16
Source File: UnixPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean isDocFlavorSupported(DocFlavor flavor) {
    if (supportedDocFlavors == null) {
        initSupportedDocFlavors();
    }
    for (int f=0; f<supportedDocFlavors.length; f++) {
        if (flavor.equals(supportedDocFlavors[f])) {
            return true;
        }
    }
    return false;
}
 
Example #17
Source File: RasterPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 2D printing or no longer available.
 */
public void setPrintService(PrintService service)
    throws PrinterException {
    if (service == null) {
        throw new PrinterException("Service cannot be null");
    } else if (!(service instanceof StreamPrintService) &&
               service.getName() == null) {
        throw new PrinterException("Null PrintService name.");
    } else {
        // Check the list of services.  This service may have been
        // deleted already
        PrinterState prnState = (PrinterState)service.getAttribute(
                                              PrinterState.class);
        if (prnState == PrinterState.STOPPED) {
            PrinterStateReasons prnStateReasons =
                (PrinterStateReasons)service.getAttribute(
                                             PrinterStateReasons.class);
            if ((prnStateReasons != null) &&
                (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
            {
                throw new PrinterException("PrintService is no longer available.");
            }
        }


        if (service.isDocFlavorSupported(
                                         DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
            service.isDocFlavorSupported(
                                         DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            myService = service;
        } else {
            throw new PrinterException("Not a 2D print service: " + service);
        }
    }
}
 
Example #18
Source File: IPPPrintService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
                                             AttributeSet attributes) {
    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor +
                                           "is not supported");
    }

    if (attributes == null) {
        return null;
    }

    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute []attrs = attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            } else if (!isAttributeValueSupported(attr, flavor,
                                                  attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
 
Example #19
Source File: PrintSEUmlauts.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example #20
Source File: UnixPrintService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
                                             AttributeSet attributes) {

    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor +
                                           "is not supported");
    }

    if (attributes == null) {
        return null;
    }

    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute []attrs = attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            } else if (!isAttributeValueSupported(attr, flavor,
                                                  attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
 
Example #21
Source File: Win32PrintService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
                                             AttributeSet attributes) {

    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor +
                                           "is not supported");
    }

    if (attributes == null) {
        return null;
    }

    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute []attrs = attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            }
            else if (!isAttributeValueSupported(attr, flavor, attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
 
Example #22
Source File: UnixPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isAutoSense(DocFlavor flavor) {
    if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
        flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
        flavor.equals(DocFlavor.URL.AUTOSENSE)) {
        return true;
    }
    else {
        return false;
    }
}
 
Example #23
Source File: IPPPrintService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isAutoSense(DocFlavor flavor) {
    if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
        flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
        flavor.equals(DocFlavor.URL.AUTOSENSE)) {
        return true;
    }
    else {
        return false;
    }
}
 
Example #24
Source File: UnixPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
                                             AttributeSet attributes) {

    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor +
                                           "is not supported");
    }

    if (attributes == null) {
        return null;
    }

    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute []attrs = attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            } else if (!isAttributeValueSupported(attr, flavor,
                                                  attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
 
Example #25
Source File: IPPPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
                                             AttributeSet attributes) {
    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor +
                                           "is not supported");
    }

    if (attributes == null) {
        return null;
    }

    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute []attrs = attributes.toArray();
    for (int i=0; i<attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            } else if (!isAttributeValueSupported(attr, flavor,
                                                  attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
 
Example #26
Source File: IPPPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean isDocFlavorSupported(DocFlavor flavor) {
    if (supportedDocFlavors == null) {
        getSupportedDocFlavors();
    }
    if (supportedDocFlavors != null) {
        for (int f=0; f<supportedDocFlavors.length; f++) {
            if (flavor.equals(supportedDocFlavors[f])) {
                return true;
            }
        }
    }
    return false;
}
 
Example #27
Source File: IPPPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isAutoSense(DocFlavor flavor) {
    if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
        flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
        flavor.equals(DocFlavor.URL.AUTOSENSE)) {
        return true;
    }
    else {
        return false;
    }
}
 
Example #28
Source File: IPPPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean
    isDestinationSupported(DocFlavor flavor, AttributeSet attributes) {

        if ((attributes != null) &&
                (attributes.get(Destination.class) != null) &&
                !(flavor == null ||
                  flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
                  flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
            return false;
        }
        return true;
}
 
Example #29
Source File: PrintServiceLookupProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public MultiDocPrintService[]
    getMultiDocPrintServices(DocFlavor[] flavors,
                             AttributeSet attributes) {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
      security.checkPrintJobAccess();
    }
    return new MultiDocPrintService[0];
}
 
Example #30
Source File: PrintServiceLookupProvider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public MultiDocPrintService[]
    getMultiDocPrintServices(DocFlavor[] flavors,
                             AttributeSet attributes) {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
      security.checkPrintJobAccess();
    }
    return new MultiDocPrintService[0];
}