diff --git a/src/canvas.js b/src/canvas.js index 1b62bce4e..a96cdee10 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -1030,6 +1030,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { continue; } + var restoreNeeded = false; var character = glyph.fontChar; var vmetric = glyph.vmetric || defaultVMetrics; if (vertical) { @@ -1055,6 +1056,22 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { scaledAccentX = scaledX + accent.offset.x / fontSizeScale; scaledAccentY = scaledY - accent.offset.y / fontSizeScale; } + + if (font.remeasure && width > 0) { + // some standard fonts may not have the exact width, trying to + // rescale per character + var measuredWidth = ctx.measureText(character).width * 1000 / + current.fontSize * current.fontSizeScale; + var characterScaleX = width / measuredWidth; + restoreNeeded = true; + ctx.save(); + ctx.scale(characterScaleX, 1); + scaledX /= characterScaleX; + if (accent) { + scaledAccentX /= characterScaleX; + } + } + switch (textRenderingMode) { default: // other unsupported rendering modes case TextRenderingMode.FILL: @@ -1096,6 +1113,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { x += charWidth; canvasWidth += charWidth; + + if (restoreNeeded) { + ctx.restore(); + } } if (vertical) { current.y -= x * textHScale; diff --git a/src/fonts.js b/src/fonts.js index 02710eadd..e86be2d20 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -2443,6 +2443,9 @@ var Font = (function FontClosure() { // name ArialBlack for example will be replaced by Helvetica. this.black = (name.search(/Black/g) != -1); + // if at least one width is present, remeasure all chars when exists + this.remeasure = Object.keys(this.widths).length > 0; + this.encoding = properties.baseEncoding; this.noUnicodeAdaptation = true; this.loadedName = fontName.split('-')[0]; @@ -4656,6 +4659,7 @@ var Font = (function FontClosure() { } fontCharCode = this.toFontChar[charcode] || charcode; break; + case 'MMType1': // XXX at the moment only "standard" fonts are supported case 'Type1': var glyphName = this.differences[charcode] || this.encoding[charcode]; if (!isNum(width))