--- @pdf-lib/fontkit-1.1.1-original +++ fontkit-patched.js @@ -40711,9 +40711,8 @@ var s = new restructure.EncodeStream(); nextTick(function () { - _this.encode(s); - - return s.end(); + // PDF APP v1.7.1: forward asynchronous encoding failures to the caller. + try { _this.encode(s); s.end(); } catch (error) { s.emit('error', error); } }); return s; }; @@ -40842,6 +40841,8 @@ endPtsOfContours.push(pointCount - 1); } + // PDF APP v1.7.1: flush the last run of repeated flags before coordinates. + if (same > 0) flags.push(same); var bbox = path.bbox; var glyf = { numberOfContours: endPtsOfContours.length, @@ -40940,7 +40941,9 @@ buffer = this.glyphEncoder.encodeSimple(glyph.path, glyf.instructions); } - this.glyf.push(buffer); + // PDF APP v1.7.1: short loca offsets require even glyph boundaries. + if (buffer.length % 2) { var padded = new buffer_1(buffer.length + 1); padded.set(buffer); buffer = padded; } + this.glyf.push(buffer); this.loca.offsets.push(this.offset); this.hmtx.metrics.push({ advance: glyph.advanceWidth,