include/vcl/print.hxx                          |    6 ++
 sc/qa/uitest/calc_dialogs/printDialog.py       |   38 ++++++++++++
 sc/qa/uitest/data/tdf155218.ods                |binary
 sc/source/ui/inc/pfuncache.hxx                 |    7 +-
 sc/source/ui/inc/printfun.hxx                  |   18 +++++-
 sc/source/ui/unoobj/docuno.cxx                 |   53 +++++++++++++++--
 sc/source/ui/view/pfuncache.cxx                |   15 +++--
 sc/source/ui/view/printfun.cxx                 |   41 +++++++++----
 sw/qa/extras/rtfexport/data/piccrop.rtf        |   74 +++++++++++++++++++++++++
 sw/qa/extras/rtfexport/rtfexport8.cxx          |   25 ++++++++
 vcl/inc/printdlg.hxx                           |    2 
 vcl/source/gdi/print.cxx                       |    1 
 vcl/source/gdi/print3.cxx                      |    1 
 vcl/source/window/printdlg.cxx                 |   49 ++++++++++++++++
 writerfilter/source/dmapper/GraphicImport.cxx  |   12 +++-
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   10 +++
 writerfilter/source/rtftok/rtfvalue.cxx        |    9 +++
 writerfilter/source/rtftok/rtfvalue.hxx        |    6 ++
 18 files changed, 335 insertions(+), 32 deletions(-)

New commits:
commit 1ad60d6860fd92d58394061f3bdb49dce38ecf72
Author:     Tibor Nagy <tibor.nagy.ext...@allotropia.de>
AuthorDate: Sun Feb 11 16:25:48 2024 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Fri Feb 23 15:37:31 2024 +0100

    tdf#155218 sc: fix incorrect print area
    
    In the print dialog, changes to the page orientation should not alter
    the print area that is defined by the page style.
    
    issue caused by commit I5e494a0714e398221bee00744d7e25c419a41df7
    (tdf#155218 sc: fix different page orientation in print dialog)
    
    Change-Id: I44eb3b30df0e8a227743df334da35316f86a0679
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163231
    Tested-by: Jenkins
    Reviewed-by: Nagy Tibor <tibor.nagy.ext...@allotropia.de>

diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index 1ebab3b48177..5fb7b2b286d1 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -514,6 +514,7 @@ bool 
Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController,
             PrintDialog aDlg(xController->getWindow(), xController);
             if (!aDlg.run())
             {
+                xController->getPrinter()->SetUsePrintDialogSetting(false);
                 xController->abortJob();
                 return false;
             }
commit c8f7ecd06aec9305a39678b28239e163475b8cfd
Author:     Tibor Nagy <tibor.nagy.ext...@allotropia.de>
AuthorDate: Wed Jan 31 16:49:24 2024 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Fri Feb 23 15:36:02 2024 +0100

    tdf#155218 sc: fix different page orientation in print dialog
    
    The page orientation is correct if you set it in the page style first.
    However, if you change it in the Print dialog the page layout and size
    refresh but the content orientation remains the same.
    
    Change-Id: I5e494a0714e398221bee00744d7e25c419a41df7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162845
    Tested-by: Jenkins
    Reviewed-by: Nagy Tibor <tibor.nagy.ext...@allotropia.de>

diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index e23cf8d0af1b..870ed5d915a1 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -80,6 +80,7 @@ private:
     JobSetup                    maJobSetup;
     Point                       maPageOffset;
     Size                        maPaperSize;
+    Size                        maPrintPageSize;
     ErrCode                     mnError;
     sal_uInt16                  mnPageQueueSize;
     sal_uInt16                  mnCopyCount;
@@ -91,6 +92,7 @@ private:
     bool                        mbInPrintPage;
     bool                        mbNewJobSetup;
     bool                        mbSinglePrintJobs;
+    bool                        mbUsePrintSetting;
 
     VCL_DLLPRIVATE void         ImplInitData();
     VCL_DLLPRIVATE void         ImplInit( SalPrinterQueueInfo* pInfo );
@@ -220,6 +222,10 @@ public:
     VCL_DLLPRIVATE void         SetPrinterOptions( const 
vcl::printer::Options& rOptions );
     const vcl::printer::Options& GetPrinterOptions() const { return( 
*mpPrinterOptions ); }
 
+    void                        SetUsePrintDialogSetting(bool bUsed) { 
mbUsePrintSetting = bUsed; }
+    bool                        IsUsePrintDialogSetting() { return 
mbUsePrintSetting; }
+    void                        SetPrintPageSize(Size aPrintPageSize) { 
maPrintPageSize = aPrintPageSize; }
+    Size                        GetPrintPageSize() { return maPrintPageSize; }
     bool                        SetOrientation( Orientation eOrient );
     Orientation                 GetOrientation() const;
     void                        SetDuplexMode( DuplexMode );
diff --git a/sc/qa/uitest/calc_dialogs/printDialog.py 
b/sc/qa/uitest/calc_dialogs/printDialog.py
new file mode 100644
index 000000000000..3e1290b9c8af
--- /dev/null
+++ b/sc/qa/uitest/calc_dialogs/printDialog.py
@@ -0,0 +1,38 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file, 
select_by_text
+
+class printDialog(UITestCase):
+    def test_printDialog(self):
+        with self.ui_test.load_file(get_url_for_data_file("tdf155218.ods")):
+            with self.ui_test.execute_dialog_through_command(".uno:Print", 
close_button="cancel") as xDialog:
+
+                xPortraiTotalNumberPages = xDialog.getChild("totalnumpages")
+                
self.assertEqual(get_state_as_dict(xPortraiTotalNumberPages)["Text"], "/ 2")
+
+                xPortraiPageRange = xDialog.getChild("pagerange")
+                self.assertEqual(get_state_as_dict(xPortraiPageRange)["Text"], 
"1-2")
+
+                xpageorientationbox = xDialog.getChild("pageorientationbox")
+                select_by_text(xpageorientationbox, "Landscape")
+
+                # Without the fix in place, this test would have failed with
+                # Expected: "/ 1"
+                # Actual  : "/ 2"
+                xLandscapeTotalNumberPages = xDialog.getChild("totalnumpages")
+                
self.assertEqual(get_state_as_dict(xLandscapeTotalNumberPages)["Text"], "/ 1")
+
+                # Without the fix in place, this test would have failed with
+                # Expected: "1"
+                # Actual  : "1-2"
+                xLandscapePageRange = xDialog.getChild("pagerange")
+                
self.assertEqual(get_state_as_dict(xLandscapePageRange)["Text"], "1")
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/qa/uitest/data/tdf155218.ods b/sc/qa/uitest/data/tdf155218.ods
new file mode 100644
index 000000000000..cd6417973972
Binary files /dev/null and b/sc/qa/uitest/data/tdf155218.ods differ
diff --git a/sc/source/ui/inc/pfuncache.hxx b/sc/source/ui/inc/pfuncache.hxx
index 5621cd2628ac..7cd286f39223 100644
--- a/sc/source/ui/inc/pfuncache.hxx
+++ b/sc/source/ui/inc/pfuncache.hxx
@@ -90,10 +90,13 @@ class ScPrintFuncCache
     std::vector<tools::Long>       nFirstAttr;
     std::vector<ScPrintPageLocation> aLocations;
     bool                    bLocInitialized;
+    Size                    aPrintPageSize;          // print page size in 
Print dialog
+    bool                    bPrintPageLandscape;     // print page orientation 
in Print dialog
+    bool                    bUsePrintDialogSetting;  // use Print dialog 
setting
 
 public:
-            ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
-                                ScPrintSelectionStatus aStatus );
+            ScPrintFuncCache(ScDocShell* pD, const ScMarkData& rMark, 
ScPrintSelectionStatus aStatus,
+                             Size aPageSize = {}, bool bLandscape = false, 
bool bUse = false);
             ~ScPrintFuncCache();
 
     bool    IsSameSelection( const ScPrintSelectionStatus& rStatus ) const;
diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx
index f9780bd0e53c..2e9dd7bb49d1 100644
--- a/sc/source/ui/inc/printfun.hxx
+++ b/sc/source/ui/inc/printfun.hxx
@@ -312,15 +312,25 @@ private:
 
     ScPageBreakData*    pPageData;          // for recording the breaks etc.
 
+    Size                aPrintPageSize;         // print page size in Print 
dialog
+    bool                bPrintPageLandscape;    // print page orientation in 
Print dialog
+    bool                bUsePrintDialogSetting; // use Print dialog setting
+
 public:
                     ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, 
SCTAB nTab,
                                  tools::Long nPage = 0, tools::Long nDocP = 0,
                                  const ScRange* pArea = nullptr,
                                  const ScPrintOptions* pOptions = nullptr,
-                                 ScPageBreakData* pData = nullptr );
+                                 ScPageBreakData* pData = nullptr,
+                                 Size aPrintPageSize = {},
+                                 bool bPrintPageLandscape = false,
+                                 bool bUsePrintDialogSetting = false );
 
                     ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter,
-                                const ScPrintState& rState, const 
ScPrintOptions* pOptions );
+                                const ScPrintState& rState, const 
ScPrintOptions* pOptions,
+                                Size aPrintPageSize = {},
+                                bool bPrintPageLandscape = false,
+                                bool bUsePrintDialogSetting = false );
 
                     // ctors for device other than printer - for preview and 
pdf:
 
@@ -331,7 +341,9 @@ public:
 
                     ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
                                  const ScPrintState& rState,
-                                 const ScPrintOptions* pOptions );
+                                 const ScPrintOptions* pOptions, Size 
aPrintPageSize = {},
+                                 bool bPrintPageLandscape = false,
+                                 bool bUsePrintDialogSetting = false);
 
                     ~ScPrintFunc();
 
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index a4fc5f6d60de..d70716b0a4c1 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1570,6 +1570,24 @@ static bool lcl_ParseTarget( const OUString& rTarget, 
ScRange& rTargetRange, too
     return bRangeValid;
 }
 
+ static void lcl_SetPrintPage(const uno::Sequence<beans::PropertyValue>& 
rOptions, Size& aSize,
+                             bool& bLandscape, bool& bUsed)
+{
+    OutputDevice* pDev = lcl_GetRenderDevice(rOptions);
+    if (pDev && pDev->GetOutDevType() == OUTDEV_PRINTER)
+    {
+        Printer* pPrinter = dynamic_cast<Printer*>(pDev);
+        if (pPrinter && pPrinter->IsUsePrintDialogSetting())
+        {
+            bUsed = true;
+            bLandscape = (pPrinter->GetOrientation() == 
Orientation::Landscape);
+            aSize = pPrinter->GetPrintPageSize();
+            aSize.setWidth(o3tl::convert(aSize.Width(), o3tl::Length::mm100, 
o3tl::Length::twip));
+            aSize.setHeight(o3tl::convert(aSize.Height(), o3tl::Length::mm100, 
o3tl::Length::twip));
+        }
+    }
+}
+
 bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
                                      const uno::Sequence< beans::PropertyValue 
>& rOptions,
                                      ScMarkData& rMark,
@@ -1756,13 +1774,19 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const 
uno::Any& aSelection,
     if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr, 
bRenderToGraphic ) )
         return 0;
 
+    Size aPrintPageSize;
+    bool bPrintPageLandscape = false;
+    bool bUsePrintDialogSetting = false;
+    lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, 
bUsePrintDialogSetting);
+
     //  The same ScPrintFuncCache object in pPrintFuncCache is used as long as
     //  the same selection is used (aStatus) and the document isn't changed
     //  (pPrintFuncCache is cleared in Notify handler)
 
-    if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
+    if (!pPrintFuncCache || !pPrintFuncCache->IsSameSelection(aStatus) || 
bUsePrintDialogSetting)
     {
-        pPrintFuncCache.reset(new ScPrintFuncCache( pDocShell, aMark, aStatus 
));
+        pPrintFuncCache.reset(new ScPrintFuncCache(pDocShell, aMark, aStatus, 
aPrintPageSize,
+                                                   bPrintPageLandscape, 
bUsePrintDialogSetting));
     }
     sal_Int32 nPages = pPrintFuncCache->GetPageCount();
 
@@ -1988,12 +2012,23 @@ uno::Sequence<beans::PropertyValue> SAL_CALL 
ScModelObj::getRenderer( sal_Int32
     }
     else
     {
+        Size aPrintPageSize;
+        bool bPrintPageLandscape = false;
+        bool bUsePrintDialogSetting = false;
+        lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, 
bUsePrintDialogSetting);
+
         std::unique_ptr<ScPrintFunc, o3tl::default_delete<ScPrintFunc>> 
pPrintFunc;
         if (m_pPrintState && m_pPrintState->nPrintTab == nTab)
-            pPrintFunc.reset(new ScPrintFunc(pDocShell, 
pDocShell->GetPrinter(), *m_pPrintState, &aStatus.GetOptions()));
+            pPrintFunc.reset(new ScPrintFunc(pDocShell, 
pDocShell->GetPrinter(), *m_pPrintState,
+                                             &aStatus.GetOptions(), 
aPrintPageSize,
+                                             bPrintPageLandscape,
+                                             bUsePrintDialogSetting));
         else
             pPrintFunc.reset(new ScPrintFunc(pDocShell, 
pDocShell->GetPrinter(), nTab,
-                                             
pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, 
&aStatus.GetOptions()));
+                                             
pPrintFuncCache->GetFirstAttr(nTab), nTotalPages,
+                                             pSelRange, &aStatus.GetOptions(), 
nullptr,
+                                             aPrintPageSize, 
bPrintPageLandscape,
+                                             bUsePrintDialogSetting));
         pPrintFunc->SetRenderFlag( true );
 
         sal_Int32 nContent = 0;
@@ -2213,14 +2248,20 @@ void SAL_CALL ScModelObj::render( sal_Int32 
nSelRenderer, const uno::Any& aSelec
         aDrawViewKeeper.mpDrawView->SetPrintPreview();
     }
 
+    Size aPrintPageSize;
+    bool bPrintPageLandscape = false;
+    bool bUsePrintDialogSetting = false;
+    lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, 
bUsePrintDialogSetting);
+
     //  to increase performance, ScPrintState might be used here for subsequent
     //  pages of the same sheet
 
-
     std::unique_ptr<ScPrintFunc, o3tl::default_delete<ScPrintFunc>> pPrintFunc;
     if (m_pPrintState && m_pPrintState->nPrintTab == nTab
         && ! pSelRange) // tdf#120161 use selection to set required printed 
area
-        pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, *m_pPrintState, 
&aStatus.GetOptions()));
+        pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, *m_pPrintState, 
&aStatus.GetOptions(),
+                                         aPrintPageSize, bPrintPageLandscape,
+                                         bUsePrintDialogSetting));
     else
         pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, nTab, 
pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, 
&aStatus.GetOptions()));
 
diff --git a/sc/source/ui/view/pfuncache.cxx b/sc/source/ui/view/pfuncache.cxx
index fe563ba961df..078633da5da0 100644
--- a/sc/source/ui/view/pfuncache.cxx
+++ b/sc/source/ui/view/pfuncache.cxx
@@ -27,12 +27,17 @@
 #include <prevloc.hxx>
 #include <utility>
 
-ScPrintFuncCache::ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
-                                    ScPrintSelectionStatus aStatus ) :
+ScPrintFuncCache::ScPrintFuncCache(ScDocShell* pD, const ScMarkData& rMark,
+                                   ScPrintSelectionStatus aStatus, Size 
aPageSize, bool bLandscape,
+                                   bool bUsed)
+    :
     aSelection(std::move( aStatus )),
     pDocSh( pD ),
     nTotalPages( 0 ),
-    bLocInitialized( false )
+    bLocInitialized( false ),
+    aPrintPageSize( aPageSize ),
+    bPrintPageLandscape( bLandscape ),
+    bUsePrintDialogSetting( bUsed )
 {
     //  page count uses the stored cell widths for the printer anyway,
     //  so ScPrintFunc with the document's printer can be used to count
@@ -62,7 +67,9 @@ ScPrintFuncCache::ScPrintFuncCache( ScDocShell* pD, const 
ScMarkData& rMark,
         tools::Long nThisTab = 0;
         if ( rMark.GetTableSelect( nTab ) )
         {
-            ScPrintFunc aFunc( pDocSh, pPrinter, nTab, nAttrPage, 0, 
pSelRange, &aSelection.GetOptions() );
+            ScPrintFunc aFunc(pDocSh, pPrinter, nTab, nAttrPage, 0, pSelRange,
+                              &aSelection.GetOptions(), nullptr, 
aPrintPageSize,
+                              bPrintPageLandscape, bUsePrintDialogSetting);
             nThisTab = aFunc.GetTotalPages();
             nFirstAttr.push_back( aFunc.GetFirstPageNo() );         // from 
page style or previous sheet
         }
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 84e21da02214..c526781d1346 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -195,10 +195,9 @@ void ScPrintFunc::Construct( const ScPrintOptions* 
pOptions )
     pPageData = nullptr;       // is only needed for initialisation
 }
 
-ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB 
nTab,
-                            tools::Long nPage, tools::Long nDocP, const 
ScRange* pArea,
-                            const ScPrintOptions* pOptions,
-                            ScPageBreakData* pData )
+ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB 
nTab, tools::Long nPage,
+                         tools::Long nDocP, const ScRange* pArea, const 
ScPrintOptions* pOptions,
+                         ScPageBreakData* pData, Size aSize, bool 
bPrintLandscape, bool bUsed)
     :   pDocShell           ( pShell ),
         rDoc(pDocShell->GetDocument()),
         pPrinter            ( pNewPrinter ),
@@ -215,7 +214,10 @@ ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* 
pNewPrinter, SCTAB nTa
         nTabPages           ( 0 ),
         nTotalPages         ( 0 ),
         bPrintAreaValid     ( false ),
-        pPageData           ( pData )
+        pPageData           ( pData ),
+        aPrintPageSize      ( aSize ),
+        bPrintPageLandscape ( bPrintLandscape ),
+        bUsePrintDialogSetting ( bUsed )
 {
     pDev = pPrinter.get();
     aSrcOffset = pPrinter->PixelToLogic(pPrinter->GetPageOffsetPixel(), 
MapMode(MapUnit::Map100thMM));
@@ -225,8 +227,9 @@ ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* 
pNewPrinter, SCTAB nTa
     Construct( pOptions );
 }
 
-ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter,
-                         const ScPrintState& rState, const ScPrintOptions* 
pOptions)
+ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, const 
ScPrintState& rState,
+                         const ScPrintOptions* pOptions, Size aSize, bool 
bPrintLandscape,
+                         bool bUsed)
     :   pDocShell           ( pShell ),
         rDoc(pDocShell->GetDocument()),
         pPrinter            ( pNewPrinter ),
@@ -236,7 +239,10 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* 
pNewPrinter,
         bPrintCurrentTable  ( false ),
         bMultiArea          ( false ),
         mbHasPrintRange(true),
-        pPageData           ( nullptr )
+        pPageData           ( nullptr ),
+        aPrintPageSize      ( aSize ),
+        bPrintPageLandscape ( bPrintLandscape ),
+        bUsePrintDialogSetting ( bUsed )
 {
     pDev = pPrinter.get();
 
@@ -293,7 +299,10 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, 
ScDocShell* pShell, SCTAB nTab,
         nTabPages           ( 0 ),
         nTotalPages         ( 0 ),
         bPrintAreaValid     ( false ),
-        pPageData           ( nullptr )
+        pPageData           ( nullptr ),
+        aPrintPageSize      ( Size() ),
+        bPrintPageLandscape ( false ),
+        bUsePrintDialogSetting ( false )
 {
     pDev = pOutDev;
     m_aRanges.m_xPageEndX = std::make_shared<std::vector<SCCOL>>();
@@ -302,8 +311,9 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, 
ScDocShell* pShell, SCTAB nTab,
     Construct( pOptions );
 }
 
-ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
-                             const ScPrintState& rState, const ScPrintOptions* 
pOptions )
+ScPrintFunc::ScPrintFunc(OutputDevice* pOutDev, ScDocShell* pShell, const 
ScPrintState& rState,
+                         const ScPrintOptions* pOptions, Size aSize, bool 
bPrintLandscape,
+                         bool bUsed)
     :   pDocShell           ( pShell ),
         rDoc(pDocShell->GetDocument()),
         pPrinter            ( nullptr ),
@@ -313,7 +323,10 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, 
ScDocShell* pShell,
         bPrintCurrentTable  ( false ),
         bMultiArea          ( false ),
         mbHasPrintRange(true),
-        pPageData           ( nullptr )
+        pPageData           ( nullptr ),
+        aPrintPageSize      ( aSize ),
+        bPrintPageLandscape ( bPrintLandscape ),
+        bUsePrintDialogSetting ( bUsed )
 {
     pDev = pOutDev;
 
@@ -877,13 +890,13 @@ void ScPrintFunc::InitParam( const ScPrintOptions* 
pOptions )
 
     const SvxPageItem* pPageItem = &pParamSet->Get( ATTR_PAGE );
     nPageUsage          = pPageItem->GetPageUsage();
-    bLandscape          = pPageItem->IsLandscape();
+    bLandscape          = bUsePrintDialogSetting ? bPrintPageLandscape : 
pPageItem->IsLandscape();
     aFieldData.eNumType = pPageItem->GetNumType();
 
     bCenterHor = pParamSet->Get(ATTR_PAGE_HORCENTER).GetValue();
     bCenterVer = pParamSet->Get(ATTR_PAGE_VERCENTER).GetValue();
 
-    aPageSize = pParamSet->Get(ATTR_PAGE_SIZE).GetSize();
+    aPageSize = bUsePrintDialogSetting ? aPrintPageSize : 
pParamSet->Get(ATTR_PAGE_SIZE).GetSize();
     if ( !aPageSize.Width() || !aPageSize.Height() )
     {
         OSL_FAIL("PageSize Null ?!?!?");
diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx
index bf058b079717..26d5ebb2777d 100644
--- a/vcl/inc/printdlg.hxx
+++ b/vcl/inc/printdlg.hxx
@@ -231,6 +231,8 @@ namespace vcl
         void readFromSettings();
         void setPaperOrientation( Orientation eOrientation, bool fromUser );
         void updateOrientationBox( bool bAutomatic = true );
+        void updatePageSize( int nOrientation );
+        void updatePageRange( const sal_Int32 nPages );
         bool hasOrientationChanged() const;
         void setPreviewText();
         void updatePrinterText();
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 94b80680e5d9..98aca69aed5d 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -449,6 +449,7 @@ void Printer::ImplInitData()
     mbInPrintPage       = false;
     mbNewJobSetup       = false;
     mbSinglePrintJobs   = false;
+    mbUsePrintSetting   = false;
     mpInfoPrinter       = nullptr;
     mpPrinter           = nullptr;
     mpDisplayDev        = nullptr;
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index 4ea3c6ca69e8..ff3dd99dcaca 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -945,6 +945,9 @@ void PrintDialog::preparePreview( bool i_bMayUseCache )
     sal_Int32 nPages = maPController->getFilteredPageCount();
     mnCachedPages = nPages;
 
+    if (!i_bMayUseCache)
+        updatePageRange(nPages);
+
     setPreviewText();
 
     if ( !hasPreview() )
@@ -1001,6 +1004,43 @@ void PrintDialog::preparePreview( bool i_bMayUseCache )
     mxPageEdit->set_sensitive( nPages > 1 );
 }
 
+void PrintDialog::updatePageRange(sal_Int32 nPages)
+{
+    if (nPages > 0 && !mxPageRangesRadioButton->get_active())
+    {
+        OUStringBuffer aBuf(32);
+        aBuf.append("1");
+        if (nPages > 1)
+        {
+            aBuf.append("-" + OUString::number(nPages));
+        }
+        maPController->setValue("PageRange", 
css::uno::Any(aBuf.makeStringAndClear()));
+        setupOptionalUI();
+    }
+}
+
+void PrintDialog::updatePageSize(int nOrientation)
+{
+    VclPtr<Printer> aPrt(maPController->getPrinter());
+
+    PaperInfo aInfo = aPrt->GetPaperInfo(mxPaperSizeBox->get_active());
+    Size aSize(aInfo.getWidth(), aInfo.getHeight());
+    if (aSize.IsEmpty())
+        aSize = aPrt->GetSizeOfPaper();
+
+    if (nOrientation != ORIENTATION_AUTOMATIC)
+    {
+        if ((nOrientation == ORIENTATION_PORTRAIT && aSize.Width() > 
aSize.Height())
+            || (nOrientation == ORIENTATION_LANDSCAPE && aSize.Width() < 
aSize.Height()))
+        {
+            aSize = Size(aSize.Height(), aSize.Width());
+        }
+    }
+
+    aPrt->SetPrintPageSize(aSize);
+    aPrt->SetUsePrintDialogSetting(true);
+}
+
 void PrintDialog::updateOrientationBox( const bool bAutomatic )
 {
     if ( !bAutomatic )
@@ -1913,6 +1953,9 @@ IMPL_LINK(PrintDialog, ClickHdl, weld::Button&, rButton, 
void)
             }
 
             updateOrientationBox( false );
+
+            updatePageSize(mxOrientationBox->get_active());
+
             setupPaperSidesBox();
 
             // tdf#63905 don't use cache: page size may change
@@ -1954,6 +1997,7 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, 
void )
             maUpdatePreviewIdle.Start();
         }
 
+        updatePageSize(mxOrientationBox->get_active());
         setupPaperSidesBox();
     }
     else if ( &rBox == mxPaperSidesBox.get() )
@@ -1967,6 +2011,7 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, 
void )
         if ( nOrientation != ORIENTATION_AUTOMATIC )
             setPaperOrientation( static_cast<Orientation>( nOrientation - 1 ), 
true );
 
+        updatePageSize(nOrientation);
         updateNup( false );
     }
     else if ( &rBox == mxNupOrderBox.get() )
@@ -1993,7 +2038,9 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, 
void )
 
         maPController->setPaperSizeFromUser( Size( aInfo.getWidth(), 
aInfo.getHeight() ) );
 
-        maUpdatePreviewIdle.Start();
+        updatePageSize(mxOrientationBox->get_active());
+
+        maUpdatePreviewNoCacheIdle.Start();
     }
 }
 
commit 300da1c069fe5c9ed016fa62e7d01c0d368915c8
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Tue Feb 13 14:45:25 2024 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Fri Feb 23 15:33:29 2024 +0100

    tdf#155663 writerfilter: RTF import: don't lose \piccrop*
    
    For DOCX the a:srcRect is imported in oox module in BlipFillContext and
    set on the XShape; obviously that doesn't work for RTF.
    
    The crop was already taken into account in
    RTFDocumentImpl::resolvePict(), but only to set the size of the picture;
    to actually set a crop effect, set shape's "GraphicsCrop" property
    in dmapper::GraphicImport::lcl_attribute().
    
    Change-Id: Ib12853724744542a09b0073fefc42ad32bb2ff19
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163310
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 47f50af3f057bac1739b7d17d781c0b1d05faa95)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163331
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/sw/qa/extras/rtfexport/data/piccrop.rtf 
b/sw/qa/extras/rtfexport/data/piccrop.rtf
new file mode 100644
index 000000000000..4e8a70420575
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/piccrop.rtf
@@ -0,0 +1,74 @@
+{ 
tf1deflang1025nsinsicpg1252\uc1deff31507\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi31507\deflang1033\deflangfe1028
       hemelang1033    hemelangfe1028  hemelangcs1025{onttbl{1bidi swiss
charset0prq2{\*\panose 020b0604020202020204}Arial{\*alt Arial};}
+{14bidi nilcharset136prq2{\*\panose 02010601000101010101}PMingLiU{\*alt 
Arial Unicode MS};}{34bidi romancharset0prq2{\*\panose 
02040503050406030204}Cambria Math;}
+{37bidi swisscharset0prq2{\*\panose 020f0502020204030204}Calibri;}{291
bidi nilcharset136prq2{\*\panose 00000000000000000000}@PMingLiU;}
+{lomajor31500bidi romancharset0prq2{\*\panose 02020603050405020304}Times 
New Roman{\*alt Arial};}{dbmajor31501bidi nilcharset136prq2{\*\panose 
02010601000101010101}PMingLiU{\*alt Arial Unicode MS};}
+{himajor31502bidi swisscharset0prq2{\*\panose 
020f0302020204030204}Calibri Light;}{bimajor31503bidi romancharset0
prq2{\*\panose 02020603050405020304}Times New Roman{\*alt Arial};}
+{lominor31504bidi romancharset0prq2{\*\panose 02020603050405020304}Times 
New Roman{\*alt Arial};}{dbminor31505bidi nilcharset136prq2{\*\panose 
02010601000101010101}PMingLiU{\*alt Arial Unicode MS};}
+{himinor31506bidi swisscharset0prq2{\*\panose 
020f0502020204030204}Calibri;}{biminor31507bidi swisscharset0
prq2{\*\panose 020b0604020202020204}Arial{\*alt Arial};}{302bidi swiss
charset238prq2 Arial CE{\*alt Arial};}
+{303bidi swisscharset204prq2 Arial Cyr{\*alt Arial};}{305bidi swiss
charset161prq2 Arial Greek{\*alt Arial};}{306bidi swisscharset162prq2 
Arial Tur{\*alt Arial};}
+{307bidi swisscharset177prq2 Arial (Hebrew){\*alt Arial};}{308bidi 
swisscharset178prq2 Arial (Arabic){\*alt Arial};}{309bidi swiss
charset186prq2 Arial Baltic{\*alt Arial};}
+{310bidi swisscharset163prq2 Arial (Vietnamese){\*alt Arial};}{632bidi 
romancharset238prq2 Cambria Math CE;}{633bidi romancharset204prq2 
Cambria Math Cyr;}{635bidi romancharset161prq2 Cambria Math Greek;}
+{636bidi romancharset162prq2 Cambria Math Tur;}{639bidi roman
charset186prq2 Cambria Math Baltic;}{640bidi romancharset163prq2 Cambria 
Math (Vietnamese);}{662bidi swisscharset238prq2 Calibri CE;}
+{663bidi swisscharset204prq2 Calibri Cyr;}{665bidi swisscharset161
prq2 Calibri Greek;}{666bidi swisscharset162prq2 Calibri Tur;}{667bidi 
swisscharset177prq2 Calibri (Hebrew);}
+{668bidi swisscharset178prq2 Calibri (Arabic);}{669bidi swiss
charset186prq2 Calibri Baltic;}{670bidi swisscharset163prq2 Calibri 
(Vietnamese);}
+{lomajor31508bidi romancharset238prq2 Times New Roman CE{\*alt 
Arial};}{lomajor31509bidi romancharset204prq2 Times New Roman Cyr{\*alt 
Arial};}
+{lomajor31511bidi romancharset161prq2 Times New Roman Greek{\*alt 
Arial};}{lomajor31512bidi romancharset162prq2 Times New Roman Tur{\*alt 
Arial};}
+{lomajor31513bidi romancharset177prq2 Times New Roman (Hebrew){\*alt 
Arial};}{lomajor31514bidi romancharset178prq2 Times New Roman (Arabic){\*
alt Arial};}
+{lomajor31515bidi romancharset186prq2 Times New Roman Baltic{\*alt 
Arial};}{lomajor31516bidi romancharset163prq2 Times New Roman 
(Vietnamese){\*alt Arial};}{himajor31528bidi swisscharset238prq2 Calibri 
Light CE;}
+{himajor31529bidi swisscharset204prq2 Calibri Light Cyr;}{himajor31531
bidi swisscharset161prq2 Calibri Light Greek;}{himajor31532bidi swiss
charset162prq2 Calibri Light Tur;}
+{himajor31533bidi swisscharset177prq2 Calibri Light (Hebrew);}{himajor
31534bidi swisscharset178prq2 Calibri Light (Arabic);}{himajor31535bidi 
swisscharset186prq2 Calibri Light Baltic;}
+{himajor31536bidi swisscharset163prq2 Calibri Light (Vietnamese);}{
bimajor31538bidi romancharset238prq2 Times New Roman CE{\*alt Arial};}{
bimajor31539bidi romancharset204prq2 Times New Roman Cyr{\*alt Arial};}
+{bimajor31541bidi romancharset161prq2 Times New Roman Greek{\*alt 
Arial};}{bimajor31542bidi romancharset162prq2 Times New Roman Tur{\*alt 
Arial};}
+{bimajor31543bidi romancharset177prq2 Times New Roman (Hebrew){\*alt 
Arial};}{bimajor31544bidi romancharset178prq2 Times New Roman (Arabic){\*
alt Arial};}
+{bimajor31545bidi romancharset186prq2 Times New Roman Baltic{\*alt 
Arial};}{bimajor31546bidi romancharset163prq2 Times New Roman 
(Vietnamese){\*alt Arial};}
+{lominor31548bidi romancharset238prq2 Times New Roman CE{\*alt 
Arial};}{lominor31549bidi romancharset204prq2 Times New Roman Cyr{\*alt 
Arial};}
+{lominor31551bidi romancharset161prq2 Times New Roman Greek{\*alt 
Arial};}{lominor31552bidi romancharset162prq2 Times New Roman Tur{\*alt 
Arial};}
+{lominor31553bidi romancharset177prq2 Times New Roman (Hebrew){\*alt 
Arial};}{lominor31554bidi romancharset178prq2 Times New Roman (Arabic){\*
alt Arial};}
+{lominor31555bidi romancharset186prq2 Times New Roman Baltic{\*alt 
Arial};}{lominor31556bidi romancharset163prq2 Times New Roman 
(Vietnamese){\*alt Arial};}{himinor31568bidi swisscharset238prq2 Calibri 
CE;}
+{himinor31569bidi swisscharset204prq2 Calibri Cyr;}{himinor31571bidi 
swisscharset161prq2 Calibri Greek;}{himinor31572bidi swisscharset162
prq2 Calibri Tur;}
+{himinor31573bidi swisscharset177prq2 Calibri (Hebrew);}{himinor31574
bidi swisscharset178prq2 Calibri (Arabic);}{himinor31575bidi swiss
charset186prq2 Calibri Baltic;}
+{himinor31576bidi swisscharset163prq2 Calibri (Vietnamese);}{biminor
31578bidi swisscharset238prq2 Arial CE{\*alt Arial};}{biminor31579bidi 
swisscharset204prq2 Arial Cyr{\*alt Arial};}
+{biminor31581bidi swisscharset161prq2 Arial Greek{\*alt Arial};}{
biminor31582bidi swisscharset162prq2 Arial Tur{\*alt Arial};}{biminor
31583bidi swisscharset177prq2 Arial (Hebrew){\*alt Arial};}
+{biminor31584bidi swisscharset178prq2 Arial (Arabic){\*alt Arial};}{
biminor31585bidi swisscharset186prq2 Arial Baltic{\*alt Arial};}{biminor
31586bidi swisscharset163prq2 Arial (Vietnamese){\*alt Arial};}
+{292bidi romancharset238prq2 Times New Roman CE{\*alt Arial};}{293bidi 
romancharset204prq2 Times New Roman Cyr{\*alt Arial};}{295bidi roman
charset161prq2 Times New Roman Greek{\*alt Arial};}
+{296bidi romancharset162prq2 Times New Roman Tur{\*alt Arial};}{297
bidi romancharset177prq2 Times New Roman (Hebrew){\*alt Arial};}{298bidi 
romancharset178prq2 Times New Roman (Arabic){\*alt Arial};}
+{299bidi romancharset186prq2 Times New Roman Baltic{\*alt Arial};}{300
bidi romancharset163prq2 Times New Roman (Vietnamese){\*alt Arial};}}{+ 
ed0\green255lue0; ed255\green0lue255; ed255\green0lue0; ed255\green255lue0; 
ed255\green255lue255; ed0\green0lue128; ed0\green128lue128; 
ed0\green128lue0; ed128\green0lue128; ed128\green0lue0; ed128\green128lue0;
+ ed128\green128lue128; ed192\green192lue192;}{\*\defchp 
s22\lochf31506\hichf31506\dbchf31505 }{\*\defpap \ql \li0 
i0\sa160\sl259\slmult1\widctlpar\wrapdefaultspalphaspnumaautodjustright 
in0\lin0\itap0 }
oqfpromote {\stylesheet{
+\ql \li0 i0\sa160\sl259\slmult1\widctlpar\wrapdefaultspalphaspnum
aautodjustright in0\lin0\itap0  tlchcs1 f31507fs22lang1025 \ltrchcs0 
s22\lang1033\langfe1028\loch31506\hichf31506\dbchf31505+\snext0 \sqformat 
\spriority0 Normal;}{\*+  s11     srowd   rftsWidthB3     rpaddl108       
rpaddr108       rpaddfl3        rpaddft3        rpaddfb3        rpaddfr3        
blind0  blindtype3      svertalt        sbrdrt  sbrdrl  sbrdrb  sbrdrr  
sbrdrdgl        sbrdrdgr        sbrdrh  sbrdrv \ql \li0 i0\sa160\sl259\slmult1
+\widctlpar\wrapdefaultspalphaspnumaautodjustright in0\lin0\itap0  tlchcs1 
f31507fs22lang1025 \ltrchcs0 s22\lang1033\langfe1028\loch
31506\hichf31506\dbchf31505+Normal Table;}}{\* sidtbl  sid1539605 sid6818220 
sid9513591}{\mmathPr\mmathFont34\mbrkBin0\mbrkBinSub0\msmallFrac0\mdispDef1\mlMargin0\mrMargin0\mdefJc1\mwrapIndent1440\mintLim0\mnaryLim1}{\info{uthor
 ms}{\operator ms}
+{+\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\gutter0\ltrsect
 
+\widowctrltnbjenddoc rackmoves0      rackformatting1\donotembedsysfont1 
elyonvml0\donotembedlingdata0\grfdocevents0
alidatexml1\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0\showxmlerrors1
oxlattoyen
+xpshrtn
oultrlspc\dntblnsbdb
ospaceforul
ormshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1440\dgvorigin1440\dghshow1\dgvshow1
+\jexpandiewkind1iewscale100\pgbrdrhead\pgbrdrfoot\splytwnine
tnlytwnine\htmautsp
olnhtadjtbl\useltbalnlntblind\lytcalctblwd\lyttblrtgr\lnbrkrule
obrkwrptbl\snaptogridincellllowfieldendsel\wrppunct
+sianbrkrule sidroot1539605
ewtblstyruls
ogrowautofit\usenormstyforlist
oindnmbrtselnbrelev
ocxsptable\indrlsweleven
oafcnsttblfelev\utinl\hwelev\spltpgpar
otcvasp
otbrkcnstfrctbl
otvatxbx\krnprsnet+{\*\wgrffmtfilter 2450}
ofeaturethrottle1\ilfomacatclnup0\ltrpar \sectd \ltrsect\linex0\headery708
ootery708+\pard\plain \ltrpar\ql \li0 
i0\sa160\sl259\slmult1\widctlpar\wrapdefaultspalphaspnumaautodjustright 
in0\lin0\itap0  tlchcs1 f31507fs22lang1025 \ltrchcs0 
+
s22\lang1033\langfe1028\lochf31506\hichf31506\dbchf31505+{\pict{\*\picprop\shplid1025{\sp{\sn
 shapeType}{\sv 75}}{\sp{\sn fFlipH}{\sv 0}}{\sp{\sn fFlipV}{\sv 0}}{\sp{\sn 
fLockAspectRatio}{\sv 1}}{\sp{\sn fLockPosition}{\sv 0}}{\sp{\sn 
fLockAgainstSelect}{\sv 0}}{\sp{\sn fLockAgainstGrouping}{\sv 0}}
+{\sp{\sn pictureGray}{\sv 0}}{\sp{\sn pictureBiLevel}{\sv 0}}{\sp{\sn 
fFilled}{\sv 0}}{\sp{\sn fLine}{\sv 0}}{\sp{\sn wzName}{\sv Picture 1}}{\sp{\sn 
dhgt}{\sv 251658240}}{\sp{\sn fHidden}{\sv 0}}{\sp{\sn fLayoutInCell}{\sv 1}}}
+\picscalex780\picscaley780\piccropl70\piccropr70\piccropt70\piccropb70\picw503\pich503\picwgoal285\pichgoal285\pngblipliptag-2138324634{\*lipuid
 808bc16643ef1085bdc9d6183a9f49dc}
+89504e470d0a1a0a0000000d4948445200000013000000130806000000725036cc0000000467414d410000d6d8d44f58320000001974455874536f6674776172
+650041646f626520496d616765526561647971c9653c000001694944415478da62fcffff3f03b50040003111a3e8e3646ba26c04082026620ce2bf720cc5c049
+eb57fe076174b50001c4448c41479f3232201bd83b733356f50001c4448c4120806e20360010404cc418c4d1b81dc5c04bdef7192e5d7a8da10f208098883148
+53d312c3c05ea1e518860104101331067171f1613510ddcb0001c4448c4120408c810001c4084ab4f80cfaf6ed13dc6618fffaf5e30c3fea3dc162d6d240fd3a
+560cfcb9471901028809dda0a83f5128068134e6752f02d3203ecc852075e82e040820963b56750c0c5640d700258c8ddd195d1ba7fc87790d64c0f42db71926
+95c6810dcc84a8011be86a69c1605dbf84f1ecd99dffcf425d0e10400c206f22e3e486c9ff41e0ebd78fff416c108d8d0f5587a2172080f0e680ddc74fa04400
+888f0f000410130315014000b160130405f48f1f5fb16ac0250e02000184d53050c0e302f7ef5fc229071040580d03c5200cc87bc4e09443070001c448cd921620c000313009ee012707180000000049454e44ae426082}}{
onshppict
+{\pict\picscalex781\picscaley790\piccropl70\piccropr70\piccropt70\piccropb70\picw503\pich503\picwgoal285\pichgoal285\wmetafile8liptag-2138324634{\*lipuid
 808bc16643ef1085bdc9d6183a9f49dc}
+010009000003370100000000b300000000000400000003010800050000000b0200000000050000000c0214001400030000001e00040000000701040004000000
+070104000800000026060f000600544e505006014b000000410b8600ee0013001300000000001300130000000000280000001300000013000000010001000000
+0000000000000000000000000000000000000000000000000000ffffff000000000c0ffe000c0ffe00000ffe00000ffe00000ffe00000ffe0000effee000ffff
+e0007fffc0003fff80001fff00000ffe000507fe000003fe000c01f6000c00e600000040000000000000b3000000410bc6008800130013000000000013001300
+000000002800000013000000130000000100040000000000000000000000000000000000000000000000000000000000ffffff004ba1f3000078ff00b5baa000
+035dcd006d592c00c3d4d400a2907500f3f7f700eaf0f00000000000000000000000000000000000000000001111111111111111111001011111888666668881
+11100101111187761116778111100801111189a61116a98111100706111181961116918111100100111181961116918111100106111181989198918111100101
+77718117898711817770080123556919787919655320090612355791999197553210010011235579111975532110090811123557919755321110070111112355
+797553211110080111111235575532811110010911111123555326411110024c1111111235321641111009011111111123211441111002031111111112111111111005031111111111111111111005070800000026060f000600544e50500701040000002701ffff030000000000}}}{
 tlchcs1 f31507 
+\ltrchcs0 \insrsid6818220 
+\par }
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport8.cxx 
b/sw/qa/extras/rtfexport/rtfexport8.cxx
index 943735098082..b32247bd7f06 100644
--- a/sw/qa/extras/rtfexport/rtfexport8.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport8.cxx
@@ -9,9 +9,10 @@
 
 #include <swmodeltestbase.hxx>
 
+#include <com/sun/star/awt/FontWeight.hpp>
+#include <com/sun/star/text/GraphicCrop.hpp>
 #include <com/sun/star/text/XFootnote.hpp>
 #include <com/sun/star/text/XFootnotesSupplier.hpp>
-#include <com/sun/star/awt/FontWeight.hpp>
 #include <com/sun/star/text/XEndnotesSupplier.hpp>
 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
 #include <com/sun/star/text/XTextTablesSupplier.hpp>
@@ -48,6 +49,28 @@ public:
     }
 };
 
+DECLARE_RTFEXPORT_TEST(testTdf155663, "piccrop.rtf")
+{
+    auto const xShape(getShape(1));
+    if (!isExported())
+    {
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2004), xShape->getSize().Height);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2004), xShape->getSize().Width);
+    }
+    else // bit of rounding loss?
+    {
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2013), xShape->getSize().Height);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2013), xShape->getSize().Width);
+    }
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(123), 
getProperty<text::GraphicCrop>(xShape, "GraphicCrop").Top);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(123),
+                         getProperty<text::GraphicCrop>(xShape, 
"GraphicCrop").Bottom);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(123),
+                         getProperty<text::GraphicCrop>(xShape, 
"GraphicCrop").Left);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(123),
+                         getProperty<text::GraphicCrop>(xShape, 
"GraphicCrop").Right);
+}
+
 DECLARE_RTFEXPORT_TEST(testTdf158586_0, "tdf158586_pageBreak0.rtf")
 {
     // The specified page break must be lost because it is in a text frame
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx 
b/writerfilter/source/dmapper/GraphicImport.cxx
index dfc084f9c3ee..ec78380c8c9e 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -271,6 +271,7 @@ public:
     std::optional<sal_Int32> m_oEffectExtentTop;
     std::optional<sal_Int32> m_oEffectExtentRight;
     std::optional<sal_Int32> m_oEffectExtentBottom;
+    std::optional<text::GraphicCrop> m_oCrop;
 
     GraphicImport_Impl(GraphicImportType & rImportType, DomainMapper& rDMapper,
             std::pair<OUString, OUString>& rPositionOffsets,
@@ -796,6 +797,9 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
         case NS_ooxml::LN_CT_WrapSquare_wrapText: //90928;
             handleWrapTextValue(rValue.getInt());
             break;
+        case NS_ooxml::LN_CT_BlipFillProperties_srcRect:
+            m_pImpl->m_oCrop.emplace(rValue.getAny().get<text::GraphicCrop>());
+            break;
         case NS_ooxml::LN_shape:
             {
                 uno::Reference< drawing::XShape> xShape;
@@ -858,7 +862,13 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
                             text::GraphicCrop aGraphicCrop( 0, 0, 0, 0 );
                             uno::Reference< beans::XPropertySet > 
xSourceGraphProps( xShape, uno::UNO_QUERY );
                             uno::Any aAny = 
xSourceGraphProps->getPropertyValue("GraphicCrop");
-                            if(aAny >>= aGraphicCrop) {
+                            if (m_pImpl->m_oCrop)
+                            {   // RTF: RTFValue from resolvePict()
+                                xGraphProps->setPropertyValue("GraphicCrop",
+                                        uno::Any(*m_pImpl->m_oCrop));
+                            }
+                            else if (aAny >>= aGraphicCrop)
+                            {   // DOCX: imported in oox BlipFillContext
                                 xGraphProps->setPropertyValue("GraphicCrop",
                                     uno::Any( aGraphicCrop ) );
                             }
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx 
b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index b9c17c0adc61..7357589b180b 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1067,6 +1067,16 @@ void RTFDocumentImpl::resolvePict(bool const bInline, 
uno::Reference<drawing::XS
     RTFSprms aAttributes;
     // shape attribute
     RTFSprms aPicAttributes;
+    if (m_aStates.top().getPicture().nCropT != 0 || 
m_aStates.top().getPicture().nCropB != 0
+        || m_aStates.top().getPicture().nCropL != 0 || 
m_aStates.top().getPicture().nCropR != 0)
+    {
+        text::GraphicCrop const crop{ m_aStates.top().getPicture().nCropT,
+                                      m_aStates.top().getPicture().nCropB,
+                                      m_aStates.top().getPicture().nCropL,
+                                      m_aStates.top().getPicture().nCropR };
+        auto const pCrop = new RTFValue(crop);
+        aPicAttributes.set(NS_ooxml::LN_CT_BlipFillProperties_srcRect, pCrop);
+    }
     auto pShapeValue = new RTFValue(xShape);
     aPicAttributes.set(NS_ooxml::LN_shape, pShapeValue);
     // pic sprm
diff --git a/writerfilter/source/rtftok/rtfvalue.cxx 
b/writerfilter/source/rtftok/rtfvalue.cxx
index 7a9137f5db4a..6654a3f2eca5 100644
--- a/writerfilter/source/rtftok/rtfvalue.cxx
+++ b/writerfilter/source/rtftok/rtfvalue.cxx
@@ -85,6 +85,11 @@ RTFValue::RTFValue(const RTFPicture& rPicture)
 {
 }
 
+RTFValue::RTFValue(text::GraphicCrop const& rCrop)
+    : m_oCrop(rCrop)
+{
+}
+
 RTFValue::~RTFValue() = default;
 
 int RTFValue::getInt() const { return m_nValue; }
@@ -110,6 +115,10 @@ uno::Any RTFValue::getAny() const
         ret <<= m_xStream;
     else if (m_xObject.is())
         ret <<= m_xObject;
+    else if (m_oCrop)
+    {
+        ret <<= *m_oCrop;
+    }
     else
         ret <<= static_cast<sal_Int32>(m_nValue);
     return ret;
diff --git a/writerfilter/source/rtftok/rtfvalue.hxx 
b/writerfilter/source/rtftok/rtfvalue.hxx
index 4f37a5dcbcec..6c87c61a1d05 100644
--- a/writerfilter/source/rtftok/rtfvalue.hxx
+++ b/writerfilter/source/rtftok/rtfvalue.hxx
@@ -11,6 +11,10 @@
 
 #include <dmapper/resourcemodel.hxx>
 
+#include <com/sun/star/text/GraphicCrop.hpp>
+
+#include <optional>
+
 namespace com::sun::star
 {
 namespace embed
@@ -49,6 +53,7 @@ public:
     explicit RTFValue(css::uno::Reference<css::embed::XEmbeddedObject> 
xObject);
     explicit RTFValue(const RTFShape& aShape);
     explicit RTFValue(const RTFPicture& rPicture);
+    explicit RTFValue(css::text::GraphicCrop const& rCrop);
     ~RTFValue() override;
     void setString(const OUString& sValue);
     int getInt() const override;
@@ -79,6 +84,7 @@ private:
     bool m_bForceString = false;
     mutable tools::SvRef<RTFShape> m_pShape;
     mutable tools::SvRef<RTFPicture> m_pPicture;
+    ::std::optional<css::text::GraphicCrop> m_oCrop;
 };
 } // namespace writerfilter::rtftok
 

Reply via email to