Skip to content
This repository has been archived by the owner on Apr 19, 2018. It is now read-only.

Implement better text rendering for the titles #46

Closed
rfgamaral opened this issue Jan 4, 2012 · 10 comments
Closed

Implement better text rendering for the titles #46

rfgamaral opened this issue Jan 4, 2012 · 10 comments

Comments

@rfgamaral
Copy link
Contributor

As soon as I tried ViewPagerIndicator on my app, I noticed the title text rendering didn't look that great. I looked into the code to understand how the titles were being drawn and what could I do about it. They are being rendered on a Canvas using the Paint object.

There's nothing more it can be done about it, anti-aliasing is already enabled on the Paint object. The only thing it could be done is to change this:

mPaintText = new Paint();

Into this:

mPaintText = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

And also remove mPaintText.setAntiAlias(true);, but this does not give a better solution. Instead, we get a "different" solution. The rendering is just different. If it's better or worse, it really depends on the eye of the beholder.

If you don't know, the meaning of LINEAR_TEXT_FLAG, in the words of Android Developer Roman Guy, is this:

"Text rendering uses a font cache containing bitmap representations of each glyph the application needs. Linear text basically lets you skip the font cache."

So, my suggestion is this:

Get rid of the Paint object and use TextViews instead for each title. The TextView rendering is much better, here's an example on my app's implementation of the ViewPagerIndicator:

I understand that this requires a big rewrite to the code, but in the end, the rendering will look much better and more consistent with the rest of the UI.

@rfgamaral
Copy link
Contributor Author

Today I have also noticed that most of the selected page title poor quality comes from the fact that the text is being drawn twice, one on top of the other. I couldn't fix that issue per se but I changed the code enough to see how it would look like if the title were to be drawn only once and looked much better (but not as good as a TextView render).

@protyposis
Copy link

Here's a simple fix for the issue: #48

@rfgamaral
Copy link
Contributor Author

Just to make it clear, that fix does not exactly fix the issue here described. It's only for the "double title drawing", not for the general poor text rendering quality.

@protyposis
Copy link

It's not the perfect solution but like you already said, still much better than before... I thought it would be a good temporary solution until the control has been rewritten to use TextViews.

@rfgamaral
Copy link
Contributor Author

Yes, but that's just for the selected title, the other ones don't have this "double drawing" problem.

But this is just a feature request to rewrite the control with TextViews, @JakeWharton hasn't pitched in yet so we don't know what he feels about such rewrite...

@JakeWharton
Copy link
Owner

See #34 for my view on the subject :)

@protyposis
Copy link

Alright. For people in need of a quick fix it might still be helpful ;)

@JakeWharton
Copy link
Owner

Agreed. Will merge tonight and probably release as well. I want to get this out before sweeping changes start happening.

@rfgamaral
Copy link
Contributor Author

Didn't notice #34, sorry...

I guess this issue can be closed then?

@JakeWharton
Copy link
Owner

Closed... but not dead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants