Skip to content

Commit

Permalink
Merge pull request #195 from sbs20/staging
Browse files Browse the repository at this point in the history
Paper sizes and geometry fix
  • Loading branch information
sbs20 authored Apr 17, 2021
2 parents 938a9b0 + 3458b6f commit c3122b5
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 22 deletions.
2 changes: 1 addition & 1 deletion server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scanservjs-server",
"version": "2.9.1",
"version": "2.9.2",
"description": "scanservjs is a simple web-based UI for SANE which allows you to share a scanner on a network without the need for drivers or complicated installation. scanserv does not do image conversion or manipulation (beyond the bare minimum necessary for the purposes of browser preview) or OCR.",
"scripts": {
"serve": "nodemon --exec 'vue-cli-service serve'",
Expand Down
21 changes: 21 additions & 0 deletions server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ 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: '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: [
{
extension: 'jpg',
Expand Down
3 changes: 3 additions & 0 deletions server/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Context {

/** @type {Filter[]} */
this.filters = Config.filters;

/** @type {PaperSize[]} */
this.paperSizes = Config.paperSizes;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions server/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,6 +70,7 @@
* @property {Pipeline} previewPipeline
* @property {Filter[]} filters
* @property {Pipeline[]} pipelines
* @property {PaperSize[]} paperSizes
*/

/**
Expand Down
93 changes: 73 additions & 20 deletions webui/src/components/Scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,28 @@
<v-col cols="12" md="auto" class="mb-10 mb-md-0" :style="{width: `${preview.width}px`}">
<cropper ref="cropper" class="cropper" :key="preview.key" :transitionTime="10" :wheelResize="false"
:default-position="cropperDefaultPosition" :default-size="cropperDefaultSize"
:src="img" @change="onCrop"></cropper>
:src="img" @change="onCropperChange"></cropper>
</v-col>

<v-col cols="12" md="3" class="mb-10 mb-md-0">
<v-text-field :label="$t('scan.top')" type="number" v-model="request.params.top" @change="onCoordinatesChange" />
<v-text-field :label="$t('scan.left')" type="number" v-model="request.params.left" @change="onCoordinatesChange" />
<v-text-field :label="$t('scan.width')" type="number" v-model="request.params.width" @change="onCoordinatesChange" />
<v-text-field :label="$t('scan.height')" type="number" v-model="request.params.height" @change="onCoordinatesChange" />
<v-text-field :label="$t('scan.top')" type="number" v-model="request.params.top" @blur="onCoordinatesChange" />
<v-text-field :label="$t('scan.left')" type="number" v-model="request.params.left" @blur="onCoordinatesChange" />
<v-text-field :label="$t('scan.width')" type="number" v-model="request.params.width" @blur="onCoordinatesChange" />
<v-text-field :label="$t('scan.height')" type="number" v-model="request.params.height" @blur="onCoordinatesChange" />

<v-menu offset-y>
<template v-slot:activator="{ on, attrs }">
<v-btn color="primary" v-bind="attrs" v-on="on">{{ $t('scan.paperSize') }}</v-btn>
</template>
<v-list>
<v-list-item
v-for="(item, index) in paperSizes"
@click="updatePaperSize(item)"
:key="index">
<v-list-item-title>{{ item.name }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>

<div v-if="'--brightness' in device.features">
<v-slider class="align-center" v-model="request.params.brightness"
Expand Down Expand Up @@ -116,6 +130,11 @@ import Storage from '../classes/storage';
const storage = Storage.instance();
function round(n, dp) {
const f = Math.pow(10, dp || 0);
return Math.round(n * f) / f;
}
export default {
name: 'Scan',
components: {
Expand All @@ -134,6 +153,7 @@ export default {
],
filters: [],
pipelines: [],
paperSizes: [],
version: '0'
},
device: device,
Expand All @@ -159,6 +179,13 @@ export default {
},
computed: {
deviceSize() {
return {
width: this.device.features['-x'].limits[1],
height: this.device.features['-y'].limits[1]
};
},
filters() {
return this.context.filters.map(f => {
return {
Expand All @@ -168,6 +195,17 @@ export default {
});
},
paperSizes() {
const deviceSize = {
x: this.device.features['-x'].limits[1],
y: this.device.features['-y'].limits[1]
};
const paperSizes = this.context.paperSizes
.filter(paper => paper.dimensions.x <= deviceSize.x && paper.dimensions.y <= deviceSize.y);
return paperSizes;
},
pipelines() {
return this.context.pipelines.map(p => {
const variables = (p.match(/@:[a-z-.]+/ig) || []).map(s => s.substr(2));
Expand All @@ -188,7 +226,6 @@ export default {
request: {
handler(request) {
storage.request = request;
this.onCoordinatesChange();
},
deep: true
}
Expand Down Expand Up @@ -267,10 +304,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
Expand All @@ -283,12 +317,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)
};
},
Expand Down Expand Up @@ -333,17 +366,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) {
Expand Down Expand Up @@ -454,6 +499,14 @@ 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;
this.onCoordinatesChange();
}
}
}
};
Expand Down
1 change: 1 addition & 0 deletions webui/src/locales/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"left": "左边距",
"width": "宽度",
"height": "高度",
"paperSize": "Paper size",
"brightness": "亮度",
"contrast": "对比度",
"message:loading-devices": "加载设备 ...",
Expand Down
1 change: 1 addition & 0 deletions webui/src/locales/cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -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í...",
Expand Down
1 change: 1 addition & 0 deletions webui/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
Expand Down
1 change: 1 addition & 0 deletions webui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"left": "Left",
"width": "Width",
"height": "Height",
"paperSize": "Paper size",
"brightness": "Brightness",
"contrast": "Contrast",
"message:loading-devices": "Loading devices...",
Expand Down
1 change: 1 addition & 0 deletions webui/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"left": "Izquierda",
"width": "Anchura",
"height": "Altura",
"paperSize": "Paper size",
"brightness": "Brillo",
"contrast": "Contraste",
"message:loading-devices": "Cargando dispositivos...",
Expand Down
1 change: 1 addition & 0 deletions webui/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"left": "Gauche",
"width": "Largeur",
"height": "Hauteur",
"paperSize": "Paper size",
"brightness": "Luminosité",
"contrast": "Contraste",
"message:loading-devices": "Chargement des scanners...",
Expand Down
1 change: 1 addition & 0 deletions webui/src/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"left": "Sinistra",
"width": "Larghezza",
"height": "Altezza",
"paperSize": "Paper size",
"brightness": "Luminosità",
"contrast": "Contrasto",
"message:loading-devices": "Caricamento dispositivi...",
Expand Down
1 change: 1 addition & 0 deletions webui/src/locales/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c3122b5

Please sign in to comment.