使用Android中的自定义TTF使得真难看文本自定义、难看、文本、Android

由网友(Hypoxia.(缺氧))分享简介:我有一个应用程序,其中包含一个自定义视图,并在其中我想用一个自定义的字体。不幸的是,这会导致真难看文本渲染。I have an app that contains a custom view, and in it I want to use a custom font. Unfortunately, this res...

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

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.

阅读全文

相关推荐

最新文章