Skip to content

Commit

Permalink
fix: fixed exist cropzone bug in toDataUrl image (fix #237 #224) (#300)
Browse files Browse the repository at this point in the history
* feat: webpack version up

* feat: cssExtract plugin update

* feat: karma.conf update middle commit

* feat: karma.conf update middle commit

* feat: webpack with karma version update middle commit

* update package-lock

* feat: karma version update 4.x.x

* fix: fixed all vulnerabilities at package.json

* fix: added mode property webpack config

* feat: added dist directory for npm istall test

* test complete with delete dist directory

* restore un nessary fix point

* apply code review at webpack config

* fix: fixed fabricjs install guide

* fix: fix karma.conf.js for css-loader webpack config

* fix: fixed exist cropzone bug in toDataUrl image

* apply code review
  • Loading branch information
jinwoo-kim-nhn committed Jan 17, 2020
1 parent c166a55 commit 9578538
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/js/component/cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ class Cropper extends Component {
fabric.util.removeListener(document, 'keyup', this._listeners.keyup);
}

/**
* Change cropzone visible
* @param {boolean} visible - cropzone visible state
*/
changeVisibility(visible) {
if (this._cropzone) {
this._cropzone.set({visible});
}
}

/**
* onMousedown handler in fabric canvas
* @param {{target: fabric.Object, e: MouseEvent}} fEvent - Fabric event
Expand Down
9 changes: 3 additions & 6 deletions src/js/extension/cropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Cropzone = fabric.util.createClass(fabric.Rect, /** @lends Cropzone.protot
});
},

_renderCropzone() {
_renderCropzone(ctx) {
const cropzoneDashLineWidth = 7;
const cropzoneDashLineOffset = 7;

Expand All @@ -57,7 +57,6 @@ const Cropzone = fabric.util.createClass(fabric.Rect, /** @lends Cropzone.protot
const originalScaleY = originalFlipY / this.scaleY;

// Set original scale
const ctx = this.canvas.getContext();
ctx.scale(originalScaleX, originalScaleY);

// Render outer rect
Expand Down Expand Up @@ -90,12 +89,10 @@ const Cropzone = fabric.util.createClass(fabric.Rect, /** @lends Cropzone.protot
* @private
* @override
*/
_render() {
const ctx = this.canvas.getContext();

_render(ctx) {
this.callSuper('_render', ctx);

this._renderCropzone();
this._renderCropzone(ctx);
},

/**
Expand Down
8 changes: 7 additions & 1 deletion src/js/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ class Graphics {
* @returns {string} A DOMString containing the requested data URI.
*/
toDataURL(options) {
return this._canvas && this._canvas.toDataURL(options);
const cropper = this.getComponent(components.CROPPER);
cropper.changeVisibility(false);

const dataUrl = this._canvas && this._canvas.toDataURL(options);
cropper.changeVisibility(true);

return dataUrl;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/graphics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ describe('Graphics', () => {
graphics.stopDrawingMode();
});

it('Cropzone must be hidden initially and then redisplayed after completion at toDataURL is executed with a cropzone present', () => {
const cropper = graphics.getComponent(components.CROPPER);
spyOn(cropper, 'changeVisibility');

graphics.startDrawingMode(drawingModes.CROPPER);
graphics.toDataURL();

expect(cropper.changeVisibility.calls.allArgs()).toEqual([[false], [true]]);
});

it('can set brush setting into LINE_DRAWING, FREE_DRAWING', () => {
graphics.startDrawingMode(drawingModes.LINE_DRAWING);
graphics.setBrush({
Expand Down

0 comments on commit 9578538

Please sign in to comment.