Skip to content

Commit

Permalink
Support textEmphasis across linebreaks (sandflow#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
palemieux authored and nigelmegitt committed Dec 11, 2020
1 parent 75989e2 commit f558306
Showing 1 changed file with 75 additions and 55 deletions.
130 changes: 75 additions & 55 deletions src/main/js/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,6 @@

}

var te = isd_element.styleAttrs[imscStyles.byName.textEmphasis.qname];

if (te && te.style !== "none") {

context.textEmphasis = true;

}

//e.textContent = isd_element.text;

} else if (isd_element.kind === 'br') {
Expand Down Expand Up @@ -383,12 +375,26 @@

if (isd_element.kind === "span" && isd_element.text) {

var te = isd_element.styleAttrs[imscStyles.byName.textEmphasis.qname];

if (te && te.style !== "none") {

context.textEmphasis = true;

}

if (imscStyles.byName.textCombine.qname in isd_element.styleAttrs &&
isd_element.styleAttrs[imscStyles.byName.textCombine.qname][0] === "all") {

/* ignore tate-chu-yoku since line break cannot happen within */
e.textContent = isd_element.text;

if (te) {

applyTextEmphasis(context, e, isd_element, te);

};

} else {

// wrap characters in spans to find the line wrap locations
Expand All @@ -408,6 +414,14 @@
var span = document.createElement("span");

span.textContent = cbuf;

/* apply textEmphasis */

if (te) {

applyTextEmphasis(context, span, isd_element, te);

};

e.appendChild(span);

Expand Down Expand Up @@ -465,7 +479,7 @@

if (context.textEmphasis) {

applyTextEmphasis(linelist, context);
applyTextEmphasisOutside(linelist, context);

context.textEmphasis = null;

Expand Down Expand Up @@ -642,7 +656,7 @@

}

function applyTextEmphasis(lineList, context) {
function applyTextEmphasisOutside(lineList, context) {

/* supports "outside" only */

Expand Down Expand Up @@ -1120,6 +1134,56 @@

}

function applyTextEmphasis(context, dom_element, isd_element, attr) {

/* ignore color (not used in IMSC 1.1) */

if (attr.style === "none") {

dom_element.style[TEXTEMPHASISSTYLE_PROP] = "none";

/* no need to set position, so return */

return;

} else if (attr.style === "auto") {

dom_element.style[TEXTEMPHASISSTYLE_PROP] = "filled";

} else {

dom_element.style[TEXTEMPHASISSTYLE_PROP] = attr.style + " " + attr.symbol;
}

/* ignore "outside" position (set in postprocessing) */

if (attr.position === "before" || attr.position === "after") {

var pos;

if (context.bpd === "tb") {

pos = (attr.position === "before") ? "left over" : "left under";


} else {

if (context.bpd === "rl") {

pos = (attr.position === "before") ? "right under" : "left under";

} else {

pos = (attr.position === "before") ? "left under" : "right under";

}

}

dom_element.style[TEXTEMPHASISPOSITION_PROP] = pos;
}
}

function HTMLStylingMapDefintion(qName, mapFunc) {
this.qname = qName;
this.map = mapFunc;
Expand Down Expand Up @@ -1547,52 +1611,8 @@
"http://www.w3.org/ns/ttml#styling textEmphasis",
function (context, dom_element, isd_element, attr) {

/* ignore color (not used in IMSC 1.1) */

if (attr.style === "none") {

dom_element.style[TEXTEMPHASISSTYLE_PROP] = "none";
/* applied as part of HTML document construction */

/* no need to set position, so return */

return;

} else if (attr.style === "auto") {

dom_element.style[TEXTEMPHASISSTYLE_PROP] = "filled";

} else {

dom_element.style[TEXTEMPHASISSTYLE_PROP] = attr.style + " " + attr.symbol;
}

/* ignore "outside" position (set in postprocessing) */

if (attr.position === "before" || attr.position === "after") {

var pos;

if (context.bpd === "tb") {

pos = (attr.position === "before") ? "left over" : "left under";


} else {

if (context.bpd === "rl") {

pos = (attr.position === "before") ? "right under" : "left under";

} else {

pos = (attr.position === "before") ? "left under" : "right under";

}

}

dom_element.style[TEXTEMPHASISPOSITION_PROP] = pos;
}
}
),
new HTMLStylingMapDefintion(
Expand Down

0 comments on commit f558306

Please sign in to comment.