diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-04-01 14:47:13 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-04-10 08:34:13 +0200 |
commit | e4eb416c3ef81d098ed61caabd2077cbbb2418bc (patch) | |
tree | 5aa13b196431f02a1b4fc0d1049f7ba2eb0ba74c /sw | |
parent | ea3d755ac949c1b6dada5c341e018f8c23f5d395 (diff) |
remove swapping and link from GraphicObject and Graphic
Change-Id: If81127e0589b504909801bcbf392d2dec3a3efc1
Reviewed-on: https://gerrit.libreoffice.org/52244
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/globalfilter/globalfilter.cxx | 1 | ||||
-rw-r--r-- | sw/source/core/doc/notxtfrm.cxx | 38 | ||||
-rw-r--r-- | sw/source/core/docnode/swbaslnk.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/edit/editsh.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/graphic/ndgrf.cxx | 227 |
5 files changed, 5 insertions, 268 deletions
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx index 1c4bc6f5e793..66b0d72d31b3 100644 --- a/sw/qa/extras/globalfilter/globalfilter.cxx +++ b/sw/qa/extras/globalfilter/globalfilter.cxx @@ -184,7 +184,6 @@ void Test::testLinkedGraphicRT() CPPUNIT_ASSERT(pGrfNode); const GraphicObject& rGraphicObj = pGrfNode->GetGrfObj(true); - CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), !rGraphicObj.IsSwappedOut()); CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), int(GraphicType::Bitmap), int(rGraphicObj.GetType())); CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), static_cast<sal_uLong>(864900), rGraphicObj.GetSizeBytes()); bImageFound = true; diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx index 6d503dce45fa..4c6c8ffc80e9 100644 --- a/sw/source/core/doc/notxtfrm.cxx +++ b/sw/source/core/doc/notxtfrm.cxx @@ -941,44 +941,6 @@ void paintGraphicUsingPrimitivesHelper( drawinglayer::primitive2d::Primitive2DContainer aContent(1); bool bDone(false); - // #i125171# The mechanism to get lossless jpegs into pdf is based on having the original - // file data (not the bitmap data) at the Graphic in the GfxLink (which has *nothing* to - // do with the graphic being linked). This works well for DrawingLayer GraphicObjects (linked - // and unlinked) but fails for linked Writer GraphicObjects. These have the URL in the - // GraphicObject, but no GfxLink with the original file data when it's a linked graphic. - // Since this blows up PDF size by a factor of 10 (the graphics get embedded as pixel maps - // then) it is okay to add this workarund: In the needed case, load the graphic in a way to - // get the GfxLink in the needed form and use that Graphic temporarily. Do this only when - // - we have PDF export - // - the GraphicObject is linked - // - the Graphic has no GfxLink - // - LosslessCompression is activated - // - it's indeed a jpeg graphic (could be checked by the url ending, but is more reliable to check later) - // In all other cases (normal repaint, print, etc...) use the available Graphic with the - // already loaded pixel graphic as before this change. - if (rOutputDevice.GetExtOutDevData() && rGrfObj.HasLink() && !rGrfObj.GetGraphic().IsLink()) - { - const vcl::PDFExtOutDevData* pPDFExt = dynamic_cast< const vcl::PDFExtOutDevData* >(rOutputDevice.GetExtOutDevData()); - - if (pPDFExt && pPDFExt->GetIsLosslessCompression()) - { - Graphic aTempGraphic; - INetURLObject aURL(rGrfObj.GetLink()); - - if (ERRCODE_NONE == GraphicFilter::GetGraphicFilter().ImportGraphic(aTempGraphic, aURL)) - { - if(aTempGraphic.IsLink() && GfxLinkType::NativeJpg == aTempGraphic.GetLink().GetType()) - { - aContent[0] = new drawinglayer::primitive2d::GraphicPrimitive2D( - rGraphicTransform, - aTempGraphic, - rGraphicAttr); - bDone = true; - } - } - } - } - if(!bDone) { aContent[0] = new drawinglayer::primitive2d::GraphicPrimitive2D( diff --git a/sw/source/core/docnode/swbaslnk.cxx b/sw/source/core/docnode/swbaslnk.cxx index cc3bff0306d4..4f30f7b4d67e 100644 --- a/sw/source/core/docnode/swbaslnk.cxx +++ b/sw/source/core/docnode/swbaslnk.cxx @@ -164,7 +164,7 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem ) bGraphicPieceArrived = false; } - pSwGrfNode->SetGraphic(aGrf, rGrfObj.GetLink()); + pSwGrfNode->SetGraphic(aGrf, ""); bUpdate = true; // In order for the Node to have the right transparency status diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx index 9ac89cd6f01b..7d3dd51265b7 100644 --- a/sw/source/core/edit/editsh.cxx +++ b/sw/source/core/edit/editsh.cxx @@ -246,9 +246,8 @@ bool SwEditShell::IsLinkedGrfSwapOut() const { SwGrfNode *pGrfNode = GetGrfNode_(); return pGrfNode && - ( pGrfNode->IsLinkedFile() && - ( GraphicType::Default == pGrfNode->GetGrfObj().GetType() || - pGrfNode->GetGrfObj().IsSwappedOut())); + pGrfNode->IsLinkedFile() && + GraphicType::Default == pGrfNode->GetGrfObj().GetType(); } const GraphicObject* SwEditShell::GetGraphicObj() const diff --git a/sw/source/core/graphic/ndgrf.cxx b/sw/source/core/graphic/ndgrf.cxx index 31fab60ce388..97660f6cbbde 100644 --- a/sw/source/core/graphic/ndgrf.cxx +++ b/sw/source/core/graphic/ndgrf.cxx @@ -73,7 +73,6 @@ SwGrfNode::SwGrfNode( mbLinkedInputStreamReady( false ), mbIsStreamReadOnly( false ) { - maGrfObj.SetSwapStreamHdl( LINK(this, SwGrfNode, SwapGraphic) ); bInSwapIn = bChgTwipSize = bFrameInPaint = bScaleImageMap = false; @@ -92,7 +91,6 @@ SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere, mbLinkedInputStreamReady( false ), mbIsStreamReadOnly( false ) { - maGrfObj.SetSwapStreamHdl( LINK(this, SwGrfNode, SwapGraphic) ); bInSwapIn = bChgTwipSize = bFrameInPaint = bScaleImageMap = false; bGraphicArrived = true; @@ -116,8 +114,6 @@ SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere, mbLinkedInputStreamReady( false ), mbIsStreamReadOnly( false ) { - maGrfObj.SetSwapStreamHdl( LINK(this, SwGrfNode, SwapGraphic) ); - Graphic aGrf; aGrf.SetDefaultType(); maGrfObj.SetGraphic( aGrf, rGrfName ); @@ -195,7 +191,6 @@ bool SwGrfNode::ReRead( else if( pGrfObj ) { maGrfObj = *pGrfObj; - maGrfObj.SetLink( rGrfName ); onGraphicChanged(); bReadGrf = true; } @@ -256,7 +251,6 @@ bool SwGrfNode::ReRead( else if( pGrfObj ) { maGrfObj = *pGrfObj; - maGrfObj.SetLink( rGrfName ); onGraphicChanged(); bReadGrf = true; // create connection without update, as we have the graphic @@ -410,11 +404,6 @@ const GraphicObject* SwGrfNode::GetReplacementGrfObj() const // Replacement graphic for PDF and metafiles is just the bitmap. const_cast<SwGrfNode*>(this)->mpReplacementGraphic = new GraphicObject(GetGrfObj().GetGraphic().GetBitmapEx()); } - if (mpReplacementGraphic) - { - mpReplacementGraphic->SetSwapStreamHdl( - LINK(const_cast<SwGrfNode*>(this), SwGrfNode, SwapReplacement)); - } } return mpReplacementGraphic; @@ -479,157 +468,17 @@ bool SwGrfNode::ImportGraphic( SvStream& rStrm ) return false; } -namespace -{ - -struct StreamAndStorageNames -{ - OUString sStream; - OUString sStorage; -}; - -StreamAndStorageNames lcl_GetStreamStorageNames( const OUString& sUserData ) -{ - StreamAndStorageNames aNames; - if( sUserData.isEmpty() ) - return aNames; - - const OUString aProt( "vnd.sun.star.Package:" ); - if (sUserData.startsWithIgnoreAsciiCase(aProt)) - { - // 6.0 (XML) Package - const sal_Int32 nPos = sUserData.indexOf('/'); - if (nPos<0) - { - aNames.sStream = sUserData.copy(aProt.getLength()); - } - else - { - const sal_Int32 nPathStart = aProt.getLength(); - aNames.sStorage = sUserData.copy( nPathStart, nPos-nPathStart ); - aNames.sStream = sUserData.copy( nPos+1 ); - } - } - else - { - OSL_FAIL( "<lcl_GetStreamStorageNames(..)> - unknown graphic URL type. Code for handling 3.1 - 5.2 storages has been deleted by issue i53025." ); - } - OSL_ENSURE( aNames.sStream.indexOf('/')<0, "invalid graphic stream name" ); - return aNames; -} - -} - /** * @return true if ReRead or reading successful, * false if not loaded */ -bool SwGrfNode::SwapIn( bool bWaitForData ) +bool SwGrfNode::SwapIn( bool /*bWaitForData*/ ) { - if( bInSwapIn ) // not recursively! - return !maGrfObj.IsSwappedOut(); - - bool bRet = false; - bInSwapIn = true; - SwBaseLink* pLink = static_cast<SwBaseLink*>( refLink.get() ); - - if( pLink ) - { - if( GraphicType::NONE == maGrfObj.GetType() || - GraphicType::Default == maGrfObj.GetType() ) - { - // link was not loaded yet - if( pLink->SwapIn( bWaitForData ) ) - { - bRet = true; - } - else if( GraphicType::Default == maGrfObj.GetType() ) - { - // no default bitmap anymore, thus re-paint - delete mpReplacementGraphic; - mpReplacementGraphic = nullptr; - - maGrfObj.SetGraphic( Graphic() ); - onGraphicChanged(); - SwMsgPoolItem aMsgHint( RES_GRAPHIC_PIECE_ARRIVED ); - ModifyNotification( &aMsgHint, &aMsgHint ); - } - } - else if( maGrfObj.IsSwappedOut() ) - { - // link to download - bRet = pLink->SwapIn( bWaitForData ); - } - else - bRet = true; - } - else if( maGrfObj.IsSwappedOut() ) - { - // graphic is in storage or in a temp file - if( !HasEmbeddedStreamName() ) - { - bRet = maGrfObj.SwapIn(); - } - else - { - try - { - const StreamAndStorageNames aNames = lcl_GetStreamStorageNames( maGrfObj.GetUserData() ); - uno::Reference < embed::XStorage > refPics = GetDocSubstorageOrRoot( aNames.sStorage ); - SvStream* pStrm = GetStreamForEmbedGrf( refPics, aNames.sStream ); - if ( pStrm ) - { - bRet = ImportGraphic( *pStrm ); - delete pStrm; - if( bRet ) - { - maGrfObj.SetUserData(); - } - } - } - catch (const uno::Exception&) - { - // #i48434# - OSL_FAIL( "<SwGrfNode::SwapIn(..)> - unhandled exception!" ); - } - } - - if( bRet ) - { - SwMsgPoolItem aMsg( RES_GRAPHIC_SWAPIN ); - ModifyNotification( &aMsg, &aMsg ); - } - } - else - bRet = true; - OSL_ENSURE( bRet, "Cannot swap in graphic" ); - - if( bRet ) - { - if( !nGrfSize.Width() && !nGrfSize.Height() ) - SetTwipSize( ::GetGraphicSizeTwip( maGrfObj.GetGraphic(), nullptr ) ); - } - bInSwapIn = false; - return bRet; + return true; } bool SwGrfNode::SwapOut() { - if( maGrfObj.GetType() != GraphicType::Default && - maGrfObj.GetType() != GraphicType::NONE && - !maGrfObj.IsSwappedOut() && !bInSwapIn ) - { - if( refLink.is() ) - { - // written graphics and links are removed here - return maGrfObj.SwapOut( GRFMGR_AUTOSWAPSTREAM_LINK ); - } - else - { - return maGrfObj.SwapOut(); - } - - } return true; } @@ -735,14 +584,12 @@ void SwGrfNode::InsertLink( const OUString& rGrfName, const OUString& rFltName ) (!bSync && !rFltName.isEmpty() ? &rFltName : nullptr) ); } } - maGrfObj.SetLink( rGrfName ); } void SwGrfNode::ReleaseLink() { if( refLink.is() ) { - const OUString aFileName(maGrfObj.GetLink()); const Graphic aLocalGraphic(maGrfObj.GetGraphic()); const bool bHasOriginalData(aLocalGraphic.IsLink()); @@ -755,7 +602,6 @@ void SwGrfNode::ReleaseLink() getIDocumentLinksAdministration().GetLinkManager().Remove( refLink.get() ); refLink.clear(); - maGrfObj.SetLink(); // #i15508# added extra processing after getting rid of the link. Use whatever is // known from the formerly linked graphic to get to a state as close to a directly @@ -772,21 +618,6 @@ void SwGrfNode::ReleaseLink() // This happens e.g. when inserting a linked graphic and breaking the link maGrfObj.SetGraphic(aLocalGraphic); } - else if(!aFileName.isEmpty()) - { - // #i15508# we have no original data, but a file name. This happens e.g. - // when inserting a linked graphic and save, reload document. Try to access - // that data from the original file; if this works, use it. Else use the - // data we have (but without knowing the original format) - GraphicFilter& rFlt = GraphicFilter::GetGraphicFilter(); - Graphic aNew; - ErrCode nRes = GraphicFilter::LoadGraphic( aFileName, OUString(), aNew, &rFlt); - - if(ERRCODE_NONE == nRes) - { - maGrfObj.SetGraphic(aNew); - } - } } } @@ -964,60 +795,6 @@ SwContentNode* SwGrfNode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const return pGrfNd; } -IMPL_STATIC_LINK(SwGrfNode, SwapReplacement, const GraphicObject*, pGrfObj, SvStream*) -{ - // replacement image is always swapped - if (pGrfObj->IsInSwapOut()) - { - return GRFMGR_AUTOSWAPSTREAM_TEMP; - } - else if (pGrfObj->IsInSwapIn()) - { - return GRFMGR_AUTOSWAPSTREAM_TEMP; - } - else - { - assert(!"why is swap handler being called?"); - } - - return GRFMGR_AUTOSWAPSTREAM_NONE; -} - -IMPL_LINK( SwGrfNode, SwapGraphic, const GraphicObject*, pGrfObj, SvStream* ) -{ - SvStream* pRet; - - // Keep graphic while in swap in. That's at least important - // when breaking links, because in this situation a reschedule call and - // a DataChanged call lead to a paint of the graphic. - if( pGrfObj->IsInSwapOut() && (IsSelected() || bInSwapIn) ) - pRet = GRFMGR_AUTOSWAPSTREAM_NONE; - else if( refLink.is() ) - { - if( pGrfObj->IsInSwapIn() ) - { - // then make it by your self - if( !bInSwapIn ) - { - const bool bIsModifyLocked = IsModifyLocked(); - LockModify(); - SwapIn(); - if( !bIsModifyLocked ) - UnlockModify(); - } - pRet = GRFMGR_AUTOSWAPSTREAM_NONE; - } - else - pRet = GRFMGR_AUTOSWAPSTREAM_LINK; - } - else - { - pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; - } - - return pRet; -} - /// returns the Graphic-Attr-Structure filled with our graphic attributes GraphicAttr& SwGrfNode::GetGraphicAttr( GraphicAttr& rGA, const SwFrame* pFrame ) const |