HTML5 Canvas 5 Gets New Features
HTML5 Canvas 5 Gets New Features
Written by David Conrad   
Tuesday, 03 April 2012

The 2D work horse of the web canvas is on its way to version 5 with some interesting new features. What is surprising is how sophisticated the features are  - suggesting that the Canvas element is now fairly mature.

Most of the additions fit into the "handy" but not essential category. For example there is now an Ellipse drawing command. You could create an ellipse before but not directly and it involved a lot of strange geometry with Bezier curves.



Another nice addition is the path primitive. You can now create a path object, define a path and then render the path to the Canvas. This means you can maintain multiple paths rather than just one.  You can also now use the SVG mini-language for a path e.g. "M 100,100 H 50 V 50" and so on. You can also apply SVG transformation to paths defined in this way.

Paths can also be rendered as dashed lines and you can fit text to a path which is the sort of facility you expect to find in an up market drawing package.

A major addition is the ability to define "hit regions". This allows you to specify an arbitrary area to respond to user events. In other words you can define hot-spots within a graphic. All you have to do is define a path and add a HitRegion before closing it. For example:

{ id: 'The First Button' });

This creates a rectangular area that will respond to a user clicking on it by generating an  event. Yes it acts like a button within your graphic. In future you wont have to create similar functionality by arranging click-able elements in front of the Canvas element. You can discover which area has been clicked by examining the event arguments passed to the Canvas event handler. You can also specify automatic cursor changes if the user moves the cursor over the hit region so that they know that it is a click-able area.

There are some other minor additions -more metrics in MeasureText, the ability to transform a pattern, a reset for the clip region and transform.

Let's hope that we see the new Canvas features rolled out in browsers as soon as possible.



More Information

canvas v5 API additions

WHATWG Weekly: Path objects for canvas and creating paths through SVG syntax


Related Articles

Chrome 18 Now With 2D GPU Graphics

Getting Started with Box2D in JavaScript

SVG, JavaScript and the DOM

Getting started with SVG for HTML5

A Programmer's Guide to Canvas


blog comments powered by Disqus


To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter, Linkedin or Facebook or sign up for our weekly newsletter.



Node.js Foundation Releases First Joint Code

Node v4.0.0 is the first code release from the reunited io.js and node.js communities, following last year's fork of the project. The breakaway group returned due to a new governance model under  [ ... ]

NSA Codebreaker Challenge 3.0

NSA, the United States National Security Agency, is challenging university students in the US to exercise their reverse engineering and low-level code analysis skills while working on a fictitious, ye [ ... ]

More News

Last Updated ( Tuesday, 03 April 2012 )

RSS feed of news items only
I Programmer News
Copyright © 2015 All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.