diff options
author | Daniel Rentz <dr@openoffice.org> | 2010-06-03 11:12:10 +0200 |
---|---|---|
committer | Daniel Rentz <dr@openoffice.org> | 2010-06-03 11:12:10 +0200 |
commit | 85b12c651ea75ce0006b1b04c2eaafb998cb9837 (patch) | |
tree | 494052d2496a51dd75ae41eaa1c1c25540fd4814 /oox | |
parent | 1ab26b208e07f2348ccf55d12de9648b8c6594a2 (diff) |
dr76: #i111404# move image stream handling into GraphicHelper
Diffstat (limited to 'oox')
-rw-r--r-- | oox/inc/oox/core/filterbase.hxx | 6 | ||||
-rw-r--r-- | oox/inc/oox/helper/graphichelper.hxx | 22 | ||||
-rw-r--r-- | oox/inc/oox/vml/vmlformatting.hxx | 2 | ||||
-rwxr-xr-x | oox/source/core/filterbase.cxx | 35 | ||||
-rw-r--r-- | oox/source/drawingml/fillpropertiesgroupcontext.cxx | 3 | ||||
-rw-r--r-- | oox/source/drawingml/graphicshapecontext.cxx | 3 | ||||
-rw-r--r-- | oox/source/helper/graphichelper.cxx | 34 | ||||
-rw-r--r-- | oox/source/ppt/pptimport.cxx | 2 | ||||
-rw-r--r-- | oox/source/vml/vmlformatting.cxx | 5 | ||||
-rw-r--r-- | oox/source/vml/vmlshape.cxx | 9 | ||||
-rw-r--r-- | oox/source/xls/pagesettings.cxx | 2 | ||||
-rw-r--r-- | oox/source/xls/stylesbuffer.cxx | 2 |
12 files changed, 72 insertions, 53 deletions
diff --git a/oox/inc/oox/core/filterbase.hxx b/oox/inc/oox/core/filterbase.hxx index 31e26d38f590..1733c2ad51c2 100644 --- a/oox/inc/oox/core/filterbase.hxx +++ b/oox/inc/oox/core/filterbase.hxx @@ -202,12 +202,6 @@ public: @return True, if the data could be imported from the stream. */ bool importBinaryData( StreamDataSequence& orDataSeq, const ::rtl::OUString& rStreamName ); - /** Imports a graphic from the storage stream with the passed path and name. */ - ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > - importEmbeddedGraphic( const ::rtl::OUString& rStreamName ) const; - /** Imports a graphic object from the storage stream with the passed path and name. */ - ::rtl::OUString importEmbeddedGraphicObject( const ::rtl::OUString& rStreamName ) const; - // com.sun.star.lang.XServiceInfo interface ------------------------------- virtual ::rtl::OUString SAL_CALL diff --git a/oox/inc/oox/helper/graphichelper.hxx b/oox/inc/oox/helper/graphichelper.hxx index 2d0964b37715..37002940cb17 100644 --- a/oox/inc/oox/helper/graphichelper.hxx +++ b/oox/inc/oox/helper/graphichelper.hxx @@ -34,6 +34,7 @@ #include <com/sun/star/awt/DeviceInfo.hpp> #include <com/sun/star/uno/Reference.hxx> #include "oox/helper/binarystreambase.hxx" +#include "oox/helper/storagebase.hxx" namespace com { namespace sun { namespace star { namespace awt { struct Point; } @@ -68,9 +69,12 @@ class GraphicHelper public: explicit GraphicHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxGlobalFactory, - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxTargetFrame ); + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxTargetFrame, + const StorageRef& rxStorage ); virtual ~GraphicHelper(); + // System colors and predefined colors ------------------------------------ + /** Returns a system color specified by the passed XML token identifier. */ sal_Int32 getSystemColor( sal_Int32 nToken, sal_Int32 nDefaultRgb = API_RGB_TRANSPARENT ) const; /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */ @@ -78,6 +82,8 @@ public: /** Derived classes may implement to resolve a palette index to an RGB color. */ virtual sal_Int32 getPaletteColor( sal_Int32 nPaletteIdx ) const; + // Device info and device dependent unit conversion ----------------------- + /** Returns information about the output device. */ const ::com::sun::star::awt::DeviceInfo& getDeviceInfo() const; @@ -109,6 +115,8 @@ public: /** Converts the passed size from 1/100 mm to AppFont units. */ ::com::sun::star::awt::Size convertHmmToAppFont( const ::com::sun::star::awt::Size& rHmm ) const; + // Graphics and graphic objects ------------------------------------------ + /** Imports a graphic from the passed input stream. */ ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > importGraphic( @@ -118,6 +126,10 @@ public: ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > importGraphic( const StreamDataSequence& rGraphicData ) const; + /** Imports a graphic from the storage stream with the passed path and name. */ + ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > + importEmbeddedGraphic( const ::rtl::OUString& rStreamName ) const; + /** Creates a persistent graphic object from the passed graphic. @return The URL of the created and internally cached graphic object. */ ::rtl::OUString createGraphicObject( @@ -132,16 +144,24 @@ public: @return The URL of the created and internally cached graphic object. */ ::rtl::OUString importGraphicObject( const StreamDataSequence& rGraphicData ) const; + /** Imports a graphic object from the storage stream with the passed path and name. + @return The URL of the created and internally cached graphic object. */ + ::rtl::OUString importEmbeddedGraphicObject( const ::rtl::OUString& rStreamName ) const; + + // ------------------------------------------------------------------------ private: typedef ::std::map< sal_Int32, sal_Int32 > SystemPalette; typedef ::std::deque< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicObject > > GraphicObjectDeque; + typedef ::std::map< ::rtl::OUString, ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > > EmbeddedGraphicMap; ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxCompContext; ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicProvider > mxGraphicProvider; ::com::sun::star::uno::Reference< ::com::sun::star::awt::XUnitConversion > mxUnitConversion; ::com::sun::star::awt::DeviceInfo maDeviceInfo; /// Current output device info. SystemPalette maSystemPalette; /// Maps system colors (XML tokens) to RGB color values. + StorageRef mxStorage; /// Storage containing embedded graphics. mutable GraphicObjectDeque maGraphicObjects; /// Caches all created graphic objects to keep them alive. + mutable EmbeddedGraphicMap maEmbeddedGraphics; /// Maps all embedded graphics by their storage path. const ::rtl::OUString maGraphicObjScheme; /// The URL scheme name for graphic objects. double mfPixelPerHmmX; /// Number of screen pixels per 1/100 mm in X direction. double mfPixelPerHmmY; /// Number of screen pixels per 1/100 mm in Y direction. diff --git a/oox/inc/oox/vml/vmlformatting.hxx b/oox/inc/oox/vml/vmlformatting.hxx index 6b970e5b80cc..db67d7a85af4 100644 --- a/oox/inc/oox/vml/vmlformatting.hxx +++ b/oox/inc/oox/vml/vmlformatting.hxx @@ -34,7 +34,6 @@ namespace oox { class GraphicHelper; class ModelObjectHelper; class PropertyMap; - namespace core { class FilterBase; } } namespace oox { @@ -178,7 +177,6 @@ struct FillModel /** Writes the properties to the passed property map. */ void pushToPropMap( PropertyMap& rPropMap, - ::oox::core::FilterBase& rFilter, ModelObjectHelper& rModelObjectHelper, const GraphicHelper& rGraphicHelper ) const; }; diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx index 902784cafe80..5ed1d7094ff3 100755 --- a/oox/source/core/filterbase.cxx +++ b/oox/source/core/filterbase.cxx @@ -130,10 +130,9 @@ enum FilterDirection struct FilterBaseImpl { - typedef ::boost::shared_ptr< GraphicHelper > GraphicHelperRef; - typedef ::boost::shared_ptr< ModelObjectHelper > ModelObjHelperRef; - typedef ::boost::shared_ptr< OleObjectHelper > OleObjHelperRef; - typedef ::std::map< OUString, Reference< XGraphic > > EmbeddedGraphicMap; + typedef ::boost::shared_ptr< GraphicHelper > GraphicHelperRef; + typedef ::boost::shared_ptr< ModelObjectHelper > ModelObjHelperRef; + typedef ::boost::shared_ptr< OleObjectHelper > OleObjHelperRef; FilterDirection meDirection; SequenceAsHashMap maArguments; @@ -144,7 +143,6 @@ struct FilterBaseImpl GraphicHelperRef mxGraphicHelper; /// Graphic and graphic object handling. ModelObjHelperRef mxModelObjHelper; /// Tables to create new named drawing objects. OleObjHelperRef mxOleObjHelper; /// OLE object handling. - EmbeddedGraphicMap maEmbeddedGraphics; /// Maps all imported embedded graphics by their path. Reference< XMultiServiceFactory > mxGlobalFactory; Reference< XModel > mxModel; @@ -423,31 +421,6 @@ bool FilterBase::importBinaryData( StreamDataSequence& orDataSeq, const OUString return true; } -Reference< XGraphic > FilterBase::importEmbeddedGraphic( const OUString& rStreamName ) const -{ - Reference< XGraphic > xGraphic; - OSL_ENSURE( rStreamName.getLength() > 0, "FilterBase::importEmbeddedGraphic - empty stream name" ); - if( rStreamName.getLength() > 0 ) - { - FilterBaseImpl::EmbeddedGraphicMap::const_iterator aIt = mxImpl->maEmbeddedGraphics.find( rStreamName ); - if( aIt == mxImpl->maEmbeddedGraphics.end() ) - { - xGraphic = getGraphicHelper().importGraphic( openInputStream( rStreamName ) ); - if( xGraphic.is() ) - mxImpl->maEmbeddedGraphics[ rStreamName ] = xGraphic; - } - else - xGraphic = aIt->second; - } - return xGraphic; -} - -OUString FilterBase::importEmbeddedGraphicObject( const OUString& rStreamName ) const -{ - Reference< XGraphic > xGraphic = importEmbeddedGraphic( rStreamName ); - return xGraphic.is() ? getGraphicHelper().createGraphicObject( xGraphic ) : OUString(); -} - // com.sun.star.lang.XServiceInfo interface ----------------------------------- OUString SAL_CALL FilterBase::getImplementationName() throw( RuntimeException ) @@ -587,7 +560,7 @@ void FilterBase::setMediaDescriptor( const Sequence< PropertyValue >& rMediaDesc GraphicHelper* FilterBase::implCreateGraphicHelper() const { // default: return base implementation without any special behaviour - return new GraphicHelper( mxImpl->mxGlobalFactory, mxImpl->mxTargetFrame ); + return new GraphicHelper( mxImpl->mxGlobalFactory, mxImpl->mxTargetFrame, mxImpl->mxStorage ); } // ============================================================================ diff --git a/oox/source/drawingml/fillpropertiesgroupcontext.cxx b/oox/source/drawingml/fillpropertiesgroupcontext.cxx index 8adffb265240..b9d7fa7e1142 100644 --- a/oox/source/drawingml/fillpropertiesgroupcontext.cxx +++ b/oox/source/drawingml/fillpropertiesgroupcontext.cxx @@ -27,6 +27,7 @@ #include "oox/drawingml/fillpropertiesgroupcontext.hxx" #include "oox/helper/attributelist.hxx" +#include "oox/helper/graphichelper.hxx" #include "oox/core/namespaces.hxx" #include "oox/core/xmlfilterbase.hxx" #include "oox/drawingml/drawingmltypes.hxx" @@ -170,7 +171,7 @@ BlipContext::BlipContext( ContextHandler& rParent, // internal picture URL OUString aFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( embed ), OUString() ) ); if( aFragmentPath.getLength() > 0 ) - mrBlipProps.mxGraphic = getFilter().importEmbeddedGraphic( aFragmentPath ); + mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importEmbeddedGraphic( aFragmentPath ); } else if( aAttribs.hasAttribute( R_TOKEN( link ) ) ) { diff --git a/oox/source/drawingml/graphicshapecontext.cxx b/oox/source/drawingml/graphicshapecontext.cxx index a0335fe68ee2..16604a77469b 100644 --- a/oox/source/drawingml/graphicshapecontext.cxx +++ b/oox/source/drawingml/graphicshapecontext.cxx @@ -35,6 +35,7 @@ #include "oox/core/namespaces.hxx" #include "oox/core/xmlfilterbase.hxx" #include "oox/helper/attributelist.hxx" +#include "oox/helper/graphichelper.hxx" #include "oox/helper/propertyset.hxx" #include "oox/vml/vmldrawing.hxx" #include "oox/vml/vmlshape.hxx" @@ -189,7 +190,7 @@ OUString CreateOleObjectCallback::onCreateXShape( const OUString&, const awt::Re // import and store the graphic if( aGraphicPath.getLength() > 0 ) { - Reference< graphic::XGraphic > xGraphic = mrFilter.importEmbeddedGraphic( aGraphicPath ); + Reference< graphic::XGraphic > xGraphic = mrFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath ); if( xGraphic.is() ) maShapeProps[ PROP_Graphic ] <<= xGraphic; } diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx index 6b294f61abef..455778f939f7 100644 --- a/oox/source/helper/graphichelper.cxx +++ b/oox/source/helper/graphichelper.cxx @@ -76,8 +76,9 @@ inline sal_Int32 lclConvertScreenPixelToHmm( double fPixel, double fPixelPerHmm // ============================================================================ -GraphicHelper::GraphicHelper( const Reference< XMultiServiceFactory >& rxGlobalFactory, const Reference< XFrame >& rxTargetFrame ) : +GraphicHelper::GraphicHelper( const Reference< XMultiServiceFactory >& rxGlobalFactory, const Reference< XFrame >& rxTargetFrame, const StorageRef& rxStorage ) : mxGraphicProvider( rxGlobalFactory->createInstance( CREATE_OUSTRING( "com.sun.star.graphic.GraphicProvider" ) ), UNO_QUERY ), + mxStorage( rxStorage ), maGraphicObjScheme( CREATE_OUSTRING( "vnd.sun.star.GraphicObject:" ) ) { ::comphelper::ComponentContext aContext( rxGlobalFactory ); @@ -149,6 +150,8 @@ GraphicHelper::~GraphicHelper() { } +// System colors and predefined colors ---------------------------------------- + sal_Int32 GraphicHelper::getSystemColor( sal_Int32 nToken, sal_Int32 nDefaultRgb ) const { return ContainerHelper::getMapElement( maSystemPalette, nToken, nDefaultRgb ); @@ -166,6 +169,8 @@ sal_Int32 GraphicHelper::getPaletteColor( sal_Int32 /*nPaletteIdx*/ ) const return API_RGB_TRANSPARENT; } +// Device info and device dependent unit conversion --------------------------- + const DeviceInfo& GraphicHelper::getDeviceInfo() const { return maDeviceInfo; @@ -267,6 +272,8 @@ Size GraphicHelper::convertHmmToAppFont( const Size& rHmm ) const return Size( 0, 0 ); } +// Graphics and graphic objects ---------------------------------------------- + Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStream >& rxInStrm ) const { Reference< XGraphic > xGraphic; @@ -294,6 +301,25 @@ Reference< XGraphic > GraphicHelper::importGraphic( const StreamDataSequence& rG return xGraphic; } +Reference< XGraphic > GraphicHelper::importEmbeddedGraphic( const OUString& rStreamName ) const +{ + Reference< XGraphic > xGraphic; + OSL_ENSURE( rStreamName.getLength() > 0, "GraphicHelper::importEmbeddedGraphic - empty stream name" ); + if( rStreamName.getLength() > 0 ) + { + EmbeddedGraphicMap::const_iterator aIt = maEmbeddedGraphics.find( rStreamName ); + if( aIt == maEmbeddedGraphics.end() ) + { + xGraphic = importGraphic( mxStorage->openInputStream( rStreamName ) ); + if( xGraphic.is() ) + maEmbeddedGraphics[ rStreamName ] = xGraphic; + } + else + xGraphic = aIt->second; + } + return xGraphic; +} + OUString GraphicHelper::createGraphicObject( const Reference< XGraphic >& rxGraphic ) const { OUString aGraphicObjUrl; @@ -320,6 +346,12 @@ OUString GraphicHelper::importGraphicObject( const StreamDataSequence& rGraphicD return createGraphicObject( importGraphic( rGraphicData ) ); } +OUString GraphicHelper::importEmbeddedGraphicObject( const OUString& rStreamName ) const +{ + Reference< XGraphic > xGraphic = importEmbeddedGraphic( rStreamName ); + return xGraphic.is() ? createGraphicObject( xGraphic ) : OUString(); +} + // ============================================================================ } // namespace oox diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx index 39ad52316a92..d60629b4481b 100644 --- a/oox/source/ppt/pptimport.cxx +++ b/oox/source/ppt/pptimport.cxx @@ -163,7 +163,7 @@ private: }; PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) : - GraphicHelper( rFilter.getGlobalFactory(), rFilter.getTargetFrame() ), + GraphicHelper( rFilter.getGlobalFactory(), rFilter.getTargetFrame(), rFilter.getStorage() ), mrFilter( rFilter ) { } diff --git a/oox/source/vml/vmlformatting.cxx b/oox/source/vml/vmlformatting.cxx index 3b832d9daf12..827930c22496 100644 --- a/oox/source/vml/vmlformatting.cxx +++ b/oox/source/vml/vmlformatting.cxx @@ -31,7 +31,6 @@ #include "oox/token/tokenmap.hxx" #include "oox/helper/graphichelper.hxx" #include "oox/helper/propertymap.hxx" -#include "oox/core/filterbase.hxx" #include "oox/drawingml/color.hxx" #include "oox/drawingml/drawingmltypes.hxx" #include "oox/drawingml/fillproperties.hxx" @@ -475,7 +474,7 @@ void FillModel::assignUsed( const FillModel& rSource ) moRotate.assignIfUsed( rSource.moRotate ); } -void FillModel::pushToPropMap( PropertyMap& rPropMap, ::oox::core::FilterBase& rFilter, +void FillModel::pushToPropMap( PropertyMap& rPropMap, ModelObjectHelper& rModelObjectHelper, const GraphicHelper& rGraphicHelper ) const { /* Convert VML fill formatting to DrawingML fill formatting and let the @@ -569,7 +568,7 @@ void FillModel::pushToPropMap( PropertyMap& rPropMap, ::oox::core::FilterBase& r { if( moBitmapPath.has() && moBitmapPath.get().getLength() > 0 ) { - aFillProps.maBlipProps.mxGraphic = rFilter.importEmbeddedGraphic( moBitmapPath.get() ); + aFillProps.maBlipProps.mxGraphic = rGraphicHelper.importEmbeddedGraphic( moBitmapPath.get() ); if( aFillProps.maBlipProps.mxGraphic.is() ) { aFillProps.moFillType = XML_blipFill; diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index 9bca05d69b24..d557a7f50354 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -36,6 +36,7 @@ #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/graphic/XGraphic.hpp> #include "properties.hxx" +#include "oox/helper/graphichelper.hxx" #include "oox/helper/propertymap.hxx" #include "oox/helper/propertyset.hxx" #include "oox/core/xmlfilterbase.hxx" @@ -99,7 +100,7 @@ Reference< XShape > lclCreateXShape( const XmlFilterBase& rFilter, const OUStrin Reference< XShape > xShape; try { - Reference< XMultiServiceFactory > xFactory( rFilter.getModel(), UNO_QUERY_THROW ); + Reference< XMultiServiceFactory > xFactory( rFilter.getModelFactory(), UNO_SET_THROW ); xShape.set( xFactory->createInstance( rService ), UNO_QUERY_THROW ); } catch( Exception& ) @@ -317,7 +318,7 @@ void ShapeBase::convertShapeProperties( const Reference< XShape >& rxShape ) con PropertyMap aPropMap; maTypeModel.maStrokeModel.pushToPropMap( aPropMap, rModelObjectHelper, rGraphicHelper ); - maTypeModel.maFillModel.pushToPropMap( aPropMap, mrDrawing.getFilter(), rModelObjectHelper, rGraphicHelper ); + maTypeModel.maFillModel.pushToPropMap( aPropMap, rModelObjectHelper, rGraphicHelper ); PropertySet aPropSet( rxShape ); aPropSet.setProperties( aPropMap ); @@ -431,7 +432,7 @@ Reference< XShape > ComplexShape::implConvertAndInsert( const Reference< XShapes // set the replacement graphic if( aGraphicPath.getLength() > 0 ) { - Reference< XGraphic > xGraphic = rFilter.importEmbeddedGraphic( aGraphicPath ); + Reference< XGraphic > xGraphic = rFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath ); if( xGraphic.is() ) aOleProps[ PROP_Graphic ] <<= xGraphic; } @@ -478,7 +479,7 @@ Reference< XShape > ComplexShape::implConvertAndInsert( const Reference< XShapes Reference< XShape > xShape = lclCreateAndInsertXShape( rFilter, rxShapes, CREATE_OUSTRING( "com.sun.star.drawing.GraphicObjectShape" ), rShapeRect ); if( xShape.is() ) { - OUString aGraphicUrl = rFilter.importEmbeddedGraphicObject( aGraphicPath ); + OUString aGraphicUrl = rFilter.getGraphicHelper().importEmbeddedGraphicObject( aGraphicPath ); if( aGraphicUrl.getLength() > 0 ) { PropertySet aPropSet( xShape ); diff --git a/oox/source/xls/pagesettings.cxx b/oox/source/xls/pagesettings.cxx index c0b1011fdbcc..0a5ce05a37df 100644 --- a/oox/source/xls/pagesettings.cxx +++ b/oox/source/xls/pagesettings.cxx @@ -440,7 +440,7 @@ void PageSettings::importPictureData( const Relations& rRelations, const OUStrin { OUString aPicturePath = rRelations.getFragmentPathFromRelId( rRelId ); if( aPicturePath.getLength() > 0 ) - maModel.maGraphicUrl = getBaseFilter().importEmbeddedGraphicObject( aPicturePath ); + maModel.maGraphicUrl = getBaseFilter().getGraphicHelper().importEmbeddedGraphicObject( aPicturePath ); } // ============================================================================ diff --git a/oox/source/xls/stylesbuffer.cxx b/oox/source/xls/stylesbuffer.cxx index b9a11b5104ea..5a149961c0e2 100644 --- a/oox/source/xls/stylesbuffer.cxx +++ b/oox/source/xls/stylesbuffer.cxx @@ -306,7 +306,7 @@ sal_Int32 lclReadRgbColor( BinaryInputStream& rStrm ) // ============================================================================ ExcelGraphicHelper::ExcelGraphicHelper( const WorkbookHelper& rHelper ) : - GraphicHelper( rHelper.getGlobalFactory(), rHelper.getBaseFilter().getTargetFrame() ), + GraphicHelper( rHelper.getGlobalFactory(), rHelper.getBaseFilter().getTargetFrame(), rHelper.getBaseFilter().getStorage() ), WorkbookHelper( rHelper ) { } |