vcl/source/window/printdlg.cxx |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

New commits:
commit c0f4822eadadccd8908bd0c15731d79f0a8085af
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri Feb 20 16:31:14 2026 +0500
Commit:     Xisco Fauli <[email protected]>
CommitDate: Fri Feb 20 19:59:00 2026 +0100

    tdf#170910: exact match can also be rotated
    
    For Microsoft XPS Document Writer printer, the paper list is very
    logn, and contains duplicates (e.g., two portrait Letter), as well
    as rotated variants (e.g., landscape Letter).
    
    The code that looks for matching paper in setPaperSizes would find
    all elelemts with matching Paper value, regardless of orientation;
    and would use the last match. It happened, that for A4 and Letter,
    the last matches were landscape, so the perfect portrait-oriented
    matches would get skipped.
    
    This change checks orientation for exact matches as well; and will
    prefer the first found best match.
    
    Change-Id: Iaa93292ef60b94ab1f807b21e8a3494099c0b002
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199841
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    (cherry picked from commit d8a3c74a10e70bae243162cb08572a9c2f2552a3)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199888
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index 976242be6eee..243d7aed1299 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -823,6 +823,7 @@ void PrintDialog::setPaperSizes()
 #endif
     {
         int nExactMatch = -1;
+        int nExactRotatedMatch = -1;
         int nSizeMatch = -1;
         int nRotatedSizeMatch = -1;
         Size aSizeOfPaper = aPrt->GetSizeOfPaper();
@@ -860,8 +861,15 @@ void PrintDialog::setPaperSizes()
 
             mxPaperSizeBox->append_text(aPaperName);
 
+            // For exact match, check that paper orientation also matches
             if (ePaper != PAPER_USER && ePaper == mePaper)
-                nExactMatch = nPaper;
+            {
+                // Only get the first match, in case there are multiple papers 
with the same size
+                if (nExactMatch == -1 && aInfo.sloppyEqual(aPaperInfo))
+                    nExactMatch = nPaper;
+                else if (nExactRotatedMatch == -1 && 
aInfo.sloppyEqual(aRotatedPaperInfo))
+                    nExactRotatedMatch = nPaper;
+            }
 
             if (ePaper == PAPER_USER && aInfo.sloppyEqual(aPaperInfo))
                 nSizeMatch = nPaper;
@@ -872,6 +880,8 @@ void PrintDialog::setPaperSizes()
 
         if (nExactMatch != -1)
             mxPaperSizeBox->set_active(nExactMatch);
+        else if (nExactRotatedMatch != -1)
+            mxPaperSizeBox->set_active(nExactRotatedMatch);
         else if (nSizeMatch != -1)
             mxPaperSizeBox->set_active(nSizeMatch);
         else if (nRotatedSizeMatch != -1)

Reply via email to