CanvasExamples.cs 2.1 KB

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