1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Add a pref to know if the alt-text must be automatically generated (bug 1909310)

This commit is contained in:
Calixte Denizet 2024-07-22 22:09:08 +02:00
parent 91655aae7f
commit 042183b89b
4 changed files with 21 additions and 12 deletions

View file

@ -205,10 +205,10 @@ const PDFViewerApplication = {
if (mode) {
document.documentElement.classList.add(mode);
}
} else {
} else if (AppOptions.get("enableAltText")) {
// We want to load the image-to-text AI engine as soon as possible.
this.mlManager = new MLManager({
enableAltText: AppOptions.get("enableAltText"),
enableGuessAltText: AppOptions.get("enableGuessAltText"),
altTextLearnMoreUrl: AppOptions.get("altTextLearnMoreUrl"),
});
}
@ -376,14 +376,14 @@ const PDFViewerApplication = {
let eventBus;
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
eventBus =
AppOptions.eventBus =
this.mlManager.eventBus =
new FirefoxEventBus(
AppOptions.get("allowedGlobalEvents"),
externalServices,
AppOptions.get("isInAutomation")
);
eventBus = AppOptions.eventBus = new FirefoxEventBus(
AppOptions.get("allowedGlobalEvents"),
externalServices,
AppOptions.get("isInAutomation")
);
if (this.mlManager) {
this.mlManager.eventBus = eventBus;
}
} else {
eventBus = new EventBus();
}

View file

@ -179,6 +179,11 @@ const defaultOptions = {
value: false,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
enableGuessAltText: {
/** @type {boolean} */
value: true,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
enableHighlightEditor: {
// We'll probably want to make some experiments before enabling this
// in Firefox release, but it has to be temporary.

View file

@ -328,8 +328,8 @@ class MLManager {
return FirefoxCom.requestAsync("mlGuess", data);
}
enable({ altTextLearnMoreUrl, enableAltText, listenToProgress }) {
if (enableAltText) {
enable({ altTextLearnMoreUrl, enableGuessAltText, listenToProgress }) {
if (enableGuessAltText) {
this.#loadAltTextEngine(listenToProgress);
}
// The `altTextLearnMoreUrl` is used to provide a link to the user to learn