Jelajahi Sumber

Updated native dependency to Skia 135; Added support for language in PDF Document Metadata; Added checking if the native library version is as expected

Marcin Ziąbek 9 bulan lalu
induk
melakukan
3633372f7f

+ 2 - 0
Source/QuestPDF/Drawing/PdfCanvas.cs

@@ -25,6 +25,7 @@ namespace QuestPDF.Drawing
             using var keywords = new SkText(documentMetadata.Keywords);
             using var creator = new SkText(documentMetadata.Creator);
             using var producer = new SkText(documentMetadata.Producer);
+            using var language = new SkText(documentMetadata.Language);
             
             var internalMetadata = new SkPdfDocumentMetadata
             {
@@ -34,6 +35,7 @@ namespace QuestPDF.Drawing
                 Keywords = keywords,
                 Creator = creator,
                 Producer = producer,
+                Language = language,
                 
                 CreationDate = new SkDateTime(documentMetadata.CreationDate),
                 ModificationDate = new SkDateTime(documentMetadata.ModifiedDate),

+ 8 - 1
Source/QuestPDF/Helpers/NativeDependencyCompatibilityChecker.cs

@@ -11,6 +11,7 @@ namespace QuestPDF.Helpers
         private bool IsCompatibilityChecked { get; set; } = false;
 
         public Action ExecuteNativeCode { get; set; } = () => { };
+        public Func<bool>? CheckNativeLibraryVersion { get; set; } = () => false;
         public Func<string> ExceptionHint { get; set; } = () => string.Empty;
         
         public void Test()
@@ -27,6 +28,7 @@ namespace QuestPDF.Helpers
             if (IsCompatibilityChecked)
                 return;
             
+            const string exceptionBaseMessage = "The QuestPDF library has encountered an issue while loading one of its dependencies.";
             const string paragraph = "\n\n";
                 
             // test with dotnet-based mechanism where native files are provided
@@ -34,7 +36,12 @@ namespace QuestPDF.Helpers
             var innerException = CheckIfExceptionIsThrownWhenLoadingNativeDependencies();
 
             if (innerException == null)
+            {
+                if (CheckNativeLibraryVersion != null && !CheckNativeLibraryVersion())
+                    throw new Exception($"{exceptionBaseMessage}{paragraph}The loaded native library version is incompatible with the current QuestPDF version. To resolve this issue, please: 1) Clean and rebuild your solution, 2) Remove the bin and obj folders, and 3) Ensure all projects in your solution use the same QuestPDF NuGet package version.");
+
                 return;
+            }
 
             if (!NativeDependencyProvider.IsCurrentPlatformSupported())
                 ThrowCompatibilityException(innerException);
@@ -55,7 +62,7 @@ namespace QuestPDF.Helpers
                 var currentRuntime = NativeDependencyProvider.GetRuntimePlatform();
                 var isRuntimeSupported = NativeDependencyProvider.SupportedPlatforms.Contains(currentRuntime);
 
-                var message = $"The QuestPDF library has encountered an issue while loading one of its dependencies.";
+                var message = $"{exceptionBaseMessage}";
                 
                 if (!isRuntimeSupported)
                 {

+ 5 - 0
Source/QuestPDF/Infrastructure/DocumentMetadata.cs

@@ -35,6 +35,11 @@ namespace QuestPDF.Infrastructure
         /// </summary>
         public string? Producer { get; set; }
 
+        /// <summary>
+        /// Specifies the language of the document content, defined using language tags such as "en-US" for American English.
+        /// </summary>
+        public string? Language { get; set; }
+        
         /// <summary>
         /// Represents the date and time when the document was created.
         /// This property is used to specify the creation timestamp.

+ 1 - 6
Source/QuestPDF/Qpdf/QpdfNativeDependencyCompatibilityChecker.cs

@@ -26,11 +26,6 @@ internal static class QpdfNativeDependencyCompatibilityChecker
 
     private static string GetHint()
     {
-        var platform = NativeDependencyProvider.GetRuntimePlatform();
-
-        if (platform != "linux-musl-x64")
-            return string.Empty;
-        
-        return $"Installing additional dependencies may help. Please try the following command: 'apk add libjpeg-turbo'. Do NOT install the qpdf package.";
+        return $"Please do NOT install the qpdf package.";
     }
 }

TEMPAT SAMPAH
Source/QuestPDF/Runtimes/linux-arm64/native/libQuestPdfSkia.so


TEMPAT SAMPAH
Source/QuestPDF/Runtimes/linux-musl-x64/native/libQuestPdfSkia.so


TEMPAT SAMPAH
Source/QuestPDF/Runtimes/linux-x64/native/libQuestPdfSkia.so


TEMPAT SAMPAH
Source/QuestPDF/Runtimes/osx-arm64/native/libQuestPdfSkia.dylib


TEMPAT SAMPAH
Source/QuestPDF/Runtimes/osx-x64/native/libQuestPdfSkia.dylib


TEMPAT SAMPAH
Source/QuestPDF/Runtimes/win-x64/native/QuestPdfSkia.dll


TEMPAT SAMPAH
Source/QuestPDF/Runtimes/win-x86/native/QuestPdfSkia.dll


+ 19 - 1
Source/QuestPDF/Skia/SkNativeDependencyCompatibilityChecker.cs

@@ -7,9 +7,12 @@ namespace QuestPDF.Skia;
 
 internal static class SkNativeDependencyCompatibilityChecker
 {
+    private const int ExpectedNativeLibraryVersion = 1;
+    
     private static NativeDependencyCompatibilityChecker Instance { get; } = new()
     {
-        ExecuteNativeCode = ExecuteNativeCode
+        ExecuteNativeCode = ExecuteNativeCode,
+        CheckNativeLibraryVersion = CheckNativeLibraryVersion
     };
     
     public static void Test()
@@ -17,6 +20,18 @@ internal static class SkNativeDependencyCompatibilityChecker
         Instance.Test();
     }
 
+    private static bool CheckNativeLibraryVersion()
+    {
+        try
+        {
+            return API.get_questpdf_version() == ExpectedNativeLibraryVersion;
+        }
+        catch
+        {
+            return false;
+        }
+    }
+    
     private static void ExecuteNativeCode()
     {
         var random = new Random();
@@ -33,6 +48,9 @@ internal static class SkNativeDependencyCompatibilityChecker
     
     private static class API
     {
+        [DllImport(SkiaAPI.LibraryName, CallingConvention = CallingConvention.Cdecl)]
+        public static extern int get_questpdf_version();
+        
         [DllImport(SkiaAPI.LibraryName, CallingConvention = CallingConvention.Cdecl)]
         public static extern int check_compatibility_by_calculating_sum(int a, int b);
     }

+ 1 - 0
Source/QuestPDF/Skia/SkPdfDocument.cs

@@ -12,6 +12,7 @@ internal struct SkPdfDocumentMetadata
     public IntPtr Keywords; // string
     public IntPtr Creator; // string
     public IntPtr Producer; // string
+    public IntPtr Language; // string
 
     public SkDateTime CreationDate;
     public SkDateTime ModificationDate;