Java Code Examples for com.badlogic.gdx.graphics.g2d.BitmapFont#BitmapFontData

The following examples show how to use com.badlogic.gdx.graphics.g2d.BitmapFont#BitmapFontData . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmartFontGenerator.java    From gdx-smart-font with MIT License 5 votes vote down vote up
/** Convenience method for generating a font, and then writing the fnt and png files.
 * Writing a generated font to files allows the possibility of only generating the fonts when they are missing, otherwise
 * loading from a previously generated file.
 * @param fontFile
 * @param fontSize
 */
private BitmapFont generateFontWriteFiles(String fontName, FileHandle fontFile, int fontSize, int pageWidth, int pageHeight) {
	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);

	PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight, Pixmap.Format.RGBA8888, 2, false);
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = fontSize;
	parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
	parameter.flip = false;
	parameter.packer = packer;
	FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(parameter);
	Array<PixmapPacker.Page> pages = packer.getPages();
	Array<TextureRegion> texRegions = new Array<>();
	for (int i = 0; i < pages.size; i++) {
		PixmapPacker.Page p = pages.get(i);
		Texture tex = new Texture(
				new PixmapTextureData(p.getPixmap(), p.getPixmap().getFormat(), false, false, true)) {
			@Override
			public void dispose() {
				super.dispose();
				getTextureData().consumePixmap().dispose();
			}
		};
		tex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
		texRegions.add(new TextureRegion(tex));
	}
	BitmapFont font = new BitmapFont((BitmapFont.BitmapFontData) fontData, texRegions, false);
	saveFontToFile(font, fontSize, fontName, packer);
	generator.dispose();
	packer.dispose();
	return font;
}
 
Example 2
Source File: Fonts.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public Fonts(AssetManager assets) {
  consolas12   = loadEx(assets, "consolas12.fnt");
  consolas16   = loadEx(assets, "consolas16.fnt");
  font6        = load(assets, "font6",  BlendMode.LUMINOSITY_TINT);
  font8        = load(assets, "font8",  BlendMode.LUMINOSITY_TINT);
  font16       = load(assets, "font16", BlendMode.LUMINOSITY_TINT);
  font24       = load(assets, "font24", BlendMode.ID);
  font30       = load(assets, "font30", BlendMode.ID);
  font42       = load(assets, "font42", BlendMode.ID);
  fontformal10 = load(assets, "fontformal10", BlendMode.LUMINOSITY_TINT);
  fontformal11 = load(assets, "fontformal11", BlendMode.LUMINOSITY_TINT);
  fontformal12 = load(assets, "fontformal12", BlendMode.LUMINOSITY_TINT);
  fontexocet10 = load(assets, "fontexocet10", BlendMode.TINT_BLACKS);
  fontridiculous = load(assets, "fontridiculous", BlendMode.TINT_BLACKS);
  ReallyTheLastSucker = load(assets, "ReallyTheLastSucker", BlendMode.ID);

  BitmapFont.BitmapFontData data;
  data = font8.getData();
  data.lineHeight = data.xHeight = data.capHeight = 12;
  data.ascent = 16;
  data.down = -12;

  data = font16.getData();
  data.lineHeight = data.xHeight = data.capHeight = 14;
  data.ascent = 17;
  data.down = -16;

  data = font42.getData();
  data.lineHeight = data.xHeight = data.capHeight = 31;
  data.ascent = 48;
  data.down = -31;

  data = fontformal10.getData();
  data.lineHeight = data.xHeight = data.capHeight = 14;
  data.ascent = 17;
  data.down = -14;

  data = fontformal11.getData();
  data.lineHeight = data.xHeight = data.capHeight = 18;
  data.ascent = 18;
  data.down = -18;

  data = fontformal12.getData();
  data.lineHeight = data.xHeight = data.capHeight = 16;
  data.ascent = 42;
  data.down = -20;

  data = ReallyTheLastSucker.getData();
  data.lineHeight = data.xHeight = data.capHeight = 8;
  data.ascent = 11;
  data.down = -8;
}
 
Example 3
Source File: LibgdxBitmapFont.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
public LibgdxBitmapFont (BitmapFont.BitmapFontData data, TextureRegion region, boolean integer) {
	this(data, region != null ? Array.with(region) : null, integer);
}
 
Example 4
Source File: LibgdxBitmapFont.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
public LibgdxBitmapFont (BitmapFont.BitmapFontData data, Array<TextureRegion> pageRegions, boolean integer) {
	bitmapFont = new com.badlogic.gdx.graphics.g2d.BitmapFont(data, convert(pageRegions), integer);
	sharedGlyphLayout = (BitmapFontGlyphLayout) newGlyphLayout();
	tmpColor = new LibgdxColor(bitmapFont.getColor());
}