Commit 721f5c32 authored by Fred Chasen's avatar Fred Chasen

Merge branch 'hyphen_fixes' into 'master'

Hyphen Fixes

See merge request !42
parents 69705652 53469e15
Pipeline #173 passed with stage
in 3 minutes and 37 seconds
......@@ -302,6 +302,11 @@ class Layout {
parent = findElement(renderedNode, source);
index = indexOfTextNode(container, parent);
if (index === -1) {
return;
}
node = child(parent, index);
offset += node.textContent.indexOf(container.textContent);
......@@ -407,7 +412,7 @@ class Layout {
left = 0;
for (var i = 0; i != rects.length; i++) {
rect = rects[i];
if (!left || rect.left > left) {
if (rect.width > 0 && (!left || rect.left > left)) {
left = rect.left;
}
}
......@@ -542,21 +547,23 @@ class Layout {
}
removeOverflow(overflow) {
this.hyphenateAtBreak(overflow);
let {startContainer} = overflow;
let extracted = overflow.extractContents();
this.hyphenateAtBreak(startContainer);
return overflow.extractContents();
return extracted;
}
hyphenateAtBreak(overflow) {
if (isText(overflow.startContainer) && overflow.startOffset > 0) {
let startText = overflow.startContainer.textContent;
let startOffset = overflow.startOffset;
let prevLetter = startText[startOffset-1];
hyphenateAtBreak(startContainer) {
if (isText(startContainer)) {
let startText = startContainer.textContent;
let prevLetter = startText[startText.length-1];
// Add a hyphen if previous character is a letter or soft hyphen
if (/^\w|\u00AD$/.test(prevLetter)) {
overflow.startContainer.textContent = startText.slice(0, startOffset) + "\u2010";
overflow.setStart(overflow.startContainer, startOffset + 1);
startContainer.parentNode.classList.add("pagedjs_hyphen");
startContainer.textContent += "\u2011";
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment