mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Merge pull request #18465 from Snuffleupagus/issue-18210
Disable system fonts on Android (issue 18210)
This commit is contained in:
commit
0c34efbef9
4 changed files with 63 additions and 24 deletions
10
web/app.js
10
web/app.js
|
@ -1004,16 +1004,6 @@ const PDFViewerApplication = {
|
||||||
AppOptions.set("docBaseUrl", this.baseUrl);
|
AppOptions.set("docBaseUrl", this.baseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// On Android, there is almost no chance to have the font we want so we
|
|
||||||
// don't use the system fonts in this case.
|
|
||||||
if (
|
|
||||||
typeof PDFJSDev === "undefined"
|
|
||||||
? window.isGECKOVIEW
|
|
||||||
: PDFJSDev.test("GECKOVIEW")
|
|
||||||
) {
|
|
||||||
args.useSystemFonts = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the necessary API parameters, using all the available options.
|
// Set the necessary API parameters, using all the available options.
|
||||||
const apiParams = AppOptions.getAll(OptionKind.API);
|
const apiParams = AppOptions.getAll(OptionKind.API);
|
||||||
const loadingTask = getDocument({
|
const loadingTask = getDocument({
|
||||||
|
|
|
@ -39,6 +39,14 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||||
compatParams.set("maxCanvasPixels", 5242880);
|
compatParams.set("maxCanvasPixels", 5242880);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// Don't use system fonts on Android (issue 18210).
|
||||||
|
// Support: Android
|
||||||
|
(function () {
|
||||||
|
if (isAndroid) {
|
||||||
|
compatParams.set("useSystemFonts", false);
|
||||||
|
}
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
const OptionKind = {
|
const OptionKind = {
|
||||||
|
@ -47,6 +55,7 @@ const OptionKind = {
|
||||||
API: 0x04,
|
API: 0x04,
|
||||||
WORKER: 0x08,
|
WORKER: 0x08,
|
||||||
EVENT_DISPATCH: 0x10,
|
EVENT_DISPATCH: 0x10,
|
||||||
|
UNDEF_ALLOWED: 0x20,
|
||||||
PREFERENCE: 0x80,
|
PREFERENCE: 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -385,6 +394,19 @@ const defaultOptions = {
|
||||||
: "../web/standard_fonts/",
|
: "../web/standard_fonts/",
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API,
|
||||||
},
|
},
|
||||||
|
useSystemFonts: {
|
||||||
|
// On Android, there is almost no chance to have the font we want so we
|
||||||
|
// don't use the system fonts in this case (bug 1882613).
|
||||||
|
/** @type {boolean|undefined} */
|
||||||
|
value: (
|
||||||
|
typeof PDFJSDev === "undefined"
|
||||||
|
? window.isGECKOVIEW
|
||||||
|
: PDFJSDev.test("GECKOVIEW")
|
||||||
|
)
|
||||||
|
? false
|
||||||
|
: undefined,
|
||||||
|
kind: OptionKind.API + OptionKind.UNDEF_ALLOWED,
|
||||||
|
},
|
||||||
verbosity: {
|
verbosity: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: 1,
|
value: 1,
|
||||||
|
@ -472,6 +494,11 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
|
||||||
if (kind & OptionKind.BROWSER) {
|
if (kind & OptionKind.BROWSER) {
|
||||||
throw new Error(`Cannot mix "PREFERENCE" and "BROWSER" kind: ${name}`);
|
throw new Error(`Cannot mix "PREFERENCE" and "BROWSER" kind: ${name}`);
|
||||||
}
|
}
|
||||||
|
if (kind & OptionKind.UNDEF_ALLOWED) {
|
||||||
|
throw new Error(
|
||||||
|
`Cannot allow \`undefined\` value for "PREFERENCE" kind: ${name}`
|
||||||
|
);
|
||||||
|
}
|
||||||
if (typeof compatParams === "object" && compatParams.has(name)) {
|
if (typeof compatParams === "object" && compatParams.has(name)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Should not have compatibility-value for "PREFERENCE" kind: ${name}`
|
`Should not have compatibility-value for "PREFERENCE" kind: ${name}`
|
||||||
|
@ -486,6 +513,11 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
|
||||||
throw new Error(`Invalid value for "PREFERENCE" kind: ${name}`);
|
throw new Error(`Invalid value for "PREFERENCE" kind: ${name}`);
|
||||||
}
|
}
|
||||||
} else if (kind & OptionKind.BROWSER) {
|
} else if (kind & OptionKind.BROWSER) {
|
||||||
|
if (kind & OptionKind.UNDEF_ALLOWED) {
|
||||||
|
throw new Error(
|
||||||
|
`Cannot allow \`undefined\` value for "BROWSER" kind: ${name}`
|
||||||
|
);
|
||||||
|
}
|
||||||
if (typeof compatParams === "object" && compatParams.has(name)) {
|
if (typeof compatParams === "object" && compatParams.has(name)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Should not have compatibility-value for "BROWSER" kind: ${name}`
|
`Should not have compatibility-value for "BROWSER" kind: ${name}`
|
||||||
|
@ -514,23 +546,30 @@ class AppOptions {
|
||||||
static getAll(kind = null, defaultOnly = false) {
|
static getAll(kind = null, defaultOnly = false) {
|
||||||
const options = Object.create(null);
|
const options = Object.create(null);
|
||||||
for (const name in defaultOptions) {
|
for (const name in defaultOptions) {
|
||||||
const defaultOption = defaultOptions[name];
|
const defaultOpt = defaultOptions[name];
|
||||||
|
|
||||||
if (kind && !(kind & defaultOption.kind)) {
|
if (kind && !(kind & defaultOpt.kind)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
options[name] =
|
options[name] =
|
||||||
!defaultOnly && userOptions.has(name)
|
!defaultOnly && userOptions.has(name)
|
||||||
? userOptions.get(name)
|
? userOptions.get(name)
|
||||||
: defaultOption.value;
|
: defaultOpt.value;
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
static set(name, value) {
|
static set(name, value) {
|
||||||
const defaultOption = defaultOptions[name];
|
const defaultOpt = defaultOptions[name];
|
||||||
|
|
||||||
if (!defaultOption || typeof value !== typeof defaultOption.value) {
|
if (
|
||||||
|
!defaultOpt ||
|
||||||
|
!(
|
||||||
|
typeof value === typeof defaultOpt.value ||
|
||||||
|
(defaultOpt.kind & OptionKind.UNDEF_ALLOWED &&
|
||||||
|
(value === undefined || defaultOpt.value === undefined))
|
||||||
|
)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
userOptions.set(name, value);
|
userOptions.set(name, value);
|
||||||
|
@ -540,23 +579,30 @@ class AppOptions {
|
||||||
let events;
|
let events;
|
||||||
|
|
||||||
for (const name in options) {
|
for (const name in options) {
|
||||||
const defaultOption = defaultOptions[name],
|
const defaultOpt = defaultOptions[name],
|
||||||
userOption = options[name];
|
userOpt = options[name];
|
||||||
|
|
||||||
if (!defaultOption || typeof userOption !== typeof defaultOption.value) {
|
if (
|
||||||
|
!defaultOpt ||
|
||||||
|
!(
|
||||||
|
typeof userOpt === typeof defaultOpt.value ||
|
||||||
|
(defaultOpt.kind & OptionKind.UNDEF_ALLOWED &&
|
||||||
|
(userOpt === undefined || defaultOpt.value === undefined))
|
||||||
|
)
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (prefs) {
|
if (prefs) {
|
||||||
const { kind } = defaultOption;
|
const { kind } = defaultOpt;
|
||||||
|
|
||||||
if (!(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) {
|
if (!(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
|
if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
|
||||||
(events ||= new Map()).set(name, userOption);
|
(events ||= new Map()).set(name, userOpt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userOptions.set(name, userOption);
|
userOptions.set(name, userOpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events) {
|
if (events) {
|
||||||
|
|
|
@ -42,6 +42,12 @@ See https://github.com/adobe-type-tools/cmap-resources
|
||||||
<!--#endif-->
|
<!--#endif-->
|
||||||
|
|
||||||
<!--#if !MOZCENTRAL-->
|
<!--#if !MOZCENTRAL-->
|
||||||
|
<script>
|
||||||
|
if (typeof PDFJSDev === "undefined") {
|
||||||
|
window.isGECKOVIEW = true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script type="importmap">
|
<script type="importmap">
|
||||||
{
|
{
|
||||||
"imports": {
|
"imports": {
|
||||||
|
|
|
@ -60,9 +60,6 @@ function getViewerConfiguration() {
|
||||||
function webViewerLoad() {
|
function webViewerLoad() {
|
||||||
const config = getViewerConfiguration();
|
const config = getViewerConfiguration();
|
||||||
|
|
||||||
if (typeof PDFJSDev === "undefined") {
|
|
||||||
window.isGECKOVIEW = true;
|
|
||||||
}
|
|
||||||
PDFViewerApplication.run(config);
|
PDFViewerApplication.run(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue