diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 453bd05f3e92d..2950662d4d56c 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -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, @@ -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]; @@ -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(' '); } } } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 62bfa3a9b637d..28f2dfa2e6c4e 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -74,6 +74,7 @@ !issue1171.pdf !smaskdim.pdf !endchar.pdf +!pr6019.pdf !type4psfunc.pdf !issue1350.pdf !S2.pdf diff --git a/test/pdfs/pr6019.pdf b/test/pdfs/pr6019.pdf new file mode 100644 index 0000000000000..7dba7b629379e Binary files /dev/null and b/test/pdfs/pr6019.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 6e432debee516..52340b390e9a4 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -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",