[Libreoffice-commits] core.git: 3 commits - include/svtools svtools/qa svtools/source sw/inc sw/source
Zolnai Tamás
zolnaitamas2000 at gmail.com
Sun Feb 22 05:50:21 PST 2015
include/svtools/grfmgr.hxx | 4 --
svtools/qa/unit/GraphicObjectTest.cxx | 66 ++++++++++++++++++++++++++++++++++
svtools/source/graphic/grfcache.cxx | 24 ------------
svtools/source/graphic/grfcache.hxx | 1
svtools/source/graphic/grfmgr.cxx | 7 ---
svtools/source/graphic/grfmgr2.cxx | 18 ++++-----
sw/inc/ndgrf.hxx | 5 --
sw/source/core/docnode/swbaslnk.cxx | 29 ++++----------
sw/source/core/graphic/ndgrf.cxx | 6 +--
sw/source/filter/html/htmlgrin.cxx | 2 -
10 files changed, 88 insertions(+), 74 deletions(-)
New commits:
commit 2d16cf85d1d1145eae37780920961e4a667f2e51
Author: Zolnai Tamás <zolnaitamas2000 at gmail.com>
Date: Sat Feb 21 09:59:12 2015 +0100
ChgTwipSizeFromPixel flag is useless
It is used only to make the same conversion
on a different way.
GetGraphicSizeTwip() also returns the size in twips.
Change-Id: Ic532341ab37c86a63792c82bf3a5fb2e3d8d0e67
diff --git a/sw/inc/ndgrf.hxx b/sw/inc/ndgrf.hxx
index b40da0c..ce25a78 100644
--- a/sw/inc/ndgrf.hxx
+++ b/sw/inc/ndgrf.hxx
@@ -46,7 +46,6 @@ class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode
bool bGraphicArrived :1;
bool bChgTwipSize :1;
- bool bChgTwipSizeFromPixel :1;
bool bFrameInPaint :1; ///< To avoid Start-/EndActions in Paint via SwapIn.
bool bScaleImageMap :1; ///< Scale image map in SetTwipSize.
@@ -144,11 +143,9 @@ public:
bool IsAnimated() const { return maGrfObj.IsAnimated(); }
bool IsChgTwipSize() const { return bChgTwipSize; }
- bool IsChgTwipSizeFromPixel() const { return bChgTwipSizeFromPixel; }
- void SetChgTwipSize( bool b, bool bFromPx=false )
+ void SetChgTwipSize( bool b)
{
bChgTwipSize = b;
- bChgTwipSizeFromPixel = bFromPx;
}
bool IsGraphicArrived() const { return bGraphicArrived; }
diff --git a/sw/source/core/docnode/swbaslnk.cxx b/sw/source/core/docnode/swbaslnk.cxx
index 85ec6f8..fbc3af8 100644
--- a/sw/source/core/docnode/swbaslnk.cxx
+++ b/sw/source/core/docnode/swbaslnk.cxx
@@ -53,7 +53,7 @@
using namespace com::sun::star;
-static bool SetGrfFlySize( const Size& rGrfSz, const Size& rFrmSz, SwGrfNode* pGrfNd, const Size &rOrigGrfSize );
+static bool SetGrfFlySize( const Size& rGrfSz, SwGrfNode* pGrfNd, const Size &rOrigGrfSize );
TYPEINIT1( SwBaseLink, ::sfx2::SvBaseLink );
@@ -153,17 +153,6 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem )
GRAPHIC_DEFAULT != rGrfObj.GetType() ) )
{
aGrfSz = ::GetGraphicSizeTwip( aGrf, 0 );
- if( pSwGrfNode->IsChgTwipSizeFromPixel() )
- {
- const MapMode aMapTwip( MAP_TWIP );
- aFrmFmtSz =
- Application::GetDefaultDevice()->PixelToLogic(
- aGrf.GetSizePixel(), aMapTwip );
- }
- else
- {
- aFrmFmtSz = aGrfSz;
- }
if( bGraphicPieceArrived && GRAPHIC_DEFAULT != aGrf.GetType() &&
( !aOldSz.Width() || !aOldSz.Height() ) )
@@ -261,13 +250,13 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem )
IsGraphicArrived() );
// Adjust the Fly's graphic
- if (!::SetGrfFlySize(aGrfSz, aFrmFmtSz, pGrfNd, aPreArriveSize))
+ if (!::SetGrfFlySize(aGrfSz, pGrfNd, aPreArriveSize))
::lcl_CallModify( *pGrfNd, aMsgHint );
}
else if (pBLink == this)
{
assert(pGrfNd == pSwGrfNode && "fdo#87083 needs a different fix");
- if (!::SetGrfFlySize(aGrfSz, aFrmFmtSz, pGrfNd, aOldSz))
+ if (!::SetGrfFlySize(aGrfSz, pGrfNd, aOldSz))
{
// Adjust the Fly's graphic
::lcl_CallModify( *pGrfNd, aMsgHint );
@@ -300,7 +289,7 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem )
return SUCCESS;
}
-static bool SetGrfFlySize( const Size& rGrfSz, const Size& rFrmSz, SwGrfNode* pGrfNd, const Size& rOrigGrfSize )
+static bool SetGrfFlySize( const Size& rGrfSz, SwGrfNode* pGrfNd, const Size& rOrigGrfSize )
{
bool bRet = false;
SwViewShell *pSh = pGrfNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
@@ -319,15 +308,15 @@ static bool SetGrfFlySize( const Size& rGrfSz, const Size& rFrmSz, SwGrfNode* pG
Size aCalcSz( aSz );
if ( !aSz.Height() && aSz.Width() )
// Calculate the right height
- aCalcSz.Height() = rFrmSz.Height() *
- aSz.Width() / rFrmSz.Width();
+ aCalcSz.Height() = rGrfSz.Height() *
+ aSz.Width() / rGrfSz.Width();
else if ( !aSz.Width() && aSz.Height() )
// Calculate the right width
- aCalcSz.Width() = rFrmSz.Width() *
- aSz.Height() / rFrmSz.Height();
+ aCalcSz.Width() = rGrfSz.Width() *
+ aSz.Height() / rGrfSz.Height();
else
// Take over height and width
- aCalcSz = rFrmSz;
+ aCalcSz = rGrfSz;
const SvxBoxItem &rBox = pFmt->GetBox();
aCalcSz.Width() += rBox.CalcLineSpace(BOX_LINE_LEFT) +
diff --git a/sw/source/core/graphic/ndgrf.cxx b/sw/source/core/graphic/ndgrf.cxx
index 987e4fe..ee9d873 100644
--- a/sw/source/core/graphic/ndgrf.cxx
+++ b/sw/source/core/graphic/ndgrf.cxx
@@ -74,7 +74,7 @@ SwGrfNode::SwGrfNode(
mbIsStreamReadOnly( false )
{
maGrfObj.SetSwapStreamHdl( LINK(this, SwGrfNode, SwapGraphic) );
- bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel =
+ bInSwapIn = bChgTwipSize =
bFrameInPaint = bScaleImageMap = false;
bGraphicArrived = true;
@@ -92,7 +92,7 @@ SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere,
mbIsStreamReadOnly( false )
{
maGrfObj.SetSwapStreamHdl( LINK(this, SwGrfNode, SwapGraphic) );
- bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel =
+ bInSwapIn = bChgTwipSize =
bFrameInPaint = bScaleImageMap = false;
bGraphicArrived = true;
}
@@ -119,7 +119,7 @@ SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere,
Graphic aGrf; aGrf.SetDefaultType();
maGrfObj.SetGraphic( aGrf, rGrfName );
- bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel =
+ bInSwapIn = bChgTwipSize =
bFrameInPaint = bScaleImageMap = false;
bGraphicArrived = true;
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index cb4db4c..99a5844 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -754,7 +754,7 @@ IMAGE_SETEVENT:
if( bSetTwipSize )
pGrfNd->SetTwipSize( aGrfSz );
- pGrfNd->SetChgTwipSize( bChangeFrmSize, bChangeFrmSize );
+ pGrfNd->SetChgTwipSize( bChangeFrmSize );
if( bSetScaleImageMap )
pGrfNd->SetScaleImageMap( true );
commit 908c060ceef81a733cf1d1912b48f5d499afdad8
Author: Zolnai Tamás <zolnaitamas2000 at gmail.com>
Date: Tue Feb 17 15:50:08 2015 +0100
Test for tdf#88935
Change-Id: I625a59a632c53c77f593268b14e60ab265e5a821
diff --git a/svtools/qa/unit/GraphicObjectTest.cxx b/svtools/qa/unit/GraphicObjectTest.cxx
index d4ecf29..cc73b5c 100644
--- a/svtools/qa/unit/GraphicObjectTest.cxx
+++ b/svtools/qa/unit/GraphicObjectTest.cxx
@@ -41,6 +41,7 @@ public:
void testSwap();
void testSizeBasedAutoSwap();
void testTdf88836();
+ void testTdf88935();
virtual void setUp() SAL_OVERRIDE
@@ -58,6 +59,7 @@ private:
CPPUNIT_TEST(testSwap);
CPPUNIT_TEST(testSizeBasedAutoSwap);
CPPUNIT_TEST(testTdf88836);
+ CPPUNIT_TEST(testTdf88935);
CPPUNIT_TEST_SUITE_END();
};
@@ -239,6 +241,70 @@ void GraphicObjectTest::testTdf88836()
CPPUNIT_ASSERT_EQUAL(GRAPHIC_NONE, aGraphic.GetType());
}
+void GraphicObjectTest::testTdf88935()
+{
+ // Cache size was not updated by deletion of graphic objects
+
+ // Load a file with two images
+ uno::Reference< lang::XComponent > xComponent =
+ loadFromDesktop(getURLFromSrc("svtools/qa/unit/data/document_with_two_images.odt"), "com.sun.star.text.TextDocument");
+ SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(xComponent.get());
+ CPPUNIT_ASSERT(pTxtDoc);
+ SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+ SwNodes& aNodes = pDoc->GetNodes();
+
+ // Find images
+ const GraphicObject* pGraphObj1 = 0;
+ const GraphicObject* pGraphObj2 = 0;
+ for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
+ {
+ if( aNodes[nIndex]->IsGrfNode() )
+ {
+ SwGrfNode* pGrfNode = aNodes[nIndex]->GetGrfNode();
+ if( !pGraphObj1 )
+ {
+ pGraphObj1 = &pGrfNode->GetGrfObj();
+ }
+ else
+ {
+ pGraphObj2 = &pGrfNode->GetGrfObj();
+ }
+ }
+ }
+ CPPUNIT_ASSERT_MESSAGE("Missing image", pGraphObj1 != 0 && pGraphObj2 != 0);
+
+ // Set cache size
+ {
+ GraphicManager& rGrfMgr = pGraphObj1->GetGraphicManager();
+ rGrfMgr.SetMaxCacheSize((pGraphObj1->GetSizeBytes()+pGraphObj2->GetSizeBytes())*10);
+ }
+
+ // Both images fit into the cache
+ {
+ pGraphObj1->GetGraphic();
+ pGraphObj2->GetGraphic();
+ CPPUNIT_ASSERT(!pGraphObj1->IsSwappedOut());
+ CPPUNIT_ASSERT(!pGraphObj2->IsSwappedOut());
+ }
+
+ // Create and remove some copy of the first image
+ for( int i = 0; i < 50; ++i )
+ {
+ GraphicObject aGraphObj3(*pGraphObj1, &pGraphObj1->GetGraphicManager());
+ CPPUNIT_ASSERT(aGraphObj3.SwapOut());
+ CPPUNIT_ASSERT(aGraphObj3.SwapIn());
+ }
+
+ // Both images fit into the cache
+ {
+ pGraphObj1->GetGraphic();
+ pGraphObj2->GetGraphic();
+ CPPUNIT_ASSERT(!pGraphObj1->IsSwappedOut());
+ CPPUNIT_ASSERT(!pGraphObj2->IsSwappedOut());
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(GraphicObjectTest);
}
commit ab00ac3e88e0a28d0e38c5968c23014a6a8fb194
Author: Zolnai Tamás <zolnaitamas2000 at gmail.com>
Date: Sat Feb 21 19:48:33 2015 +0100
More improvements of graphic cache size handling
* ImplFillSwappedGraphicObject method is part of
the old caching mechanism which interferes with
the newer one, so remove this method.
* Use Graphic size directly becuase in some case
it does not match with the GraphicObject's
size.
* Assertions to avoid underflow of mnUsedSize
Change-Id: I3381f49ca05e3e5d565848c8af24c78e7b9ac3af
diff --git a/include/svtools/grfmgr.hxx b/include/svtools/grfmgr.hxx
index 42d9a70..7e50750 100644
--- a/include/svtools/grfmgr.hxx
+++ b/include/svtools/grfmgr.hxx
@@ -592,10 +592,6 @@ private:
// Only used in swap case by GraphicObject
void SVT_DLLPRIVATE ImplGraphicObjectWasSwappedOut( const GraphicObject& rObj );
- bool SVT_DLLPRIVATE ImplFillSwappedGraphicObject(
- const GraphicObject& rObj,
- Graphic& rSubstitute
- );
void SVT_DLLPRIVATE ImplGraphicObjectWasSwappedIn( const GraphicObject& rObj );
OString SVT_DLLPRIVATE ImplGetUniqueID( const GraphicObject& rObj ) const;
diff --git a/svtools/source/graphic/grfcache.cxx b/svtools/source/graphic/grfcache.cxx
index f5baadb..485dfed 100644
--- a/svtools/source/graphic/grfcache.cxx
+++ b/svtools/source/graphic/grfcache.cxx
@@ -173,7 +173,6 @@ public:
void TryToSwapIn();
void GraphicObjectWasSwappedOut( const GraphicObject& rObj );
- bool FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute );
void GraphicObjectWasSwappedIn( const GraphicObject& rObj );
};
@@ -371,19 +370,6 @@ void GraphicCacheEntry::GraphicObjectWasSwappedOut( const GraphicObject& /*rObj*
}
}
-bool GraphicCacheEntry::FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute )
-{
- bool bRet = false;
-
- if( !mbSwappedAll && rObj.IsSwappedOut() )
- {
- ImplFillSubstitute( rSubstitute );
- bRet = true;
- }
-
- return bRet;
-}
-
void GraphicCacheEntry::GraphicObjectWasSwappedIn( const GraphicObject& rObj )
{
if( mbSwappedAll )
@@ -987,16 +973,6 @@ void GraphicCache::GraphicObjectWasSwappedOut( const GraphicObject& rObj )
pEntry->GraphicObjectWasSwappedOut( rObj );
}
-bool GraphicCache::FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute )
-{
- GraphicCacheEntry* pEntry = ImplGetCacheEntry( rObj );
-
- if( !pEntry )
- return false;
-
- return pEntry->FillSwappedGraphicObject( rObj, rSubstitute );
-}
-
void GraphicCache::GraphicObjectWasSwappedIn( const GraphicObject& rObj )
{
GraphicCacheEntry* pEntry = ImplGetCacheEntry( rObj );
diff --git a/svtools/source/graphic/grfcache.hxx b/svtools/source/graphic/grfcache.hxx
index e8259e7..968c312 100644
--- a/svtools/source/graphic/grfcache.hxx
+++ b/svtools/source/graphic/grfcache.hxx
@@ -74,7 +74,6 @@ public:
void ReleaseGraphicObject( const GraphicObject& rObj );
void GraphicObjectWasSwappedOut( const GraphicObject& rObj );
- bool FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute );
void GraphicObjectWasSwappedIn( const GraphicObject& rObj );
OString GetUniqueID( const GraphicObject& rObj ) const;
diff --git a/svtools/source/graphic/grfmgr.cxx b/svtools/source/graphic/grfmgr.cxx
index 32ec707..de571bf 100644
--- a/svtools/source/graphic/grfmgr.cxx
+++ b/svtools/source/graphic/grfmgr.cxx
@@ -210,9 +210,6 @@ void GraphicObject::ImplAutoSwapIn()
{
if( IsSwappedOut() )
{
- if( mpMgr && mpMgr->ImplFillSwappedGraphicObject( *this, maGraphic ) )
- mbAutoSwapped = false;
- else
{
mbIsInSwapIn = true;
@@ -1037,10 +1034,6 @@ bool GraphicObject::SwapIn()
ImplAutoSwapIn();
bRet = true;
}
- else if( mpMgr && mpMgr->ImplFillSwappedGraphicObject( *this, maGraphic ) )
- {
- bRet = true;
- }
else
{
bRet = maGraphic.SwapIn();
diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index 3aabb52..0c4e17b 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -157,19 +157,21 @@ void GraphicManager::ImplRegisterObj( const GraphicObject& rObj, Graphic& rSubst
maObjList.push_back( (GraphicObject*)&rObj );
mpCache->AddGraphicObject( rObj, rSubstitute, pID, pCopyObj );
if( !rObj.IsSwappedOut() )
- mnUsedSize += rObj.GetSizeBytes();
+ mnUsedSize += rObj.maGraphic.GetSizeBytes();
}
void GraphicManager::ImplUnregisterObj( const GraphicObject& rObj )
{
mpCache->ReleaseGraphicObject( rObj );
+ if( !rObj.IsSwappedOut() )
+ {
+ assert(mnUsedSize >= rObj.maGraphic.GetSizeBytes());
+ mnUsedSize -= rObj.maGraphic.GetSizeBytes();
+ }
for( GraphicObjectList_impl::iterator it = maObjList.begin(); it != maObjList.end(); ++it )
{
if ( *it == &rObj ) {
maObjList.erase( it );
-
- if( !rObj.IsSwappedOut() )
- mnUsedSize -= rObj.GetSizeBytes();
return;
}
}
@@ -179,6 +181,7 @@ void GraphicManager::ImplUnregisterObj( const GraphicObject& rObj )
void GraphicManager::ImplGraphicObjectWasSwappedOut( const GraphicObject& rObj )
{
mpCache->GraphicObjectWasSwappedOut( rObj );
+ assert(mnUsedSize >= rObj.GetSizeBytes());
mnUsedSize -= rObj.GetSizeBytes();
}
@@ -236,15 +239,10 @@ void GraphicManager::ImplCheckSizeOfSwappedInGraphics(const GraphicObject* pGrap
}
}
-bool GraphicManager::ImplFillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute )
-{
- return mpCache->FillSwappedGraphicObject(rObj, rSubstitute);
-}
-
void GraphicManager::ImplGraphicObjectWasSwappedIn( const GraphicObject& rObj )
{
mpCache->GraphicObjectWasSwappedIn( rObj );
- mnUsedSize += rObj.GetSizeBytes();
+ mnUsedSize += rObj.maGraphic.GetSizeBytes();
}
bool GraphicManager::ImplDraw( OutputDevice* pOut, const Point& rPt,
More information about the Libreoffice-commits
mailing list