在Android 4.0(冰淇淋三明治)自定义字体渲染 [英] Custom font rendering on Android 4.0 (Ice cream sandwich)

查看:150
本文介绍了在Android 4.0(冰淇淋三明治)自定义字体渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试使用Helvetica Neue字体作为Android 4.0的它的主要字体我已经发现有在字体渲染不一致相比,多个不同版本的Andr​​oid的应用程序。我们在2.1,2.2.2,2.3.5,3.2,4.0和4.0.3具有相同的结果,每次测试这一点。我们也做这些测试用不同的字体的二进制文件具有相同的结果。

任何输入或解决方法将AP preciated。

下面是一个示例应用程序来显示意外的结果的屏幕截图,第一是2.3.5第二个是4.0.3

  @覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);

    TextView中的TextView =新的TextView(本);
    textView.setText(Lorem存有悲坐阿梅德,consectetur adipisicing ELIT,sed的做eiusmod tempor incididunt UT labore等dolore麦格纳aliqua。UT斯达康enim广告微量veniam,QUIS nostrud实习ullamco laboris妮斯UT aliquip前EA commodo consequat。DUIS奥特irure悲在重新prehenderit在voluptate velit ESSE cillum dolore欧盟fugiat法无pariatur Excepteur SINT occaecat cupidatat非proident,必须遵守的过失魁正式开通了deserunt mollit阿尼姆ID EST laborum)。
    textView.setTypeface(Typeface.createFromAsset(getAssets(),黑体Neue.ttf));
    textView.setTextSize(9);
    的setContentView(TextView的);
}
 

解决方案

虽然我们从来没有找到一个解决的Helvetica字体渲染错误,我们能够说服客户切换到Roboto后,我们向他们展示了一个Galaxy Nexus的错误。


更新:

 公共类TextViewCompat扩展TextView的{

    公共TextViewCompat(上下文的背景下){
        超(上下文);
        设置(上下文,空,0);
    }

    公共TextViewCompat(上下文的背景下,ATTRS的AttributeSet){
        超(背景下,ATTRS);
        设置(上下文,ATTRS,0);
    }

    公共TextViewCompat(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
        超(背景下,ATTRS,defStyle);
        设置(背景下,ATTRS,defStyle);
    }

    私人无效设置(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
        setPaintFlags(getPaintFlags()| Paint.SUBPIXEL_TEXT_FLAG);
    }
}
 

While testing an application that uses Helvetica Neue as its primary font on Android 4.0 I have found that there is an inconsistency in typeface rendering compared to multiple different version of Android. We tested this on 2.1, 2.2.2, 2.3.5, 3.2, 4.0, and 4.0.3 with the same results every time. We also did these tests with different typeface binaries with the same results.

Any input or workarounds would be appreciated.

Below is a screenshot from an example application to show the undesired results, the first is 2.3.5 the second is 4.0.3.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView textView = new TextView(this);
    textView.setText("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
    textView.setTypeface(Typeface.createFromAsset(getAssets(), "Helvetica Neue.ttf"));
    textView.setTextSize(9);
    setContentView(textView);
}

解决方案

Although we never found a solution to the Helvetica rendering bug we were able to convince the client to switch to Roboto after we showed them the bug on a Galaxy Nexus.


Update:

public class TextViewCompat extends TextView {

    public TextViewCompat(Context context) {
        super(context);
        setup(context, null, 0);
    }

    public TextViewCompat(Context context, AttributeSet attrs) {
        super(context, attrs);
        setup(context, attrs, 0);
    }

    public TextViewCompat(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setup(context, attrs, defStyle);
    }

    private void setup(Context context, AttributeSet attrs, int defStyle) {
        setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    }
}

这篇关于在Android 4.0(冰淇淋三明治)自定义字体渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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