Skip to content

Commit

Permalink
add basic readingDirection editing
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnth committed Jan 10, 2024
1 parent 4f5b78b commit f8cc8f4
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 16 deletions.
31 changes: 26 additions & 5 deletions scss/viewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -628,23 +628,44 @@ body{
position: absolute;
max-height: 40%;
overflow-y: auto;
padding: 0px;
margin: 0px;
padding: 0;
margin: 0;
.card{
margin: 0;
}
ul{
padding: 0px;
margin: 0px;
}
li{
padding: 3px 10px !important;
min-height: 0px;
min-height: 0;
}
.legendicon{
height: 10px;
width: 10px;
display: inline-block;
margin-right: 4px;
}
.contextTypeOption{
.select-directions{
ul{
padding: 0;
margin: 0;
}
li{
padding: 3px 10px !important;
min-height: 0;
border-bottom: 1px solid #e0e0e0;
}
}
.reading-direction-item{
cursor: pointer;
&:hover{
background-color: $color3;
color: $color2;
}
}
.contextTypeOption, .contextReadingDirectionOption {
cursor: pointer;
&:hover{
background-color: $color3;
Expand Down Expand Up @@ -846,7 +867,7 @@ label{
}
}

#kb-shortcut-modal-tabs{
.tabs{
overflow-x: hidden;
.indicator{
background-color: #0277bd;
Expand Down
53 changes: 43 additions & 10 deletions src/main/webapp/WEB-INF/tags/contextmenu.tag
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,48 @@
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div id="contextmenu" class="card hide infocus">
<div class="select-regions">
<ul class="collection highlight">
<c:forEach var="type" items="${regionTypes}">
<c:if test="${!(type.key eq 'ignore')}">
<li class="collection-item contextTypeOption contextregionlegend" data-type="${type.key}">
<div class="legendicon ${type.key}"></div>${type.key}
</li>
</c:if>
</c:forEach>
</ul>
<div class="card">
<div class="card-tabs">
<ul class="tabs tabs-fixed-width" id="contextMenuTab">
<li class="tab"><a href="#types">Types</a></li>
<li class="tab"><a href="#directions">Reading Direction</a></li>
</ul>
</div>
<div class="card-content">
<div id="types">
<div class="select-regions">
<ul class="collection highlight">
<c:forEach var="type" items="${regionTypes}">
<c:if test="${!(type.key eq 'ignore')}">
<li class="collection-item contextTypeOption contextregionlegend" data-type="${type.key}">
<div class="legendicon ${type.key}"></div>${type.key}
</li>
</c:if>
</c:forEach>
</ul>
</div>
</div>
<div id="directions">
<div class="select-directions">
<ul class="collection highlight">
<li class="reading-direction-item contextReadingDirectionOption" data-direction="unspecified">
Unspecified
</li>
<li class="reading-direction-item contextReadingDirectionOption" data-direction="left-to-right">
Left To Right
</li>
<li class="reading-direction-item contextReadingDirectionOption" data-direction="right-to-left">
Right To Left
</li>
<li class="reading-direction-item contextReadingDirectionOption" data-direction="top-to-bottom">
Top To Bottom
</li>
<li class="reading-direction-item contextReadingDirectionOption" data-direction="bottom-to-top">
Bottom To Top
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion src/main/webapp/resources/css/viewer.css

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions src/main/webapp/resources/js/viewer/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,48 @@ function ActionChangeTypeSegment(id, newType, viewer, textViewer, controller, se
}
}

function ActionChangeReadingDirection(id, newDirection, viewer, textViewer, controller, selector, segmentation, page) {
let _isExecuted = false;
let _segment = segmentation[page].segments[id];
const _oldDirection = _segment.readingDirection;

this.execute = function () {
if (!_isExecuted) {
_isExecuted = true;
if(newDirection === "unspecified"){
_segment.readingDirection = null
}else{
_segment.readingDirection = newDirection
}

if(_segment.textlines){
let textlines = Object.entries(_segment.textlines).map(([_,t]) => t);
for(let textline of textlines){
textViewer.updateTextLineReadingDirection(textline, newDirection)
}
}

console.log('Do - Change Reading Direction: {id:"' + id + '",[..],readingDirection:"' + newDirection + '"}');
}
}
this.undo = function () {
if (_isExecuted) {
_isExecuted = false;
_segment.readingDirection = _oldDirection

if(_segment.textlines){
let textlines = Object.entries(_segment.textlines).map(([_,t]) => t);
for(let textline of textlines){
textViewer.updateTextLineReadingDirection(textline, _oldDirection)
}
}

console.log('Undo - Change Reading Direction: {id:"' + id + '",[..],readingDirection:"' + _oldDirection + '"}');
}
}

}

function ActionAddRegionArea(id, points, type, editor, settings) {
let _isExecuted = false;
const _area = { id: id, coords: {points: points, isRelative: true}, type: type };
Expand Down
24 changes: 24 additions & 0 deletions src/main/webapp/resources/js/viewer/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,30 @@ function Controller(bookID, accessible_modes, canvasID, regionColors, colors, gl
}
}

this.changeReadingDirection = function(id, direction) {
const polygonType = this.getIDType(id);
if(polygonType === ElementType.SEGMENT && this.isIDTextRegion(id)){
const actionChangeReadingDirection = new ActionChangeReadingDirection(id, direction, _editor, _textViewer, this, _selector, _segmentation, _currentPage, false);
_actionController.addAndExecuteAction(actionChangeReadingDirection, _currentPage);
}
}

this.changeReadingDirectionSelected = function (direction){
const selected = _selector.getSelectedSegments();
const selectType = _selector.getSelectedPolygonType();
const selectedlength = selected.length;
if (selectType === ElementType.SEGMENT){
if (selectedlength || selectedlength > 0) {
const actions = [];
for (let i = 0; i < selectedlength; i++) {
if(this.isIDTextRegion(selected[i])) actions.push(new ActionChangeReadingDirection(selected[i], direction, _editor, _textViewer, this, _selector, _segmentation, _currentPage, false));
}
const multiChange = new ActionMultiple(actions);
_actionController.addAndExecuteAction(multiChange, _currentPage);
}
}
}

this.openRegionSettings = function (regionType) {
if(regionType){
let region = _settings.regions[regionType];
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/resources/js/viewer/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ function GUI(canvas, viewer, colors, accessible_modes) {
this.openContextMenu = function (doSelected, id) {
const $contextmenu = $("#contextmenu");
$contextmenu.removeClass("hide");
const $contextMenuTab = $("#contextMenuTab")
$contextMenuTab.tabs("select_tab", "types");
const fitsInWindow = _mouse.y + $contextmenu.height() < $(window).height();

if (fitsInWindow) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/webapp/resources/js/viewer/guiInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ function GuiInput(navigationController, controller, gui, textViewer, selector, c
}
_gui.closeContextMenu();
});
$('.contextReadingDirectionOption').click(function () {
const $this = $(this);
const $contextmenu = $("#contextmenu");
const doSelected = $contextmenu.data('doSelected');
const readingDirection = $this.data('direction');

if (doSelected) {
_controller.changeReadingDirectionSelected(readingDirection);
} else {
const id = $contextmenu.data('id');
_controller.changeReadingDirection(id, readingDirection);
}
_gui.closeContextMenu();
});

$('#regioneditorSave').click(() => {
const $regioneditor = $('#regioneditor');
Expand Down
16 changes: 16 additions & 0 deletions src/main/webapp/resources/js/viewer/textViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ class TextViewer {
this._displayOnly();
}

updateTextLineReadingDirection(textline, readingDirection){
const $textlinecontent = $(`.textline-container[data-id='${textline.id}']`)

switch(readingDirection){
case "right-to-left":
$textlinecontent.attr("dir", "rtl");
break;
case "left-to-right":
$textlinecontent.attr("dir", "ltr");
break;
default:
$textlinecontent.removeAttr("dir")
break;
}
}

/**
* Display a save of the contents of a textline
*
Expand Down

0 comments on commit f8cc8f4

Please sign in to comment.