function renderCellText(cell) {
  const doc = this.document;

  // Configure fonts
  const rollbackFont = doc._fontSource;
  const rollbackFontSize = doc._fontSize;
  const rollbackFontFamily = doc._fontFamily;
  if (cell.customFont) {
    if (cell.font.src) doc.font(cell.font.src, cell.font.family);
    if (cell.font.size) doc.fontSize(cell.font.size);
  }

  const x = cell.textX;
  const y = cell.textY;
  const Ah = cell.textAllocatedHeight;
  const Aw = cell.textAllocatedWidth;
  const Cw = cell.textBounds.width;
  const Ch = cell.textBounds.height;
  const Ox = -cell.textBounds.x;
  const Oy = -cell.textBounds.y;

  const PxScale =
    cell.align.x === 'right' ? 1 : cell.align.x === 'center' ? 0.5 : 0;
  const Px = (Aw - Cw) * PxScale;
  const PyScale =
    cell.align.y === 'bottom' ? 1 : cell.align.y === 'center' ? 0.5 : 0;
  const Py = (Ah - Ch) * PyScale;

  const dx = Px + Ox;
  const dy = Py + Oy;

  if (cell.debug) {
    doc.save();
    doc.dash(1, { space: 1 }).lineWidth(1).strokeOpacity(0.3);

    // Debug actual text bounds
    if (cell.text) {
      doc
        .moveTo(x + Px, y)
        .lineTo(x + Px, y + Ah)
        .moveTo(x + Px + Cw, y)
        .lineTo(x + Px + Cw, y + Ah)
        .stroke('blue')
        .moveTo(x, y + Py)
        .lineTo(x + Aw, y + Py)
        .moveTo(x, y + Py + Ch)
        .lineTo(x + Aw, y + Py + Ch)
        .stroke('green');
    }
    // Debug allocated text bounds
    doc.rect(x, y, Aw, Ah).stroke('orange');

    doc.restore();
  }

  // Create text mask to cut off any overflowing text
  // Mask cuts off at the padding not the actual cell, this is intentional!
  doc.save().rect(x, y, Aw, Ah).clip();

  doc.fillColor(cell.textColor).strokeColor(cell.textStrokeColor);
  if (cell.textStroke > 0) doc.lineWidth(cell.textStroke);

  // Render the text
  doc.text(cell.text, x + dx, y + dy, cell.textOptions);

  // Cleanup
  doc.restore();
  if (cell.font) doc.font(rollbackFont, rollbackFontFamily, rollbackFontSize);
}
@this PDFTable
@memberOf PDFTable
@param {SizedNormalizedTableCellStyle} cell