pdfmake 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/svgMeasure.js CHANGED
@@ -14,7 +14,7 @@ function stripUnits(textVal) {
14
14
  /** Make sure it's valid XML and the root tage is <svg/>, returns xmldoc DOM */
15
15
  function parseSVG(svgString) {
16
16
  var doc;
17
-
17
+
18
18
  try {
19
19
  doc = new xmldoc.XmlDocument(svgString);
20
20
  } catch (err) {
@@ -426,8 +426,10 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
426
426
  }
427
427
  if (!isNumber(fillOpacity)) {
428
428
  fillOpacity = isFunction(this.layout.fillOpacity) ? this.layout.fillOpacity(rowIndex, this.tableNode, colIndex) : this.layout.fillOpacity;
429
- }
430
- if (fillColor) {
429
+ }
430
+ var overlayPattern = body[rowIndex][colIndex].overlayPattern;
431
+ var overlayOpacity = body[rowIndex][colIndex].overlayOpacity;
432
+ if (fillColor || overlayPattern) {
431
433
  var widthLeftBorder = leftCellBorder ? this.layout.vLineWidth(colIndex, this.tableNode) : 0;
432
434
  var widthRightBorder;
433
435
  if ((colIndex === 0 || colIndex + 1 == body[rowIndex].length) && !rightCellBorder) {
@@ -442,16 +444,33 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
442
444
  var y1f = this.dontBreakRows ? y1 : y1 - (hzLineOffset / 2);
443
445
  var x2f = xs[i + 1].x + widthRightBorder;
444
446
  var y2f = this.dontBreakRows ? y2 + this.bottomLineWidth : y2 + (this.bottomLineWidth / 2);
445
- writer.addVector({
446
- type: 'rect',
447
- x: x1f,
448
- y: y1f,
449
- w: x2f - x1f,
450
- h: y2f - y1f,
451
- lineWidth: 0,
452
- color: fillColor,
453
- fillOpacity: fillOpacity
454
- }, false, true, writer.context().backgroundLength[writer.context().page]);
447
+ var bgWidth = x2f - x1f;
448
+ var bgHeight = y2f - y1f;
449
+ if (fillColor) {
450
+ writer.addVector({
451
+ type: 'rect',
452
+ x: x1f,
453
+ y: y1f,
454
+ w: bgWidth,
455
+ h: bgHeight,
456
+ lineWidth: 0,
457
+ color: fillColor,
458
+ fillOpacity: fillOpacity
459
+ }, false, true, writer.context().backgroundLength[writer.context().page]);
460
+ }
461
+
462
+ if (overlayPattern) {
463
+ writer.addVector({
464
+ type: 'rect',
465
+ x: x1f,
466
+ y: y1f,
467
+ w: bgWidth,
468
+ h: bgHeight,
469
+ lineWidth: 0,
470
+ color: overlayPattern,
471
+ fillOpacity: overlayOpacity
472
+ }, false, true);
473
+ }
455
474
  }
456
475
  }
457
476
  }
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var isArray = require('./helpers').isArray;
4
+ var isPattern = require('./helpers').isPattern;
5
+ var getPattern = require('./helpers').getPattern;
4
6
 
5
7
  function groupDecorations(line) {
6
8
  var groups = [], currentGroup = null;
@@ -131,15 +133,19 @@ function drawDecorations(line, x, y, pdfKitDoc) {
131
133
  }
132
134
  }
133
135
 
134
- function drawBackground(line, x, y, pdfKitDoc) {
136
+ function drawBackground(line, x, y, patterns, pdfKitDoc) {
135
137
  var height = line.getHeight();
136
138
  for (var i = 0, l = line.inlines.length; i < l; i++) {
137
139
  var inline = line.inlines[i];
138
140
  if (!inline.background) {
139
141
  continue;
140
142
  }
143
+ var color = inline.background;
144
+ if (isPattern(inline.background)) {
145
+ color = getPattern(inline.background, patterns);
146
+ }
141
147
  var justifyShift = (inline.justifyShift || 0);
142
- pdfKitDoc.fillColor(inline.background)
148
+ pdfKitDoc.fillColor(color)
143
149
  .rect(x + inline.x - justifyShift, y, inline.width + justifyShift, height)
144
150
  .fill();
145
151
  }