Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  135] [ 4]  / answers: 1 / hits: 19480  / 16 Years ago, sun, april 5, 2009, 12:00:00

I've been experimenting with using the <canvas> tag for drawing simple diagrams and charts, and so far it's pretty easy to work with. I have one issue thought. I can't figure out how to draw text on a <canvas> in Safari. In Firefox 3.0, I can do this:



Chart.prototype.drawTextCentered = function(context, text, x, y, font, color) {
if (context.mozDrawText) {
context.save();
context.fillStyle = color;
context.mozTextStyle = font;
x -= 0.5 * context.mozMeasureText(text);
context.translate(x, y);
context.mozDrawText(text);
context.restore();
}
}


I've seen reference to a fillText() method in Apple's Safari docs, but it doesn't appear to be supported in Safari 3.2. Is this just something that's currently missing, or is it some well-kept secret?


More From » safari

 Answers
104

I don't believe that Safari 3.2 supports rendering text in the canvas.



According to this blog, Safari 4 beta supports rending text to the canvas, based on the HTML 5 canvas text APIs.



edit: I have confirmed that the following snippet works in Safari 4 beta:



<canvas id=canvas></canvas>
<script>
var context = document.getElementById(canvas).getContext(2d);
context.fillText(Hello, world!, 10, 10);
</script>

[#99742] Wednesday, April 1, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lindsay

Total Points: 402
Total Questions: 109
Total Answers: 109

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;