diff options
-rw-r--r-- | svx/source/xml/xmlgrhlp.cxx | 460 |
1 files changed, 5 insertions, 455 deletions
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index 62aa1bb6dd1b..8861ce4db830 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -74,140 +74,6 @@ const MetaCommentAction* ImplCheckForEPS( GDIMetaFile const & rMtf ) return pComment; } -class SvXMLGraphicInputStream: - public cppu::WeakImplHelper<XInputStream> -{ -private: - - virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) override; - virtual sal_Int32 SAL_CALL readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) override; - virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override; - virtual sal_Int32 SAL_CALL available() override; - virtual void SAL_CALL closeInput() override; - -private: - - ::utl::TempFile maTmp; - Reference< XInputStream > mxStmWrapper; - -public: - - explicit SvXMLGraphicInputStream( const OUString& rGraphicId, const OUString& rMimeType ); - SvXMLGraphicInputStream(const SvXMLGraphicInputStream&) = delete; - SvXMLGraphicInputStream& operator=(const SvXMLGraphicInputStream&) = delete; - - bool Exists() const { return mxStmWrapper.is(); } -}; - - -SvXMLGraphicInputStream::SvXMLGraphicInputStream( const OUString& rGraphicId, const OUString& rMimeType ) -{ - GraphicObject aGrfObject( OUStringToOString(rGraphicId, RTL_TEXTENCODING_ASCII_US) ); - - maTmp.EnableKillingFile(); - - if( aGrfObject.GetType() != GraphicType::NONE ) - { - SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( maTmp.GetURL(), StreamMode::WRITE | StreamMode::TRUNC ); - - if( pStm ) - { - Graphic aGraphic( aGrfObject.GetGraphic() ); - const GfxLink aGfxLink( aGraphic.GetLink() ); - bool bRet = false; - - if( aGfxLink.GetDataSize() && aGfxLink.GetData() ) - { - if ( rMimeType.isEmpty() ) - { - pStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); - bRet = ( pStm->GetError() == ERRCODE_NONE ); - } - else - { - GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter(); - bRet = ( rFilter.ExportGraphic( aGraphic, "", *pStm, rFilter.GetExportFormatNumberForMediaType( rMimeType ) ) == ERRCODE_NONE ); - } - } - else - { - if( aGraphic.GetType() == GraphicType::Bitmap ) - { - GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter(); - OUString aFormat=rMimeType; - - if( aGraphic.IsAnimated() ) - aFormat = "image/gif"; - else if( aFormat.isEmpty() ) - aFormat = "image/png"; - - bRet = ( rFilter.ExportGraphic( aGraphic, "", *pStm, rFilter.GetExportFormatNumberForMediaType( aFormat ) ) == ERRCODE_NONE ); - } - else if( rMimeType.isEmpty() && aGraphic.GetType() == GraphicType::GdiMetafile ) - { - pStm->SetVersion( SOFFICE_FILEFORMAT_8 ); - pStm->SetCompressMode( SvStreamCompressFlags::ZBITMAP ); - const_cast<GDIMetaFile&>( aGraphic.GetGDIMetaFile() ).Write( *pStm ); - bRet = ( pStm->GetError() == ERRCODE_NONE ); - } - else if( !rMimeType.isEmpty() ) - { - GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter(); - bRet = ( rFilter.ExportGraphic( aGraphic, "", *pStm, rFilter.GetExportFormatNumberForMediaType( rMimeType ) ) == ERRCODE_NONE ); - } - } - - if( bRet ) - { - pStm->Seek( 0 ); - mxStmWrapper = new ::utl::OInputStreamWrapper( pStm, true ); - } - else - delete pStm; - } - } -} - -sal_Int32 SAL_CALL SvXMLGraphicInputStream::readBytes( Sequence< sal_Int8 >& rData, sal_Int32 nBytesToRead ) -{ - if( !mxStmWrapper.is() ) - throw NotConnectedException(); - - return mxStmWrapper->readBytes( rData, nBytesToRead ); -} - -sal_Int32 SAL_CALL SvXMLGraphicInputStream::readSomeBytes( Sequence< sal_Int8 >& rData, sal_Int32 nMaxBytesToRead ) -{ - if( !mxStmWrapper.is() ) - throw NotConnectedException() ; - - return mxStmWrapper->readSomeBytes( rData, nMaxBytesToRead ); -} - -void SAL_CALL SvXMLGraphicInputStream::skipBytes( sal_Int32 nBytesToSkip ) -{ - if( !mxStmWrapper.is() ) - throw NotConnectedException() ; - - mxStmWrapper->skipBytes( nBytesToSkip ); -} - -sal_Int32 SAL_CALL SvXMLGraphicInputStream::available() -{ - if( !mxStmWrapper.is() ) - throw NotConnectedException() ; - - return mxStmWrapper->available(); -} - -void SAL_CALL SvXMLGraphicInputStream::closeInput() -{ - if( !mxStmWrapper.is() ) - throw NotConnectedException() ; - - mxStmWrapper->closeInput(); -} - namespace xmloff { class GraphicInputStream : public cppu::WeakImplHelper<XInputStream> @@ -639,272 +505,6 @@ Graphic SvXMLGraphicHelper::ImplReadGraphic( const OUString& rPictureStorageName return aGraphic; } -bool SvXMLGraphicHelper::ImplWriteGraphic( const OUString& rPictureStorageName, - const OUString& rPictureStreamName, - const OUString& rGraphicId, - bool bUseGfxLink ) -{ - GraphicObject aGrfObject( OUStringToOString(rGraphicId, RTL_TEXTENCODING_ASCII_US) ); - bool bRet = false; - - if( aGrfObject.GetType() != GraphicType::NONE ) - { - SvxGraphicHelperStream_Impl aStream( ImplGetGraphicStream( rPictureStorageName, rPictureStreamName ) ); - if( aStream.xStream.is() ) - { - Graphic aGraphic( aGrfObject.GetGraphic() ); - const GfxLink aGfxLink( aGraphic.GetLink() ); - const OUString aMimeType( ImplGetGraphicMimeType( rPictureStreamName ) ); - uno::Reference < beans::XPropertySet > xProps( aStream.xStream, uno::UNO_QUERY ); - - // set stream properties (MediaType/Compression) - if( !aMimeType.isEmpty() ) - { - xProps->setPropertyValue( "MediaType", Any(aMimeType) ); - } - - // picture formats that actually _do_ benefit from zip - // storage compression - // .svm pics gets compressed via ZBITMAP old-style stream - // option below - static const char* aCompressiblePics[] = - { - "image/svg+xml", - "image/x-wmf", - "image/tiff", - "image/x-eps", - "image/bmp", - "image/x-pict" - }; - - bool bCompressed = aMimeType.isEmpty(); - if( !bCompressed ) - { - for(const char* p : aCompressiblePics) - { - if( aMimeType.equalsIgnoreAsciiCaseAscii(p) ) - { - bCompressed = true; - break; - } - } - } - - xProps->setPropertyValue( "Compressed", Any(bCompressed) ); - - std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aStream.xStream )); - if( bUseGfxLink && aGfxLink.GetDataSize() && aGfxLink.GetData() ) - { - const uno::Sequence<sal_Int8>& rPdfData = aGraphic.getPdfData(); - if (rPdfData.hasElements()) - { - // The graphic has PDF data attached to it, use that. - // vcl::ImportPDF() possibly downgraded the PDF data from a - // higher PDF version, while aGfxLink still contains the - // original data provided by the user. - pStream->WriteBytes(rPdfData.getConstArray(), rPdfData.getLength()); - } - else - { - pStream->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); - } - bRet = (pStream->GetError() == ERRCODE_NONE); - } - else - { - if( aGraphic.GetType() == GraphicType::Bitmap ) - { - GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter(); - OUString aFormat; - - if( aGraphic.IsAnimated() ) - aFormat = "gif"; - else - aFormat = "png"; - - bRet = ( rFilter.ExportGraphic( aGraphic, "", *pStream, - rFilter.GetExportFormatNumberForShortName( aFormat ) ) == ERRCODE_NONE ); - } - else if( aGraphic.GetType() == GraphicType::GdiMetafile ) - { - pStream->SetVersion( SOFFICE_FILEFORMAT_8 ); - pStream->SetCompressMode( SvStreamCompressFlags::ZBITMAP ); - - // SJ: first check if this metafile is just a eps file, then we will store the eps instead of svm - GDIMetaFile& rMtf(const_cast<GDIMetaFile&>( aGraphic.GetGDIMetaFile() )); - const MetaCommentAction* pComment = ImplCheckForEPS( rMtf ); - if ( pComment ) - { - sal_uInt32 nSize = pComment->GetDataSize(); - const sal_uInt8* pData = pComment->GetData(); - if ( nSize && pData ) - pStream->WriteBytes(pData, nSize); - - const MetaEPSAction* pAct = static_cast<const MetaEPSAction*>(rMtf.FirstAction()); - const GfxLink& rLink = pAct->GetLink(); - - pStream->WriteBytes(rLink.GetData(), rLink.GetDataSize()); - } - else - rMtf.Write( *pStream ); - - bRet = ( pStream->GetError() == ERRCODE_NONE ); - } - } - uno::Reference < embed::XTransactedObject > xStorage( - aStream.xStorage, uno::UNO_QUERY); - pStream.reset(); - aStream.xStream->getOutputStream()->closeOutput(); - if( xStorage.is() ) - xStorage->commit(); - } - } - - return bRet; -} - -void SvXMLGraphicHelper::ImplInsertGraphicURL( const OUString& rURLStr, sal_uInt32 nInsertPos, OUString const & rRequestedFileName ) -{ - OUString aPictureStorageName, aPictureStreamName; - if( maURLSet.find( rURLStr ) != maURLSet.end() ) - { - for (URLPairVector::const_iterator aIter( maGrfURLs.begin() ), aEnd( maGrfURLs.end() ); aIter != aEnd ; ++aIter) - { - if( rURLStr == (*aIter).first ) - { - maGrfURLs[ nInsertPos ].second = (*aIter).second; - break; - } - } - } - else if( ImplGetStreamNames( rURLStr, aPictureStorageName, aPictureStreamName ) ) - { - URLPair& rURLPair = maGrfURLs[ nInsertPos ]; - - if( SvXMLGraphicHelperMode::Read == meCreateMode ) - { - const GraphicObject aObj( ImplReadGraphic( aPictureStorageName, aPictureStreamName ) ); - - if( aObj.GetType() != GraphicType::NONE ) - { - maGrfObjs.push_back( aObj ); - - rURLPair.second = XML_GRAPHICOBJECT_URL_BASE; - rURLPair.second += OStringToOUString(aObj.GetUniqueID(), - RTL_TEXTENCODING_ASCII_US); - } - else - rURLPair.second.clear(); - } - else - { - const OString aAsciiObjectID(OUStringToOString(aPictureStreamName, RTL_TEXTENCODING_ASCII_US)); - const GraphicObject aGrfObject( aAsciiObjectID ); - if( aGrfObject.GetType() != GraphicType::NONE ) - { - OUString aStreamName( aPictureStreamName ); - Graphic aGraphic( aGrfObject.GetGraphic() ); - const GfxLink aGfxLink( aGraphic.GetLink() ); - OUString aExtension; - bool bUseGfxLink( true ); - - if( aGfxLink.GetDataSize() ) - { - switch( aGfxLink.GetType() ) - { - case GfxLinkType::EpsBuffer: aExtension = ".eps"; break; - case GfxLinkType::NativeGif: aExtension = ".gif"; break; - // #i15508# added BMP type for better exports (checked, works) - case GfxLinkType::NativeBmp: aExtension = ".bmp"; break; - case GfxLinkType::NativeJpg: aExtension = ".jpg"; break; - case GfxLinkType::NativePng: aExtension = ".png"; break; - case GfxLinkType::NativeTif: aExtension = ".tif"; break; - case GfxLinkType::NativeWmf: aExtension = ".wmf"; break; - case GfxLinkType::NativeMet: aExtension = ".met"; break; - case GfxLinkType::NativePct: aExtension = ".pct"; break; - case GfxLinkType::NativeSvg: - // backward-compat kludge: since no released OOo - // version to date can handle svg properly, wrap it up - // into an svm. slight catch22 here, since strict ODF - // conformance _recommends_ svg - then again, most old - // ODF consumers are believed to be OOo - if( SvtSaveOptions().GetODFDefaultVersion() <= SvtSaveOptions::ODFVER_012 ) - { - bUseGfxLink = false; - aExtension = ".svm"; - } - else - aExtension = ".svg"; - break; - case GfxLinkType::NativePdf: aExtension = ".pdf"; break; - - default: - aExtension = ".grf"; - break; - } - } - else - { - if( aGrfObject.GetType() == GraphicType::Bitmap ) - { - if( aGrfObject.IsAnimated() ) - aExtension = ".gif"; - else - aExtension = ".png"; - } - else if( aGrfObject.GetType() == GraphicType::GdiMetafile ) - { - // SJ: first check if this metafile is just a eps file, then we will store the eps instead of svm - GDIMetaFile& rMtf(const_cast<GDIMetaFile&>( aGraphic.GetGDIMetaFile() )); - if ( ImplCheckForEPS( rMtf ) ) - aExtension = ".eps"; - else - aExtension = ".svm"; - } - } - - OUString aURLEntry; - const OUString sPictures( "Pictures/" ); - - if ( !rRequestedFileName.isEmpty() ) - { - aURLEntry = sPictures; - aURLEntry += rRequestedFileName; - aURLEntry += aExtension; - - URLPairVector::const_iterator aIter( maGrfURLs.begin() ), aEnd( maGrfURLs.end() ); - for ( ; aIter != aEnd; ++aIter ) - { - if( aURLEntry == (*aIter).second ) - break; - } - if ( aIter == aEnd ) - aStreamName = rRequestedFileName; - } - - aStreamName += aExtension; - - if( mbDirect && !aStreamName.isEmpty() ) - ImplWriteGraphic( aPictureStorageName, aStreamName, aPictureStreamName, bUseGfxLink ); - - rURLPair.second = sPictures; - rURLPair.second += aStreamName; - } -#if OSL_DEBUG_LEVEL > 0 - else - { - OStringBuffer sMessage("graphic object with ID '"); - sMessage.append(aAsciiObjectID). - append("' has an unknown type"); - OSL_ENSURE( false, sMessage.getStr() ); - } -#endif - } - - maURLSet.insert( rURLStr ); - } -} - void SvXMLGraphicHelper::Init( const uno::Reference < embed::XStorage >& rXMLStorage, SvXMLGraphicHelperMode eCreateMode, bool bDirect, @@ -958,46 +558,10 @@ void splitUserDataFromURL(OUString const & rWholeURL, OUString & rJustURL, OUStr } // end anonymous namespace // XGraphicObjectResolver -OUString SAL_CALL SvXMLGraphicHelper::resolveGraphicObjectURL( const OUString& rURL ) +OUString SAL_CALL SvXMLGraphicHelper::resolveGraphicObjectURL( const OUString& /*rURL*/ ) { - ::osl::MutexGuard aGuard( maMutex ); - const sal_Int32 nIndex = maGrfURLs.size(); - - OUString aURL( rURL ); - OUString aUserData; - OUString aRequestedFileName; - - sal_Int32 nUser = rURL.indexOf( '?' ); - if ( nUser >= 0 ) - { - aURL = rURL.copy( 0, nUser ); - nUser++; - aUserData = rURL.copy( nUser ); - } - if ( !aUserData.isEmpty() ) - { - sal_Int32 nIndex2 = 0; - do - { - OUString aToken = aUserData.getToken( 0, ';', nIndex2 ); - sal_Int32 n = aToken.indexOf( '=' ); - if ( ( n > 0 ) && ( ( n + 1 ) < aToken.getLength() ) ) - { - OUString aParam( aToken.copy( 0, n ) ); - OUString aValue( aToken.copy( n + 1 ) ); - - const OUString sRequestedName( "requestedName" ); - if ( aParam.match( sRequestedName ) ) - aRequestedFileName = aValue; - } - } - while ( nIndex2 >= 0 ); - } - - maGrfURLs.emplace_back( aURL, OUString() ); - ImplInsertGraphicURL( aURL, nIndex, aRequestedFileName ); - - return maGrfURLs[ nIndex ].second; + osl::MutexGuard aGuard( maMutex ); + return OUString(); } // XGraphicStorageHandler @@ -1309,23 +873,9 @@ uno::Reference<io::XInputStream> SAL_CALL SvXMLGraphicHelper::createInputStream( } // XBinaryStreamResolver -Reference< XInputStream > SAL_CALL SvXMLGraphicHelper::getInputStream( const OUString& rURL ) +Reference< XInputStream > SAL_CALL SvXMLGraphicHelper::getInputStream( const OUString& /*rURL*/ ) { - Reference< XInputStream > xRet; - OUString aPictureStorageName, aGraphicId; - - if( ( SvXMLGraphicHelperMode::Write == meCreateMode ) && - ImplGetStreamNames( rURL, aPictureStorageName, aGraphicId ) ) - { - OUString sMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForExtension( OUStringToOString( maOutputMimeType, RTL_TEXTENCODING_ASCII_US ) ); - SvXMLGraphicInputStream* pInputStream = new SvXMLGraphicInputStream( aGraphicId, sMimeType ); - - if( pInputStream->Exists() ) - xRet = pInputStream; - else - delete pInputStream; - } - + Reference<XInputStream> xRet; return xRet; } |