I am rotating and scaling canvas using canvas.setMatrix()
and then drawing text on canvas using canvas.drawText();
. That's working as expected but when I try to draw text that contains emojis (android device's default emojis), they don't get rotated. Everything else in the text gets rotated as expected. Also drawing + scaling works as expected for emojis, it's just the rotating that doesn't work.
I really would like to avoid solutions where emoji is drawn on another bitmap and then that bitmap drawn on the canvas with rotation applied.
Text with 0 rotation: https://i.gyazo.com/68ca0a13a1178e1614c976d4f041c8ee.png Text with rotation applied: https://i.gyazo.com/3f9f9150b89e387e64cb9fc79737ca7d.png
To make clear, the emoji is part of the String element.
if(text != null && text.length > 0){
canvas.save();
canvas.setMatrix(getDrawingMatrix(rect)); //Get a matrix with scaling, rotation & transformation applied.
for(int i = 0; i < text.length; i++){ //text is a string array containing multiple lines of text.
String string = text[i];
if(string.length() > 0){
canvas.drawText(string, 0, (i)*paint.descent() - (i+1)*paint.ascent(), paint); //each line has different y-value.
}
}
canvas.restore(); //after drawing the matrix is restored to default.
}
Ohh, just found out this is actually duplicate of: emojis not rotating with canvas