Search in sources :

Example 1 with UnicodeFont

use of com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont in project libgdx by libgdx.

the class Hiero method updateFont.

void updateFont() {
    int fontSize = ((Integer) fontSizeSpinner.getValue()).intValue();
    File file = null;
    if (fontFileRadio.isSelected()) {
        file = new File(fontFileText.getText());
        if (!file.exists() || !file.isFile())
            file = null;
    }
    boolean isFreeType = freeTypeRadio.isSelected();
    boolean isNative = nativeRadio.isSelected();
    boolean isJava = javaRadio.isSelected();
    addEffectButton.setVisible(isJava);
    effectsScroll.setVisible(isJava);
    appliedEffectsScroll.setVisible(isJava);
    boldCheckBox.setEnabled(!isFreeType);
    italicCheckBox.setEnabled(!isFreeType);
    bitmapPanel.setVisible(isFreeType);
    unicodePanel.setVisible(!isFreeType);
    updateFontSelector();
    UnicodeFont unicodeFont = null;
    if (file != null) {
        // Load from file.
        try {
            unicodeFont = new UnicodeFont(fontFileText.getText(), fontSize, boldCheckBox.isSelected(), italicCheckBox.isSelected());
        } catch (Throwable ex) {
            ex.printStackTrace();
            fontFileRadio.setSelected(false);
        }
    }
    if (unicodeFont == null) {
        // Load from java.awt.Font (kerning not available!).
        unicodeFont = new UnicodeFont(Font.decode((String) fontList.getSelectedValue()), fontSize, boldCheckBox.isSelected(), italicCheckBox.isSelected());
    }
    unicodeFont.setMono(monoCheckBox.isSelected());
    unicodeFont.setGamma(((Number) gammaSpinner.getValue()).floatValue());
    unicodeFont.setPaddingTop(((Number) padTopSpinner.getValue()).intValue());
    unicodeFont.setPaddingRight(((Number) padRightSpinner.getValue()).intValue());
    unicodeFont.setPaddingBottom(((Number) padBottomSpinner.getValue()).intValue());
    unicodeFont.setPaddingLeft(((Number) padLeftSpinner.getValue()).intValue());
    unicodeFont.setPaddingAdvanceX(((Number) padAdvanceXSpinner.getValue()).intValue());
    unicodeFont.setPaddingAdvanceY(((Number) padAdvanceYSpinner.getValue()).intValue());
    unicodeFont.setGlyphPageWidth(((Number) glyphPageWidthCombo.getSelectedItem()).intValue());
    unicodeFont.setGlyphPageHeight(((Number) glyphPageHeightCombo.getSelectedItem()).intValue());
    if (nativeRadio.isSelected())
        unicodeFont.setRenderType(RenderType.Native);
    else if (freeTypeRadio.isSelected())
        unicodeFont.setRenderType(RenderType.FreeType);
    else
        unicodeFont.setRenderType(RenderType.Java);
    for (Iterator iter = effectPanels.iterator(); iter.hasNext(); ) {
        EffectPanel panel = (EffectPanel) iter.next();
        unicodeFont.getEffects().add(panel.getEffect());
    }
    int size = sampleTextPane.getFont().getSize();
    if (size < 14)
        size = 14;
    sampleTextPane.setFont(unicodeFont.getFont().deriveFont((float) size));
    if (this.unicodeFont != null)
        this.unicodeFont.dispose();
    this.unicodeFont = unicodeFont;
    updateFontSelector();
}
Also used : UnicodeFont(com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont) Iterator(java.util.Iterator) File(java.io.File)

Example 2 with UnicodeFont

use of com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont 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

UnicodeFont (com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont)2 File (java.io.File)2 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 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 Iterator (java.util.Iterator)1