Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom font rendering on Android 4.0 (Ice cream sandwich)

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.

2.3.5

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);
}
like image 247
HandlerExploit Avatar asked Jan 27 '12 15:01

HandlerExploit


1 Answers

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);
    }
}
like image 115
HandlerExploit Avatar answered Oct 24 '22 23:10

HandlerExploit