KineticJS : scaling issue while using custom clipFunc on 2x pixel aspect display

扶醉桌前 提交于 2019-12-14 02:20:06

问题


Kineticjs automatically adopts canvas size and whole graphics on Retina displays, so all looks sharp and clean without blurry pixelation. But thing goes wrong when I try to use custom clipping function.

Here is some code

this.layerOne = new Kinetic.Layer();
this.layerTwo = new Kinetic.Layer({
 clipFunc : function(c){
 var ctx = c.getContext();
  ctx.rect(0,0,width,height);
 }
});

If I add shape on layerOne it will be rendered perfectly considering 2x pixel aspect, but the same shape added on layerTwo will be rendered ignoring pixel aspect, thus not beign scaled up by 2. As a result shapes on layer with clipFunc becomes 2x smaller.

How can I resolve this problem?

P.S. Here is some quick example I've made on JS Fiddle

  • Light Green is background, Dark Green is 100 pixel square, both on non cropped layer;
  • Light Yellow is 100 pixel square, and pink is rectangle with width equals to stage, they are on cropped layer;

On normal screen we see Yellow's width is equal Light Green's width, and properly cropped. Pink is not visible because is being out of clipping region.

On Retina display we see Yellow is smaller than Dark Green and Pink is particularly visible. Dark Green and Pink shows us that cropping rectange has normalized dimentions for Retina, but all graphics scaled down.

Standart

Pixel Aspect = 2

UPDATE: Same in Chrome on my Galaxy Nexus
UPDATE: Everything looks perfect in Safari on OS X! Other major browsers (FF, O, Chrome) on OS X are affected.


回答1:


looks like a bug, I'll add this to my todo list. The fix will be to scale the path according to the pixel ratio, before rendering it. i.e. if the pixel ratio is 2, then we need to scale the path by a factor of 2.




回答2:


To fix this bug I've modified kinetic-v4.5.5.js source as mentioned in this comment



来源:https://stackoverflow.com/questions/17077427/kineticjs-scaling-issue-while-using-custom-clipfunc-on-2x-pixel-aspect-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!