Resolves: tdf#159046 hang on export of math objects in cells

regression from:

commit a9d6b6ef049dd41c91a30c03df0ba38ba8dcada8
Date:   Thu Oct 5 14:12:51 2023 +0100

    crash copying text + chart to clipboard with InputOptions::TextWysiwyg

    of true, the mxPoolHelper is still null when trying to create a
    Printer to use as a reference device

revert that, and use a different simpler workaround for the original
crash case.

Change-Id: I74cec710aec033e1652e637ed056dae1c261aa98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161750
Tested-by: Jenkins
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 11b65e9..09747bb 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2708,8 +2708,6 @@ public:
    const ScTable* FetchTable( SCTAB nTab ) const;

    ScRefCellValue GetRefCellValue( const ScAddress& rPos );

    void SharePooledResources( const ScDocument* pSrcDoc );
private:
    ScRefCellValue GetRefCellValue( const ScAddress& rPos, sc::ColumnBlockPosition& rBlockPos );

@@ -2719,6 +2717,8 @@ private:
    SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const;
    void   ReservePatternCount( SCTAB nTab, SCCOL nCol, SCSIZE nReserve );

    void SharePooledResources( const ScDocument* pSrcDoc );

    void EndListeningIntersectedGroup(
        sc::EndListeningContext& rCxt, const ScAddress& rPos, std::vector<ScAddress>* pGroupPos );

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 84233f4..50748236 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -114,7 +114,7 @@ void ScDocument::ImplDeleteOptions()

SfxPrinter* ScDocument::GetPrinter(bool bCreateIfNotExist)
{
    if ( !mpPrinter && bCreateIfNotExist )
    if (!mpPrinter && bCreateIfNotExist && mxPoolHelper)
    {
        auto pSet =
            std::make_unique<SfxItemSetFixed
@@ -202,8 +202,11 @@ OutputDevice* ScDocument::GetRefDevice(bool bForceVirtDev)
    // Create printer like ref device, see Writer...
    OutputDevice* pRefDevice = nullptr;
    if ( !bForceVirtDev && SC_MOD()->GetInputOptions().GetTextWysiwyg() )
    {
        pRefDevice = GetPrinter();
    else
        SAL_WARN_IF(!pRefDevice, "sc", "unable to get a printer, fallback to virdev");
    }
    if (!pRefDevice)
        pRefDevice = GetVirtualDevice_100th_mm();
    return pRefDevice;
}
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 8aea1eb..7a64032 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -242,9 +242,6 @@ bool ScViewFunc::CopyToClipSingleRange( ScDocument* pClipDoc, const ScRangeList&
    if ( pSysClipDoc && bIncludeObjects )
    {
        bool bAnyOle = rDoc.HasOLEObjectsInArea( aRange );
        // There are optional paths (e.g. bAnyOle and InputOptions().GetTextWysiwyg true)
        // which dereference pSysClipDoc->mxPoolHelper so ensure that is set here.
        pSysClipDoc->SharePooledResources(&rDoc);
        // Update ScGlobal::xDrawClipDocShellRef.
        ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle, pSysClipDoc ) );
    }