Skip to content

Commit

Permalink
Handle LWSP when parsing tts:fontFamily
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjuggins authored Dec 22, 2023
1 parent bf2e98a commit 2c939c8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/js/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
var rslt = [];

for (var i = 0; i < ffs.length; i++) {
ffs[i] = ffs[i].trim();

if (ffs[i].charAt(0) !== "'" && ffs[i].charAt(0) !== '"') {

Expand Down
16 changes: 16 additions & 0 deletions src/test/resources/unit-tests/fontFamily.ttml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<tt xml:lang="en" xmlns="http://www.w3.org/ns/ttml" xmlns:ttm="http://www.w3.org/ns/ttml#metadata"
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" ttp:cellResolution="1 1" tts:extent="100px 100px">
<head>
</head>
<body>
<div>
<p tts:fontFamily="default">Maps 'default' generic family name to 'monospaceSerif' correctly.</p>
<p tts:fontFamily="Arial,default">Maps 'default' value used as a fallback to 'monospaceSerif' correctly.</p>
<p tts:fontFamily="Arial, default ">Maps 'default' value used as a fallback with spacing characters to 'monospaceSerif' correctly.</p>
<p tts:fontFamily="'My Test Font', default ">Fonts names wrapped in '' are preserved.</p>
<p tts:fontFamily='"My Test Font", default '>Fonts names wrapped in "" are preserved.</p>
</div>
</body>
</tt>
44 changes: 43 additions & 1 deletion src/test/webapp/js/unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,46 @@ QUnit.test(
return getIMSC1Document("unit-tests/metadataHandler.ttml", mh);

}
);
);

QUnit.test(
"Font Family Parsing",
function (assert) {

return getIMSC1Document("unit-tests/fontFamily.ttml").then(
function (doc) {

assert.deepEqual(
doc.body.contents[0].contents[0].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
["monospaceSerif"],
"Maps 'default' generic family name to 'monospaceSerif' correctly."
);

assert.deepEqual(
doc.body.contents[0].contents[1].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
["Arial", "monospaceSerif"],
"Maps 'default' value used as a fallback to 'monospaceSerif' correctly."
);

assert.deepEqual(
doc.body.contents[0].contents[2].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
["Arial", "monospaceSerif"],
"Maps 'default' value used as a fallback with spacing characters to 'monospaceSerif' correctly."
);

assert.deepEqual(
doc.body.contents[0].contents[3].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
["'My Test Font'", "monospaceSerif"],
"Fonts names wrapped in '' are preserved."
);

assert.deepEqual(
doc.body.contents[0].contents[4].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
['"My Test Font"', "monospaceSerif"],
'Fonts names wrapped in "" are preserved.'
);
}
);

}
);

0 comments on commit 2c939c8

Please sign in to comment.