Skip to content

Commit

Permalink
Add extension point to table cell for custom overlay
Browse files Browse the repository at this point in the history
If `overlay` function is set on cell, it is used to obtain vectors to be
rendered overlaying the given cell.

Callback is called with `x,y,w,h` of the current cell.
  • Loading branch information
jesenko committed Dec 25, 2024
1 parent bfe7fd3 commit b5ff409
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/tableProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,10 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
if (!isNumber(fillOpacity)) {
fillOpacity = isFunction(this.layout.fillOpacity) ? this.layout.fillOpacity(rowIndex, this.tableNode, colIndex) : this.layout.fillOpacity;
}
var overlay = body[rowIndex][colIndex].overlay;
var overlayPattern = body[rowIndex][colIndex].overlayPattern;
var overlayOpacity = body[rowIndex][colIndex].overlayOpacity;
if (fillColor || overlayPattern) {
if (fillColor || overlay || overlayPattern) {
var widthLeftBorder = leftCellBorder ? this.layout.vLineWidth(colIndex, this.tableNode) : 0;
var widthRightBorder;
if ((colIndex === 0 || colIndex + 1 == body[rowIndex].length) && !rightCellBorder) {
Expand Down Expand Up @@ -522,6 +523,13 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
fillOpacity: overlayOpacity
}, false, true);
}

if (overlay) {
var overlayVectors = overlay({x: x1f, y: y1f, w: bgWidth, h: bgHeight });
overlayVectors.forEach(function (vector) {
writer.addVector(vector, false, true);
});
}
}
}
}
Expand Down

0 comments on commit b5ff409

Please sign in to comment.