vcl/inc/ppdparser.hxx                 |    8 ++++++--
 vcl/source/gdi/print.cxx              |    1 +
 vcl/unx/generic/print/genprnpsp.cxx   |   14 ++++++++------
 vcl/unx/generic/printer/ppdparser.cxx |   29 +++++++++++++++++++++++++----
 4 files changed, 40 insertions(+), 12 deletions(-)

New commits:
commit 6005aeca4416eb0d583fd12ab837afa91d9d18ec
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Wed Sep 21 22:22:38 2022 +0200
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Sep 22 19:40:02 2022 +0200

    tdf#151107 swap job orientation if paper matching swapped width/height
    
    if we eventually are forced to pick a final paper size which has the
    orthogonal orientation than that requested, then swap the orientation of
    the jobdata too
    
    and re-init the orientation to defaults in Printer::SetPaperSizeUser
    when we set a new user paper size rather than keeping the orig
    
    Change-Id: Ie9e783575734c7f9eec3984efd1357cae5375130
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140358
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/inc/ppdparser.hxx b/vcl/inc/ppdparser.hxx
index 5d4195783a68..7ef864bc9cfc 100644
--- a/vcl/inc/ppdparser.hxx
+++ b/vcl/inc/ppdparser.hxx
@@ -36,6 +36,8 @@
 
 namespace psp {
 
+enum class orientation;
+
 class PPDCache;
 class PPDTranslator;
 
@@ -110,7 +112,6 @@ struct PPDKeyhash
         { return reinterpret_cast<size_t>(pKey); }
 };
 
-
 /*
  * PPDParser - parses a PPD file and contains all available keys from it
  */
@@ -177,6 +178,9 @@ private:
     static void scanPPDDir( const OUString& rDir );
     static void initPPDFiles(PPDCache &rPPDCache);
     static OUString getPPDFile( const OUString& rFile );
+
+    OUString        matchPaperImpl(int nWidth, int nHeight, bool bDontSwap = 
false, psp::orientation* pOrientation = nullptr) const;
+
 public:
     ~PPDParser();
     static const PPDParser* getParser( const OUString& rFile );
@@ -201,7 +205,7 @@ public:
     // returns false if paper not found
 
     // match the best paper for width and height
-    OUString        matchPaper( int nWidth, int nHeight, bool bDontSwap = 
false ) const;
+    OUString        matchPaper( int nWidth, int nHeight, psp::orientation* 
pOrientation = nullptr ) const;
 
     bool getMargins( std::u16string_view rPaperName,
                      int &rLeft, int& rRight,
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 5300de9a881d..6225db3a6b35 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -1347,6 +1347,7 @@ bool Printer::SetPaperSizeUser( const Size& rSize )
         rData.SetPaperFormat( PAPER_USER );
         rData.SetPaperWidth( aPageSize.Width() );
         rData.SetPaperHeight( aPageSize.Height() );
+        rData.SetOrientation( Orientation::Portrait );
 
         if ( IsDisplayPrinter() )
         {
diff --git a/vcl/unx/generic/print/genprnpsp.cxx 
b/vcl/unx/generic/print/genprnpsp.cxx
index 5c17874c4dfb..30c4f884a041 100644
--- a/vcl/unx/generic/print/genprnpsp.cxx
+++ b/vcl/unx/generic/print/genprnpsp.cxx
@@ -569,6 +569,10 @@ bool PspSalInfoPrinter::SetData(
         const PPDKey* pKey;
         const PPDValue* pValue;
 
+        // merge orientation if necessary
+        if( nSetDataFlags & JobSetFlags::ORIENTATION )
+            aData.m_eOrientation = pJobSetup->GetOrientation() == 
Orientation::Landscape ? orientation::Landscape : orientation::Portrait;
+
         // merge papersize if necessary
         if( nSetDataFlags & JobSetFlags::PAPERSIZE )
         {
@@ -577,7 +581,8 @@ bool PspSalInfoPrinter::SetData(
             if( pJobSetup->GetPaperFormat() == PAPER_USER )
                 aPaper = aData.m_pParser->matchPaper(
                     TenMuToPt( pJobSetup->GetPaperWidth() ),
-                    TenMuToPt( pJobSetup->GetPaperHeight() ) );
+                    TenMuToPt( pJobSetup->GetPaperHeight() ),
+                    &aData.m_eOrientation );
             else
                 aPaper = 
OStringToOUString(PaperInfo::toPSName(pJobSetup->GetPaperFormat()), 
RTL_TEXTENCODING_ISO_8859_1);
 
@@ -591,7 +596,8 @@ bool PspSalInfoPrinter::SetData(
                 PaperInfo aInfo( pJobSetup->GetPaperFormat() );
                 aPaper = aData.m_pParser->matchPaper(
                     TenMuToPt( aInfo.getWidth() ),
-                    TenMuToPt( aInfo.getHeight() ) );
+                    TenMuToPt( aInfo.getHeight() ),
+                    &aData.m_eOrientation );
                 pValue = pKey->getValueCaseInsensitive( aPaper );
             }
 
@@ -619,10 +625,6 @@ bool PspSalInfoPrinter::SetData(
             // (e.g. SGENPRT has no InputSlot)
         }
 
-        // merge orientation if necessary
-        if( nSetDataFlags & JobSetFlags::ORIENTATION )
-            aData.m_eOrientation = pJobSetup->GetOrientation() == 
Orientation::Landscape ? orientation::Landscape : orientation::Portrait;
-
         // merge duplex if necessary
         if( nSetDataFlags & JobSetFlags::DUPLEXMODE )
         {
diff --git a/vcl/unx/generic/printer/ppdparser.cxx 
b/vcl/unx/generic/printer/ppdparser.cxx
index 6e980776e73e..dfe553caa6ed 100644
--- a/vcl/unx/generic/printer/ppdparser.cxx
+++ b/vcl/unx/generic/printer/ppdparser.cxx
@@ -1466,7 +1466,7 @@ bool PPDParser::getPaperDimension(
     return true;
 }
 
-OUString PPDParser::matchPaper(int nWidth, int nHeight, bool bDontSwap) const
+OUString PPDParser::matchPaperImpl(int nWidth, int nHeight, bool bSwaped, 
psp::orientation* pOrientation) const
 {
     if( ! m_pPaperDimensions )
         return OUString();
@@ -1497,13 +1497,34 @@ OUString PPDParser::matchPaper(int nWidth, int nHeight, 
bool bDontSwap) const
         }
     }
 
-    if( nPDim == -1 && ! bDontSwap )
+    if (nPDim == -1 && !bSwaped)
     {
         // swap portrait/landscape and try again
-        return matchPaper( nHeight, nWidth, true );
+        return matchPaperImpl(nHeight, nWidth, true, pOrientation);
     }
 
-    return nPDim != -1 ? m_pPaperDimensions->getValue( nPDim )->m_aOption : 
OUString();
+    if (nPDim == -1)
+        return OUString();
+
+    if (bSwaped && pOrientation)
+    {
+        switch (*pOrientation)
+        {
+            case psp::orientation::Portrait:
+                *pOrientation = psp::orientation::Landscape;
+            break;
+            case psp::orientation::Landscape:
+                *pOrientation = psp::orientation::Portrait;
+            break;
+        }
+    }
+
+    return m_pPaperDimensions->getValue( nPDim )->m_aOption;
+}
+
+OUString PPDParser::matchPaper(int nWidth, int nHeight, psp::orientation* 
pOrientation) const
+{
+    return matchPaperImpl(nHeight, nWidth, true, pOrientation);
 }
 
 OUString PPDParser::getDefaultInputSlot() const

Reply via email to