Comparing version 0.1.24 to 0.1.25
{ | ||
"name": "pdfmake", | ||
"version": "0.1.24", | ||
"version": "0.1.25", | ||
"description": "Client/server side PDF printing in pure JavaScript", | ||
@@ -11,3 +11,4 @@ "main": "src/printer.js", | ||
"pdfkit": "^0.8.0", | ||
"lodash": "^4.17.3" | ||
"linebreak": "^0.3.0", | ||
"lodash": "^4.17.4" | ||
}, | ||
@@ -22,7 +23,6 @@ "devDependencies": { | ||
"gulp-spawn-mocha": "^3.1.0", | ||
"gulp-uglify": "^2.0.0", | ||
"gulp-uglify": "^2.0.1", | ||
"gulp-util": "^3.0.8", | ||
"gulp-each": "^0.2.0", | ||
"gulp-file-contents-to-json": "^0.2.1", | ||
"linebreak": "^0.3.0", | ||
"iconv-lite":"^0.4.15", | ||
@@ -33,3 +33,3 @@ "json-loader": "^0.5.4", | ||
"jshint":"^2.9.4", | ||
"string-replace-webpack-plugin": "^0.0.4", | ||
"string-replace-webpack-plugin": "^0.0.5", | ||
"transform-loader": "^0.2.3", | ||
@@ -36,0 +36,0 @@ "brfs": "^1.4.3", |
/* jslint node: true */ | ||
/* jslint browser: true */ | ||
/* global BlobBuilder */ | ||
'use strict'; | ||
@@ -47,4 +46,7 @@ | ||
doc.on('data', function (chunk) { | ||
chunks.push(chunk); | ||
doc.on('readable', function () { | ||
var chunk; | ||
while ((chunk = doc.read(9007199254740991)) !== null) { | ||
chunks.push(chunk); | ||
} | ||
}); | ||
@@ -67,27 +69,42 @@ doc.on('end', function () { | ||
Document.prototype.open = function (message) { | ||
Document.prototype._bufferToBlob = function (buffer) { | ||
var blob; | ||
try { | ||
blob = new Blob([buffer], {type: 'application/pdf'}); | ||
} catch (e) { | ||
// Old browser which can't handle it without making it an byte array (ie10) | ||
if (e.name === 'InvalidStateError') { | ||
var byteArray = new Uint8Array(buffer); | ||
blob = new Blob([byteArray.buffer], {type: 'application/pdf'}); | ||
} | ||
} | ||
if (!blob) { | ||
throw 'Could not generate blob'; | ||
} | ||
return blob; | ||
}; | ||
Document.prototype._openWindow = function () { | ||
// we have to open the window immediately and store the reference | ||
// otherwise popup blockers will stop us | ||
var win = window.open('', '_blank'); | ||
if (win === null) { | ||
throw 'Open PDF in new window blocked by browser'; | ||
} | ||
return win; | ||
}; | ||
Document.prototype.open = function () { | ||
var win = this._openWindow(); | ||
try { | ||
var that = this; | ||
this.getBuffer(function (result) { | ||
var blob; | ||
try { | ||
blob = new Blob([result], {type: 'application/pdf'}); | ||
} catch (e) { | ||
// Old browser which can't handle it without making it an byte array (ie10) | ||
if (e.name == 'InvalidStateError') { | ||
var byteArray = new Uint8Array(result); | ||
blob = new Blob([byteArray.buffer], {type: 'application/pdf'}); | ||
} | ||
} | ||
if (blob) { | ||
var urlCreator = window.URL || window.webkitURL; | ||
var pdfUrl = urlCreator.createObjectURL(blob); | ||
win.location.href = pdfUrl; | ||
} else { | ||
throw 'Could not generate blob'; | ||
} | ||
var blob = that._bufferToBlob(result); | ||
var urlCreator = window.URL || window.webkitURL; | ||
var pdfUrl = urlCreator.createObjectURL(blob); | ||
win.location.href = pdfUrl; | ||
}, {autoPrint: false}); | ||
@@ -102,26 +119,11 @@ } catch (e) { | ||
Document.prototype.print = function () { | ||
// we have to open the window immediately and store the reference | ||
// otherwise popup blockers will stop us | ||
var win = window.open('', '_blank'); | ||
var win = this._openWindow(); | ||
try { | ||
var that = this; | ||
this.getBuffer(function (result) { | ||
var blob; | ||
try { | ||
blob = new Blob([result], {type: 'application/pdf'}); | ||
} catch (e) { | ||
// Old browser which can't handle it without making it an byte array (ie10) | ||
if (e.name == 'InvalidStateError') { | ||
var byteArray = new Uint8Array(result); | ||
blob = new Blob([byteArray.buffer], {type: 'application/pdf'}); | ||
} | ||
} | ||
if (blob) { | ||
var urlCreator = window.URL || window.webkitURL; | ||
var pdfUrl = urlCreator.createObjectURL(blob); | ||
win.location.href = pdfUrl; | ||
} else { | ||
throw 'Could not generate blob'; | ||
} | ||
var blob = that._bufferToBlob(result); | ||
var urlCreator = window.URL || window.webkitURL; | ||
var pdfUrl = urlCreator.createObjectURL(blob); | ||
win.location.href = pdfUrl; | ||
}, {autoPrint: true}); | ||
@@ -141,18 +143,7 @@ } catch (e) { | ||
defaultFileName = defaultFileName || 'file.pdf'; | ||
var that = this; | ||
this.getBuffer(function (result) { | ||
var blob; | ||
try { | ||
blob = new Blob([result], {type: 'application/pdf'}); | ||
} catch (e) { | ||
// Old browser which can't handle it without making it an byte array (ie10) | ||
if (e.name == 'InvalidStateError') { | ||
var byteArray = new Uint8Array(result); | ||
blob = new Blob([byteArray.buffer], {type: 'application/pdf'}); | ||
} | ||
} | ||
if (blob) { | ||
saveAs(blob, defaultFileName); | ||
} else { | ||
throw 'Could not generate blob'; | ||
} | ||
var blob = that._bufferToBlob(result); | ||
saveAs(blob, defaultFileName); | ||
if (typeof cb === 'function') { | ||
@@ -159,0 +150,0 @@ cb(); |
@@ -17,3 +17,8 @@ /* jslint node: true */ | ||
return this.fileSystem[filename]; | ||
var content = this.fileSystem[filename]; | ||
if (content) { | ||
return content; | ||
} | ||
throw 'File \'' + filename + '\' not found in virtual file system'; | ||
}; | ||
@@ -26,3 +31,3 @@ | ||
VirtualFileSystem.prototype.bindFS = function (data) { | ||
this.baseSystem = data; | ||
this.baseSystem = data || {}; | ||
}; | ||
@@ -29,0 +34,0 @@ |
@@ -320,3 +320,2 @@ /* jslint node: true */ | ||
if (!data._span) { | ||
var _this = this; | ||
data = rowData[col] = this.styleStack.auto(data, measureCb(this, data)); | ||
@@ -364,6 +363,7 @@ | ||
/*jshint unused: false */ | ||
var defaultLayout = { | ||
hLineWidth: function (i, node) { | ||
return 1; | ||
}, //return node.table.headerRows && i === node.table.headerRows && 3 || 0; }, | ||
}, | ||
vLineWidth: function (i, node) { | ||
@@ -380,6 +380,6 @@ return 1; | ||
return 4; | ||
}, //i && 4 || 0; }, | ||
}, | ||
paddingRight: function (i, node) { | ||
return 4; | ||
}, //(i < node.table.widths.length - 1) ? 4 : 0; }, | ||
}, | ||
paddingTop: function (i, node) { | ||
@@ -391,2 +391,5 @@ return 2; | ||
}, | ||
fillColor: function (i, node) { | ||
return null; | ||
}, | ||
defaultBorder: true | ||
@@ -393,0 +396,0 @@ }; |
@@ -202,5 +202,5 @@ /* jslint node: true */ | ||
if (createNewPage) { | ||
var currentAvailableWidth = this.availableWidth; | ||
this.addPage(getPageSize(this.getCurrentPage(), pageOrientation)); | ||
this.availableWidth = currentAvailableWidth; | ||
var pageSize = getPageSize(this.getCurrentPage(), pageOrientation); | ||
this.addPage(pageSize); | ||
this.pageSnapshot().availableWidth = pageSize.width - this.x - this.pageMargins.right; | ||
} else { | ||
@@ -207,0 +207,0 @@ this.page = nextPageIndex; |
/* jslint node: true */ | ||
/* global window */ | ||
'use strict'; | ||
@@ -85,2 +84,7 @@ | ||
// if pageSize.height is set to auto, set the height to infinity so there are no page breaks. | ||
if (docDefinition.pageSize && docDefinition.pageSize.height === 'auto') { | ||
docDefinition.pageSize.height = Infinity; | ||
} | ||
var pageSize = pageSize2widthAndHeight(docDefinition.pageSize || 'a4'); | ||
@@ -93,3 +97,3 @@ | ||
this.pdfKitDoc = new PdfKit({size: [pageSize.width, pageSize.height], compress: docDefinition.compress || true}); | ||
this.pdfKitDoc = new PdfKit({size: [pageSize.width, pageSize.height], autoFirstPage: false, compress: docDefinition.compress || true}); | ||
this.pdfKitDoc.info.Producer = 'pdfmake'; | ||
@@ -130,2 +134,9 @@ this.pdfKitDoc.info.Creator = 'pdfmake'; | ||
// if pageSize.height is set to Infinity, calculate the actual height of the page that | ||
// was laid out using the height of each of the items in the page. | ||
if (pageSize.height === Infinity) { | ||
var pageHeight = calculatePageHeight(pages, docDefinition.pageMargins); | ||
this.pdfKitDoc.options.size = [pageSize.width, pageHeight]; | ||
} | ||
renderPages(pages, this.fontProvider, this.pdfKitDoc); | ||
@@ -145,2 +156,13 @@ | ||
function calculatePageHeight(pages, margins) { | ||
var fixedMargins = fixPageMargins(margins || 40); | ||
var height = fixedMargins.top + fixedMargins.bottom; | ||
pages.forEach(function (page) { | ||
page.items.forEach(function (item) { | ||
height += item.item.getHeight(); | ||
}); | ||
}); | ||
return height; | ||
} | ||
function fixPageMargins(margin) { | ||
@@ -166,2 +188,3 @@ if (!margin) { | ||
function registerDefaultTableLayouts(layoutBuilder) { | ||
/*jshint unused: false */ | ||
layoutBuilder.registerTableLayouts({ | ||
@@ -180,3 +203,3 @@ noBorders: { | ||
return (i < node.table.widths.length - 1) ? 4 : 0; | ||
}, | ||
} | ||
}, | ||
@@ -223,32 +246,4 @@ headerLineOnly: { | ||
var defaultLayout = { | ||
hLineWidth: function (i, node) { | ||
return 1; | ||
}, //return node.table.headerRows && i === node.table.headerRows && 3 || 0; }, | ||
vLineWidth: function (i, node) { | ||
return 1; | ||
}, | ||
hLineColor: function (i, node) { | ||
return 'black'; | ||
}, | ||
vLineColor: function (i, node) { | ||
return 'black'; | ||
}, | ||
paddingLeft: function (i, node) { | ||
return 4; | ||
}, //i && 4 || 0; }, | ||
paddingRight: function (i, node) { | ||
return 4; | ||
}, //(i < node.table.widths.length - 1) ? 4 : 0; }, | ||
paddingTop: function (i, node) { | ||
return 2; | ||
}, | ||
paddingBottom: function (i, node) { | ||
return 2; | ||
}, | ||
defaultBorder: true | ||
}; | ||
function pageSize2widthAndHeight(pageSize) { | ||
if (typeof pageSize == 'string' || pageSize instanceof String) { | ||
if (typeof pageSize === 'string' || pageSize instanceof String) { | ||
var size = sizes[pageSize.toUpperCase()]; | ||
@@ -264,9 +259,2 @@ if (!size) { | ||
function StringObject(str) { | ||
this.isString = true; | ||
this.toString = function () { | ||
return str; | ||
}; | ||
} | ||
function updatePageOrientationInOptions(currentPage, pdfKitDoc) { | ||
@@ -284,2 +272,3 @@ var previousPageOrientation = pdfKitDoc.options.size[0] > pdfKitDoc.options.size[1] ? 'landscape' : 'portrait'; | ||
pdfKitDoc._pdfMakePages = pages; | ||
pdfKitDoc.addPage(); | ||
for (var i = 0; i < pages.length; i++) { | ||
@@ -367,3 +356,3 @@ if (i > 0) { | ||
if (vector.dash) { | ||
pdfDoc.dash(vector.dash.length, {space: vector.dash.space || vector.dash.length}); | ||
pdfDoc.dash(vector.dash.length, {space: vector.dash.space || vector.dash.length, phase: vector.dash.phase || 0}); | ||
} else { | ||
@@ -370,0 +359,0 @@ pdfDoc.undash(); |
@@ -111,2 +111,3 @@ /* jslint node: true */ | ||
// (cf. Table 20 in JIS X 0510:2004 p. 42) | ||
/*jshint unused: false */ | ||
var MASKFUNCS = [ | ||
@@ -113,0 +114,0 @@ function (i, j) { |
@@ -307,2 +307,5 @@ /* jslint node: true */ | ||
var fillColor = body[rowIndex][colIndex].fillColor; | ||
if (!fillColor) { | ||
fillColor = typeof this.layout.fillColor === 'function' ? this.layout.fillColor(rowIndex, this.tableNode) : this.layout.fillColor; | ||
} | ||
if (fillColor) { | ||
@@ -309,0 +312,0 @@ var wBorder = (leftBorder || rightBorder) ? this.layout.vLineWidth(colIndex, this.tableNode) : 0; |
/* jslint node: true */ | ||
'use strict'; | ||
function groupDecorations(line) { | ||
@@ -6,0 +5,0 @@ var groups = [], curGroup = null; |
@@ -85,3 +85,3 @@ /* jslint node: true */ | ||
return { | ||
width: font.widthOfString(removeDiacritics(text), fontSize), | ||
width: font.widthOfString(text, fontSize), | ||
height: font.lineHeight(fontSize) * lineHeight, | ||
@@ -137,3 +137,3 @@ fontSize: fontSize, | ||
function normalizeTextArray(array) { | ||
function normalizeTextArray(array, styleContextStack) { | ||
var results = []; | ||
@@ -150,7 +150,8 @@ | ||
var noWrap = getStyleProperty(item, styleContextStack, 'noWrap', false); | ||
if (item !== null && (typeof item === 'object' || item instanceof Object)) { | ||
words = splitWords(normalizeString(item.text), item.noWrap); | ||
words = splitWords(normalizeString(item.text), noWrap); | ||
style = copyStyle(item); | ||
} else { | ||
words = splitWords(normalizeString(item)); | ||
words = splitWords(normalizeString(item), noWrap); | ||
} | ||
@@ -188,12 +189,2 @@ | ||
//TODO: support for other languages (currently only polish is supported) | ||
var diacriticsMap = {'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ó': 'O', 'Ś': 'S', 'Ź': 'Z', 'Ż': 'Z', 'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ó': 'o', 'ś': 's', 'ź': 'z', 'ż': 'z'}; | ||
// ' << atom.io workaround | ||
function removeDiacritics(text) { | ||
return text.replace(/[^A-Za-z0-9\[\] ]/g, function (a) { | ||
return diacriticsMap[a] || a; | ||
}); | ||
} | ||
function getStyleProperty(item, styleContextStack, property, defaultValue) { | ||
@@ -223,3 +214,3 @@ var value; | ||
function measure(fontProvider, textArray, styleContextStack) { | ||
var normalized = normalizeTextArray(textArray); | ||
var normalized = normalizeTextArray(textArray, styleContextStack); | ||
@@ -242,3 +233,3 @@ normalized.forEach(function (item) { | ||
// TODO: character spacing | ||
item.width = font.widthOfString(removeDiacritics(item.text), fontSize); | ||
item.width = font.widthOfString(item.text, fontSize); | ||
item.height = font.lineHeight(fontSize) * lineHeight; | ||
@@ -245,0 +236,0 @@ |
@@ -55,8 +55,9 @@ var path = require('path'); | ||
{test: /readable-stream[\/\\]/, loader: StringReplacePlugin.replace({ | ||
/* temporary bugfix for fontkit version 1.5.2 - issue https://github.com/devongovett/fontkit/issues/66 */ | ||
{test: /fontkit[\/\\]index.js$/, loader: StringReplacePlugin.replace({ | ||
replacements: [ | ||
{ | ||
pattern: 'stream.read()', | ||
pattern: 'if (this._font.GDEF) {', | ||
replacement: function () { | ||
return 'stream.read(9007199254740991)'; | ||
return 'if (this._font.GDEF && this._font.GDEF.glyphClassDef) {'; | ||
} | ||
@@ -66,2 +67,4 @@ } | ||
}, | ||
/* *** */ | ||
/* hack for IE 10 */ | ||
@@ -68,0 +71,0 @@ {test: /brotli[\/\\]dec[\/\\]/, loader: StringReplacePlugin.replace({ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
9664135
21
113052
3
+ Addedlinebreak@^0.3.0
Updatedlodash@^4.17.4