Delay's Blog is the blog of David Anson, a Microsoft developer who works with the Silverlight, WPF, Windows Phone, and web platforms.
I posted the source code for a Silverlight implementation of the HTML 5 <canvas> API yesterday and some readers have been pretty interested in the concept/implementation. Thanks for all your comments and feedback!
Earlier today, kind user Fabien Ménager left a comment reporting an unhandled exception in the sample app and was generous enough to follow up by sending me the text of the exception. And as soon as I saw it, I knew the problem - both because of what it said and because of the language it was in!
Here, you give it a try:
System.FormatException: Le format de la chaîne d'entrée est incorrect.
context.fillStyle = "rgba(255, 127, 39, 0.8)";
The <canvas> specification allows for strings to be assigned to the fillStyle property, so it's necessary for Html5Canvas to parse that string. And it was the "0.8" alpha value that was the problem here. Attempting to parse that value with the user's culture settings will fail for a culture that uses ',' as the decimal separator. This is actually a common problem for text formats that are meant to be used in multiple cultures - and the typical solution is to require that the text always be written for some form of invariant culture (which typically adheres to the US's conventions). Therefore, the trivial fix was to parse that value according to the invariant culture (i.e., always use '.' as the decimal separator) instead of using the default parsing behavior which honors the user's settings.
Aside: The default behavior is nearly always what you want... except for very rarely when it's not... like this time! :)
To be clear, there is no functional change because of this - but now the code is just a little bit cleaner. :)
[Please click here to download the updated source code to Html5Canvas and its sample application.]
And while I was at it, I decided to post the sample application in runnable form just in case there were some people who wanted to watch the Hypotrochoid draw itself, but didn't want to compile the sample themselves.
[Click here or on the image below to run the sample application in your browser.]
It has been great to see all the interest in this project over the past couple of days - thanks very much for everyone's support, feedback, and kind words!!