static extractContoursFromText(
    text,
    { fontFamily, fontStyle, fontWeight },
    pageWidth,
    pageHeight,
    rotation,
    innerMargin
  ) {
    let canvas = new OffscreenCanvas(1, 1);
    let ctx = canvas.getContext("2d", { alpha: false });
    const fontSize = 200;
    const font =
      (ctx.font = `${fontStyle} ${fontWeight} ${fontSize}px ${fontFamily}`);
    const {
      actualBoundingBoxLeft,
      actualBoundingBoxRight,
      actualBoundingBoxAscent,
      actualBoundingBoxDescent,
      fontBoundingBoxAscent,
      fontBoundingBoxDescent,
      width,
    } = ctx.measureText(text);

    // We rescale the canvas to make "sure" the text fits.
    const SCALE = 1.5;
    const canvasWidth = Math.ceil(
      Math.max(
        Math.abs(actualBoundingBoxLeft) + Math.abs(actualBoundingBoxRight) || 0,
        width
      ) * SCALE
    );
    const canvasHeight = Math.ceil(
      Math.max(
        Math.abs(actualBoundingBoxAscent) +
          Math.abs(actualBoundingBoxDescent) || fontSize,
        Math.abs(fontBoundingBoxAscent) + Math.abs(fontBoundingBoxDescent) ||
          fontSize
      ) * SCALE
    );
    canvas = new OffscreenCanvas(canvasWidth, canvasHeight);
    ctx = canvas.getContext("2d", { alpha: true, willReadFrequently: true });
    ctx.font = font;
    ctx.filter = "grayscale(1)";
    ctx.fillStyle = "white";
    ctx.fillRect(0, 0, canvasWidth, canvasHeight);
    ctx.fillStyle = "black";
    ctx.fillText(
      text,
      (canvasWidth * (SCALE - 1)) / 2,
      (canvasHeight * (3 - SCALE)) / 2
    );

    const uint8Buf = this.#toUint8(
      ctx.getImageData(0, 0, canvasWidth, canvasHeight).data
    );
    const histogram = this.#getHistogram(uint8Buf);
    const threshold = this.#guessThreshold(histogram);

    const contourList = this.#findContours(
      uint8Buf,
      canvasWidth,
      canvasHeight,
      threshold
    );

    return this.processDrawnLines({
      lines: { curves: contourList, width: canvasWidth, height: canvasHeight },
      pageWidth,
      pageHeight,
      rotation,
      innerMargin,
      mustSmooth: true,
      areContours: true,
    });
  }
Basic text editor in order to create a Signature annotation.