Browse Source

Simplify public API related to semantic content and artifacts

Marcin Ziąbek 1 month ago
parent
commit
f07cab53b4

+ 1 - 1
Source/QuestPDF.ConformanceTests/TableOfContentsTests.cs

@@ -106,7 +106,7 @@ internal class TableOfContentsTests : ConformanceTestBase
                                 foreach (var j in Enumerable.Range(1, i))
                                 {
                                     column.Item()
-                                        .ArtifactOther()
+                                        .SemanticIgnore()
                                         .Width(200)
                                         .Height(150)
                                         .CornerRadius(10)

+ 3 - 2
Source/QuestPDF/Elements/Page.cs

@@ -2,6 +2,7 @@ using System;
 using QuestPDF.Fluent;
 using QuestPDF.Helpers;
 using QuestPDF.Infrastructure;
+using QuestPDF.Skia;
 
 namespace QuestPDF.Elements
 {
@@ -43,7 +44,7 @@ namespace QuestPDF.Elements
                         .Layer()
                         .Repeat()
                         .DebugPointer(DebugPointerType.DocumentStructure, DocumentStructureTypes.Background.ToString())
-                        .ArtifactBackground()
+                        .Artifact(SkSemanticNodeSpecialId.BackgroundArtifact)
                         .Element(Background);
                     
                     layers
@@ -83,7 +84,7 @@ namespace QuestPDF.Elements
                     layers
                         .Layer()
                         .Repeat()
-                        .ArtifactPaginationWatermark()
+                        .Artifact(SkSemanticNodeSpecialId.PaginationWatermarkArtifact)
                         .DebugPointer(DebugPointerType.DocumentStructure, DocumentStructureTypes.Foreground.ToString())
                         .Element(Foreground);
                 });

+ 0 - 87
Source/QuestPDF/Fluent/ArtifactExtensions.cs

@@ -1,87 +0,0 @@
-using QuestPDF.Infrastructure;
-using QuestPDF.Skia;
-
-namespace QuestPDF.Fluent;
-
-public static class ArtifactExtensions
-{
-    private static IContainer Artifact(this IContainer container, int nodeId)
-    {
-        return container.Element(new Elements.ArtifactTag
-        {
-            Id = nodeId
-        });
-    }
-    
-    /// <summary>
-    /// Marks the container content as a generic PDF artifact.
-    /// Generic artifacts are non-structural elements that don't fit into other specific categories.
-    /// </summary>
-    public static IContainer ArtifactOther(this IContainer container)
-    {
-        return container.Artifact(SkSemanticNodeSpecialId.OtherArtifact);
-    }
-
-    /// <summary>
-    /// Marks the container content as a pagination artifact.
-    /// Used for page-related content that isn't part of the document's logical structure.
-    /// </summary>
-    public static IContainer ArtifactPagination(this IContainer container)
-    {
-        return container.Artifact(SkSemanticNodeSpecialId.PaginationArtifact);
-    }
-
-    /// <summary>
-    /// Marks the container content as a page header artifact.
-    /// Used for repeating header content that appears at the top of pages.
-    /// </summary>
-    public static IContainer ArtifactPaginationHeader(this IContainer container)
-    {
-        return container.Artifact(SkSemanticNodeSpecialId.PaginationHeaderArtifact);
-    }
-
-    /// <summary>
-    /// Marks the container content as a page footer artifact.
-    /// Used for repeating footer content that appears at the bottom of pages.
-    /// </summary>
-    public static IContainer ArtifactPaginationFooter(this IContainer container)
-    {
-        return container.Artifact(SkSemanticNodeSpecialId.PaginationFooterArtifact);
-    }
-
-    /// <summary>
-    /// Marks the container content as a watermark artifact.
-    /// Used for watermark content that overlays the page but isn't part of the document structure.
-    /// </summary>
-    public static IContainer ArtifactPaginationWatermark(this IContainer container)
-    {
-        return container.Artifact(SkSemanticNodeSpecialId.PaginationWatermarkArtifact);
-    }
-
-    /// <summary>
-    /// Marks the container content as a layout artifact.
-    /// Used for decorative or layout-related content that doesn't convey document meaning.
-    /// </summary>
-    public static IContainer ArtifactLayout(this IContainer container)
-    {
-        return container.Artifact(SkSemanticNodeSpecialId.LayoutArtifact);
-    }
-
-    /// <summary>
-    /// Marks the container content as a page artifact.
-    /// Used for page-level decorative elements that aren't part of the document's logical structure.
-    /// </summary>
-    public static IContainer ArtifactPage(this IContainer container)
-    {
-        return container.Artifact(SkSemanticNodeSpecialId.PageArtifact);
-    }
-
-    /// <summary>
-    /// Marks the container content as a background artifact.
-    /// Used for background graphics or shading that doesn't convey document meaning.
-    /// </summary>
-    public static IContainer ArtifactBackground(this IContainer container)
-    {
-        return container.Artifact(SkSemanticNodeSpecialId.BackgroundArtifact);
-    }
-}

+ 5 - 1
Source/QuestPDF/Fluent/MultiColumnExtensions.cs

@@ -2,6 +2,7 @@ using System;
 using QuestPDF.Drawing.Exceptions;
 using QuestPDF.Elements;
 using QuestPDF.Infrastructure;
+using QuestPDF.Skia;
 
 namespace QuestPDF.Fluent;
 
@@ -79,7 +80,10 @@ public sealed class MultiColumnDescriptor
         
         var container = new Container();
         MultiColumn.Spacer = container;
-        return container.ArtifactLayout().Repeat();
+        
+        return container
+            .Artifact(SkSemanticNodeSpecialId.LayoutArtifact)
+            .Repeat();
     }
 }
 

+ 17 - 0
Source/QuestPDF/Fluent/SemanticExtensions.cs

@@ -7,6 +7,23 @@ namespace QuestPDF.Fluent;
 
 public static class SemanticExtensions
 {
+    internal static IContainer Artifact(this IContainer container, int nodeId)
+    {
+        return container.Element(new Elements.ArtifactTag
+        {
+            Id = nodeId
+        });
+    }
+    
+    /// <summary>
+    /// Excludes the container content from the semantic tree.
+    /// Use for decorative elements, layout artifacts, or other non-structural content that shouldn't be part of the document's logical structure.
+    /// </summary>
+    public static IContainer SemanticIgnore(this IContainer container)
+    {
+        return container.Artifact(SkSemanticNodeSpecialId.OtherArtifact);
+    }
+    
     internal static IContainer SemanticTag(this IContainer container, string type, string? alternativeText = null, string? language = null)
     {
         return container.Element(new Elements.SemanticTag