Fix empty image drawing (#1605)

Empty raster (for example coming from path with empty bound
rasterization, ...) drawing threw error.
This change prevent raster drawing in that case.
Closes #1320
This commit is contained in:
Samuel Asensi 2018-11-14 11:21:40 +01:00 committed by Jürg Lehni
parent 8202f78453
commit 2968faad51
3 changed files with 16 additions and 1 deletions

View file

@ -1,5 +1,13 @@
# Change Log
## Prebuilt version
### Fixed
- Fix empty image drawing (#1320).
### Added
## `0.11.8`
### News

View file

@ -753,7 +753,8 @@ var Raster = Item.extend(/** @lends Raster# */{
_draw: function(ctx, param, viewMatrix) {
var element = this.getElement();
if (element) {
// Only draw if image is not empty (#1320).
if (element && element.width > 0 && element.height > 0) {
// Handle opacity for Rasters separately from the rest, since
// Rasters never draw a stroke. See Item#draw().
ctx.globalAlpha = this._opacity;

View file

@ -945,3 +945,9 @@ test('Children global matrices are cleared after parent transformation', functio
group.translate(100, 0);
equals(item.localToGlobal(item.getPointAt(0)), new Point(100, 100));
});
test('Item#rasterize() with empty bounds', function() {
new Path.Line([0, 0], [100, 0]).rasterize();
view.update();
expect(0);
});