vcl/source/gdi/print3.cxx |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

New commits:
commit 07e529abf77c582233587574b864c28387506ba9
Author:     Justin Luth <[email protected]>
AuthorDate: Thu Oct 23 15:08:21 2025 -0400
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Nov 24 11:58:55 2025 +0100

    tdf#166185 vcl PrinterController: auto orient in getRealPaperSize
    
    This patch fixes the situation
    when you print a landscape-page-styled document
    and chose a different paper size (i.e Letter -> Legal)
    'automatic orientation' no longer is portrait.
    
    This also allows some pages being in landscape mode
    while other pages are portrait.
    
    Change-Id: Iec22ab7a196a775a2a589ae3e9f76114e50db1c2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192926
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <[email protected]>
    (cherry picked from commit cae2ae964468b3aa5b773676a4c67b40e305725e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194427
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index 75d28ca69688..d3e257849699 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -236,15 +236,25 @@ public:
             size = maMultiPage.aPaperSize;
         else
             size = i_rPageSize;
+
+        bool bSwap = false;
+        const bool bSizeIsLandscape = size.Width() > size.Height();
         if(mbOrientationFromUser)
         {
-            if ( (meUserOrientation == Orientation::Portrait && size.Width() > 
size.Height()) ||
-                 (meUserOrientation == Orientation::Landscape && size.Width() 
< size.Height()) )
-            {
-                // coverity[swapped_arguments : FALSE] - this is in the 
correct order
-                size = Size( size.Height(), size.Width() );
-            }
+            bSwap = (bSizeIsLandscape && Orientation::Portrait == 
meUserOrientation)
+                    || (!bSizeIsLandscape && Orientation::Landscape == 
meUserOrientation);
+        }
+        else if (mbPapersizeFromUser || mbPapersizeFromSetup) // automatic 
orientation
+        {
+            const bool bDocumentPageIsLandscape = i_rPageSize.Width() > 
i_rPageSize.Height();
+            bSwap = bDocumentPageIsLandscape != bSizeIsLandscape;
+        }
+        if (bSwap)
+        {
+            // coverity[swapped_arguments : FALSE] - this is in the correct 
order
+            size = Size(size.Height(), size.Width());
         }
+
         return size;
     }
     PrinterController::PageSize modifyJobSetup( const css::uno::Sequence< 
css::beans::PropertyValue >& i_rProps );

Reply via email to