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" : " ^10.2.2" ,
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 @@ -5016,6 +5016,11 @@ longest@^1.0.1:
5016
5016
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
5017
5017
integrity sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=
5018
5018
5019
+ lru-cache@^10.2.2 :
5020
+ version "10.2.2"
5021
+ resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.2.tgz#48206bc114c1252940c41b25b41af5b545aca878"
5022
+ integrity sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==
5023
+
5019
5024
lru-cache@^5.1.1 :
5020
5025
version "5.1.1"
5021
5026
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
You can’t perform that action at this time.
0 commit comments