Browse Source

Add validation for scale factors in ScaleExtensions

Marcin Ziąbek 2 months ago
parent
commit
13a479ec56
1 changed files with 11 additions and 1 deletions
  1. 11 1
      Source/QuestPDF/Fluent/ScaleExtensions.cs

+ 11 - 1
Source/QuestPDF/Fluent/ScaleExtensions.cs

@@ -1,4 +1,5 @@
-using QuestPDF.Elements;
+using System;
+using QuestPDF.Elements;
 using QuestPDF.Infrastructure;
 
 namespace QuestPDF.Fluent
@@ -23,6 +24,9 @@ namespace QuestPDF.Fluent
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="scale.factorParam"]/*' />
         public static IContainer Scale(this IContainer element, float factor)
         {
+            if (factor == 0)
+                throw new ArgumentException("Vertical scale factor cannot be zero.", nameof(factor));
+            
             return element.ScaleValue(x: factor, y: factor);
         }
         
@@ -34,6 +38,9 @@ namespace QuestPDF.Fluent
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="scale.factorParam"]/*' />
         public static IContainer ScaleHorizontal(this IContainer element, float factor)
         {
+            if (factor == 0)
+                throw new ArgumentException("Vertical scale factor cannot be zero.", nameof(factor));
+            
             return element.ScaleValue(x: factor);
         }
         
@@ -45,6 +52,9 @@ namespace QuestPDF.Fluent
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="scale.factorParam"]/*' />
         public static IContainer ScaleVertical(this IContainer element, float factor)
         {
+            if (factor == 0)
+                throw new ArgumentException("Vertical scale factor cannot be zero.", nameof(factor));
+            
             return element.ScaleValue(y: factor);
         }