Search in sources :

Example 1 with FreeTypeFontParameter

use of com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter in project libgdx by libgdx.

the class UnicodeFont method setRenderType.

public void setRenderType(RenderType renderType) {
    this.renderType = renderType;
    if (renderType != RenderType.FreeType) {
        if (bitmapFont != null) {
            bitmapFont.dispose();
            generator.dispose();
        }
    } else {
        String fontFile = getFontFile();
        if (fontFile != null) {
            generator = new FreeTypeFontGenerator(Gdx.files.absolute(fontFile));
            FreeTypeFontParameter param = new FreeTypeFontParameter();
            param.size = font.getSize();
            param.incremental = true;
            param.flip = true;
            param.mono = mono;
            param.gamma = gamma;
            bitmapFont = generator.generateFont(param);
            if (bitmapFont.getData().missingGlyph == null)
                bitmapFont.getData().missingGlyph = bitmapFont.getData().getGlyph('�');
            cache = bitmapFont.newFontCache();
            layout = new GlyphLayout();
        }
    }
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 2 with FreeTypeFontParameter

use of com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter in project libgdx by libgdx.

the class FreeTypeDisposeTest method render.

public void render() {
    if (Gdx.input.justTouched()) {
        for (int i = 0; i < 10; i++) {
            if (font != null) {
                font.dispose();
            }
            FileHandle fontFile = Gdx.files.internal("data/arial.ttf");
            FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
            FreeTypeFontParameter parameter = new FreeTypeFontParameter();
            parameter.size = 15;
            font = generator.generateFont(parameter);
            generator.dispose();
        }
        for (int i = 0; i < 10; i++) System.gc();
        Gdx.app.log("FreeTypeDisposeTest", "generated 10 fonts");
        Gdx.app.log("FreeTypeDisposeTest", Gdx.app.getJavaHeap() + ", " + Gdx.app.getNativeHeap());
    }
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 3 with FreeTypeFontParameter

use of com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter in project libgdx by libgdx.

the class FreeTypeIncrementalTest method create.

public void create() {
    batch = new SpriteBatch();
    shapes = new ShapeRenderer();
    shapes.setColor(Color.RED);
    FreeTypeFontGenerator.setMaxTextureSize(128);
    generator = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf"));
    FreeTypeFontParameter param = new FreeTypeFontParameter();
    param.incremental = true;
    param.size = 24;
    param.characters = "howdY";
    FreeTypeBitmapFontData data = new FreeTypeBitmapFontData() {

        public int getWrapIndex(Array<Glyph> glyphs, int start) {
            return SimplifiedChinese.getWrapIndex(glyphs, start);
        }
    };
    // By default latin chars are used for x and cap height, causing some fonts to display non-latin chars out of bounds.
    data.xChars = new char[] { '动' };
    data.capChars = new char[] { '动' };
    font = generator.generateFont(param, data);
}
Also used : Array(com.badlogic.gdx.utils.Array) FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) FreeTypeBitmapFontData(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 4 with FreeTypeFontParameter

use of com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter in project libgdx by libgdx.

the class FreeTypeTest method create.

@Override
public void create() {
    boolean flip = false;
    batch = new SpriteBatch();
    if (flip) {
        OrthographicCamera cam = new OrthographicCamera();
        cam.setToOrtho(flip);
        cam.update();
        batch.setProjectionMatrix(cam.combined);
    }
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), flip);
    FileHandle fontFile = Gdx.files.internal("data/arial.ttf");
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 15;
    parameter.flip = flip;
    parameter.genMipMaps = true;
    // parameter.shadowOffsetX = 1;
    // parameter.shadowOffsetY = 1;
    // parameter.shadowColor = Color.GREEN;
    // parameter.borderWidth = 1f;
    // parameter.borderColor = Color.PURPLE;
    FreeTypeBitmapFontData fontData = generator.generateData(parameter);
    ftFont = generator.generateFont(parameter);
    generator.dispose();
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) FileHandle(com.badlogic.gdx.files.FileHandle) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) FreeTypeBitmapFontData(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 5 with FreeTypeFontParameter

use of com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter in project libgdx by libgdx.

the class FreeTypeMetricsTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    atlas = new TextureAtlas("data/pack");
    smallFont = new BitmapFont();
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 60;
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf"));
    font = generator.generateFont(parameter);
    generator.dispose();
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Aggregations

FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)6 FreeTypeFontParameter (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter)6 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)4 FileHandle (com.badlogic.gdx.files.FileHandle)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 FreeTypeBitmapFontData (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData)2 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)2 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Array (com.badlogic.gdx.utils.Array)1