From 69c2a670f17c2511ab7121e4672edfec229b7b68 Mon Sep 17 00:00:00 2001 From: sbs20 Date: Sat, 17 Apr 2021 08:41:46 +0100 Subject: [PATCH 1/4] Paper sizes #192 --- server/src/config.js | 24 ++++++++++++++++++++++++ server/src/context.js | 3 +++ server/src/types.js | 13 +++++++++++++ webui/src/components/Scan.vue | 27 +++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/server/src/config.js b/server/src/config.js index c36be5f6..247d7c77 100644 --- a/server/src/config.js +++ b/server/src/config.js @@ -69,6 +69,30 @@ class Config { } ], + paperSizes: [ + { + name: 'A3', + dimensions: { + x: 297, + y: 420 + } + }, + { + name: 'A4', + dimensions: { + x: 215, + y: 297 + } + }, + { + name: 'A5', + dimensions: { + x: 148, + y: 215 + } + } + ], + pipelines: [ { extension: 'jpg', diff --git a/server/src/context.js b/server/src/context.js index a3dd4166..46e5d01e 100644 --- a/server/src/context.js +++ b/server/src/context.js @@ -27,6 +27,9 @@ class Context { /** @type {Filter[]} */ this.filters = Config.filters; + + /** @type {PaperSize[]} */ + this.paperSizes = Config.paperSizes; } /** diff --git a/server/src/types.js b/server/src/types.js index 762360e3..57008489 100644 --- a/server/src/types.js +++ b/server/src/types.js @@ -40,6 +40,18 @@ * @property {string[]} commands */ +/** + * @typedef {Object} Dimensions + * @property {number} x + * @property {number} y + */ + +/** + * @typedef {Object} PaperSize + * @property {string} name + * @property {Dimensions} dimensions + */ + /** * @typedef {Object} Configuration * @property {string} version @@ -58,6 +70,7 @@ * @property {Pipeline} previewPipeline * @property {Filter[]} filters * @property {Pipeline[]} pipelines + * @property {PaperSize[]} paperSizes */ /** diff --git a/webui/src/components/Scan.vue b/webui/src/components/Scan.vue index b7e555c5..557ef0f0 100644 --- a/webui/src/components/Scan.vue +++ b/webui/src/components/Scan.vue @@ -73,6 +73,13 @@ + +
paper.dimensions.x <= deviceSize.x && paper.dimensions.y <= deviceSize.y); + paperSizes.splice(0, 0, { name: '' }); + return paperSizes; + }, + pipelines() { return this.context.pipelines.map(p => { const variables = (p.match(/@:[a-z-.]+/ig) || []).map(s => s.substr(2)); @@ -454,6 +474,13 @@ export default { this.$router.push('/files'); } }); + }, + + updatePaperSize(value) { + if (value.dimensions) { + this.request.params.width = value.dimensions.x; + this.request.params.height = value.dimensions.y; + } } } }; From 5e6c2ae337d0e29637111067f21a44dcc25603f2 Mon Sep 17 00:00:00 2001 From: sbs20 Date: Sat, 17 Apr 2021 09:45:18 +0100 Subject: [PATCH 2/4] Geometry field misbehaviuor #193 --- webui/src/components/Scan.vue | 59 +++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/webui/src/components/Scan.vue b/webui/src/components/Scan.vue index b7e555c5..9b972634 100644 --- a/webui/src/components/Scan.vue +++ b/webui/src/components/Scan.vue @@ -64,14 +64,14 @@ + :src="img" @change="onCropperChange"> - - - - + + + +
{ return { @@ -188,7 +200,6 @@ export default { request: { handler(request) { storage.request = request; - this.onCoordinatesChange(); }, deep: true } @@ -267,10 +278,7 @@ export default { }, pixelsPerMm() { - const scanner = { - width: this.device.features['-x'].limits[1], - height: this.device.features['-y'].limits[1] - }; + const scanner = this.deviceSize; // The preview image may not have perfectly scaled dimensions // because pixel counts are integers. So we report a horizontal @@ -283,12 +291,11 @@ export default { }, scaleCoordinates(coordinates, xScale, yScale) { - const round = (n) => Math.round(n * 10) / 10; return { - width: round(coordinates.width * xScale), - height: round(coordinates.height * yScale), - left: round(coordinates.left * xScale), - top: round(coordinates.top * yScale) + width: round(coordinates.width * xScale, 1), + height: round(coordinates.height * yScale, 1), + left: round(coordinates.left * xScale, 1), + top: round(coordinates.top * yScale, 1) }; }, @@ -333,17 +340,29 @@ export default { this.$refs.cropper.setCoordinates(adjusted); }, - onCrop({coordinates}) { + onCropperChange({coordinates}) { const adjusted = this.scaleCoordinates( coordinates, 1 / this.pixelsPerMm().x, 1 / this.pixelsPerMm().y); + // The cropper changes even when coordinates are set manually. This will + // result in manually set values being overwritten because of rounding. + // If someone is taking the trouble to set values manually then they + // should be preserved. We should only update the values if they breaach + // a threshold or the scanner dimensions + const scanner = this.deviceSize; const params = this.request.params; - params.width = adjusted.width; - params.height = adjusted.height; - params.left = adjusted.left; - params.top = adjusted.top; + const threshold = 0.4; + const boundAndRound = (n, min, max) => round(Math.min(Math.max(min, n), max), 1); + const bestValue = (current, crop, min, max) => Math.abs(current - crop) < threshold + ? boundAndRound(current, min, max) + : boundAndRound(crop, min, max); + + params.width = bestValue(params.width, adjusted.width, 0, scanner.width); + params.height = bestValue(params.height, adjusted.height, 0, scanner.height); + params.left = bestValue(params.left, adjusted.left, 0, scanner.width); + params.top = bestValue(params.top, adjusted.top, 0, scanner.height); }, readContext(force) { From c23e5ca60d8a9ad4869b0ae2db85a720f61c5bcf Mon Sep 17 00:00:00 2001 From: sbs20 Date: Sat, 17 Apr 2021 09:52:50 +0100 Subject: [PATCH 3/4] Paper change update coordinates --- webui/src/components/Scan.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/webui/src/components/Scan.vue b/webui/src/components/Scan.vue index cee1b013..4db38c00 100644 --- a/webui/src/components/Scan.vue +++ b/webui/src/components/Scan.vue @@ -499,6 +499,7 @@ export default { if (value.dimensions) { this.request.params.width = value.dimensions.x; this.request.params.height = value.dimensions.y; + this.onCoordinatesChange(); } } } From 194a52693d40522141d55804f08335ce57ad442b Mon Sep 17 00:00:00 2001 From: sbs20 Date: Sat, 17 Apr 2021 10:22:49 +0100 Subject: [PATCH 4/4] More paper size #192 --- server/src/config.js | 39 ++++++++++++++++------------------- webui/src/components/Scan.vue | 20 +++++++++++------- webui/src/locales/cn.json | 1 + webui/src/locales/cz.json | 1 + webui/src/locales/de.json | 1 + webui/src/locales/en.json | 1 + webui/src/locales/es.json | 1 + webui/src/locales/fr.json | 1 + webui/src/locales/it.json | 1 + webui/src/locales/test.json | 1 + 10 files changed, 39 insertions(+), 28 deletions(-) diff --git a/server/src/config.js b/server/src/config.js index 247d7c77..2e2d8e52 100644 --- a/server/src/config.js +++ b/server/src/config.js @@ -70,27 +70,24 @@ class Config { ], paperSizes: [ - { - name: 'A3', - dimensions: { - x: 297, - y: 420 - } - }, - { - name: 'A4', - dimensions: { - x: 215, - y: 297 - } - }, - { - name: 'A5', - dimensions: { - x: 148, - y: 215 - } - } + { name: 'A3', dimensions: { x: 297, y: 420 } }, + { name: 'A4', dimensions: { x: 215, y: 297 } }, + { name: 'A5', dimensions: { x: 148, y: 215 } }, + { name: 'A6', dimensions: { x: 105, y: 148 } }, + { name: 'B3', dimensions: { x: 353, y: 500 } }, + { name: 'B4', dimensions: { x: 250, y: 353 } }, + { name: 'B5', dimensions: { x: 176, y: 250 } }, + { name: 'B6', dimensions: { x: 125, y: 176 } }, + { name: 'DIN D3', dimensions: { x: 272, y: 385 } }, + { name: 'DIN D4', dimensions: { x: 192, y: 272 } }, + { name: 'DIN D5', dimensions: { x: 136, y: 192 } }, + { name: 'DIN D6', dimensions: { x: 96, y: 136 } }, + { name: 'Letter', dimensions: { x: 216, y: 279 } }, + { name: 'Legal', dimensions: { x: 216, y: 356 } }, + { name: 'Tabloid', dimensions: { x: 279, y: 432 } }, + { name: 'Ledger', dimensions: { x: 432, y: 279 } }, + { name: 'Junior legal', dimensions: { x: 127, y: 203 } }, + { name: 'Half letter', dimensions: { x: 140, y: 216 } } ], pipelines: [ diff --git a/webui/src/components/Scan.vue b/webui/src/components/Scan.vue index 4db38c00..b75666b3 100644 --- a/webui/src/components/Scan.vue +++ b/webui/src/components/Scan.vue @@ -73,12 +73,19 @@ - + + + + + {{ item.name }} + + +
paper.dimensions.x <= deviceSize.x && paper.dimensions.y <= deviceSize.y); - paperSizes.splice(0, 0, { name: '' }); return paperSizes; }, diff --git a/webui/src/locales/cn.json b/webui/src/locales/cn.json index 0d912844..fc416929 100644 --- a/webui/src/locales/cn.json +++ b/webui/src/locales/cn.json @@ -69,6 +69,7 @@ "left": "左边距", "width": "宽度", "height": "高度", + "paperSize": "Paper size", "brightness": "亮度", "contrast": "对比度", "message:loading-devices": "加载设备 ...", diff --git a/webui/src/locales/cz.json b/webui/src/locales/cz.json index 99071d04..ffeb151c 100644 --- a/webui/src/locales/cz.json +++ b/webui/src/locales/cz.json @@ -69,6 +69,7 @@ "left": "Vlevo", "width": "Šířka", "height": "Výška", + "paperSize": "Paper size", "brightness": "Jas", "contrast": "Kontrast", "message:loading-devices": "Načítání zařízení...", diff --git a/webui/src/locales/de.json b/webui/src/locales/de.json index bb55abc1..9b5b42fc 100644 --- a/webui/src/locales/de.json +++ b/webui/src/locales/de.json @@ -69,6 +69,7 @@ "left": "Links", "width": "Breite", "height": "Höhe", + "paperSize": "Paper size", "brightness": "Helligkeit", "contrast": "Kontrast", "message:loading-devices": "Suche nach Geräten...", diff --git a/webui/src/locales/en.json b/webui/src/locales/en.json index 57fe587b..1945b1e8 100644 --- a/webui/src/locales/en.json +++ b/webui/src/locales/en.json @@ -69,6 +69,7 @@ "left": "Left", "width": "Width", "height": "Height", + "paperSize": "Paper size", "brightness": "Brightness", "contrast": "Contrast", "message:loading-devices": "Loading devices...", diff --git a/webui/src/locales/es.json b/webui/src/locales/es.json index 90bb4609..19732b19 100644 --- a/webui/src/locales/es.json +++ b/webui/src/locales/es.json @@ -69,6 +69,7 @@ "left": "Izquierda", "width": "Anchura", "height": "Altura", + "paperSize": "Paper size", "brightness": "Brillo", "contrast": "Contraste", "message:loading-devices": "Cargando dispositivos...", diff --git a/webui/src/locales/fr.json b/webui/src/locales/fr.json index 2eeadc8e..61288db5 100644 --- a/webui/src/locales/fr.json +++ b/webui/src/locales/fr.json @@ -69,6 +69,7 @@ "left": "Gauche", "width": "Largeur", "height": "Hauteur", + "paperSize": "Paper size", "brightness": "Luminosité", "contrast": "Contraste", "message:loading-devices": "Chargement des scanners...", diff --git a/webui/src/locales/it.json b/webui/src/locales/it.json index 3f82c278..50afa518 100644 --- a/webui/src/locales/it.json +++ b/webui/src/locales/it.json @@ -69,6 +69,7 @@ "left": "Sinistra", "width": "Larghezza", "height": "Altezza", + "paperSize": "Paper size", "brightness": "Luminosità", "contrast": "Contrasto", "message:loading-devices": "Caricamento dispositivi...", diff --git a/webui/src/locales/test.json b/webui/src/locales/test.json index 4f0b4de2..11e52ae4 100644 --- a/webui/src/locales/test.json +++ b/webui/src/locales/test.json @@ -70,6 +70,7 @@ "left": "##SCAN.LEFT", "width": "##SCAN.WIDTH", "height": "##SCAN.HEIGHT", + "paperSize": "##SCAN.PAPERSIZE", "brightness": "##SCAN.BRIGHTNESS", "contrast": "##SCAN.CONSTRAST", "message:loading-devices": "##SCAN.LOADING",