android 上的抗锯齿字体正确吗?

发布于 2024-11-15 10:21:59 字数 819 浏览 3 评论 0原文

有没有什么方法可以以视觉上令人愉悦的方式呈现带有自定义字体的文本(尽管我认为系统字体可能不会有太大不同)?

我使用分配了自定义字体的涂料在画布上渲染文本。

我发现的唯一与抗锯齿远程相关的命令是绘画的“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池予 2024-11-22 10:21:59

您可以为 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文