From e7febbf0f7f49f77129fc137645c4945524db25f Mon Sep 17 00:00:00 2001 From: Jani Pehkonen Date: Sun, 23 Aug 2020 20:48:10 +0300 Subject: [PATCH] Accent positioning in Type1 `seac` glyphs In `display/canvas.js` the accent offsets must be multiplied by `fontSize` to make the offsets large enough. Another problem is in `core/type1_parser.js` when the Type1 command `seac` is handled. There is an error in the Adobe Type1 spec. See chapter 6 in Type1 Font Format Supplement, which provides an errata: The arguments of `seac` specify the offset of the left side bearing (LSB) points, not the offset of origins. This can be fixed in `core/type1_parser.js` by adding the difference of the LSB values. --- src/core/type1_parser.js | 2 ++ src/display/canvas.js | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/type1_parser.js b/src/core/type1_parser.js index f465aedd5283e..0083b541b56d5 100644 --- a/src/core/type1_parser.js +++ b/src/core/type1_parser.js @@ -232,7 +232,9 @@ var Type1CharString = (function Type1CharStringClosure() { // seac is like type 2's special endchar but it doesn't use the // first argument asb, so remove it. if (seacAnalysisEnabled) { + const asb = this.stack[this.stack.length - 5]; this.seac = this.stack.splice(-4, 4); + this.seac[0] += this.lsb - asb; error = this.executeCommand(0, COMMAND_MAP.endchar); } else { error = this.executeCommand(4, COMMAND_MAP.endchar); diff --git a/src/display/canvas.js b/src/display/canvas.js index cca53d40d1eb3..58b65d631fa6f 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1798,8 +1798,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } else { this.paintChar(character, scaledX, scaledY, patternTransform); if (accent) { - scaledAccentX = scaledX + accent.offset.x / fontSizeScale; - scaledAccentY = scaledY - accent.offset.y / fontSizeScale; + scaledAccentX = + scaledX + (fontSize * accent.offset.x) / fontSizeScale; + scaledAccentY = + scaledY - (fontSize * accent.offset.y) / fontSizeScale; this.paintChar( accent.fontChar, scaledAccentX,