Errata

HTML5 Canvas

Errata for HTML5 Canvas

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
1.7
First paragraph

This is the first paragraph of section 1.7. Safari To Go doesn't have page numbers. The text "left and down" should be "right and down".

Todd Chapman  Jun 08, 2011 
PDF, Other Digital Version Page 8
Second line

On the list of alternative ways to add a load event handler, there is an extra set of parenthesis in one example that makes it fail. They make the handler point to the result of the function instead of the function itself.

window.onload = canvasApp();

should be changed to:

window.onload = canvasApp;

Anonymous  May 28, 2011 
Printed Page 8
2nd line

window.onload = canvasApp();

should be

window.onload = canvasApp;

We don't want the *returned value* of calling canvasApp to be assigned to window.onload. We want the function object to be assigned. If we place "alert(window.onload)" in a script at the bottom of the body, the value of window.onload will be undefined if we say "window.onload = canvasApp();".

seltzerl  Jun 03, 2011 
Printed Page 8
top

For the third alternate event listener method, the code should be:
window.onload = canvasApp; //not window.onload = canvasApp();

If the parenthesis are included, JavaScript will execute the canvasApp method before the DOM is fully loaded.

Jeff Miller  Jun 27, 2011 
8
Top of the page second line.

The line at the top of page 8 that states,
window.onload = canvasapp();

Should not have the parentheses in the function name canvasapp. It should be like this:
window.onload = canvasapp;

James Butler  Jul 28, 2012 
Printed Page 10
2nd code block

In the function that tests for a dummy canvas created for the sole purpose of seeing whether browser support exists, the function creates a "testcanvas" element. This "testcanvas" element does not exist in HTML5 and it should be changed to "canvas". A better way to write that function would be:

function canvasSupport () {
return (typeof document.createElement('canvas').getContext !== "undefined");
}

Jeff Miller  Jun 27, 2011 
Printed Page 12
4th paragraph ("Finally, let's draw ...")

context.StrokeStyle

should be

context.strokeStyle

seltzerl  Jun 07, 2011 
Printed Page 12
4th paragraph ("Finally, let's draw ...")

The

context.StrokeStyle()

method doesn't exist.

context.strokeStyle

is a *property* that must be set on context.

seltzerl  Jun 07, 2011 
Printed Page 12
3rd paragraph ("Before you display ...")

A callback() function is mentioned as if there were a named function called "callback". The text should mention that a callback function must be specified and will be executed when the image has been loaded. The code itself has an *anonymous* callback function, as it should.

Note from the Author or Editor:
You are correct, the () should be removed.

seltzerl  Jun 07, 2011 
Printed Page 12
4th paragraph

"The four parameters for the strokeRect() method are the upper left x and y coordinates, and the lower right x and y coordinates." conflicts with the 1st paragraph of page 29 "strokeRect(x,y,width,height)". I believe the later is correct.

Mike Macewich  Jul 05, 2011 
Printed Page 15
2nd paragraph, last sentence

Should read " . . . Coordinates increasing in value to the RIGHT and down"

Steve Pretty  Jun 14, 2011 
Printed Page 15
1st paragraph

discussing coordinate system of the CanvasRenderingContext2d:
"left and down" should be "right and down"

Sam  Jun 14, 2011 
Printed Page 15
End of first paragraph

"a Cartesian coordinate system with 0,0 at the upper left and corner of the canvas, and coordinates increasing in value to the left and down."

should read

"a Cartesian coordinate system with 0,0 at the upper left and corner of the canvas, and coordinates increasing in value to the right and down."

Earbeep  Aug 28, 2011 
Printed Page 15
1st paragraph

The last line in the first paragraph states "... and coordinates increasing in value to the left and down." This should read "... and coordinates increasing to the right and down".

Anonymous  Jun 21, 2012 
Printed Page 15
Last line of first paragraph (not counting the code example at the top)

"and coordinates increasing in value to the left and down"
should be
"and coordinates increasing in value to the right and down"

Geoffrey Emmans  May 09, 2013 
Other Digital Version 18
Not sure abt. page#, because i read on KIndle - Paragraph "the 2D context"

Change coordinates increase down and left into increase down and right

Anonymous  Oct 14, 2011 
Printed Page 19
.

On page 19 the following line:
window.addEventListener("keyup",eventKeyPressed, true);

should be changed to:
window.addEventListener("keyup",eventKeyPressed, false);

(according to page 7 the parameter useCapture will always be set to false)

Anonymous  Jan 04, 2013 
Printed Page 22
First paragraph (after "Exporting Canvas to an Image")

We should see "toDataURL" with a capital R in place of "toDataUrL" :

Earlier, we briefly discussed the toDataUrL() property...

Antoine Proulx  Dec 26, 2011 
Other Digital Version 23
Code table

The

eventWindowLoaded()
{
canvasApp();
}

is defined twice.

hdgam3r  Aug 14, 2011 
PDF, Mobi Page 27
Note on page 27

The external link "http://dev.w3.org/html5/canvas-api/canvas-2d-api.html" is not opening in browser.

Anonymous  Sep 23, 2013 
PDF, Other Digital Version Page 32
Description of lineCap attributes

square
A rectangle with the length of the line width and the width of half the line width placed flat perpendicular to the edge of the line.

should be:
A rectangle with the length of the line width and the HEIGHT of half the line width placed flat perpendicular to the edge of the line.

Anonymous  Feb 16, 2012 
Printed Page 37
1st paragraph under The Canvas Clipping Region

I found the first line "Combing the save() and restore()..." very confusing, as I don't believe that save() nor restore() have anything to do with clipping per se. The save() in Example 2-5 saves the current non-clipped state of the canvas, and allows the subsequent restore() to revert back to not clipping anything, but since we haven't been introduced to save() and restore() yet, they detract from how to use clip(). Would suggest that this section be expanded to first explain clip(), and THEN show how to save()/restore() states. (Or, explain save() and restore() first, as they can be applied to things we have learned, then go on to clip().)
Thanks.

George Langley  Sep 01, 2011 
Printed Page 41
top of page and 1st paragraph

The globalCompositeOperation should be set to destination-over to get the results shown in Figure 2-11. Setting it to destination-atop, as printed, clips the image outside the newly-drawn square.

George Washington  Oct 16, 2011 
Other Digital Version 44
when talking about translation

Kindle version:

There is reference to the translation using the following code:

This line:
y+.05*height
Should be:
y+0.5*height

Also:
context.translate(x+.05*width, y+.05*height)
Should be:
context.translate(x+0.5*width, y+0.5*height)

The full code that is listed later, in example 2-9, does not have this error.

Brij Charan  Sep 24, 2011 
Printed Page 49

Canvas composition example does not turn out properly. Proper code is here ctx.globalCompositeOperation = "destination-over"; instead of "destination-atop"

Anonymous  Mar 26, 2014 
Printed Page 52
Top section

Both the rgb() and rgba() examples need quotes around them, same as the hex example. So:

context.fillStyle = rgb(255,0,0);

should be:

context.fillStyle = "rgb(255,0,0)";

AND

context.fillStyle = rgba(255,0,0);

should be:

context.fillStyle = "rgba(255,0,0)";

George Langley  Sep 04, 2011 
Printed Page 110
2

to change the mine type of a base 64 encoded image to jpeg format use "image/jpeg" not "image/jpg". (Tested in Safari and Chrome on OS X snow leopard.)

John O'Donnell  Jun 02, 2011 
Printed Page 126
.

on page 126:
function placeShip(ctx, obj, posX, posY, width, height) {
if (width && height) {
context.drawImage(obj, posX, posY, width, height);
} else {
context.drawImage(obj, posX, posY);
}
}

*should be fixed to:*


function placeShip(ctx, obj, posX, posY, width, height) {
if (width && height) {
ctx.drawImage(obj, posX, posY, width, height);
} else {
ctx.drawImage(obj, posX, posY);
}
}

Anonymous  Jan 04, 2013 
Printed Page 153
first code sample

In the description of zooming, we're instructed to change...
context.drawImage(photo, windowX, windowY, windowWidth, windowHeight, 0, 0, windowWidth, windowHeight);
...to this...
context.drawImage(photo, windowX, windowY, windowWidth, windowHeight, 0, 0, windowWidth * 0.5, windowHeight * 0.5);

The above code just reduces the destination copy size by half, which is more like scaling than zooming. Perhaps, this is more closer to what people would call zooming...
context.drawImage(photo, windowX, windowY, windowWidth * 0.5, windowHeight * 0.5, 0, 0, windowWidth, windowHeight);
...this would keep the viewport at 500 x 500 while making the image features larger.

BTW, great book so far. I'm having a lot of fun learning about the canvas. : )

John O'Donnell  Jun 04, 2011 
Printed Page 193
9nd line of code

The code should be:

tempRadius = Math.floor(Math.random()*(maxSize-minSize+1))+minSize;

since was said on page 188:

maxSize
The maximum radius length for any given ball

minSize
The minimum radius length for any given ball

Mauricio *Maujor* Samy Silva  Jul 06, 2011 
Printed Page 341
3rd paragraph

In determining the x location for the play slider we're told to use the following...
var sliderX = (playBackW, bH, controlStartX + bW) + (slideIncrement * audioElement.currentTime);

My question is: why are we using the comma operator in this calculation?
From my research, "(playBackW, bH, controlStartX+bW)" is equivalent to "(controlStartX+bW)". The comma operator just returns the result of the last expression in "(playBackW, bH, controlStartX+bW)" which is "controlStartX+bW".

Neither playBackW or bH are changed in this operation, or contribute to the value of sliderX. So why are they here?

I tried CH7EX5.html both ways and they appear to behave the same.

Note from the Author or Editor:
Yes, that is a pasting mistake.

John O'Donell  Jun 13, 2011 
Printed Page 354
Center

If one attempts to execute the Chapter 7 examples CH7EX6.html to CH7EX9.html, one will find a crash bug in all versions of IE7 - IE9 on the line "const STATE_INIT = 10;" listed on page 354.

There is no programmable example anywhere that demonstrates IE being able to play a sound without using controls or auto play. Would be nice to resolve this once and for all.

Mark Lowe  Nov 13, 2011