File tree 3 files changed +13
-4
lines changed
3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change
1
+ import LRUCache from 'lru-cache' ;
1
2
import PDFFont from '../font' ;
2
3
3
4
const toHex = function ( num ) {
@@ -24,7 +25,9 @@ class EmbeddedFont extends PDFFont {
24
25
this . bbox = this . font . bbox ;
25
26
26
27
if ( document . options . fontLayoutCache !== false ) {
27
- this . layoutCache = Object . create ( null ) ;
28
+ this . layoutCache = new LRUCache ( {
29
+ max : document . options . fontLayoutMaxCacheSize || 1000
30
+ } ) ;
28
31
}
29
32
}
30
33
@@ -49,12 +52,12 @@ class EmbeddedFont extends PDFFont {
49
52
return this . layoutRun ( text ) ;
50
53
}
51
54
let cached ;
52
- if ( ( cached = this . layoutCache [ text ] ) ) {
55
+ if ( ( cached = this . layoutCache . get ( text ) ) ) {
53
56
return cached ;
54
57
}
55
58
56
59
const run = this . layoutRun ( text ) ;
57
- this . layoutCache [ text ] = run ;
60
+ this . layoutCache . set ( text , run ) ;
58
61
return run ;
59
62
}
60
63
Original file line number Diff line number Diff line change 52
52
"fontkit" : " ^1.8.1" ,
53
53
"jpeg-exif" : " ^1.1.4" ,
54
54
"linebreak" : " ^1.0.2" ,
55
+ "lru-cache" : " ^7.0.0" ,
55
56
"png-js" : " ^1.0.0"
56
57
},
57
58
"scripts" : {
89
90
" <rootDir>/tests/unit/setupTests.js"
90
91
]
91
92
}
92
- }
93
+ }
Original file line number Diff line number Diff line change @@ -5030,6 +5030,11 @@ lru-cache@^6.0.0:
5030
5030
dependencies :
5031
5031
yallist "^4.0.0"
5032
5032
5033
+ lru-cache@^7.0.0 :
5034
+ version "7.18.3"
5035
+ resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.18.3.tgz#f793896e0fd0e954a59dfdd82f0773808df6aa89"
5036
+ integrity sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==
5037
+
5033
5038
5034
5039
version "0.25.1"
5035
5040
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.1.tgz#b1c248b399cd7485da0fe7385c2fc7011843266e"
You can’t perform that action at this time.
0 commit comments