本文整理匯總了Java中com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateData方法的典型用法代碼示例。如果您正苦於以下問題:Java FreeTypeFontGenerator.generateData方法的具體用法?Java FreeTypeFontGenerator.generateData怎麽用?Java FreeTypeFontGenerator.generateData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
的用法示例。
在下文中一共展示了FreeTypeFontGenerator.generateData方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; //導入方法依賴的package包/類
@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;
FreeTypeBitmapFontData fontData = generator.generateData(parameter);
ftFont = generator.generateFont(parameter);
generator.dispose();
}
示例2: generateFiles
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; //導入方法依賴的package包/類
/**
* 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
* @param destiny
*/
private void generateFiles(String fontName, FileHandle fontFile,
int fontSize, int pageWidth, int pageHeight, FileHandle destiny) {
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight,
Pixmap.Format.RGBA8888, 2, false);
FreeTypeFontParameter param = new FreeTypeFontParameter();
param.packer = packer;
param.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
param.size = fontSize;
param.flip = false;
FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator
.generateData(param);
saveFontToFile(fontData, fontSize, fontName, packer, destiny);
generator.dispose();
packer.dispose();
}
示例3: generateFontWriteFiles
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; //導入方法依賴的package包/類
/** 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;
}
示例4: generateFontWriteFiles
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; //導入方法依賴的package包/類
/** 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.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = fontSize;
parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
parameter.packer = packer;
FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(parameter);//(fontSize, FreeTypeFontGenerator.DEFAULT_CHARS, false, packer);
Array<PixmapPacker.Page> pages = packer.getPages();
Array<TextureRegion> texRegions = new Array<TextureRegion>(pageSize);
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(fontData,texRegions,false); //fontData, texRegions, false);
saveFontToFile(font, fontSize, fontName, packer);
generator.dispose();
packer.dispose();
return font;
}
示例5: generateFontWriteFiles
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; //導入方法依賴的package包/類
/**
* 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 freeTypeFontParameter = new FreeTypeFontParameter();
freeTypeFontParameter.size = fontSize;
freeTypeFontParameter.packer = packer;
FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(freeTypeFontParameter);
Array<PixmapPacker.Page> pages = packer.getPages();
Array<TextureRegion> texRegions = new Array<TextureRegion>();
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(fontData, texRegions, false);
saveFontToFile(font, fontSize, fontName, packer);
generator.dispose();
packer.dispose();
return font;
}
示例6: generateFontWriteFiles
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; //導入方法依賴的package包/類
/** 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;
}
示例7: loadSync
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; //導入方法依賴的package包/類
@Override
public BitmapFont loadSync( AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter ) {
int fontSize = 10;
String scrubbedFileName = fileName;
int qMark = fileName.lastIndexOf( "?" );
if ( qMark != -1 ) {
scrubbedFileName = scrubbedFileName.substring( 0, qMark );
Matcher m = argsPtn.matcher( fileName );
m.region( qMark+1, fileName.length() );
while ( m.lookingAt() ) {
if ( m.group( 1 ).equals( "size" ) ) {
fontSize = Integer.parseInt( m.group( 2 ) );
}
if ( m.group( 3 ).length() > 0 ) break; // Hit the "#" separator.
m.region( m.end(), fileName.length() );
}
}
boolean flip = parameter != null ? parameter.flip : false;
FreeTypeFontGenerator generator = new FreeTypeFontGenerator( file );
FreeTypeBitmapFontData data = generator.generateData( fontSize, FreeTypeFontGenerator.DEFAULT_CHARS, flip );
generator.dispose();
return new BitmapFont( data, data.getTextureRegions(), true );
}
示例8: generateFiles
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; //導入方法依賴的package包/類
/**
* 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
* @param destiny
*/
private void generateFiles(String fontName, FileHandle fontFile,
int fontSize, FileHandle destiny) {
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
// compute the minimum page size for a square png
FreeType.Library library = FreeType.initFreeType();
FreeType.Face face = FreeType.newFace(library, fontFile, 0);
FreeType.setPixelSizes(face, 0, fontSize);
FreeType.SizeMetrics fontMetrics = face.getSize().getMetrics();
float scale = FreeType.toInt(fontMetrics.getHeight());
for (int c = 32; c < (32 + face.getNumGlyphs()); c++) {
if (FreeType.loadChar(face, c, FreeType.FT_LOAD_DEFAULT)) {
int lh = FreeType.toInt(face.getGlyph().getMetrics()
.getHeight());
scale = (lh > scale) ? lh : scale;
}
}
// generate the glyphs
int maxGlyphHeight = (int) Math.ceil(scale);
float area = maxGlyphHeight * maxGlyphHeight
* FreeTypeFontGenerator.DEFAULT_CHARS.length();
int pageWidth = MathUtils.nextPowerOfTwo((int) Math.sqrt(area));
pageWidth = Math.min(pageWidth, 1024);
PixmapPacker packer = new PixmapPacker(pageWidth, pageWidth,
Pixmap.Format.RGBA8888, 2, false);
FreeTypeFontGenerator.FreeTypeFontParameter param = new FreeTypeFontGenerator.FreeTypeFontParameter();
param.packer = packer;
param.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
param.size = fontSize;
param.flip = false;
FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator
.generateData(param);
saveFontToFile(fontData, fontSize, fontName, packer, destiny);
generator.dispose();
packer.dispose();
}