P5-1492: Fix for image cropping moves to center after switching between inch and cm
This commit is contained in:
@@ -131,15 +131,20 @@ function Viewport(canvas) {
|
|||||||
* @return {Viewport}
|
* @return {Viewport}
|
||||||
*/
|
*/
|
||||||
this.set = function (width, height, units) {
|
this.set = function (width, height, units) {
|
||||||
_data = util.calcCrop(canvas.getImage(), width, height);
|
var oldData = _data;
|
||||||
_data.dim.units = units;
|
|
||||||
|
_data = util.calcCrop(canvas.getImage(), width, height, units);
|
||||||
|
|
||||||
|
var keepCropping = (oldData && (Math.abs(oldData.dim.width / oldData.dim.height - width / height) <= 0.01));
|
||||||
|
if (keepCropping) {
|
||||||
|
canvas.getImageData().setCropData();
|
||||||
|
}
|
||||||
|
|
||||||
apply();
|
apply();
|
||||||
this.getGores().reset();
|
this.getGores().reset();
|
||||||
this.getRulers().reset();
|
this.getRulers().reset();
|
||||||
|
|
||||||
if (canvas.getImage().__cropped) {
|
if (!canvas.getImage().__cropped && !keepCropping) {
|
||||||
|
|
||||||
} else {
|
|
||||||
canvas.getApertures().setTransparent(true);
|
canvas.getApertures().setTransparent(true);
|
||||||
canvas.getImageData().removeCropData();
|
canvas.getImageData().removeCropData();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Integer} width
|
* @param {fabric.Image} obj
|
||||||
* @param {Integer} height
|
* @param {int} width
|
||||||
|
* @param {int} height
|
||||||
|
* @param {string} units
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
* axis: STRING,
|
* axis: STRING,
|
||||||
* dim: OBJECT( width: NUMBER, height: NUMBER),
|
* dim: OBJECT( width: NUMBER, height: NUMBER),
|
||||||
@@ -10,7 +12,7 @@
|
|||||||
* height: NUMBER,
|
* height: NUMBER,
|
||||||
* ppmm: NUMBER
|
* ppmm: NUMBER
|
||||||
*/
|
*/
|
||||||
function calcCrop(obj, width, height) {
|
function calcCrop(obj, width, height, units) {
|
||||||
var cropRatio = width / height;
|
var cropRatio = width / height;
|
||||||
var objRatio = obj.width / obj.height;
|
var objRatio = obj.width / obj.height;
|
||||||
|
|
||||||
@@ -19,7 +21,8 @@ function calcCrop(obj, width, height) {
|
|||||||
axis: objRatio > cropRatio ? 'x' : 'y',
|
axis: objRatio > cropRatio ? 'x' : 'y',
|
||||||
dim: {
|
dim: {
|
||||||
width: Number(width),
|
width: Number(width),
|
||||||
height: Number(height)
|
height: Number(height),
|
||||||
|
units: units
|
||||||
},
|
},
|
||||||
width: obj.width * obj.scaleX,
|
width: obj.width * obj.scaleX,
|
||||||
height: obj.height * obj.scaleY,
|
height: obj.height * obj.scaleY,
|
||||||
@@ -33,7 +36,7 @@ function calcCrop(obj, width, height) {
|
|||||||
returnValue.height /= cropRatio / objRatio;
|
returnValue.height /= cropRatio / objRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pixels per milimeter
|
// Pixels per millimeter
|
||||||
returnValue.ppmm = returnValue.width / ((returnValue.dim.width * obj.scaleX) * 10);
|
returnValue.ppmm = returnValue.width / ((returnValue.dim.width * obj.scaleX) * 10);
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user