Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions src/main/js/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,26 +1487,7 @@ export class Set {

TimedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);

const styles = elementGetStyles(node, errorHandler);

this.qname = null;
this.value = null;

for (const qname in styles) {

if (!hasOwnProperty(styles, qname)) continue;

if (this.qname) {

reportError(errorHandler, "More than one style specified on set");
break;

}

this.qname = qname;
this.value = styles[qname];

}
this.styles = elementGetStyles(node, errorHandler);

}
}
Expand Down Expand Up @@ -1592,6 +1573,10 @@ function elementGetStyles(node, errorHandler) {

if (val !== null) {

if (qname in s) {
reportWarning(errorHandler, "More than one style attribute for " + qname);
}

s[qname] = val;

/* TODO: consider refactoring errorHandler into parse and compute routines */
Expand Down
8 changes: 7 additions & 1 deletion src/main/js/isd.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ function isdProcessContentElement(doc, offset, region, body, parent, inherited_r
if (offset < elem.sets[i].begin || offset >= elem.sets[i].end)
continue;

styleAttrs[elem.sets[i].qname] = elem.sets[i].value;
for (const qname in elem.sets[i].styles) {

if (!hasOwnProperty(elem.sets[i].styles, qname)) continue;

styleAttrs[qname] = elem.sets[i].styles[qname];

}

}
}
Expand Down
40 changes: 40 additions & 0 deletions src/test/js/SetMultipleStylesTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { equal } from "node:assert";
import { test } from "node:test";
import { generateISD } from "../../main/js/isd.js";
import { getIMSC1Document } from "./utils/getIMSC1Document.js";

const FONT_WEIGHT_QNAME = "http://www.w3.org/ns/ttml#styling fontWeight";
const TEXT_ALIGN_QNAME = "http://www.w3.org/ns/ttml#styling textAlign";

test("Multiple styles specified on set", async () => {
const doc = await getIMSC1Document("./src/test/resources/unit-tests/setMultipleStyles.ttml");

const set = doc.body.contents[0].contents[0].sets[0];

equal(set.styles[FONT_WEIGHT_QNAME], "bold");
equal(set.styles[TEXT_ALIGN_QNAME], "end");

/* before the set is active */

const before = generateISD(doc, 0.5);
const pBefore = before.contents[0].contents[0].contents[0].contents[0];

equal(pBefore.styleAttrs[FONT_WEIGHT_QNAME], "normal");
equal(pBefore.styleAttrs[TEXT_ALIGN_QNAME], "start");

/* while the set is active */

const during = generateISD(doc, 3);
const pDuring = during.contents[0].contents[0].contents[0].contents[0];

equal(pDuring.styleAttrs[FONT_WEIGHT_QNAME], "bold");
equal(pDuring.styleAttrs[TEXT_ALIGN_QNAME], "end");

/* after the set is no longer active */

const after = generateISD(doc, 7);
const pAfter = after.contents[0].contents[0].contents[0].contents[0];

equal(pAfter.styleAttrs[FONT_WEIGHT_QNAME], "normal");
equal(pAfter.styleAttrs[TEXT_ALIGN_QNAME], "start");
});
15 changes: 15 additions & 0 deletions src/test/resources/unit-tests/setMultipleStyles.ttml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<tt xml:lang="en" xmlns="http://www.w3.org/ns/ttml"
xmlns:ttp="http://www.w3.org/ns/ttml#parameter" ttp:profile="http://www.w3.org/ns/ttml/profile/imsc1/text"
xmlns:tts="http://www.w3.org/ns/ttml#styling">
<head>
</head>
<body>
<div>
<p begin="0s" end="10s">
Hello
<set begin="1s" end="5s" tts:fontWeight="bold" tts:textAlign="end"/>
</p>
</div>
</body>
</tt>
Loading