DOC import: lazy-read images

At least JPEG files are now only loaded when the user scrolls to the
relevant page.

Also fix the root cause of the EMF lazy-read problem and remove the
previous workarounds.

Change-Id: I9699927282b99bcb71a0d271a20bbfd56a361ee8
Reviewed-on: https://gerrit.libreoffice.org/53219
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
This commit is contained in:
Miklos Vajna
2018-04-20 17:58:09 +02:00
parent 40edbce398
commit b11188835d
7 changed files with 22 additions and 10 deletions

View File

@@ -6545,7 +6545,14 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, tool
else
{ // and unleash our filter
GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
nRes = rGF.ImportGraphic( rData, "", *pGrStream );
Graphic aGraphic = rGF.ImportUnloadedGraphic(*pGrStream);
if (aGraphic)
{
rData = aGraphic;
nRes = ERRCODE_NONE;
}
else
nRes = rGF.ImportGraphic( rData, "", *pGrStream );
// SJ: I40472, sometimes the aspect ratio (aMtfSize100) does not match and we get scaling problems,
// then it is better to use the prefsize that is stored within the metafile. Bug #72846# for what the

View File

@@ -244,7 +244,7 @@ Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStrea
aArgs[ 1 ].Name = "LazyRead";
aArgs[ 1 ].Value <<= true;
if ( pExtHeader )
if ( pExtHeader && pExtHeader->mapMode > 0 )
{
aArgs.realloc( aArgs.getLength() + 1 );
Sequence< PropertyValue > aFilterData( 3 );
@@ -341,11 +341,6 @@ Reference< XGraphic > GraphicHelper::importEmbeddedGraphic( const OUString& rStr
EmbeddedGraphicMap::const_iterator aIt = maEmbeddedGraphics.find( rStreamName );
if( aIt == maEmbeddedGraphics.end() )
{
// TODO make lazy-load work for EMF as well.
WmfExternal aHeader;
if (rStreamName.endsWith(".emf") && !pExtHeader)
pExtHeader = &aHeader;
xGraphic = importGraphic(mxStorage->openInputStream(rStreamName), pExtHeader);
if( xGraphic.is() )
maEmbeddedGraphics[ rStreamName ] = xGraphic;

View File

@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_ww8import, \
sal \
test \
unotest \
vcl \
sfx \
sw \
utl \

Binary file not shown.

View File

@@ -116,6 +116,14 @@ DECLARE_WW8IMPORT_TEST( testTdf105570, "tdf105570.doc" )
CPPUNIT_ASSERT_EQUAL( sal_uInt16(0), pTableNd->GetTable().GetRowsToRepeat() );
}
DECLARE_OOXMLIMPORT_TEST(testImageLazyRead, "image-lazy-read.doc")
{
auto xGraphic = getProperty<uno::Reference<graphic::XGraphic>>(getShape(1), "Graphic");
Graphic aGraphic(xGraphic);
// This failed, import loaded the graphic, it wasn't lazy-read.
CPPUNIT_ASSERT(!aGraphic.isAvailable());
}
DECLARE_WW8IMPORT_TEST(testTdf106799, "tdf106799.doc")
{
sal_Int32 const nCellWidths[3][4] = { { 9530, 0, 0, 0 },{ 2382, 2382, 2382, 2384 },{ 2382, 2382, 2382, 2384 } };

View File

@@ -1572,6 +1572,7 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream)
nGraphicContentSize = nStreamLength;
pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
rIStream.Seek(nStreamBegin);
rIStream.ReadBytes(pGraphicContent.get(), nStreamLength);
if (!rIStream.GetError())

View File

@@ -355,9 +355,6 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
}
}
if (bLazyRead && aFilterData.hasElements())
bLazyRead = false;
SolarMutexGuard g;
if( xIStm.is() )
@@ -396,7 +393,10 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
aExtHeader.mapMode = nExtMapMode;
WmfExternal *pExtHeader = nullptr;
if ( nExtMapMode > 0 )
{
pExtHeader = &aExtHeader;
bLazyRead = false;
}
ErrCode error = ERRCODE_NONE;
if (bLazyRead)