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:Main.java

public static void main(String[] a) throws Exception {
    String fName = "/fonts/A.ttf";
    InputStream is = Main.class.getResourceAsStream(fName);
    Font font = Font.createFont(Font.TRUETYPE_FONT, is);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fontFileName = "yourfont.ttf";
    InputStream is = new FileInputStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(Font.BOLD);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fontFileName = "yourfont.ttf";
    InputStream is = new FileInputStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(Font.PLAIN, 24);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fontFileName = "yourfont.ttf";
    InputStream is = new FileInputStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(24F);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fontFileName = "yourfont.ttf";
    InputStream is = new FileInputStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(Font.BOLD, AffineTransform.getRotateInstance(0.5));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fontFileName = "yourfont.ttf";
    InputStream is = new FileInputStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(AffineTransform.getRotateInstance(0.5));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("your.ttf");
    FileInputStream in = new FileInputStream(f);
    Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in);
    Font dynamicFont32Pt = dynamicFont.deriveFont(32f);

    JLabel testLabel = new JLabel(dynamicFont.getName());
    testLabel.setFont(dynamicFont32Pt);/* w w  w. j  av a  2 s  . c om*/
    JFrame frame = new JFrame("Font Loading Demo");
    frame.getContentPane().add(testLabel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    File f = new File("your.ttf");
    FileInputStream in = new FileInputStream(f);
    Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in);
    Font dynamicFont32Pt = dynamicFont.deriveFont(32f);

    JLabel testLabel = new JLabel("Dynamically loaded font \"" + dynamicFont.getName() + "\"");
    testLabel.setFont(dynamicFont32Pt);/*from   w w w . j a va 2 s. co  m*/
    JFrame frame = new JFrame("Font Loading Demo");
    frame.getContentPane().add(testLabel);
    frame.pack();
    frame.setVisible(true);
}

From source file:com.vitco.Main.java

public static void main(String[] args) throws Exception {
    // display version number on splash screen
    final SplashScreen splash = SplashScreen.getSplashScreen();
    if (splash != null) {
        Graphics2D g = splash.createGraphics();
        if (g != null) {
            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
            Font font = Font
                    .createFont(Font.TRUETYPE_FONT,
                            new SaveResourceLoader("resource/font/arcade.ttf").asInputStream())
                    .deriveFont(Font.PLAIN, 42f);
            g.setFont(font);//from w  ww. j  a  v  a  2 s .  c  o m
            //g.setFont(g.getFont().deriveFont(9f));
            g.setColor(VitcoSettings.SPLASH_SCREEN_OVERLAY_TEXT_COLOR);
            int width = g.getFontMetrics().stringWidth(VitcoSettings.VERSION_ID);
            g.drawString(VitcoSettings.VERSION_ID, 400 - 20 - width, 110);
            splash.update();
            g.dispose();
        }
    }

    // the JIDE license
    SaveResourceLoader saveResourceLoader = new SaveResourceLoader("resource/jidelicense.txt");
    if (!saveResourceLoader.error) {
        String[] jidelicense = saveResourceLoader.asLines();
        if (jidelicense.length == 3) {
            com.jidesoft.utils.Lm.verifyLicense(jidelicense[0], jidelicense[1], jidelicense[2]);
        }
    }

    // check if we are in debug mode
    if ((args.length > 0) && args[0].equals("debug")) {
        ErrorHandler.setDebugMode();
        debug = true;
    }

    // build the application
    final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
            "com/vitco/glue/config.xml");

    // for debugging
    if (debug) {
        ((ActionManager) context.getBean("ActionManager")).performValidityCheck();
        ((ComplexActionManager) context.getBean("ComplexActionManager")).performValidityCheck();
    }

    // open vsd file when program is started with "open with"
    MainMenuLogic mainMenuLogic = ((MainMenuLogic) context.getBean("MainMenuLogic"));
    for (String arg : args) {
        if (arg.endsWith(".vsd")) {
            File file = new File(arg);
            if (file.exists() && !file.isDirectory()) {
                mainMenuLogic.openFile(file);
                break;
            }
        }
    }

    // perform shortcut check
    ((ShortcutManager) context.getBean("ShortcutManager")).doSanityCheck(debug);
    //        // test console
    //        final Console console = ((Console) context.getBean("Console"));
    //        new Thread() {
    //            public void run() {
    //                while (true) {
    //                    console.addLine("text");
    //                    try {
    //                        sleep(2000);
    //                    } catch (InterruptedException e) {
    //                       //e.printStackTrace();
    //                    }
    //                }
    //            }
    //        }.start();

    // add a shutdown hook
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            // make reference so Preferences object doesn't get destroyed
            Preferences pref = ((Preferences) context.getBean("Preferences"));
            // trigger @PreDestroy
            context.close();
            // store the preferences (this needs to be done here, b/c
            // some PreDestroys are used to store preferences!)
            pref.save();
        }
    });
}

From source file:pl.mcpg.brainfuckjava.Start.java

public static void main(String[] args) {
    System.out.println("Detected language is " + userLocale.toString() + ".");
    switch (userLocale.toString()) {
    case "pl_PL":
        loadLanguage("pl");
        break;//from   w  w  w  . j av a  2s . co  m
    default:
        loadLanguage("en");
        break;
    }
    Config.load();
    try {
        spacemonoFont = Font.createFont(Font.TRUETYPE_FONT,
                Start.class.getResourceAsStream("/fonts/spacemono.ttf"));
    } catch (FontFormatException | IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    if (args.length == 0) // if there are no args, just run GUI.
    {
        runGUI();
        return;
    }

    Options options = new Options();
    Option forceLangOption = new Option("l", "forcelang", true, getText("forcelangCli"));
    forceLangOption.setArgName("language");
    Option interactiveOption = new Option("i", "intercml", false, getText("interactiveCli"));
    Option runOption = new Option("r", "run", true, getText("runCli"));
    runOption.setArgs(1);
    Option displayNumbersOption = new Option("n", "displayint", false, getText("dnmCli"));
    Option helpOption = new Option("h", "help", false, getText("helpCli"));
    options.addOption(forceLangOption);
    options.addOption(interactiveOption);
    options.addOption(runOption);
    options.addOption(displayNumbersOption);
    options.addOption(helpOption);

    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('l')) {
            boolean found = true;
            switch (commandLine.getOptionValue('l')) {
            case "pl":
                loadLanguage("pl");
                break;
            case "en":
                loadLanguage("en");
                break;
            default:
                System.err.println(getText("forcedLangNotFound", commandLine.getOptionValue('l')));
                found = false;
                break;
            }
            if (found) {
                System.out.println(getText("forcedLang", commandLine.getOptionValue('l')));
            }
        }
        if (commandLine.hasOption('h')) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar brainfuck.java.jar [-h] [-n] [-i] [-r {file}]",
                    "Brainfuck.java command line options", options,
                    "Issues? Report them on https://github.com/MCPlayG/Brainfuck.java/issues!");
            System.exit(0);
        }
        if (commandLine.hasOption('n')) {
            numberDisplayMode = true;
        }
        if (commandLine.hasOption('i')) {
            new InteractiveCommandLine().run();
            System.exit(0);
        }
        if (commandLine.hasOption('r')) {
            run(new File(commandLine.getOptionValue('r')));
            System.exit(0);
        }
    } catch (ParseException e) {
        System.err.println(getText("parseCliError"));
        e.printStackTrace();
        runGUI();
    }
    runGUI();
}