Skip to content

Commit 0c34efb

Browse files
Merge pull request #18465 from Snuffleupagus/issue-18210
Disable system fonts on Android (issue 18210)
2 parents d0b580e + 80d6bf6 commit 0c34efb

File tree

4 files changed

+63
-24
lines changed

4 files changed

+63
-24
lines changed

web/app.js

-10
Original file line numberDiff line numberDiff line change
@@ -1004,16 +1004,6 @@ const PDFViewerApplication = {
10041004
AppOptions.set("docBaseUrl", this.baseUrl);
10051005
}
10061006

1007-
// On Android, there is almost no chance to have the font we want so we
1008-
// don't use the system fonts in this case.
1009-
if (
1010-
typeof PDFJSDev === "undefined"
1011-
? window.isGECKOVIEW
1012-
: PDFJSDev.test("GECKOVIEW")
1013-
) {
1014-
args.useSystemFonts = false;
1015-
}
1016-
10171007
// Set the necessary API parameters, using all the available options.
10181008
const apiParams = AppOptions.getAll(OptionKind.API);
10191009
const loadingTask = getDocument({

web/app_options.js

+57-11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
3939
compatParams.set("maxCanvasPixels", 5242880);
4040
}
4141
})();
42+
43+
// Don't use system fonts on Android (issue 18210).
44+
// Support: Android
45+
(function () {
46+
if (isAndroid) {
47+
compatParams.set("useSystemFonts", false);
48+
}
49+
})();
4250
}
4351

4452
const OptionKind = {
@@ -47,6 +55,7 @@ const OptionKind = {
4755
API: 0x04,
4856
WORKER: 0x08,
4957
EVENT_DISPATCH: 0x10,
58+
UNDEF_ALLOWED: 0x20,
5059
PREFERENCE: 0x80,
5160
};
5261

@@ -385,6 +394,19 @@ const defaultOptions = {
385394
: "../web/standard_fonts/",
386395
kind: OptionKind.API,
387396
},
397+
useSystemFonts: {
398+
// On Android, there is almost no chance to have the font we want so we
399+
// don't use the system fonts in this case (bug 1882613).
400+
/** @type {boolean|undefined} */
401+
value: (
402+
typeof PDFJSDev === "undefined"
403+
? window.isGECKOVIEW
404+
: PDFJSDev.test("GECKOVIEW")
405+
)
406+
? false
407+
: undefined,
408+
kind: OptionKind.API + OptionKind.UNDEF_ALLOWED,
409+
},
388410
verbosity: {
389411
/** @type {number} */
390412
value: 1,
@@ -472,6 +494,11 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
472494
if (kind & OptionKind.BROWSER) {
473495
throw new Error(`Cannot mix "PREFERENCE" and "BROWSER" kind: ${name}`);
474496
}
497+
if (kind & OptionKind.UNDEF_ALLOWED) {
498+
throw new Error(
499+
`Cannot allow \`undefined\` value for "PREFERENCE" kind: ${name}`
500+
);
501+
}
475502
if (typeof compatParams === "object" && compatParams.has(name)) {
476503
throw new Error(
477504
`Should not have compatibility-value for "PREFERENCE" kind: ${name}`
@@ -486,6 +513,11 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
486513
throw new Error(`Invalid value for "PREFERENCE" kind: ${name}`);
487514
}
488515
} else if (kind & OptionKind.BROWSER) {
516+
if (kind & OptionKind.UNDEF_ALLOWED) {
517+
throw new Error(
518+
`Cannot allow \`undefined\` value for "BROWSER" kind: ${name}`
519+
);
520+
}
489521
if (typeof compatParams === "object" && compatParams.has(name)) {
490522
throw new Error(
491523
`Should not have compatibility-value for "BROWSER" kind: ${name}`
@@ -514,23 +546,30 @@ class AppOptions {
514546
static getAll(kind = null, defaultOnly = false) {
515547
const options = Object.create(null);
516548
for (const name in defaultOptions) {
517-
const defaultOption = defaultOptions[name];
549+
const defaultOpt = defaultOptions[name];
518550

519-
if (kind && !(kind & defaultOption.kind)) {
551+
if (kind && !(kind & defaultOpt.kind)) {
520552
continue;
521553
}
522554
options[name] =
523555
!defaultOnly && userOptions.has(name)
524556
? userOptions.get(name)
525-
: defaultOption.value;
557+
: defaultOpt.value;
526558
}
527559
return options;
528560
}
529561

530562
static set(name, value) {
531-
const defaultOption = defaultOptions[name];
563+
const defaultOpt = defaultOptions[name];
532564

533-
if (!defaultOption || typeof value !== typeof defaultOption.value) {
565+
if (
566+
!defaultOpt ||
567+
!(
568+
typeof value === typeof defaultOpt.value ||
569+
(defaultOpt.kind & OptionKind.UNDEF_ALLOWED &&
570+
(value === undefined || defaultOpt.value === undefined))
571+
)
572+
) {
534573
return;
535574
}
536575
userOptions.set(name, value);
@@ -540,23 +579,30 @@ class AppOptions {
540579
let events;
541580

542581
for (const name in options) {
543-
const defaultOption = defaultOptions[name],
544-
userOption = options[name];
582+
const defaultOpt = defaultOptions[name],
583+
userOpt = options[name];
545584

546-
if (!defaultOption || typeof userOption !== typeof defaultOption.value) {
585+
if (
586+
!defaultOpt ||
587+
!(
588+
typeof userOpt === typeof defaultOpt.value ||
589+
(defaultOpt.kind & OptionKind.UNDEF_ALLOWED &&
590+
(userOpt === undefined || defaultOpt.value === undefined))
591+
)
592+
) {
547593
continue;
548594
}
549595
if (prefs) {
550-
const { kind } = defaultOption;
596+
const { kind } = defaultOpt;
551597

552598
if (!(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) {
553599
continue;
554600
}
555601
if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
556-
(events ||= new Map()).set(name, userOption);
602+
(events ||= new Map()).set(name, userOpt);
557603
}
558604
}
559-
userOptions.set(name, userOption);
605+
userOptions.set(name, userOpt);
560606
}
561607

562608
if (events) {

web/viewer-geckoview.html

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
<!--#endif-->
4343

4444
<!--#if !MOZCENTRAL-->
45+
<script>
46+
if (typeof PDFJSDev === "undefined") {
47+
window.isGECKOVIEW = true;
48+
}
49+
</script>
50+
4551
<script type="importmap">
4652
{
4753
"imports": {

web/viewer-geckoview.js

-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ function getViewerConfiguration() {
6060
function webViewerLoad() {
6161
const config = getViewerConfiguration();
6262

63-
if (typeof PDFJSDev === "undefined") {
64-
window.isGECKOVIEW = true;
65-
}
6663
PDFViewerApplication.run(config);
6764
}
6865

0 commit comments

Comments
 (0)