libgdx / libgdx/libgdx

Freetype font kerning on Android not working

Open
#5,124 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

fonts
Dominant language
Java
Stars
25.4k
Forks
6.5k
Avg merge
1d 16h
Merged PRs (30d)
5

Description

Issue details

Freetype font kerning works just fine when I run my code as desktop app, I can set kerning to true or false.

But on android device setting kerning true of false makes no difference, kerning is not there either way.

Tested with 3 different phones with different Android versions, issue is always present.

Below is an example. I downloaded the latest libGDX setup App and added some freetype font words to a newly generated default project.

The font I used is OpenSans-Bold.ttf, downloaded from Google Fonts, but I have tried other fonts too.

A screenshot

Reproduction steps/code

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;

public class MyGdxGame extends ApplicationAdapter {
	SpriteBatch batch;
	Texture img;
	BitmapFont font;

	@Override
	public void create () {

		FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("OpenSans-Bold.ttf"));
		FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
		parameter.size = 50;
		parameter.color = Color.WHITE;

		parameter.kerning = true;

		font = generator.generateFont(parameter); // font size 12 pixels
		generator.dispose(); // don't forget to dispose to avoid memory leaks!

		batch = new SpriteBatch();
		img = new Texture("badlogic.jpg");
	}

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

		font.draw(batch, "START Yawn", 50, 460);

		batch.end();
	}
	
	@Override
	public void dispose () {
		batch.dispose();
		img.dispose();
	}
}

Version of LibGDX and/or relevant dependencies

  • libGDX 1.9.8
  • Freetype extension checked in libGDX setup app

Please select the affected platforms

  • Android

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the FreeTypeFontGenerator usage in the create() entry point and reproduce the sample on desktop and Android using OpenSans-Bold.ttf. Compare the generated font behavior with parameter.kerning set to true and false, then trace the Android font-generation path. Done means kerning behavior is consistent or the Android limitation is documented and covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.