Example usage for java.awt Font createFont

List of usage examples for java.awt Font createFont

Introduction

In this page you can find the example usage for java.awt Font createFont.

Prototype

public static Font createFont(int fontFormat, File fontFile)
        throws java.awt.FontFormatException, java.io.IOException 

Source Link

Document

Returns a new Font using the specified font type and the specified font file.

Usage

From source file:org.lnicholls.galleon.server.Server.java

private void preLoadFonts() {
    if (log.isDebugEnabled())
        log.debug("preLoadFonts()");
    try {/* ww w.  j  a  va 2s. com*/
        Font.createFont(Font.TRUETYPE_FONT, Server.class.getClassLoader().getResourceAsStream(
                ScrollText.class.getPackage().getName().replace('.', '/') + "/" + "default.ttf"));
    } catch (Throwable e) {
    }
}

From source file:abfab3d.shapejs.ShapeJSGlobal.java

/**
 * js function to load a font/*from   w  ww .j  a va  2  s . co m*/
 * returns BufferedImage
 */
public static Object loadFont(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
    if (args.length < 1) {
        throw Context.reportRuntimeError("loadFont() requires one filename.");
    }

    String filename = Context.toString(args[0]);

    if (filename == null || filename.length() == 0) {
        throw Context.reportRuntimeError("No file provided for loadFont() command");
    }

    printf("loading font file: %s\n", filename);

    String reason = null;

    File f = new File(filename);
    Font font = null;
    if (!f.exists()) {
        throw Context.reportRuntimeError(fmt("Cannot find font file: %s\n", f.getAbsoluteFile()));
    }

    if (f.length() > 800000) {
        // Bit of security thought here, font's should not be too large unless they contain some malware payload
        throw Context.reportRuntimeError(fmt("Font file too large"));
    }
    try {
        int type = Font.TRUETYPE_FONT;
        if (filename.indexOf(".ttf") == -1)
            type = Font.TYPE1_FONT;
        font = Font.createFont(type, f);
    } catch (Exception e) {
        reason = e.getMessage();
        e.printStackTrace();
    }
    if (font == null) {
        throw Context.reportRuntimeError(fmt("failed to load font file: %s.  Reason: %s\n", filename, reason));
    }

    return font;
}

From source file:org.jtrfp.trcl.core.ResourceManager.java

public Font getFont(String zipName, String fontFileName) {
    try {/*from ww w.  j av  a  2  s .  com*/
        zipName = "/fonts/" + zipName;
        if (zipName.toUpperCase().endsWith(".ZIP")) {// Search the zip
            ZipInputStream zip = new ZipInputStream(ResourceManager.class.getResourceAsStream(zipName));
            ZipEntry entry;

            while ((entry = zip.getNextEntry()) != null) {
                System.out.println("ZIP ENTRY: " + entry.getName());
                if (entry.getName().toUpperCase().endsWith(fontFileName.toUpperCase())) {
                    Font font = Font.createFont(Font.TRUETYPE_FONT, zip);
                    zip.closeEntry();
                    zip.close();
                    return font;
                }
            } // end while(elements)
        } // end if(zip)
        else {
        } // TODO: Handle non-zipped fonts?
    } catch (Exception e) {
        tr.showStopper(e);
    }
    return null;
}

From source file:org.yccheok.jstock.gui.Utils.java

private static Font _getRobotoLightFont() {
    InputStream inputStream = Utils.class.getResourceAsStream("/assets/fonts/Roboto-Light.ttf");
    try {//from w  ww. j  a va2s  .co m
        Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
        if (font != null) {
            return font;
        }
    } catch (FontFormatException ex) {
        log.error(null, ex);
    } catch (IOException ex) {
        log.error(null, ex);
    } finally {
        org.yccheok.jstock.file.Utils.close(inputStream);
    }
    Font oldLabelFont = UIManager.getFont("Label.font");
    return oldLabelFont;
}