From f17ba5b9abc324a181f5498f7448524524dca256 Mon Sep 17 00:00:00 2001 From: Fabien Tafel Date: Tue, 14 Aug 2018 15:29:29 +0200 Subject: [PATCH] added opacity for column borders --- README.md | 11 +++++++++-- package.json | 2 +- voilab-table.js | 20 ++++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 89bb46f..9c5822b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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! @@ -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 diff --git a/package.json b/package.json index fb14c3d..24fe768 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "table" ], "dependencies": { - "lodash": "4.*" + "lodash": "^4.17.10" }, "author": { "name": "Fabien Tafelmacher" diff --git a/voilab-table.js b/voilab-table.js index 393a853..8a7516d 100644 --- a/voilab-table.js +++ b/voilab-table.js @@ -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); @@ -582,6 +590,8 @@ lodash.assign(PdfTable.prototype, { *
  • Boolean hidden: True to define the column as * hidden (default to false)
  • *
  • String border: cell border (LTBR)
  • + *
  • Number borderOpacity: cell border opacity, from 0 + * to 1
  • *
  • Number width: column width
  • *
  • Number height: min height for cell (default to * standard linebreak)
  • @@ -602,6 +612,8 @@ lodash.assign(PdfTable.prototype, { *
  • Function headerRenderer: renderer function for * header cell. Recieve (PdfTable table, row)
  • *
  • String headerBorder: cell border (LTBR)
  • + *
  • Number headerBorderOpacity: cell border opacity, + * from 0 to 1
  • *
  • Boolean headerFill: True to fill the header with * the predefined color (with pdf.fillColor(color))
  • *
  • Number headerHeight: min height for cell (default