admin管理员组文章数量:1415673
Running the script below in IE9 produces a buttery smooth animation. But the same script when run in Chrome20 (win & mac) produces a wobbly animation. How can i fix this?
Also I would appreciate if someone could provide a definite answer to the following related questions as well.
Does chrome support sub-pixel text rendering?
Does chrome support GPU based text rendering?
If so then please mention the exact version and OS the feature was added in.
<canvas id="myCanvas" width="1000" height="500" style="border:1px solid #d3d3d3;">
</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var i=12;
function f() {
ctx.clearRect(0,0,1000,500);
ctx.font=i + "px Arial";
ctx.fillText("Hello World",10,350);
i+=0.1;
}
setInterval("f()", 16);
</script>
In IE9 initially the animation is also a bit wobbly but after a few iterations it bees extremely smooth.
Running the script below in IE9 produces a buttery smooth animation. But the same script when run in Chrome20 (win & mac) produces a wobbly animation. How can i fix this?
Also I would appreciate if someone could provide a definite answer to the following related questions as well.
Does chrome support sub-pixel text rendering?
Does chrome support GPU based text rendering?
If so then please mention the exact version and OS the feature was added in.
http://jsbin./ijegam/2
<canvas id="myCanvas" width="1000" height="500" style="border:1px solid #d3d3d3;">
</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var i=12;
function f() {
ctx.clearRect(0,0,1000,500);
ctx.font=i + "px Arial";
ctx.fillText("Hello World",10,350);
i+=0.1;
}
setInterval("f()", 16);
</script>
In IE9 initially the animation is also a bit wobbly but after a few iterations it bees extremely smooth.
Share Improve this question edited Jul 6, 2013 at 20:27 Naximus asked Jul 29, 2012 at 22:15 NaximusNaximus 6298 silver badges19 bronze badges 1- This is an anti aliasing bug I think – starbeamrainbowlabs Commented Jul 30, 2012 at 10:37
2 Answers
Reset to default 2It seems like your answer is yes: http://trac.webkit/wiki/LayoutUnit
However, when I play with text resizing really slow, I notice that the text grows along the X, then the Y, then the X, then the Y, creating that choppiness, so maybe there is some other issue at play...
Try using requestAnimationFrame with the cross-browser shim instead of a timeout: http://creativejs./resources/requestanimationframe/
I created this to play with: http://codepen.io/anon/pen/iCABx
Hopefully that helps in some way.
Does chrome support GPU based text rendering?
In this case, the text is a drawing on the canvas. Canvas2D hardware accelerated rendering was added in Chrome 18: http://en.wikipedia/wiki/Google_Chrome#Release_history Other than the canvas, I can't say for sure, but I know CSS 3D hardware acceleration exists.
If your text is just a single message a reasonable solution could be to just create a big text in a separate hidden canvas object and then drawing this as an image with the scaling you need.
Note also that scaling a text by changing the font size is quite different from just applying a transformation on it. In other words in general the shape of an 8pt font is not just the same of a 16pt font with everything scaled down 50%... the reason is for example that for readability and aesthetics you want the three legs of a small "m" character to by on exact pixel boundaries and equally sized and spaced... clearly this is not possible by simply shrinking the coordinates and the difference (especially on small fonts) can be huge.
If an animation of a text with smooth slow zoomming doesn't "wobble" then it simply means that the rendering (as text) is poor quality. But probably in that case what you want is a zooming on the image of a text... and that's what's the hidden canvas is.
本文标签: javascriptHow to smoothly animate scaling of HTML5 canvas fillText()Stack Overflow
版权声明:本文标题:javascript - How to smoothly animate scaling of HTML5 canvas fillText() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745198852a2647273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论