include/vcl/print.hxx          |    2 ++
 vcl/source/gdi/print3.cxx      |   11 +++++++----
 vcl/source/window/printdlg.cxx |   26 +++++++++++++++++++++++---
 3 files changed, 32 insertions(+), 7 deletions(-)

New commits:
commit f736e3a0c23acf908462bfd184e1224c78244224
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sat Aug 10 21:02:30 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sun Aug 11 16:22:55 2024 +0200

    Related: tdf#154959 suitable label printer paper size not auto-selected
    
    a) If the printer is the default, then it doesn't get a paper size auto
    selected in the paper combobox, even though the preview shows it rendered
    on a paper size that the printer supports.
    
    b) With that fixed, then if the printer is the default one then right
    paper gets selected automatically, but starting with another and then
    switching to it gets different results, so throw away the "page cache"
    on switching pages and get it again.
    
    Change-Id: Idd5254eac2668164b02b41a63943f65a222656d7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171721
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index a1aacf8f0d90..3728c2ca0219 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -496,6 +496,8 @@ public:
 
     SAL_DLLPRIVATE    DrawModeFlags     removeTransparencies( GDIMetaFile 
const & i_rIn, GDIMetaFile& o_rOut );
     SAL_DLLPRIVATE    void              resetPrinterOptions( bool 
i_bFileOutput );
+
+    SAL_DLLPRIVATE    void              invalidatePageCache();
 };
 
 class VCL_DLLPUBLIC PrinterOptionsHelper
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index 95745b61eaf6..2a0846a0a63d 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -857,6 +857,11 @@ void PrinterController::resetPrinterOptions( bool 
i_bFileOutput )
     mpImplData->mxPrinter->SetPrinterOptions( aOpt );
 }
 
+void PrinterController::invalidatePageCache()
+{
+    mpImplData->maPageCache.invalidate();
+}
+
 void PrinterController::setupPrinter( weld::Window* i_pParent )
 {
     bool bRet = false;
@@ -913,9 +918,7 @@ void PrinterController::setupPrinter( weld::Window* 
i_pParent )
         }
 
         if (bInvalidateCache)
-        {
-            mpImplData->maPageCache.invalidate();
-        }
+            invalidatePageCache();
     }
     else
     {
@@ -1061,7 +1064,7 @@ PrinterController::PageSize 
PrinterController::getPageFile( int i_nUnfilteredPag
         }
     }
     else
-        mpImplData->maPageCache.invalidate();
+        invalidatePageCache();
 
     o_rMtf.Clear();
 
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index 06b7dc8a385c..182b82ea9276 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -854,8 +854,12 @@ void PrintDialog::setPaperSizes()
     }
     else
     {
+        int nExactMatch = -1;
+        int nSizeMatch = -1;
+        int nRotatedSizeMatch = -1;
         Size aSizeOfPaper = aPrt->GetSizeOfPaper();
         PaperInfo aPaperInfo(aSizeOfPaper.getWidth(), 
aSizeOfPaper.getHeight());
+        PaperInfo aRotatedPaperInfo(aSizeOfPaper.getHeight(), 
aSizeOfPaper.getWidth());
         const LocaleDataWrapper& 
rLocWrap(Application::GetSettings().GetLocaleDataWrapper());
         o3tl::Length eUnit = o3tl::Length::mm;
         int nDigits = 0;
@@ -887,11 +891,23 @@ void PrintDialog::setPaperSizes()
 
             mxPaperSizeBox->append_text(aPaperName);
 
-            if ( (ePaper != PAPER_USER && ePaper == mePaper) ||
-                 (ePaper == PAPER_USER && aInfo.sloppyEqual(aPaperInfo) ) )
-                 mxPaperSizeBox->set_active( nPaper );
+            if (ePaper != PAPER_USER && ePaper == mePaper)
+                nExactMatch = nPaper;
+
+            if (ePaper == PAPER_USER && aInfo.sloppyEqual(aPaperInfo))
+                nSizeMatch = nPaper;
+
+            if (ePaper == PAPER_USER && aInfo.sloppyEqual(aRotatedPaperInfo))
+                nRotatedSizeMatch = nPaper;
         }
 
+        if (nExactMatch != -1)
+            mxPaperSizeBox->set_active(nExactMatch);
+        else if (nSizeMatch != -1)
+            mxPaperSizeBox->set_active(nSizeMatch);
+        else if (nRotatedSizeMatch != -1)
+            mxPaperSizeBox->set_active(nRotatedSizeMatch);
+
         mxPaperSizeBox->set_sensitive( true );
     }
 }
@@ -1977,12 +1993,16 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, 
rBox, void )
             // set new printer
             maPController->setPrinter( VclPtrInstance<Printer>( aNewPrinter ) 
);
             maPController->resetPrinterOptions( false  );
+            // invalidate page cache and start fresh
+            maPController->invalidatePageCache();
+            maFirstPageSize = Size();
 
             updateOrientationBox();
 
             // update text fields
             mxOKButton->set_label(maPrintText);
             updatePrinterText();
+            updateNup(false);
             setPaperSizes();
             maUpdatePreviewIdle.Start();
         }

Reply via email to