@@ -979,15 +979,13 @@ class PartialEvaluator {
979
979
}
980
980
981
981
loadFont ( fontName , font , resources ) {
982
- const errorFont = ( ) => {
983
- return Promise . resolve (
984
- new TranslatedFont ( {
985
- loadedName : "g_font_error" ,
986
- font : new ErrorFont ( `Font "${ fontName } " is not available.` ) ,
987
- dict : font ,
988
- extraProperties : this . options . fontExtraProperties ,
989
- } )
990
- ) ;
982
+ const errorFont = async ( ) => {
983
+ return new TranslatedFont ( {
984
+ loadedName : "g_font_error" ,
985
+ font : new ErrorFont ( `Font "${ fontName } " is not available.` ) ,
986
+ dict : font ,
987
+ extraProperties : this . options . fontExtraProperties ,
988
+ } ) ;
991
989
} ;
992
990
993
991
var fontRef ,
@@ -1034,10 +1032,10 @@ class PartialEvaluator {
1034
1032
return errorFont ( ) ;
1035
1033
}
1036
1034
1037
- // We are holding `font.translated ` references just for `fontRef`s that
1035
+ // We are holding `font.cacheKey ` references only for `fontRef`s that
1038
1036
// are not actually `Ref`s, but rather `Dict`s. See explanation below.
1039
- if ( font . translated ) {
1040
- return font . translated ;
1037
+ if ( font . cacheKey && this . fontCache . has ( font . cacheKey ) ) {
1038
+ return this . fontCache . get ( font . cacheKey ) ;
1041
1039
}
1042
1040
1043
1041
var fontCapability = createPromiseCapability ( ) ;
@@ -1077,18 +1075,16 @@ class PartialEvaluator {
1077
1075
1078
1076
// Workaround for bad PDF generators that reference fonts incorrectly,
1079
1077
// where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
1080
- // In this case we should not put the font into `this.fontCache` (which is
1081
- // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
1078
+ // In this case we cannot put the font into `this.fontCache` (which is
1079
+ // a `RefSetCache`), since it's not possible to use a `Dict` as a key.
1082
1080
//
1083
1081
// However, if we don't cache the font it's not possible to remove it
1084
1082
// when `cleanup` is triggered from the API, which causes issues on
1085
- // subsequent rendering operations (see issue7403.pdf).
1086
- // A simple workaround would be to just not hold `font.translated`
1087
- // references in this case, but this would force us to unnecessarily load
1088
- // the same fonts over and over.
1083
+ // subsequent rendering operations (see issue7403.pdf) and would force us
1084
+ // to unnecessarily load the same fonts over and over.
1089
1085
//
1090
- // Instead, we cheat a bit by attempting to use a modified `fontID` as a
1091
- // key in `this.fontCache`, to allow the font to be cached.
1086
+ // Instead, we cheat a bit by using a modified `fontID` as a key in
1087
+ // `this.fontCache`, to allow the font to be cached.
1092
1088
// NOTE: This works because `RefSetCache` calls `toString()` on provided
1093
1089
// keys. Also, since `fontRef` is used when getting cached fonts,
1094
1090
// we'll not accidentally match fonts cached with the `fontID`.
@@ -1098,7 +1094,8 @@ class PartialEvaluator {
1098
1094
if ( ! fontID ) {
1099
1095
fontID = this . idFactory . createFontId ( ) ;
1100
1096
}
1101
- this . fontCache . put ( `id_${ fontID } ` , fontCapability . promise ) ;
1097
+ font . cacheKey = `cacheKey_${ fontID } ` ;
1098
+ this . fontCache . put ( font . cacheKey , fontCapability . promise ) ;
1102
1099
}
1103
1100
assert (
1104
1101
fontID && fontID . startsWith ( "f" ) ,
@@ -1109,8 +1106,6 @@ class PartialEvaluator {
1109
1106
// load them asynchronously before calling display on a page.
1110
1107
font . loadedName = `${ this . idFactory . getDocId ( ) } _${ fontID } ` ;
1111
1108
1112
- font . translated = fontCapability . promise ;
1113
-
1114
1109
this . translateFont ( preEvaluatedFont )
1115
1110
. then ( translatedFont => {
1116
1111
if ( translatedFont . fontType !== undefined ) {
0 commit comments