Skip to content

Commit 4443f97

Browse files
committed
Merge branch 'rwwagner90-retina-support'
2 parents 607bd67 + d4da549 commit 4443f97

File tree

7 files changed

+387
-244
lines changed

7 files changed

+387
-244
lines changed

.jscsrc

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,69 @@
11
{
2-
"preset": "jquery",
32
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
4-
"validateQuoteMarks": "'",
3+
"disallowMultipleVarDecl": true,
4+
"requireCurlyBraces": [
5+
"if",
6+
"else",
7+
"for",
8+
"while",
9+
"do",
10+
"try",
11+
"catch"
12+
],
13+
"requireOperatorBeforeLineBreak": true,
14+
"requireParenthesesAroundIIFE": true,
15+
"requireCommaBeforeLineBreak": true,
16+
"requireDotNotation": true,
17+
"requireSpacesInsideArrayBrackets": "all",
518
"maximumLineLength": {
6-
"value": 1000
7-
}
19+
"value": 1000,
20+
"tabSize": 4,
21+
"allowUrlComments": true,
22+
"allowRegex": true
23+
},
24+
"validateQuoteMarks": "'",
25+
"disallowMixedSpacesAndTabs": "smart",
26+
"disallowTrailingWhitespace": true,
27+
"disallowMultipleLineStrings": true,
28+
"disallowTrailingComma": true,
29+
"requireSpacesInFunctionExpression": {
30+
"beforeOpeningCurlyBrace": true
31+
},
32+
"requireSpaceAfterKeywords": [
33+
"if",
34+
"else",
35+
"for",
36+
"while",
37+
"do",
38+
"switch",
39+
"return",
40+
"try",
41+
"catch"
42+
],
43+
"requireSpacesInsideObjectBrackets": "all",
44+
"requireSpacesInsideArrayBrackets": "all",
45+
"requireSpacesInConditionalExpression": true,
46+
"requireSpaceAfterBinaryOperators": true,
47+
"requireLineFeedAtFileEnd": true,
48+
"requireSpaceBeforeBinaryOperators": [
49+
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
50+
"&=", "|=", "^=", "+=",
51+
"+", "-", "*", "/", "%", "<<", ">>", ">>>", "&",
52+
"|", "^", "&&", "||", "===", "==", ">=",
53+
"<=", "<", ">", "!=", "!=="
54+
],
55+
"requireSpacesInAnonymousFunctionExpression": {
56+
"beforeOpeningCurlyBrace": true
57+
},
58+
"requireSpacesInNamedFunctionExpression": {
59+
"beforeOpeningCurlyBrace": true
60+
},
61+
"validateLineBreaks": "LF",
62+
"disallowKeywords": [ "with" ],
63+
"disallowKeywordsOnNewLine": [ "else" ],
64+
"disallowSpaceAfterObjectKeys": true,
65+
"disallowSpaceAfterPrefixUnaryOperators": true,
66+
"disallowSpaceBeforePostfixUnaryOperators": true,
67+
"disallowSpaceBeforeBinaryOperators": [ ",", ":" ],
68+
"disallowMultipleLineBreaks": true
869
}

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"homepage": "http://github.com/sayanee/angularjs-pdf",
88
"dependencies": {
99
"angular": "1.3.15",
10-
"pdfjs-dist": "1.1.337"
10+
"pdfjs-dist": "1.1.399"
1111
},
1212
"ignore": [
1313
"**/.*",

dist/angular-pdf.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,40 @@
44
'use strict';
55

66
angular.module('pdf', []).directive('ngPdf', [ '$window', function($window) {
7+
var backingScale = function(canvas) {
8+
var ctx = canvas.getContext('2d');
9+
var dpr = window.devicePixelRatio || 1;
10+
var bsr = ctx.webkitBackingStorePixelRatio ||
11+
ctx.mozBackingStorePixelRatio ||
12+
ctx.msBackingStorePixelRatio ||
13+
ctx.oBackingStorePixelRatio ||
14+
ctx.backingStorePixelRatio || 1;
15+
16+
return dpr / bsr;
17+
};
18+
19+
var setCanvasDimensions = function(canvas, w, h) {
20+
var ratio = backingScale(canvas);
21+
canvas.width = w * ratio;
22+
canvas.height = h * ratio;
23+
canvas.style.width = w + 'px';
24+
canvas.style.height = h + 'px';
25+
canvas.getContext('2d').setTransform(ratio, 0, 0, ratio, 0, 0);
26+
return canvas;
27+
};
728
return {
829
restrict: 'E',
930
templateUrl: function(element, attr) {
1031
return attr.templateUrl ? attr.templateUrl : 'partials/viewer.html'
1132
},
1233
link: function(scope, element, attrs) {
13-
var url = scope.pdfUrl,
14-
pdfDoc = null,
15-
pageNum = (attrs.page ? attrs.page : 1),
16-
scale = attrs.scale > 0 ? attrs.scale : 1,
17-
canvas = (attrs.canvasid ? document.getElementById(attrs.canvasid) : document.getElementById('pdf-canvas')),
18-
ctx = canvas.getContext('2d'),
19-
windowEl = angular.element($window);
34+
var url = scope.pdfUrl;
35+
var pdfDoc = null
36+
var pageNum = (attrs.page ? attrs.page : 1);
37+
var scale = attrs.scale > 0 ? attrs.scale : 1;
38+
var canvas = (attrs.canvasid ? document.getElementById(attrs.canvasid) : document.getElementById('pdf-canvas'));
39+
var ctx = canvas.getContext('2d');
40+
var windowEl = angular.element($window);
2041

2142
windowEl.on('scroll', function() {
2243
scope.$apply(function() {
@@ -29,11 +50,11 @@
2950

3051
scope.renderPage = function(num) {
3152
pdfDoc.getPage(num).then(function(page) {
32-
var viewport,
33-
pageWidthScale,
34-
pageHeightScale,
35-
renderContext = {},
36-
pageRendering;
53+
var viewport;
54+
var pageWidthScale;
55+
var pageHeightScale;
56+
var renderContext = {};
57+
var pageRendering;
3758

3859
if (attrs.scale === 'page-fit' && !scale) {
3960
viewport = page.getViewport(1);
@@ -44,8 +65,7 @@
4465
viewport = page.getViewport(scale)
4566
}
4667

47-
canvas.height = viewport.height;
48-
canvas.width = viewport.width;
68+
setCanvasDimensions(canvas, viewport.width, viewport.height);
4969

5070
renderContext = {
5171
canvasContext: ctx,

dist/angular-pdf.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/js/directives/angular-pdf.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,40 @@
44
'use strict';
55

66
angular.module('pdf', []).directive('ngPdf', [ '$window', function($window) {
7+
var backingScale = function(canvas) {
8+
var ctx = canvas.getContext('2d');
9+
var dpr = window.devicePixelRatio || 1;
10+
var bsr = ctx.webkitBackingStorePixelRatio ||
11+
ctx.mozBackingStorePixelRatio ||
12+
ctx.msBackingStorePixelRatio ||
13+
ctx.oBackingStorePixelRatio ||
14+
ctx.backingStorePixelRatio || 1;
15+
16+
return dpr / bsr;
17+
};
18+
19+
var setCanvasDimensions = function(canvas, w, h) {
20+
var ratio = backingScale(canvas);
21+
canvas.width = w * ratio;
22+
canvas.height = h * ratio;
23+
canvas.style.width = w + 'px';
24+
canvas.style.height = h + 'px';
25+
canvas.getContext('2d').setTransform(ratio, 0, 0, ratio, 0, 0);
26+
return canvas;
27+
};
728
return {
829
restrict: 'E',
930
templateUrl: function(element, attr) {
1031
return attr.templateUrl ? attr.templateUrl : 'partials/viewer.html'
1132
},
1233
link: function(scope, element, attrs) {
13-
var url = scope.pdfUrl,
14-
pdfDoc = null,
15-
pageNum = (attrs.page ? attrs.page : 1),
16-
scale = attrs.scale > 0 ? attrs.scale : 1,
17-
canvas = (attrs.canvasid ? document.getElementById(attrs.canvasid) : document.getElementById('pdf-canvas')),
18-
ctx = canvas.getContext('2d'),
19-
windowEl = angular.element($window);
34+
var url = scope.pdfUrl;
35+
var pdfDoc = null
36+
var pageNum = (attrs.page ? attrs.page : 1);
37+
var scale = attrs.scale > 0 ? attrs.scale : 1;
38+
var canvas = (attrs.canvasid ? document.getElementById(attrs.canvasid) : document.getElementById('pdf-canvas'));
39+
var ctx = canvas.getContext('2d');
40+
var windowEl = angular.element($window);
2041

2142
windowEl.on('scroll', function() {
2243
scope.$apply(function() {
@@ -29,11 +50,11 @@
2950

3051
scope.renderPage = function(num) {
3152
pdfDoc.getPage(num).then(function(page) {
32-
var viewport,
33-
pageWidthScale,
34-
pageHeightScale,
35-
renderContext = {},
36-
pageRendering;
53+
var viewport;
54+
var pageWidthScale;
55+
var pageHeightScale;
56+
var renderContext = {};
57+
var pageRendering;
3758

3859
if (attrs.scale === 'page-fit' && !scale) {
3960
viewport = page.getViewport(1);
@@ -44,8 +65,7 @@
4465
viewport = page.getViewport(scale)
4566
}
4667

47-
canvas.height = viewport.height;
48-
canvas.width = viewport.width;
68+
setCanvasDimensions(canvas, viewport.width, viewport.height);
4969

5070
renderContext = {
5171
canvasContext: ctx,

example/js/lib/pdf.js

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
2222
(typeof window !== 'undefined' ? window : this).PDFJS = {};
2323
}
2424

25-
PDFJS.version = '1.1.337';
26-
PDFJS.build = '61f9052';
25+
PDFJS.version = '1.1.399';
26+
PDFJS.build = '23cb01c';
2727

2828
(function pdfjsWrapper() {
2929
// Use strict in our context only - users might not want it
@@ -1508,6 +1508,10 @@ function MessageHandler(name, comObj) {
15081508
data: result
15091509
});
15101510
}, function (reason) {
1511+
if (reason instanceof Error) {
1512+
// Serialize error to avoid "DataCloneError"
1513+
reason = reason + '';
1514+
}
15111515
comObj.postMessage({
15121516
isReply: true,
15131517
callbackId: data.callbackId,
@@ -1751,6 +1755,14 @@ PDFJS.openExternalLinksInNewWindow = (
17511755
PDFJS.openExternalLinksInNewWindow === undefined ?
17521756
false : PDFJS.openExternalLinksInNewWindow);
17531757

1758+
/**
1759+
* Determines if we can eval strings as JS. Primarily used to improve
1760+
* performance for font rendering.
1761+
* @var {boolean}
1762+
*/
1763+
PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
1764+
true : PDFJS.isEvalSupported);
1765+
17541766
/**
17551767
* Document initialization / loading parameters object.
17561768
*
@@ -1861,6 +1873,8 @@ PDFJS.getDocument = function getDocument(src,
18611873
} else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
18621874
!isNaN(pdfBytes.length)) {
18631875
params[key] = new Uint8Array(pdfBytes);
1876+
} else if (isArrayBuffer(pdfBytes)) {
1877+
params[key] = new Uint8Array(pdfBytes);
18641878
} else {
18651879
error('Invalid PDF binary data: either typed array, string or ' +
18661880
'array-like object is expected in the data property.');
@@ -5773,7 +5787,7 @@ var WebGLUtils = (function WebGLUtilsClosure() {
57735787
for (var j = 0, jj = ps.length; j < jj; j++) {
57745788
coords[pIndex] = coordsMap[ps[j]];
57755789
coords[pIndex + 1] = coordsMap[ps[j] + 1];
5776-
colors[cIndex] = colorsMap[cs[i]];
5790+
colors[cIndex] = colorsMap[cs[j]];
57775791
colors[cIndex + 1] = colorsMap[cs[j] + 1];
57785792
colors[cIndex + 2] = colorsMap[cs[j] + 2];
57795793
pIndex += 2;
@@ -6311,6 +6325,18 @@ var FontLoader = {
63116325
));
63126326
},
63136327

6328+
get isEvalSupported() {
6329+
var evalSupport = false;
6330+
if (PDFJS.isEvalSupported) {
6331+
try {
6332+
/* jshint evil: true */
6333+
new Function('');
6334+
evalSupport = true;
6335+
} catch (e) {}
6336+
}
6337+
return shadow(this, 'isEvalSupported', evalSupport);
6338+
},
6339+
63146340
loadTestFontId: 0,
63156341

63166342
loadingContext: {
@@ -6587,9 +6613,40 @@ var FontFaceObject = (function FontFaceObjectClosure() {
65876613

65886614
getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
65896615
if (!(character in this.compiledGlyphs)) {
6590-
var js = objs.get(this.loadedName + '_path_' + character);
6591-
/*jshint -W054 */
6592-
this.compiledGlyphs[character] = new Function('c', 'size', js);
6616+
var cmds = objs.get(this.loadedName + '_path_' + character);
6617+
var current, i, len;
6618+
6619+
// If we can, compile cmds into JS for MAXIMUM SPEED
6620+
if (FontLoader.isEvalSupported) {
6621+
var args, js = '';
6622+
for (i = 0, len = cmds.length; i < len; i++) {
6623+
current = cmds[i];
6624+
6625+
if (current.args !== undefined) {
6626+
args = current.args.join(',');
6627+
} else {
6628+
args = '';
6629+
}
6630+
6631+
js += 'c.' + current.cmd + '(' + args + ');\n';
6632+
}
6633+
/* jshint -W054 */
6634+
this.compiledGlyphs[character] = new Function('c', 'size', js);
6635+
} else {
6636+
// But fall back on using Function.prototype.apply() if we're
6637+
// blocked from using eval() for whatever reason (like CSP policies)
6638+
this.compiledGlyphs[character] = function(c, size) {
6639+
for (i = 0, len = cmds.length; i < len; i++) {
6640+
current = cmds[i];
6641+
6642+
if (current.cmd === 'scale') {
6643+
current.args = [size, -size];
6644+
}
6645+
6646+
c[current.cmd].apply(c, current.args);
6647+
}
6648+
};
6649+
}
65936650
}
65946651
return this.compiledGlyphs[character];
65956652
}

0 commit comments

Comments
 (0)