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

change of scheme for rubyReserve. #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 31 additions & 75 deletions src/main/js/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,91 +871,47 @@
}

function applyRubyReserve(lineList, context) {

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

var ruby = document.createElement("ruby");
var rubyover = document.createElement("ruby");
var fs = context.rubyReserve[1].toUsedLength(context.w, context.h) + "px";

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

ruby.appendChild(rb);

var rt1;
var rt2;

var fs = context.rubyReserve[1].toUsedLength(context.w, context.h) + "px";
rb.textContent = "ん";
rb.style.marginInlineStart = '-10em';
var rt = document.createElement("rt");
/* note: the text content matters from a size perspective */
rt.textContent = "ん";
rt.style.fontSize = fs;
rt.style.marginInlineStart = '-10em';
rubyover.style.visibility = 'hidden';
rubyover.style.rubyPosition = 'over';
rubyover.appendChild(rb);
rubyover.appendChild(rt);

var rubyunder = rubyover.cloneNode(true);
rubyunder.style.rubyPosition = 'under';

// get first leaf node on this line.
var sib = lineList[i].elements[0].node;
var target = sib;
var parent = sib.parentElement;
while (parent.nodeName !== 'P'){
target = parent;
parent = parent.parentElement;
}

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

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

rt2 = document.createElement("rtc");
rt2.style[RUBYPOSITION_PROP] = RUBYPOSITION_ISWK ? "before" : "over";
rt2.textContent = "\u200B";
rt2.style.fontSize = fs;

ruby.appendChild(rt1);
ruby.appendChild(rt2);

target.parentElement.insertBefore(rubyover, target);
target.parentElement.insertBefore(rubyunder, target);
} else {

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

var pos;

if (context.rubyReserve[0] === "after" || (context.rubyReserve[0] === "outside" && i > 0)) {

pos = RUBYPOSITION_ISWK ? "after" : ((context.bpd === "tb" || context.bpd === "rl") ? "under" : "over");

target.parentElement.insertBefore(rubyunder, target);
} else {

pos = RUBYPOSITION_ISWK ? "before" : ((context.bpd === "tb" || context.bpd === "rl") ? "over" : "under");

target.parentElement.insertBefore(rubyover, target);
}

rt1.style[RUBYPOSITION_PROP] = pos;

ruby.appendChild(rt1);

}

/* add in front of the first ruby element of the line, if it exists */

var sib = null;

for (var j = 0; j < lineList[i].rbc.length; j++) {

if (lineList[i].rbc[j].localName === 'ruby') {

sib = lineList[i].rbc[j];

/* copy specified style properties from the sibling ruby container */

for (var k = 0; k < sib.style.length; k++) {

ruby.style.setProperty(sib.style.item(k), sib.style.getPropertyValue(sib.style.item(k)));

}

break;
}

}

/* otherwise add before first span */

sib = sib || lineList[i].elements[0].node;

sib.parentElement.insertBefore(ruby, sib);

}

}

function applyFillLineGap(lineList, par_before, par_after, context, element) {
Expand Down Expand Up @@ -1822,7 +1778,7 @@

/* CSS property names */

var RUBYPOSITION_ISWK = "webkitRubyPosition" in window.getComputedStyle(document.documentElement);
var RUBYPOSITION_ISWK = false; //"webkitRubyPosition" in window.getComputedStyle(document.documentElement);

var RUBYPOSITION_PROP = RUBYPOSITION_ISWK ? "webkitRubyPosition" : "rubyPosition";

Expand Down