if ellipse is found, consider it a circle with r=rx+ry/2 (fix #2)

This commit is contained in:
Tomáš Mládek 2021-01-16 14:52:05 +01:00
parent 124ce4779f
commit 2e2728f4e2

View file

@ -392,19 +392,25 @@ async function processScrolls(svg: XMLDocument): Promise<VideoScrollDef[]> {
}
function processAudio(svg: XMLDocument): AudioAreaDef[] {
return Array.from(svg.getElementsByTagName("circle"))
const circles: (SVGCircleElement | SVGEllipseElement)[] = Array.from(svg.getElementsByTagName("circle"));
const ellipses: (SVGCircleElement | SVGEllipseElement)[] = Array.from(svg.getElementsByTagName("ellipse"));
return circles.concat(ellipses)
.filter((el) => Array.from(el.children).some((el) => el.tagName == "desc"))
.map((el) => {
const descNode = Array.from(el.children).find((el) => el.tagName == "desc");
console.debug(`[SVG/AUDIOAREAS] Found audio area #${el.id}: ${descNode?.textContent}`);
const audioSrc = descNode!.textContent!.trim();
const radius = el.hasAttribute("r") ?
(el as SVGCircleElement).r.baseVal.value :
((el as SVGEllipseElement).rx.baseVal.value + (el as SVGEllipseElement).ry.baseVal.value) / 2;
el.classList.add("internal");
return {
cx: el.cx.baseVal.value,
cy: el.cy.baseVal.value,
radius: el.r.baseVal.value,
radius,
src: `content/${audioSrc}`,
};
});