Skip to content

Commit

Permalink
added opacity for column borders
Browse files Browse the repository at this point in the history
  • Loading branch information
tafel committed Aug 14, 2018
1 parent 2148164 commit f17ba5b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PdfKit wrapper that helps to draw informations in simple tables.
## Installation

```
node install --save voilab-pdf-table
npm install --save voilab-pdf-table
```

## Usage
Expand Down Expand Up @@ -106,6 +106,13 @@ table.onPageAdd(function (table, row, ev) {

## Changelogs

### 0.4.1
Thank you, contributors!

**From #vikram1992**

+ added `headerOpacity` and `headerBorderOpacity` in column configuration

### 0.4.0
Thank you, contributors!

Expand All @@ -116,7 +123,7 @@ Thank you, contributors!

**From #cbwebdevelopment**

+ added `addonCellBackgroundAdd` and `onCellBackgroundAdded` events
+ added `onCellBackgroundAdd` and `onCellBackgroundAdded` events
+ added `onCellBorderAdd` and `onCellBorderAdded` events
+ the current row index is passed in events
+ some modifications about pos calculation
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"table"
],
"dependencies": {
"lodash": "4.*"
"lodash": "^4.17.10"
},
"author": {
"name": "Fabien Tafelmacher"
Expand Down
20 changes: 16 additions & 4 deletions voilab-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,27 @@ var lodash = require('lodash'),
bpos = {
x: pos.x + column.width,
y: pos.y + row._renderedContent.height
},
doStroke = function () {
var opacity = (!isHeader && column.borderOpacity) || (isHeader && column.headerBorderOpacity);
self.pdf.lineCap('square').opacity(opacity || 1).stroke().restore();
};

if (border.indexOf('L') !== -1) {
self.pdf.save().moveTo(pos.x, pos.y).lineTo(pos.x, bpos.y).lineCap('square').stroke().restore();
self.pdf.save().moveTo(pos.x, pos.y).lineTo(pos.x, bpos.y);
doStroke();
}
if (border.indexOf('T') !== -1) {
self.pdf.save().moveTo(pos.x, pos.y).lineTo(bpos.x, pos.y).lineCap('square').stroke().restore();
self.pdf.save().moveTo(pos.x, pos.y).lineTo(bpos.x, pos.y);
doStroke();
}
if (border.indexOf('B') !== -1) {
self.pdf.save().moveTo(pos.x, bpos.y).lineTo(bpos.x, bpos.y).lineCap('square').stroke().restore();
self.pdf.save().moveTo(pos.x, bpos.y).lineTo(bpos.x, bpos.y);
doStroke();
}
if (border.indexOf('R') !== -1) {
self.pdf.save().moveTo(bpos.x, pos.y).lineTo(bpos.x, bpos.y).lineCap('square').stroke().restore();
self.pdf.save().moveTo(bpos.x, pos.y).lineTo(bpos.x, bpos.y);
doStroke();
}

self.emitter.emit('cell-border-added', self, column, row, isHeader);
Expand Down Expand Up @@ -582,6 +590,8 @@ lodash.assign(PdfTable.prototype, {
* <li><i>Boolean</i> <b>hidden</b>: True to define the column as
* hidden (default to false)</li>
* <li><i>String</i> <b>border</b>: cell border (LTBR)</li>
* <li><i>Number</i> <b>borderOpacity</b>: cell border opacity, from 0
* to 1</li>
* <li><i>Number</i> <b>width</b>: column width</li>
* <li><i>Number</i> <b>height</b>: min height for cell (default to
* standard linebreak)</li>
Expand All @@ -602,6 +612,8 @@ lodash.assign(PdfTable.prototype, {
* <li><i>Function</i> <b>headerRenderer</b>: renderer function for
* header cell. Recieve (PdfTable table, row)</li>
* <li><i>String</i> <b>headerBorder</b>: cell border (LTBR)</li>
* <li><i>Number</i> <b>headerBorderOpacity</b>: cell border opacity,
* from 0 to 1</li>
* <li><i>Boolean</i> <b>headerFill</b>: True to fill the header with
* the predefined color (with pdf.fillColor(color))</li>
* <li><i>Number</i> <b>headerHeight</b>: min height for cell (default
Expand Down

0 comments on commit f17ba5b

Please sign in to comment.