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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The headless script [src/test/script/gen-render-package.mjs](src/test/script/gen
```sh
npm run gen-imsc1
npm run gen-imsc1_1
npm run gen-imsc1_3
```

[src/test/script/compare_renders.py](src/test/script/compare_renders.py) compares two such render outputs (unzipped), performing byte-level, JSON/HTML and pixel-level PNG diffs, and optionally generating an HTML comparison report.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"prepublishOnly": "npm run build",
"gen-imsc1": "node src/test/script/gen-render-package.mjs imsc-tests/imsc1 build/renders-imsc1.zip",
"gen-imsc1_1": "node src/test/script/gen-render-package.mjs imsc-tests/imsc1_1 build/renders-imsc1_1.zip",
"gen-imsc1_3": "node src/test/script/gen-render-package.mjs imsc-tests/imsc1_3 build/renders-imsc1_3.zip",
"gen-reference-files": "node src/test/script/gen-reference-files.mjs",
"install:firefox": "puppeteer browsers install firefox",
"lint": "eslint .",
Expand Down
25 changes: 25 additions & 0 deletions src/main/js/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,31 @@ const STYLING_MAP_DEFS = [
dom_element.style.fontStyle = attr;
},
),
new HTMLStylingMapDefinition(
"http://www.w3.org/ns/ttml#styling fontVariant",
function (context, dom_element, isd_element, attr) {

/*
* font-variant-position is not used since some browsers do not
* synthesize sub/superscript glyphs when the font does not provide
* them.
*
* vertical-align/font-size are applied only to spans that contain
* text to avoid accumulating baseline offsets and smaller font
* size.
*
* The sub/superscript font size is 70% of the normal font size.
*/

if (!isd_element.text || attr === "normal") return;

dom_element.style.verticalAlign = attr;

const fs = isd_element.styleAttrs[byName.fontSize.qname];

dom_element.style.fontSize = (fs.toUsedLength(context.w, context.h) * 0.70) + "px";
},
),
new HTMLStylingMapDefinition(
"http://www.w3.org/ns/ttml#styling fontWeight",
function (context, dom_element, isd_element, attr) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/js/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ export const all = [
},
null,
),
new StylingAttributeDefinition(
ns_tts,
"fontVariant",
"normal",
["span"],
true,
true,
function (str) {
if (str === "normal" || str === "sub" || str === "super") {

return str;
}

return null;
},
null,
),
new StylingAttributeDefinition(
ns_tts,
"fontWeight",
Expand Down
64 changes: 64 additions & 0 deletions src/test/js/FontVariantTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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_VARIANT_QNAME = "http://www.w3.org/ns/ttml#styling fontVariant";

test("tts:fontVariant", async () => {
const doc = await getIMSC1Document("./src/test/resources/unit-tests/fontVariant.ttml");

const isd = generateISD(doc, 1);
const p = isd.contents[0].contents[0].contents[0].contents[0];

/* not applicable to p */

equal(FONT_VARIANT_QNAME in p.styleAttrs, false);

/* initial value */

equal(p.contents[0].styleAttrs[FONT_VARIANT_QNAME], "normal");
equal(p.contents[2].styleAttrs[FONT_VARIANT_QNAME], "normal");

/* explicit super, inherited by nested span */

const sup = p.contents[1];

equal(sup.styleAttrs[FONT_VARIANT_QNAME], "super");
equal(sup.contents[0].styleAttrs[FONT_VARIANT_QNAME], "super");
equal(sup.contents[1].styleAttrs[FONT_VARIANT_QNAME], "super");

/* explicit sub */

equal(p.contents[3].styleAttrs[FONT_VARIANT_QNAME], "sub");

/* inherited through p, even though not applicable to p */

const p2 = isd.contents[0].contents[0].contents[0].contents[1];

equal(FONT_VARIANT_QNAME in p2.styleAttrs, false);
equal(p2.contents[0].styleAttrs[FONT_VARIANT_QNAME], "sub");
equal(p2.contents[1].styleAttrs[FONT_VARIANT_QNAME], "normal");
});

test("tts:fontVariant (imsc-tests fontVariant001)", async () => {
const doc = await getIMSC1Document("./src/test/resources/imsc-tests/imsc1_3/ttml/fontVariant/fontVariant001.ttml");

const isd = generateISD(doc, 0);
const div = isd.contents[0].contents[0].contents[0];

const expected = [
["normal", "super", "normal", "super", "normal"],
["normal", "sub", "normal", "sub", "normal"],
];

for (let i = 0; i < expected.length; i++) {
const spans = div.contents[i].contents;

equal(spans.length, expected[i].length);

for (let j = 0; j < expected[i].length; j++) {
equal(spans[j].styleAttrs[FONT_VARIANT_QNAME], expected[i][j]);
}
}
});
2 changes: 1 addition & 1 deletion src/test/js/GenerateReferenceFilesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { renderTestSuite } from "../script/render-harness.mjs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const REFERENCE_FILES_ROOT = path.resolve(__dirname, "..", "resources", "reference-files");

const REFFILES_ROOTS = ["imsc-tests/imsc1", "imsc-tests/imsc1_1"];
const REFFILES_ROOTS = ["imsc-tests/imsc1", "imsc-tests/imsc1_1", "imsc-tests/imsc1_3"];

async function listFilesRecursively(dir) {
const entries = await fs.readdir(dir, { withFileTypes: true, recursive: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"rh": 0.05
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down Expand Up @@ -333,6 +334,7 @@
"rh": 0.05
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down Expand Up @@ -518,6 +520,7 @@
"rh": 0.05
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "bold",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down Expand Up @@ -200,6 +201,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down Expand Up @@ -203,6 +204,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"rh": 0.06666666666666667
},
"http://www.w3.org/ns/ttml#styling fontStyle": "normal",
"http://www.w3.org/ns/ttml#styling fontVariant": "normal",
"http://www.w3.org/ns/ttml#styling fontWeight": "normal",
"http://www.w3.org/ns/ttml#styling textCombine": "none",
"http://www.w3.org/ns/ttml#styling textDecoration": [
Expand Down
Loading
Loading