question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FreeType generated font misses some characters with certain parameters

See original GitHub issue

Issue details

When using the font provided below and one of the affected sizes some characters are not rendered.

Reproduction steps/code

  1. Generate new project with FreeType feature enabled
  2. Replace the body of your generated ApplicationAdapter class (MyGdxGame by default) with this:
    private SpriteBatch batch;
    private BitmapFont font;

    @Override
    public void create() {
        batch = new SpriteBatch();

        FreeTypeFontGenerator fontGenerator =
                new FreeTypeFontGenerator(Gdx.files.internal("Carlito-Regular.ttf"));

        FreeTypeFontGenerator.FreeTypeFontParameter parameter =
                new FreeTypeFontGenerator.FreeTypeFontParameter();

        // Rendered text depending on font size:

        // 211:       "abcde" as expected
        // 212:       "something strange bcde"
        // 214 - 215: " b de"
        // 216 - 262: " b d "
        // 263:       " bcde"
        // 264 - 266: " b de"
        // 267 - 268: " b d "
        // 269:       "abcde" as expected

        parameter.size = 216;

        font = fontGenerator.generateFont(parameter);
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        batch.begin();
        font.draw(batch, "abcde", 5, 300);
        batch.end();
    }

    @Override
    public void dispose() {
        batch.dispose();
        font.dispose();
    }
  1. Download Carlito font from https://fontlibrary.org/en/font/carlito and copy Carlito-Regular.ttf to your assets folder
  2. Set parameter.size to one of the values from the comments above
  3. Run and see a certain kind of unexpected render

Version of LibGDX and/or relevant dependencies

• LibGdx 1.9.8 • Windows and Android, other platforms not tested • Carlito-Regular.ttf font, other fonts not tested.

Please select the affected platforms

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
NathanSweetcommented, Oct 18, 2018

Cool, glad you got it sorted. Sorry it took so long to reply. I’ve updated the wiki. Feel free to make wiki contributions! I believe anyone can edit the wiki, that is what it is there for.

BTW, you might look at DistanceFieldFont: https://github.com/libgdx/libgdx/wiki/Distance-field-fonts That wiki page looks outdated though, since it doesn’t even mention that you should use the shader created by DistanceFieldFont.createDistanceFieldShader.

0reactions
Vlad-M-1commented, Oct 18, 2018

Found a much more simple solution:

FreeTypeFontGenerator.setMaxTextureSize(4096);

Then I guess it’s even better to mention this method on https://github.com/libgdx/libgdx/wiki/Gdx-freetype

Read more comments on GitHub >

github_iconTop Results From Across the Web

libGDX FressType font misses accented characters (french)
I'm stupid !!! the problem came from the file in which I read the texts: it was coded in ANSI, not in UTF-8...
Read more >
Error Code Values - FreeType-2.12.1 API Reference
See the 'Error Enumerations' subsection how to automatically generate a list of ... 0x0C, "missing property" ) /* glyph/character errors */ FT_ERRORDEF_( ...
Read more >
Base Interface - FreeType-2.12.1 API Reference
A handle to a FreeType library instance. Each 'library' is completely independent from the others; it is the 'root' of a set of...
Read more >
Driver properties - FreeType-2.12.1 API Reference
A list of constants used for the hinting-engine property to select the hinting engine for CFF, Type 1, and CID fonts. values. FT_HINTING_FREETYPE....
Read more >
TrueType Tables - FreeType-2.12.1 API Reference
This section contains definitions of some basic tables specific to ... For an OpenType variation font, the values of the following fields can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found