Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix space for cache canvas for thin lines #3596

Merged
merged 3 commits into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
5 changes: 3 additions & 2 deletions src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down
2 changes: 1 addition & 1 deletion test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions test/unit/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down