From 4bc3b5b624083799b675c9b716f2ada4b3fae6bb Mon Sep 17 00:00:00 2001 From: DD Liu Date: Mon, 29 Oct 2018 11:01:53 -0400 Subject: [PATCH] Cut off text2 (#744) --- src/helper/bitmap.js | 2 +- src/helper/tools/text-tool.js | 2 +- src/hocs/update-image-hoc.jsx | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/helper/bitmap.js b/src/helper/bitmap.js index 136ba1d8..5b5ec415 100644 --- a/src/helper/bitmap.js +++ b/src/helper/bitmap.js @@ -369,7 +369,7 @@ const convertToBitmap = function (clearSelectedItems, onUpdateImage) { // Export svg const guideLayers = hideGuideLayers(true /* includeRaster */); - const bounds = paper.project.activeLayer.bounds; + const bounds = paper.project.activeLayer.drawnBounds; const svg = paper.project.exportSVG({ bounds: 'content', matrix: new paper.Matrix().translate(-bounds.x, -bounds.y) diff --git a/src/helper/tools/text-tool.js b/src/helper/tools/text-tool.js index 24b779d2..6b77a1aa 100644 --- a/src/helper/tools/text-tool.js +++ b/src/helper/tools/text-tool.js @@ -386,7 +386,7 @@ class TextTool extends paper.Tool { if (!this.textBox || !this.textBox.parent) return; // @todo get crisp text https://github.com/LLK/scratch-paint/issues/508 - const textRaster = this.textBox.rasterize(72, false /* insert */); + const textRaster = this.textBox.rasterize(72, false /* insert */, this.textBox.drawnBounds); this.textBox.remove(); this.textBox = null; getRaster().drawImage( diff --git a/src/hocs/update-image-hoc.jsx b/src/hocs/update-image-hoc.jsx index eda819bc..f7997c5e 100644 --- a/src/hocs/update-image-hoc.jsx +++ b/src/hocs/update-image-hoc.jsx @@ -59,7 +59,7 @@ const UpdateImageHOC = function (WrappedComponent) { } // Anything that is selected is on the vector layer waiting to be committed to the bitmap layer. // Plaster the selection onto the raster layer before exporting, if there is a selection. - const plasteredRaster = getRaster().getSubRaster(getRaster().bounds); + const plasteredRaster = getRaster().getSubRaster(getRaster().bounds); // Clone the raster layer plasteredRaster.remove(); // Don't insert const selectedItems = getSelectedLeafItems(); if (selectedItems.length === 1) { @@ -80,10 +80,11 @@ const UpdateImageHOC = function (WrappedComponent) { } else if (item instanceof paper.Shape && item.type === 'ellipse') { commitOvalToBitmap(item, plasteredRaster); } else if (item instanceof paper.PointText) { - const textRaster = item.rasterize(72, false /* insert */); + const bounds = item.drawnBounds; + const textRaster = item.rasterize(72, false /* insert */, bounds); plasteredRaster.drawImage( textRaster.canvas, - new paper.Point(Math.floor(textRaster.bounds.x), Math.floor(textRaster.bounds.y)) + new paper.Point(Math.floor(bounds.x), Math.floor(bounds.y)) ); } } @@ -103,7 +104,7 @@ const UpdateImageHOC = function (WrappedComponent) { // Export at 0.5x scaleWithStrokes(paper.project.activeLayer, .5, new paper.Point()); - const bounds = paper.project.activeLayer.bounds; + const bounds = paper.project.activeLayer.drawnBounds; // @todo (https://github.com/LLK/scratch-paint/issues/445) generate view box this.props.onUpdateImage( true /* isVector */,