From 603dc13d0fa0060f3cd12b53ca77026feefa22b7 Mon Sep 17 00:00:00 2001 From: MarcinZiabek Date: Thu, 29 Sep 2022 21:12:46 +0200 Subject: [PATCH] RTL: aspect ratio --- QuestPDF.Examples/RightToLeftExamples.cs | 20 ++++++++++++++++++++ QuestPDF/Elements/AspectRatio.cs | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/QuestPDF.Examples/RightToLeftExamples.cs b/QuestPDF.Examples/RightToLeftExamples.cs index 03489e0..bca4226 100644 --- a/QuestPDF.Examples/RightToLeftExamples.cs +++ b/QuestPDF.Examples/RightToLeftExamples.cs @@ -2,6 +2,7 @@ using QuestPDF.Examples.Engine; using QuestPDF.Fluent; using QuestPDF.Helpers; +using QuestPDF.Infrastructure; namespace QuestPDF.Examples { @@ -104,5 +105,24 @@ namespace QuestPDF.Examples }); }); } + + [Test] + public void AspectRatio() + { + RenderingTest + .Create() + .ProduceImages() + .PageSize(600, 600) + .ShowResults() + .Render(container => + { + container + .Padding(25) + .ContentFromRightToLeft() + .Border(1) + .AspectRatio(0.55f, AspectRatioOption.FitArea) + .Background(Colors.Red.Medium); + }); + } } } \ No newline at end of file diff --git a/QuestPDF/Elements/AspectRatio.cs b/QuestPDF/Elements/AspectRatio.cs index 3f1679f..0f556ff 100644 --- a/QuestPDF/Elements/AspectRatio.cs +++ b/QuestPDF/Elements/AspectRatio.cs @@ -42,7 +42,11 @@ namespace QuestPDF.Elements return; var size = GetTargetSize(availableSpace); + var offset = new Position(availableSpace.Width - size.Width, 0); + + Canvas.Translate(offset); base.Draw(size); + Canvas.Translate(offset.Reverse()); } private Size GetTargetSize(Size availableSpace)