Browse Source

RTL: aspect ratio

MarcinZiabek 3 years ago
parent
commit
603dc13d0f
2 changed files with 24 additions and 0 deletions
  1. 20 0
      QuestPDF.Examples/RightToLeftExamples.cs
  2. 4 0
      QuestPDF/Elements/AspectRatio.cs

+ 20 - 0
QuestPDF.Examples/RightToLeftExamples.cs

@@ -2,6 +2,7 @@
 using QuestPDF.Examples.Engine;
 using QuestPDF.Examples.Engine;
 using QuestPDF.Fluent;
 using QuestPDF.Fluent;
 using QuestPDF.Helpers;
 using QuestPDF.Helpers;
+using QuestPDF.Infrastructure;
 
 
 namespace QuestPDF.Examples
 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);
+                });
+        }
     }
     }
 }
 }

+ 4 - 0
QuestPDF/Elements/AspectRatio.cs

@@ -42,7 +42,11 @@ namespace QuestPDF.Elements
                 return;
                 return;
             
             
             var size = GetTargetSize(availableSpace);
             var size = GetTargetSize(availableSpace);
+            var offset = new Position(availableSpace.Width - size.Width, 0);
+            
+            Canvas.Translate(offset);
             base.Draw(size);
             base.Draw(size);
+            Canvas.Translate(offset.Reverse());
         }
         }
         
         
         private Size GetTargetSize(Size availableSpace)
         private Size GetTargetSize(Size availableSpace)