|
|
@@ -1,4 +1,5 @@
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
@@ -70,10 +71,7 @@ namespace QuestPDF.Drawing
|
|
|
|
|
|
private static void RegisterLibraryDefaultFonts()
|
|
|
{
|
|
|
- var supportedFontExtensions = new[] { "*.ttf", "*.otf", "*.ttc", "*.pfb" };
|
|
|
-
|
|
|
- var fontFilePaths = supportedFontExtensions
|
|
|
- .SelectMany(extension => Directory.GetFiles(Helpers.Helpers.ApplicationFilesPath, extension, SearchOption.AllDirectories));
|
|
|
+ var fontFilePaths = SearchFontFiles();
|
|
|
|
|
|
foreach (var fileName in fontFilePaths)
|
|
|
{
|
|
|
@@ -87,6 +85,27 @@ namespace QuestPDF.Drawing
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ ICollection<string> SearchFontFiles()
|
|
|
+ {
|
|
|
+ const int maxFilesToScan = 100_000;
|
|
|
+
|
|
|
+ var applicationFiles = Settings
|
|
|
+ .FontDiscoveryPaths
|
|
|
+ .Select(path => Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))
|
|
|
+ .SelectMany(file => file)
|
|
|
+ .Take(maxFilesToScan)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ if (applicationFiles.Count == maxFilesToScan)
|
|
|
+ throw new InvalidOperationException($"The library has reached the limit of {maxFilesToScan} files to scan for font files. Please adjust the {nameof(Settings.FontDiscoveryPaths)} collection to include only the necessary directories. The reason of this exception is to prevent scanning too many files and avoid performance issues on the application startup.");
|
|
|
+
|
|
|
+ var supportedFontExtensions = new[] { ".ttf", ".otf", ".ttc", ".pfb" };
|
|
|
+
|
|
|
+ return applicationFiles
|
|
|
+ .Where(x => supportedFontExtensions.Contains(Path.GetExtension(x).ToLowerInvariant()))
|
|
|
+ .ToList();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|