Detecting if web fonts are disable in Firefox.
This commit is contained in:
parent
223ad0c117
commit
5dc87a7fca
@ -71,6 +71,14 @@ function getBoolPref(pref, def) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getIntPref(pref, def) {
|
||||||
|
try {
|
||||||
|
return Services.prefs.getIntPref(pref);
|
||||||
|
} catch (ex) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setStringPref(pref, value) {
|
function setStringPref(pref, value) {
|
||||||
let str = Cc['@mozilla.org/supports-string;1']
|
let str = Cc['@mozilla.org/supports-string;1']
|
||||||
.createInstance(Ci.nsISupportsString);
|
.createInstance(Ci.nsISupportsString);
|
||||||
@ -351,6 +359,10 @@ ChromeActions.prototype = {
|
|||||||
getChromeWindow(this.domWindow).gFindBar &&
|
getChromeWindow(this.domWindow).gFindBar &&
|
||||||
'updateControlState' in getChromeWindow(this.domWindow).gFindBar;
|
'updateControlState' in getChromeWindow(this.domWindow).gFindBar;
|
||||||
},
|
},
|
||||||
|
supportsDocumentFonts: function() {
|
||||||
|
var pref = getIntPref('browser.display.use_document_fonts', 1);
|
||||||
|
return !!pref;
|
||||||
|
},
|
||||||
fallback: function(url, sendResponse) {
|
fallback: function(url, sendResponse) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var domWindow = this.domWindow;
|
var domWindow = this.domWindow;
|
||||||
|
@ -120,3 +120,4 @@ text_annotation_type=[{{type}} Annotation]
|
|||||||
request_password=PDF is protected by a password:
|
request_password=PDF is protected by a password:
|
||||||
|
|
||||||
printing_not_supported=Warning: Printing is not fully supported by this browser.
|
printing_not_supported=Warning: Printing is not fully supported by this browser.
|
||||||
|
web_fonts_disabled=Web fonts are disabled: unable to use embedded PDF fonts.
|
||||||
|
11
src/api.js
11
src/api.js
@ -90,6 +90,13 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||||||
get fingerprint() {
|
get fingerprint() {
|
||||||
return this.pdfInfo.fingerprint;
|
return this.pdfInfo.fingerprint;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* @return {boolean} true if embedded document fonts are in use. Will be
|
||||||
|
* set during rendering of the pages.
|
||||||
|
*/
|
||||||
|
get embeddedFontsUsed() {
|
||||||
|
return this.transport.embeddedFontsUsed;
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* @param {number} The page number to get. The first page is 1.
|
* @param {number} The page number to get. The first page is 1.
|
||||||
* @return {Promise} A promise that is resolved with a {PDFPageProxy}
|
* @return {Promise} A promise that is resolved with a {PDFPageProxy}
|
||||||
@ -340,6 +347,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
fontObjs.push(obj);
|
fontObjs.push(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.transport.embeddedFontsUsed = this.transport.embeddedFontsUsed ||
|
||||||
|
fontObjs.length > 0;
|
||||||
|
|
||||||
// Load all the fonts
|
// Load all the fonts
|
||||||
FontLoader.bind(
|
FontLoader.bind(
|
||||||
fontObjs,
|
fontObjs,
|
||||||
@ -443,6 +453,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
this.pageCache = [];
|
this.pageCache = [];
|
||||||
this.pagePromises = [];
|
this.pagePromises = [];
|
||||||
this.fontsLoading = {};
|
this.fontsLoading = {};
|
||||||
|
this.embeddedFontsUsed = false;
|
||||||
|
|
||||||
// If worker support isn't disabled explicit and the browser has worker
|
// If worker support isn't disabled explicit and the browser has worker
|
||||||
// support, create a new web worker and test if it/the browser fullfills
|
// support, create a new web worker and test if it/the browser fullfills
|
||||||
|
@ -882,6 +882,19 @@ var PDFView = {
|
|||||||
return support;
|
return support;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get supportsDocumentFonts() {
|
||||||
|
var support = true;
|
||||||
|
//#if !(FIREFOX || MOZCENTRAL)
|
||||||
|
//#else
|
||||||
|
// support = FirefoxCom.requestSync('supportsDocumentFonts');
|
||||||
|
//#endif
|
||||||
|
Object.defineProperty(this, 'supportsDocumentFonts', { value: support,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true,
|
||||||
|
writable: false });
|
||||||
|
return support;
|
||||||
|
},
|
||||||
|
|
||||||
initPassiveLoading: function pdfViewInitPassiveLoading() {
|
initPassiveLoading: function pdfViewInitPassiveLoading() {
|
||||||
if (!PDFView.loadingBar) {
|
if (!PDFView.loadingBar) {
|
||||||
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
|
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
|
||||||
@ -2035,6 +2048,10 @@ var PageView = function pageView(container, pdfPage, id, scale,
|
|||||||
if (outputScale.scaled) {
|
if (outputScale.scaled) {
|
||||||
ctx.scale(outputScale.sx, outputScale.sy);
|
ctx.scale(outputScale.sx, outputScale.sy);
|
||||||
}
|
}
|
||||||
|
//#if (FIREFOX || MOZCENTRAL)
|
||||||
|
// // Checking if document fonts are used only once
|
||||||
|
// var checkIfDocumentFontsUsed = !PDFView.pdfDocument.embeddedFontsUsed;
|
||||||
|
//#endif
|
||||||
|
|
||||||
// Rendering area
|
// Rendering area
|
||||||
|
|
||||||
@ -2047,6 +2064,14 @@ var PageView = function pageView(container, pdfPage, id, scale,
|
|||||||
delete self.loadingIconDiv;
|
delete self.loadingIconDiv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#if (FIREFOX || MOZCENTRAL)
|
||||||
|
// if (checkIfDocumentFontsUsed && PDFView.pdfDocument.embeddedFontsUsed &&
|
||||||
|
// !PDFView.supportsDocumentFonts) {
|
||||||
|
// console.error(mozL10n.get('web_fonts_disabled', null,
|
||||||
|
// 'Web fonts are disabled: unable to use embedded PDF fonts.'));
|
||||||
|
// PDFView.fallback();
|
||||||
|
// }
|
||||||
|
//#endif
|
||||||
if (error) {
|
if (error) {
|
||||||
PDFView.error(mozL10n.get('rendering_error', null,
|
PDFView.error(mozL10n.get('rendering_error', null,
|
||||||
'An error occurred while rendering the page.'), error);
|
'An error occurred while rendering the page.'), error);
|
||||||
|
Loading…
Reference in New Issue
Block a user