Просмотр исходного кода

Improved the default path for loading font files to prevent rare application hangs in certain environments.

Marcin Ziąbek 1 год назад
Родитель
Сommit
5a3bc64ee5

+ 13 - 2
Source/QuestPDF/Helpers/Helpers.cs

@@ -131,8 +131,19 @@ namespace QuestPDF.Helpers
             process.Start();
             process.WaitForExit();
         }
-        
-        internal static string ApplicationFilesPath => AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
+
+        internal static string ApplicationFilesPath
+        {
+            get
+            {
+                var baseDirectory = AppContext.BaseDirectory;
+
+                if (string.IsNullOrWhiteSpace(baseDirectory) || baseDirectory == "/")
+                    return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+
+                return baseDirectory;
+            }
+        }
         
         internal static (float widthScale, float heightScale) CalculateSpaceScale(this SkSvgImage image, Size availableSpace)
         {

+ 1 - 1
Source/QuestPDF/Settings.cs

@@ -60,7 +60,7 @@ namespace QuestPDF
         /// </remarks>
         public static ICollection<string> FontDiscoveryPaths { get; } = new List<string>()
         {
-            AppDomain.CurrentDomain.BaseDirectory
+            Helpers.Helpers.ApplicationFilesPath
         };
         
         static Settings()

+ 2 - 1
Source/QuestPDF/Skia/Text/SkFontManager.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Linq;
 using System.Runtime.InteropServices;
 
 namespace QuestPDF.Skia.Text;
@@ -7,7 +8,7 @@ internal sealed class SkFontManager
 {
     public IntPtr Instance { get; }
     
-    public static SkFontManager Local { get; } = new(API.font_manager_create_local(Helpers.Helpers.ApplicationFilesPath));
+    public static SkFontManager Local { get; } = new(API.font_manager_create_local(Settings.FontDiscoveryPaths.FirstOrDefault() ?? Helpers.Helpers.ApplicationFilesPath));
     public static SkFontManager Global { get; } = new(API.font_manager_create_global());
 
     private SkFontManager(IntPtr instance)