Search code examples
kineticjsretina-displayclipping

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


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 Non-Retina

Pixel Aspect = 2 Retina

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.


Solution

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