Java Code Examples for com.badlogic.gdx.graphics.g2d.PixmapPacker

The following examples show how to use com.badlogic.gdx.graphics.g2d.PixmapPacker. These examples are extracted from open source projects. 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
@Override
public void resetGenerators() {
	if (fonts != null) {
		for (FreeTypeFontGenerator generator : fonts.keySet()) {
			for (BitmapFont f : fonts.get(generator).values()) {
				f.dispose();
			}
			fonts.get(generator).clear();
			generator.dispose();
		}
		fonts.clear();
		if (packer != null) {
			for (PixmapPacker.Page p : packer.getPages()) {
				p.getTexture().dispose();
			}
			packer.dispose();
		}
		fonts = null;
	}
	setupFontGenerators(pageSize, systemfont);
}
 
Example 2
@Override
public void resetGenerators() {
	if (fonts != null) {
		for (FreeTypeFontGenerator generator : fonts.keySet()) {
			for (BitmapFont f : fonts.get(generator).values()) {
				f.dispose();
			}
			fonts.get(generator).clear();
			generator.dispose();
		}
		fonts.clear();
		if (packer != null) {
			for (PixmapPacker.Page p : packer.getPages()) {
				p.getTexture().dispose();
			}
			packer.dispose();
		}
		fonts = null;
	}
	setupFontGenerators(pageSize, systemfont);
}
 
Example 3
Source Project: gdx-proto   Source File: SmartFontGenerator.java    License: Apache License 2.0 6 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);
	FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(fontSize, FreeTypeFontGenerator.DEFAULT_CHARS, false, packer);
	Array<PixmapPacker.Page> pages = packer.getPages();
	TextureRegion[] texRegions = new TextureRegion[pages.size];
	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[i] = new TextureRegion(tex);
	}
	BitmapFont font = new BitmapFont(fontData, texRegions, false);
	saveFontToFile(font, fontSize, fontName, packer);
	generator.dispose();
	packer.dispose();
	return font;
}
 
Example 4
Source Project: gdx-smart-font   Source File: SmartFontGenerator.java    License: 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 5
Source Project: gdx-smart-font   Source File: SmartFontGenerator.java    License: MIT License 5 votes vote down vote up
private void saveFontToFile(BitmapFont font, int fontSize, String fontName, PixmapPacker packer) {
	FileHandle fontFile = getFontFile(fontName + ".fnt", fontSize); // .fnt path
	FileHandle pixmapDir = getFontFile(fontName, fontSize); // png dir path
	BitmapFontWriter.setOutputFormat(BitmapFontWriter.OutputFormat.Text);

	String[] pageRefs = BitmapFontWriter.writePixmaps(packer.getPages(), pixmapDir, fontName);
	Gdx.app.debug(TAG, String.format("Saving font [%s]: fontfile: %s, pixmapDir: %s\n", fontName, fontFile, pixmapDir));
	// here we must add the png dir to the page refs
	for (int i = 0; i < pageRefs.length; i++) {
		pageRefs[i] = fontSize + "_" + fontName + "/" + pageRefs[i];
	}
	BitmapFontWriter.writeFont(font.getData(), pageRefs, fontFile, new BitmapFontWriter.FontInfo(fontName, fontSize), 1, 1);
}
 
Example 6
Source Project: gdx-proto   Source File: SmartFontGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private void saveFontToFile(BitmapFont font, int fontSize, String fontName, PixmapPacker packer) {
	FileHandle fontFile = getFontFile(fontName + ".fnt"); // .fnt path
	FileHandle pixmapDir = getFontFile(fontName); // png dir path
	BitmapFontWriter.setOutputFormat(BitmapFontWriter.OutputFormat.Text);

	String[] pageRefs = BitmapFontWriter.writePixmaps(packer.getPages(), pixmapDir, fontName);
	Gdx.app.debug(TAG, String.format("Saving font [%s]: fontfile: %s, pixmapDir: %s\n", fontName, fontFile, pixmapDir));
	// here we must add the png dir to the page refs
	for (int i = 0; i < pageRefs.length; i++) {
		pageRefs[i] = fontName + "/" + pageRefs[i];
	}
	BitmapFontWriter.writeFont(font.getData(), pageRefs, fontFile, new BitmapFontWriter.FontInfo(fontName, fontSize), 1, 1);
}
 
Example 7
Source Project: skin-composer   Source File: DesktopWorker.java    License: MIT License votes vote down vote up
void writeFont(FreeTypeBitmapFontData data, Array<PixmapPacker.Page> pages, FileHandle target);