diff --git a/.eslintignore b/.eslintignore index 6fe2008c3dac..8a45078e6099 100644 --- a/.eslintignore +++ b/.eslintignore @@ -68,7 +68,8 @@ browser/components/sessionstore/** browser/components/tabview/** # generated files in cld2 browser/components/translation/cld2/cld-worker.js -browser/extensions/pdfjs/content/** +browser/extensions/pdfjs/content/build** +browser/extensions/pdfjs/content/web** # generated or library files in pocket browser/extensions/pocket/content/panels/js/tmpl.js browser/extensions/pocket/content/panels/js/vendor/** diff --git a/browser/extensions/pdfjs/README.mozilla b/browser/extensions/pdfjs/README.mozilla index 4a6f41fbf31b..5d46cc7d0c74 100644 --- a/browser/extensions/pdfjs/README.mozilla +++ b/browser/extensions/pdfjs/README.mozilla @@ -1,3 +1,3 @@ This is the pdf.js project output, https://github.com/mozilla/pdf.js -Current extension version is: 1.7.227 +Current extension version is: 1.7.235 diff --git a/browser/extensions/pdfjs/content/PdfJs.jsm b/browser/extensions/pdfjs/content/PdfJs.jsm index b18532d2101f..4602a5eaec37 100644 --- a/browser/extensions/pdfjs/content/PdfJs.jsm +++ b/browser/extensions/pdfjs/content/PdfJs.jsm @@ -15,9 +15,9 @@ /* globals Components, Services, XPCOMUtils, PdfjsChromeUtils, PdfjsContentUtils, PdfStreamConverter */ -'use strict'; +"use strict"; -var EXPORTED_SYMBOLS = ['PdfJs']; +var EXPORTED_SYMBOLS = ["PdfJs"]; const Cc = Components.classes; const Ci = Components.interfaces; @@ -25,32 +25,32 @@ const Cr = Components.results; const Cm = Components.manager; const Cu = Components.utils; -const PREF_PREFIX = 'pdfjs'; -const PREF_DISABLED = PREF_PREFIX + '.disabled'; -const PREF_MIGRATION_VERSION = PREF_PREFIX + '.migrationVersion'; -const PREF_PREVIOUS_ACTION = PREF_PREFIX + '.previousHandler.preferredAction'; +const PREF_PREFIX = "pdfjs"; +const PREF_DISABLED = PREF_PREFIX + ".disabled"; +const PREF_MIGRATION_VERSION = PREF_PREFIX + ".migrationVersion"; +const PREF_PREVIOUS_ACTION = PREF_PREFIX + ".previousHandler.preferredAction"; const PREF_PREVIOUS_ASK = PREF_PREFIX + - '.previousHandler.alwaysAskBeforeHandling'; -const PREF_DISABLED_PLUGIN_TYPES = 'plugin.disable_full_page_plugin_for_types'; -const TOPIC_PDFJS_HANDLER_CHANGED = 'pdfjs:handlerChanged'; -const TOPIC_PLUGINS_LIST_UPDATED = 'plugins-list-updated'; -const TOPIC_PLUGIN_INFO_UPDATED = 'plugin-info-updated'; -const PDF_CONTENT_TYPE = 'application/pdf'; + ".previousHandler.alwaysAskBeforeHandling"; +const PREF_DISABLED_PLUGIN_TYPES = "plugin.disable_full_page_plugin_for_types"; +const TOPIC_PDFJS_HANDLER_CHANGED = "pdfjs:handlerChanged"; +const TOPIC_PLUGINS_LIST_UPDATED = "plugins-list-updated"; +const TOPIC_PLUGIN_INFO_UPDATED = "plugin-info-updated"; +const PDF_CONTENT_TYPE = "application/pdf"; -Cu.import('resource://gre/modules/XPCOMUtils.jsm'); -Cu.import('resource://gre/modules/Services.jsm'); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); var Svc = {}; -XPCOMUtils.defineLazyServiceGetter(Svc, 'mime', - '@mozilla.org/mime;1', - 'nsIMIMEService'); -XPCOMUtils.defineLazyServiceGetter(Svc, 'pluginHost', - '@mozilla.org/plugin/host;1', - 'nsIPluginHost'); -XPCOMUtils.defineLazyModuleGetter(this, 'PdfjsChromeUtils', - 'resource://pdf.js/PdfjsChromeUtils.jsm'); -XPCOMUtils.defineLazyModuleGetter(this, 'PdfjsContentUtils', - 'resource://pdf.js/PdfjsContentUtils.jsm'); +XPCOMUtils.defineLazyServiceGetter(Svc, "mime", + "@mozilla.org/mime;1", + "nsIMIMEService"); +XPCOMUtils.defineLazyServiceGetter(Svc, "pluginHost", + "@mozilla.org/plugin/host;1", + "nsIPluginHost"); +XPCOMUtils.defineLazyModuleGetter(this, "PdfjsChromeUtils", + "resource://pdf.js/PdfjsChromeUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PdfjsContentUtils", + "resource://pdf.js/PdfjsContentUtils.jsm"); function getBoolPref(aPref, aDefaultValue) { try { @@ -98,18 +98,18 @@ function initializeDefaultPreferences() { } - var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + '.'); + var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + "."); var defaultValue; for (var key in DEFAULT_PREFERENCES) { defaultValue = DEFAULT_PREFERENCES[key]; switch (typeof defaultValue) { - case 'boolean': + case "boolean": defaultBranch.setBoolPref(key, defaultValue); break; - case 'number': + case "number": defaultBranch.setIntPref(key, defaultValue); break; - case 'string': + case "string": defaultBranch.setCharPref(key, defaultValue); break; } @@ -155,8 +155,8 @@ var PdfJs = { init: function init(remote) { if (Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT) { - throw new Error('PdfJs.init should only get called ' + - 'in the parent process.'); + throw new Error("PdfJs.init should only get called " + + "in the parent process."); } PdfjsChromeUtils.init(); if (!remote) { @@ -219,13 +219,13 @@ var PdfJs = { } if (currentVersion < 2) { // cleaning up of unused database preference (see #3994) - Services.prefs.clearUserPref(PREF_PREFIX + '.database'); + Services.prefs.clearUserPref(PREF_PREFIX + ".database"); } Services.prefs.setIntPref(PREF_MIGRATION_VERSION, VERSION); }, _becomeHandler: function _becomeHandler() { - let handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, 'pdf'); + let handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, "pdf"); let prefs = Services.prefs; if (handlerInfo.preferredAction !== Ci.nsIHandlerInfo.handleInternally && handlerInfo.preferredAction !== false) { @@ -236,7 +236,7 @@ var PdfJs = { prefs.setBoolPref(PREF_PREVIOUS_ASK, handlerInfo.alwaysAskBeforeHandling); } - let handlerService = Cc['@mozilla.org/uriloader/handler-service;1']. + let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"]. getService(Ci.nsIHandlerService); // Change and save mime handler settings. @@ -245,24 +245,24 @@ var PdfJs = { handlerService.store(handlerInfo); // Also disable any plugins for pdfs. - var stringTypes = ''; + var stringTypes = ""; var types = []; if (prefs.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES)) { stringTypes = prefs.getCharPref(PREF_DISABLED_PLUGIN_TYPES); } - if (stringTypes !== '') { - types = stringTypes.split(','); + if (stringTypes !== "") { + types = stringTypes.split(","); } if (types.indexOf(PDF_CONTENT_TYPE) === -1) { types.push(PDF_CONTENT_TYPE); } - prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES, types.join(',')); + prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES, types.join(",")); // Update the category manager in case the plugins are already loaded. - let categoryManager = Cc['@mozilla.org/categorymanager;1']; + let categoryManager = Cc["@mozilla.org/categorymanager;1"]; categoryManager.getService(Ci.nsICategoryManager). - deleteCategoryEntry('Gecko-Content-Viewers', + deleteCategoryEntry("Gecko-Content-Viewers", PDF_CONTENT_TYPE, false); }, @@ -272,7 +272,7 @@ var PdfJs = { this.updateRegistration(); if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_DEFAULT) { - let jsm = 'resource://pdf.js/PdfjsChromeUtils.jsm'; + let jsm = "resource://pdf.js/PdfjsChromeUtils.jsm"; let PdfjsChromeUtils = Components.utils.import(jsm, {}).PdfjsChromeUtils; PdfjsChromeUtils.notifyChildOfSettingsChange(); } @@ -297,7 +297,7 @@ var PdfJs = { // Check if we have disabled plugin handling of 'application/pdf' in prefs if (Services.prefs.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES)) { let disabledPluginTypes = - Services.prefs.getCharPref(PREF_DISABLED_PLUGIN_TYPES).split(','); + Services.prefs.getCharPref(PREF_DISABLED_PLUGIN_TYPES).split(","); if (disabledPluginTypes.indexOf(PDF_CONTENT_TYPE) >= 0) { return true; } @@ -306,7 +306,7 @@ var PdfJs = { // Check if there is an enabled pdf plugin. // Note: this check is performed last because getPluginTags() triggers // costly plugin list initialization (bug 881575) - let tags = Cc['@mozilla.org/plugin/host;1']. + let tags = Cc["@mozilla.org/plugin/host;1"]. getService(Ci.nsIPluginHost). getPluginTags(); let enabledPluginFound = tags.some(function(tag) { @@ -328,7 +328,7 @@ var PdfJs = { return; } this._pdfStreamConverterFactory = new Factory(); - Cu.import('resource://pdf.js/PdfStreamConverter.jsm'); + Cu.import("resource://pdf.js/PdfStreamConverter.jsm"); this._pdfStreamConverterFactory.register(PdfStreamConverter); this._registered = true; @@ -339,7 +339,7 @@ var PdfJs = { return; } this._pdfStreamConverterFactory.unregister(); - Cu.unload('resource://pdf.js/PdfStreamConverter.jsm'); + Cu.unload("resource://pdf.js/PdfStreamConverter.jsm"); delete this._pdfStreamConverterFactory; this._registered = false; diff --git a/browser/extensions/pdfjs/content/PdfJsNetwork.jsm b/browser/extensions/pdfjs/content/PdfJsNetwork.jsm index 8724f6dbe9ff..31d7c8b542e8 100644 --- a/browser/extensions/pdfjs/content/PdfJsNetwork.jsm +++ b/browser/extensions/pdfjs/content/PdfJsNetwork.jsm @@ -14,14 +14,14 @@ */ /* globals Components, Services */ -'use strict'; +"use strict"; -Components.utils.import('resource://gre/modules/Services.jsm'); +Components.utils.import("resource://gre/modules/Services.jsm"); -var EXPORTED_SYMBOLS = ['NetworkManager']; +var EXPORTED_SYMBOLS = ["NetworkManager"]; function log(aMsg) { - var msg = 'PdfJsNetwork.jsm: ' + (aMsg.join ? aMsg.join('') : aMsg); + var msg = "PdfJsNetwork.jsm: " + (aMsg.join ? aMsg.join("") : aMsg); Services.console.logStringMessage(msg); } @@ -32,7 +32,7 @@ var NetworkManager = (function NetworkManagerClosure() { function getArrayBuffer(xhr) { var data = xhr.response; - if (typeof data !== 'string') { + if (typeof data !== "string") { return data; } var length = data.length; @@ -82,18 +82,18 @@ var NetworkManager = (function NetworkManagerClosure() { xhr, }; - xhr.open('GET', this.url); + xhr.open("GET", this.url); xhr.withCredentials = this.withCredentials; for (var property in this.httpHeaders) { var value = this.httpHeaders[property]; - if (typeof value === 'undefined') { + if (typeof value === "undefined") { continue; } xhr.setRequestHeader(property, value); } - if (this.isHttp && 'begin' in args && 'end' in args) { - var rangeStr = args.begin + '-' + (args.end - 1); - xhr.setRequestHeader('Range', 'bytes=' + rangeStr); + if (this.isHttp && "begin" in args && "end" in args) { + var rangeStr = args.begin + "-" + (args.end - 1); + xhr.setRequestHeader("Range", "bytes=" + rangeStr); pendingRequest.expectedStatus = 206; } else { pendingRequest.expectedStatus = 200; @@ -101,11 +101,11 @@ var NetworkManager = (function NetworkManagerClosure() { var useMozChunkedLoading = !!args.onProgressiveData; if (useMozChunkedLoading) { - xhr.responseType = 'moz-chunked-arraybuffer'; + xhr.responseType = "moz-chunked-arraybuffer"; pendingRequest.onProgressiveData = args.onProgressiveData; pendingRequest.mozChunked = true; } else { - xhr.responseType = 'arraybuffer'; + xhr.responseType = "arraybuffer"; } if (args.onError) { @@ -197,7 +197,7 @@ var NetworkManager = (function NetworkManagerClosure() { var chunk = getArrayBuffer(xhr); if (xhrStatus === PARTIAL_CONTENT_RESPONSE) { - var rangeHeader = xhr.getResponseHeader('Content-Range'); + var rangeHeader = xhr.getResponseHeader("Content-Range"); var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader); var begin = parseInt(matches[1], 10); pendingRequest.onDone({ diff --git a/browser/extensions/pdfjs/content/PdfJsTelemetry.jsm b/browser/extensions/pdfjs/content/PdfJsTelemetry.jsm index 9f09888017f9..b57fe980136b 100644 --- a/browser/extensions/pdfjs/content/PdfJsTelemetry.jsm +++ b/browser/extensions/pdfjs/content/PdfJsTelemetry.jsm @@ -15,56 +15,56 @@ /* eslint max-len: ["error", 100] */ /* globals Components, Services */ -'use strict'; +"use strict"; -this.EXPORTED_SYMBOLS = ['PdfJsTelemetry']; +this.EXPORTED_SYMBOLS = ["PdfJsTelemetry"]; const Cu = Components.utils; -Cu.import('resource://gre/modules/Services.jsm'); +Cu.import("resource://gre/modules/Services.jsm"); this.PdfJsTelemetry = { onViewerIsUsed() { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_USED'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_USED"); histogram.add(true); }, onFallback() { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FALLBACK_SHOWN'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FALLBACK_SHOWN"); histogram.add(true); }, onDocumentSize(size) { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_SIZE_KB'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_SIZE_KB"); histogram.add(size / 1024); }, onDocumentVersion(versionId) { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_VERSION'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_VERSION"); histogram.add(versionId); }, onDocumentGenerator(generatorId) { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_GENERATOR'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_GENERATOR"); histogram.add(generatorId); }, onEmbed(isObject) { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_EMBED'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_EMBED"); histogram.add(isObject); }, onFontType(fontTypeId) { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FONT_TYPES'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FONT_TYPES"); histogram.add(fontTypeId); }, onForm(isAcroform) { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FORM'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FORM"); histogram.add(isAcroform); }, onPrint() { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_PRINT'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_PRINT"); histogram.add(true); }, onStreamType(streamTypeId) { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_STREAM_TYPES'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_STREAM_TYPES"); histogram.add(streamTypeId); }, onTimeToView(ms) { - let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_TIME_TO_VIEW_MS'); + let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_TIME_TO_VIEW_MS"); histogram.add(ms); } }; diff --git a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm index 7a71d10b455d..0ab7b4d14755 100644 --- a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm +++ b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm @@ -15,43 +15,43 @@ /* globals Components, Services, XPCOMUtils, NetUtil, PrivateBrowsingUtils, dump, NetworkManager, PdfJsTelemetry, PdfjsContentUtils */ -'use strict'; +"use strict"; -var EXPORTED_SYMBOLS = ['PdfStreamConverter']; +var EXPORTED_SYMBOLS = ["PdfStreamConverter"]; const Cc = Components.classes; const Ci = Components.interfaces; const Cr = Components.results; const Cu = Components.utils; // True only if this is the version of pdf.js that is included with firefox. -const MOZ_CENTRAL = JSON.parse('true'); -const PDFJS_EVENT_ID = 'pdf.js.message'; -const PDF_CONTENT_TYPE = 'application/pdf'; -const PREF_PREFIX = 'pdfjs'; -const PDF_VIEWER_WEB_PAGE = 'resource://pdf.js/web/viewer.html'; +const MOZ_CENTRAL = JSON.parse("true"); +const PDFJS_EVENT_ID = "pdf.js.message"; +const PDF_CONTENT_TYPE = "application/pdf"; +const PREF_PREFIX = "pdfjs"; +const PDF_VIEWER_WEB_PAGE = "resource://pdf.js/web/viewer.html"; const MAX_NUMBER_OF_PREFS = 50; const MAX_STRING_PREF_LENGTH = 128; -Cu.import('resource://gre/modules/XPCOMUtils.jsm'); -Cu.import('resource://gre/modules/Services.jsm'); -Cu.import('resource://gre/modules/NetUtil.jsm'); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, 'NetworkManager', - 'resource://pdf.js/PdfJsNetwork.jsm'); +XPCOMUtils.defineLazyModuleGetter(this, "NetworkManager", + "resource://pdf.js/PdfJsNetwork.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, 'PrivateBrowsingUtils', - 'resource://gre/modules/PrivateBrowsingUtils.jsm'); +XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", + "resource://gre/modules/PrivateBrowsingUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, 'PdfJsTelemetry', - 'resource://pdf.js/PdfJsTelemetry.jsm'); +XPCOMUtils.defineLazyModuleGetter(this, "PdfJsTelemetry", + "resource://pdf.js/PdfJsTelemetry.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, 'PdfjsContentUtils', - 'resource://pdf.js/PdfjsContentUtils.jsm'); +XPCOMUtils.defineLazyModuleGetter(this, "PdfjsContentUtils", + "resource://pdf.js/PdfjsContentUtils.jsm"); var Svc = {}; -XPCOMUtils.defineLazyServiceGetter(Svc, 'mime', - '@mozilla.org/mime;1', - 'nsIMIMEService'); +XPCOMUtils.defineLazyServiceGetter(Svc, "mime", + "@mozilla.org/mime;1", + "nsIMIMEService"); function getContainingBrowser(domWindow) { return domWindow.QueryInterface(Ci.nsIInterfaceRequestor) @@ -62,7 +62,7 @@ function getContainingBrowser(domWindow) { function getFindBar(domWindow) { if (PdfjsContentUtils.isRemote) { - throw new Error('FindBar is not accessible from the content process.'); + throw new Error("FindBar is not accessible from the content process."); } try { var browser = getContainingBrowser(domWindow); @@ -101,12 +101,12 @@ function getStringPref(pref, def) { } function log(aMsg) { - if (!getBoolPref(PREF_PREFIX + '.pdfBugEnabled', false)) { + if (!getBoolPref(PREF_PREFIX + ".pdfBugEnabled", false)) { return; } - var msg = 'PdfStreamConverter.js: ' + (aMsg.join ? aMsg.join('') : aMsg); + var msg = "PdfStreamConverter.js: " + (aMsg.join ? aMsg.join("") : aMsg); Services.console.logStringMessage(msg); - dump(msg + '\n'); + dump(msg + "\n"); } function getDOMWindow(aChannel) { @@ -118,16 +118,16 @@ function getDOMWindow(aChannel) { } function getLocalizedStrings(path) { - var stringBundle = Cc['@mozilla.org/intl/stringbundle;1']. + var stringBundle = Cc["@mozilla.org/intl/stringbundle;1"]. getService(Ci.nsIStringBundleService). - createBundle('chrome://pdf.js/locale/' + path); + createBundle("chrome://pdf.js/locale/" + path); var map = {}; var enumerator = stringBundle.getSimpleEnumeration(); while (enumerator.hasMoreElements()) { var string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement); - var key = string.key, property = 'textContent'; - var i = key.lastIndexOf('.'); + var key = string.key, property = "textContent"; + var i = key.lastIndexOf("."); if (i >= 0) { property = key.substring(i + 1); key = key.substring(0, i); @@ -140,7 +140,7 @@ function getLocalizedStrings(path) { return map; } function getLocalizedString(strings, id, property) { - property = property || 'textContent'; + property = property || "textContent"; if (id in strings) { return strings[id][property]; } @@ -233,13 +233,13 @@ class ChromeActions { // the original url. var originalUri = NetUtil.newURI(originalUrl); var filename = data.filename; - if (typeof filename !== 'string' || + if (typeof filename !== "string" || (!/\.pdf$/i.test(filename) && !data.isAttachment)) { - filename = 'document.pdf'; + filename = "document.pdf"; } var blobUri = NetUtil.newURI(blobUrl); var extHelperAppSvc = - Cc['@mozilla.org/uriloader/external-helper-app-service;1']. + Cc["@mozilla.org/uriloader/external-helper-app-service;1"]. getService(Ci.nsIExternalHelperAppService); var docIsPrivate = this.isInPrivateBrowsing(); @@ -247,7 +247,7 @@ class ChromeActions { uri: blobUri, loadUsingSystemPrincipal: true, }); - if ('nsIPrivateBrowsingChannel' in Ci && + if ("nsIPrivateBrowsingChannel" in Ci && netChannel instanceof Ci.nsIPrivateBrowsingChannel) { netChannel.setPrivate(docIsPrivate); } @@ -260,7 +260,7 @@ class ChromeActions { } // Create a nsIInputStreamChannel so we can set the url on the channel // so the filename will be correct. - var channel = Cc['@mozilla.org/network/input-stream-channel;1']. + var channel = Cc["@mozilla.org/network/input-stream-channel;1"]. createInstance(Ci.nsIInputStreamChannel); channel.QueryInterface(Ci.nsIChannel); try { @@ -275,7 +275,7 @@ class ChromeActions { channel.setURI(originalUri); channel.loadInfo = netChannel.loadInfo; channel.contentStream = aInputStream; - if ('nsIPrivateBrowsingChannel' in Ci && + if ("nsIPrivateBrowsingChannel" in Ci && channel instanceof Ci.nsIPrivateBrowsingChannel) { channel.setPrivate(docIsPrivate); } @@ -288,8 +288,8 @@ class ChromeActions { .getInterface(Ci.nsIWebNavigation) .QueryInterface(Ci.nsILoadContext); this.extListener = extHelperAppSvc.doContent( - (data.isAttachment ? 'application/octet-stream' : - 'application/pdf'), + (data.isAttachment ? "application/octet-stream" : + "application/pdf"), aRequest, loadContext, false); this.extListener.onStartRequest(aRequest, aContext); }, @@ -313,20 +313,20 @@ class ChromeActions { } getLocale() { - return getStringPref('general.useragent.locale', 'en-US'); + return getStringPref("general.useragent.locale", "en-US"); } getStrings(data) { try { // Lazy initialization of localizedStrings - if (!('localizedStrings' in this)) { - this.localizedStrings = getLocalizedStrings('viewer.properties'); + if (!("localizedStrings" in this)) { + this.localizedStrings = getLocalizedStrings("viewer.properties"); } var result = this.localizedStrings[data]; return JSON.stringify(result || null); } catch (e) { - log('Unable to retrieve localized strings: ' + e); - return 'null'; + log("Unable to retrieve localized strings: " + e); + return "null"; } } @@ -343,52 +343,52 @@ class ChromeActions { // ... or when the new find events code exists. var findBar = getFindBar(this.domWindow); - return !!findBar && ('updateControlState' in findBar); + return !!findBar && ("updateControlState" in findBar); } supportsDocumentFonts() { - var prefBrowser = getIntPref('browser.display.use_document_fonts', 1); - var prefGfx = getBoolPref('gfx.downloadable_fonts.enabled', true); + var prefBrowser = getIntPref("browser.display.use_document_fonts", 1); + var prefGfx = getBoolPref("gfx.downloadable_fonts.enabled", true); return (!!prefBrowser && prefGfx); } supportsDocumentColors() { - return getIntPref('browser.display.document_color_use', 0) !== 2; + return getIntPref("browser.display.document_color_use", 0) !== 2; } supportedMouseWheelZoomModifierKeys() { return { - ctrlKey: getIntPref('mousewheel.with_control.action', 3) === 3, - metaKey: getIntPref('mousewheel.with_meta.action', 1) === 3, + ctrlKey: getIntPref("mousewheel.with_control.action", 3) === 3, + metaKey: getIntPref("mousewheel.with_meta.action", 1) === 3, }; } reportTelemetry(data) { var probeInfo = JSON.parse(data); switch (probeInfo.type) { - case 'documentInfo': + case "documentInfo": if (!this.telemetryState.documentInfo) { PdfJsTelemetry.onDocumentVersion(probeInfo.version | 0); PdfJsTelemetry.onDocumentGenerator(probeInfo.generator | 0); if (probeInfo.formType) { - PdfJsTelemetry.onForm(probeInfo.formType === 'acroform'); + PdfJsTelemetry.onForm(probeInfo.formType === "acroform"); } this.telemetryState.documentInfo = true; } break; - case 'pageInfo': + case "pageInfo": if (!this.telemetryState.firstPageInfo) { var duration = Date.now() - this.telemetryState.startAt; PdfJsTelemetry.onTimeToView(duration); this.telemetryState.firstPageInfo = true; } break; - case 'documentStats': + case "documentStats": // documentStats can be called several times for one documents. // if stream/font types are reported, trying not to submit the same // enumeration value multiple times. var documentStats = probeInfo.stats; - if (!documentStats || typeof documentStats !== 'object') { + if (!documentStats || typeof documentStats !== "object") { break; } var i, streamTypes = documentStats.streamTypes; @@ -414,7 +414,7 @@ class ChromeActions { } } break; - case 'print': + case "print": PdfJsTelemetry.onPrint(); break; } @@ -428,29 +428,29 @@ class ChromeActions { var featureId = args.featureId; var domWindow = this.domWindow; - var strings = getLocalizedStrings('chrome.properties'); + var strings = getLocalizedStrings("chrome.properties"); var message; - if (featureId === 'forms') { - message = getLocalizedString(strings, 'unsupported_feature_forms'); + if (featureId === "forms") { + message = getLocalizedString(strings, "unsupported_feature_forms"); } else { - message = getLocalizedString(strings, 'unsupported_feature'); + message = getLocalizedString(strings, "unsupported_feature"); } PdfJsTelemetry.onFallback(); PdfjsContentUtils.displayWarning(domWindow, message, - getLocalizedString(strings, 'open_with_different_viewer'), - getLocalizedString(strings, 'open_with_different_viewer', 'accessKey')); + getLocalizedString(strings, "open_with_different_viewer"), + getLocalizedString(strings, "open_with_different_viewer", "accessKey")); let winmm = domWindow.QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIDocShell) .QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIContentFrameMessageManager); - winmm.addMessageListener('PDFJS:Child:fallbackDownload', + winmm.addMessageListener("PDFJS:Child:fallbackDownload", function fallbackDownload(msg) { let data = msg.data; sendResponse(data.download); - winmm.removeMessageListener('PDFJS:Child:fallbackDownload', + winmm.removeMessageListener("PDFJS:Child:fallbackDownload", fallbackDownload); }); } @@ -463,8 +463,8 @@ class ChromeActions { var result = data.result; var findPrevious = data.findPrevious; var findPreviousType = typeof findPrevious; - if ((typeof result !== 'number' || result < 0 || result > 3) || - (findPreviousType !== 'undefined' && findPreviousType !== 'boolean')) { + if ((typeof result !== "number" || result < 0 || result > 3) || + (findPreviousType !== "undefined" && findPreviousType !== "boolean")) { return; } @@ -473,34 +473,34 @@ class ChromeActions { .QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIContentFrameMessageManager); - winmm.sendAsyncMessage('PDFJS:Parent:updateControlState', data); + winmm.sendAsyncMessage("PDFJS:Parent:updateControlState", data); } setPreferences(prefs, sendResponse) { - var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + '.'); + var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + "."); var numberOfPrefs = 0; var prefValue, prefName; for (var key in prefs) { if (++numberOfPrefs > MAX_NUMBER_OF_PREFS) { - log('setPreferences - Exceeded the maximum number of preferences ' + - 'that is allowed to be set at once.'); + log("setPreferences - Exceeded the maximum number of preferences " + + "that is allowed to be set at once."); break; } else if (!defaultBranch.getPrefType(key)) { continue; } prefValue = prefs[key]; - prefName = (PREF_PREFIX + '.' + key); + prefName = (PREF_PREFIX + "." + key); switch (typeof prefValue) { - case 'boolean': + case "boolean": PdfjsContentUtils.setBoolPref(prefName, prefValue); break; - case 'number': + case "number": PdfjsContentUtils.setIntPref(prefName, prefValue); break; - case 'string': + case "string": if (prefValue.length > MAX_STRING_PREF_LENGTH) { - log('setPreferences - Exceeded the maximum allowed length ' + - 'for a string preference.'); + log("setPreferences - Exceeded the maximum allowed length " + + "for a string preference."); } else { PdfjsContentUtils.setStringPref(prefName, prefValue); } @@ -513,36 +513,36 @@ class ChromeActions { } getPreferences(prefs, sendResponse) { - var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + '.'); + var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + "."); var currentPrefs = {}, numberOfPrefs = 0; var prefValue, prefName; for (var key in prefs) { if (++numberOfPrefs > MAX_NUMBER_OF_PREFS) { - log('getPreferences - Exceeded the maximum number of preferences ' + - 'that is allowed to be fetched at once.'); + log("getPreferences - Exceeded the maximum number of preferences " + + "that is allowed to be fetched at once."); break; } else if (!defaultBranch.getPrefType(key)) { continue; } prefValue = prefs[key]; - prefName = (PREF_PREFIX + '.' + key); + prefName = (PREF_PREFIX + "." + key); switch (typeof prefValue) { - case 'boolean': + case "boolean": currentPrefs[key] = getBoolPref(prefName, prefValue); break; - case 'number': + case "number": currentPrefs[key] = getIntPref(prefName, prefValue); break; - case 'string': + case "string": currentPrefs[key] = getStringPref(prefName, prefValue); break; } } + let result = JSON.stringify(currentPrefs); if (sendResponse) { - sendResponse(JSON.stringify(currentPrefs)); - } else { - return JSON.stringify(currentPrefs); + sendResponse(result); } + return result; } } @@ -566,7 +566,7 @@ class RangedChromeActions extends ChromeActions { var httpHeaderVisitor = { headers: {}, visitHeader(aHeader, aValue) { - if (aHeader === 'Range') { + if (aHeader === "Range") { // When loading the PDF from cache, firefox seems to set the Range // request header to fetch only the unfetched portions of the file // (e.g. 'Range: bytes=1024-'). However, we want to set this header @@ -584,7 +584,7 @@ class RangedChromeActions extends ChromeActions { var xhr_onreadystatechange = function xhr_onreadystatechange() { if (this.readyState === 1) { // LOADING var netChannel = this.channel; - if ('nsIPrivateBrowsingChannel' in Ci && + if ("nsIPrivateBrowsingChannel" in Ci && netChannel instanceof Ci.nsIPrivateBrowsingChannel) { var docIsPrivate = self.isInPrivateBrowsing(); netChannel.setPrivate(docIsPrivate); @@ -593,9 +593,9 @@ class RangedChromeActions extends ChromeActions { }; var getXhr = function getXhr() { const XMLHttpRequest = Components.Constructor( - '@mozilla.org/xmlextras/xmlhttprequest;1'); + "@mozilla.org/xmlextras/xmlhttprequest;1"); var xhr = new XMLHttpRequest(); - xhr.addEventListener('readystatechange', xhr_onreadystatechange); + xhr.addEventListener("readystatechange", xhr_onreadystatechange); return xhr; }; @@ -606,7 +606,7 @@ class RangedChromeActions extends ChromeActions { // If we are in range request mode, this means we manually issued xhr // requests, which we need to abort when we leave the page - domWindow.addEventListener('unload', function unload(e) { + domWindow.addEventListener("unload", function unload(e) { domWindow.removeEventListener(e.type, unload); self.abortLoading(); }); @@ -624,11 +624,11 @@ class RangedChromeActions extends ChromeActions { this.dataListener.onprogress = (loaded, total) => { this.domWindow.postMessage({ - pdfjsLoadAction: 'progressiveRead', + pdfjsLoadAction: "progressiveRead", loaded, total, chunk: this.dataListener.readData(), - }, '*'); + }, "*"); }; this.dataListener.oncomplete = () => { this.dataListener = null; @@ -636,13 +636,13 @@ class RangedChromeActions extends ChromeActions { } this.domWindow.postMessage({ - pdfjsLoadAction: 'supportsRangedLoading', + pdfjsLoadAction: "supportsRangedLoading", rangeEnabled: this.rangeEnabled, streamingEnabled: this.streamingEnabled, pdfUrl: this.pdfUrl, length: this.contentLength, data, - }, '*'); + }, "*"); return true; } @@ -661,16 +661,16 @@ class RangedChromeActions extends ChromeActions { this.networkManager.requestRange(begin, end, { onDone: function RangedChromeActions_onDone(aArgs) { domWindow.postMessage({ - pdfjsLoadAction: 'range', + pdfjsLoadAction: "range", begin: aArgs.begin, chunk: aArgs.chunk, - }, '*'); + }, "*"); }, onProgress: function RangedChromeActions_onProgress(evt) { domWindow.postMessage({ - pdfjsLoadAction: 'rangeProgress', + pdfjsLoadAction: "rangeProgress", loaded: evt.loaded, - }, '*'); + }, "*"); } }); } @@ -703,18 +703,18 @@ class StandardChromeActions extends ChromeActions { this.dataListener.onprogress = (loaded, total) => { this.domWindow.postMessage({ - pdfjsLoadAction: 'progress', + pdfjsLoadAction: "progress", loaded, total, - }, '*'); + }, "*"); }; this.dataListener.oncomplete = (data, errorCode) => { this.domWindow.postMessage({ - pdfjsLoadAction: 'complete', + pdfjsLoadAction: "complete", data, errorCode, - }, '*'); + }, "*"); this.dataListener = null; this.originalRequest = null; @@ -749,7 +749,7 @@ class RequestListener { var sync = event.detail.sync; var actions = this.actions; if (!(action in actions)) { - log('Unknown action: ' + action); + log("Unknown action: " + action); return; } var response; @@ -763,9 +763,9 @@ class RequestListener { } else { response = function sendResponse(aResponse) { try { - var listener = doc.createEvent('CustomEvent'); + var listener = doc.createEvent("CustomEvent"); let detail = Cu.cloneInto({ response: aResponse }, doc.defaultView); - listener.initCustomEvent('pdf.js.response', true, false, detail); + listener.initCustomEvent("pdf.js.response", true, false, detail); return message.dispatchEvent(listener); } catch (e) { // doc is no longer accessible because the requestor is already @@ -797,14 +797,14 @@ class FindEventManager { this.unbind(); this.contentWindow.removeEventListener(e.type, unload); }.bind(this); - this.contentWindow.addEventListener('unload', unload); + this.contentWindow.addEventListener("unload", unload); // We cannot directly attach listeners to for the find events // since the FindBar is in the parent process. Instead we're // asking the PdfjsChromeUtils to do it for us and forward // all the find events to us. - this.winmm.sendAsyncMessage('PDFJS:Parent:addEventListener'); - this.winmm.addMessageListener('PDFJS:Child:handleEvent', this); + this.winmm.sendAsyncMessage("PDFJS:Parent:addEventListener"); + this.winmm.addMessageListener("PDFJS:Child:handleEvent", this); } receiveMessage(msg) { @@ -813,13 +813,13 @@ class FindEventManager { var contentWindow = this.contentWindow; detail = Cu.cloneInto(detail, contentWindow); - var forward = contentWindow.document.createEvent('CustomEvent'); + var forward = contentWindow.document.createEvent("CustomEvent"); forward.initCustomEvent(type, true, true, detail); contentWindow.dispatchEvent(forward); } unbind() { - this.winmm.sendAsyncMessage('PDFJS:Parent:removeEventListener'); + this.winmm.sendAsyncMessage("PDFJS:Parent:removeEventListener"); } } @@ -829,12 +829,12 @@ function PdfStreamConverter() { PdfStreamConverter.prototype = { // properties required for XPCOM registration: - classID: Components.ID('{d0c5195d-e798-49d4-b1d3-9324328b2291}'), - classDescription: 'pdf.js Component', - contractID: '@mozilla.org/streamconv;1?from=application/pdf&to=*/*', + classID: Components.ID("{d0c5195d-e798-49d4-b1d3-9324328b2291}"), + classDescription: "pdf.js Component", + contractID: "@mozilla.org/streamconv;1?from=application/pdf&to=*/*", - classID2: Components.ID('{d0c5195d-e798-49d4-b1d3-9324328b2292}'), - contractID2: '@mozilla.org/streamconv;1?from=application/pdf&to=text/html', + classID2: Components.ID("{d0c5195d-e798-49d4-b1d3-9324328b2292}"), + contractID2: "@mozilla.org/streamconv;1?from=application/pdf&to=text/html", QueryInterface: XPCOMUtils.generateQI([ Ci.nsISupports, @@ -894,29 +894,29 @@ PdfStreamConverter.prototype = { var rangeRequest = false; var streamRequest = false; if (isHttpRequest) { - var contentEncoding = 'identity'; + var contentEncoding = "identity"; try { - contentEncoding = aRequest.getResponseHeader('Content-Encoding'); + contentEncoding = aRequest.getResponseHeader("Content-Encoding"); } catch (e) {} var acceptRanges; try { - acceptRanges = aRequest.getResponseHeader('Accept-Ranges'); + acceptRanges = aRequest.getResponseHeader("Accept-Ranges"); } catch (e) {} var hash = aRequest.URI.ref; - var isPDFBugEnabled = getBoolPref(PREF_PREFIX + '.pdfBugEnabled', false); - rangeRequest = contentEncoding === 'identity' && - acceptRanges === 'bytes' && + var isPDFBugEnabled = getBoolPref(PREF_PREFIX + ".pdfBugEnabled", false); + rangeRequest = contentEncoding === "identity" && + acceptRanges === "bytes" && aRequest.contentLength >= 0 && - !getBoolPref(PREF_PREFIX + '.disableRange', false) && + !getBoolPref(PREF_PREFIX + ".disableRange", false) && (!isPDFBugEnabled || - hash.toLowerCase().indexOf('disablerange=true') < 0); - streamRequest = contentEncoding === 'identity' && + hash.toLowerCase().indexOf("disablerange=true") < 0); + streamRequest = contentEncoding === "identity" && aRequest.contentLength >= 0 && - !getBoolPref(PREF_PREFIX + '.disableStream', false) && + !getBoolPref(PREF_PREFIX + ".disableStream", false) && (!isPDFBugEnabled || - hash.toLowerCase().indexOf('disablestream=true') < 0); + hash.toLowerCase().indexOf("disablestream=true") < 0); } aRequest.QueryInterface(Ci.nsIChannel); @@ -929,15 +929,15 @@ PdfStreamConverter.prototype = { } catch (e) {} // Change the content type so we don't get stuck in a loop. - aRequest.setProperty('contentType', aRequest.contentType); - aRequest.contentType = 'text/html'; + aRequest.setProperty("contentType", aRequest.contentType); + aRequest.contentType = "text/html"; if (isHttpRequest) { // We trust PDF viewer, using no CSP - aRequest.setResponseHeader('Content-Security-Policy', '', false); - aRequest.setResponseHeader('Content-Security-Policy-Report-Only', '', + aRequest.setResponseHeader("Content-Security-Policy", "", false); + aRequest.setResponseHeader("Content-Security-Policy-Report-Only", "", false); // The viewer does not need to handle HTTP Refresh header. - aRequest.setResponseHeader('Refresh', '', false); + aRequest.setResponseHeader("Refresh", "", false); } PdfJsTelemetry.onViewerIsUsed(); @@ -946,7 +946,7 @@ PdfStreamConverter.prototype = { // Creating storage for PDF data var contentLength = aRequest.contentLength; this.dataListener = new PdfDataListener(contentLength); - this.binaryStream = Cc['@mozilla.org/binaryinputstream;1'] + this.binaryStream = Cc["@mozilla.org/binaryinputstream;1"] .createInstance(Ci.nsIBinaryInputStream); // Create a new channel that is viewer loaded as a resource. @@ -993,8 +993,8 @@ PdfStreamConverter.prototype = { listener.onStopRequest(aRequest, aContext, statusCode); if (domWindow.frameElement) { - var isObjectEmbed = domWindow.frameElement.tagName !== 'IFRAME' || - domWindow.frameElement.className === 'previewPluginContentFrame'; + var isObjectEmbed = domWindow.frameElement.tagName !== "IFRAME" || + domWindow.frameElement.className === "previewPluginContentFrame"; PdfJsTelemetry.onEmbed(isObjectEmbed); } } @@ -1008,7 +1008,7 @@ PdfStreamConverter.prototype = { // We can use the resource principal when data is fetched by the chrome, // e.g. useful for NoScript. Make make sure we reuse the origin attributes // from the request channel to keep isolation consistent. - var ssm = Cc['@mozilla.org/scriptsecuritymanager;1'] + var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] .getService(Ci.nsIScriptSecurityManager); var uri = NetUtil.newURI(PDF_VIEWER_WEB_PAGE); var resourcePrincipal = diff --git a/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm b/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm index a87c01a896ad..2dfbfb0c5818 100644 --- a/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm +++ b/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm @@ -14,25 +14,25 @@ */ /* globals Components, Services, XPCOMUtils */ -'use strict'; +"use strict"; -var EXPORTED_SYMBOLS = ['PdfjsChromeUtils']; +var EXPORTED_SYMBOLS = ["PdfjsChromeUtils"]; const Cc = Components.classes; const Ci = Components.interfaces; const Cr = Components.results; const Cu = Components.utils; -const PREF_PREFIX = 'pdfjs'; -const PDF_CONTENT_TYPE = 'application/pdf'; +const PREF_PREFIX = "pdfjs"; +const PDF_CONTENT_TYPE = "application/pdf"; -Cu.import('resource://gre/modules/XPCOMUtils.jsm'); -Cu.import('resource://gre/modules/Services.jsm'); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); var Svc = {}; -XPCOMUtils.defineLazyServiceGetter(Svc, 'mime', - '@mozilla.org/mime;1', - 'nsIMIMEService'); +XPCOMUtils.defineLazyServiceGetter(Svc, "mime", + "@mozilla.org/mime;1", + "nsIMIMEService"); var DEFAULT_PREFERENCES = { @@ -71,46 +71,46 @@ var PdfjsChromeUtils = { this._browsers = new WeakSet(); if (!this._ppmm) { // global parent process message manager (PPMM) - this._ppmm = Cc['@mozilla.org/parentprocessmessagemanager;1']. + this._ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]. getService(Ci.nsIMessageBroadcaster); - this._ppmm.addMessageListener('PDFJS:Parent:clearUserPref', this); - this._ppmm.addMessageListener('PDFJS:Parent:setIntPref', this); - this._ppmm.addMessageListener('PDFJS:Parent:setBoolPref', this); - this._ppmm.addMessageListener('PDFJS:Parent:setCharPref', this); - this._ppmm.addMessageListener('PDFJS:Parent:setStringPref', this); - this._ppmm.addMessageListener('PDFJS:Parent:isDefaultHandlerApp', this); + this._ppmm.addMessageListener("PDFJS:Parent:clearUserPref", this); + this._ppmm.addMessageListener("PDFJS:Parent:setIntPref", this); + this._ppmm.addMessageListener("PDFJS:Parent:setBoolPref", this); + this._ppmm.addMessageListener("PDFJS:Parent:setCharPref", this); + this._ppmm.addMessageListener("PDFJS:Parent:setStringPref", this); + this._ppmm.addMessageListener("PDFJS:Parent:isDefaultHandlerApp", this); // global dom message manager (MMg) - this._mmg = Cc['@mozilla.org/globalmessagemanager;1']. + this._mmg = Cc["@mozilla.org/globalmessagemanager;1"]. getService(Ci.nsIMessageListenerManager); - this._mmg.addMessageListener('PDFJS:Parent:displayWarning', this); + this._mmg.addMessageListener("PDFJS:Parent:displayWarning", this); - this._mmg.addMessageListener('PDFJS:Parent:addEventListener', this); - this._mmg.addMessageListener('PDFJS:Parent:removeEventListener', this); - this._mmg.addMessageListener('PDFJS:Parent:updateControlState', this); + this._mmg.addMessageListener("PDFJS:Parent:addEventListener", this); + this._mmg.addMessageListener("PDFJS:Parent:removeEventListener", this); + this._mmg.addMessageListener("PDFJS:Parent:updateControlState", this); // observer to handle shutdown - Services.obs.addObserver(this, 'quit-application', false); + Services.obs.addObserver(this, "quit-application", false); } }, uninit() { if (this._ppmm) { - this._ppmm.removeMessageListener('PDFJS:Parent:clearUserPref', this); - this._ppmm.removeMessageListener('PDFJS:Parent:setIntPref', this); - this._ppmm.removeMessageListener('PDFJS:Parent:setBoolPref', this); - this._ppmm.removeMessageListener('PDFJS:Parent:setCharPref', this); - this._ppmm.removeMessageListener('PDFJS:Parent:setStringPref', this); - this._ppmm.removeMessageListener('PDFJS:Parent:isDefaultHandlerApp', + this._ppmm.removeMessageListener("PDFJS:Parent:clearUserPref", this); + this._ppmm.removeMessageListener("PDFJS:Parent:setIntPref", this); + this._ppmm.removeMessageListener("PDFJS:Parent:setBoolPref", this); + this._ppmm.removeMessageListener("PDFJS:Parent:setCharPref", this); + this._ppmm.removeMessageListener("PDFJS:Parent:setStringPref", this); + this._ppmm.removeMessageListener("PDFJS:Parent:isDefaultHandlerApp", this); - this._mmg.removeMessageListener('PDFJS:Parent:displayWarning', this); + this._mmg.removeMessageListener("PDFJS:Parent:displayWarning", this); - this._mmg.removeMessageListener('PDFJS:Parent:addEventListener', this); - this._mmg.removeMessageListener('PDFJS:Parent:removeEventListener', this); - this._mmg.removeMessageListener('PDFJS:Parent:updateControlState', this); + this._mmg.removeMessageListener("PDFJS:Parent:addEventListener", this); + this._mmg.removeMessageListener("PDFJS:Parent:removeEventListener", this); + this._mmg.removeMessageListener("PDFJS:Parent:updateControlState", this); - Services.obs.removeObserver(this, 'quit-application'); + Services.obs.removeObserver(this, "quit-application"); this._mmg = null; this._ppmm = null; @@ -131,7 +131,7 @@ var PdfjsChromeUtils = { // manager, which means this is going to fire to every child process // we have open. Unfortunately I can't find a way to get at that // process specific mm from js. - this._ppmm.broadcastAsyncMessage('PDFJS:Child:refreshSettings', {}); + this._ppmm.broadcastAsyncMessage("PDFJS:Child:refreshSettings", {}); } }, @@ -140,42 +140,42 @@ var PdfjsChromeUtils = { */ observe(aSubject, aTopic, aData) { - if (aTopic === 'quit-application') { + if (aTopic === "quit-application") { this.uninit(); } }, receiveMessage(aMsg) { switch (aMsg.name) { - case 'PDFJS:Parent:clearUserPref': + case "PDFJS:Parent:clearUserPref": this._clearUserPref(aMsg.data.name); break; - case 'PDFJS:Parent:setIntPref': + case "PDFJS:Parent:setIntPref": this._setIntPref(aMsg.data.name, aMsg.data.value); break; - case 'PDFJS:Parent:setBoolPref': + case "PDFJS:Parent:setBoolPref": this._setBoolPref(aMsg.data.name, aMsg.data.value); break; - case 'PDFJS:Parent:setCharPref': + case "PDFJS:Parent:setCharPref": this._setCharPref(aMsg.data.name, aMsg.data.value); break; - case 'PDFJS:Parent:setStringPref': + case "PDFJS:Parent:setStringPref": this._setStringPref(aMsg.data.name, aMsg.data.value); break; - case 'PDFJS:Parent:isDefaultHandlerApp': + case "PDFJS:Parent:isDefaultHandlerApp": return this.isDefaultHandlerApp(); - case 'PDFJS:Parent:displayWarning': + case "PDFJS:Parent:displayWarning": this._displayWarning(aMsg); break; - - case 'PDFJS:Parent:updateControlState': + case "PDFJS:Parent:updateControlState": return this._updateControlState(aMsg); - case 'PDFJS:Parent:addEventListener': + case "PDFJS:Parent:addEventListener": return this._addEventListener(aMsg); - case 'PDFJS:Parent:removeEventListener': + case "PDFJS:Parent:removeEventListener": return this._removeEventListener(aMsg); } + return undefined; }, /* @@ -208,25 +208,25 @@ var PdfjsChromeUtils = { let browser = aEvent.currentTarget.browser; if (!this._browsers.has(browser)) { - throw new Error('FindEventManager was not bound ' + - 'for the current browser.'); + throw new Error("FindEventManager was not bound " + + "for the current browser."); } // Only forward the events if the current browser is a registered browser. let mm = browser.messageManager; - mm.sendAsyncMessage('PDFJS:Child:handleEvent', { type, detail, }); + mm.sendAsyncMessage("PDFJS:Child:handleEvent", { type, detail, }); aEvent.preventDefault(); }, - _types: ['find', - 'findagain', - 'findhighlightallchange', - 'findcasesensitivitychange'], + _types: ["find", + "findagain", + "findhighlightallchange", + "findcasesensitivitychange"], _addEventListener(aMsg) { let browser = aMsg.target; if (this._browsers.has(browser)) { - throw new Error('FindEventManager was bound 2nd time ' + - 'without unbinding it first.'); + throw new Error("FindEventManager was bound 2nd time " + + "without unbinding it first."); } // Since this jsm is global, we need to store all the browsers @@ -244,7 +244,7 @@ var PdfjsChromeUtils = { _removeEventListener(aMsg) { let browser = aMsg.target; if (!this._browsers.has(browser)) { - throw new Error('FindEventManager was unbound without binding it first.'); + throw new Error("FindEventManager was unbound without binding it first."); } this._browsers.delete(browser); @@ -258,11 +258,11 @@ var PdfjsChromeUtils = { }, _ensurePreferenceAllowed(aPrefName) { - let unPrefixedName = aPrefName.split(PREF_PREFIX + '.'); - if (unPrefixedName[0] !== '' || + let unPrefixedName = aPrefName.split(PREF_PREFIX + "."); + if (unPrefixedName[0] !== "" || this._allowedPrefNames.indexOf(unPrefixedName[1]) === -1) { - let msg = '"' + aPrefName + '" ' + - 'can\'t be accessed from content. See PdfjsChromeUtils.'; + let msg = "\"" + aPrefName + "\" " + + "can't be accessed from content. See PdfjsChromeUtils."; throw new Error(msg); } }, @@ -289,7 +289,7 @@ var PdfjsChromeUtils = { _setStringPref(aPrefName, aPrefValue) { this._ensurePreferenceAllowed(aPrefName); - let str = Cc['@mozilla.org/supports-string;1'] + let str = Cc["@mozilla.org/supports-string;1"] .createInstance(Ci.nsISupportsString); str.data = aPrefValue; Services.prefs.setComplexValue(aPrefName, Ci.nsISupportsString, str); @@ -301,7 +301,7 @@ var PdfjsChromeUtils = { * parent. */ isDefaultHandlerApp() { - var handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, 'pdf'); + var handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, "pdf"); return (!handlerInfo.alwaysAskBeforeHandling && handlerInfo.preferredAction === Ci.nsIHandlerInfo.handleInternally); }, @@ -323,7 +323,7 @@ var PdfjsChromeUtils = { let messageSent = false; function sendMessage(download) { let mm = browser.messageManager; - mm.sendAsyncMessage('PDFJS:Child:fallbackDownload', { download, }); + mm.sendAsyncMessage("PDFJS:Child:fallbackDownload", { download, }); } let buttons = [{ label: data.label, @@ -333,13 +333,13 @@ var PdfjsChromeUtils = { sendMessage(true); } }]; - notificationBox.appendNotification(data.message, 'pdfjs-fallback', null, + notificationBox.appendNotification(data.message, "pdfjs-fallback", null, notificationBox.PRIORITY_INFO_LOW, buttons, function eventsCallback(eventType) { // Currently there is only one event "removed" but if there are any other // added in the future we still only care about removed at the moment. - if (eventType !== 'removed') { + if (eventType !== "removed") { return; } // Don't send a response again if we already responded when the button was diff --git a/browser/extensions/pdfjs/content/PdfjsContentUtils.jsm b/browser/extensions/pdfjs/content/PdfjsContentUtils.jsm index 340e4e3adc6a..f645011ef94a 100644 --- a/browser/extensions/pdfjs/content/PdfjsContentUtils.jsm +++ b/browser/extensions/pdfjs/content/PdfjsContentUtils.jsm @@ -14,17 +14,17 @@ */ /* globals Components, Services, XPCOMUtils */ -'use strict'; +"use strict"; -var EXPORTED_SYMBOLS = ['PdfjsContentUtils']; +var EXPORTED_SYMBOLS = ["PdfjsContentUtils"]; const Cc = Components.classes; const Ci = Components.interfaces; const Cr = Components.results; const Cu = Components.utils; -Cu.import('resource://gre/modules/XPCOMUtils.jsm'); -Cu.import('resource://gre/modules/Services.jsm'); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); var PdfjsContentUtils = { _mm: null, @@ -42,17 +42,17 @@ var PdfjsContentUtils = { // child *process* mm, or when loaded into the parent for in-content // support the psuedo child process mm 'child PPMM'. if (!this._mm) { - this._mm = Cc['@mozilla.org/childprocessmessagemanager;1']. + this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"]. getService(Ci.nsISyncMessageSender); - this._mm.addMessageListener('PDFJS:Child:refreshSettings', this); - Services.obs.addObserver(this, 'quit-application', false); + this._mm.addMessageListener("PDFJS:Child:refreshSettings", this); + Services.obs.addObserver(this, "quit-application", false); } }, uninit() { if (this._mm) { - this._mm.removeMessageListener('PDFJS:Child:refreshSettings', this); - Services.obs.removeObserver(this, 'quit-application'); + this._mm.removeMessageListener("PDFJS:Child:refreshSettings", this); + Services.obs.removeObserver(this, "quit-application"); } this._mm = null; }, @@ -64,34 +64,34 @@ var PdfjsContentUtils = { */ clearUserPref(aPrefName) { - this._mm.sendSyncMessage('PDFJS:Parent:clearUserPref', { + this._mm.sendSyncMessage("PDFJS:Parent:clearUserPref", { name: aPrefName }); }, setIntPref(aPrefName, aPrefValue) { - this._mm.sendSyncMessage('PDFJS:Parent:setIntPref', { + this._mm.sendSyncMessage("PDFJS:Parent:setIntPref", { name: aPrefName, value: aPrefValue }); }, setBoolPref(aPrefName, aPrefValue) { - this._mm.sendSyncMessage('PDFJS:Parent:setBoolPref', { + this._mm.sendSyncMessage("PDFJS:Parent:setBoolPref", { name: aPrefName, value: aPrefValue }); }, setCharPref(aPrefName, aPrefValue) { - this._mm.sendSyncMessage('PDFJS:Parent:setCharPref', { + this._mm.sendSyncMessage("PDFJS:Parent:setCharPref", { name: aPrefName, value: aPrefValue }); }, setStringPref(aPrefName, aPrefValue) { - this._mm.sendSyncMessage('PDFJS:Parent:setStringPref', { + this._mm.sendSyncMessage("PDFJS:Parent:setStringPref", { name: aPrefName, value: aPrefValue }); @@ -102,7 +102,7 @@ var PdfjsContentUtils = { * handler app settings only available in the parent process. */ isDefaultHandlerApp() { - return this._mm.sendSyncMessage('PDFJS:Parent:isDefaultHandlerApp')[0]; + return this._mm.sendSyncMessage("PDFJS:Parent:isDefaultHandlerApp")[0]; }, /* @@ -115,7 +115,7 @@ var PdfjsContentUtils = { .getInterface(Ci.nsIDocShell) .QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIContentFrameMessageManager); - winmm.sendAsyncMessage('PDFJS:Parent:displayWarning', { + winmm.sendAsyncMessage("PDFJS:Parent:displayWarning", { message: aMessage, label: aLabel, accessKey: aAccessKey, @@ -127,18 +127,18 @@ var PdfjsContentUtils = { */ observe(aSubject, aTopic, aData) { - if (aTopic === 'quit-application') { + if (aTopic === "quit-application") { this.uninit(); } }, receiveMessage(aMsg) { switch (aMsg.name) { - case 'PDFJS:Child:refreshSettings': + case "PDFJS:Child:refreshSettings": // Only react to this if we are remote. if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) { - let jsm = 'resource://pdf.js/PdfJs.jsm'; + let jsm = "resource://pdf.js/PdfJs.jsm"; let pdfjs = Components.utils.import(jsm, {}).PdfJs; pdfjs.updateRegistration(); } diff --git a/browser/extensions/pdfjs/content/build/pdf.js b/browser/extensions/pdfjs/content/build/pdf.js index 9135b4a0a715..2bea2c968905 100644 --- a/browser/extensions/pdfjs/content/build/pdf.js +++ b/browser/extensions/pdfjs/content/build/pdf.js @@ -23,8 +23,8 @@ } }(this, function (exports) { 'use strict'; - var pdfjsVersion = '1.7.227'; - var pdfjsBuild = 'e132fa97'; + var pdfjsVersion = '1.7.235'; + var pdfjsBuild = '3f320f0b'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null; var pdfjsLibs = {}; (function pdfjsWrapper() { @@ -1620,7 +1620,7 @@ clear: function fontLoaderClear() { var styleElement = this.styleElement; if (styleElement) { - styleElement.remove(); + styleElement.parentNode.removeChild(styleElement); styleElement = this.styleElement = null; } } @@ -4693,13 +4693,7 @@ needRestore = true; } if (this.pendingEOFill) { - if (ctx.mozFillRule !== undefined) { - ctx.mozFillRule = 'evenodd'; - ctx.fill(); - ctx.mozFillRule = 'nonzero'; - } else { - ctx.fill('evenodd'); - } + ctx.fill('evenodd'); this.pendingEOFill = false; } else { ctx.fill(); @@ -5531,13 +5525,7 @@ var ctx = this.ctx; if (this.pendingClip) { if (this.pendingClip === EO_CLIP) { - if (ctx.mozFillRule !== undefined) { - ctx.mozFillRule = 'evenodd'; - ctx.clip(); - ctx.mozFillRule = 'nonzero'; - } else { - ctx.clip('evenodd'); - } + ctx.clip('evenodd'); } else { ctx.clip(); } diff --git a/browser/extensions/pdfjs/content/build/pdf.worker.js b/browser/extensions/pdfjs/content/build/pdf.worker.js index 628f309bd660..7321d8badc97 100644 --- a/browser/extensions/pdfjs/content/build/pdf.worker.js +++ b/browser/extensions/pdfjs/content/build/pdf.worker.js @@ -23,8 +23,8 @@ } }(this, function (exports) { 'use strict'; - var pdfjsVersion = '1.7.227'; - var pdfjsBuild = 'e132fa97'; + var pdfjsVersion = '1.7.235'; + var pdfjsBuild = '3f320f0b'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null; var pdfjsLibs = {}; (function pdfjsWrapper() { @@ -19520,6 +19520,7 @@ factory(root.pdfjsCorePrimitives = {}, root.pdfjsSharedUtil); }(this, function (exports, sharedUtil) { var isArray = sharedUtil.isArray; + var EOF = {}; var Name = function NameClosure() { function Name(name) { this.name = name; @@ -19705,6 +19706,9 @@ }; return RefSetCache; }(); + function isEOF(v) { + return v === EOF; + } function isName(v, name) { return v instanceof Name && (name === undefined || v.name === name); } @@ -19723,12 +19727,14 @@ function isStream(v) { return typeof v === 'object' && v !== null && v.getBytes !== undefined; } + exports.EOF = EOF; exports.Cmd = Cmd; exports.Dict = Dict; exports.Name = Name; exports.Ref = Ref; exports.RefSet = RefSet; exports.RefSetCache = RefSetCache; + exports.isEOF = isEOF; exports.isCmd = isCmd; exports.isDict = isDict; exports.isName = isName; @@ -22350,6 +22356,200 @@ exports.getNormalizedUnicodes = getNormalizedUnicodes; exports.getUnicodeForGlyph = getUnicodeForGlyph; })); + (function (root, factory) { + factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives); + }(this, function (exports, sharedUtil, corePrimitives) { + var error = sharedUtil.error; + var isSpace = sharedUtil.isSpace; + var EOF = corePrimitives.EOF; + var PostScriptParser = function PostScriptParserClosure() { + function PostScriptParser(lexer) { + this.lexer = lexer; + this.operators = []; + this.token = null; + this.prev = null; + } + PostScriptParser.prototype = { + nextToken: function PostScriptParser_nextToken() { + this.prev = this.token; + this.token = this.lexer.getToken(); + }, + accept: function PostScriptParser_accept(type) { + if (this.token.type === type) { + this.nextToken(); + return true; + } + return false; + }, + expect: function PostScriptParser_expect(type) { + if (this.accept(type)) { + return true; + } + error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.'); + }, + parse: function PostScriptParser_parse() { + this.nextToken(); + this.expect(PostScriptTokenTypes.LBRACE); + this.parseBlock(); + this.expect(PostScriptTokenTypes.RBRACE); + return this.operators; + }, + parseBlock: function PostScriptParser_parseBlock() { + while (true) { + if (this.accept(PostScriptTokenTypes.NUMBER)) { + this.operators.push(this.prev.value); + } else if (this.accept(PostScriptTokenTypes.OPERATOR)) { + this.operators.push(this.prev.value); + } else if (this.accept(PostScriptTokenTypes.LBRACE)) { + this.parseCondition(); + } else { + return; + } + } + }, + parseCondition: function PostScriptParser_parseCondition() { + var conditionLocation = this.operators.length; + this.operators.push(null, null); + this.parseBlock(); + this.expect(PostScriptTokenTypes.RBRACE); + if (this.accept(PostScriptTokenTypes.IF)) { + this.operators[conditionLocation] = this.operators.length; + this.operators[conditionLocation + 1] = 'jz'; + } else if (this.accept(PostScriptTokenTypes.LBRACE)) { + var jumpLocation = this.operators.length; + this.operators.push(null, null); + var endOfTrue = this.operators.length; + this.parseBlock(); + this.expect(PostScriptTokenTypes.RBRACE); + this.expect(PostScriptTokenTypes.IFELSE); + this.operators[jumpLocation] = this.operators.length; + this.operators[jumpLocation + 1] = 'j'; + this.operators[conditionLocation] = endOfTrue; + this.operators[conditionLocation + 1] = 'jz'; + } else { + error('PS Function: error parsing conditional.'); + } + } + }; + return PostScriptParser; + }(); + var PostScriptTokenTypes = { + LBRACE: 0, + RBRACE: 1, + NUMBER: 2, + OPERATOR: 3, + IF: 4, + IFELSE: 5 + }; + var PostScriptToken = function PostScriptTokenClosure() { + function PostScriptToken(type, value) { + this.type = type; + this.value = value; + } + var opCache = Object.create(null); + PostScriptToken.getOperator = function PostScriptToken_getOperator(op) { + var opValue = opCache[op]; + if (opValue) { + return opValue; + } + return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op); + }; + PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{'); + PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}'); + PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF'); + PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE'); + return PostScriptToken; + }(); + var PostScriptLexer = function PostScriptLexerClosure() { + function PostScriptLexer(stream) { + this.stream = stream; + this.nextChar(); + this.strBuf = []; + } + PostScriptLexer.prototype = { + nextChar: function PostScriptLexer_nextChar() { + return this.currentChar = this.stream.getByte(); + }, + getToken: function PostScriptLexer_getToken() { + var comment = false; + var ch = this.currentChar; + while (true) { + if (ch < 0) { + return EOF; + } + if (comment) { + if (ch === 0x0A || ch === 0x0D) { + comment = false; + } + } else if (ch === 0x25) { + comment = true; + } else if (!isSpace(ch)) { + break; + } + ch = this.nextChar(); + } + switch (ch | 0) { + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + case 0x38: + case 0x39: + case 0x2B: + case 0x2D: + case 0x2E: + return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber()); + case 0x7B: + this.nextChar(); + return PostScriptToken.LBRACE; + case 0x7D: + this.nextChar(); + return PostScriptToken.RBRACE; + } + var strBuf = this.strBuf; + strBuf.length = 0; + strBuf[0] = String.fromCharCode(ch); + while ((ch = this.nextChar()) >= 0 && (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) { + strBuf.push(String.fromCharCode(ch)); + } + var str = strBuf.join(''); + switch (str.toLowerCase()) { + case 'if': + return PostScriptToken.IF; + case 'ifelse': + return PostScriptToken.IFELSE; + default: + return PostScriptToken.getOperator(str); + } + }, + getNumber: function PostScriptLexer_getNumber() { + var ch = this.currentChar; + var strBuf = this.strBuf; + strBuf.length = 0; + strBuf[0] = String.fromCharCode(ch); + while ((ch = this.nextChar()) >= 0) { + if (ch >= 0x30 && ch <= 0x39 || ch === 0x2D || ch === 0x2E) { + strBuf.push(String.fromCharCode(ch)); + } else { + break; + } + } + var value = parseFloat(strBuf.join('')); + if (isNaN(value)) { + error('Invalid floating point number: ' + value); + } + return value; + } + }; + return PostScriptLexer; + }(); + exports.PostScriptLexer = PostScriptLexer; + exports.PostScriptParser = PostScriptParser; + })); (function (root, factory) { factory(root.pdfjsCoreStream = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg, root.pdfjsCoreJpx); }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg, coreJpx) { @@ -33594,6 +33794,1001 @@ }(); exports.FontRendererFactory = FontRendererFactory; })); + (function (root, factory) { + factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser); + }(this, function (exports, sharedUtil, corePrimitives, corePsParser) { + var error = sharedUtil.error; + var info = sharedUtil.info; + var isArray = sharedUtil.isArray; + var isBool = sharedUtil.isBool; + var isDict = corePrimitives.isDict; + var isStream = corePrimitives.isStream; + var PostScriptLexer = corePsParser.PostScriptLexer; + var PostScriptParser = corePsParser.PostScriptParser; + var PDFFunction = function PDFFunctionClosure() { + var CONSTRUCT_SAMPLED = 0; + var CONSTRUCT_INTERPOLATED = 2; + var CONSTRUCT_STICHED = 3; + var CONSTRUCT_POSTSCRIPT = 4; + return { + getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) { + var i, ii; + var length = 1; + for (i = 0, ii = size.length; i < ii; i++) { + length *= size[i]; + } + length *= outputSize; + var array = new Array(length); + var codeSize = 0; + var codeBuf = 0; + var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1); + var strBytes = str.getBytes((length * bps + 7) / 8); + var strIdx = 0; + for (i = 0; i < length; i++) { + while (codeSize < bps) { + codeBuf <<= 8; + codeBuf |= strBytes[strIdx++]; + codeSize += 8; + } + codeSize -= bps; + array[i] = (codeBuf >> codeSize) * sampleMul; + codeBuf &= (1 << codeSize) - 1; + } + return array; + }, + getIR: function PDFFunction_getIR(xref, fn) { + var dict = fn.dict; + if (!dict) { + dict = fn; + } + var types = [ + this.constructSampled, + null, + this.constructInterpolated, + this.constructStiched, + this.constructPostScript + ]; + var typeNum = dict.get('FunctionType'); + var typeFn = types[typeNum]; + if (!typeFn) { + error('Unknown type of function'); + } + return typeFn.call(this, fn, dict, xref); + }, + fromIR: function PDFFunction_fromIR(IR) { + var type = IR[0]; + switch (type) { + case CONSTRUCT_SAMPLED: + return this.constructSampledFromIR(IR); + case CONSTRUCT_INTERPOLATED: + return this.constructInterpolatedFromIR(IR); + case CONSTRUCT_STICHED: + return this.constructStichedFromIR(IR); + default: + return this.constructPostScriptFromIR(IR); + } + }, + parse: function PDFFunction_parse(xref, fn) { + var IR = this.getIR(xref, fn); + return this.fromIR(IR); + }, + parseArray: function PDFFunction_parseArray(xref, fnObj) { + if (!isArray(fnObj)) { + return this.parse(xref, fnObj); + } + var fnArray = []; + for (var j = 0, jj = fnObj.length; j < jj; j++) { + var obj = xref.fetchIfRef(fnObj[j]); + fnArray.push(PDFFunction.parse(xref, obj)); + } + return function (src, srcOffset, dest, destOffset) { + for (var i = 0, ii = fnArray.length; i < ii; i++) { + fnArray[i](src, srcOffset, dest, destOffset + i); + } + }; + }, + constructSampled: function PDFFunction_constructSampled(str, dict) { + function toMultiArray(arr) { + var inputLength = arr.length; + var out = []; + var index = 0; + for (var i = 0; i < inputLength; i += 2) { + out[index] = [ + arr[i], + arr[i + 1] + ]; + ++index; + } + return out; + } + var domain = dict.getArray('Domain'); + var range = dict.getArray('Range'); + if (!domain || !range) { + error('No domain or range'); + } + var inputSize = domain.length / 2; + var outputSize = range.length / 2; + domain = toMultiArray(domain); + range = toMultiArray(range); + var size = dict.get('Size'); + var bps = dict.get('BitsPerSample'); + var order = dict.get('Order') || 1; + if (order !== 1) { + info('No support for cubic spline interpolation: ' + order); + } + var encode = dict.getArray('Encode'); + if (!encode) { + encode = []; + for (var i = 0; i < inputSize; ++i) { + encode.push(0); + encode.push(size[i] - 1); + } + } + encode = toMultiArray(encode); + var decode = dict.getArray('Decode'); + if (!decode) { + decode = range; + } else { + decode = toMultiArray(decode); + } + var samples = this.getSampleArray(size, outputSize, bps, str); + return [ + CONSTRUCT_SAMPLED, + inputSize, + domain, + encode, + decode, + samples, + size, + outputSize, + Math.pow(2, bps) - 1, + range + ]; + }, + constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) { + function interpolate(x, xmin, xmax, ymin, ymax) { + return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin)); + } + return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) { + var m = IR[1]; + var domain = IR[2]; + var encode = IR[3]; + var decode = IR[4]; + var samples = IR[5]; + var size = IR[6]; + var n = IR[7]; + var range = IR[9]; + var cubeVertices = 1 << m; + var cubeN = new Float64Array(cubeVertices); + var cubeVertex = new Uint32Array(cubeVertices); + var i, j; + for (j = 0; j < cubeVertices; j++) { + cubeN[j] = 1; + } + var k = n, pos = 1; + for (i = 0; i < m; ++i) { + var domain_2i = domain[i][0]; + var domain_2i_1 = domain[i][1]; + var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1); + var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]); + var size_i = size[i]; + e = Math.min(Math.max(e, 0), size_i - 1); + var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; + var n0 = e0 + 1 - e; + var n1 = e - e0; + var offset0 = e0 * k; + var offset1 = offset0 + k; + for (j = 0; j < cubeVertices; j++) { + if (j & pos) { + cubeN[j] *= n1; + cubeVertex[j] += offset1; + } else { + cubeN[j] *= n0; + cubeVertex[j] += offset0; + } + } + k *= size_i; + pos <<= 1; + } + for (j = 0; j < n; ++j) { + var rj = 0; + for (i = 0; i < cubeVertices; i++) { + rj += samples[cubeVertex[i] + j] * cubeN[i]; + } + rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]); + dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]); + } + }; + }, + constructInterpolated: function PDFFunction_constructInterpolated(str, dict) { + var c0 = dict.getArray('C0') || [0]; + var c1 = dict.getArray('C1') || [1]; + var n = dict.get('N'); + if (!isArray(c0) || !isArray(c1)) { + error('Illegal dictionary for interpolated function'); + } + var length = c0.length; + var diff = []; + for (var i = 0; i < length; ++i) { + diff.push(c1[i] - c0[i]); + } + return [ + CONSTRUCT_INTERPOLATED, + c0, + diff, + n + ]; + }, + constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) { + var c0 = IR[1]; + var diff = IR[2]; + var n = IR[3]; + var length = diff.length; + return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) { + var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n); + for (var j = 0; j < length; ++j) { + dest[destOffset + j] = c0[j] + x * diff[j]; + } + }; + }, + constructStiched: function PDFFunction_constructStiched(fn, dict, xref) { + var domain = dict.getArray('Domain'); + if (!domain) { + error('No domain'); + } + var inputSize = domain.length / 2; + if (inputSize !== 1) { + error('Bad domain for stiched function'); + } + var fnRefs = dict.get('Functions'); + var fns = []; + for (var i = 0, ii = fnRefs.length; i < ii; ++i) { + fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i]))); + } + var bounds = dict.getArray('Bounds'); + var encode = dict.getArray('Encode'); + return [ + CONSTRUCT_STICHED, + domain, + bounds, + encode, + fns + ]; + }, + constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) { + var domain = IR[1]; + var bounds = IR[2]; + var encode = IR[3]; + var fnsIR = IR[4]; + var fns = []; + var tmpBuf = new Float32Array(1); + for (var i = 0, ii = fnsIR.length; i < ii; i++) { + fns.push(PDFFunction.fromIR(fnsIR[i])); + } + return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) { + var clip = function constructStichedFromIRClip(v, min, max) { + if (v > max) { + v = max; + } else if (v < min) { + v = min; + } + return v; + }; + var v = clip(src[srcOffset], domain[0], domain[1]); + for (var i = 0, ii = bounds.length; i < ii; ++i) { + if (v < bounds[i]) { + break; + } + } + var dmin = domain[0]; + if (i > 0) { + dmin = bounds[i - 1]; + } + var dmax = domain[1]; + if (i < bounds.length) { + dmax = bounds[i]; + } + var rmin = encode[2 * i]; + var rmax = encode[2 * i + 1]; + tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin); + fns[i](tmpBuf, 0, dest, destOffset); + }; + }, + constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) { + var domain = dict.getArray('Domain'); + var range = dict.getArray('Range'); + if (!domain) { + error('No domain.'); + } + if (!range) { + error('No range.'); + } + var lexer = new PostScriptLexer(fn); + var parser = new PostScriptParser(lexer); + var code = parser.parse(); + return [ + CONSTRUCT_POSTSCRIPT, + domain, + range, + code + ]; + }, + constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) { + var domain = IR[1]; + var range = IR[2]; + var code = IR[3]; + var compiled = new PostScriptCompiler().compile(code, domain, range); + if (compiled) { + return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled); + } + info('Unable to compile PS function'); + var numOutputs = range.length >> 1; + var numInputs = domain.length >> 1; + var evaluator = new PostScriptEvaluator(code); + var cache = Object.create(null); + var MAX_CACHE_SIZE = 2048 * 4; + var cache_available = MAX_CACHE_SIZE; + var tmpBuf = new Float32Array(numInputs); + return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) { + var i, value; + var key = ''; + var input = tmpBuf; + for (i = 0; i < numInputs; i++) { + value = src[srcOffset + i]; + input[i] = value; + key += value + '_'; + } + var cachedValue = cache[key]; + if (cachedValue !== undefined) { + dest.set(cachedValue, destOffset); + return; + } + var output = new Float32Array(numOutputs); + var stack = evaluator.execute(input); + var stackIndex = stack.length - numOutputs; + for (i = 0; i < numOutputs; i++) { + value = stack[stackIndex + i]; + var bound = range[i * 2]; + if (value < bound) { + value = bound; + } else { + bound = range[i * 2 + 1]; + if (value > bound) { + value = bound; + } + } + output[i] = value; + } + if (cache_available > 0) { + cache_available--; + cache[key] = output; + } + dest.set(output, destOffset); + }; + } + }; + }(); + function isPDFFunction(v) { + var fnDict; + if (typeof v !== 'object') { + return false; + } else if (isDict(v)) { + fnDict = v; + } else if (isStream(v)) { + fnDict = v.dict; + } else { + return false; + } + return fnDict.has('FunctionType'); + } + var PostScriptStack = function PostScriptStackClosure() { + var MAX_STACK_SIZE = 100; + function PostScriptStack(initialStack) { + this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0); + } + PostScriptStack.prototype = { + push: function PostScriptStack_push(value) { + if (this.stack.length >= MAX_STACK_SIZE) { + error('PostScript function stack overflow.'); + } + this.stack.push(value); + }, + pop: function PostScriptStack_pop() { + if (this.stack.length <= 0) { + error('PostScript function stack underflow.'); + } + return this.stack.pop(); + }, + copy: function PostScriptStack_copy(n) { + if (this.stack.length + n >= MAX_STACK_SIZE) { + error('PostScript function stack overflow.'); + } + var stack = this.stack; + for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) { + stack.push(stack[i]); + } + }, + index: function PostScriptStack_index(n) { + this.push(this.stack[this.stack.length - n - 1]); + }, + roll: function PostScriptStack_roll(n, p) { + var stack = this.stack; + var l = stack.length - n; + var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t; + for (i = l, j = r; i < j; i++, j--) { + t = stack[i]; + stack[i] = stack[j]; + stack[j] = t; + } + for (i = l, j = c - 1; i < j; i++, j--) { + t = stack[i]; + stack[i] = stack[j]; + stack[j] = t; + } + for (i = c, j = r; i < j; i++, j--) { + t = stack[i]; + stack[i] = stack[j]; + stack[j] = t; + } + } + }; + return PostScriptStack; + }(); + var PostScriptEvaluator = function PostScriptEvaluatorClosure() { + function PostScriptEvaluator(operators) { + this.operators = operators; + } + PostScriptEvaluator.prototype = { + execute: function PostScriptEvaluator_execute(initialStack) { + var stack = new PostScriptStack(initialStack); + var counter = 0; + var operators = this.operators; + var length = operators.length; + var operator, a, b; + while (counter < length) { + operator = operators[counter++]; + if (typeof operator === 'number') { + stack.push(operator); + continue; + } + switch (operator) { + case 'jz': + b = stack.pop(); + a = stack.pop(); + if (!a) { + counter = b; + } + break; + case 'j': + a = stack.pop(); + counter = a; + break; + case 'abs': + a = stack.pop(); + stack.push(Math.abs(a)); + break; + case 'add': + b = stack.pop(); + a = stack.pop(); + stack.push(a + b); + break; + case 'and': + b = stack.pop(); + a = stack.pop(); + if (isBool(a) && isBool(b)) { + stack.push(a && b); + } else { + stack.push(a & b); + } + break; + case 'atan': + a = stack.pop(); + stack.push(Math.atan(a)); + break; + case 'bitshift': + b = stack.pop(); + a = stack.pop(); + if (a > 0) { + stack.push(a << b); + } else { + stack.push(a >> b); + } + break; + case 'ceiling': + a = stack.pop(); + stack.push(Math.ceil(a)); + break; + case 'copy': + a = stack.pop(); + stack.copy(a); + break; + case 'cos': + a = stack.pop(); + stack.push(Math.cos(a)); + break; + case 'cvi': + a = stack.pop() | 0; + stack.push(a); + break; + case 'cvr': + break; + case 'div': + b = stack.pop(); + a = stack.pop(); + stack.push(a / b); + break; + case 'dup': + stack.copy(1); + break; + case 'eq': + b = stack.pop(); + a = stack.pop(); + stack.push(a === b); + break; + case 'exch': + stack.roll(2, 1); + break; + case 'exp': + b = stack.pop(); + a = stack.pop(); + stack.push(Math.pow(a, b)); + break; + case 'false': + stack.push(false); + break; + case 'floor': + a = stack.pop(); + stack.push(Math.floor(a)); + break; + case 'ge': + b = stack.pop(); + a = stack.pop(); + stack.push(a >= b); + break; + case 'gt': + b = stack.pop(); + a = stack.pop(); + stack.push(a > b); + break; + case 'idiv': + b = stack.pop(); + a = stack.pop(); + stack.push(a / b | 0); + break; + case 'index': + a = stack.pop(); + stack.index(a); + break; + case 'le': + b = stack.pop(); + a = stack.pop(); + stack.push(a <= b); + break; + case 'ln': + a = stack.pop(); + stack.push(Math.log(a)); + break; + case 'log': + a = stack.pop(); + stack.push(Math.log(a) / Math.LN10); + break; + case 'lt': + b = stack.pop(); + a = stack.pop(); + stack.push(a < b); + break; + case 'mod': + b = stack.pop(); + a = stack.pop(); + stack.push(a % b); + break; + case 'mul': + b = stack.pop(); + a = stack.pop(); + stack.push(a * b); + break; + case 'ne': + b = stack.pop(); + a = stack.pop(); + stack.push(a !== b); + break; + case 'neg': + a = stack.pop(); + stack.push(-a); + break; + case 'not': + a = stack.pop(); + if (isBool(a)) { + stack.push(!a); + } else { + stack.push(~a); + } + break; + case 'or': + b = stack.pop(); + a = stack.pop(); + if (isBool(a) && isBool(b)) { + stack.push(a || b); + } else { + stack.push(a | b); + } + break; + case 'pop': + stack.pop(); + break; + case 'roll': + b = stack.pop(); + a = stack.pop(); + stack.roll(a, b); + break; + case 'round': + a = stack.pop(); + stack.push(Math.round(a)); + break; + case 'sin': + a = stack.pop(); + stack.push(Math.sin(a)); + break; + case 'sqrt': + a = stack.pop(); + stack.push(Math.sqrt(a)); + break; + case 'sub': + b = stack.pop(); + a = stack.pop(); + stack.push(a - b); + break; + case 'true': + stack.push(true); + break; + case 'truncate': + a = stack.pop(); + a = a < 0 ? Math.ceil(a) : Math.floor(a); + stack.push(a); + break; + case 'xor': + b = stack.pop(); + a = stack.pop(); + if (isBool(a) && isBool(b)) { + stack.push(a !== b); + } else { + stack.push(a ^ b); + } + break; + default: + error('Unknown operator ' + operator); + break; + } + } + return stack.stack; + } + }; + return PostScriptEvaluator; + }(); + var PostScriptCompiler = function PostScriptCompilerClosure() { + function AstNode(type) { + this.type = type; + } + AstNode.prototype.visit = function (visitor) { + throw new Error('abstract method'); + }; + function AstArgument(index, min, max) { + AstNode.call(this, 'args'); + this.index = index; + this.min = min; + this.max = max; + } + AstArgument.prototype = Object.create(AstNode.prototype); + AstArgument.prototype.visit = function (visitor) { + visitor.visitArgument(this); + }; + function AstLiteral(number) { + AstNode.call(this, 'literal'); + this.number = number; + this.min = number; + this.max = number; + } + AstLiteral.prototype = Object.create(AstNode.prototype); + AstLiteral.prototype.visit = function (visitor) { + visitor.visitLiteral(this); + }; + function AstBinaryOperation(op, arg1, arg2, min, max) { + AstNode.call(this, 'binary'); + this.op = op; + this.arg1 = arg1; + this.arg2 = arg2; + this.min = min; + this.max = max; + } + AstBinaryOperation.prototype = Object.create(AstNode.prototype); + AstBinaryOperation.prototype.visit = function (visitor) { + visitor.visitBinaryOperation(this); + }; + function AstMin(arg, max) { + AstNode.call(this, 'max'); + this.arg = arg; + this.min = arg.min; + this.max = max; + } + AstMin.prototype = Object.create(AstNode.prototype); + AstMin.prototype.visit = function (visitor) { + visitor.visitMin(this); + }; + function AstVariable(index, min, max) { + AstNode.call(this, 'var'); + this.index = index; + this.min = min; + this.max = max; + } + AstVariable.prototype = Object.create(AstNode.prototype); + AstVariable.prototype.visit = function (visitor) { + visitor.visitVariable(this); + }; + function AstVariableDefinition(variable, arg) { + AstNode.call(this, 'definition'); + this.variable = variable; + this.arg = arg; + } + AstVariableDefinition.prototype = Object.create(AstNode.prototype); + AstVariableDefinition.prototype.visit = function (visitor) { + visitor.visitVariableDefinition(this); + }; + function ExpressionBuilderVisitor() { + this.parts = []; + } + ExpressionBuilderVisitor.prototype = { + visitArgument: function (arg) { + this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))'); + }, + visitVariable: function (variable) { + this.parts.push('v', variable.index); + }, + visitLiteral: function (literal) { + this.parts.push(literal.number); + }, + visitBinaryOperation: function (operation) { + this.parts.push('('); + operation.arg1.visit(this); + this.parts.push(' ', operation.op, ' '); + operation.arg2.visit(this); + this.parts.push(')'); + }, + visitVariableDefinition: function (definition) { + this.parts.push('var '); + definition.variable.visit(this); + this.parts.push(' = '); + definition.arg.visit(this); + this.parts.push(';'); + }, + visitMin: function (max) { + this.parts.push('Math.min('); + max.arg.visit(this); + this.parts.push(', ', max.max, ')'); + }, + toString: function () { + return this.parts.join(''); + } + }; + function buildAddOperation(num1, num2) { + if (num2.type === 'literal' && num2.number === 0) { + return num1; + } + if (num1.type === 'literal' && num1.number === 0) { + return num2; + } + if (num2.type === 'literal' && num1.type === 'literal') { + return new AstLiteral(num1.number + num2.number); + } + return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max); + } + function buildMulOperation(num1, num2) { + if (num2.type === 'literal') { + if (num2.number === 0) { + return new AstLiteral(0); + } else if (num2.number === 1) { + return num1; + } else if (num1.type === 'literal') { + return new AstLiteral(num1.number * num2.number); + } + } + if (num1.type === 'literal') { + if (num1.number === 0) { + return new AstLiteral(0); + } else if (num1.number === 1) { + return num2; + } + } + var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max); + var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max); + return new AstBinaryOperation('*', num1, num2, min, max); + } + function buildSubOperation(num1, num2) { + if (num2.type === 'literal') { + if (num2.number === 0) { + return num1; + } else if (num1.type === 'literal') { + return new AstLiteral(num1.number - num2.number); + } + } + if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) { + return num2.arg2; + } + return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min); + } + function buildMinOperation(num1, max) { + if (num1.min >= max) { + return new AstLiteral(max); + } else if (num1.max <= max) { + return num1; + } + return new AstMin(num1, max); + } + function PostScriptCompiler() { + } + PostScriptCompiler.prototype = { + compile: function PostScriptCompiler_compile(code, domain, range) { + var stack = []; + var i, ii; + var instructions = []; + var inputSize = domain.length >> 1, outputSize = range.length >> 1; + var lastRegister = 0; + var n, j; + var num1, num2, ast1, ast2, tmpVar, item; + for (i = 0; i < inputSize; i++) { + stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1])); + } + for (i = 0, ii = code.length; i < ii; i++) { + item = code[i]; + if (typeof item === 'number') { + stack.push(new AstLiteral(item)); + continue; + } + switch (item) { + case 'add': + if (stack.length < 2) { + return null; + } + num2 = stack.pop(); + num1 = stack.pop(); + stack.push(buildAddOperation(num1, num2)); + break; + case 'cvr': + if (stack.length < 1) { + return null; + } + break; + case 'mul': + if (stack.length < 2) { + return null; + } + num2 = stack.pop(); + num1 = stack.pop(); + stack.push(buildMulOperation(num1, num2)); + break; + case 'sub': + if (stack.length < 2) { + return null; + } + num2 = stack.pop(); + num1 = stack.pop(); + stack.push(buildSubOperation(num1, num2)); + break; + case 'exch': + if (stack.length < 2) { + return null; + } + ast1 = stack.pop(); + ast2 = stack.pop(); + stack.push(ast1, ast2); + break; + case 'pop': + if (stack.length < 1) { + return null; + } + stack.pop(); + break; + case 'index': + if (stack.length < 1) { + return null; + } + num1 = stack.pop(); + if (num1.type !== 'literal') { + return null; + } + n = num1.number; + if (n < 0 || (n | 0) !== n || stack.length < n) { + return null; + } + ast1 = stack[stack.length - n - 1]; + if (ast1.type === 'literal' || ast1.type === 'var') { + stack.push(ast1); + break; + } + tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max); + stack[stack.length - n - 1] = tmpVar; + stack.push(tmpVar); + instructions.push(new AstVariableDefinition(tmpVar, ast1)); + break; + case 'dup': + if (stack.length < 1) { + return null; + } + if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' && code[i + 3] === i + 7 && code[i + 4] === 'jz' && code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) { + num1 = stack.pop(); + stack.push(buildMinOperation(num1, code[i + 1])); + i += 6; + break; + } + ast1 = stack[stack.length - 1]; + if (ast1.type === 'literal' || ast1.type === 'var') { + stack.push(ast1); + break; + } + tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max); + stack[stack.length - 1] = tmpVar; + stack.push(tmpVar); + instructions.push(new AstVariableDefinition(tmpVar, ast1)); + break; + case 'roll': + if (stack.length < 2) { + return null; + } + num2 = stack.pop(); + num1 = stack.pop(); + if (num2.type !== 'literal' || num1.type !== 'literal') { + return null; + } + j = num2.number; + n = num1.number; + if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) { + return null; + } + j = (j % n + n) % n; + if (j === 0) { + break; + } + Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j)); + break; + default: + return null; + } + } + if (stack.length !== outputSize) { + return null; + } + var result = []; + instructions.forEach(function (instruction) { + var statementBuilder = new ExpressionBuilderVisitor(); + instruction.visit(statementBuilder); + result.push(statementBuilder.toString()); + }); + stack.forEach(function (expr, i) { + var statementBuilder = new ExpressionBuilderVisitor(); + expr.visit(statementBuilder); + var min = range[i * 2], max = range[i * 2 + 1]; + var out = [statementBuilder.toString()]; + if (min > expr.min) { + out.unshift('Math.max(', min, ', '); + out.push(')'); + } + if (max < expr.max) { + out.unshift('Math.min(', max, ', '); + out.push(')'); + } + out.unshift('dest[destOffset + ', i, '] = '); + out.push(';'); + result.push(out.join('')); + }); + return result.join('\n'); + } + }; + return PostScriptCompiler; + }(); + exports.isPDFFunction = isPDFFunction; + exports.PDFFunction = PDFFunction; + exports.PostScriptEvaluator = PostScriptEvaluator; + exports.PostScriptCompiler = PostScriptCompiler; + })); (function (root, factory) { factory(root.pdfjsCoreParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream); }(this, function (exports, sharedUtil, corePrimitives, coreStream) { @@ -33607,10 +34802,12 @@ var isNum = sharedUtil.isNum; var isString = sharedUtil.isString; var warn = sharedUtil.warn; + var EOF = corePrimitives.EOF; var Cmd = corePrimitives.Cmd; var Dict = corePrimitives.Dict; var Name = corePrimitives.Name; var Ref = corePrimitives.Ref; + var isEOF = corePrimitives.isEOF; var isCmd = corePrimitives.isCmd; var isDict = corePrimitives.isDict; var isName = corePrimitives.isName; @@ -33625,10 +34822,6 @@ var NullStream = coreStream.NullStream; var PredictorStream = coreStream.PredictorStream; var RunLengthStream = coreStream.RunLengthStream; - var EOF = {}; - function isEOF(v) { - return v === EOF; - } var MAX_LENGTH_TO_CACHE = 1000; var Parser = function ParserClosure() { function Parser(lexer, allowStreams, xref, recoveryMode) { @@ -34799,11 +35992,9 @@ }; } }; - exports.EOF = EOF; exports.Lexer = Lexer; exports.Linearization = Linearization; exports.Parser = Parser; - exports.isEOF = isEOF; })); (function (root, factory) { factory(root.pdfjsCoreType1Parser = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreEncodings); @@ -35355,12 +36546,12 @@ var isInt = sharedUtil.isInt; var isString = sharedUtil.isString; var MissingDataException = sharedUtil.MissingDataException; + var isEOF = corePrimitives.isEOF; var isName = corePrimitives.isName; var isCmd = corePrimitives.isCmd; var isStream = corePrimitives.isStream; var StringStream = coreStream.StringStream; var Lexer = coreParser.Lexer; - var isEOF = coreParser.isEOF; var BUILT_IN_CMAPS = [ 'Adobe-GB1-UCS2', 'Adobe-CNS1-UCS2', @@ -36243,6 +37434,1022 @@ exports.CMapFactory = CMapFactory; exports.IdentityCMap = IdentityCMap; })); + (function (root, factory) { + factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction); + }(this, function (exports, sharedUtil, corePrimitives, coreFunction) { + var error = sharedUtil.error; + var info = sharedUtil.info; + var isArray = sharedUtil.isArray; + var isString = sharedUtil.isString; + var shadow = sharedUtil.shadow; + var warn = sharedUtil.warn; + var isDict = corePrimitives.isDict; + var isName = corePrimitives.isName; + var isStream = corePrimitives.isStream; + var PDFFunction = coreFunction.PDFFunction; + var ColorSpace = function ColorSpaceClosure() { + function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) { + var COMPONENTS = 3; + alpha01 = alpha01 !== 1 ? 0 : alpha01; + var xRatio = w1 / w2; + var yRatio = h1 / h2; + var i, j, py, newIndex = 0, oldIndex; + var xScaled = new Uint16Array(w2); + var w1Scanline = w1 * COMPONENTS; + for (i = 0; i < w2; i++) { + xScaled[i] = Math.floor(i * xRatio) * COMPONENTS; + } + for (i = 0; i < h2; i++) { + py = Math.floor(i * yRatio) * w1Scanline; + for (j = 0; j < w2; j++) { + oldIndex = py + xScaled[j]; + dest[newIndex++] = src[oldIndex++]; + dest[newIndex++] = src[oldIndex++]; + dest[newIndex++] = src[oldIndex++]; + newIndex += alpha01; + } + } + } + function ColorSpace() { + error('should not call ColorSpace constructor'); + } + ColorSpace.prototype = { + getRgb: function ColorSpace_getRgb(src, srcOffset) { + var rgb = new Uint8Array(3); + this.getRgbItem(src, srcOffset, rgb, 0); + return rgb; + }, + getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) { + error('Should not call ColorSpace.getRgbItem'); + }, + getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + error('Should not call ColorSpace.getRgbBuffer'); + }, + getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) { + error('Should not call ColorSpace.getOutputLength'); + }, + isPassthrough: function ColorSpace_isPassthrough(bits) { + return false; + }, + fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) { + var count = originalWidth * originalHeight; + var rgbBuf = null; + var numComponentColors = 1 << bpc; + var needsResizing = originalHeight !== height || originalWidth !== width; + var i, ii; + if (this.isPassthrough(bpc)) { + rgbBuf = comps; + } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') { + var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors); + var key; + for (i = 0; i < numComponentColors; i++) { + allColors[i] = i; + } + var colorMap = new Uint8Array(numComponentColors * 3); + this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, 0); + var destPos, rgbPos; + if (!needsResizing) { + destPos = 0; + for (i = 0; i < count; ++i) { + key = comps[i] * 3; + dest[destPos++] = colorMap[key]; + dest[destPos++] = colorMap[key + 1]; + dest[destPos++] = colorMap[key + 2]; + destPos += alpha01; + } + } else { + rgbBuf = new Uint8Array(count * 3); + rgbPos = 0; + for (i = 0; i < count; ++i) { + key = comps[i] * 3; + rgbBuf[rgbPos++] = colorMap[key]; + rgbBuf[rgbPos++] = colorMap[key + 1]; + rgbBuf[rgbPos++] = colorMap[key + 2]; + } + } + } else { + if (!needsResizing) { + this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01); + } else { + rgbBuf = new Uint8Array(count * 3); + this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, 0); + } + } + if (rgbBuf) { + if (needsResizing) { + resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest); + } else { + rgbPos = 0; + destPos = 0; + for (i = 0, ii = width * actualHeight; i < ii; i++) { + dest[destPos++] = rgbBuf[rgbPos++]; + dest[destPos++] = rgbBuf[rgbPos++]; + dest[destPos++] = rgbBuf[rgbPos++]; + destPos += alpha01; + } + } + } + }, + usesZeroToOneRange: true + }; + ColorSpace.parse = function ColorSpace_parse(cs, xref, res) { + var IR = ColorSpace.parseToIR(cs, xref, res); + if (IR instanceof AlternateCS) { + return IR; + } + return ColorSpace.fromIR(IR); + }; + ColorSpace.fromIR = function ColorSpace_fromIR(IR) { + var name = isArray(IR) ? IR[0] : IR; + var whitePoint, blackPoint, gamma; + switch (name) { + case 'DeviceGrayCS': + return this.singletons.gray; + case 'DeviceRgbCS': + return this.singletons.rgb; + case 'DeviceCmykCS': + return this.singletons.cmyk; + case 'CalGrayCS': + whitePoint = IR[1]; + blackPoint = IR[2]; + gamma = IR[3]; + return new CalGrayCS(whitePoint, blackPoint, gamma); + case 'CalRGBCS': + whitePoint = IR[1]; + blackPoint = IR[2]; + gamma = IR[3]; + var matrix = IR[4]; + return new CalRGBCS(whitePoint, blackPoint, gamma, matrix); + case 'PatternCS': + var basePatternCS = IR[1]; + if (basePatternCS) { + basePatternCS = ColorSpace.fromIR(basePatternCS); + } + return new PatternCS(basePatternCS); + case 'IndexedCS': + var baseIndexedCS = IR[1]; + var hiVal = IR[2]; + var lookup = IR[3]; + return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup); + case 'AlternateCS': + var numComps = IR[1]; + var alt = IR[2]; + var tintFnIR = IR[3]; + return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR)); + case 'LabCS': + whitePoint = IR[1]; + blackPoint = IR[2]; + var range = IR[3]; + return new LabCS(whitePoint, blackPoint, range); + default: + error('Unknown name ' + name); + } + return null; + }; + ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) { + if (isName(cs)) { + var colorSpaces = res.get('ColorSpace'); + if (isDict(colorSpaces)) { + var refcs = colorSpaces.get(cs.name); + if (refcs) { + cs = refcs; + } + } + } + cs = xref.fetchIfRef(cs); + if (isName(cs)) { + switch (cs.name) { + case 'DeviceGray': + case 'G': + return 'DeviceGrayCS'; + case 'DeviceRGB': + case 'RGB': + return 'DeviceRgbCS'; + case 'DeviceCMYK': + case 'CMYK': + return 'DeviceCmykCS'; + case 'Pattern': + return [ + 'PatternCS', + null + ]; + default: + error('unrecognized colorspace ' + cs.name); + } + } else if (isArray(cs)) { + var mode = xref.fetchIfRef(cs[0]).name; + var numComps, params, alt, whitePoint, blackPoint, gamma; + switch (mode) { + case 'DeviceGray': + case 'G': + return 'DeviceGrayCS'; + case 'DeviceRGB': + case 'RGB': + return 'DeviceRgbCS'; + case 'DeviceCMYK': + case 'CMYK': + return 'DeviceCmykCS'; + case 'CalGray': + params = xref.fetchIfRef(cs[1]); + whitePoint = params.getArray('WhitePoint'); + blackPoint = params.getArray('BlackPoint'); + gamma = params.get('Gamma'); + return [ + 'CalGrayCS', + whitePoint, + blackPoint, + gamma + ]; + case 'CalRGB': + params = xref.fetchIfRef(cs[1]); + whitePoint = params.getArray('WhitePoint'); + blackPoint = params.getArray('BlackPoint'); + gamma = params.getArray('Gamma'); + var matrix = params.getArray('Matrix'); + return [ + 'CalRGBCS', + whitePoint, + blackPoint, + gamma, + matrix + ]; + case 'ICCBased': + var stream = xref.fetchIfRef(cs[1]); + var dict = stream.dict; + numComps = dict.get('N'); + alt = dict.get('Alternate'); + if (alt) { + var altIR = ColorSpace.parseToIR(alt, xref, res); + var altCS = ColorSpace.fromIR(altIR); + if (altCS.numComps === numComps) { + return altIR; + } + warn('ICCBased color space: Ignoring incorrect /Alternate entry.'); + } + if (numComps === 1) { + return 'DeviceGrayCS'; + } else if (numComps === 3) { + return 'DeviceRgbCS'; + } else if (numComps === 4) { + return 'DeviceCmykCS'; + } + break; + case 'Pattern': + var basePatternCS = cs[1] || null; + if (basePatternCS) { + basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res); + } + return [ + 'PatternCS', + basePatternCS + ]; + case 'Indexed': + case 'I': + var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res); + var hiVal = xref.fetchIfRef(cs[2]) + 1; + var lookup = xref.fetchIfRef(cs[3]); + if (isStream(lookup)) { + lookup = lookup.getBytes(); + } + return [ + 'IndexedCS', + baseIndexedCS, + hiVal, + lookup + ]; + case 'Separation': + case 'DeviceN': + var name = xref.fetchIfRef(cs[1]); + numComps = isArray(name) ? name.length : 1; + alt = ColorSpace.parseToIR(cs[2], xref, res); + var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3])); + return [ + 'AlternateCS', + numComps, + alt, + tintFnIR + ]; + case 'Lab': + params = xref.fetchIfRef(cs[1]); + whitePoint = params.getArray('WhitePoint'); + blackPoint = params.getArray('BlackPoint'); + var range = params.getArray('Range'); + return [ + 'LabCS', + whitePoint, + blackPoint, + range + ]; + default: + error('unimplemented color space object "' + mode + '"'); + } + } else { + error('unrecognized color space object: "' + cs + '"'); + } + return null; + }; + ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) { + if (!isArray(decode)) { + return true; + } + if (n * 2 !== decode.length) { + warn('The decode map is not the correct length'); + return true; + } + for (var i = 0, ii = decode.length; i < ii; i += 2) { + if (decode[i] !== 0 || decode[i + 1] !== 1) { + return false; + } + } + return true; + }; + ColorSpace.singletons = { + get gray() { + return shadow(this, 'gray', new DeviceGrayCS()); + }, + get rgb() { + return shadow(this, 'rgb', new DeviceRgbCS()); + }, + get cmyk() { + return shadow(this, 'cmyk', new DeviceCmykCS()); + } + }; + return ColorSpace; + }(); + var AlternateCS = function AlternateCSClosure() { + function AlternateCS(numComps, base, tintFn) { + this.name = 'Alternate'; + this.numComps = numComps; + this.defaultColor = new Float32Array(numComps); + for (var i = 0; i < numComps; ++i) { + this.defaultColor[i] = 1; + } + this.base = base; + this.tintFn = tintFn; + this.tmpBuf = new Float32Array(base.numComps); + } + AlternateCS.prototype = { + getRgb: ColorSpace.prototype.getRgb, + getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) { + var tmpBuf = this.tmpBuf; + this.tintFn(src, srcOffset, tmpBuf, 0); + this.base.getRgbItem(tmpBuf, 0, dest, destOffset); + }, + getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + var tintFn = this.tintFn; + var base = this.base; + var scale = 1 / ((1 << bits) - 1); + var baseNumComps = base.numComps; + var usesZeroToOneRange = base.usesZeroToOneRange; + var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0; + var pos = isPassthrough ? destOffset : 0; + var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count); + var numComps = this.numComps; + var scaled = new Float32Array(numComps); + var tinted = new Float32Array(baseNumComps); + var i, j; + for (i = 0; i < count; i++) { + for (j = 0; j < numComps; j++) { + scaled[j] = src[srcOffset++] * scale; + } + tintFn(scaled, 0, tinted, 0); + if (usesZeroToOneRange) { + for (j = 0; j < baseNumComps; j++) { + baseBuf[pos++] = tinted[j] * 255; + } + } else { + base.getRgbItem(tinted, 0, baseBuf, pos); + pos += baseNumComps; + } + } + if (!isPassthrough) { + base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01); + } + }, + getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) { + return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01); + }, + isPassthrough: ColorSpace.prototype.isPassthrough, + fillRgb: ColorSpace.prototype.fillRgb, + isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) { + return ColorSpace.isDefaultDecode(decodeMap, this.numComps); + }, + usesZeroToOneRange: true + }; + return AlternateCS; + }(); + var PatternCS = function PatternCSClosure() { + function PatternCS(baseCS) { + this.name = 'Pattern'; + this.base = baseCS; + } + PatternCS.prototype = {}; + return PatternCS; + }(); + var IndexedCS = function IndexedCSClosure() { + function IndexedCS(base, highVal, lookup) { + this.name = 'Indexed'; + this.numComps = 1; + this.defaultColor = new Uint8Array(this.numComps); + this.base = base; + this.highVal = highVal; + var baseNumComps = base.numComps; + var length = baseNumComps * highVal; + if (isStream(lookup)) { + this.lookup = new Uint8Array(length); + var bytes = lookup.getBytes(length); + this.lookup.set(bytes); + } else if (isString(lookup)) { + this.lookup = new Uint8Array(length); + for (var i = 0; i < length; ++i) { + this.lookup[i] = lookup.charCodeAt(i); + } + } else if (lookup instanceof Uint8Array || lookup instanceof Array) { + this.lookup = lookup; + } else { + error('Unrecognized lookup table: ' + lookup); + } + } + IndexedCS.prototype = { + getRgb: ColorSpace.prototype.getRgb, + getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) { + var numComps = this.base.numComps; + var start = src[srcOffset] * numComps; + this.base.getRgbItem(this.lookup, start, dest, destOffset); + }, + getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + var base = this.base; + var numComps = base.numComps; + var outputDelta = base.getOutputLength(numComps, alpha01); + var lookup = this.lookup; + for (var i = 0; i < count; ++i) { + var lookupPos = src[srcOffset++] * numComps; + base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01); + destOffset += outputDelta; + } + }, + getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) { + return this.base.getOutputLength(inputLength * this.base.numComps, alpha01); + }, + isPassthrough: ColorSpace.prototype.isPassthrough, + fillRgb: ColorSpace.prototype.fillRgb, + isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) { + return true; + }, + usesZeroToOneRange: true + }; + return IndexedCS; + }(); + var DeviceGrayCS = function DeviceGrayCSClosure() { + function DeviceGrayCS() { + this.name = 'DeviceGray'; + this.numComps = 1; + this.defaultColor = new Float32Array(this.numComps); + } + DeviceGrayCS.prototype = { + getRgb: ColorSpace.prototype.getRgb, + getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) { + var c = src[srcOffset] * 255 | 0; + c = c < 0 ? 0 : c > 255 ? 255 : c; + dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c; + }, + getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + var scale = 255 / ((1 << bits) - 1); + var j = srcOffset, q = destOffset; + for (var i = 0; i < count; ++i) { + var c = scale * src[j++] | 0; + dest[q++] = c; + dest[q++] = c; + dest[q++] = c; + q += alpha01; + } + }, + getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) { + return inputLength * (3 + alpha01); + }, + isPassthrough: ColorSpace.prototype.isPassthrough, + fillRgb: ColorSpace.prototype.fillRgb, + isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) { + return ColorSpace.isDefaultDecode(decodeMap, this.numComps); + }, + usesZeroToOneRange: true + }; + return DeviceGrayCS; + }(); + var DeviceRgbCS = function DeviceRgbCSClosure() { + function DeviceRgbCS() { + this.name = 'DeviceRGB'; + this.numComps = 3; + this.defaultColor = new Float32Array(this.numComps); + } + DeviceRgbCS.prototype = { + getRgb: ColorSpace.prototype.getRgb, + getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) { + var r = src[srcOffset] * 255 | 0; + var g = src[srcOffset + 1] * 255 | 0; + var b = src[srcOffset + 2] * 255 | 0; + dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r; + dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g; + dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b; + }, + getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + if (bits === 8 && alpha01 === 0) { + dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset); + return; + } + var scale = 255 / ((1 << bits) - 1); + var j = srcOffset, q = destOffset; + for (var i = 0; i < count; ++i) { + dest[q++] = scale * src[j++] | 0; + dest[q++] = scale * src[j++] | 0; + dest[q++] = scale * src[j++] | 0; + q += alpha01; + } + }, + getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) { + return inputLength * (3 + alpha01) / 3 | 0; + }, + isPassthrough: function DeviceRgbCS_isPassthrough(bits) { + return bits === 8; + }, + fillRgb: ColorSpace.prototype.fillRgb, + isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) { + return ColorSpace.isDefaultDecode(decodeMap, this.numComps); + }, + usesZeroToOneRange: true + }; + return DeviceRgbCS; + }(); + var DeviceCmykCS = function DeviceCmykCSClosure() { + function convertToRgb(src, srcOffset, srcScale, dest, destOffset) { + var c = src[srcOffset + 0] * srcScale; + var m = src[srcOffset + 1] * srcScale; + var y = src[srcOffset + 2] * srcScale; + var k = src[srcOffset + 3] * srcScale; + var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747) + 255 | 0; + var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578) + 255 | 0; + var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367) + 255 | 0; + dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r; + dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g; + dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b; + } + function DeviceCmykCS() { + this.name = 'DeviceCMYK'; + this.numComps = 4; + this.defaultColor = new Float32Array(this.numComps); + this.defaultColor[3] = 1; + } + DeviceCmykCS.prototype = { + getRgb: ColorSpace.prototype.getRgb, + getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) { + convertToRgb(src, srcOffset, 1, dest, destOffset); + }, + getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + var scale = 1 / ((1 << bits) - 1); + for (var i = 0; i < count; i++) { + convertToRgb(src, srcOffset, scale, dest, destOffset); + srcOffset += 4; + destOffset += 3 + alpha01; + } + }, + getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) { + return inputLength / 4 * (3 + alpha01) | 0; + }, + isPassthrough: ColorSpace.prototype.isPassthrough, + fillRgb: ColorSpace.prototype.fillRgb, + isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) { + return ColorSpace.isDefaultDecode(decodeMap, this.numComps); + }, + usesZeroToOneRange: true + }; + return DeviceCmykCS; + }(); + var CalGrayCS = function CalGrayCSClosure() { + function CalGrayCS(whitePoint, blackPoint, gamma) { + this.name = 'CalGray'; + this.numComps = 1; + this.defaultColor = new Float32Array(this.numComps); + if (!whitePoint) { + error('WhitePoint missing - required for color space CalGray'); + } + blackPoint = blackPoint || [ + 0, + 0, + 0 + ]; + gamma = gamma || 1; + this.XW = whitePoint[0]; + this.YW = whitePoint[1]; + this.ZW = whitePoint[2]; + this.XB = blackPoint[0]; + this.YB = blackPoint[1]; + this.ZB = blackPoint[2]; + this.G = gamma; + if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) { + error('Invalid WhitePoint components for ' + this.name + ', no fallback available'); + } + if (this.XB < 0 || this.YB < 0 || this.ZB < 0) { + info('Invalid BlackPoint for ' + this.name + ', falling back to default'); + this.XB = this.YB = this.ZB = 0; + } + if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) { + warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.'); + } + if (this.G < 1) { + info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default'); + this.G = 1; + } + } + function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) { + var A = src[srcOffset] * scale; + var AG = Math.pow(A, cs.G); + var L = cs.YW * AG; + var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0; + dest[destOffset] = val; + dest[destOffset + 1] = val; + dest[destOffset + 2] = val; + } + CalGrayCS.prototype = { + getRgb: ColorSpace.prototype.getRgb, + getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) { + convertToRgb(this, src, srcOffset, dest, destOffset, 1); + }, + getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + var scale = 1 / ((1 << bits) - 1); + for (var i = 0; i < count; ++i) { + convertToRgb(this, src, srcOffset, dest, destOffset, scale); + srcOffset += 1; + destOffset += 3 + alpha01; + } + }, + getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) { + return inputLength * (3 + alpha01); + }, + isPassthrough: ColorSpace.prototype.isPassthrough, + fillRgb: ColorSpace.prototype.fillRgb, + isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) { + return ColorSpace.isDefaultDecode(decodeMap, this.numComps); + }, + usesZeroToOneRange: true + }; + return CalGrayCS; + }(); + var CalRGBCS = function CalRGBCSClosure() { + var BRADFORD_SCALE_MATRIX = new Float32Array([ + 0.8951, + 0.2664, + -0.1614, + -0.7502, + 1.7135, + 0.0367, + 0.0389, + -0.0685, + 1.0296 + ]); + var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([ + 0.9869929, + -0.1470543, + 0.1599627, + 0.4323053, + 0.5183603, + 0.0492912, + -0.0085287, + 0.0400428, + 0.9684867 + ]); + var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([ + 3.2404542, + -1.5371385, + -0.4985314, + -0.9692660, + 1.8760108, + 0.0415560, + 0.0556434, + -0.2040259, + 1.0572252 + ]); + var FLAT_WHITEPOINT_MATRIX = new Float32Array([ + 1, + 1, + 1 + ]); + var tempNormalizeMatrix = new Float32Array(3); + var tempConvertMatrix1 = new Float32Array(3); + var tempConvertMatrix2 = new Float32Array(3); + var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0; + function CalRGBCS(whitePoint, blackPoint, gamma, matrix) { + this.name = 'CalRGB'; + this.numComps = 3; + this.defaultColor = new Float32Array(this.numComps); + if (!whitePoint) { + error('WhitePoint missing - required for color space CalRGB'); + } + blackPoint = blackPoint || new Float32Array(3); + gamma = gamma || new Float32Array([ + 1, + 1, + 1 + ]); + matrix = matrix || new Float32Array([ + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 1 + ]); + var XW = whitePoint[0]; + var YW = whitePoint[1]; + var ZW = whitePoint[2]; + this.whitePoint = whitePoint; + var XB = blackPoint[0]; + var YB = blackPoint[1]; + var ZB = blackPoint[2]; + this.blackPoint = blackPoint; + this.GR = gamma[0]; + this.GG = gamma[1]; + this.GB = gamma[2]; + this.MXA = matrix[0]; + this.MYA = matrix[1]; + this.MZA = matrix[2]; + this.MXB = matrix[3]; + this.MYB = matrix[4]; + this.MZB = matrix[5]; + this.MXC = matrix[6]; + this.MYC = matrix[7]; + this.MZC = matrix[8]; + if (XW < 0 || ZW < 0 || YW !== 1) { + error('Invalid WhitePoint components for ' + this.name + ', no fallback available'); + } + if (XB < 0 || YB < 0 || ZB < 0) { + info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default'); + this.blackPoint = new Float32Array(3); + } + if (this.GR < 0 || this.GG < 0 || this.GB < 0) { + info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default'); + this.GR = this.GG = this.GB = 1; + } + if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 || this.MXB < 0 || this.MYB < 0 || this.MZB < 0 || this.MXC < 0 || this.MYC < 0 || this.MZC < 0) { + info('Invalid Matrix for ' + this.name + ' [' + this.MXA + ', ' + this.MYA + ', ' + this.MZA + this.MXB + ', ' + this.MYB + ', ' + this.MZB + this.MXC + ', ' + this.MYC + ', ' + this.MZC + '], falling back to default'); + this.MXA = this.MYB = this.MZC = 1; + this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0; + } + } + function matrixProduct(a, b, result) { + result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2]; + result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2]; + } + function convertToFlat(sourceWhitePoint, LMS, result) { + result[0] = LMS[0] * 1 / sourceWhitePoint[0]; + result[1] = LMS[1] * 1 / sourceWhitePoint[1]; + result[2] = LMS[2] * 1 / sourceWhitePoint[2]; + } + function convertToD65(sourceWhitePoint, LMS, result) { + var D65X = 0.95047; + var D65Y = 1; + var D65Z = 1.08883; + result[0] = LMS[0] * D65X / sourceWhitePoint[0]; + result[1] = LMS[1] * D65Y / sourceWhitePoint[1]; + result[2] = LMS[2] * D65Z / sourceWhitePoint[2]; + } + function sRGBTransferFunction(color) { + if (color <= 0.0031308) { + return adjustToRange(0, 1, 12.92 * color); + } + return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055); + } + function adjustToRange(min, max, value) { + return Math.max(min, Math.min(max, value)); + } + function decodeL(L) { + if (L < 0) { + return -decodeL(-L); + } + if (L > 8.0) { + return Math.pow((L + 16) / 116, 3); + } + return L * DECODE_L_CONSTANT; + } + function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) { + if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) { + result[0] = XYZ_Flat[0]; + result[1] = XYZ_Flat[1]; + result[2] = XYZ_Flat[2]; + return; + } + var zeroDecodeL = decodeL(0); + var X_DST = zeroDecodeL; + var X_SRC = decodeL(sourceBlackPoint[0]); + var Y_DST = zeroDecodeL; + var Y_SRC = decodeL(sourceBlackPoint[1]); + var Z_DST = zeroDecodeL; + var Z_SRC = decodeL(sourceBlackPoint[2]); + var X_Scale = (1 - X_DST) / (1 - X_SRC); + var X_Offset = 1 - X_Scale; + var Y_Scale = (1 - Y_DST) / (1 - Y_SRC); + var Y_Offset = 1 - Y_Scale; + var Z_Scale = (1 - Z_DST) / (1 - Z_SRC); + var Z_Offset = 1 - Z_Scale; + result[0] = XYZ_Flat[0] * X_Scale + X_Offset; + result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset; + result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset; + } + function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) { + if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) { + result[0] = XYZ_In[0]; + result[1] = XYZ_In[1]; + result[2] = XYZ_In[2]; + return; + } + var LMS = result; + matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS); + var LMS_Flat = tempNormalizeMatrix; + convertToFlat(sourceWhitePoint, LMS, LMS_Flat); + matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result); + } + function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) { + var LMS = result; + matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS); + var LMS_D65 = tempNormalizeMatrix; + convertToD65(sourceWhitePoint, LMS, LMS_D65); + matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result); + } + function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) { + var A = adjustToRange(0, 1, src[srcOffset] * scale); + var B = adjustToRange(0, 1, src[srcOffset + 1] * scale); + var C = adjustToRange(0, 1, src[srcOffset + 2] * scale); + var AGR = Math.pow(A, cs.GR); + var BGG = Math.pow(B, cs.GG); + var CGB = Math.pow(C, cs.GB); + var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB; + var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB; + var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB; + var XYZ = tempConvertMatrix1; + XYZ[0] = X; + XYZ[1] = Y; + XYZ[2] = Z; + var XYZ_Flat = tempConvertMatrix2; + normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat); + var XYZ_Black = tempConvertMatrix1; + compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black); + var XYZ_D65 = tempConvertMatrix2; + normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65); + var SRGB = tempConvertMatrix1; + matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB); + var sR = sRGBTransferFunction(SRGB[0]); + var sG = sRGBTransferFunction(SRGB[1]); + var sB = sRGBTransferFunction(SRGB[2]); + dest[destOffset] = Math.round(sR * 255); + dest[destOffset + 1] = Math.round(sG * 255); + dest[destOffset + 2] = Math.round(sB * 255); + } + CalRGBCS.prototype = { + getRgb: function CalRGBCS_getRgb(src, srcOffset) { + var rgb = new Uint8Array(3); + this.getRgbItem(src, srcOffset, rgb, 0); + return rgb; + }, + getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) { + convertToRgb(this, src, srcOffset, dest, destOffset, 1); + }, + getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + var scale = 1 / ((1 << bits) - 1); + for (var i = 0; i < count; ++i) { + convertToRgb(this, src, srcOffset, dest, destOffset, scale); + srcOffset += 3; + destOffset += 3 + alpha01; + } + }, + getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) { + return inputLength * (3 + alpha01) / 3 | 0; + }, + isPassthrough: ColorSpace.prototype.isPassthrough, + fillRgb: ColorSpace.prototype.fillRgb, + isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) { + return ColorSpace.isDefaultDecode(decodeMap, this.numComps); + }, + usesZeroToOneRange: true + }; + return CalRGBCS; + }(); + var LabCS = function LabCSClosure() { + function LabCS(whitePoint, blackPoint, range) { + this.name = 'Lab'; + this.numComps = 3; + this.defaultColor = new Float32Array(this.numComps); + if (!whitePoint) { + error('WhitePoint missing - required for color space Lab'); + } + blackPoint = blackPoint || [ + 0, + 0, + 0 + ]; + range = range || [ + -100, + 100, + -100, + 100 + ]; + this.XW = whitePoint[0]; + this.YW = whitePoint[1]; + this.ZW = whitePoint[2]; + this.amin = range[0]; + this.amax = range[1]; + this.bmin = range[2]; + this.bmax = range[3]; + this.XB = blackPoint[0]; + this.YB = blackPoint[1]; + this.ZB = blackPoint[2]; + if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) { + error('Invalid WhitePoint components, no fallback available'); + } + if (this.XB < 0 || this.YB < 0 || this.ZB < 0) { + info('Invalid BlackPoint, falling back to default'); + this.XB = this.YB = this.ZB = 0; + } + if (this.amin > this.amax || this.bmin > this.bmax) { + info('Invalid Range, falling back to defaults'); + this.amin = -100; + this.amax = 100; + this.bmin = -100; + this.bmax = 100; + } + } + function fn_g(x) { + var result; + if (x >= 6 / 29) { + result = x * x * x; + } else { + result = 108 / 841 * (x - 4 / 29); + } + return result; + } + function decode(value, high1, low2, high2) { + return low2 + value * (high2 - low2) / high1; + } + function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) { + var Ls = src[srcOffset]; + var as = src[srcOffset + 1]; + var bs = src[srcOffset + 2]; + if (maxVal !== false) { + Ls = decode(Ls, maxVal, 0, 100); + as = decode(as, maxVal, cs.amin, cs.amax); + bs = decode(bs, maxVal, cs.bmin, cs.bmax); + } + as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as; + bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs; + var M = (Ls + 16) / 116; + var L = M + as / 500; + var N = M - bs / 200; + var X = cs.XW * fn_g(L); + var Y = cs.YW * fn_g(M); + var Z = cs.ZW * fn_g(N); + var r, g, b; + if (cs.ZW < 1) { + r = X * 3.1339 + Y * -1.6170 + Z * -0.4906; + g = X * -0.9785 + Y * 1.9160 + Z * 0.0333; + b = X * 0.0720 + Y * -0.2290 + Z * 1.4057; + } else { + r = X * 3.2406 + Y * -1.5372 + Z * -0.4986; + g = X * -0.9689 + Y * 1.8758 + Z * 0.0415; + b = X * 0.0557 + Y * -0.2040 + Z * 1.0570; + } + dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0; + dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0; + dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0; + } + LabCS.prototype = { + getRgb: ColorSpace.prototype.getRgb, + getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) { + convertToRgb(this, src, srcOffset, false, dest, destOffset); + }, + getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { + var maxVal = (1 << bits) - 1; + for (var i = 0; i < count; i++) { + convertToRgb(this, src, srcOffset, maxVal, dest, destOffset); + srcOffset += 3; + destOffset += 3 + alpha01; + } + }, + getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) { + return inputLength * (3 + alpha01) / 3 | 0; + }, + isPassthrough: ColorSpace.prototype.isPassthrough, + fillRgb: ColorSpace.prototype.fillRgb, + isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) { + return true; + }, + usesZeroToOneRange: false + }; + return LabCS; + }(); + exports.ColorSpace = ColorSpace; + })); (function (root, factory) { factory(root.pdfjsCoreFonts = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser); }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreGlyphList, coreFontRenderer, coreEncodings, coreStandardFonts, coreUnicode, coreType1Parser, coreCFFParser) { @@ -39199,2211 +41406,6 @@ exports.ToUnicodeMap = ToUnicodeMap; exports.getFontType = getFontType; })); - (function (root, factory) { - factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreParser); - }(this, function (exports, sharedUtil, coreParser) { - var error = sharedUtil.error; - var isSpace = sharedUtil.isSpace; - var EOF = coreParser.EOF; - var PostScriptParser = function PostScriptParserClosure() { - function PostScriptParser(lexer) { - this.lexer = lexer; - this.operators = []; - this.token = null; - this.prev = null; - } - PostScriptParser.prototype = { - nextToken: function PostScriptParser_nextToken() { - this.prev = this.token; - this.token = this.lexer.getToken(); - }, - accept: function PostScriptParser_accept(type) { - if (this.token.type === type) { - this.nextToken(); - return true; - } - return false; - }, - expect: function PostScriptParser_expect(type) { - if (this.accept(type)) { - return true; - } - error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.'); - }, - parse: function PostScriptParser_parse() { - this.nextToken(); - this.expect(PostScriptTokenTypes.LBRACE); - this.parseBlock(); - this.expect(PostScriptTokenTypes.RBRACE); - return this.operators; - }, - parseBlock: function PostScriptParser_parseBlock() { - while (true) { - if (this.accept(PostScriptTokenTypes.NUMBER)) { - this.operators.push(this.prev.value); - } else if (this.accept(PostScriptTokenTypes.OPERATOR)) { - this.operators.push(this.prev.value); - } else if (this.accept(PostScriptTokenTypes.LBRACE)) { - this.parseCondition(); - } else { - return; - } - } - }, - parseCondition: function PostScriptParser_parseCondition() { - var conditionLocation = this.operators.length; - this.operators.push(null, null); - this.parseBlock(); - this.expect(PostScriptTokenTypes.RBRACE); - if (this.accept(PostScriptTokenTypes.IF)) { - this.operators[conditionLocation] = this.operators.length; - this.operators[conditionLocation + 1] = 'jz'; - } else if (this.accept(PostScriptTokenTypes.LBRACE)) { - var jumpLocation = this.operators.length; - this.operators.push(null, null); - var endOfTrue = this.operators.length; - this.parseBlock(); - this.expect(PostScriptTokenTypes.RBRACE); - this.expect(PostScriptTokenTypes.IFELSE); - this.operators[jumpLocation] = this.operators.length; - this.operators[jumpLocation + 1] = 'j'; - this.operators[conditionLocation] = endOfTrue; - this.operators[conditionLocation + 1] = 'jz'; - } else { - error('PS Function: error parsing conditional.'); - } - } - }; - return PostScriptParser; - }(); - var PostScriptTokenTypes = { - LBRACE: 0, - RBRACE: 1, - NUMBER: 2, - OPERATOR: 3, - IF: 4, - IFELSE: 5 - }; - var PostScriptToken = function PostScriptTokenClosure() { - function PostScriptToken(type, value) { - this.type = type; - this.value = value; - } - var opCache = Object.create(null); - PostScriptToken.getOperator = function PostScriptToken_getOperator(op) { - var opValue = opCache[op]; - if (opValue) { - return opValue; - } - return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op); - }; - PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{'); - PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}'); - PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF'); - PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE'); - return PostScriptToken; - }(); - var PostScriptLexer = function PostScriptLexerClosure() { - function PostScriptLexer(stream) { - this.stream = stream; - this.nextChar(); - this.strBuf = []; - } - PostScriptLexer.prototype = { - nextChar: function PostScriptLexer_nextChar() { - return this.currentChar = this.stream.getByte(); - }, - getToken: function PostScriptLexer_getToken() { - var comment = false; - var ch = this.currentChar; - while (true) { - if (ch < 0) { - return EOF; - } - if (comment) { - if (ch === 0x0A || ch === 0x0D) { - comment = false; - } - } else if (ch === 0x25) { - comment = true; - } else if (!isSpace(ch)) { - break; - } - ch = this.nextChar(); - } - switch (ch | 0) { - case 0x30: - case 0x31: - case 0x32: - case 0x33: - case 0x34: - case 0x35: - case 0x36: - case 0x37: - case 0x38: - case 0x39: - case 0x2B: - case 0x2D: - case 0x2E: - return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber()); - case 0x7B: - this.nextChar(); - return PostScriptToken.LBRACE; - case 0x7D: - this.nextChar(); - return PostScriptToken.RBRACE; - } - var strBuf = this.strBuf; - strBuf.length = 0; - strBuf[0] = String.fromCharCode(ch); - while ((ch = this.nextChar()) >= 0 && (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) { - strBuf.push(String.fromCharCode(ch)); - } - var str = strBuf.join(''); - switch (str.toLowerCase()) { - case 'if': - return PostScriptToken.IF; - case 'ifelse': - return PostScriptToken.IFELSE; - default: - return PostScriptToken.getOperator(str); - } - }, - getNumber: function PostScriptLexer_getNumber() { - var ch = this.currentChar; - var strBuf = this.strBuf; - strBuf.length = 0; - strBuf[0] = String.fromCharCode(ch); - while ((ch = this.nextChar()) >= 0) { - if (ch >= 0x30 && ch <= 0x39 || ch === 0x2D || ch === 0x2E) { - strBuf.push(String.fromCharCode(ch)); - } else { - break; - } - } - var value = parseFloat(strBuf.join('')); - if (isNaN(value)) { - error('Invalid floating point number: ' + value); - } - return value; - } - }; - return PostScriptLexer; - }(); - exports.PostScriptLexer = PostScriptLexer; - exports.PostScriptParser = PostScriptParser; - })); - (function (root, factory) { - factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser); - }(this, function (exports, sharedUtil, corePrimitives, corePsParser) { - var error = sharedUtil.error; - var info = sharedUtil.info; - var isArray = sharedUtil.isArray; - var isBool = sharedUtil.isBool; - var isDict = corePrimitives.isDict; - var isStream = corePrimitives.isStream; - var PostScriptLexer = corePsParser.PostScriptLexer; - var PostScriptParser = corePsParser.PostScriptParser; - var PDFFunction = function PDFFunctionClosure() { - var CONSTRUCT_SAMPLED = 0; - var CONSTRUCT_INTERPOLATED = 2; - var CONSTRUCT_STICHED = 3; - var CONSTRUCT_POSTSCRIPT = 4; - return { - getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) { - var i, ii; - var length = 1; - for (i = 0, ii = size.length; i < ii; i++) { - length *= size[i]; - } - length *= outputSize; - var array = new Array(length); - var codeSize = 0; - var codeBuf = 0; - var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1); - var strBytes = str.getBytes((length * bps + 7) / 8); - var strIdx = 0; - for (i = 0; i < length; i++) { - while (codeSize < bps) { - codeBuf <<= 8; - codeBuf |= strBytes[strIdx++]; - codeSize += 8; - } - codeSize -= bps; - array[i] = (codeBuf >> codeSize) * sampleMul; - codeBuf &= (1 << codeSize) - 1; - } - return array; - }, - getIR: function PDFFunction_getIR(xref, fn) { - var dict = fn.dict; - if (!dict) { - dict = fn; - } - var types = [ - this.constructSampled, - null, - this.constructInterpolated, - this.constructStiched, - this.constructPostScript - ]; - var typeNum = dict.get('FunctionType'); - var typeFn = types[typeNum]; - if (!typeFn) { - error('Unknown type of function'); - } - return typeFn.call(this, fn, dict, xref); - }, - fromIR: function PDFFunction_fromIR(IR) { - var type = IR[0]; - switch (type) { - case CONSTRUCT_SAMPLED: - return this.constructSampledFromIR(IR); - case CONSTRUCT_INTERPOLATED: - return this.constructInterpolatedFromIR(IR); - case CONSTRUCT_STICHED: - return this.constructStichedFromIR(IR); - default: - return this.constructPostScriptFromIR(IR); - } - }, - parse: function PDFFunction_parse(xref, fn) { - var IR = this.getIR(xref, fn); - return this.fromIR(IR); - }, - parseArray: function PDFFunction_parseArray(xref, fnObj) { - if (!isArray(fnObj)) { - return this.parse(xref, fnObj); - } - var fnArray = []; - for (var j = 0, jj = fnObj.length; j < jj; j++) { - var obj = xref.fetchIfRef(fnObj[j]); - fnArray.push(PDFFunction.parse(xref, obj)); - } - return function (src, srcOffset, dest, destOffset) { - for (var i = 0, ii = fnArray.length; i < ii; i++) { - fnArray[i](src, srcOffset, dest, destOffset + i); - } - }; - }, - constructSampled: function PDFFunction_constructSampled(str, dict) { - function toMultiArray(arr) { - var inputLength = arr.length; - var out = []; - var index = 0; - for (var i = 0; i < inputLength; i += 2) { - out[index] = [ - arr[i], - arr[i + 1] - ]; - ++index; - } - return out; - } - var domain = dict.getArray('Domain'); - var range = dict.getArray('Range'); - if (!domain || !range) { - error('No domain or range'); - } - var inputSize = domain.length / 2; - var outputSize = range.length / 2; - domain = toMultiArray(domain); - range = toMultiArray(range); - var size = dict.get('Size'); - var bps = dict.get('BitsPerSample'); - var order = dict.get('Order') || 1; - if (order !== 1) { - info('No support for cubic spline interpolation: ' + order); - } - var encode = dict.getArray('Encode'); - if (!encode) { - encode = []; - for (var i = 0; i < inputSize; ++i) { - encode.push(0); - encode.push(size[i] - 1); - } - } - encode = toMultiArray(encode); - var decode = dict.getArray('Decode'); - if (!decode) { - decode = range; - } else { - decode = toMultiArray(decode); - } - var samples = this.getSampleArray(size, outputSize, bps, str); - return [ - CONSTRUCT_SAMPLED, - inputSize, - domain, - encode, - decode, - samples, - size, - outputSize, - Math.pow(2, bps) - 1, - range - ]; - }, - constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) { - function interpolate(x, xmin, xmax, ymin, ymax) { - return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin)); - } - return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) { - var m = IR[1]; - var domain = IR[2]; - var encode = IR[3]; - var decode = IR[4]; - var samples = IR[5]; - var size = IR[6]; - var n = IR[7]; - var range = IR[9]; - var cubeVertices = 1 << m; - var cubeN = new Float64Array(cubeVertices); - var cubeVertex = new Uint32Array(cubeVertices); - var i, j; - for (j = 0; j < cubeVertices; j++) { - cubeN[j] = 1; - } - var k = n, pos = 1; - for (i = 0; i < m; ++i) { - var domain_2i = domain[i][0]; - var domain_2i_1 = domain[i][1]; - var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1); - var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]); - var size_i = size[i]; - e = Math.min(Math.max(e, 0), size_i - 1); - var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; - var n0 = e0 + 1 - e; - var n1 = e - e0; - var offset0 = e0 * k; - var offset1 = offset0 + k; - for (j = 0; j < cubeVertices; j++) { - if (j & pos) { - cubeN[j] *= n1; - cubeVertex[j] += offset1; - } else { - cubeN[j] *= n0; - cubeVertex[j] += offset0; - } - } - k *= size_i; - pos <<= 1; - } - for (j = 0; j < n; ++j) { - var rj = 0; - for (i = 0; i < cubeVertices; i++) { - rj += samples[cubeVertex[i] + j] * cubeN[i]; - } - rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]); - dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]); - } - }; - }, - constructInterpolated: function PDFFunction_constructInterpolated(str, dict) { - var c0 = dict.getArray('C0') || [0]; - var c1 = dict.getArray('C1') || [1]; - var n = dict.get('N'); - if (!isArray(c0) || !isArray(c1)) { - error('Illegal dictionary for interpolated function'); - } - var length = c0.length; - var diff = []; - for (var i = 0; i < length; ++i) { - diff.push(c1[i] - c0[i]); - } - return [ - CONSTRUCT_INTERPOLATED, - c0, - diff, - n - ]; - }, - constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) { - var c0 = IR[1]; - var diff = IR[2]; - var n = IR[3]; - var length = diff.length; - return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) { - var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n); - for (var j = 0; j < length; ++j) { - dest[destOffset + j] = c0[j] + x * diff[j]; - } - }; - }, - constructStiched: function PDFFunction_constructStiched(fn, dict, xref) { - var domain = dict.getArray('Domain'); - if (!domain) { - error('No domain'); - } - var inputSize = domain.length / 2; - if (inputSize !== 1) { - error('Bad domain for stiched function'); - } - var fnRefs = dict.get('Functions'); - var fns = []; - for (var i = 0, ii = fnRefs.length; i < ii; ++i) { - fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i]))); - } - var bounds = dict.getArray('Bounds'); - var encode = dict.getArray('Encode'); - return [ - CONSTRUCT_STICHED, - domain, - bounds, - encode, - fns - ]; - }, - constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) { - var domain = IR[1]; - var bounds = IR[2]; - var encode = IR[3]; - var fnsIR = IR[4]; - var fns = []; - var tmpBuf = new Float32Array(1); - for (var i = 0, ii = fnsIR.length; i < ii; i++) { - fns.push(PDFFunction.fromIR(fnsIR[i])); - } - return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) { - var clip = function constructStichedFromIRClip(v, min, max) { - if (v > max) { - v = max; - } else if (v < min) { - v = min; - } - return v; - }; - var v = clip(src[srcOffset], domain[0], domain[1]); - for (var i = 0, ii = bounds.length; i < ii; ++i) { - if (v < bounds[i]) { - break; - } - } - var dmin = domain[0]; - if (i > 0) { - dmin = bounds[i - 1]; - } - var dmax = domain[1]; - if (i < bounds.length) { - dmax = bounds[i]; - } - var rmin = encode[2 * i]; - var rmax = encode[2 * i + 1]; - tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin); - fns[i](tmpBuf, 0, dest, destOffset); - }; - }, - constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) { - var domain = dict.getArray('Domain'); - var range = dict.getArray('Range'); - if (!domain) { - error('No domain.'); - } - if (!range) { - error('No range.'); - } - var lexer = new PostScriptLexer(fn); - var parser = new PostScriptParser(lexer); - var code = parser.parse(); - return [ - CONSTRUCT_POSTSCRIPT, - domain, - range, - code - ]; - }, - constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) { - var domain = IR[1]; - var range = IR[2]; - var code = IR[3]; - var compiled = new PostScriptCompiler().compile(code, domain, range); - if (compiled) { - return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled); - } - info('Unable to compile PS function'); - var numOutputs = range.length >> 1; - var numInputs = domain.length >> 1; - var evaluator = new PostScriptEvaluator(code); - var cache = Object.create(null); - var MAX_CACHE_SIZE = 2048 * 4; - var cache_available = MAX_CACHE_SIZE; - var tmpBuf = new Float32Array(numInputs); - return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) { - var i, value; - var key = ''; - var input = tmpBuf; - for (i = 0; i < numInputs; i++) { - value = src[srcOffset + i]; - input[i] = value; - key += value + '_'; - } - var cachedValue = cache[key]; - if (cachedValue !== undefined) { - dest.set(cachedValue, destOffset); - return; - } - var output = new Float32Array(numOutputs); - var stack = evaluator.execute(input); - var stackIndex = stack.length - numOutputs; - for (i = 0; i < numOutputs; i++) { - value = stack[stackIndex + i]; - var bound = range[i * 2]; - if (value < bound) { - value = bound; - } else { - bound = range[i * 2 + 1]; - if (value > bound) { - value = bound; - } - } - output[i] = value; - } - if (cache_available > 0) { - cache_available--; - cache[key] = output; - } - dest.set(output, destOffset); - }; - } - }; - }(); - function isPDFFunction(v) { - var fnDict; - if (typeof v !== 'object') { - return false; - } else if (isDict(v)) { - fnDict = v; - } else if (isStream(v)) { - fnDict = v.dict; - } else { - return false; - } - return fnDict.has('FunctionType'); - } - var PostScriptStack = function PostScriptStackClosure() { - var MAX_STACK_SIZE = 100; - function PostScriptStack(initialStack) { - this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0); - } - PostScriptStack.prototype = { - push: function PostScriptStack_push(value) { - if (this.stack.length >= MAX_STACK_SIZE) { - error('PostScript function stack overflow.'); - } - this.stack.push(value); - }, - pop: function PostScriptStack_pop() { - if (this.stack.length <= 0) { - error('PostScript function stack underflow.'); - } - return this.stack.pop(); - }, - copy: function PostScriptStack_copy(n) { - if (this.stack.length + n >= MAX_STACK_SIZE) { - error('PostScript function stack overflow.'); - } - var stack = this.stack; - for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) { - stack.push(stack[i]); - } - }, - index: function PostScriptStack_index(n) { - this.push(this.stack[this.stack.length - n - 1]); - }, - roll: function PostScriptStack_roll(n, p) { - var stack = this.stack; - var l = stack.length - n; - var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t; - for (i = l, j = r; i < j; i++, j--) { - t = stack[i]; - stack[i] = stack[j]; - stack[j] = t; - } - for (i = l, j = c - 1; i < j; i++, j--) { - t = stack[i]; - stack[i] = stack[j]; - stack[j] = t; - } - for (i = c, j = r; i < j; i++, j--) { - t = stack[i]; - stack[i] = stack[j]; - stack[j] = t; - } - } - }; - return PostScriptStack; - }(); - var PostScriptEvaluator = function PostScriptEvaluatorClosure() { - function PostScriptEvaluator(operators) { - this.operators = operators; - } - PostScriptEvaluator.prototype = { - execute: function PostScriptEvaluator_execute(initialStack) { - var stack = new PostScriptStack(initialStack); - var counter = 0; - var operators = this.operators; - var length = operators.length; - var operator, a, b; - while (counter < length) { - operator = operators[counter++]; - if (typeof operator === 'number') { - stack.push(operator); - continue; - } - switch (operator) { - case 'jz': - b = stack.pop(); - a = stack.pop(); - if (!a) { - counter = b; - } - break; - case 'j': - a = stack.pop(); - counter = a; - break; - case 'abs': - a = stack.pop(); - stack.push(Math.abs(a)); - break; - case 'add': - b = stack.pop(); - a = stack.pop(); - stack.push(a + b); - break; - case 'and': - b = stack.pop(); - a = stack.pop(); - if (isBool(a) && isBool(b)) { - stack.push(a && b); - } else { - stack.push(a & b); - } - break; - case 'atan': - a = stack.pop(); - stack.push(Math.atan(a)); - break; - case 'bitshift': - b = stack.pop(); - a = stack.pop(); - if (a > 0) { - stack.push(a << b); - } else { - stack.push(a >> b); - } - break; - case 'ceiling': - a = stack.pop(); - stack.push(Math.ceil(a)); - break; - case 'copy': - a = stack.pop(); - stack.copy(a); - break; - case 'cos': - a = stack.pop(); - stack.push(Math.cos(a)); - break; - case 'cvi': - a = stack.pop() | 0; - stack.push(a); - break; - case 'cvr': - break; - case 'div': - b = stack.pop(); - a = stack.pop(); - stack.push(a / b); - break; - case 'dup': - stack.copy(1); - break; - case 'eq': - b = stack.pop(); - a = stack.pop(); - stack.push(a === b); - break; - case 'exch': - stack.roll(2, 1); - break; - case 'exp': - b = stack.pop(); - a = stack.pop(); - stack.push(Math.pow(a, b)); - break; - case 'false': - stack.push(false); - break; - case 'floor': - a = stack.pop(); - stack.push(Math.floor(a)); - break; - case 'ge': - b = stack.pop(); - a = stack.pop(); - stack.push(a >= b); - break; - case 'gt': - b = stack.pop(); - a = stack.pop(); - stack.push(a > b); - break; - case 'idiv': - b = stack.pop(); - a = stack.pop(); - stack.push(a / b | 0); - break; - case 'index': - a = stack.pop(); - stack.index(a); - break; - case 'le': - b = stack.pop(); - a = stack.pop(); - stack.push(a <= b); - break; - case 'ln': - a = stack.pop(); - stack.push(Math.log(a)); - break; - case 'log': - a = stack.pop(); - stack.push(Math.log(a) / Math.LN10); - break; - case 'lt': - b = stack.pop(); - a = stack.pop(); - stack.push(a < b); - break; - case 'mod': - b = stack.pop(); - a = stack.pop(); - stack.push(a % b); - break; - case 'mul': - b = stack.pop(); - a = stack.pop(); - stack.push(a * b); - break; - case 'ne': - b = stack.pop(); - a = stack.pop(); - stack.push(a !== b); - break; - case 'neg': - a = stack.pop(); - stack.push(-a); - break; - case 'not': - a = stack.pop(); - if (isBool(a)) { - stack.push(!a); - } else { - stack.push(~a); - } - break; - case 'or': - b = stack.pop(); - a = stack.pop(); - if (isBool(a) && isBool(b)) { - stack.push(a || b); - } else { - stack.push(a | b); - } - break; - case 'pop': - stack.pop(); - break; - case 'roll': - b = stack.pop(); - a = stack.pop(); - stack.roll(a, b); - break; - case 'round': - a = stack.pop(); - stack.push(Math.round(a)); - break; - case 'sin': - a = stack.pop(); - stack.push(Math.sin(a)); - break; - case 'sqrt': - a = stack.pop(); - stack.push(Math.sqrt(a)); - break; - case 'sub': - b = stack.pop(); - a = stack.pop(); - stack.push(a - b); - break; - case 'true': - stack.push(true); - break; - case 'truncate': - a = stack.pop(); - a = a < 0 ? Math.ceil(a) : Math.floor(a); - stack.push(a); - break; - case 'xor': - b = stack.pop(); - a = stack.pop(); - if (isBool(a) && isBool(b)) { - stack.push(a !== b); - } else { - stack.push(a ^ b); - } - break; - default: - error('Unknown operator ' + operator); - break; - } - } - return stack.stack; - } - }; - return PostScriptEvaluator; - }(); - var PostScriptCompiler = function PostScriptCompilerClosure() { - function AstNode(type) { - this.type = type; - } - AstNode.prototype.visit = function (visitor) { - throw new Error('abstract method'); - }; - function AstArgument(index, min, max) { - AstNode.call(this, 'args'); - this.index = index; - this.min = min; - this.max = max; - } - AstArgument.prototype = Object.create(AstNode.prototype); - AstArgument.prototype.visit = function (visitor) { - visitor.visitArgument(this); - }; - function AstLiteral(number) { - AstNode.call(this, 'literal'); - this.number = number; - this.min = number; - this.max = number; - } - AstLiteral.prototype = Object.create(AstNode.prototype); - AstLiteral.prototype.visit = function (visitor) { - visitor.visitLiteral(this); - }; - function AstBinaryOperation(op, arg1, arg2, min, max) { - AstNode.call(this, 'binary'); - this.op = op; - this.arg1 = arg1; - this.arg2 = arg2; - this.min = min; - this.max = max; - } - AstBinaryOperation.prototype = Object.create(AstNode.prototype); - AstBinaryOperation.prototype.visit = function (visitor) { - visitor.visitBinaryOperation(this); - }; - function AstMin(arg, max) { - AstNode.call(this, 'max'); - this.arg = arg; - this.min = arg.min; - this.max = max; - } - AstMin.prototype = Object.create(AstNode.prototype); - AstMin.prototype.visit = function (visitor) { - visitor.visitMin(this); - }; - function AstVariable(index, min, max) { - AstNode.call(this, 'var'); - this.index = index; - this.min = min; - this.max = max; - } - AstVariable.prototype = Object.create(AstNode.prototype); - AstVariable.prototype.visit = function (visitor) { - visitor.visitVariable(this); - }; - function AstVariableDefinition(variable, arg) { - AstNode.call(this, 'definition'); - this.variable = variable; - this.arg = arg; - } - AstVariableDefinition.prototype = Object.create(AstNode.prototype); - AstVariableDefinition.prototype.visit = function (visitor) { - visitor.visitVariableDefinition(this); - }; - function ExpressionBuilderVisitor() { - this.parts = []; - } - ExpressionBuilderVisitor.prototype = { - visitArgument: function (arg) { - this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))'); - }, - visitVariable: function (variable) { - this.parts.push('v', variable.index); - }, - visitLiteral: function (literal) { - this.parts.push(literal.number); - }, - visitBinaryOperation: function (operation) { - this.parts.push('('); - operation.arg1.visit(this); - this.parts.push(' ', operation.op, ' '); - operation.arg2.visit(this); - this.parts.push(')'); - }, - visitVariableDefinition: function (definition) { - this.parts.push('var '); - definition.variable.visit(this); - this.parts.push(' = '); - definition.arg.visit(this); - this.parts.push(';'); - }, - visitMin: function (max) { - this.parts.push('Math.min('); - max.arg.visit(this); - this.parts.push(', ', max.max, ')'); - }, - toString: function () { - return this.parts.join(''); - } - }; - function buildAddOperation(num1, num2) { - if (num2.type === 'literal' && num2.number === 0) { - return num1; - } - if (num1.type === 'literal' && num1.number === 0) { - return num2; - } - if (num2.type === 'literal' && num1.type === 'literal') { - return new AstLiteral(num1.number + num2.number); - } - return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max); - } - function buildMulOperation(num1, num2) { - if (num2.type === 'literal') { - if (num2.number === 0) { - return new AstLiteral(0); - } else if (num2.number === 1) { - return num1; - } else if (num1.type === 'literal') { - return new AstLiteral(num1.number * num2.number); - } - } - if (num1.type === 'literal') { - if (num1.number === 0) { - return new AstLiteral(0); - } else if (num1.number === 1) { - return num2; - } - } - var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max); - var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max); - return new AstBinaryOperation('*', num1, num2, min, max); - } - function buildSubOperation(num1, num2) { - if (num2.type === 'literal') { - if (num2.number === 0) { - return num1; - } else if (num1.type === 'literal') { - return new AstLiteral(num1.number - num2.number); - } - } - if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) { - return num2.arg2; - } - return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min); - } - function buildMinOperation(num1, max) { - if (num1.min >= max) { - return new AstLiteral(max); - } else if (num1.max <= max) { - return num1; - } - return new AstMin(num1, max); - } - function PostScriptCompiler() { - } - PostScriptCompiler.prototype = { - compile: function PostScriptCompiler_compile(code, domain, range) { - var stack = []; - var i, ii; - var instructions = []; - var inputSize = domain.length >> 1, outputSize = range.length >> 1; - var lastRegister = 0; - var n, j; - var num1, num2, ast1, ast2, tmpVar, item; - for (i = 0; i < inputSize; i++) { - stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1])); - } - for (i = 0, ii = code.length; i < ii; i++) { - item = code[i]; - if (typeof item === 'number') { - stack.push(new AstLiteral(item)); - continue; - } - switch (item) { - case 'add': - if (stack.length < 2) { - return null; - } - num2 = stack.pop(); - num1 = stack.pop(); - stack.push(buildAddOperation(num1, num2)); - break; - case 'cvr': - if (stack.length < 1) { - return null; - } - break; - case 'mul': - if (stack.length < 2) { - return null; - } - num2 = stack.pop(); - num1 = stack.pop(); - stack.push(buildMulOperation(num1, num2)); - break; - case 'sub': - if (stack.length < 2) { - return null; - } - num2 = stack.pop(); - num1 = stack.pop(); - stack.push(buildSubOperation(num1, num2)); - break; - case 'exch': - if (stack.length < 2) { - return null; - } - ast1 = stack.pop(); - ast2 = stack.pop(); - stack.push(ast1, ast2); - break; - case 'pop': - if (stack.length < 1) { - return null; - } - stack.pop(); - break; - case 'index': - if (stack.length < 1) { - return null; - } - num1 = stack.pop(); - if (num1.type !== 'literal') { - return null; - } - n = num1.number; - if (n < 0 || (n | 0) !== n || stack.length < n) { - return null; - } - ast1 = stack[stack.length - n - 1]; - if (ast1.type === 'literal' || ast1.type === 'var') { - stack.push(ast1); - break; - } - tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max); - stack[stack.length - n - 1] = tmpVar; - stack.push(tmpVar); - instructions.push(new AstVariableDefinition(tmpVar, ast1)); - break; - case 'dup': - if (stack.length < 1) { - return null; - } - if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' && code[i + 3] === i + 7 && code[i + 4] === 'jz' && code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) { - num1 = stack.pop(); - stack.push(buildMinOperation(num1, code[i + 1])); - i += 6; - break; - } - ast1 = stack[stack.length - 1]; - if (ast1.type === 'literal' || ast1.type === 'var') { - stack.push(ast1); - break; - } - tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max); - stack[stack.length - 1] = tmpVar; - stack.push(tmpVar); - instructions.push(new AstVariableDefinition(tmpVar, ast1)); - break; - case 'roll': - if (stack.length < 2) { - return null; - } - num2 = stack.pop(); - num1 = stack.pop(); - if (num2.type !== 'literal' || num1.type !== 'literal') { - return null; - } - j = num2.number; - n = num1.number; - if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) { - return null; - } - j = (j % n + n) % n; - if (j === 0) { - break; - } - Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j)); - break; - default: - return null; - } - } - if (stack.length !== outputSize) { - return null; - } - var result = []; - instructions.forEach(function (instruction) { - var statementBuilder = new ExpressionBuilderVisitor(); - instruction.visit(statementBuilder); - result.push(statementBuilder.toString()); - }); - stack.forEach(function (expr, i) { - var statementBuilder = new ExpressionBuilderVisitor(); - expr.visit(statementBuilder); - var min = range[i * 2], max = range[i * 2 + 1]; - var out = [statementBuilder.toString()]; - if (min > expr.min) { - out.unshift('Math.max(', min, ', '); - out.push(')'); - } - if (max < expr.max) { - out.unshift('Math.min(', max, ', '); - out.push(')'); - } - out.unshift('dest[destOffset + ', i, '] = '); - out.push(';'); - result.push(out.join('')); - }); - return result.join('\n'); - } - }; - return PostScriptCompiler; - }(); - exports.isPDFFunction = isPDFFunction; - exports.PDFFunction = PDFFunction; - exports.PostScriptEvaluator = PostScriptEvaluator; - exports.PostScriptCompiler = PostScriptCompiler; - })); - (function (root, factory) { - factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction); - }(this, function (exports, sharedUtil, corePrimitives, coreFunction) { - var error = sharedUtil.error; - var info = sharedUtil.info; - var isArray = sharedUtil.isArray; - var isString = sharedUtil.isString; - var shadow = sharedUtil.shadow; - var warn = sharedUtil.warn; - var isDict = corePrimitives.isDict; - var isName = corePrimitives.isName; - var isStream = corePrimitives.isStream; - var PDFFunction = coreFunction.PDFFunction; - var ColorSpace = function ColorSpaceClosure() { - function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) { - var COMPONENTS = 3; - alpha01 = alpha01 !== 1 ? 0 : alpha01; - var xRatio = w1 / w2; - var yRatio = h1 / h2; - var i, j, py, newIndex = 0, oldIndex; - var xScaled = new Uint16Array(w2); - var w1Scanline = w1 * COMPONENTS; - for (i = 0; i < w2; i++) { - xScaled[i] = Math.floor(i * xRatio) * COMPONENTS; - } - for (i = 0; i < h2; i++) { - py = Math.floor(i * yRatio) * w1Scanline; - for (j = 0; j < w2; j++) { - oldIndex = py + xScaled[j]; - dest[newIndex++] = src[oldIndex++]; - dest[newIndex++] = src[oldIndex++]; - dest[newIndex++] = src[oldIndex++]; - newIndex += alpha01; - } - } - } - function ColorSpace() { - error('should not call ColorSpace constructor'); - } - ColorSpace.prototype = { - getRgb: function ColorSpace_getRgb(src, srcOffset) { - var rgb = new Uint8Array(3); - this.getRgbItem(src, srcOffset, rgb, 0); - return rgb; - }, - getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) { - error('Should not call ColorSpace.getRgbItem'); - }, - getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - error('Should not call ColorSpace.getRgbBuffer'); - }, - getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) { - error('Should not call ColorSpace.getOutputLength'); - }, - isPassthrough: function ColorSpace_isPassthrough(bits) { - return false; - }, - fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) { - var count = originalWidth * originalHeight; - var rgbBuf = null; - var numComponentColors = 1 << bpc; - var needsResizing = originalHeight !== height || originalWidth !== width; - var i, ii; - if (this.isPassthrough(bpc)) { - rgbBuf = comps; - } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') { - var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors); - var key; - for (i = 0; i < numComponentColors; i++) { - allColors[i] = i; - } - var colorMap = new Uint8Array(numComponentColors * 3); - this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, 0); - var destPos, rgbPos; - if (!needsResizing) { - destPos = 0; - for (i = 0; i < count; ++i) { - key = comps[i] * 3; - dest[destPos++] = colorMap[key]; - dest[destPos++] = colorMap[key + 1]; - dest[destPos++] = colorMap[key + 2]; - destPos += alpha01; - } - } else { - rgbBuf = new Uint8Array(count * 3); - rgbPos = 0; - for (i = 0; i < count; ++i) { - key = comps[i] * 3; - rgbBuf[rgbPos++] = colorMap[key]; - rgbBuf[rgbPos++] = colorMap[key + 1]; - rgbBuf[rgbPos++] = colorMap[key + 2]; - } - } - } else { - if (!needsResizing) { - this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01); - } else { - rgbBuf = new Uint8Array(count * 3); - this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, 0); - } - } - if (rgbBuf) { - if (needsResizing) { - resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest); - } else { - rgbPos = 0; - destPos = 0; - for (i = 0, ii = width * actualHeight; i < ii; i++) { - dest[destPos++] = rgbBuf[rgbPos++]; - dest[destPos++] = rgbBuf[rgbPos++]; - dest[destPos++] = rgbBuf[rgbPos++]; - destPos += alpha01; - } - } - } - }, - usesZeroToOneRange: true - }; - ColorSpace.parse = function ColorSpace_parse(cs, xref, res) { - var IR = ColorSpace.parseToIR(cs, xref, res); - if (IR instanceof AlternateCS) { - return IR; - } - return ColorSpace.fromIR(IR); - }; - ColorSpace.fromIR = function ColorSpace_fromIR(IR) { - var name = isArray(IR) ? IR[0] : IR; - var whitePoint, blackPoint, gamma; - switch (name) { - case 'DeviceGrayCS': - return this.singletons.gray; - case 'DeviceRgbCS': - return this.singletons.rgb; - case 'DeviceCmykCS': - return this.singletons.cmyk; - case 'CalGrayCS': - whitePoint = IR[1]; - blackPoint = IR[2]; - gamma = IR[3]; - return new CalGrayCS(whitePoint, blackPoint, gamma); - case 'CalRGBCS': - whitePoint = IR[1]; - blackPoint = IR[2]; - gamma = IR[3]; - var matrix = IR[4]; - return new CalRGBCS(whitePoint, blackPoint, gamma, matrix); - case 'PatternCS': - var basePatternCS = IR[1]; - if (basePatternCS) { - basePatternCS = ColorSpace.fromIR(basePatternCS); - } - return new PatternCS(basePatternCS); - case 'IndexedCS': - var baseIndexedCS = IR[1]; - var hiVal = IR[2]; - var lookup = IR[3]; - return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup); - case 'AlternateCS': - var numComps = IR[1]; - var alt = IR[2]; - var tintFnIR = IR[3]; - return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR)); - case 'LabCS': - whitePoint = IR[1]; - blackPoint = IR[2]; - var range = IR[3]; - return new LabCS(whitePoint, blackPoint, range); - default: - error('Unknown name ' + name); - } - return null; - }; - ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) { - if (isName(cs)) { - var colorSpaces = res.get('ColorSpace'); - if (isDict(colorSpaces)) { - var refcs = colorSpaces.get(cs.name); - if (refcs) { - cs = refcs; - } - } - } - cs = xref.fetchIfRef(cs); - if (isName(cs)) { - switch (cs.name) { - case 'DeviceGray': - case 'G': - return 'DeviceGrayCS'; - case 'DeviceRGB': - case 'RGB': - return 'DeviceRgbCS'; - case 'DeviceCMYK': - case 'CMYK': - return 'DeviceCmykCS'; - case 'Pattern': - return [ - 'PatternCS', - null - ]; - default: - error('unrecognized colorspace ' + cs.name); - } - } else if (isArray(cs)) { - var mode = xref.fetchIfRef(cs[0]).name; - var numComps, params, alt, whitePoint, blackPoint, gamma; - switch (mode) { - case 'DeviceGray': - case 'G': - return 'DeviceGrayCS'; - case 'DeviceRGB': - case 'RGB': - return 'DeviceRgbCS'; - case 'DeviceCMYK': - case 'CMYK': - return 'DeviceCmykCS'; - case 'CalGray': - params = xref.fetchIfRef(cs[1]); - whitePoint = params.getArray('WhitePoint'); - blackPoint = params.getArray('BlackPoint'); - gamma = params.get('Gamma'); - return [ - 'CalGrayCS', - whitePoint, - blackPoint, - gamma - ]; - case 'CalRGB': - params = xref.fetchIfRef(cs[1]); - whitePoint = params.getArray('WhitePoint'); - blackPoint = params.getArray('BlackPoint'); - gamma = params.getArray('Gamma'); - var matrix = params.getArray('Matrix'); - return [ - 'CalRGBCS', - whitePoint, - blackPoint, - gamma, - matrix - ]; - case 'ICCBased': - var stream = xref.fetchIfRef(cs[1]); - var dict = stream.dict; - numComps = dict.get('N'); - alt = dict.get('Alternate'); - if (alt) { - var altIR = ColorSpace.parseToIR(alt, xref, res); - var altCS = ColorSpace.fromIR(altIR); - if (altCS.numComps === numComps) { - return altIR; - } - warn('ICCBased color space: Ignoring incorrect /Alternate entry.'); - } - if (numComps === 1) { - return 'DeviceGrayCS'; - } else if (numComps === 3) { - return 'DeviceRgbCS'; - } else if (numComps === 4) { - return 'DeviceCmykCS'; - } - break; - case 'Pattern': - var basePatternCS = cs[1] || null; - if (basePatternCS) { - basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res); - } - return [ - 'PatternCS', - basePatternCS - ]; - case 'Indexed': - case 'I': - var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res); - var hiVal = xref.fetchIfRef(cs[2]) + 1; - var lookup = xref.fetchIfRef(cs[3]); - if (isStream(lookup)) { - lookup = lookup.getBytes(); - } - return [ - 'IndexedCS', - baseIndexedCS, - hiVal, - lookup - ]; - case 'Separation': - case 'DeviceN': - var name = xref.fetchIfRef(cs[1]); - numComps = isArray(name) ? name.length : 1; - alt = ColorSpace.parseToIR(cs[2], xref, res); - var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3])); - return [ - 'AlternateCS', - numComps, - alt, - tintFnIR - ]; - case 'Lab': - params = xref.fetchIfRef(cs[1]); - whitePoint = params.getArray('WhitePoint'); - blackPoint = params.getArray('BlackPoint'); - var range = params.getArray('Range'); - return [ - 'LabCS', - whitePoint, - blackPoint, - range - ]; - default: - error('unimplemented color space object "' + mode + '"'); - } - } else { - error('unrecognized color space object: "' + cs + '"'); - } - return null; - }; - ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) { - if (!isArray(decode)) { - return true; - } - if (n * 2 !== decode.length) { - warn('The decode map is not the correct length'); - return true; - } - for (var i = 0, ii = decode.length; i < ii; i += 2) { - if (decode[i] !== 0 || decode[i + 1] !== 1) { - return false; - } - } - return true; - }; - ColorSpace.singletons = { - get gray() { - return shadow(this, 'gray', new DeviceGrayCS()); - }, - get rgb() { - return shadow(this, 'rgb', new DeviceRgbCS()); - }, - get cmyk() { - return shadow(this, 'cmyk', new DeviceCmykCS()); - } - }; - return ColorSpace; - }(); - var AlternateCS = function AlternateCSClosure() { - function AlternateCS(numComps, base, tintFn) { - this.name = 'Alternate'; - this.numComps = numComps; - this.defaultColor = new Float32Array(numComps); - for (var i = 0; i < numComps; ++i) { - this.defaultColor[i] = 1; - } - this.base = base; - this.tintFn = tintFn; - this.tmpBuf = new Float32Array(base.numComps); - } - AlternateCS.prototype = { - getRgb: ColorSpace.prototype.getRgb, - getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) { - var tmpBuf = this.tmpBuf; - this.tintFn(src, srcOffset, tmpBuf, 0); - this.base.getRgbItem(tmpBuf, 0, dest, destOffset); - }, - getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - var tintFn = this.tintFn; - var base = this.base; - var scale = 1 / ((1 << bits) - 1); - var baseNumComps = base.numComps; - var usesZeroToOneRange = base.usesZeroToOneRange; - var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0; - var pos = isPassthrough ? destOffset : 0; - var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count); - var numComps = this.numComps; - var scaled = new Float32Array(numComps); - var tinted = new Float32Array(baseNumComps); - var i, j; - for (i = 0; i < count; i++) { - for (j = 0; j < numComps; j++) { - scaled[j] = src[srcOffset++] * scale; - } - tintFn(scaled, 0, tinted, 0); - if (usesZeroToOneRange) { - for (j = 0; j < baseNumComps; j++) { - baseBuf[pos++] = tinted[j] * 255; - } - } else { - base.getRgbItem(tinted, 0, baseBuf, pos); - pos += baseNumComps; - } - } - if (!isPassthrough) { - base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01); - } - }, - getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) { - return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01); - }, - isPassthrough: ColorSpace.prototype.isPassthrough, - fillRgb: ColorSpace.prototype.fillRgb, - isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) { - return ColorSpace.isDefaultDecode(decodeMap, this.numComps); - }, - usesZeroToOneRange: true - }; - return AlternateCS; - }(); - var PatternCS = function PatternCSClosure() { - function PatternCS(baseCS) { - this.name = 'Pattern'; - this.base = baseCS; - } - PatternCS.prototype = {}; - return PatternCS; - }(); - var IndexedCS = function IndexedCSClosure() { - function IndexedCS(base, highVal, lookup) { - this.name = 'Indexed'; - this.numComps = 1; - this.defaultColor = new Uint8Array(this.numComps); - this.base = base; - this.highVal = highVal; - var baseNumComps = base.numComps; - var length = baseNumComps * highVal; - if (isStream(lookup)) { - this.lookup = new Uint8Array(length); - var bytes = lookup.getBytes(length); - this.lookup.set(bytes); - } else if (isString(lookup)) { - this.lookup = new Uint8Array(length); - for (var i = 0; i < length; ++i) { - this.lookup[i] = lookup.charCodeAt(i); - } - } else if (lookup instanceof Uint8Array || lookup instanceof Array) { - this.lookup = lookup; - } else { - error('Unrecognized lookup table: ' + lookup); - } - } - IndexedCS.prototype = { - getRgb: ColorSpace.prototype.getRgb, - getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) { - var numComps = this.base.numComps; - var start = src[srcOffset] * numComps; - this.base.getRgbItem(this.lookup, start, dest, destOffset); - }, - getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - var base = this.base; - var numComps = base.numComps; - var outputDelta = base.getOutputLength(numComps, alpha01); - var lookup = this.lookup; - for (var i = 0; i < count; ++i) { - var lookupPos = src[srcOffset++] * numComps; - base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01); - destOffset += outputDelta; - } - }, - getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) { - return this.base.getOutputLength(inputLength * this.base.numComps, alpha01); - }, - isPassthrough: ColorSpace.prototype.isPassthrough, - fillRgb: ColorSpace.prototype.fillRgb, - isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) { - return true; - }, - usesZeroToOneRange: true - }; - return IndexedCS; - }(); - var DeviceGrayCS = function DeviceGrayCSClosure() { - function DeviceGrayCS() { - this.name = 'DeviceGray'; - this.numComps = 1; - this.defaultColor = new Float32Array(this.numComps); - } - DeviceGrayCS.prototype = { - getRgb: ColorSpace.prototype.getRgb, - getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) { - var c = src[srcOffset] * 255 | 0; - c = c < 0 ? 0 : c > 255 ? 255 : c; - dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c; - }, - getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - var scale = 255 / ((1 << bits) - 1); - var j = srcOffset, q = destOffset; - for (var i = 0; i < count; ++i) { - var c = scale * src[j++] | 0; - dest[q++] = c; - dest[q++] = c; - dest[q++] = c; - q += alpha01; - } - }, - getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) { - return inputLength * (3 + alpha01); - }, - isPassthrough: ColorSpace.prototype.isPassthrough, - fillRgb: ColorSpace.prototype.fillRgb, - isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) { - return ColorSpace.isDefaultDecode(decodeMap, this.numComps); - }, - usesZeroToOneRange: true - }; - return DeviceGrayCS; - }(); - var DeviceRgbCS = function DeviceRgbCSClosure() { - function DeviceRgbCS() { - this.name = 'DeviceRGB'; - this.numComps = 3; - this.defaultColor = new Float32Array(this.numComps); - } - DeviceRgbCS.prototype = { - getRgb: ColorSpace.prototype.getRgb, - getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) { - var r = src[srcOffset] * 255 | 0; - var g = src[srcOffset + 1] * 255 | 0; - var b = src[srcOffset + 2] * 255 | 0; - dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r; - dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g; - dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b; - }, - getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - if (bits === 8 && alpha01 === 0) { - dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset); - return; - } - var scale = 255 / ((1 << bits) - 1); - var j = srcOffset, q = destOffset; - for (var i = 0; i < count; ++i) { - dest[q++] = scale * src[j++] | 0; - dest[q++] = scale * src[j++] | 0; - dest[q++] = scale * src[j++] | 0; - q += alpha01; - } - }, - getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) { - return inputLength * (3 + alpha01) / 3 | 0; - }, - isPassthrough: function DeviceRgbCS_isPassthrough(bits) { - return bits === 8; - }, - fillRgb: ColorSpace.prototype.fillRgb, - isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) { - return ColorSpace.isDefaultDecode(decodeMap, this.numComps); - }, - usesZeroToOneRange: true - }; - return DeviceRgbCS; - }(); - var DeviceCmykCS = function DeviceCmykCSClosure() { - function convertToRgb(src, srcOffset, srcScale, dest, destOffset) { - var c = src[srcOffset + 0] * srcScale; - var m = src[srcOffset + 1] * srcScale; - var y = src[srcOffset + 2] * srcScale; - var k = src[srcOffset + 3] * srcScale; - var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747) + 255 | 0; - var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578) + 255 | 0; - var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367) + 255 | 0; - dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r; - dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g; - dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b; - } - function DeviceCmykCS() { - this.name = 'DeviceCMYK'; - this.numComps = 4; - this.defaultColor = new Float32Array(this.numComps); - this.defaultColor[3] = 1; - } - DeviceCmykCS.prototype = { - getRgb: ColorSpace.prototype.getRgb, - getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) { - convertToRgb(src, srcOffset, 1, dest, destOffset); - }, - getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - var scale = 1 / ((1 << bits) - 1); - for (var i = 0; i < count; i++) { - convertToRgb(src, srcOffset, scale, dest, destOffset); - srcOffset += 4; - destOffset += 3 + alpha01; - } - }, - getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) { - return inputLength / 4 * (3 + alpha01) | 0; - }, - isPassthrough: ColorSpace.prototype.isPassthrough, - fillRgb: ColorSpace.prototype.fillRgb, - isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) { - return ColorSpace.isDefaultDecode(decodeMap, this.numComps); - }, - usesZeroToOneRange: true - }; - return DeviceCmykCS; - }(); - var CalGrayCS = function CalGrayCSClosure() { - function CalGrayCS(whitePoint, blackPoint, gamma) { - this.name = 'CalGray'; - this.numComps = 1; - this.defaultColor = new Float32Array(this.numComps); - if (!whitePoint) { - error('WhitePoint missing - required for color space CalGray'); - } - blackPoint = blackPoint || [ - 0, - 0, - 0 - ]; - gamma = gamma || 1; - this.XW = whitePoint[0]; - this.YW = whitePoint[1]; - this.ZW = whitePoint[2]; - this.XB = blackPoint[0]; - this.YB = blackPoint[1]; - this.ZB = blackPoint[2]; - this.G = gamma; - if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) { - error('Invalid WhitePoint components for ' + this.name + ', no fallback available'); - } - if (this.XB < 0 || this.YB < 0 || this.ZB < 0) { - info('Invalid BlackPoint for ' + this.name + ', falling back to default'); - this.XB = this.YB = this.ZB = 0; - } - if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) { - warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.'); - } - if (this.G < 1) { - info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default'); - this.G = 1; - } - } - function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) { - var A = src[srcOffset] * scale; - var AG = Math.pow(A, cs.G); - var L = cs.YW * AG; - var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0; - dest[destOffset] = val; - dest[destOffset + 1] = val; - dest[destOffset + 2] = val; - } - CalGrayCS.prototype = { - getRgb: ColorSpace.prototype.getRgb, - getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) { - convertToRgb(this, src, srcOffset, dest, destOffset, 1); - }, - getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - var scale = 1 / ((1 << bits) - 1); - for (var i = 0; i < count; ++i) { - convertToRgb(this, src, srcOffset, dest, destOffset, scale); - srcOffset += 1; - destOffset += 3 + alpha01; - } - }, - getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) { - return inputLength * (3 + alpha01); - }, - isPassthrough: ColorSpace.prototype.isPassthrough, - fillRgb: ColorSpace.prototype.fillRgb, - isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) { - return ColorSpace.isDefaultDecode(decodeMap, this.numComps); - }, - usesZeroToOneRange: true - }; - return CalGrayCS; - }(); - var CalRGBCS = function CalRGBCSClosure() { - var BRADFORD_SCALE_MATRIX = new Float32Array([ - 0.8951, - 0.2664, - -0.1614, - -0.7502, - 1.7135, - 0.0367, - 0.0389, - -0.0685, - 1.0296 - ]); - var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([ - 0.9869929, - -0.1470543, - 0.1599627, - 0.4323053, - 0.5183603, - 0.0492912, - -0.0085287, - 0.0400428, - 0.9684867 - ]); - var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([ - 3.2404542, - -1.5371385, - -0.4985314, - -0.9692660, - 1.8760108, - 0.0415560, - 0.0556434, - -0.2040259, - 1.0572252 - ]); - var FLAT_WHITEPOINT_MATRIX = new Float32Array([ - 1, - 1, - 1 - ]); - var tempNormalizeMatrix = new Float32Array(3); - var tempConvertMatrix1 = new Float32Array(3); - var tempConvertMatrix2 = new Float32Array(3); - var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0; - function CalRGBCS(whitePoint, blackPoint, gamma, matrix) { - this.name = 'CalRGB'; - this.numComps = 3; - this.defaultColor = new Float32Array(this.numComps); - if (!whitePoint) { - error('WhitePoint missing - required for color space CalRGB'); - } - blackPoint = blackPoint || new Float32Array(3); - gamma = gamma || new Float32Array([ - 1, - 1, - 1 - ]); - matrix = matrix || new Float32Array([ - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 1 - ]); - var XW = whitePoint[0]; - var YW = whitePoint[1]; - var ZW = whitePoint[2]; - this.whitePoint = whitePoint; - var XB = blackPoint[0]; - var YB = blackPoint[1]; - var ZB = blackPoint[2]; - this.blackPoint = blackPoint; - this.GR = gamma[0]; - this.GG = gamma[1]; - this.GB = gamma[2]; - this.MXA = matrix[0]; - this.MYA = matrix[1]; - this.MZA = matrix[2]; - this.MXB = matrix[3]; - this.MYB = matrix[4]; - this.MZB = matrix[5]; - this.MXC = matrix[6]; - this.MYC = matrix[7]; - this.MZC = matrix[8]; - if (XW < 0 || ZW < 0 || YW !== 1) { - error('Invalid WhitePoint components for ' + this.name + ', no fallback available'); - } - if (XB < 0 || YB < 0 || ZB < 0) { - info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default'); - this.blackPoint = new Float32Array(3); - } - if (this.GR < 0 || this.GG < 0 || this.GB < 0) { - info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default'); - this.GR = this.GG = this.GB = 1; - } - if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 || this.MXB < 0 || this.MYB < 0 || this.MZB < 0 || this.MXC < 0 || this.MYC < 0 || this.MZC < 0) { - info('Invalid Matrix for ' + this.name + ' [' + this.MXA + ', ' + this.MYA + ', ' + this.MZA + this.MXB + ', ' + this.MYB + ', ' + this.MZB + this.MXC + ', ' + this.MYC + ', ' + this.MZC + '], falling back to default'); - this.MXA = this.MYB = this.MZC = 1; - this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0; - } - } - function matrixProduct(a, b, result) { - result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; - result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2]; - result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2]; - } - function convertToFlat(sourceWhitePoint, LMS, result) { - result[0] = LMS[0] * 1 / sourceWhitePoint[0]; - result[1] = LMS[1] * 1 / sourceWhitePoint[1]; - result[2] = LMS[2] * 1 / sourceWhitePoint[2]; - } - function convertToD65(sourceWhitePoint, LMS, result) { - var D65X = 0.95047; - var D65Y = 1; - var D65Z = 1.08883; - result[0] = LMS[0] * D65X / sourceWhitePoint[0]; - result[1] = LMS[1] * D65Y / sourceWhitePoint[1]; - result[2] = LMS[2] * D65Z / sourceWhitePoint[2]; - } - function sRGBTransferFunction(color) { - if (color <= 0.0031308) { - return adjustToRange(0, 1, 12.92 * color); - } - return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055); - } - function adjustToRange(min, max, value) { - return Math.max(min, Math.min(max, value)); - } - function decodeL(L) { - if (L < 0) { - return -decodeL(-L); - } - if (L > 8.0) { - return Math.pow((L + 16) / 116, 3); - } - return L * DECODE_L_CONSTANT; - } - function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) { - if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) { - result[0] = XYZ_Flat[0]; - result[1] = XYZ_Flat[1]; - result[2] = XYZ_Flat[2]; - return; - } - var zeroDecodeL = decodeL(0); - var X_DST = zeroDecodeL; - var X_SRC = decodeL(sourceBlackPoint[0]); - var Y_DST = zeroDecodeL; - var Y_SRC = decodeL(sourceBlackPoint[1]); - var Z_DST = zeroDecodeL; - var Z_SRC = decodeL(sourceBlackPoint[2]); - var X_Scale = (1 - X_DST) / (1 - X_SRC); - var X_Offset = 1 - X_Scale; - var Y_Scale = (1 - Y_DST) / (1 - Y_SRC); - var Y_Offset = 1 - Y_Scale; - var Z_Scale = (1 - Z_DST) / (1 - Z_SRC); - var Z_Offset = 1 - Z_Scale; - result[0] = XYZ_Flat[0] * X_Scale + X_Offset; - result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset; - result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset; - } - function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) { - if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) { - result[0] = XYZ_In[0]; - result[1] = XYZ_In[1]; - result[2] = XYZ_In[2]; - return; - } - var LMS = result; - matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS); - var LMS_Flat = tempNormalizeMatrix; - convertToFlat(sourceWhitePoint, LMS, LMS_Flat); - matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result); - } - function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) { - var LMS = result; - matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS); - var LMS_D65 = tempNormalizeMatrix; - convertToD65(sourceWhitePoint, LMS, LMS_D65); - matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result); - } - function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) { - var A = adjustToRange(0, 1, src[srcOffset] * scale); - var B = adjustToRange(0, 1, src[srcOffset + 1] * scale); - var C = adjustToRange(0, 1, src[srcOffset + 2] * scale); - var AGR = Math.pow(A, cs.GR); - var BGG = Math.pow(B, cs.GG); - var CGB = Math.pow(C, cs.GB); - var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB; - var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB; - var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB; - var XYZ = tempConvertMatrix1; - XYZ[0] = X; - XYZ[1] = Y; - XYZ[2] = Z; - var XYZ_Flat = tempConvertMatrix2; - normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat); - var XYZ_Black = tempConvertMatrix1; - compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black); - var XYZ_D65 = tempConvertMatrix2; - normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65); - var SRGB = tempConvertMatrix1; - matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB); - var sR = sRGBTransferFunction(SRGB[0]); - var sG = sRGBTransferFunction(SRGB[1]); - var sB = sRGBTransferFunction(SRGB[2]); - dest[destOffset] = Math.round(sR * 255); - dest[destOffset + 1] = Math.round(sG * 255); - dest[destOffset + 2] = Math.round(sB * 255); - } - CalRGBCS.prototype = { - getRgb: function CalRGBCS_getRgb(src, srcOffset) { - var rgb = new Uint8Array(3); - this.getRgbItem(src, srcOffset, rgb, 0); - return rgb; - }, - getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) { - convertToRgb(this, src, srcOffset, dest, destOffset, 1); - }, - getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - var scale = 1 / ((1 << bits) - 1); - for (var i = 0; i < count; ++i) { - convertToRgb(this, src, srcOffset, dest, destOffset, scale); - srcOffset += 3; - destOffset += 3 + alpha01; - } - }, - getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) { - return inputLength * (3 + alpha01) / 3 | 0; - }, - isPassthrough: ColorSpace.prototype.isPassthrough, - fillRgb: ColorSpace.prototype.fillRgb, - isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) { - return ColorSpace.isDefaultDecode(decodeMap, this.numComps); - }, - usesZeroToOneRange: true - }; - return CalRGBCS; - }(); - var LabCS = function LabCSClosure() { - function LabCS(whitePoint, blackPoint, range) { - this.name = 'Lab'; - this.numComps = 3; - this.defaultColor = new Float32Array(this.numComps); - if (!whitePoint) { - error('WhitePoint missing - required for color space Lab'); - } - blackPoint = blackPoint || [ - 0, - 0, - 0 - ]; - range = range || [ - -100, - 100, - -100, - 100 - ]; - this.XW = whitePoint[0]; - this.YW = whitePoint[1]; - this.ZW = whitePoint[2]; - this.amin = range[0]; - this.amax = range[1]; - this.bmin = range[2]; - this.bmax = range[3]; - this.XB = blackPoint[0]; - this.YB = blackPoint[1]; - this.ZB = blackPoint[2]; - if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) { - error('Invalid WhitePoint components, no fallback available'); - } - if (this.XB < 0 || this.YB < 0 || this.ZB < 0) { - info('Invalid BlackPoint, falling back to default'); - this.XB = this.YB = this.ZB = 0; - } - if (this.amin > this.amax || this.bmin > this.bmax) { - info('Invalid Range, falling back to defaults'); - this.amin = -100; - this.amax = 100; - this.bmin = -100; - this.bmax = 100; - } - } - function fn_g(x) { - var result; - if (x >= 6 / 29) { - result = x * x * x; - } else { - result = 108 / 841 * (x - 4 / 29); - } - return result; - } - function decode(value, high1, low2, high2) { - return low2 + value * (high2 - low2) / high1; - } - function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) { - var Ls = src[srcOffset]; - var as = src[srcOffset + 1]; - var bs = src[srcOffset + 2]; - if (maxVal !== false) { - Ls = decode(Ls, maxVal, 0, 100); - as = decode(as, maxVal, cs.amin, cs.amax); - bs = decode(bs, maxVal, cs.bmin, cs.bmax); - } - as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as; - bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs; - var M = (Ls + 16) / 116; - var L = M + as / 500; - var N = M - bs / 200; - var X = cs.XW * fn_g(L); - var Y = cs.YW * fn_g(M); - var Z = cs.ZW * fn_g(N); - var r, g, b; - if (cs.ZW < 1) { - r = X * 3.1339 + Y * -1.6170 + Z * -0.4906; - g = X * -0.9785 + Y * 1.9160 + Z * 0.0333; - b = X * 0.0720 + Y * -0.2290 + Z * 1.4057; - } else { - r = X * 3.2406 + Y * -1.5372 + Z * -0.4986; - g = X * -0.9689 + Y * 1.8758 + Z * 0.0415; - b = X * 0.0557 + Y * -0.2040 + Z * 1.0570; - } - dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0; - dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0; - dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0; - } - LabCS.prototype = { - getRgb: ColorSpace.prototype.getRgb, - getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) { - convertToRgb(this, src, srcOffset, false, dest, destOffset); - }, - getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) { - var maxVal = (1 << bits) - 1; - for (var i = 0; i < count; i++) { - convertToRgb(this, src, srcOffset, maxVal, dest, destOffset); - srcOffset += 3; - destOffset += 3 + alpha01; - } - }, - getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) { - return inputLength * (3 + alpha01) / 3 | 0; - }, - isPassthrough: ColorSpace.prototype.isPassthrough, - fillRgb: ColorSpace.prototype.fillRgb, - isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) { - return true; - }, - usesZeroToOneRange: false - }; - return LabCS; - }(); - exports.ColorSpace = ColorSpace; - })); (function (root, factory) { factory(root.pdfjsCoreImage = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream, root.pdfjsCoreJpx); }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace, coreStream, coreJpx) { @@ -44188,6 +44190,7 @@ var warn = sharedUtil.warn; var Dict = corePrimitives.Dict; var Name = corePrimitives.Name; + var isEOF = corePrimitives.isEOF; var isCmd = corePrimitives.isCmd; var isDict = corePrimitives.isDict; var isName = corePrimitives.isName; @@ -44198,7 +44201,6 @@ var Stream = coreStream.Stream; var Lexer = coreParser.Lexer; var Parser = coreParser.Parser; - var isEOF = coreParser.isEOF; var PDFImage = coreImage.PDFImage; var ColorSpace = coreColorSpace.ColorSpace; var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64; diff --git a/browser/extensions/pdfjs/content/pdfjschildbootstrap.js b/browser/extensions/pdfjs/content/pdfjschildbootstrap.js index 2051e3055d56..b4d7515dc12b 100644 --- a/browser/extensions/pdfjs/content/pdfjschildbootstrap.js +++ b/browser/extensions/pdfjs/content/pdfjschildbootstrap.js @@ -14,16 +14,16 @@ */ /* globals Components, PdfjsContentUtils, PdfJs, Services */ -'use strict'; +"use strict"; /* * pdfjschildbootstrap.js loads into the content process to take care of * initializing our built-in version of pdfjs when running remote. */ -Components.utils.import('resource://gre/modules/Services.jsm'); -Components.utils.import('resource://pdf.js/PdfJs.jsm'); -Components.utils.import('resource://pdf.js/PdfjsContentUtils.jsm'); +Components.utils.import("resource://gre/modules/Services.jsm"); +Components.utils.import("resource://pdf.js/PdfJs.jsm"); +Components.utils.import("resource://pdf.js/PdfjsContentUtils.jsm"); // init content utils shim pdfjs will use to access privileged apis. PdfjsContentUtils.init(); diff --git a/browser/extensions/pdfjs/content/web/l10n.js b/browser/extensions/pdfjs/content/web/l10n.js index 3fd173b8ebf8..0659f0e8c1b5 100644 --- a/browser/extensions/pdfjs/content/web/l10n.js +++ b/browser/extensions/pdfjs/content/web/l10n.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; // Small subset of the webL10n API by Fabien Cazenave for pdf.js extension. (function(window) { - var gLanguage = ''; + var gLanguage = ""; var gExternalLocalizerServices = null; - var gReadyState = 'loading'; + var gReadyState = "loading"; // fetch an l10n objects function getL10nData(key) { var response = gExternalLocalizerServices.getStrings(key); var data = JSON.parse(response); if (!data) { - console.warn('[l10n] #' + key + ' missing for [' + gLanguage + ']'); + console.warn("[l10n] #" + key + " missing for [" + gLanguage + "]"); } return data; } @@ -22,25 +22,25 @@ return text; } return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function(all, name) { - return (name in args ? args[name] : '{{' + name + '}}'); + return (name in args ? args[name] : "{{" + name + "}}"); }); } // translate a string function translateString(key, args, fallback) { - var i = key.lastIndexOf('.'); + var i = key.lastIndexOf("."); var name, property; if (i >= 0) { name = key.substring(0, i); property = key.substring(i + 1); } else { name = key; - property = 'textContent'; + property = "textContent"; } var data = getL10nData(name); var value = (data && data[property]) || fallback; if (!value) { - return '{{' + key + '}}'; + return "{{" + key + "}}"; } return substArguments(value, args); } @@ -65,7 +65,7 @@ try { args = JSON.parse(element.dataset.l10nArgs); } catch (e) { - console.warn('[l10n] could not parse arguments for #' + key + ''); + console.warn("[l10n] could not parse arguments for #" + key + ""); } } @@ -79,10 +79,10 @@ // translate an HTML subtree function translateFragment(element) { - element = element || document.querySelector('html'); + element = element || document.querySelector("html"); // check all translatable children (= w/ a `data-l10n-id' attribute) - var children = element.querySelectorAll('*[data-l10n-id]'); + var children = element.querySelectorAll("*[data-l10n-id]"); var elementCount = children.length; for (var i = 0; i < elementCount; i++) { translateElement(children[i]); @@ -99,16 +99,16 @@ translateFragment(); - gReadyState = 'complete'; + gReadyState = "complete"; // fire a 'localized' DOM event - var evtObject = document.createEvent('Event'); - evtObject.initEvent('localized', false, false); + var evtObject = document.createEvent("Event"); + evtObject.initEvent("localized", false, false); evtObject.language = gLanguage; window.dispatchEvent(evtObject); } - window.addEventListener('DOMContentLoaded', function() { + window.addEventListener("DOMContentLoaded", function() { if (gExternalLocalizerServices) { translateDocument(); } @@ -129,12 +129,12 @@ getDirection() { // http://www.w3.org/International/questions/qa-scripts // Arabic, Hebrew, Farsi, Pashto, Urdu - var rtlList = ['ar', 'he', 'fa', 'ps', 'ur']; + var rtlList = ["ar", "he", "fa", "ps", "ur"]; // use the short language code for "full" codes like 'ar-sa' (issue 5440) - var shortCode = gLanguage.split('-')[0]; + var shortCode = gLanguage.split("-")[0]; - return (rtlList.indexOf(shortCode) >= 0) ? 'rtl' : 'ltr'; + return (rtlList.indexOf(shortCode) >= 0) ? "rtl" : "ltr"; }, getReadyState() { @@ -145,8 +145,8 @@ gExternalLocalizerServices = externalLocalizerServices; // ... in case if we missed DOMContentLoaded above. - if (window.document.readyState === 'interactive' || - window.document.readyState === 'complete') { + if (window.document.readyState === "interactive" || + window.document.readyState === "complete") { translateDocument(); } }, diff --git a/browser/extensions/pdfjs/content/web/viewer.js b/browser/extensions/pdfjs/content/web/viewer.js index 1318c24de05d..96348ac47545 100644 --- a/browser/extensions/pdfjs/content/web/viewer.js +++ b/browser/extensions/pdfjs/content/web/viewer.js @@ -125,7 +125,7 @@ var pdfjsWebLibs; this.document.removeEventListener('mousemove', this._onmousemove, true); this.document.removeEventListener('mouseup', this._endPan, true); if (this.overlay.parentNode) { - this.overlay.remove(); + this.overlay.parentNode.removeChild(this.overlay); } } };