html2canvas icon indicating copy to clipboard operation
html2canvas copied to clipboard

CSS transform: scale(VALUE);

Open Xaorn opened this issue 2 years ago • 3 comments

Bug reports:

Dom-Element transform: scale(VALUE) -> Font will not be scaled => 1 - overlapping letters in a generated Screenshot Before: wrongFontSize After: withFontScale

--> Short Solution for me Added new Option fontScale and included it into the createFontStyle prototype

CanvasRenderer( ... _this.canvas.fontScale = options.fontScale; ....

renderOptions = { ... fontScale: (_e =opts.fontScale) !== null && _e !== void 0 ? _e : 1
...

CanvasRenderer.prototype.createFontStyle = function (styles) { var fontVariant = styles.fontVariant .filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; }) .join(''); var fontFamily = fixIOSSystemFonts(styles.fontFamily).join(', '); var fontSize = isDimensionToken(styles.fontSize) ? "" + styles.fontSize.number* this.canvas.fontScale + styles.fontSize.unit : styles.fontSize.number* this.canvas.fontScale + "px"; return [ [styles.fontStyle, fontVariant, styles.fontWeight, fontSize, fontFamily].join(' '), fontFamily, fontSize ]; };

Edit: Same scale missing in transform x & y (Array-element 4 & 5) (prototype.applyEffect -> effect.matrix[4] & effect.matrix[5]

Specifications:

  • html2canvas version tested with: 1.4.1
  • Browser & version: Chrome Version 99.0.4844.51 - 64bit
  • Operating system: Windows 10

Xaorn avatar Mar 04 '22 10:03 Xaorn

CanvasRenderer( ... _this.canvas.fontScale = options.fontScale; ....

renderOptions = { ... fontScale: (_e =opts.fontScale) !== null && _e !== void 0 ? _e : 1 ...

CanvasRenderer.prototype.createFontStyle = function (styles) { var fontVariant = styles.fontVariant .filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; }) .join(''); var fontFamily = fixIOSSystemFonts(styles.fontFamily).join(', '); var fontSize = isDimensionToken(styles.fontSize) ? "" + styles.fontSize.number* this.canvas.fontScale + styles.fontSize.unit : styles.fontSize.number* this.canvas.fontScale + "px"; return [ [styles.fontStyle, fontVariant, styles.fontWeight, fontSize, fontFamily].join(' '), fontFamily, fontSize ]; };

Can you share the code? Same problem here!

JcGuerrero15 avatar Nov 03 '22 21:11 JcGuerrero15

Interested to know as well.

Dams591 avatar Jun 06 '23 15:06 Dams591

There's one solution, use setTimeout to delay the canvas paint, then it will be ok. Think it's the timing when paint, the font scale is not ready yet.

Aggie123 avatar Apr 19 '24 09:04 Aggie123