Search in sources :

Example 1 with BMFontUtil

use of com.badlogic.gdx.tools.hiero.BMFontUtil in project gdx-skineditor by cobolfoo.

the class NewFontDialog method refreshFontPreview.

/**
	 * 
	 */
public void refreshFontPreview() {
    try {
        String fontName = selectFonts.getSelected();
        Gdx.app.log("FontPickerDialog", "Refreshing preview for font: " + fontName);
        File fontPath = game.fm.fonts.get(selectFonts.getSelected());
        Gdx.app.log("FontPickerDialog", "Loading font from file:" + fontPath);
        Font font = Font.createFont(Font.TRUETYPE_FONT, fontPath);
        UnicodeFont unicodeFont = new UnicodeFont(font, Integer.valueOf(selectSize.getSelected()), checkBold.isChecked(), checkItalic.isChecked());
        if (checkShadow.isChecked() == true) {
            ColorEffect colorEffect = new ColorEffect();
            colorEffect.setColor(java.awt.Color.BLACK);
            unicodeFont.getEffects().add(colorEffect);
            ShadowEffect shadow = new ShadowEffect();
            shadow.setOpacity(1.0f);
            shadow.setXDistance(1);
            shadow.setYDistance(1);
            shadow.setColor(java.awt.Color.WHITE);
            unicodeFont.getEffects().add(shadow);
        } else {
            ColorEffect colorEffect = new ColorEffect();
            colorEffect.setColor(java.awt.Color.WHITE);
            unicodeFont.getEffects().add(colorEffect);
        }
        unicodeFont.addAsciiGlyphs();
        String newFontName = generateProperFontName(fontName);
        textFontName.setText(newFontName);
        // Create bitmap font
        BMFontUtil bfu = new BMFontUtil(unicodeFont);
        FileHandle handle = new FileHandle(System.getProperty("java.io.tmpdir")).child(newFontName);
        FileHandle handleFont = new FileHandle(handle.file().getAbsolutePath() + ".fnt");
        bfu.save(handle.file());
        FileHandle handleImage = new FileHandle(System.getProperty("java.io.tmpdir")).child(newFontName + ".png");
        TextField.TextFieldStyle textStyle = new TextField.TextFieldStyle();
        textStyle.cursor = game.skin.getDrawable("cursor");
        textStyle.selection = game.skin.getDrawable("selection");
        textStyle.background = game.skin.getDrawable("textfield");
        textStyle.fontColor = Color.YELLOW;
        textStyle.font = new BitmapFont(handleFont, handleImage, false);
        textFontPreview.setStyle(textStyle);
        // Have to do this to force clipping of font
        textFontPreview.setText(textFontPreview.getText());
    } catch (Exception e) {
        e.printStackTrace();
        textFontPreview.getStyle().font = game.skin.getFont("default-font");
        // Have to do this to force clipping of font
        textFontPreview.setText(textFontPreview.getText());
    }
}
Also used : UnicodeFont(com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont) FileHandle(com.badlogic.gdx.files.FileHandle) Font(java.awt.Font) UnicodeFont(com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ColorEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ColorEffect) ShadowEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ShadowEffect) BMFontUtil(com.badlogic.gdx.tools.hiero.BMFontUtil) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) File(java.io.File)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 BMFontUtil (com.badlogic.gdx.tools.hiero.BMFontUtil)1 UnicodeFont (com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont)1 ColorEffect (com.badlogic.gdx.tools.hiero.unicodefont.effects.ColorEffect)1 ShadowEffect (com.badlogic.gdx.tools.hiero.unicodefont.effects.ShadowEffect)1 Font (java.awt.Font)1 File (java.io.File)1