Skip to content

Commit c4009d5

Browse files
committed
Merge branch 'feature/rollup-support'
2 parents 6ac4463 + 7d54bde commit c4009d5

File tree

3 files changed

+138
-5
lines changed

3 files changed

+138
-5
lines changed

README.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ at a point in time (`offset` parameter). This point in time does not have to be
101101
example, given an ISOBMFF sample covering the interval `[a, b[`, `generateISD(tt, offset, errorHandler)` would be called first with `offset = a`,
102102
then in turn with offset set to each value of `getMediaTimeEvents()` that fall in the interval `]a, b[`.
103103

104-
* `renderHTML(isd, element, imgResolver, eheight, ewidth, displayForcedOnlyMode, errorHandler)` renders an `isd` object returned by `generateISD()`
104+
* `renderHTML(isd, element, imgResolver, eheight, ewidth, displayForcedOnlyMode, errorHandler, previousISDState, enableRollUp)`
105+
renders an `isd` object returned by `generateISD()`
105106
into a newly-created `div` element that is appended to the `element`. The `element` must be attached to the DOM.
106107
The height and width of the child `div` element are equal to `eheight` and `ewidth` if not null, or `clientWidth` and `clientHeight` of the
107108
parent `element` otherwise. Images URIs specified in `smpte:background` attributes are mapped to image resource URLs by the `imgResolver`
108109
function. The latter takes the value of the `smpte:background` attribute URI and an `img` DOM element as input and is expected to
109110
set the `src` attribute of the `img` DOM element to the absolute URI of the image. `displayForcedOnlyMode` sets the (boolean) value
110-
of the IMSC1 displayForcedOnlyMode parameter.
111+
of the IMSC1 displayForcedOnlyMode parameter. `enableRollUp` enables roll-up as specified in CEA 708. `previousISDState` maintains states across
112+
calls, e.g. for roll-up processing.
111113

112114
In each step, the caller can provide an `errorHandler` to be notified of events during processing. The `errorHandler` may define four methods:
113115
`info`, `warn`, `error` and `fatal`. Each is called with a string argument describing the event, and will cause processing to terminate if it

src/main/js/html.js

Lines changed: 128 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
* attribute and an <code>img</code> DOM element as input, and is expected to
5151
* set the <code>src</code> attribute of the <code>img</code> to the absolute URI of the image.
5252
* <pre>displayForcedOnlyMode</pre> sets the (boolean)
53-
* value of the IMSC1 displayForcedOnlyMode parameter.
53+
* value of the IMSC1 displayForcedOnlyMode parameter. The function returns
54+
* an opaque object that should passed in <code>previousISDState</code> when this function
55+
* is called for the next ISD, otherwise <code>previousISDState</code> should be set to
56+
* <code>null</code>.
5457
*
5558
* @param {Object} isd ISD to be rendered
5659
* @param {Object} element Element into which the ISD is rendered
@@ -62,9 +65,21 @@
6265
* @param {?boolean} displayForcedOnlyMode Value of the IMSC1 displayForcedOnlyMode parameter,
6366
* or false if null
6467
* @param {?module:imscUtils.ErrorHandler} errorHandler Error callback
68+
* @param {Object} previousISDState State saved during processing of the previous ISD, or null if initial call
69+
* @param {?boolean} enableRollUp Enables roll-up animations (see CEA 708)
70+
* @return {Object} ISD state to be provided when this funtion is called for the next ISD
6571
*/
6672

67-
imscHTML.render = function (isd, element, imgResolver, eheight, ewidth, displayForcedOnlyMode, errorHandler) {
73+
imscHTML.render = function ( isd,
74+
element,
75+
imgResolver,
76+
eheight,
77+
ewidth,
78+
displayForcedOnlyMode,
79+
errorHandler,
80+
previousISDState,
81+
enableRollUp
82+
) {
6883

6984
/* maintain aspect ratio if specified */
7085

@@ -107,7 +122,10 @@
107122
imgResolver: imgResolver,
108123
displayForcedOnlyMode: displayForcedOnlyMode || false,
109124
isd: isd,
110-
errorHandler: errorHandler
125+
errorHandler: errorHandler,
126+
previousISDState: previousISDState,
127+
enableRollUp : enableRollUp || false,
128+
currentISDState: {}
111129
};
112130

113131
element.appendChild(rootcontainer);
@@ -118,6 +136,8 @@
118136

119137
}
120138

139+
return context.currentISDState;
140+
121141
};
122142

123143
function processElement(context, dom_parent, isd_element) {
@@ -263,6 +283,61 @@
263283

264284
}
265285

286+
/* region processing */
287+
288+
if (isd_element.kind === "region") {
289+
290+
/* build line list */
291+
292+
var linelist = [];
293+
294+
constructLineList(proc_e, linelist);
295+
296+
/* perform roll up if needed */
297+
298+
var wdir = isd_element.styleAttrs[imscStyles.byName.writingMode.qname];
299+
300+
if ((wdir === "lrtb" || wdir === "lr" || wdir === "rltb" || wdir === "rl") &&
301+
context.enableRollUp &&
302+
isd_element.contents.length > 0 &&
303+
isd_element.styleAttrs[imscStyles.byName.displayAlign.qname] === 'after') {
304+
305+
/* horrible hack, perhaps default region id should be underscore everywhere? */
306+
307+
var rid = isd_element.id === '' ? '_' : isd_element.id;
308+
309+
var rb = new RegionPBuffer(rid, linelist);
310+
311+
context.currentISDState[rb.id] = rb;
312+
313+
if (context.previousISDState &&
314+
rb.id in context.previousISDState &&
315+
context.previousISDState[rb.id].plist.length > 0 &&
316+
rb.plist.length > 1 &&
317+
rb.plist[rb.plist.length - 2].text ===
318+
context.previousISDState[rb.id].plist[context.previousISDState[rb.id].plist.length - 1].text) {
319+
320+
var body_elem = e.firstElementChild;
321+
322+
body_elem.style.bottom = "-" + rb.plist[rb.plist.length - 1].height + "px";
323+
body_elem.style.transition = "transform 0.4s";
324+
body_elem.style.position = "relative";
325+
body_elem.style.transform = "translateY(-" + rb.plist[rb.plist.length - 1].height + "px)";
326+
327+
}
328+
329+
}
330+
331+
}
332+
}
333+
334+
335+
function RegionPBuffer(id, lineList) {
336+
337+
this.id = id;
338+
339+
this.plist = lineList;
340+
266341
}
267342

268343
function pruneEmptySpans(element) {
@@ -320,6 +395,56 @@
320395

321396
}
322397

398+
399+
function constructLineList(element, llist) {
400+
401+
if (element.childElementCount === 0 && element.localName === 'span') {
402+
403+
var r = element.getBoundingClientRect();
404+
405+
if (llist.length === 0 ||
406+
(!isSameLine(r.top, r.height, llist[llist.length - 1].top, llist[llist.length - 1].height))
407+
) {
408+
409+
llist.push({
410+
top: r.top,
411+
height: r.height,
412+
text: element.textContent
413+
});
414+
415+
} else {
416+
417+
if (r.top < llist[llist.length - 1].top) {
418+
llist[llist.length - 1].top = r.top;
419+
}
420+
421+
if (r.height > llist[llist.length - 1].height) {
422+
llist[llist.length - 1].height = r.height;
423+
}
424+
425+
llist[llist.length - 1].text += element.textContent;
426+
427+
}
428+
429+
} else {
430+
431+
432+
var child = element.firstChild;
433+
434+
while (child) {
435+
436+
if (child.nodeType === Node.ELEMENT_NODE) {
437+
438+
constructLineList(child, llist);
439+
440+
}
441+
442+
child = child.nextSibling;
443+
}
444+
}
445+
446+
}
447+
323448
function isSameLine(top1, height1, top2, height2) {
324449

325450
return (((top1 + height1) < (top2 + height2)) && (top1 > top2)) || (((top2 + height2) <= (top1 + height1)) && (top2 >= top1));

src/main/js/isd.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,12 @@
529529
/* assume the element is a region if it does not have a kind */
530530

531531
this.kind = ttelem.kind || 'region';
532+
533+
/* copy id */
534+
535+
if (ttelem.id) {
536+
this.id = ttelem.id;
537+
}
532538

533539
/* deep copy of style attributes */
534540
this.styleAttrs = {};

0 commit comments

Comments
 (0)