html2canvas+1.4.1.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. diff --git a/node_modules/html2canvas/dist/html2canvas.js b/node_modules/html2canvas/dist/html2canvas.js
  2. index 84cb30d..d914e1b 100644
  3. --- a/node_modules/html2canvas/dist/html2canvas.js
  4. +++ b/node_modules/html2canvas/dist/html2canvas.js
  5. @@ -6803,14 +6803,40 @@
  6. });
  7. };
  8. CanvasRenderer.prototype.renderReplacedElement = function (container, curves, image) {
  9. + // if (image && container.intrinsicWidth > 0 && container.intrinsicHeight > 0) {
  10. + // var box = contentBox(container);
  11. + // var path = calculatePaddingBoxPath(curves);
  12. + // this.path(path);
  13. + // this.ctx.save();
  14. + // this.ctx.clip();
  15. + // this.ctx.drawImage(image, 0, 0, container.intrinsicWidth, container.intrinsicHeight, box.left, box.top, box.width, box.height);
  16. + // this.ctx.restore();
  17. + // }
  18. if (image && container.intrinsicWidth > 0 && container.intrinsicHeight > 0) {
  19. - var box = contentBox(container);
  20. - var path = calculatePaddingBoxPath(curves);
  21. - this.path(path);
  22. - this.ctx.save();
  23. - this.ctx.clip();
  24. - this.ctx.drawImage(image, 0, 0, container.intrinsicWidth, container.intrinsicHeight, box.left, box.top, box.width, box.height);
  25. - this.ctx.restore();
  26. + var box = contentBox(container);
  27. + var path = calculatePaddingBoxPath(curves);
  28. +
  29. + this.path(path);
  30. + this.ctx.save();
  31. + this.ctx.clip();
  32. +
  33. + let newWidth;
  34. + let newHeight;
  35. + let newX = box.left;
  36. + let newY = box.top;
  37. +
  38. + if(container.intrinsicWidth / box.width < container.intrinsicHeight / box.height) {
  39. + newWidth = box.width;
  40. + newHeight = container.intrinsicHeight * (box.width / container.intrinsicWidth);
  41. + newY = box.top + (box.height - newHeight) / 2;
  42. + } else {
  43. + newWidth = container.intrinsicWidth * (box.height / container.intrinsicHeight);
  44. + newHeight = box.height;
  45. + newX = box.left + (box.width - newWidth) / 2;
  46. + }
  47. +
  48. + this.ctx.drawImage(image, 0, 0, container.intrinsicWidth, container.intrinsicHeight, newX, newY, newWidth, newHeight);
  49. + this.ctx.restore();
  50. }
  51. };
  52. CanvasRenderer.prototype.renderNodeContent = function (paint) {