From def0574020446231c787dc4b6c2d9b042df52996 Mon Sep 17 00:00:00 2001 From: ffd8 Date: Mon, 12 Nov 2018 18:02:31 +0100 Subject: [PATCH 1/2] potential fix for bounds() - i think this simple + -> - might have fixed all issues with `bounds()` when using `canvasMode(MARGIN)` and `canvasMode(FACING_MARGINS)`? --- basil.js | 28 ++++++++++++++-------------- src/includes/document.js | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/basil.js b/basil.js index 71239c8..4011ba1 100644 --- a/basil.js +++ b/basil.js @@ -3365,20 +3365,20 @@ pub.bounds = function (obj) { return {"width": w, "height": h, - "left": x1 + currOriginX, - "right": x2 + currOriginX, - "top": y1 + currOriginY, - "bottom": y2 + currOriginY, - "baseline": baseline + currOriginY, - "xHeight": xHeight + currOriginY}; + "left": x1 - currOriginX, + "right": x2 - currOriginX, + "top": y1 - currOriginY, + "bottom": y2 - currOriginY, + "baseline": baseline - currOriginY, + "xHeight": xHeight - currOriginY}; } else { // is it a pageItem? if (obj.hasOwnProperty("geometricBounds")) { var geometricBounds = obj.geometricBounds; // [y1, x1, y2, x2] - x1 = geometricBounds[1] + currOriginX; - y1 = geometricBounds[0] + currOriginY; - x2 = geometricBounds[3] + currOriginX; - y2 = geometricBounds[2] + currOriginY; + x1 = geometricBounds[1] - currOriginX; + y1 = geometricBounds[0] - currOriginY; + x2 = geometricBounds[3] - currOriginX; + y2 = geometricBounds[2] - currOriginY; w = x2 - x1; h = y2 - y1; return {"width": w, "height": h, "left": x1, "right": x2, "top": y1, "bottom": y2}; @@ -3386,10 +3386,10 @@ pub.bounds = function (obj) { // everything else e.g. page, spread else if (obj.hasOwnProperty("bounds")) { var bounds = obj.bounds; // [y1, x1, y2, x2] - x1 = bounds[1] + currOriginX; - y1 = bounds[0] + currOriginY; - x2 = bounds[3] + currOriginX; - y2 = bounds[2] + currOriginY; + x1 = bounds[1] - currOriginX; + y1 = bounds[0] - currOriginY; + x2 = bounds[3] - currOriginX; + y2 = bounds[2] - currOriginY; w = x2 - x1; h = y2 - y1; return {"width": w, "height": h, "left": x1, "right": x2, "top": y1, "bottom": y2}; diff --git a/src/includes/document.js b/src/includes/document.js index 60e6594..13a35b0 100644 --- a/src/includes/document.js +++ b/src/includes/document.js @@ -861,20 +861,20 @@ pub.bounds = function (obj) { return {"width": w, "height": h, - "left": x1 + currOriginX, - "right": x2 + currOriginX, - "top": y1 + currOriginY, - "bottom": y2 + currOriginY, - "baseline": baseline + currOriginY, - "xHeight": xHeight + currOriginY}; + "left": x1 - currOriginX, + "right": x2 - currOriginX, + "top": y1 - currOriginY, + "bottom": y2 - currOriginY, + "baseline": baseline - currOriginY, + "xHeight": xHeight - currOriginY}; } else { // is it a pageItem? if (obj.hasOwnProperty("geometricBounds")) { var geometricBounds = obj.geometricBounds; // [y1, x1, y2, x2] - x1 = geometricBounds[1] + currOriginX; - y1 = geometricBounds[0] + currOriginY; - x2 = geometricBounds[3] + currOriginX; - y2 = geometricBounds[2] + currOriginY; + x1 = geometricBounds[1] - currOriginX; + y1 = geometricBounds[0] - currOriginY; + x2 = geometricBounds[3] - currOriginX; + y2 = geometricBounds[2] - currOriginY; w = x2 - x1; h = y2 - y1; return {"width": w, "height": h, "left": x1, "right": x2, "top": y1, "bottom": y2}; @@ -882,10 +882,10 @@ pub.bounds = function (obj) { // everything else e.g. page, spread else if (obj.hasOwnProperty("bounds")) { var bounds = obj.bounds; // [y1, x1, y2, x2] - x1 = bounds[1] + currOriginX; - y1 = bounds[0] + currOriginY; - x2 = bounds[3] + currOriginX; - y2 = bounds[2] + currOriginY; + x1 = bounds[1] - currOriginX; + y1 = bounds[0] - currOriginY; + x2 = bounds[3] - currOriginX; + y2 = bounds[2] - currOriginY; w = x2 - x1; h = y2 - y1; return {"width": w, "height": h, "left": x1, "right": x2, "top": y1, "bottom": y2}; From c45b94c4e4a2704ed3116b092d7cbcaef32791b5 Mon Sep 17 00:00:00 2001 From: ffd8 Date: Mon, 12 Nov 2018 18:14:06 +0100 Subject: [PATCH 2/2] Slight fix for page() - nearly fixed `bounds()`, when getting bounds of `page()`, just needs some love for FACING_PAGES/MARGINS/BLEEDS --- basil.js | 4 ++-- src/includes/document.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/basil.js b/basil.js index 4011ba1..3aa5e68 100644 --- a/basil.js +++ b/basil.js @@ -3390,8 +3390,8 @@ pub.bounds = function (obj) { y1 = bounds[0] - currOriginY; x2 = bounds[3] - currOriginX; y2 = bounds[2] - currOriginY; - w = x2 - x1; - h = y2 - y1; + w = x2 - x1 - currOriginX; + h = y2 - y1 - currOriginX; return {"width": w, "height": h, "left": x1, "right": x2, "top": y1, "bottom": y2}; } // no idea what that might be, give up diff --git a/src/includes/document.js b/src/includes/document.js index 13a35b0..d45f97c 100644 --- a/src/includes/document.js +++ b/src/includes/document.js @@ -886,8 +886,8 @@ pub.bounds = function (obj) { y1 = bounds[0] - currOriginY; x2 = bounds[3] - currOriginX; y2 = bounds[2] - currOriginY; - w = x2 - x1; - h = y2 - y1; + w = x2 - x1 - currOriginX; + h = y2 - y1 - currOriginX; return {"width": w, "height": h, "left": x1, "right": x2, "top": y1, "bottom": y2}; } // no idea what that might be, give up