SolidBlock.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using QuestPDF.Drawing;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Skia;
  4. namespace QuestPDF.LayoutTests.TestEngine;
  5. internal class SolidBlock : Element, IStateful
  6. {
  7. public float TotalWidth { get; set; }
  8. public float TotalHeight { get; set; }
  9. internal override SpacePlan Measure(Size availableSpace)
  10. {
  11. if (IsRendered)
  12. return SpacePlan.Empty();
  13. if (TotalWidth > availableSpace.Width + Size.Epsilon)
  14. return SpacePlan.Wrap("The content requires more horizontal space than available.");
  15. if (TotalHeight > availableSpace.Height + Size.Epsilon)
  16. return SpacePlan.Wrap("The content requires more vertical space than available.");
  17. return SpacePlan.FullRender(TotalWidth, TotalHeight);
  18. }
  19. internal override void Draw(Size availableSpace)
  20. {
  21. using var paint = new SkPaint();
  22. paint.SetSolidColor(Placeholders.BackgroundColor());
  23. Canvas.DrawRectangle(Position.Zero, availableSpace, paint);
  24. IsRendered = true;
  25. }
  26. #region IStateful
  27. private bool IsRendered { get; set; }
  28. public void ResetState(bool hardReset = false) => IsRendered = false;
  29. public object GetState() => IsRendered;
  30. public void SetState(object state) => IsRendered = (bool) state;
  31. #endregion
  32. }