| 12345678910111213141516171819202122232425262728293031323334 |
- using System.Diagnostics;
- namespace QuestPDF.LayoutTests.TestEngine;
- internal class ElementObserver : ContainerElement
- {
- public string? ObserverId { get; set; }
- public DrawingRecorder? DrawingRecorder { get; set; }
-
- internal override void Draw(Size availableSpace)
- {
- Debug.Assert(ObserverId != null);
- Debug.Assert(DrawingRecorder != null);
-
- var matrix = Canvas.GetCurrentMatrix();
-
- DrawingRecorder?.Record(new ElementDrawingEvent
- {
- ObserverId = ObserverId,
- PageNumber = PageContext.CurrentPage,
- Position = new Position(matrix.TranslateX, matrix.TranslateY),
- Size = ObserverId == "$document" ? Child.Measure(availableSpace) : availableSpace
- });
-
- var matrixBeforeDraw = Canvas.GetCurrentMatrix().ToMatrix4x4();
- base.Draw(availableSpace);
- var matrixAfterDraw = Canvas.GetCurrentMatrix().ToMatrix4x4();
-
- if (matrixAfterDraw != matrixBeforeDraw)
- throw new InvalidOperationException("Canvas state was not restored after drawing operation.");
- }
- }
|