android 上的抗锯齿字体正确吗?
有没有什么方法可以以视觉上令人愉悦的方式呈现带有自定义字体的文本(尽管我认为系统字体可能不会有太大不同)?
我使用分配了自定义字体的涂料在画布上渲染文本。
我发现的唯一与抗锯齿远程相关的命令是绘画的“setAntiAlias”。但文字看起来仍然很可怕。几乎和 Photoshop 中没有抗锯齿一样糟糕。
那么...有什么办法可以做到这一点吗?
和... 由于这是针对游戏的,位图字体是一种常用的替代方案,但由于我想要有适当的字母间距,我必须编写一个相当复杂的位图字体类来实现这一点。因为我还没有找到已经存在的。似乎只有 libgdx 包含一个。但那个与库紧密集成,需要进行很多修改。因此,如果这里有人知道不需要这样做的人,那也会有很大的帮助。
我的代码片段作为参考,尽管它非常基本并且工作得很好,我不认为它是相关的:
textPaint = new Paint();
textPaint.setTextSize(size);
textPaint.setAntiAlias(true);
textPaint.setARGB(0xff, 0xff, 0xff, 0xff);
textPaint.setTypeface(Typeface.createFromAsset(pView.getContext().getAssets(),
"fonts/cordia.ttf"));
...
canvas.drawText(text, (int)(dimension / 2 - textwidth / 2),
(int)(dimension / 2 - size / 2), textPaint);
is there any way to render text with custom fonts (though i suppose the system font probably won't be much different) in a visually pleasing manner?
i render my text in a canvas, using a paint i've assigned a custom typeface to.
the only command i've found that remotely relates to anti-aliasing is the "setAntiAlias" of the paint. but the text still looks horrible. almost as bad as no anti-aliasing at all in photoshop.
so... is there any way to do that?
and...
since this is for a game, bitmap fonts are a commonly offered alternative but as i want to have proper letter spacing, i'd have to program quite a complex bitmap font class to achieve that. because i haven't found an already existing one. only libgdx seems to contain one. but that one is tightly integrated with the library and a lot would have to be modified. so if anybody here knows of one that doesn't require that - that would also be of great help.
snippets from my code as reference although it's so basic and works perfectly fine that i don't imagine it's of relevance:
textPaint = new Paint();
textPaint.setTextSize(size);
textPaint.setAntiAlias(true);
textPaint.setARGB(0xff, 0xff, 0xff, 0xff);
textPaint.setTypeface(Typeface.createFromAsset(pView.getContext().getAssets(),
"fonts/cordia.ttf"));
...
canvas.drawText(text, (int)(dimension / 2 - textwidth / 2),
(int)(dimension / 2 - size / 2), textPaint);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为 Android 构建 freetype (http://freetype.org/)。它仅依赖于 zlib,并且生成的字体非常好。大多数专利问题最近已得到解决(专利已过期)。
You could build freetype (http://freetype.org/) for Android. It has only dependency against zlib and resulting fonts are very nice. Most patent issues were solved recently (patents expired).