Fix text spacing with vertical fonts (#6387)
According to the PDF spec 5.3.2, 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.
This commit is contained in:
parent
e68a5c0222
commit
2564827503
5 changed files with 39 additions and 13 deletions
|
@ -1360,6 +1360,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
var textHScale = current.textHScale * fontDirection;
|
||||
var glyphsLength = glyphs.length;
|
||||
var vertical = font.vertical;
|
||||
var spacingDir = vertical ? 1 : -1;
|
||||
var defaultVMetrics = font.defaultVMetrics;
|
||||
var widthAdvanceScale = fontSize * current.fontMatrix[0];
|
||||
|
||||
|
@ -1406,7 +1407,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
x += fontDirection * wordSpacing;
|
||||
continue;
|
||||
} else if (isNum(glyph)) {
|
||||
x += -glyph * fontSize * 0.001;
|
||||
x += spacingDir * glyph * fontSize / 1000;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1476,6 +1477,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
var font = current.font;
|
||||
var fontSize = current.fontSize;
|
||||
var fontDirection = current.fontDirection;
|
||||
var spacingDir = font.vertical ? 1 : -1;
|
||||
var charSpacing = current.charSpacing;
|
||||
var wordSpacing = current.wordSpacing;
|
||||
var textHScale = current.textHScale * fontDirection;
|
||||
|
@ -1483,7 +1485,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
var glyphsLength = glyphs.length;
|
||||
var isTextInvisible =
|
||||
current.textRenderingMode === TextRenderingMode.INVISIBLE;
|
||||
var i, glyph, width;
|
||||
var i, glyph, width, spacingLength;
|
||||
|
||||
if (isTextInvisible || fontSize === 0) {
|
||||
return;
|
||||
|
@ -1504,7 +1506,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||
current.x += wordSpacing * textHScale;
|
||||
continue;
|
||||
} else if (isNum(glyph)) {
|
||||
var spacingLength = -glyph * 0.001 * fontSize;
|
||||
spacingLength = spacingDir * glyph * fontSize / 1000;
|
||||
this.ctx.translate(spacingLength, 0);
|
||||
current.x += spacingLength * textHScale;
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue