@@ -34,11 +34,19 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
34
34
35
35
// Limit canvas size to 5 mega-pixels on mobile.
36
36
// Support: Android, iOS
37
- ( function checkCanvasSizeLimitation ( ) {
37
+ ( function ( ) {
38
38
if ( isIOS || isAndroid ) {
39
39
compatibilityParams . maxCanvasPixels = 5242880 ;
40
40
}
41
41
} ) ( ) ;
42
+
43
+ // Don't use system fonts on Android (issue 18210).
44
+ // Support: Android
45
+ ( function ( ) {
46
+ if ( isAndroid ) {
47
+ compatibilityParams . useSystemFonts = false ;
48
+ }
49
+ } ) ( ) ;
42
50
}
43
51
44
52
const OptionKind = {
@@ -47,6 +55,7 @@ const OptionKind = {
47
55
API : 0x04 ,
48
56
WORKER : 0x08 ,
49
57
EVENT_DISPATCH : 0x10 ,
58
+ UNDEF_ALLOWED : 0x20 ,
50
59
PREFERENCE : 0x80 ,
51
60
} ;
52
61
@@ -377,6 +386,19 @@ const defaultOptions = {
377
386
: "../web/standard_fonts/" ,
378
387
kind : OptionKind . API ,
379
388
} ,
389
+ useSystemFonts : {
390
+ // On Android, there is almost no chance to have the font we want so we
391
+ // don't use the system fonts in this case (bug 1882613).
392
+ /** @type {boolean|undefined } */
393
+ value : (
394
+ typeof PDFJSDev === "undefined"
395
+ ? window . isGECKOVIEW
396
+ : PDFJSDev . test ( "GECKOVIEW" )
397
+ )
398
+ ? false
399
+ : undefined ,
400
+ kind : OptionKind . API + OptionKind . UNDEF_ALLOWED ,
401
+ } ,
380
402
verbosity : {
381
403
/** @type {number } */
382
404
value : 1 ,
@@ -464,6 +486,11 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
464
486
if ( kind & OptionKind . BROWSER ) {
465
487
throw new Error ( `Cannot mix "PREFERENCE" and "BROWSER" kind: ${ name } ` ) ;
466
488
}
489
+ if ( kind & OptionKind . UNDEF_ALLOWED ) {
490
+ throw new Error (
491
+ `Cannot allow \`undefined\` value for "PREFERENCE" kind: ${ name } `
492
+ ) ;
493
+ }
467
494
if (
468
495
typeof compatibilityParams === "object" &&
469
496
compatibilityParams [ name ] !== undefined
@@ -480,6 +507,23 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
480
507
) {
481
508
throw new Error ( `Invalid value for "PREFERENCE" kind: ${ name } ` ) ;
482
509
}
510
+ } else if ( kind & OptionKind . BROWSER ) {
511
+ if ( kind & OptionKind . UNDEF_ALLOWED ) {
512
+ throw new Error (
513
+ `Cannot allow \`undefined\` value for "BROWSER" kind: ${ name } `
514
+ ) ;
515
+ }
516
+ if (
517
+ typeof compatibilityParams === "object" &&
518
+ compatibilityParams [ name ] !== undefined
519
+ ) {
520
+ throw new Error (
521
+ `Should not have compatibility-value for "BROWSER" kind: ${ name } `
522
+ ) ;
523
+ }
524
+ if ( value === undefined ) {
525
+ throw new Error ( `Invalid value for "BROWSER" kind: ${ name } ` ) ;
526
+ }
483
527
}
484
528
}
485
529
}
@@ -513,7 +557,13 @@ class AppOptions {
513
557
static set ( name , value ) {
514
558
const defaultOption = defaultOptions [ name ] ;
515
559
516
- if ( ! defaultOption || typeof value !== typeof defaultOption . value ) {
560
+ if (
561
+ ! defaultOption ||
562
+ ! (
563
+ typeof value === typeof defaultOption . value ||
564
+ defaultOption . kind & OptionKind . UNDEF_ALLOWED
565
+ )
566
+ ) {
517
567
return ;
518
568
}
519
569
userOptions [ name ] = value ;
@@ -526,7 +576,13 @@ class AppOptions {
526
576
const defaultOption = defaultOptions [ name ] ,
527
577
userOption = options [ name ] ;
528
578
529
- if ( ! defaultOption || typeof userOption !== typeof defaultOption . value ) {
579
+ if (
580
+ ! defaultOption ||
581
+ ! (
582
+ typeof userOption === typeof defaultOption . value ||
583
+ defaultOption . kind & OptionKind . UNDEF_ALLOWED
584
+ )
585
+ ) {
530
586
continue ;
531
587
}
532
588
if ( prefs ) {
@@ -554,9 +610,8 @@ class AppOptions {
554
610
555
611
if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
556
612
// Re-apply a compatibility-value, if it exists, to the user-options.
557
- const val = compatibilityParams [ name ] ;
558
- if ( val !== undefined ) {
559
- userOptions [ name ] = val ;
613
+ if ( name in compatibilityParams ) {
614
+ userOptions [ name ] = compatibilityParams [ name ] ;
560
615
}
561
616
}
562
617
}
0 commit comments