CanvasExamples.cs 2.1 KB

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