Skip to content

Commit

Permalink
Fix text spacing with vertical fonts (mozilla#6387)
Browse files Browse the repository at this point in the history
According to the PDF spec, a positive value means in horizontal, that
the next glyph is further to the left (so narrower), and in vertical that
it is further down (so wider).
This change fixes the way PDF.js has interpreted the value.
  • Loading branch information
CodingFabian committed Aug 28, 2015
1 parent c6ba5ea commit 55188ef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,17 +1131,27 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
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] / 1000;
if (!textState.font.vertical) {
offset = -val * textState.fontSize * textState.textHScale *
if (textState.font.vertical) {
offset = val * textState.fontSize * textState.textMatrix[3];
// Value needs to added to height to paint down.
textState.translateTextMatrix(0, offset);
textChunk.height += offset;
} else {
offset = val * textState.fontSize * textState.textHScale *
textState.textMatrix[0];
// Value needs to be subtracted from width to paint left.
offset = -offset;
textState.translateTextMatrix(offset, 0);
textChunk.width += offset;
} else {
offset = -val * textState.fontSize *
textState.textMatrix[3];
textState.translateTextMatrix(0, offset);
textChunk.height += offset;
}
if (items[j] < 0 && textState.font.spaceWidth > 0) {
var fakeSpaces = -items[j] / textState.font.spaceWidth;
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
!issue5747.pdf
!issue6099.pdf
!issue6336.pdf
!issue6387.pdf
!gradientfill.pdf
!bug903856.pdf
!bug850854.pdf
Expand Down
Binary file added test/pdfs/issue6387.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,12 @@
"lastPage": 1,
"type": "eq"
},
{ "id": "issue6387",
"file": "pdfs/issue6387.pdf",
"md5": "08c39ac6d0aab1596e6e59793eaf3ee4",
"rounds": 1,
"type": "eq"
},
{ "id": "issue4890",
"file": "pdfs/issue4890.pdf",
"md5": "1666feb4cd26318c2bdbea6a175dce87",
Expand Down

0 comments on commit 55188ef

Please sign in to comment.