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

The following examples show how to use com.badlogic.gdx.graphics.g2d.BitmapFont#Glyph . 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: FontUtilTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldUnableToGenerateBitmapIfCharNotInTTF() throws Exception {
    FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");
    String text = "มันเป็นการทดสอบ";
    BitmapFont bitmapFont = FontUtil.createFont(defaultFont, text, 14);

    assertThat(bitmapFont, not(nullValue()));
    for (char c : text.toCharArray()) {
        BitmapFont.Glyph glyph = bitmapFont.getData().getGlyph(c);
        try {
            assertThat(glyph, is(nullValue()));
        } catch (AssertionError ignored) {
            //Different behaviour for 1.7.0
            assertThat(glyph.id, is(127));
        }
    }
}
 
Example 2
Source File: FontUtilTest.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Test
@NeedGL
public void shouldAbleGenerateBitmapFontFromTTF() throws Exception {
    FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");
    String text = "This is a test. 这是一个测试。これはテストです.";
    BitmapFont bitmapFont = FontUtil.createFont(defaultFont, text, 14);

    assertThat(bitmapFont, not(nullValue()));
    for (char c : text.toCharArray()) {
        BitmapFont.Glyph glyph = bitmapFont.getData().getGlyph(c);
        assertThat(glyph, not(nullValue()));
        assertThat(glyph.id, not(nullValue()));
    }
}
 
Example 3
Source File: RenderedText.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void measure(){
	
	if (Thread.currentThread().getName().equals("SHPD Actor Thread")){
		throw new RuntimeException("Text measured from the actor thread!");
	}
	
	if ( text == null || text.equals("") ) {
		text = "";
		width=height=0;
		visible = false;
		return;
	} else {
		visible = true;
	}
	
	font = Game.platform.getFont(size, text);
	
	if (font != null){
		GlyphLayout glyphs = new GlyphLayout( font, text);
		
		for (char c : text.toCharArray()) {
			BitmapFont.Glyph g = font.getData().getGlyph(c);
			if (g == null || (g.id != c)){
				Game.reportException(new Throwable("font file " + font.toString() + " could not render " + c));
			}
		}
		
		//We use the xadvance of the last glyph in some cases to fix issues
		// with fullwidth punctuation marks in some asian scripts
		BitmapFont.Glyph lastGlyph = font.getData().getGlyph(text.charAt(text.length()-1));
		if (lastGlyph != null && lastGlyph.xadvance > lastGlyph.width*1.5f){
			width = glyphs.width - lastGlyph.width + lastGlyph.xadvance;
		} else {
			width = glyphs.width;
		}
		
		//this is identical to l.height in most cases, but we force this for consistency.
		height = Math.round(size*0.75f);
		renderedHeight = glyphs.height;
	}
}
 
Example 4
Source File: RenderedText.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void measure(){
	
	if (Thread.currentThread().getName().equals("SHPD Actor Thread")){
		throw new RuntimeException("Text measured from the actor thread!");
	}
	
	if ( text == null || text.equals("") ) {
		text = "";
		width=height=0;
		visible = false;
		return;
	} else {
		visible = true;
	}
	
	font = getFont(size);
	
	if (font != null){
		GlyphLayout glyphs = new GlyphLayout( font, text);
		
		for (char c : text.toCharArray()) {
			BitmapFont.Glyph g = font.getData().getGlyph(c);
			if (g == null || (g.id != c)){
				Game.reportException(new Throwable("font file " + font.toString() + " could not render " + c));
			}
		}
		
		//We use the xadvance of the last glyph in some cases to fix issues
		// with fullwidth punctuation marks in some asian scripts
		BitmapFont.Glyph lastGlyph = font.getData().getGlyph(text.charAt(text.length()-1));
		if (lastGlyph != null && lastGlyph.xadvance > lastGlyph.width*1.5f){
			width = glyphs.width - lastGlyph.width + lastGlyph.xadvance;
		} else {
			width = glyphs.width;
		}
		
		//this is identical to l.height in most cases, but we force this for consistency.
		height = Math.round(size*0.75f);
		renderedHeight = glyphs.height;
	}
}