function measureCell(cell, rowHeight) {
  // ====================
  // Calculate cell width
  // ====================
  let cellWidth = 0;

  // Traverse all the columns of the cell
  for (let i = 0; i < cell.colSpan; i++) {
    cellWidth += this._columnWidths[cell.colIndex + i];
  }

  // =====================
  // Calculate cell height
  // =====================
  let cellHeight = rowHeight;
  if (cellHeight === 'auto') {
    // The cells height is effectively infinite
    // (although we clamp it to the page content size)
    cellHeight = this.document.page.contentHeight;
  } else {
    // Add all the spanning rows heights to the cell
    for (let i = 0; i < cell.rowSpan - 1; i++) {
      cellHeight += this._rowHeights[cell.rowIndex + i];
    }
  }

  // Allocated text space
  const textAllocatedWidth = cellWidth - cell.padding.left - cell.padding.right;

  const textAllocatedHeight =
    cellHeight - cell.padding.top - cell.padding.bottom;

  // Compute the text bounds
  const rotation = cell.textOptions.rotation ?? 0;
  const { width: textMaxWidth, height: textMaxHeight } = computeBounds(
    rotation,
    textAllocatedWidth,
    textAllocatedHeight,
  );

  const textOptions = {
    // Alignment is handled internally
    align: cell.align.x,
    ellipsis: true, // Default make overflowing text ellipsis
    stroke: cell.textStroke > 0,
    fill: true, // To fix the stroke issue
    width: textMaxWidth,
    height: textMaxHeight,
    rotation,
    // Allow the user to define any custom fields
    ...cell.textOptions,
  };

  // ========================
  // Calculate text height
  // ========================

  // Compute rendered bounds of the text given the constraints of the cell
  let textBounds = { x: 0, y: 0, width: 0, height: 0 };
  if (cell.text) {
    const rollbackFont = this.document._fontSource;
    const rollbackFontSize = this.document._fontSize;
    const rollbackFontFamily = this.document._fontFamily;
    if (cell.font?.src) this.document.font(cell.font.src, cell.font?.family);
    if (cell.font?.size) this.document.fontSize(cell.font.size);

    // We first compute the un-rotated bounds so that we can calculate the width of the text
    const unRotatedTextBounds = this.document.boundsOfString(cell.text, 0, 0, {
      ...textOptions,
      rotation: 0,
    });
    textOptions.width = unRotatedTextBounds.width;
    textOptions.height = unRotatedTextBounds.height;

    // Then compute the rendered bounds
    textBounds = this.document.boundsOfString(cell.text, 0, 0, textOptions);

    this.document.font(rollbackFont, rollbackFontFamily, rollbackFontSize);
  }

  return {
    ...cell,
    textOptions,
    x: this._columnXPos[cell.colIndex],
    y: this._rowYPos[cell.rowIndex],
    textX: this._columnXPos[cell.colIndex] + cell.padding.left,
    textY: this._rowYPos[cell.rowIndex] + cell.padding.top,
    width: cellWidth,
    height: cellHeight,
    textAllocatedHeight,
    textAllocatedWidth,
    textBounds,
  };
}
Compute the dimensions of the cell and its text

@this PDFTable
@memberOf PDFTable
@param {NormalizedTableCellStyle} cell
@param {number | 'auto'} rowHeight
@returns {SizedNormalizedTableCellStyle}
@private