html2canvas-pro 2.3.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,7 @@ const color_utilities_1 = require("../../css/types/color-utilities");
18
18
  const parser_1 = require("../../css/syntax/parser");
19
19
  const writing_mode_1 = require("../../css/property-descriptors/writing-mode");
20
20
  const text_decoration_renderer_1 = require("./text/text-decoration-renderer");
21
+ const font_utils_1 = require("./font-utils");
21
22
  // iOS font fix - see https://github.com/niklasvh/html2canvas/pull/2645
22
23
  const iOSBrokenFonts = ['-apple-system', 'system-ui'];
23
24
  /**
@@ -100,7 +101,6 @@ class TextRenderer {
100
101
  */
101
102
  this.glyphWidthCache = null;
102
103
  this.ctx = deps.ctx;
103
- this.fontMetrics = deps.fontMetrics;
104
104
  this.options = deps.options;
105
105
  this.decorationRenderer = new text_decoration_renderer_1.TextDecorationRenderer(deps.ctx);
106
106
  }
@@ -440,16 +440,17 @@ class TextRenderer {
440
440
  // Reset glyph width cache at the start of each text node render —
441
441
  // the font may change between nodes.
442
442
  this.glyphWidthCache = null;
443
- const [fontString, fontFamily, fontSize] = this.createFontStyle(styles);
443
+ const [fontString] = this.createFontStyle(styles);
444
444
  this.ctx.font = fontString;
445
445
  this.ctx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr';
446
446
  this.ctx.textAlign = 'left';
447
447
  this.ctx.textBaseline = 'alphabetic';
448
448
  const paintOrder = styles.paintOrder;
449
- // Use the measured baseline from FontMetrics instead of fontSize,
450
- // which correctly accounts for fonts with large descenders (e.g. Paul)
451
- // where the alphabetic baseline is closer to the top of the em-square.
452
- const { baseline } = this.fontMetrics.getMetrics(fontFamily, fontSize);
449
+ // Compute baseline using the actual rendered font via Canvas API.
450
+ // This ensures correct positioning whether using webfonts (which may not
451
+ // be loaded in the original document but are active in the Canvas) or
452
+ // system fonts.
453
+ const baseline = (0, font_utils_1.measureBaseline)(this.ctx, styles.fontSize.number);
453
454
  // -webkit-line-clamp
454
455
  const clamp = styles.webkitLineClamp > 0 &&
455
456
  (styles.display & 2 /* DISPLAY.BLOCK */) !== 0 &&
@@ -37,7 +37,6 @@ export declare class CanvasRenderer {
37
37
  ctx: CanvasRenderingContext2D;
38
38
  private readonly context;
39
39
  private readonly options;
40
- private readonly fontMetrics;
41
40
  private readonly backgroundRenderer;
42
41
  private readonly borderRenderer;
43
42
  private readonly borderImageRenderer;
@@ -5,7 +5,6 @@ import { BoundCurves } from '../bound-curves';
5
5
  import { Vector } from '../vector';
6
6
  import { Context } from '../../core/context';
7
7
  import { TextRenderer } from './text-renderer';
8
- import { FontMetrics } from '../font-metrics';
9
8
  import { Color } from '../../css/types/color';
10
9
  import { CSSParsedDeclaration } from '../../css/index';
11
10
  /**
@@ -36,7 +35,7 @@ export declare function renderReplacedElements(ctx: CanvasRenderingContext2D, co
36
35
  /**
37
36
  * Render form element content: checkbox, radio, text input.
38
37
  */
39
- export declare function renderFormElements(ctx: CanvasRenderingContext2D, fontMetrics: FontMetrics, textRenderer: TextRenderer, pathFn: (paths: Vector[]) => void, container: ElementContainer, styles: CSSParsedDeclaration): void;
38
+ export declare function renderFormElements(ctx: CanvasRenderingContext2D, textRenderer: TextRenderer, pathFn: (paths: Vector[]) => void, container: ElementContainer, styles: CSSParsedDeclaration): void;
40
39
  /**
41
40
  * Render list-item marker (image or text).
42
41
  */
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Font measurement utility
3
+ *
4
+ * Provides Canvas API-based baseline measurement that works correctly with
5
+ * webfonts (which may not be loaded in the original document) and system fonts.
6
+ *
7
+ * Fallback chain:
8
+ * 1. fontBoundingBoxAscent — font-level metric (Chrome 99+, FF 116+, Safari 17.4+)
9
+ * 2. actualBoundingBoxAscent — glyph-level metric (widely supported)
10
+ * 3. fallback value — coarse CSS fallback
11
+ */
12
+ /**
13
+ * Measure the baseline ascent for the currently set font.
14
+ *
15
+ * @param ctx - Canvas 2D rendering context with ctx.font already set
16
+ * @param fallback - Fallback value when no metrics are available (e.g. fontSize.number)
17
+ * @returns The distance from the text baseline to the top of the bounding box
18
+ */
19
+ export declare const measureBaseline: (ctx: CanvasRenderingContext2D, fallback: number) => number;
@@ -15,13 +15,11 @@ import { CSSParsedDeclaration } from '../../css';
15
15
  import { Bounds } from '../../css/layout/bounds';
16
16
  import { TextBounds } from '../../css/layout/text';
17
17
  import { WRITING_MODE } from '../../css/property-descriptors/writing-mode';
18
- import { FontMetrics } from '../font-metrics';
19
18
  /**
20
19
  * Dependencies required for TextRenderer
21
20
  */
22
21
  export interface TextRendererDependencies {
23
22
  ctx: CanvasRenderingContext2D;
24
- fontMetrics: FontMetrics;
25
23
  options: {
26
24
  scale: number;
27
25
  };
@@ -35,7 +33,6 @@ export declare const hasCJKCharacters: (text: string) => boolean;
35
33
  */
36
34
  export declare class TextRenderer {
37
35
  private readonly ctx;
38
- private readonly fontMetrics;
39
36
  private readonly options;
40
37
  private readonly decorationRenderer;
41
38
  /**
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "default": "./dist/html2canvas-pro.esm.js"
20
20
  }
21
21
  },
22
- "version": "2.3.1",
22
+ "version": "2.3.2",
23
23
  "author": {
24
24
  "name": "yorickshan",
25
25
  "email": "yorickshan@gmail.com",