Browse Source

[Avalonia] Rotation calculation fixes

Ruben 1 year ago
parent
commit
b822c373c4
1 changed files with 39 additions and 12 deletions
  1. 39 12
      src/PicView.Core/Calculations/ImageSizeCalculationHelper.cs

+ 39 - 12
src/PicView.Core/Calculations/ImageSizeCalculationHelper.cs

@@ -58,22 +58,49 @@ namespace PicView.Core.Calculations
             }
             else if (SettingsHelper.Settings.WindowProperties.AutoFit)
             {
-                maxWidth = SettingsHelper.Settings.ImageScaling.StretchImage
-                    ? workAreaWidth - padding
-                    : Math.Min(workAreaWidth - padding, width);
-                maxHeight = SettingsHelper.Settings.ImageScaling.StretchImage
-                    ? workAreaHeight - padding
-                    : Math.Min(workAreaHeight - padding, height);
+                if (rotationAngle is 90 or 270)
+                {
+                    maxWidth = SettingsHelper.Settings.ImageScaling.StretchImage
+                        ? workAreaHeight - padding
+                        : Math.Min(workAreaHeight - padding, height);
+                    
+                    maxHeight = SettingsHelper.Settings.ImageScaling.StretchImage
+                        ? workAreaWidth - padding
+                        : Math.Min(workAreaWidth - padding, width);
+                }
+                else
+                {
+                    maxWidth = SettingsHelper.Settings.ImageScaling.StretchImage
+                        ? workAreaWidth - padding
+                        : Math.Min(workAreaWidth - padding, width);
+                    
+                    maxHeight = SettingsHelper.Settings.ImageScaling.StretchImage
+                        ? workAreaHeight - padding
+                        : Math.Min(workAreaHeight - padding, height);
+                }
             }
             else
             {
-                maxWidth = SettingsHelper.Settings.ImageScaling.StretchImage
-                    ? containerWidth
-                    : Math.Min(containerWidth, width);
+                if (rotationAngle is 90 or 270)
+                {
+                    maxWidth = SettingsHelper.Settings.ImageScaling.StretchImage
+                        ? containerHeight - galleryHeight
+                        : height;
 
-                maxHeight = SettingsHelper.Settings.ImageScaling.StretchImage
-                    ? containerHeight - galleryHeight
-                    : Math.Min(containerHeight - galleryHeight, height);
+                    maxHeight = SettingsHelper.Settings.ImageScaling.StretchImage
+                        ? containerHeight - galleryHeight
+                        : Math.Min(containerHeight, height);
+                }
+                else
+                {
+                    maxWidth = SettingsHelper.Settings.ImageScaling.StretchImage
+                        ? containerWidth
+                        : Math.Min(containerWidth, width);
+
+                    maxHeight = SettingsHelper.Settings.ImageScaling.StretchImage
+                        ? containerHeight - galleryHeight
+                        : Math.Min(containerHeight - galleryHeight, height);
+                }
             }
 
             if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)