Skip to content

Commit

Permalink
Fix chars scaling for standard fonts.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Nov 17, 2015
1 parent 2f1a626 commit 8200f09
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1421,16 +1421,22 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
scaledY = 0;
}

if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
// some standard fonts may not have the exact width, trying to
// rescale per character
if (font.remeasure && width > 0) {
// Some standard fonts may not have the exact width: rescale per
// character if measured width is greater than expected glyph width
// and subpixel-aa is enabled, otherwise just center the glyph.
var measuredWidth = ctx.measureText(character).width * 1000 /
fontSize * fontSizeScale;
var characterScaleX = width / measuredWidth;
restoreNeeded = true;
ctx.save();
ctx.scale(characterScaleX, 1);
scaledX /= characterScaleX;
if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
var characterScaleX = width / measuredWidth;
restoreNeeded = true;
ctx.save();
ctx.scale(characterScaleX, 1);
scaledX /= characterScaleX;
} else if (width !== measuredWidth) {
scaledX += (width - measuredWidth) / 2000 *
fontSize / fontSizeScale;
}
}

if (simpleFillText && !accent) {
Expand Down

0 comments on commit 8200f09

Please sign in to comment.