Save zero width and height on bitmap's imageData object

This commit is contained in:
Katie Broida 2019-03-05 15:22:20 -05:00
parent 2f5c37910f
commit 75723a7ae2
2 changed files with 12 additions and 3 deletions

View file

@ -329,10 +329,10 @@ const getHitBounds = function (raster) {
let left = 0;
let right = imageData.width;
while (bottom - 1 > top && rowBlank_(imageData, width, bottom - 1)) --bottom;
while (top < bottom && rowBlank_(imageData, width, top)) ++top;
while (right - 1 > left && columnBlank_(imageData, width, right - 1, top, bottom)) --right;
while (bottom - 1 > top && rowBlank_(imageData, width, bottom - 1)) --bottom;
while (left < right && columnBlank_(imageData, width, left, top, bottom)) ++left;
while (right - 1 > left && columnBlank_(imageData, width, right - 1, top, bottom)) --right;
return new paper.Rectangle(left, top, right - left, bottom - top);
};

View file

@ -89,9 +89,18 @@ const UpdateImageHOC = function (WrappedComponent) {
}
}
const rect = getHitBounds(plasteredRaster);
const imageData = plasteredRaster.getImageData(rect);
// If the bitmap has a zero width or height, save this information
// since zero isn't a valid value for on imageData objects' widths and heights.
if (rect.width === 0 || rect.height === 0) {
imageData.sourceWidth = rect.width;
imageData.sourceHeight = rect.height;
}
this.props.onUpdateImage(
false /* isVector */,
plasteredRaster.getImageData(rect),
imageData,
(ART_BOARD_WIDTH / 2) - rect.x,
(ART_BOARD_HEIGHT / 2) - rect.y);