Detecting if web fonts are disable in Firefox.

This commit is contained in:
Yury Delendik 2012-11-30 16:59:51 -06:00
parent 223ad0c117
commit 5dc87a7fca
4 changed files with 49 additions and 0 deletions

View File

@ -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) {
let str = Cc['@mozilla.org/supports-string;1']
.createInstance(Ci.nsISupportsString);
@ -351,6 +359,10 @@ ChromeActions.prototype = {
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) {
var self = this;
var domWindow = this.domWindow;

View File

@ -120,3 +120,4 @@ text_annotation_type=[{{type}} Annotation]
request_password=PDF is protected by a password:
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.

View File

@ -90,6 +90,13 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
get 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.
* @return {Promise} A promise that is resolved with a {PDFPageProxy}
@ -340,6 +347,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
fontObjs.push(obj);
}
this.transport.embeddedFontsUsed = this.transport.embeddedFontsUsed ||
fontObjs.length > 0;
// Load all the fonts
FontLoader.bind(
fontObjs,
@ -443,6 +453,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.pageCache = [];
this.pagePromises = [];
this.fontsLoading = {};
this.embeddedFontsUsed = false;
// 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

View File

@ -882,6 +882,19 @@ var PDFView = {
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() {
if (!PDFView.loadingBar) {
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
@ -2035,6 +2048,10 @@ var PageView = function pageView(container, pdfPage, id, scale,
if (outputScale.scaled) {
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
@ -2047,6 +2064,14 @@ var PageView = function pageView(container, pdfPage, id, scale,
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) {
PDFView.error(mozL10n.get('rendering_error', null,
'An error occurred while rendering the page.'), error);