Skip to content

Commit 2c939c8

Browse files
authored
Handle LWSP when parsing tts:fontFamily
#250
1 parent bf2e98a commit 2c939c8

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

src/main/js/styles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
var rslt = [];
194194

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

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<tt xml:lang="en" xmlns="http://www.w3.org/ns/ttml" xmlns:ttm="http://www.w3.org/ns/ttml#metadata"
3+
xmlns:ttp="http://www.w3.org/ns/ttml#parameter" ttp:profile="http://www.w3.org/ns/ttml/profile/imsc1/text"
4+
xmlns:tts="http://www.w3.org/ns/ttml#styling" ttp:cellResolution="1 1" tts:extent="100px 100px">
5+
<head>
6+
</head>
7+
<body>
8+
<div>
9+
<p tts:fontFamily="default">Maps 'default' generic family name to 'monospaceSerif' correctly.</p>
10+
<p tts:fontFamily="Arial,default">Maps 'default' value used as a fallback to 'monospaceSerif' correctly.</p>
11+
<p tts:fontFamily="Arial, default ">Maps 'default' value used as a fallback with spacing characters to 'monospaceSerif' correctly.</p>
12+
<p tts:fontFamily="'My Test Font', default ">Fonts names wrapped in '' are preserved.</p>
13+
<p tts:fontFamily='"My Test Font", default '>Fonts names wrapped in "" are preserved.</p>
14+
</div>
15+
</body>
16+
</tt>

src/test/webapp/js/unit-tests.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,46 @@ QUnit.test(
167167
return getIMSC1Document("unit-tests/metadataHandler.ttml", mh);
168168

169169
}
170-
);
170+
);
171+
172+
QUnit.test(
173+
"Font Family Parsing",
174+
function (assert) {
175+
176+
return getIMSC1Document("unit-tests/fontFamily.ttml").then(
177+
function (doc) {
178+
179+
assert.deepEqual(
180+
doc.body.contents[0].contents[0].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
181+
["monospaceSerif"],
182+
"Maps 'default' generic family name to 'monospaceSerif' correctly."
183+
);
184+
185+
assert.deepEqual(
186+
doc.body.contents[0].contents[1].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
187+
["Arial", "monospaceSerif"],
188+
"Maps 'default' value used as a fallback to 'monospaceSerif' correctly."
189+
);
190+
191+
assert.deepEqual(
192+
doc.body.contents[0].contents[2].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
193+
["Arial", "monospaceSerif"],
194+
"Maps 'default' value used as a fallback with spacing characters to 'monospaceSerif' correctly."
195+
);
196+
197+
assert.deepEqual(
198+
doc.body.contents[0].contents[3].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
199+
["'My Test Font'", "monospaceSerif"],
200+
"Fonts names wrapped in '' are preserved."
201+
);
202+
203+
assert.deepEqual(
204+
doc.body.contents[0].contents[4].styleAttrs["http://www.w3.org/ns/ttml#styling fontFamily"],
205+
['"My Test Font"', "monospaceSerif"],
206+
'Fonts names wrapped in "" are preserved.'
207+
);
208+
}
209+
);
210+
211+
}
212+
);

0 commit comments

Comments
 (0)