Libgdx: Fonts generated by FreeTypeFontGenerator have missing characters with certain font parameter settings.

Created on 18 Jul 2016  路  3Comments  路  Source: libgdx/libgdx

Issue details

I am using some Chinese fonts and it seems the bitmap fonts generated by the FreeTypeFontGenerator will have missing characters with certain FreeTypeFontParameter settings . I will show some examples below.

IMG01 [test_font.ttf, font size 16, border width 2] Looks good.

image 1

IMG02 [test_font.ttf, font size 24, border width 3] Characters missing.

image 2

IMG03 [microsoft_yahei_bold.ttf, font size 24, border width 3] Switched to a more promising Microsoft font and the situation seems to become worse.

image 3

Reproduction steps/code

Core codes for IMG02:

public class GameContext extends ApplicationAdapter {

    private BitmapFont font;

    private SpriteBatch batch;

    @Override
    public void create() {
        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("test_font.ttf"));
        String characters = Gdx.files.internal("characters.txt").readString("UTF8");
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        parameter.size = 24;
        parameter.color = Color.WHITE;
        parameter.borderColor = Color.BLACK;
        parameter.borderWidth = 3;
        parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS + characters;
        font = generator.generateFont(parameter);

        batch = new SpriteBatch();
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        batch.begin();
        font.draw(batch, "This is a test string zzz...", 10, Gdx.graphics.getHeight() / 2);
        batch.end();
    }

    @Override
    public void dispose() {
        font.dispose();
    }

}

Note: The characters.txt file includes some Chinese characters and punctuation which I need to use in my game.
You can find the example project here.

Version of LibGDX and/or relevant dependencies

1.9.3

Please select the affected platforms

Only tested on android and windows.

  • [x] Android
  • [ ] iOS (robovm)
  • [ ] iOS (MOE)
  • [ ] HTML/GWT
  • [x] Windows
  • [ ] Linux
  • [ ] MacOS

Most helpful comment

Please add the following line to check whether that makes any difference:

FreeTypeFontGenerator.setMaxTextureSize(2048);

All 3 comments

Please add the following line to check whether that makes any difference:

FreeTypeFontGenerator.setMaxTextureSize(2048);

Please add the following line to check whether that makes any difference:

FreeTypeFontGenerator.setMaxTextureSize(2048);

It actually works! Thank you so much!

Duplicate of #3525

Was this page helpful?
0 / 5 - 0 ratings