function renderBorder(border, borderColor, x, y, width, height, mask) {
  border = Object.fromEntries(
    Object.entries(border).map(([k, v]) => [k, mask && !mask[k] ? 0 : v]),
  );

  const doc = this.document;
  if (
    [border.right, border.bottom, border.left].every(
      (val) => val === border.top,
    )
  ) {
    if (border.top > 0) {
      doc
        .save()
        .lineWidth(border.top)
        .rect(x, y, width, height)
        .stroke(borderColor.top)
        .restore();
    }
  } else {
    // Top
    if (border.top > 0) {
      doc
        .save()
        .lineWidth(border.top)
        .moveTo(x, y)
        .lineTo(x + width, y)
        .stroke(borderColor.top)
        .restore();
    }
    // Right
    if (border.right > 0) {
      doc
        .save()
        .lineWidth(border.right)
        .moveTo(x + width, y)
        .lineTo(x + width, y + height)
        .stroke(borderColor.right)
        .restore();
    }
    // Bottom
    if (border.bottom > 0) {
      doc
        .save()
        .lineWidth(border.bottom)
        .moveTo(x + width, y + height)
        .lineTo(x, y + height)
        .stroke(borderColor.bottom)
        .restore();
    }
    // Left
    if (border.left > 0) {
      doc
        .save()
        .lineWidth(border.left)
        .moveTo(x, y + height)
        .lineTo(x, y)
        .stroke(borderColor.left)
        .restore();
    }
  }
}
@this PDFTable
@memberOf PDFTable
@param {ExpandedSideDefinition<number>} border
@param {ExpandedSideDefinition<PDFColor>} borderColor
@param {number} x
@param {number} y
@param {number} width
@param {number} height
@param {number[]} [mask]
@private