package fileIO.fonts;

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.io.InputStream;

import javax.swing.JOptionPane;

/*  ------------- Nihilne ------------
    * Created by Mitch Weaver - 2016 *
      ~~~~ All Rights Reserved ~~~~ */

public class fonts {

	// fall back font if init() fails
	public static Font fallbackFont = new Font("serif", Font.PLAIN, 14);

	public static Font GregorianBase = new Font("serif", Font.PLAIN, 24);
	public static Font Gregorian10 = new Font("serif", Font.PLAIN, 8);
	public static Font Gregorian20 = new Font("serif", Font.PLAIN, 24);
	public static Font Gregorian20Bold = new Font("serif", Font.BOLD, 24);
	public static Font Gregorian26 = new Font("serif", Font.PLAIN, 24);
	public static Font Gregorian32Bold = new Font("serif", Font.BOLD, 32);
	public static Font Gregorian48Bold = new Font("serif", Font.BOLD, 32);

	public static Font ponderosaBase = new Font("serif", Font.PLAIN, 12);
	public static Font ponderosa20 = new Font("serif", Font.PLAIN, 12); /* is actaully 10 */
	public static Font ponderosa8 = new Font("serif", Font.PLAIN, 12);

	public synchronized static void init() {
		try {
			InputStream is1 = fonts.class.getResourceAsStream("/gregorian.ttf");
			InputStream is2 = fonts.class.getResourceAsStream("/ponderosa.ttf");
			GregorianBase = Font.createFont(Font.TRUETYPE_FONT, is1);
			Gregorian10 = GregorianBase.deriveFont(Font.BOLD, 11.0f);
			Gregorian26 = GregorianBase.deriveFont(26.0f);
			Gregorian20 = GregorianBase.deriveFont(20.0f);
			Gregorian20Bold = GregorianBase.deriveFont(Font.BOLD, 20.0f);
			Gregorian32Bold = GregorianBase.deriveFont(Font.BOLD, 32);
			Gregorian48Bold = GregorianBase.deriveFont(Font.BOLD, 48);

			ponderosaBase = Font.createFont(Font.TRUETYPE_FONT, is2);
			ponderosa20 = ponderosaBase.deriveFont(Font.BOLD, 10.0f);
			ponderosa8 = ponderosaBase.deriveFont(Font.ITALIC, 8.0f);
			GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
			ge.registerFont(Gregorian10);
			ge.registerFont(Gregorian20);
			ge.registerFont(Gregorian20Bold);
			ge.registerFont(Gregorian26);
			ge.registerFont(Gregorian32Bold);
			ge.registerFont(Gregorian48Bold);
			ge.registerFont(ponderosa20);
			ge.registerFont(ponderosa8);
			is1.close();
			is2.close();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "Some fonts failed to load, using fall back font.");
			GregorianBase = Gregorian20 = Gregorian10 = Gregorian20Bold = Gregorian26 = Gregorian32Bold = Gregorian48Bold = ponderosaBase = ponderosa20 = ponderosa8 = fallbackFont;
			return;
		}
	}
}
