From f55830679280485187ab54aff2cf50c8c5ce49f8 Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Fri, 26 Jun 2020 21:55:58 -0700 Subject: [PATCH] Support textEmphasis across linebreaks (#188) --- src/main/js/html.js | 130 +++++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 55 deletions(-) diff --git a/src/main/js/html.js b/src/main/js/html.js index 44d7307a..979d40ff 100644 --- a/src/main/js/html.js +++ b/src/main/js/html.js @@ -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') { @@ -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 @@ -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); @@ -465,7 +479,7 @@ if (context.textEmphasis) { - applyTextEmphasis(linelist, context); + applyTextEmphasisOutside(linelist, context); context.textEmphasis = null; @@ -642,7 +656,7 @@ } - function applyTextEmphasis(lineList, context) { + function applyTextEmphasisOutside(lineList, context) { /* supports "outside" only */ @@ -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; @@ -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(