Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 2ceb9c74 authored by Robin Tissot's avatar Robin Tissot
Browse files

Adds a new mode for line visualisation.

parent 9c12f16c
No related branches found
No related tags found
1 merge request!51Adds a new mode for line visualisation.
/* /*
Baseline editor Baseline editor
a javascript based baseline segmentation editor, a javascript based baseline segmentation editor,
requires paper.js and colorThief is optional. requires paper.js.
Usage: Usage:
var segmenter = new Segmenter(img, options); var segmenter = new Segmenter(img, options);
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
deletePointBtn=null, deletePointBtn=null,
deleteSelectionBtn=null, deleteSelectionBtn=null,
toggleMasksBtn=null, toggleMasksBtn=null,
toggleLineModeBtn=null,
splitBtn=null, splitBtn=null,
mergeBtn=null, mergeBtn=null,
...@@ -155,7 +156,7 @@ class SegmenterLine { ...@@ -155,7 +156,7 @@ class SegmenterLine {
this.baseline = baseline.map(pt=>[Math.round(pt[0]), Math.round(pt[1])]); this.baseline = baseline.map(pt=>[Math.round(pt[0]), Math.round(pt[1])]);
this.baselinePath = new Path({ this.baselinePath = new Path({
strokeColor: this.segmenter.baselinesColor, strokeColor: this.segmenter.baselinesColor,
strokeWidth: 5/this.segmenter.getRatio(), // strokeWidth: 5/this.segmenter.getRatio(),
strokeCap: 'butt', strokeCap: 'butt',
selectedColor: 'black', selectedColor: 'black',
opacity: 0.5, opacity: 0.5,
...@@ -187,9 +188,20 @@ class SegmenterLine { ...@@ -187,9 +188,20 @@ class SegmenterLine {
this.showOrdering(); this.showOrdering();
this.showDirection(); this.showDirection();
if (this.baselinePath) { if (this.baselinePath) {
this.baselinePath.strokeWidth = 5/this.segmenter.getRatio(); if (this.segmenter.wideLineStrokes) {
this.baselinePath.strokeWidth = 5/this.segmenter.getRatio();
} else {
this.baselinePath.strokeWidth = 1;
}
}
if (this.directionHint) {
if (this.segmenter.showDirectionHint) {
this.directionHint.visible = true;
this.directionHint.strokeColor = this.hintColor;
} else {
this.directionHint.visible = false;
}
} }
if (this.directionHint) this.directionHint.strokeColor = this.hintColor;
} }
getMaskColor() { getMaskColor() {
...@@ -471,6 +483,7 @@ class Segmenter { ...@@ -471,6 +483,7 @@ class Segmenter {
regionTypes=['Title', 'Main', 'Marginal', 'Illustration', 'Numbering'], regionTypes=['Title', 'Main', 'Marginal', 'Illustration', 'Numbering'],
lineTypes=['Main', 'Interlinear'], lineTypes=['Main', 'Interlinear'],
wideLineStrokes=true,
// todo: choose keyboard shortcuts // todo: choose keyboard shortcuts
inactiveLayerOpacity=0.5, inactiveLayerOpacity=0.5,
...@@ -527,6 +540,8 @@ class Segmenter { ...@@ -527,6 +540,8 @@ class Segmenter {
this.regionAreaThreshold = regionAreaThreshold; this.regionAreaThreshold = regionAreaThreshold;
this.showMasks = false; this.showMasks = false;
this.showLineNumbers = false; this.showLineNumbers = false;
this.showDirectionHint = true;
this.wideLineStrokes = wideLineStrokes;
this.selecting = null; this.selecting = null;
this.spliting = false; this.spliting = false;
...@@ -534,6 +549,7 @@ class Segmenter { ...@@ -534,6 +549,7 @@ class Segmenter {
// menu btns // menu btns
this.toggleMasksBtn = document.getElementById('be-toggle-masks'); this.toggleMasksBtn = document.getElementById('be-toggle-masks');
this.toggleLineModeBtn = document.getElementById('be-toggle-line-mode');
this.toggleOrderingBtn = document.getElementById('be-toggle-order'); this.toggleOrderingBtn = document.getElementById('be-toggle-order');
this.toggleRegionModeBtn = document.getElementById('be-toggle-regions'); this.toggleRegionModeBtn = document.getElementById('be-toggle-regions');
this.splitBtn = document.getElementById('be-split-lines'); this.splitBtn = document.getElementById('be-split-lines');
...@@ -641,6 +657,11 @@ class Segmenter { ...@@ -641,6 +657,11 @@ class Segmenter {
this.toggleMasks(); this.toggleMasks();
}.bind(this)); }.bind(this));
} }
if (this.toggleLineModeBtn) {
this.toggleLineModeBtn.addEventListener('click', function(event) {
this.toggleLineMode();
}.bind(this));
}
if (this.splitBtn) this.splitBtn.addEventListener('click', function(event) { if (this.splitBtn) this.splitBtn.addEventListener('click', function(event) {
this.spliting = !this.spliting; this.spliting = !this.spliting;
...@@ -734,7 +755,7 @@ class Segmenter { ...@@ -734,7 +755,7 @@ class Segmenter {
} else if (event.keyCode == 74) { // J (for join) } else if (event.keyCode == 74) { // J (for join)
this.mergeSelection(); this.mergeSelection();
} else if (event.keyCode == 77) { // M } else if (event.keyCode == 77) { // M
this.toggleMasks(); this.toggleLineMode();
} else if (event.keyCode == 76) { // L } else if (event.keyCode == 76) { // L
this.toggleOrdering(); this.toggleOrdering();
} else if (event.keyCode == 82) { // R } else if (event.keyCode == 82) { // R
...@@ -1499,14 +1520,56 @@ class Segmenter { ...@@ -1499,14 +1520,56 @@ class Segmenter {
} }
} }
toggleMasks(force) { toggleLineMode() {
this.showMasks = force || !this.showMasks; // wide: default mode
if (this.showMasks) { // mask: show the boundary of the line
this.toggleMasksBtn.classList.add('btn-success'); // slim: set the strokeWidth at 1px
this.toggleMasksBtn.classList.remove('btn-info'); if (this.showMasks) { // mask -> slim
this.toggleMasks(false);
this.toggleLineStrokes(false);
this.toggleLineModeBtn.classList.add('btn-secondary');
this.toggleLineModeBtn.classList.remove('btn-success');
} else { } else {
this.toggleMasksBtn.classList.add('btn-info'); if (!this.wideLineStrokes) { // slim -> wide
this.toggleMasksBtn.classList.remove('btn-success'); this.toggleMasks(false);
this.toggleLineStrokes(true);
this.toggleLineModeBtn.classList.add('btn-info');
this.toggleLineModeBtn.classList.remove('btn-secondary');
} else { // wide -> mask
this.toggleMasks(true);
this.toggleLineStrokes(true);
this.toggleLineModeBtn.classList.add('btn-success');
this.toggleLineModeBtn.classList.remove('btn-info');
}
}
}
toggleLineStrokes(force) {
// wide / slim
if (force != undefined) this.wideLineStrokes = force;
else this.wideLineStrokes = !this.wideLineStrokes;
this.showDirectionHint = this.wideLineStrokes;
for (let i in this.lines) {
this.lines[i].refresh();
}
}
toggleMasks(force) {
if (force !== undefined) this.showMasks = force;
else this.showMasks = !this.showMasks;
if (this.toggleMasksBtn) {
if (this.showMasks) {
this.toggleMasksBtn.classList.add('btn-success');
this.toggleMasksBtn.classList.remove('btn-info');
} else {
this.toggleMasksBtn.classList.add('btn-info');
this.toggleMasksBtn.classList.remove('btn-success');
}
} }
for (let i in this.lines) { for (let i in this.lines) {
let poly = this.lines[i].maskPath; let poly = this.lines[i].maskPath;
......
...@@ -248,8 +248,8 @@ ...@@ -248,8 +248,8 @@
title="{% trans "Toggle ordering display. (L)" %}" title="{% trans "Toggle ordering display. (L)" %}"
class="btn btn-sm btn-info fas fa-sort-numeric-down" class="btn btn-sm btn-info fas fa-sort-numeric-down"
autocomplete="off"></button> autocomplete="off"></button>
<button id="be-toggle-masks" <button id="be-toggle-line-mode"
title="{% trans "Show line masks. (M)" %}" title="{% trans "Toggle line masks and stroke width. (M)" %}"
class="btn btn-sm btn-info fas fa-mask"></button> class="btn btn-sm btn-info fas fa-mask"></button>
</div> </div>
<div class="btn-group"> <div class="btn-group">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment