Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Improper text scaling when draw text on canvas

Tags:

android

I am drawing formatted text on canvas using DynamicLayout, and I need to implement some sort of zooming. I tried to use canvas.scale(...) for it. But when text contains highlights, text is scaled inconsistent with background, like this:

scaled text with highlight

Code which draws text is very simple:

canvas.scale(zoom, zoom);
TextPaint textPaint = new TextPaint();
textPaint.setAntiAlias(true);
DynamicLayout layout = new DynamicLayout(text, textPaint, width,
                            Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, false);
layout.draw(canvas);

How to make it right way?

like image 548
Ilya Izhovkin Avatar asked Apr 18 '11 05:04

Ilya Izhovkin


1 Answers

I've solved this issue, setting textPaint.setSubpixelText(true);

like image 58
Ilya Izhovkin Avatar answered Sep 27 '22 19:09

Ilya Izhovkin