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

Fix issue with space offsets in TJs #6019

Closed
wants to merge 4 commits into from
Closed
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
50 changes: 16 additions & 34 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
});
}

function buildTextGeometry(chars, textChunk) {
function buildTextGeometry(chars, textChunk, offset) {
var font = textState.font;
textChunk = textChunk || newTextChunk();
offset = offset || 0;
if (!textChunk.transform) {
// 9.4.4 Text Space Details
var tsm = [textState.fontSize * textState.textHScale, 0,
Expand Down Expand Up @@ -1036,17 +1037,19 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var ty = 0;
if (!font.vertical) {
var w0 = glyphWidth * textState.fontMatrix[0];
tx = (w0 * textState.fontSize + charSpacing) *
tx = ((w0 - offset) * textState.fontSize + charSpacing) *
textState.textHScale;
width += tx;
} else {
var w1 = glyphWidth * textState.fontMatrix[0];
ty = w1 * textState.fontSize + charSpacing;
ty = (w1 - offset) * textState.fontSize + charSpacing;
height += ty;
}
textState.translateTextMatrix(tx, ty);

textChunk.str.push(glyphUnicode);

offset = 0;
}

var a = textState.textLineMatrix[0];
Expand Down Expand Up @@ -1130,39 +1133,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var offset;
for (var j = 0, jj = items.length; j < jj; j++) {
if (typeof items[j] === 'string') {
buildTextGeometry(items[j], textChunk);
} else {
// PDF Specification 5.3.2 states:
// The number is expressed in thousandths of a unit of text
// space.
// This amount is subtracted from the current horizontal or
// vertical coordinate, depending on the writing mode.
// In the default coordinate system, a positive adjustment
// has the effect of moving the next glyph painted either to
// the left or down by the given amount.
var val = items[j] * textState.fontSize / 1000;
if (textState.font.vertical) {
offset = val * textState.textMatrix[3];
textState.translateTextMatrix(0, offset);
// Value needs to be added to height to paint down.
textChunk.height += offset;
} else {
offset = val * textState.textHScale *
textState.textMatrix[0];
textState.translateTextMatrix(offset, 0);
// Value needs to be subtracted from width to paint left.
textChunk.width -= offset;
}
if (items[j] < 0 && textState.font.spaceWidth > 0) {
var fakeSpaces = -items[j] / textState.font.spaceWidth;
if (fakeSpaces > MULTI_SPACE_FACTOR) {
fakeSpaces = Math.round(fakeSpaces);
while (fakeSpaces--) {
textChunk.str.push(' ');
}
} else if (fakeSpaces > SPACE_FACTOR) {
var prevChar = j > 0 ? items[j - 1] : null;
offset = isNum(prevChar) ? items[j - 1] / 1000 : 0;
buildTextGeometry(items[j], textChunk, offset);
} else if (items[j] < 0 && textState.font.spaceWidth > 0) {
var fakeSpaces = -items[j] / textState.font.spaceWidth;
if (fakeSpaces > MULTI_SPACE_FACTOR) {
fakeSpaces = Math.round(fakeSpaces);
while (fakeSpaces--) {
textChunk.str.push(' ');
}
} else if (fakeSpaces > SPACE_FACTOR) {
textChunk.str.push(' ');
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
!issue1171.pdf
!smaskdim.pdf
!endchar.pdf
!pr6019.pdf
!type4psfunc.pdf
!issue1350.pdf
!S2.pdf
Expand Down
Binary file added test/pdfs/pr6019.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,13 @@
"rounds": 1,
"type": "eq"
},
{ "id": "pr6019",
"file": "pdfs/pr6019.pdf",
"md5": "7a2e5dda3b0fc5c2e9060e378a8cdc4e",
"rounds": 1,
"type": "text",
"link": false
},
{ "id": "type4psfunc",
"file": "pdfs/type4psfunc.pdf",
"md5": "7e6027a02ff78577f74dccdf84e37189",
Expand Down