Skip to content

Commit c0c401d

Browse files
Fix font state management issue #3890
- Fixed font face map caching in context2d module - Font face map now properly rebuilds when font list changes - Resolves issue where custom fonts fail to render after being interrupted by default fonts - Maintains performance through intelligent cache invalidation Fixes #3890
1 parent 574a941 commit c0c401d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/modules/context2d.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,19 @@ import {
450450
});
451451

452452
var _fontFaceMap = null;
453+
var _cachedFontList = null;
453454

454455
function getFontFaceMap(pdf, fontFaces) {
455-
if (_fontFaceMap === null) {
456-
var fontMap = pdf.getFontList();
457-
458-
var convertedFontFaces = convertToFontFaces(fontMap);
456+
var currentFontMap = pdf.getFontList();
457+
458+
// Check if the font list has changed by comparing the JSON representation
459+
var currentFontMapString = JSON.stringify(currentFontMap);
460+
461+
if (_fontFaceMap === null || _cachedFontList !== currentFontMapString) {
462+
var convertedFontFaces = convertToFontFaces(currentFontMap);
459463

460464
_fontFaceMap = buildFontFaceMap(convertedFontFaces.concat(fontFaces));
465+
_cachedFontList = currentFontMapString;
461466
}
462467

463468
return _fontFaceMap;
@@ -533,6 +538,7 @@ import {
533538
},
534539
set: function(value) {
535540
_fontFaceMap = null;
541+
_cachedFontList = null;
536542
_fontFaces = value;
537543
}
538544
});

0 commit comments

Comments
 (0)