5

How do I skew the text generated by fillText() for the canvas tag in HTML5?

Would it be done the same way as MozTransform, webkitTransform, oTransform, transform, etc.?

1 Answer 1

10

Use a statement like

context.setTransform (1, -0.2, 0, 1, 0, 0);

See the spec for canvas transformations.

So where you'd use a CSS line like

-moz-transform:  matrix(a, c, b, d, tx, ty)

you can use the Javascript

context.setTransform (a, c, b, d, tx, ty);

An example of drawing text would be

context.font = '20px arial,sans-serif' ;
context.fillStyle = 'black' ;
context.setTransform (1, -0.2, 0, 1, 0, 0);
context.fillText ('your text', 10, 10) ;
context.setTransform (1, 0, 0, 1, 0, 0);

Note the final setTransform, which sets the transform back to the identity.

1
  • Thanks! Yeah, I was trying context.style.MozTransform = "skewx(45deg)"; and context.MozTransform = "skewx(45deg)"; (as well as the WebKit and Presto versions of that, but those weren't working with canvas.
    – chimerical
    May 3, 2010 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.