DebugExtensions.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using QuestPDF.Drawing.Exceptions;
  2. using QuestPDF.Elements;
  3. using QuestPDF.Helpers;
  4. using QuestPDF.Infrastructure;
  5. namespace QuestPDF.Fluent
  6. {
  7. public static class DebugExtensions
  8. {
  9. /// <summary>
  10. /// Draws a labeled box around its inner content.
  11. /// Useful for visual debugging and pinpointing output from specific code blocks.
  12. /// <br />
  13. /// <a href="https://www.questpdf.com/api-reference/debug-area.html">Learn more</a>
  14. /// </summary>
  15. /// <param name="text">Optional label displayed within the box.</param>
  16. /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="colorParam"]/*' />
  17. public static IContainer DebugArea(this IContainer parent, string? text = null, Color? color = null)
  18. {
  19. var container = new Container();
  20. parent.Component(new DebugArea
  21. {
  22. Child = container,
  23. Text = text ?? string.Empty,
  24. Color = color ?? Colors.Red.Medium
  25. });
  26. return container;
  27. }
  28. /// <summary>
  29. /// <para>Inserts a virtual debug element visible in the "element trace" provided along with the <see cref="DocumentLayoutException" />.</para>
  30. /// <para>Helps with understanding and navigation of that "element trace" tree hierarchy.</para>
  31. /// <a href="https://www.questpdf.com/api-reference/debug-pointer.html">Learn more</a>
  32. /// </summary>
  33. /// <remarks>
  34. /// This debug element does not appear in the final PDF output.
  35. /// </remarks>
  36. /// <param name="elementTraceText">Text visible somewhere in the "element trace" content identifying given document fragment.</param>
  37. public static IContainer DebugPointer(this IContainer parent, string label)
  38. {
  39. return parent.DebugPointer(DebugPointerType.UserDefined, label);
  40. }
  41. internal static IContainer DebugPointer(this IContainer parent, DebugPointerType type, string label)
  42. {
  43. return parent.Element(new DebugPointer
  44. {
  45. Type = type,
  46. Label = label
  47. });
  48. }
  49. }
  50. }