使用Android中的自定义TTF使得真难看文本 [英] Using a custom TTF in Android makes for really ugly text

查看:124
本文介绍了使用Android中的自定义TTF使得真难看文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中包含一个自定义视图,并在其中我想用一个自定义的字体。不幸的是,这会导致真难看文本渲染。

I have an app that contains a custom view, and in it I want to use a custom font. Unfortunately, this results in really ugly text being rendered.

我的自定义视图延伸表面(和刚刚意识到:这是一个坏主意),我得出有以下code中的文本:

My custom view extends Surface (and just realized: is this a bad idea), and I draw the 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 looks like this:

不好玩。我使用p.setFlags(Paint.ANTI_ALIAS_FLAG),但即使有,其结果就是fudgly。

Not fun. I'm using p.setFlags(Paint.ANTI_ALIAS_FLAG) but even with that the result is just fudgly.

那么,有没有一种方法,以改善自定义TTF渲染,或者我应该只是坚持到系统的字体?

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

推荐答案

在这里回答我的问题。问题是,我是延伸面(我真的到最后也没有一个合适的理由),这显然使用OpenGL渲染和OpenGL和自定义的TTF字体不混合。

Answering my own question here. The problem was that I was extending Surface (which I really in the end didn't have a proper reason for) which apparently uses OpenGL for rendering and OpenGL and custom TTF fonts don't mix.

当我切换到刚才扩展视图,字体看起来很完美。

When I switched to extending just View, the font looks perfect.

这篇关于使用Android中的自定义TTF使得真难看文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆