Browse Source

Merge pull request #4465 from Snuffleupagus/src-display-braces

Fix coding style in src/display
Tim van der Meij 11 years ago
parent
commit
67c686027c
  1. 94
      src/display/api.js
  2. 34
      src/display/canvas.js

94
src/display/api.js

@ -27,14 +27,15 @@
* above this value will not be drawn. Use -1 for no limit. * above this value will not be drawn. Use -1 for no limit.
* @var {number} * @var {number}
*/ */
PDFJS.maxImageSize = PDFJS.maxImageSize === undefined ? -1 : PDFJS.maxImageSize; PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
-1 : PDFJS.maxImageSize);
/** /**
* The url of where the predefined Adobe CMaps are located. Include trailing * The url of where the predefined Adobe CMaps are located. Include trailing
* slash. * slash.
* @var {string} * @var {string}
*/ */
PDFJS.cMapUrl = PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl; PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
/* /*
* By default fonts are converted to OpenType fonts and loaded via font face * By default fonts are converted to OpenType fonts and loaded via font face
@ -42,16 +43,16 @@ PDFJS.cMapUrl = PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl;
* that constructs the glyphs with primitive path commands. * that constructs the glyphs with primitive path commands.
* @var {boolean} * @var {boolean}
*/ */
PDFJS.disableFontFace = PDFJS.disableFontFace === undefined ? PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
false : PDFJS.disableFontFace; false : PDFJS.disableFontFace);
/** /**
* Path for image resources, mainly for annotation icons. Include trailing * Path for image resources, mainly for annotation icons. Include trailing
* slash. * slash.
* @var {string} * @var {string}
*/ */
PDFJS.imageResourcesPath = PDFJS.imageResourcesPath === undefined ? PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
'' : PDFJS.imageResourcesPath; '' : PDFJS.imageResourcesPath);
/** /**
* Disable the web worker and run all code on the main thread. This will happen * Disable the web worker and run all code on the main thread. This will happen
@ -59,8 +60,8 @@ PDFJS.imageResourcesPath = PDFJS.imageResourcesPath === undefined ?
* to workers. * to workers.
* @var {boolean} * @var {boolean}
*/ */
PDFJS.disableWorker = PDFJS.disableWorker === undefined ? PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
false : PDFJS.disableWorker; false : PDFJS.disableWorker);
/** /**
* Path and filename of the worker file. Required when the worker is enabled in * Path and filename of the worker file. Required when the worker is enabled in
@ -68,7 +69,7 @@ PDFJS.disableWorker = PDFJS.disableWorker === undefined ?
* loaded based on the location of the pdf.js file. * loaded based on the location of the pdf.js file.
* @var {string} * @var {string}
*/ */
PDFJS.workerSrc = PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc; PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
/** /**
* Disable range request loading of PDF files. When enabled and if the server * Disable range request loading of PDF files. When enabled and if the server
@ -76,8 +77,8 @@ PDFJS.workerSrc = PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc;
* Enabled (false) by default. * Enabled (false) by default.
* @var {boolean} * @var {boolean}
*/ */
PDFJS.disableRange = PDFJS.disableRange === undefined ? PDFJS.disableRange = (PDFJS.disableRange === undefined ?
false : PDFJS.disableRange; false : PDFJS.disableRange);
/** /**
* Disable pre-fetching of PDF file data. When range requests are enabled PDF.js * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
@ -85,28 +86,28 @@ PDFJS.disableRange = PDFJS.disableRange === undefined ?
* the current page. This default behavior can be disabled. * the current page. This default behavior can be disabled.
* @var {boolean} * @var {boolean}
*/ */
PDFJS.disableAutoFetch = PDFJS.disableAutoFetch === undefined ? PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
false : PDFJS.disableAutoFetch; false : PDFJS.disableAutoFetch);
/** /**
* Enables special hooks for debugging PDF.js. * Enables special hooks for debugging PDF.js.
* @var {boolean} * @var {boolean}
*/ */
PDFJS.pdfBug = PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug; PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
/** /**
* Enables transfer usage in postMessage for ArrayBuffers. * Enables transfer usage in postMessage for ArrayBuffers.
* @var {boolean} * @var {boolean}
*/ */
PDFJS.postMessageTransfers = PDFJS.postMessageTransfers === undefined ? PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
true : PDFJS.postMessageTransfers; true : PDFJS.postMessageTransfers);
/** /**
* Disables URL.createObjectURL usage. * Disables URL.createObjectURL usage.
* @var {boolean} * @var {boolean}
*/ */
PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ? PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
false : PDFJS.disableCreateObjectURL; false : PDFJS.disableCreateObjectURL);
/** /**
* Controls the logging level. * Controls the logging level.
@ -116,8 +117,8 @@ PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ?
* - infos * - infos
* @var {number} * @var {number}
*/ */
PDFJS.verbosity = PDFJS.verbosity === undefined ? PDFJS.verbosity = (PDFJS.verbosity === undefined ?
PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity; PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
/** /**
* Document initialization / loading parameters object. * Document initialization / loading parameters object.
@ -172,8 +173,9 @@ PDFJS.getDocument = function getDocument(source,
'string or a parameter object'); 'string or a parameter object');
} }
if (!source.url && !source.data) if (!source.url && !source.data) {
error('Invalid parameter array, need either .data or .url'); error('Invalid parameter array, need either .data or .url');
}
// copy/use all keys as is except 'url' -- full path is required // copy/use all keys as is except 'url' -- full path is required
var params = {}; var params = {};
@ -187,8 +189,8 @@ PDFJS.getDocument = function getDocument(source,
workerInitializedPromise = new PDFJS.LegacyPromise(); workerInitializedPromise = new PDFJS.LegacyPromise();
workerReadyPromise = new PDFJS.LegacyPromise(); workerReadyPromise = new PDFJS.LegacyPromise();
transport = new WorkerTransport(workerInitializedPromise, transport = new WorkerTransport(workerInitializedPromise, workerReadyPromise,
workerReadyPromise, pdfDataRangeTransport, progressCallback); pdfDataRangeTransport, progressCallback);
workerInitializedPromise.then(function transportInitialized() { workerInitializedPromise.then(function transportInitialized() {
transport.passwordCallback = passwordCallback; transport.passwordCallback = passwordCallback;
transport.fetchDocument(params); transport.fetchDocument(params);
@ -287,7 +289,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
var metadata = this.pdfInfo.metadata; var metadata = this.pdfInfo.metadata;
promise.resolve({ promise.resolve({
info: info, info: info,
metadata: metadata ? new PDFJS.Metadata(metadata) : null metadata: (metadata ? new PDFJS.Metadata(metadata) : null)
}); });
return promise; return promise;
}, },
@ -387,8 +389,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* with transforms required for rendering. * with transforms required for rendering.
*/ */
getViewport: function PDFPageProxy_getViewport(scale, rotate) { getViewport: function PDFPageProxy_getViewport(scale, rotate) {
if (arguments.length < 2) if (arguments.length < 2) {
rotate = this.rotate; rotate = this.rotate;
}
return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0); return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
}, },
/** /**
@ -396,8 +399,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* annotation objects. * annotation objects.
*/ */
getAnnotations: function PDFPageProxy_getAnnotations() { getAnnotations: function PDFPageProxy_getAnnotations() {
if (this.annotationsPromise) if (this.annotationsPromise) {
return this.annotationsPromise; return this.annotationsPromise;
}
var promise = new PDFJS.LegacyPromise(); var promise = new PDFJS.LegacyPromise();
this.annotationsPromise = promise; this.annotationsPromise = promise;
@ -429,9 +433,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
// this call to render. // this call to render.
this.pendingDestroy = false; this.pendingDestroy = false;
var renderingIntent = 'intent' in params ? var renderingIntent = ('intent' in params ?
(params.intent == 'print' ? 'print' : 'display') : (params.intent == 'print' ? 'print' : 'display') : 'display');
'display';
if (!this.intentStates[renderingIntent]) { if (!this.intentStates[renderingIntent]) {
this.intentStates[renderingIntent] = {}; this.intentStates[renderingIntent] = {};
@ -457,9 +460,10 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
} }
var internalRenderTask = new InternalRenderTask(complete, params, var internalRenderTask = new InternalRenderTask(complete, params,
this.objs, this.commonObjs, this.objs,
intentState.operatorList, this.commonObjs,
this.pageNumber); intentState.operatorList,
this.pageNumber);
if (!intentState.renderTasks) { if (!intentState.renderTasks) {
intentState.renderTasks = []; intentState.renderTasks = [];
} }
@ -535,8 +539,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
if (!this.pendingDestroy || if (!this.pendingDestroy ||
Object.keys(this.intentStates).some(function(intent) { Object.keys(this.intentStates).some(function(intent) {
var intentState = this.intentStates[intent]; var intentState = this.intentStates[intent];
return intentState.renderTasks.length !== 0 || return (intentState.renderTasks.length !== 0 ||
intentState.receivingOperatorList; intentState.receivingOperatorList);
}, this)) { }, this)) {
return; return;
} }
@ -591,7 +595,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
*/ */
var WorkerTransport = (function WorkerTransportClosure() { var WorkerTransport = (function WorkerTransportClosure() {
function WorkerTransport(workerInitializedPromise, workerReadyPromise, function WorkerTransport(workerInitializedPromise, workerReadyPromise,
pdfDataRangeTransport, progressCallback) { pdfDataRangeTransport, progressCallback) {
this.pdfDataRangeTransport = pdfDataRangeTransport; this.pdfDataRangeTransport = pdfDataRangeTransport;
this.workerReadyPromise = workerReadyPromise; this.workerReadyPromise = workerReadyPromise;
@ -815,8 +819,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
messageHandler.on('commonobj', function transportObj(data) { messageHandler.on('commonobj', function transportObj(data) {
var id = data[0]; var id = data[0];
var type = data[1]; var type = data[1];
if (this.commonObjs.hasData(id)) if (this.commonObjs.hasData(id)) {
return; return;
}
switch (type) { switch (type) {
case 'Font': case 'Font':
@ -893,17 +898,19 @@ var WorkerTransport = (function WorkerTransportClosure() {
messageHandler.on('PageError', function transportError(data, intent) { messageHandler.on('PageError', function transportError(data, intent) {
var page = this.pageCache[data.pageNum - 1]; var page = this.pageCache[data.pageNum - 1];
var intentState = page.intentStates[intent]; var intentState = page.intentStates[intent];
if (intentState.displayReadyPromise) if (intentState.displayReadyPromise) {
intentState.displayReadyPromise.reject(data.error); intentState.displayReadyPromise.reject(data.error);
else } else {
error(data.error); error(data.error);
}
}, this); }, this);
messageHandler.on('JpegDecode', function(data, deferred) { messageHandler.on('JpegDecode', function(data, deferred) {
var imageUrl = data[0]; var imageUrl = data[0];
var components = data[1]; var components = data[1];
if (components != 3 && components != 1) if (components != 3 && components != 1) {
error('Only 3 component or 1 component can be returned'); error('Only 3 component or 1 component can be returned');
}
var img = new Image(); var img = new Image();
img.onload = (function messageHandler_onloadClosure() { img.onload = (function messageHandler_onloadClosure() {
@ -963,8 +970,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
} }
var pageIndex = pageNumber - 1; var pageIndex = pageNumber - 1;
if (pageIndex in this.pagePromises) if (pageIndex in this.pagePromises) {
return this.pagePromises[pageIndex]; return this.pagePromises[pageIndex];
}
var promise = new PDFJS.LegacyPromise(); var promise = new PDFJS.LegacyPromise();
this.pagePromises[pageIndex] = promise; this.pagePromises[pageIndex] = promise;
this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex }); this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex });
@ -1033,8 +1041,9 @@ var PDFObjects = (function PDFObjectsClosure() {
* Ensures there is an object defined for `objId`. * Ensures there is an object defined for `objId`.
*/ */
ensureObj: function PDFObjects_ensureObj(objId) { ensureObj: function PDFObjects_ensureObj(objId) {
if (this.objs[objId]) if (this.objs[objId]) {
return this.objs[objId]; return this.objs[objId];
}
var obj = { var obj = {
promise: new LegacyPromise(), promise: new LegacyPromise(),
@ -1069,8 +1078,9 @@ var PDFObjects = (function PDFObjectsClosure() {
// If there isn't an object yet or the object isn't resolved, then the // If there isn't an object yet or the object isn't resolved, then the
// data isn't ready yet! // data isn't ready yet!
if (!obj || !obj.resolved) if (!obj || !obj.resolved) {
error('Requesting object that isn\'t resolved yet ' + objId); error('Requesting object that isn\'t resolved yet ' + objId);
}
return obj.data; return obj.data;
}, },

34
src/display/canvas.js

@ -297,7 +297,9 @@ function compileType3Glyph(imgData) {
var type = points[p], p0 = p, pp; var type = points[p], p0 = p, pp;
do { do {
var step = steps[type]; var step = steps[type];
do { p += step; } while (!points[p]); do {
p += step;
} while (!points[p]);
pp = points[p]; pp = points[p];
if (pp !== 5 && pp !== 10) { if (pp !== 5 && pp !== 10) {
@ -976,8 +978,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
consumePath = typeof consumePath !== 'undefined' ? consumePath : true; consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
var ctx = this.ctx; var ctx = this.ctx;
var strokeColor = this.current.strokeColor; var strokeColor = this.current.strokeColor;
if (this.current.lineWidth === 0) if (this.current.lineWidth === 0) {
ctx.lineWidth = this.getSinglePixelWidth(); ctx.lineWidth = this.getSinglePixelWidth();
}
// For stroke we want to temporarily change the global alpha to the // For stroke we want to temporarily change the global alpha to the
// stroking alpha. // stroking alpha.
ctx.globalAlpha = this.current.strokeAlpha; ctx.globalAlpha = this.current.strokeAlpha;
@ -992,8 +995,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
} else { } else {
ctx.stroke(); ctx.stroke();
} }
if (consumePath) if (consumePath) {
this.consumePath(); this.consumePath();
}
// Restore the global alpha to the fill alpha // Restore the global alpha to the fill alpha
ctx.globalAlpha = this.current.fillAlpha; ctx.globalAlpha = this.current.fillAlpha;
}, },
@ -1117,11 +1121,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var fontObj = this.commonObjs.get(fontRefName); var fontObj = this.commonObjs.get(fontRefName);
var current = this.current; var current = this.current;
if (!fontObj) if (!fontObj) {
error('Can\'t find font for ' + fontRefName); error('Can\'t find font for ' + fontRefName);
}
current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : current.fontMatrix = (fontObj.fontMatrix ?
FONT_IDENTITY_MATRIX; fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
// A valid matrix needs all main diagonal elements to be non-zero // A valid matrix needs all main diagonal elements to be non-zero
// This also ensures we bypass FF bugzilla bug #719844. // This also ensures we bypass FF bugzilla bug #719844.
@ -1142,8 +1147,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.font = fontObj; this.current.font = fontObj;
this.current.fontSize = size; this.current.fontSize = size;
if (fontObj.coded) if (fontObj.coded) {
return; // we don't need ctx.font for Type3 fonts return; // we don't need ctx.font for Type3 fonts
}
var name = fontObj.loadedName || 'sans-serif'; var name = fontObj.loadedName || 'sans-serif';
var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') : var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
@ -1362,13 +1368,15 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var lineWidth = current.lineWidth; var lineWidth = current.lineWidth;
var a1 = current.textMatrix[0], b1 = current.textMatrix[1]; var a1 = current.textMatrix[0], b1 = current.textMatrix[1];
var scale = Math.sqrt(a1 * a1 + b1 * b1); var scale = Math.sqrt(a1 * a1 + b1 * b1);
if (scale === 0 || lineWidth === 0) if (scale === 0 || lineWidth === 0) {
lineWidth = this.getSinglePixelWidth(); lineWidth = this.getSinglePixelWidth();
else } else {
lineWidth /= scale; lineWidth /= scale;
}
if (textSelection) if (textSelection) {
geom = this.createTextGeometry(); geom = this.createTextGeometry();
}
if (fontSizeScale != 1.0) { if (fontSizeScale != 1.0) {
ctx.scale(fontSizeScale, fontSizeScale); ctx.scale(fontSizeScale, fontSizeScale);
@ -1490,8 +1498,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
current.x += spacingLength; current.x += spacingLength;
} }
if (textSelection) if (textSelection) {
spacingAccumulator += spacingLength; spacingAccumulator += spacingLength;
}
} else { } else {
var shownCanvasWidth = this.showText(e, true); var shownCanvasWidth = this.showText(e, true);
@ -1695,8 +1704,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.save(); this.save();
this.baseTransformStack.push(this.baseTransform); this.baseTransformStack.push(this.baseTransform);
if (matrix && isArray(matrix) && 6 == matrix.length) if (matrix && isArray(matrix) && 6 == matrix.length) {
this.transform.apply(this, matrix); this.transform.apply(this, matrix);
}
this.baseTransform = this.ctx.mozCurrentTransform; this.baseTransform = this.ctx.mozCurrentTransform;

Loading…
Cancel
Save