mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #16225 from calixteman/16224
Thin whitespaces must have their own span
This commit is contained in:
commit
c1c372c320
4 changed files with 55 additions and 26 deletions
|
@ -2310,6 +2310,13 @@ class PartialEvaluator {
|
|||
return ret;
|
||||
}
|
||||
|
||||
function shouldAddWhitepsace() {
|
||||
return (
|
||||
twoLastChars[twoLastCharsPos] !== " " &&
|
||||
twoLastChars[(twoLastCharsPos + 1) % 2] === " "
|
||||
);
|
||||
}
|
||||
|
||||
function resetLastChars() {
|
||||
twoLastChars[0] = twoLastChars[1] = " ";
|
||||
twoLastCharsPos = 0;
|
||||
|
@ -2359,6 +2366,23 @@ class PartialEvaluator {
|
|||
|
||||
let textState;
|
||||
|
||||
function pushWhitespace({
|
||||
width = 0,
|
||||
height = 0,
|
||||
transform = textContentItem.prevTransform,
|
||||
fontName = textContentItem.fontName,
|
||||
}) {
|
||||
textContent.items.push({
|
||||
str: " ",
|
||||
dir: "ltr",
|
||||
width,
|
||||
height,
|
||||
transform,
|
||||
fontName,
|
||||
hasEOL: false,
|
||||
});
|
||||
}
|
||||
|
||||
function getCurrentTextTransform() {
|
||||
// 9.4.4 Text Space Details
|
||||
const font = textState.font;
|
||||
|
@ -2626,7 +2650,16 @@ class PartialEvaluator {
|
|||
}
|
||||
|
||||
if (advanceY <= textOrientation * textContentItem.trackingSpaceMin) {
|
||||
textContentItem.height += advanceY;
|
||||
if (shouldAddWhitepsace()) {
|
||||
// The space is very thin, hence it deserves to have its own span in
|
||||
// order to avoid too much shift between the canvas and the text
|
||||
// layer.
|
||||
resetLastChars();
|
||||
flushTextContentItem();
|
||||
pushWhitespace({ height: Math.abs(advanceY) });
|
||||
} else {
|
||||
textContentItem.height += advanceY;
|
||||
}
|
||||
} else if (
|
||||
!addFakeSpaces(
|
||||
advanceY,
|
||||
|
@ -2636,15 +2669,7 @@ class PartialEvaluator {
|
|||
) {
|
||||
if (textContentItem.str.length === 0) {
|
||||
resetLastChars();
|
||||
textContent.items.push({
|
||||
str: " ",
|
||||
dir: "ltr",
|
||||
width: 0,
|
||||
height: Math.abs(advanceY),
|
||||
transform: textContentItem.prevTransform,
|
||||
fontName: textContentItem.fontName,
|
||||
hasEOL: false,
|
||||
});
|
||||
pushWhitespace({ height: Math.abs(advanceY) });
|
||||
} else {
|
||||
textContentItem.height += advanceY;
|
||||
}
|
||||
|
@ -2691,21 +2716,22 @@ class PartialEvaluator {
|
|||
}
|
||||
|
||||
if (advanceX <= textOrientation * textContentItem.trackingSpaceMin) {
|
||||
textContentItem.width += advanceX;
|
||||
if (shouldAddWhitepsace()) {
|
||||
// The space is very thin, hence it deserves to have its own span in
|
||||
// order to avoid too much shift between the canvas and the text
|
||||
// layer.
|
||||
resetLastChars();
|
||||
flushTextContentItem();
|
||||
pushWhitespace({ width: Math.abs(advanceX) });
|
||||
} else {
|
||||
textContentItem.width += advanceX;
|
||||
}
|
||||
} else if (
|
||||
!addFakeSpaces(advanceX, textContentItem.prevTransform, textOrientation)
|
||||
) {
|
||||
if (textContentItem.str.length === 0) {
|
||||
resetLastChars();
|
||||
textContent.items.push({
|
||||
str: " ",
|
||||
dir: "ltr",
|
||||
width: Math.abs(advanceX),
|
||||
height: 0,
|
||||
transform: textContentItem.prevTransform,
|
||||
fontName: textContentItem.fontName,
|
||||
hasEOL: false,
|
||||
});
|
||||
pushWhitespace({ width: Math.abs(advanceX) });
|
||||
} else {
|
||||
textContentItem.width += advanceX;
|
||||
}
|
||||
|
@ -2867,16 +2893,11 @@ class PartialEvaluator {
|
|||
|
||||
flushTextContentItem();
|
||||
resetLastChars();
|
||||
textContent.items.push({
|
||||
str: " ",
|
||||
// TODO: check if using the orientation from last chunk is
|
||||
// better or not.
|
||||
dir: "ltr",
|
||||
pushWhitespace({
|
||||
width: Math.abs(width),
|
||||
height: Math.abs(height),
|
||||
transform: transf || getCurrentTextTransform(),
|
||||
fontName,
|
||||
hasEOL: false,
|
||||
});
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue