Browse Source
Simplify ALTO display code and harden the whole thing a bit against negative dimensions found in some pages in T2
better-rectangles
Simplify ALTO display code and harden the whole thing a bit against negative dimensions found in some pages in T2
better-rectangles
5 changed files with 71 additions and 108 deletions
@ -1,55 +1,48 @@ |
|||
import scale from Toolbar.Zoom; |
|||
import oNorm from Geometry.Segment; |
|||
|
|||
var schema = { |
|||
'PrintSpace': 'TextBlock', |
|||
'TextBlock': 'TextLine', |
|||
'TextLine': 'String' |
|||
'Page': {childTag: 'PrintSpace'}, |
|||
'PrintSpace': {childTag: 'TextBlock', htmlTag: 'div'}, |
|||
'TextBlock': {childTag: 'TextLine', htmlTag: 'div'}, |
|||
'TextLine': {childTag: 'String', htmlTag: 'p'}, |
|||
'String': {htmlTag: 'span'} |
|||
}; |
|||
|
|||
return { |
|||
make: make, |
|||
schema: schema, |
|||
make: make |
|||
}; |
|||
|
|||
function make(xmlElement, domElement, parentElement) { |
|||
var hPos = xmlElement.getAttribute('HPOS'); |
|||
var vPos = xmlElement.getAttribute('VPOS'); |
|||
var width = xmlElement.getAttribute('WIDTH'); |
|||
var height = xmlElement.getAttribute('HEIGHT'); |
|||
position(); |
|||
function make(xmlElement) { |
|||
var x = oNorm(get('HPOS'), get('WIDTH')); |
|||
var y = oNorm(get('VPOS'), get('HEIGHT')); |
|||
|
|||
return { |
|||
dom: dom, |
|||
geometry: geometry, |
|||
get: get |
|||
childTag: schema[xmlElement.tagName].childTag, |
|||
geometry: { |
|||
hPos: x.o, |
|||
vPos: y.o, |
|||
width: x.norm, |
|||
height: y.norm |
|||
}, |
|||
get: get, |
|||
htmlTag: schema[xmlElement.tagName].htmlTag, |
|||
id: get('ID'), |
|||
position: position, |
|||
tag: xmlElement.tagName |
|||
}; |
|||
|
|||
function dom() { |
|||
return domElement; |
|||
function get(attribute) { |
|||
return xmlElement.getAttribute(attribute); |
|||
} |
|||
|
|||
function geometry() { |
|||
return { |
|||
hPos: hPos, |
|||
vPos: vPos, |
|||
width: width, |
|||
height: height |
|||
}; |
|||
} |
|||
|
|||
function get(tag) { |
|||
return xmlElement.querySelectorAll(tag); |
|||
} |
|||
|
|||
function position() { |
|||
if(domElement != undefined) { |
|||
var mother = parentElement ? parentElement.geometry() : {hPos: 0, vPos: 0}; |
|||
scale(domElement, { |
|||
left: hPos - mother.hPos, /* due to absolute positioning in CSS, this needs to be */ |
|||
top: vPos - mother.vPos, /* computed as an offset from the parentElement */ |
|||
width: width, |
|||
height: height |
|||
}, 'left', 'top', 'width', 'height') |
|||
} |
|||
function position(domElement, parentElement) { |
|||
var mother = parentElement ? parentElement.geometry : {hPos: 0, vPos: 0}; |
|||
scale(domElement, { |
|||
left: x.o - mother.hPos, /* due to absolute positioning in CSS, this needs to be */ |
|||
top: y.o - mother.vPos, /* computed as an offset from the parentElement */ |
|||
width: x.norm, |
|||
height: y.norm |
|||
}, 'left', 'top', 'width', 'height') |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue