* Moved text settings into the "print" tab

+ Added setting to enable or disable word wrap by space
This commit is contained in:
Sync1211 2022-05-19 21:40:35 +02:00
parent 47d3d2ecea
commit 8cdaa048ee
No known key found for this signature in database
GPG Key ID: B8878699435E69EC
4 changed files with 30 additions and 17 deletions

View File

@ -55,6 +55,23 @@
<label class="label-input-span" data-hide-as="print"> <label class="label-input-span" data-hide-as="print">
<input type="checkbox" name="transparent-as-white" data-key checked /> <input type="checkbox" name="transparent-as-white" data-key checked />
<span data-i18n="transparent-as-white">Transparent as White</span> <span data-i18n="transparent-as-white">Transparent as White</span>
<br>
<label data-i18n="text-font">Text font</label>
<select id="text-font">
<option value="Serif">Serif</option>
<option value="Sans-serif" selected>Sans-serif</option>
<option value="monospace">Monospace</option>
<option value="cursive">Cursive</option>
</select>
<br>
<label>
<span data-i18n="text-size-">Text size:</span>
<input id="text-size" type="number" name="text-size" min="1" max="100" value="20" data-key />
<span>px</span>
</label>
<br>
<input type="checkbox" name="wrap-by-space" data-key checked />
<span data-i18n="wrap-by-space">Wrap text</span>
</label> </label>
<div class="center"> <div class="center">
<button data-i18n="show-more-options" data-show="print" data-once data-key>Show More Options</button> <button data-i18n="show-more-options" data-show="print" data-once data-key>Show More Options</button>
@ -91,19 +108,6 @@
<input type="checkbox" name="dump" data-key /> <input type="checkbox" name="dump" data-key />
<span data-i18n="dump-traffic">Dump Traffic</span> <span data-i18n="dump-traffic">Dump Traffic</span>
</label> --> </label> -->
<label data-i18n="text-font">Text font</label>
<select id="text-font">
<option value="Serif">Serif</option>
<option value="Sans-serif" selected>Sans-serif</option>
<option value="monospace">Monospace</option>
<option value="cursive">Cursive</option>
</select>
<br>
<label>
<span data-i18n="text-size-">Text size:</span>
<input id="text-size" type="number" name="text-size" min="1" max="100" value="20" data-key />
<span>px</span>
</label>
<button id="set-accessibility" data-key> <button id="set-accessibility" data-key>
<span>🌎</span> <span>🌎</span>
<span data-i18n="accessibility">Accessibility</span> <span data-i18n="accessibility">Accessibility</span>

View File

@ -106,5 +106,6 @@
"some-rights-reserved": "Einige Rechte sind vorbehalten.", "some-rights-reserved": "Einige Rechte sind vorbehalten.",
"text-font": "Schriftart", "text-font": "Schriftart",
"text-size": "Textgröße", "text-size": "Textgröße",
"enter-text": "Text eingeben" "enter-text": "Text eingeben",
"wrap-by-space": "autom. Zeilenumbruch"
} }

View File

@ -131,5 +131,6 @@
"show-more-options": "Show More Options", "show-more-options": "Show More Options",
"text-font": "Font", "text-font": "Font",
"text-size": "Text size", "text-size": "Text size",
"enter-text": "Enter text" "enter-text": "Enter text",
"wrap-by-space": "Wrap words by spaces"
} }

View File

@ -300,6 +300,7 @@ class CanvasController {
this.controls = document.getElementById('control-overlay'); this.controls = document.getElementById('control-overlay');
this.textSize = document.getElementById("text-size"); this.textSize = document.getElementById("text-size");
this.textFont = document.getElementById("text-font"); this.textFont = document.getElementById("text-font");
this.wrapBySpace = document.querySelector('input[name="wrap-by-space"]');
this.textAlgorithm = document.querySelector('input[name="algo"][value="algo-direct"]'); this.textAlgorithm = document.querySelector('input[name="algo"][value="algo-direct"]');
this.height = CanvasController.defaultHeight; this.height = CanvasController.defaultHeight;
this._thresholdRange = document.querySelector('[name="threshold"]'); this._thresholdRange = document.querySelector('[name="threshold"]');
@ -466,9 +467,13 @@ class CanvasController {
// Wrap the text if it does not fit on a single line // Wrap the text if it does not fit on a single line
const wrap_by_space = (text, max_length) => { const wrap_by_space = (text, max_length) => {
let split_pos = text.lastIndexOf(" ", max_length); let split_pos = max_length;
if (this.wrapBySpace.checked) {
split_pos = text.lastIndexOf(" ", max_length);
if (split_pos <= 0) { split_pos = max_length; }
}
if (split_pos <= 0) { split_pos = max_length; }
return [text.slice(0, split_pos).trim(), text.slice(split_pos, text.length).trim()]; return [text.slice(0, split_pos).trim(), text.slice(split_pos, text.length).trim()];
} }
@ -484,6 +489,7 @@ class CanvasController {
[line, text] = wrap_by_space(text, max_chars); [line, text] = wrap_by_space(text, max_chars);
lines.push(line); lines.push(line);
} }
lines.push(text); lines.push(text);
this.height = (lines.length * y_step) + (y_step / 2); this.height = (lines.length * y_step) + (y_step / 2);
ctx.font = canvas_font; // Setting this.height resets the font. ctx.font = canvas_font; // Setting this.height resets the font.
@ -653,6 +659,7 @@ class Main {
(value) => this.settings['text_mode'] = (value === 'algo-direct') (value) => this.settings['text_mode'] = (value === 'algo-direct')
); );
this.attachSetter('[name="transparent-as-white"]', 'change', 'transparent_as_white'); this.attachSetter('[name="transparent-as-white"]', 'change', 'transparent_as_white');
this.attachSetter('[name="wrap-by-space"]', 'change', 'wrap_by_space');
this.attachSetter('[name="dry-run"]', 'change', 'dry_run', this.attachSetter('[name="dry-run"]', 'change', 'dry_run',
(checked) => checked && Notice.note('dry-run-test-print-process-only') (checked) => checked && Notice.note('dry-run-test-print-process-only')
); );