Using custom TTF in Android makes really ugly text

I have an application that contains a custom view, and in it I want to use my own font. Unfortunately, this leads to the visualization of really ugly text.

My custom view extends Surface (and just realized: this is a bad idea), and I am drawing text with the following code:

// p = new Paint(); Typeface font = Typeface.createFromAsset(parent.getAssets(), "komtit.ttf"); p.setColor(Color.BLACK); p.setTypeface(font); c.drawText(this.text, x + width / 2 - p.measureText(this.text) / 2, y + height / 2, p); 

The result is as follows:

http://img.skitch.com/20101014-rxw8j8igj1jci2fx9ui32ejcp.jpg

Not fun. I use p.setFlags (Paint.ANTI_ALIAS_FLAG), but even so, the result is simply inconvenient.

So, is there a way to improve custom TTF rendering, or should I just stick with system fonts?

+2
source share
1 answer

Answering my own question here. The problem was that I was expanding Surface (in the end I had no good reason), which apparently uses OpenGL for rendering, and OpenGL and custom TTF fonts don't mix.

When I switched to the View only extension, the font looks perfect.

+2
source

All Articles