开发者

anti-alias fonts on android properly?

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 commonl开发者_如何转开发y 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);


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜