Przeglądaj źródła

Fix semantic state handling for multi-page dynamic components

Update captured semantic state after each Draw() to ensure consecutive node ID allocation when dynamic component is drawn multiple times (e.g., across pages or in MultiColumn)

Co-authored-by: MarcinZiabek <[email protected]>
copilot-swe-agent[bot] 3 tygodni temu
rodzic
commit
bfed6eade5
1 zmienionych plików z 10 dodań i 3 usunięć
  1. 10 3
      Source/QuestPDF/Elements/Dynamic.cs

+ 10 - 3
Source/QuestPDF/Elements/Dynamic.cs

@@ -75,9 +75,16 @@ namespace QuestPDF.Elements
             context.DisposeCreatedElements();
             content.ReleaseDisposableChildren();
             
-            // Restore the semantic state after drawing
-            if (SemanticTreeManager != null && previousState != null)
-                SemanticTreeManager.RestoreState(previousState);
+            // Update the captured state to reflect the node IDs allocated during this draw
+            // This ensures that subsequent Draw() calls continue from where this one left off
+            if (SemanticTreeManager != null && CapturedSemanticState != null)
+            {
+                CapturedSemanticState = SemanticTreeManager.CaptureState();
+                
+                // Restore to the state before this Draw() call to not affect other elements
+                if (previousState != null)
+                    SemanticTreeManager.RestoreState(previousState);
+            }
             
             if (!composeResult.HasMoreContent)
                 IsRendered = true;