diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 99a556c1a3e..b1726c71cb8 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -860,8 +860,8 @@ width = dim.x * zoomX, height = dim.y * zoomY; return { - width: width, - height: height, + width: Math.ceil(width) + 2, + height: Math.ceil(height) + 2, zoomX: zoomX, zoomY: zoomY }; diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index b48eb6bbc2b..8c050048021 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -404,8 +404,9 @@ */ _getCacheCanvasDimensions: function() { var dim = this.callSuper('_getCacheCanvasDimensions'); - dim.width += 2 * this.fontSize; - dim.height += 2 * this.fontSize; + var fontSize = Math.ceil(this.fontSize) * 2; + dim.width += fontSize; + dim.height += fontSize; return dim; }, diff --git a/test/unit/group.js b/test/unit/group.js index cc6bb5481e5..e697a58485f 100644 --- a/test/unit/group.js +++ b/test/unit/group.js @@ -544,7 +544,7 @@ var dims = obj._getCacheCanvasDimensions(); g1.scaleX = 2; var dims2 = obj._getCacheCanvasDimensions(); - equal(dims2.width, dims.width * g1.scaleX, 'width of cache has increased with group scale'); + equal((dims2.width - 2), (dims.width - 2) * g1.scaleX, 'width of cache has increased with group scale'); }); test('test group transformMatrix', function() { diff --git a/test/unit/object.js b/test/unit/object.js index 27b9ccbfd47..efafec647bf 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -1505,29 +1505,29 @@ test('_getCacheCanvasDimensions returns dimensions and zoom for cache canvas', function() { var object = new fabric.Object({ width: 10, height: 10, strokeWidth: 0 }); var dims = object._getCacheCanvasDimensions(); - deepEqual(dims, { width: 10, height: 10, zoomX: 1, zoomY: 1 }, 'if no scaling is applied cache is as big as object'); + deepEqual(dims, { width: 12, height: 12, zoomX: 1, zoomY: 1 }, 'if no scaling is applied cache is as big as object'); object.strokeWidth = 2; dims = object._getCacheCanvasDimensions(); - deepEqual(dims, { width: 12, height: 12, zoomX: 1, zoomY: 1 }, 'cache contains the stroke'); + deepEqual(dims, { width: 14, height: 14, zoomX: 1, zoomY: 1 }, 'cache contains the stroke'); object.scaleX = 2; object.scaleY = 3; dims = object._getCacheCanvasDimensions(); - deepEqual(dims, { width: 24, height: 36, zoomX: 2, zoomY: 3 }, 'cache is as big as the scaled object'); + deepEqual(dims, { width: 26, height: 38, zoomX: 2, zoomY: 3 }, 'cache is as big as the scaled object'); }); test('_updateCacheCanvas check if cache canvas should be updated', function() { var object = new fabric.Object({ width: 10, height: 10, strokeWidth: 0 }); object._createCacheCanvas(); - equal(object.cacheWidth, 10, 'current cache dimensions are saved'); - equal(object.cacheHeight, 10, 'current cache dimensions are saved'); + equal(object.cacheWidth, 12, 'current cache dimensions are saved'); + equal(object.cacheHeight, 12, 'current cache dimensions are saved'); equal(object._updateCacheCanvas(), false, 'second execution of cache canvas return false'); object.scaleX = 2; equal(object._updateCacheCanvas(), true, 'if scale change, it returns true'); - equal(object.cacheWidth, 20, 'current cache dimensions is updated'); + equal(object.cacheWidth, 22, 'current cache dimensions is updated'); equal(object.zoomX, 2, 'current scale level is saved'); object.width = 2; equal(object._updateCacheCanvas(), true, 'if dimension change, it returns true'); - equal(object.cacheWidth, 4, 'current cache dimensions is updated'); + equal(object.cacheWidth, 6, 'current cache dimensions is updated'); object.strokeWidth = 2; equal(object._updateCacheCanvas(), true, 'if strokeWidth change, it returns true'); });