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}
|
||||
*/
|
||||
this.set = function (width, height, units) {
|
||||
_data = util.calcCrop(canvas.getImage(), width, height);
|
||||
_data.dim.units = units;
|
||||
var oldData = _data;
|
||||
|
||||
_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();
|
||||
this.getGores().reset();
|
||||
this.getRulers().reset();
|
||||
|
||||
if (canvas.getImage().__cropped) {
|
||||
|
||||
} else {
|
||||
if (!canvas.getImage().__cropped && !keepCropping) {
|
||||
canvas.getApertures().setTransparent(true);
|
||||
canvas.getImageData().removeCropData();
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @param {Integer} width
|
||||
* @param {Integer} height
|
||||
* @param {fabric.Image} obj
|
||||
* @param {int} width
|
||||
* @param {int} height
|
||||
* @param {string} units
|
||||
* @return {Object}
|
||||
* axis: STRING,
|
||||
* dim: OBJECT( width: NUMBER, height: NUMBER),
|
||||
@@ -10,7 +12,7 @@
|
||||
* height: NUMBER,
|
||||
* ppmm: NUMBER
|
||||
*/
|
||||
function calcCrop(obj, width, height) {
|
||||
function calcCrop(obj, width, height, units) {
|
||||
var cropRatio = width / height;
|
||||
var objRatio = obj.width / obj.height;
|
||||
|
||||
@@ -19,7 +21,8 @@ function calcCrop(obj, width, height) {
|
||||
axis: objRatio > cropRatio ? 'x' : 'y',
|
||||
dim: {
|
||||
width: Number(width),
|
||||
height: Number(height)
|
||||
height: Number(height),
|
||||
units: units
|
||||
},
|
||||
width: obj.width * obj.scaleX,
|
||||
height: obj.height * obj.scaleY,
|
||||
@@ -33,7 +36,7 @@ function calcCrop(obj, width, height) {
|
||||
returnValue.height /= cropRatio / objRatio;
|
||||
}
|
||||
|
||||
// Pixels per milimeter
|
||||
// Pixels per millimeter
|
||||
returnValue.ppmm = returnValue.width / ((returnValue.dim.width * obj.scaleX) * 10);
|
||||
|
||||
return returnValue;
|
||||
|
||||
Reference in New Issue
Block a user