CanvasExamples.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Microcharts;
  2. using NUnit.Framework;
  3. using QuestPDF.Examples.Engine;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Helpers;
  6. using QuestPDF.Infrastructure;
  7. using SkiaSharp;
  8. namespace QuestPDF.Examples
  9. {
  10. public class CanvasExamples
  11. {
  12. [Test]
  13. public void BorderRadius()
  14. {
  15. RenderingTest
  16. .Create()
  17. .PageSize(175, 100)
  18. .ProduceImages()
  19. .ShowResults()
  20. .Render(container =>
  21. {
  22. container
  23. .Background(Colors.Grey.Lighten2)
  24. .Padding(25)
  25. .MinimalBox()
  26. .Layers(layers =>
  27. {
  28. layers.Layer().Canvas((canvas, size) =>
  29. {
  30. DrawRoundedRectangle(Colors.White, false);
  31. DrawRoundedRectangle(Colors.Blue.Darken2, true);
  32. void DrawRoundedRectangle(string color, bool isStroke)
  33. {
  34. using var paint = new SKPaint
  35. {
  36. Color = SKColor.Parse(color),
  37. IsStroke = isStroke,
  38. StrokeWidth = 2,
  39. IsAntialias = true
  40. };
  41. canvas.DrawRoundRect(0, 0, size.Width, size.Height, 20, 20, paint);
  42. }
  43. });
  44. layers
  45. .PrimaryLayer()
  46. .PaddingVertical(10)
  47. .PaddingHorizontal(20)
  48. .Text("Sample text")
  49. .FontSize(16)
  50. .FontColor(Colors.Blue.Darken2)
  51. .SemiBold();
  52. });
  53. });
  54. }
  55. }
  56. }