Comparing version 1.0.4 to 1.0.5
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -31,9 +31,9 @@ /* | ||
function hex(v) { | ||
function hex (v) { | ||
return v < 0x10 | ||
? '0' + Math.max(0, v).toString(16) | ||
: Math.min(255, v).toString(16); | ||
? '0' + Math.max(0, v).toString(16) | ||
: Math.min(255, v).toString(16); | ||
}; | ||
function hslToHex(h, s, l, a) { | ||
function hslToHex (h, s, l, a) { | ||
h = h % 360 + (h < 0) * 360; | ||
@@ -44,20 +44,20 @@ s = isNaN(h) || isNaN(s) ? 0 : s; | ||
return rgbToHex(hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2), hsl2rgb(h, m1, m2), | ||
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2), a); | ||
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2), a); | ||
}; | ||
function hsl2rgb(h, m1, m2) { | ||
function hsl2rgb (h, m1, m2) { | ||
return (h < 60 ? m1 + (m2 - m1) * h / 60 | ||
: h < 180 ? m2 | ||
: h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 | ||
: m1) * 255; | ||
: h < 180 ? m2 | ||
: h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 | ||
: m1) * 255; | ||
}; | ||
var reI = '\\s*([+-]?\\d+)\\s*', | ||
reN = '\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*', | ||
reP = '\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*', | ||
reRgbInteger = new RegExp('^rgb\\(' + [reI, reI, reI] + '\\)$'), | ||
reRgbPercent = new RegExp('^rgb\\(' + [reP, reP, reP] + '\\)$'), | ||
reRgbaInteger = new RegExp('^rgba\\(' + [reI, reI, reI, reN] + '\\)$'), | ||
reRgbaPercent = new RegExp('^rgba\\(' + [reP, reP, reP, reN] + '\\)$'), | ||
reHslPercent = new RegExp('^hsl\\(' + [reN, reP, reP] + '\\)$'), | ||
reHslaPercent = new RegExp('^hsla\\(' + [reN, reP, reP, reN] + '\\)$'); | ||
reN = '\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*', | ||
reP = '\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*', | ||
reRgbInteger = new RegExp('^rgb\\(' + [reI, reI, reI] + '\\)$'), | ||
reRgbPercent = new RegExp('^rgb\\(' + [reP, reP, reP] + '\\)$'), | ||
reRgbaInteger = new RegExp('^rgba\\(' + [reI, reI, reI, reN] + '\\)$'), | ||
reRgbaPercent = new RegExp('^rgba\\(' + [reP, reP, reP, reN] + '\\)$'), | ||
reHslPercent = new RegExp('^hsl\\(' + [reN, reP, reP] + '\\)$'), | ||
reHslaPercent = new RegExp('^hsla\\(' + [reN, reP, reP, reN] + '\\)$'); | ||
@@ -110,3 +110,3 @@ var rgbToHex = function (r, g, b, a) { | ||
family: 'Helvetica', | ||
weight: 'normal' | ||
weight: 'normal', | ||
}; | ||
@@ -122,3 +122,3 @@ var parseFont = function () { | ||
family: fontPart[6] || 'Helvetica', | ||
weight: fontPart[3] || 'normal' | ||
weight: fontPart[3] || 'normal', | ||
}; | ||
@@ -133,3 +133,3 @@ return data; | ||
_this.doc.fillColor(color.c, color.a); | ||
} | ||
}, | ||
}); | ||
@@ -141,7 +141,7 @@ Object.defineProperty(this, 'strokeStyle', { | ||
_this.doc.strokeColor(color.c, color.a); | ||
} | ||
}, | ||
}); | ||
Object.defineProperty(this, 'lineWidth', { | ||
get: function () { return _this.doc.lineWidth(); }, | ||
set: function (value) { _this.doc.lineWidth(value); } | ||
set: function (value) { _this.doc.lineWidth(value); }, | ||
}); | ||
@@ -151,7 +151,7 @@ | ||
get: function () { return _this.doc.lineCap(); }, | ||
set: function (value) { _this.doc.lineCap(value); } | ||
set: function (value) { _this.doc.lineCap(value); }, | ||
}); | ||
Object.defineProperty(this, 'lineJoin', { | ||
get: function () { return _this.doc.lineJoin(); }, | ||
set: function (value) { _this.doc.lineJoin(value); } | ||
set: function (value) { _this.doc.lineJoin(value); }, | ||
}); | ||
@@ -161,3 +161,3 @@ | ||
get: function () { return _this.doc.opacity(); }, | ||
set: function (value) { _this.doc.opacity(value); } | ||
set: function (value) { _this.doc.opacity(value); }, | ||
}); | ||
@@ -173,3 +173,3 @@ | ||
_this.lineHeight = this.doc.currentLineHeight(false); | ||
} | ||
}, | ||
}); | ||
@@ -257,12 +257,12 @@ _this.lineHeight = this.doc.currentLineHeight(false); | ||
var pi = Math.PI, | ||
tau = 2 * pi, | ||
epsilon = 1e-6, | ||
tauEpsilon = tau - epsilon; | ||
tau = 2 * pi, | ||
epsilon = 1e-6, | ||
tauEpsilon = tau - epsilon; | ||
x = +x, y = +y, r = +r; | ||
var dx = r * Math.cos(a0), | ||
dy = r * Math.sin(a0), | ||
x0 = x + dx, | ||
y0 = y + dy, | ||
cw = 1 ^ ccw, | ||
da = ccw ? a0 - a1 : a1 - a0; | ||
dy = r * Math.sin(a0), | ||
x0 = x + dx, | ||
y0 = y + dy, | ||
cw = 1 ^ ccw, | ||
da = ccw ? a0 - a1 : a1 - a0; | ||
@@ -295,3 +295,4 @@ // Is the radius negative? Error. | ||
if (da > tauEpsilon) { | ||
cmd += 'A' + r + ',' + r + ',0,1,' + cw + ',' + (x - dx) + ',' + (y - dy) + 'A' + r + ',' + r + ',0,1,' + cw + ',' + x0 + ',' + y0; | ||
cmd += 'A' + r + ',' + r + ',0,1,' + cw + ',' + (x - dx) + ',' + (y - dy) + 'A' + r + ',' + r + ',0,1,' + cw + | ||
',' + x0 + ',' + y0; | ||
} | ||
@@ -301,3 +302,4 @@ | ||
else if (da > epsilon) { | ||
cmd += 'A' + r + ',' + r + ',0,' + (+(da >= pi)) + ',' + cw + ',' + ( x + r * Math.cos(a1)) + ',' + ( y + r * Math.sin(a1)); | ||
cmd += 'A' + r + ',' + r + ',0,' + (+(da >= pi)) + ',' + cw + ',' + ( x + r * Math.cos(a1)) + ',' + | ||
( y + r * Math.sin(a1)); | ||
} | ||
@@ -362,3 +364,3 @@ this.doc.path(cmd); | ||
this.doc.text(text, x, y, { | ||
lineBreak: false, stroke: false, fill: true | ||
lineBreak: false, stroke: false, fill: true, | ||
}); | ||
@@ -384,2 +386,46 @@ }; | ||
canvas2pdf.PdfContext.prototype.drawImage = function (image) { | ||
var _this; | ||
var args = Array.prototype.slice.call(arguments); | ||
var image = args[0]; | ||
var dx, dy, dw, dh, sx = 0, sy = 0, sw, sh; | ||
if (args.length === 3) { | ||
dx = args[1]; | ||
dy = args[2]; | ||
sw = image.width; | ||
sh = image.height; | ||
dw = sw; | ||
dh = sh; | ||
} else if (args.length === 5) { | ||
dx = args[1]; | ||
dy = args[2]; | ||
dw = args[3]; | ||
dh = args[4]; | ||
sw = image.width; | ||
sh = image.height; | ||
} else if (args.length === 9) { | ||
sx = args[1]; | ||
sy = args[2]; | ||
sw = args[3]; | ||
sh = args[4]; | ||
dx = args[5]; | ||
dy = args[6]; | ||
dw = args[7]; | ||
dh = args[8]; | ||
} else { | ||
throw new Error('Invalid number of arguments passed to drawImage: ' + arguments.length); | ||
} | ||
if (image.nodeName === 'IMG') { | ||
var canvas = document.createElement('canvas'); | ||
canvas.width = image.width; | ||
canvas.height = image.height; | ||
canvas.getContext('2d').drawImage(image, 0, 0); | ||
var dataURL = canvas.toDataURL('image/png'); | ||
this.doc.image(dataURL, dx, dy, {width: dw, height: dh}); | ||
} else { | ||
this.doc.image(image, dx, dy, {width: dw, height: dh}); | ||
} | ||
}; | ||
/** | ||
@@ -392,6 +438,2 @@ * Not yet implemented | ||
canvas2pdf.PdfContext.prototype.drawImage = function () { | ||
console.log('drawImage not implemented'); | ||
}; | ||
canvas2pdf.PdfContext.prototype.createPattern = function (image, repetition) { | ||
@@ -398,0 +440,0 @@ console.log('createPattern not implemented'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46564
2465399
25