1 moved here from rsvg renderer
8 vcl/inc/vcl/gdimtf.hxx | 26 +++++++++
9 vcl/source/gdi/gdimtf.cxx | 129 +++++++++++++++++++++++++++++++++++++++++++++
10 2 files changed, 154 insertions(+), 1 deletions(-)
12 diff --git a/vcl/inc/vcl/gdimtf.hxx b/vcl/inc/vcl/gdimtf.hxx
13 index 234e127..6903acb 100644
14 --- vcl/inc/vcl/gdimtf.hxx
15 +++ vcl/inc/vcl/gdimtf.hxx
20 +class MetaCommentAction;
24 @@ -140,6 +141,7 @@ private:
25 const PolyPolygon& rPolyPoly,
26 const Gradient& rGrad );
27 SAL_DLLPRIVATE bool ImplPlayWithRenderer( OutputDevice* pOut, const Point& rPos, Size rDestSize );
28 + SAL_DLLPRIVATE void ImplDelegate2PluggableRenderer( const MetaCommentAction* pAct, OutputDevice* pOut );
32 @@ -243,5 +245,29 @@ public:
33 void UseCanvas( BOOL _bUseCanvas );
36 +/** Create a special metaaction that delegates rendering to specified
39 + This factory function creates a MetaCommentAction that delegates
40 + rendering to the specified services, once played back in the
43 + @param rRendererServiceName
44 + Renderer service. Gets an awt::XGraphic on instantiation
46 + @param rGraphicServiceName
47 + Graphic service. Gets the raw data on instantiation
50 + Raw data. Gets copied
53 + Length, in byte, of raw data
55 +MetaCommentAction* makePluggableRendererAction( const rtl::OUString& rRendererServiceName,
56 + const rtl::OUString& rGraphicServiceName,
58 + sal_uInt32 nDataSize );
60 #endif // _SV_GDIMTF_HXX
62 diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx
63 index 92e2acf..8c1c012 100644
64 --- vcl/source/gdi/gdimtf.cxx
65 +++ vcl/source/gdi/gdimtf.cxx
67 #include <com/sun/star/rendering/MtfRenderer.hpp>
68 #include <comphelper/processfactory.hxx>
69 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
70 +#include <com/sun/star/lang/XInitialization.hpp>
71 +#include <com/sun/star/awt/XGraphics.hpp>
72 +#include <com/sun/star/graphic/XGraphic.hpp>
73 +#include <com/sun/star/graphic/XGraphicRenderer.hpp>
75 using namespace com::sun::star;
77 @@ -477,7 +481,16 @@ void GDIMetaFile::Play( OutputDevice* pOut, ULONG nPos )
81 - pAction->Execute( pOut );
82 + MetaCommentAction* pCommentAct = static_cast<MetaCommentAction*>(pAction);
83 + if( pAction->GetType() == META_COMMENT_ACTION &&
84 + pCommentAct->GetComment().Equals("DELEGATE_PLUGGABLE_RENDERER") )
86 + ImplDelegate2PluggableRenderer(pCommentAct, pOut);
90 + pAction->Execute( pOut );
93 // flush output from time to time
94 if( i++ > nSyncCount )
95 @@ -563,6 +576,77 @@ bool GDIMetaFile::ImplPlayWithRenderer( OutputDevice* pOut, const Point& rPos, S
97 // ------------------------------------------------------------------------
99 +void GDIMetaFile::ImplDelegate2PluggableRenderer( const MetaCommentAction* pAct, OutputDevice* pOut )
101 + OSL_ASSERT( pAct->GetComment().Equals("DELEGATE_PLUGGABLE_RENDERER") );
103 + // read payload - string of service name, followed by raw render input
104 + const BYTE* pData = pAct->GetData();
105 + const BYTE* const pEndData = pData + pAct->GetDataSize();
109 + ::rtl::OUStringBuffer aBuffer;
110 + while( pData<pEndData && *pData )
111 + aBuffer.append(static_cast<sal_Unicode>(*pData++));
112 + const ::rtl::OUString aRendererServiceName=aBuffer.makeStringAndClear();
115 + while( pData<pEndData && *pData )
116 + aBuffer.append(static_cast<sal_Unicode>(*pData++));
117 + const ::rtl::OUString aGraphicServiceName=aBuffer.makeStringAndClear();
120 + uno::Reference< lang::XMultiServiceFactory > xFactory = vcl::unohelper::GetMultiServiceFactory();
121 + if( pData<pEndData && xFactory.is() )
125 + // instantiate render service
126 + uno::Sequence<uno::Any> aRendererArgs(1);
127 + aRendererArgs[0] = makeAny(uno::Reference<awt::XGraphics>(pOut->CreateUnoGraphics()));
128 + uno::Reference<graphic::XGraphicRenderer> xRenderer(
129 + xFactory->createInstanceWithArguments(
130 + aRendererServiceName,
134 + // instantiate graphic service
135 + uno::Reference<graphic::XGraphic> xGraphic(
136 + xFactory->createInstance(
137 + aGraphicServiceName),
140 + uno::Reference<lang::XInitialization> xInit(
141 + xGraphic, uno::UNO_QUERY);
143 + if(xGraphic.is() && xRenderer.is() && xInit.is())
145 + // delay intialization of XGraphic, to only expose
146 + // XGraphic-generating services to arbitrary binary data
147 + uno::Sequence< sal_Int8 > aSeq(
148 + (sal_Int8*)&pData, pEndData-pData );
149 + uno::Sequence<uno::Any> aGraphicsArgs(1);
150 + aGraphicsArgs[0] = makeAny(aSeq);
151 + xInit->initialize(aGraphicsArgs);
153 + xRenderer->render(xGraphic);
156 + catch( uno::RuntimeException& )
158 + // runtime errors are fatal
161 + catch( uno::Exception& )
163 + // ignore errors, no way of reporting them here
168 +// ------------------------------------------------------------------------
170 void GDIMetaFile::Play( OutputDevice* pOut, const Point& rPos,
171 const Size& rSize, ULONG nPos )
173 @@ -2606,3 +2690,46 @@ void GDIMetaFile::UseCanvas( BOOL _bUseCanvas )
175 bUseCanvas = _bUseCanvas;
178 +// ------------------------------------------------------------------------
180 +MetaCommentAction* makePluggableRendererAction( const rtl::OUString& rRendererServiceName,
181 + const rtl::OUString& rGraphicServiceName,
182 + const void* _pData,
183 + sal_uInt32 nDataSize )
185 + const BYTE* pData=(BYTE*)_pData;
187 + // data gets copied twice, unfortunately
188 + rtl::OString aRendererServiceName(
189 + rRendererServiceName.getStr(),
190 + rRendererServiceName.getLength(),
191 + RTL_TEXTENCODING_ASCII_US);
192 + rtl::OString aGraphicServiceName(
193 + rGraphicServiceName.getStr(),
194 + rGraphicServiceName.getLength(),
195 + RTL_TEXTENCODING_ASCII_US);
197 + std::vector<sal_uInt8> aMem(
198 + aRendererServiceName.getLength()+
199 + aGraphicServiceName.getLength()+2+nDataSize);
200 + sal_uInt8* pMem=&aMem[0];
202 + std::copy(aRendererServiceName.getStr(),
203 + aRendererServiceName.getStr()+aRendererServiceName.getLength()+1,
205 + pMem+=aRendererServiceName.getLength()+1;
206 + std::copy(aGraphicServiceName.getStr(),
207 + aGraphicServiceName.getStr()+aGraphicServiceName.getLength()+1,
209 + pMem+=aGraphicServiceName.getLength()+1;
211 + std::copy(pData,pData+nDataSize,
214 + return new MetaCommentAction(
215 + "DELEGATE_PLUGGABLE_RENDERER",