Example usage for com.badlogic.gdx.graphics.g2d.freetype FreeTypeFontGenerator scaleForPixelHeight

List of usage examples for com.badlogic.gdx.graphics.g2d.freetype FreeTypeFontGenerator scaleForPixelHeight

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d.freetype FreeTypeFontGenerator scaleForPixelHeight.

Prototype

public int scaleForPixelHeight(int height) 

Source Link

Document

Uses ascender and descender of font to calculate real height that makes all glyphs to fit in given pixel size.

Usage

From source file:edu.lehigh.cse.lol.Media.java

License:Open Source License

/**
 * Get the font described by the file name and font size
 *
 * @param fontFileName The filename for the font. This should be in the android
 *                     project's assets, and should end in .ttf
 * @param fontSize     The size to display
 * @return A font object that can be used to render text
 *//* w w w. ja  v  a  2 s . co m*/
static BitmapFont getFont(String fontFileName, int fontSize) {
    // we store fonts as their filename appended with their size
    String key = fontFileName + "--" + fontSize;

    // check if we've already got this font, return it if we do
    BitmapFont f = Lol.sGame.mMedia.mFonts.get(key);
    if (f != null) {
        // just to play it safe, make the font white... the caller can
        // change this
        f.setColor(1, 1, 1, 1);
        return f;
    }

    // Generate the font, save it, and return it
    //
    // NB: if this crashes, the user will get a reasonably good error
    // message
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(fontFileName));
    parameter.size = fontSize;
    generator.scaleForPixelHeight(fontSize);
    parameter.minFilter = Texture.TextureFilter.Linear;
    parameter.magFilter = Texture.TextureFilter.Linear;

    f = generator.generateFont(parameter);
    generator.dispose();
    Lol.sGame.mMedia.mFonts.put(key, f);
    return f;
}