Persistent Font-Subset Cache
The persistent font-subset cache avoids repeating expensive TrueType or OpenType subsetting when later documents use the same font content and glyph set
Configuration
property FontSubsetCacheFolder: AnsiString;
property FontSubsetCacheMaxBytes: Int64;
function GetFontSubsetCacheInfo: THPDFFontSubsetCacheInfo;
procedure ClearFontSubsetCache;
An empty FontSubsetCacheFolder disables disk caching without changing font output
FontSubsetCacheMaxBytes defaults to 256 MiB and may be reduced at runtime, which triggers immediate least-recently-used eviction
Statistics
THPDFFontSubsetCacheInfo contains HitCount, MissCount, WriteCount, EvictionCount, CorruptCount, RejectedCount, WriteFailureCount, CurrentBytes, and FileCount
Correctness and recovery
- A cache hit is possible only when the font content, used glyphs, subset mode, and cache schema all match
- Compact subset entries retain the CID remapping data required by PDF/A font dictionaries
- Malformed or truncated entries are rejected and removed before the subset can reach a PDF stream
- Cache failures fall back to normal in-memory subsetting and never prevent document generation
- Atomic replacement prevents readers from observing a partially written entry
Example
var
Info: THPDFFontSubsetCacheInfo;
begin
PDF.EnableFontSubsetting := True;
PDF.FontSubsetCacheFolder := 'C:\ProgramData\MyApp\HotPDF\FontSubsets';
PDF.FontSubsetCacheMaxBytes := 256 * 1024 * 1024;
{ create documents that use embedded TrueType or OpenType fonts }
Info := PDF.GetFontSubsetCacheInfo;
end;