Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #71 from iFixit/complexity-cleanup
Browse files Browse the repository at this point in the history
Easy complexity cleanup
  • Loading branch information
djmetzle authored Sep 7, 2022
2 parents 941654b + f53f99d commit 12a55d6
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions ImageMarkupBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,37 +108,38 @@ function ImageMarkupBuilder(fabricCanvas) {

//Apply markup to blank canvas
applyMarkup(callback);
} else {
finalWidth = innerJSON.finalDimensions.width;
if (isNode) {
fabricCanvas.setBackgroundColor("#FFFFFF");
var dimensions = innerJSON.dimensions;
var img = {
width: dimensions.width,
height: dimensions.height,
originX: "left",
originY: "top",
src: "file://" + path.resolve(innerJSON.sourceFile),
};

Fabric.Image.fromObject(img, function (fimg, err) {
if (!fimg || err) throw err;
var top = -imageOffset.y;
if (top % 1 != 0) {
top -= 0.5;
}
var left = -imageOffset.x;
if (left % 1 != 0) {
left -= 0.5;
}

fabricCanvas.add(fimg.set("top", top).set("left", left));
applyMarkup(callback);
});
} else {
throw new Error("Source files not supported on frontend");
}
return;
}

if (!isNode) {
throw new Error("Source files not supported on frontend");
}

finalWidth = innerJSON.finalDimensions.width;
fabricCanvas.setBackgroundColor("#FFFFFF");
var dimensions = innerJSON.dimensions;
var img = {
width: dimensions.width,
height: dimensions.height,
originX: "left",
originY: "top",
src: "file://" + path.resolve(innerJSON.sourceFile),
};

Fabric.Image.fromObject(img, function (fimg, err) {
if (!fimg || err) throw err;
var top = -imageOffset.y;
if (top % 1 != 0) {
top -= 0.5;
}
var left = -imageOffset.x;
if (left % 1 != 0) {
left -= 0.5;
}

fabricCanvas.add(fimg.set("top", top).set("left", left));
applyMarkup(callback);
});
}

/**
Expand Down

0 comments on commit 12a55d6

Please sign in to comment.