HTML and CSS Reference
In-Depth Information
By default, the fillText method uses 10px sans-serif as the
selected font. You can change this to your own font style by set-
ting the font property on the context using the same syntax as
CSS fonts (for example, ctx.font = 'italic 400 12px/2 helvet-
ica neue, sans-serif' ). When I call fillText , the text rendering
uses the same fillStyle that I set earlier (or uses the canvas
default). Equally strokeText uses strokeStyle .
Accessibility within the canvas element
One reason that canvas is so fast on today's optimised JIT
JavaScript interpreters is that it keeps no DOM. So, if you need
any kind of collision detection, for example, you need to do
all the bookkeeping yourself. There is no representation that
JavaScript can interrogate.
This also causes difficulty for accessibility. If your games are
keyboard- and mouse-accessible, that goes a long way to meet-
ing the needs of many. But for users with visual impairments,
there is nothing for assistive technology to hook into. Canvas
text is the same: bringing text into canvas means it ceases to
be text and is just pixels. It's even worse than <img> because at
least that can take alt text. Although the contents of the element
(the text between the canvas tags) can be changed with script
to refl ect the canvas text you're inserting with JavaScript, I'm not
optimistic that developers will do this.
An accessibility task force of the HTML Working Group is look-
ing at ways to enhance the accessibility of canvas. It's not
impossible; Flash 5 managed to add accessibility features. How-
ever, I recommend that for the time being, canvas shouldn't be
used for user interfaces or the only way to communicate infor-
mation. Something like the Filament Group's jQuery Visualize
plug-in is a good example of canvas being used to supplement
accessible information. It uses jQuery to inject a canvas element
to a page that graphs the information from a data table that's in
the markup. Assistive technologies have access to the raw data
table, while the information is supplemented with visual graphs
for sighted users.
NOTE JIT means Just in
Time compilation, a tech-
nique used to improve the run-
time performance of a program.
Search WWH ::

Custom Search