Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

canvas

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.?

like image 606
chimerical Avatar asked May 01 '10 09:05

chimerical


People also ask

How do I align text in canvas?

To align HTML5 Canvas text, we can use the textAlign property of the canvas context, which can be set to start, end, left, center, or right. The alignment is relative to an imaginary vertical line at the x position of the text defind by fillText() or strokeText().

How do I display text in canvas HTML?

Drawing Text on the Canvas To draw text on a canvas, the most important property and methods are: font - defines the font properties for the text. fillText(text,x,y) - draws "filled" text on the canvas. strokeText(text,x,y) - draws text on the canvas (no fill)

What is fillText?

The fillText() method draws filled text on the canvas. The default color of the text is black. Tip: Use the font property to specify font and font size, and use the fillStyle property to render the text in another color/gradient. JavaScript syntax: context.fillText(text,x,y,maxWidth);

What is the tag canvas used for in HTML5?

The <canvas> tag in HTML is used to draw graphics on a web page using JavaScript. It can be used to draw paths, boxes, texts, gradients, and adding images. By default, it does not contain borders and text. Note: The <canvas> tag is new in HTML5.


1 Answers

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.

like image 96
brainjam Avatar answered Oct 02 '22 15:10

brainjam