Skip to content

Commit

Permalink
Fix linePadding on uneven lines (sandflow#65) (sandflow#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
palemieux authored Oct 18, 2017
1 parent bdbf2a4 commit 6ac4463
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/main/js/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@
e = document.createElement("br");

}
if (! e) {

if (!e) {

reportError(context.errorHandler, "Error processing ISD element kind: " + isd_element.kind);

return;

}

/* override UA default margin */
Expand Down Expand Up @@ -247,7 +247,7 @@
if ((context.lp || context.mra) && isd_element.kind === "p") {

var elist = [];

constructElementList(proc_e, elist, "red");

/* TODO: linePadding only supported for horizontal scripts */
Expand Down Expand Up @@ -298,7 +298,7 @@
elist.push({
"element": element,
"bgcolor": bgcolor}
);
);

} else {

Expand All @@ -320,6 +320,12 @@

}

function isSameLine(top1, height1, top2, height2) {

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

}

function processLinePaddingAndMultiRowAlign(elist, lp) {

var line_head = null;
Expand All @@ -343,7 +349,11 @@

if (line_head === null ||
i === elist.length ||
elist[i].element.getBoundingClientRect().top !== elist[line_head].element.getBoundingClientRect().top) {
(!isSameLine(elist[i].element.getBoundingClientRect().top,
elist[i].element.getBoundingClientRect().height,
elist[line_head].element.getBoundingClientRect().top,
elist[line_head].element.getBoundingClientRect().height))
) {

/* apply right padding to previous line (if applicable and unless this is the first line) */

Expand All @@ -356,7 +366,10 @@
addRightPadding(elist[i].element, elist[i].color, lp);

if (elist[i].element.getBoundingClientRect().width !== 0 &&
elist[i].element.getBoundingClientRect().top === elist[line_head].element.getBoundingClientRect().top)
isSameLine(elist[i].element.getBoundingClientRect().top,
elist[i].element.getBoundingClientRect().height,
elist[line_head].element.getBoundingClientRect().top,
elist[line_head].element.getBoundingClientRect().height))
break;

removeRightPadding(elist[i].element);
Expand Down Expand Up @@ -828,7 +841,7 @@

STYLMAP_BY_QNAME[STYLING_MAP_DEFS[i].qname] = STYLING_MAP_DEFS[i];
}

function reportError(errorHandler, msg) {

if (errorHandler && errorHandler.error && errorHandler.error(msg))
Expand Down

0 comments on commit 6ac4463

Please sign in to comment.