Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts generated by FreeTypeFontGenerator have missing characters with certain font parameter settings. #4195

Closed
2 of 7 tasks
toyknight opened this issue Jul 18, 2016 · 3 comments

Comments

@toyknight
Copy link
Contributor

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.

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS
@toyknight toyknight changed the title Fonts generated by FreeTypeFontGenerator missing characters with certain font parameter settings. Fonts generated by FreeTypeFontGenerator have missing characters with certain font parameter settings. Jul 18, 2016
@xoppa
Copy link
Member

xoppa commented Jul 18, 2016

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

FreeTypeFontGenerator.setMaxTextureSize(2048);

@toyknight
Copy link
Contributor Author

toyknight commented Jul 18, 2016

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

FreeTypeFontGenerator.setMaxTextureSize(2048);

It actually works! Thank you so much!

@xoppa
Copy link
Member

xoppa commented Jul 18, 2016

Duplicate of #3525

@xoppa xoppa closed this as completed Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants