Browse Source

Add support for <Illustration/> elements in XML-ALTO rendering

main
Tissevert 4 months ago
parent
commit
6fce85c4cc
2 changed files with 22 additions and 13 deletions
  1. +14
    -7
      js/XML/ALTO.js
  2. +8
    -6
      js/XML/ALTO/Element.js

+ 14
- 7
js/XML/ALTO.js View File

@@ -35,10 +35,17 @@ function makeDomNode(xmlElement, parentElement) {
}

function makeChildren(xmlElement, element) {
var children = element.tag == 'TextBlock' ? [blockPositionElem()] : [];
xmlElement.querySelectorAll(element.childTag).forEach(function(child) {
children.push(makeDomNode(child, element));
});
var children = [];
if(Element.schema.PrintSpace.childTags.indexOf(element.tag) >= 0) {
children.push(blockPositionElem());
}
if(Array.isArray(element.childTags)) {
xmlElement.querySelectorAll(element.childTags.join(', ')).forEach(
function(child) {
children.push(makeDomNode(child, element));
}
);
}
return children;
}

@@ -73,15 +80,15 @@ function editElement(xmlElement) {
if(element.tag == 'String') {
return !isScoria(element.get('ID'));
} else {
editChildren(xmlElement, element.childTag);
editChildren(xmlElement, element.childTags);
return xmlElement.children.length > 0;
}
}

function editChildren(xmlElement, childTag) {
function editChildren(xmlElement, childTags) {
for(var i = 0; i < xmlElement.children.length; i++) {
var child = xmlElement.children[i];
if(child.tagName == childTag && !editElement(child)) {
if(childTags.indexOf(child.tagName) >= 0 && !editElement(child)) {
xmlElement.removeChild(child);
}
}


+ 8
- 6
js/XML/ALTO/Element.js View File

@@ -2,15 +2,17 @@ import scale from Toolbar.Zoom;
import oNorm from Geometry.Segment;

var schema = {
'Page': {childTag: 'PrintSpace'},
'PrintSpace': {childTag: 'TextBlock', htmlTag: 'div'},
'TextBlock': {childTag: 'TextLine', htmlTag: 'div'},
'TextLine': {childTag: 'String', htmlTag: 'p'},
'Page': {childTags: ['PrintSpace']},
'PrintSpace': {childTags: ['TextBlock', 'Illustration'], htmlTag: 'div'},
'TextBlock': {childTags: ['TextLine'], htmlTag: 'div'},
'Illustration': {htmlTag: 'div'},
'TextLine': {childTags: ['String'], htmlTag: 'p'},
'String': {htmlTag: 'span'}
};

return {
make: make
make: make,
schema: schema
};

function make(xmlElement) {
@@ -18,7 +20,7 @@ function make(xmlElement) {
var y = oNorm(get('VPOS'), get('HEIGHT'));

return {
childTag: schema[xmlElement.tagName].childTag,
childTags: schema[xmlElement.tagName].childTags,
geometry: {
hPos: x.o,
vPos: y.o,


Loading…
Cancel
Save