Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Externaldom #224

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 65 additions & 41 deletions src/main/js/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* @param {?module:imscUtils.ErrorHandler} errorHandler Error callback
* @param {Object} previousISDState State saved during processing of the previous ISD, or null if initial call
* @param {?boolean} enableRollUp Enables roll-up animations (see CEA 708)
* @param {?Object} options Additional options, e.g. { document: jsdom.window.document }
* @return {Object} ISD state to be provided when this funtion is called for the next ISD
*/

Expand All @@ -78,7 +79,8 @@
displayForcedOnlyMode,
errorHandler,
previousISDState,
enableRollUp
enableRollUp,
options
) {

/* maintain aspect ratio if specified */
Expand All @@ -102,24 +104,26 @@

}

var rootcontainer = document.createElement("div");

rootcontainer.style.position = "relative";
rootcontainer.style.width = width + "px";
rootcontainer.style.height = height + "px";
rootcontainer.style.margin = "auto";
rootcontainer.style.top = 0;
rootcontainer.style.bottom = 0;
rootcontainer.style.left = 0;
rootcontainer.style.right = 0;
rootcontainer.style.zIndex = 0;
options = options || {};

// if no alternative dom document, use browser's one
if (!options.document){
try{
options.document = document;
} catch (e) {
// no document object -
reportError(errorHandler, "Error no document object");
return;
}
}

var context = {
h: height,
w: width,
regionH: null,
regionW: null,
imgResolver: imgResolver,
document: options.document,
displayForcedOnlyMode: displayForcedOnlyMode || false,
isd: isd,
errorHandler: errorHandler,
Expand All @@ -135,6 +139,18 @@
textEmphasis: null, /* is textEmphasis present in a <p> */
rubyReserve: null /* is rubyReserve applicable to a <p> */
};

var rootcontainer = context.document.createElement("div");

rootcontainer.style.position = "relative";
rootcontainer.style.width = width + "px";
rootcontainer.style.height = height + "px";
rootcontainer.style.margin = "auto";
rootcontainer.style.top = 0;
rootcontainer.style.bottom = 0;
rootcontainer.style.left = 0;
rootcontainer.style.right = 0;
rootcontainer.style.zIndex = 0;

element.appendChild(rootcontainer);

Expand All @@ -158,20 +174,20 @@

if (isd_element.kind === 'region') {

e = document.createElement("div");
e = context.document.createElement("div");
e.style.position = "absolute";

} else if (isd_element.kind === 'body') {

e = document.createElement("div");
e = context.document.createElement("div");

} else if (isd_element.kind === 'div') {

e = document.createElement("div");
e = context.document.createElement("div");

} else if (isd_element.kind === 'image') {

e = document.createElement("img");
e = context.document.createElement("img");

if (context.imgResolver !== null && isd_element.src !== null) {

Expand All @@ -187,33 +203,33 @@

} else if (isd_element.kind === 'p') {

e = document.createElement("p");
e = context.document.createElement("p");

} else if (isd_element.kind === 'span') {

if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "container") {

e = document.createElement("ruby");
e = context.document.createElement("ruby");

context.ruby = true;

} else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "base") {

e = document.createElement("rb");
e = context.document.createElement("rb");

} else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "text") {

e = document.createElement("rt");
e = context.document.createElement("rt");


} else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "baseContainer") {

e = document.createElement("rbc");
e = context.document.createElement("rbc");


} else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "textContainer") {

e = document.createElement("rtc");
e = context.document.createElement("rtc");


} else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "delimiter") {
Expand All @@ -224,15 +240,15 @@

} else {

e = document.createElement("span");
e = context.document.createElement("span");

}

//e.textContent = isd_element.text;

} else if (isd_element.kind === 'br') {

e = document.createElement("br");
e = context.document.createElement("br");

}

Expand Down Expand Up @@ -356,7 +372,7 @@

/* create inline block to handle multirowAlign */

var s = document.createElement("span");
var s = context.document.createElement("span");

s.style.display = "inline-block";

Expand Down Expand Up @@ -424,7 +440,7 @@

/* wrap the character(s) in a span unless it is a high surrogate */

var span = document.createElement("span");
var span = context.document.createElement("span");

span.textContent = cbuf;

Expand Down Expand Up @@ -507,7 +523,7 @@

if (context.mra) {

applyMultiRowAlign(linelist);
applyMultiRowAlign(linelist, context);

context.mra = null;

Expand Down Expand Up @@ -761,7 +777,7 @@

}

function applyMultiRowAlign(lineList) {
function applyMultiRowAlign(lineList, context) {

/* apply an explicit br to all but the last line */

Expand All @@ -770,7 +786,7 @@
var l = lineList[i].elements.length;

if (l !== 0 && lineList[i].br === false) {
var br = document.createElement("br");
var br = context.document.createElement("br");

var lastnode = lineList[i].elements[l - 1].node;

Expand Down Expand Up @@ -874,9 +890,9 @@

for (var i = 0; i < lineList.length; i++) {

var ruby = document.createElement("ruby");
var ruby = context.document.createElement("ruby");

var rb = document.createElement("rb");
var rb = context.document.createElement("rb");
rb.textContent = "\u200B";

ruby.appendChild(rb);
Expand All @@ -888,12 +904,12 @@

if (context.rubyReserve[0] === "both" || (context.rubyReserve[0] === "outside" && lineList.length == 1)) {

rt1 = document.createElement("rtc");
rt1 = context.document.createElement("rtc");
rt1.style[RUBYPOSITION_PROP] = RUBYPOSITION_ISWK ? "after" : "under";
rt1.textContent = "\u200B";
rt1.style.fontSize = fs;

rt2 = document.createElement("rtc");
rt2 = context.document.createElement("rtc");
rt2.style[RUBYPOSITION_PROP] = RUBYPOSITION_ISWK ? "before" : "over";
rt2.textContent = "\u200B";
rt2.style.fontSize = fs;
Expand All @@ -903,7 +919,7 @@

} else {

rt1 = document.createElement("rtc");
rt1 = context.document.createElement("rtc");
rt1.textContent = "\u200B";
rt1.style.fontSize = fs;

Expand Down Expand Up @@ -1102,6 +1118,8 @@
return;

}

var Node = imscHTML.Node;

var curbgcolor = element.style.backgroundColor || bgcolor;

Expand Down Expand Up @@ -1183,7 +1201,7 @@

while (child) {

if (child.nodeType === Node.ELEMENT_NODE) {
if (child.nodeType === 1) { /* was Node.ELEMENT_NODE - but only in browser */

constructLineList(context, child, llist, curbgcolor);

Expand Down Expand Up @@ -1820,16 +1838,22 @@
STYLMAP_BY_QNAME[STYLING_MAP_DEFS[i].qname] = STYLING_MAP_DEFS[i];
}

/* CSS property names */

var RUBYPOSITION_ISWK = "webkitRubyPosition" in window.getComputedStyle(document.documentElement);
// if no browser window/document, then default, not break;
var RUBYPOSITION_ISWK = false;
var RUBYPOSITION_PROP = "rubyPosition";
var TEXTEMPHASISSTYLE_PROP = "textEmphasisStyle";
var TEXTEMPHASISPOSITION_PROP = "textEmphasisPosition";

var RUBYPOSITION_PROP = RUBYPOSITION_ISWK ? "webkitRubyPosition" : "rubyPosition";
try {
RUBYPOSITION_ISWK = "webkitRubyPosition" in window.getComputedStyle(document.documentElement);

var TEXTEMPHASISSTYLE_PROP = "webkitTextEmphasisStyle" in window.getComputedStyle(document.documentElement) ? "webkitTextEmphasisStyle" : "textEmphasisStyle";
RUBYPOSITION_PROP = RUBYPOSITION_ISWK ? "webkitRubyPosition" : "rubyPosition";

var TEXTEMPHASISPOSITION_PROP = "webkitTextEmphasisPosition" in window.getComputedStyle(document.documentElement) ? "webkitTextEmphasisPosition" : "textEmphasisPosition";
TEXTEMPHASISSTYLE_PROP = "webkitTextEmphasisStyle" in window.getComputedStyle(document.documentElement) ? "webkitTextEmphasisStyle" : "textEmphasisStyle";

TEXTEMPHASISPOSITION_PROP = "webkitTextEmphasisPosition" in window.getComputedStyle(document.documentElement) ? "webkitTextEmphasisPosition" : "textEmphasisPosition";
} catch (e){
}
/* error utilities */

function reportError(errorHandler, msg) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@

exports.generateISD = require('./isd').generateISD;
exports.fromXML = require('./doc').fromXML;
exports.renderHTML = require('./html').render;
exports.renderHTML = require('./html').render;
exports.styles = require('./styles');