26#include <com/sun/star/uno/Exception.hpp>
27#include <com/sun/star/graphic/GraphicProvider.hpp>
28#include <com/sun/star/graphic/XGraphicProvider.hpp>
29#include <com/sun/star/graphic/XGraphic.hpp>
46#include <bitmaps.hlst>
59 std::unique_ptr<SvMemoryStream> pResult;
62 std::unique_ptr<SvMemoryStream> pStream(
new SvMemoryStream( 65535, 65535 ));
65 pResult = std::move(pStream);
73void* GraphicHelper::getEnhMetaFileFromGDI_Impl(
const GDIMetaFile* pGDIMeta )
75 void* pResult =
nullptr;
82 OUString aMetaFile = aTempFile.GetFileName();
83 OUString aMetaURL = aTempFile.GetURL();
94 pResult = GetEnhMetaFileW( o3tl::toW(aMetaFile.getStr()) );
106void* GraphicHelper::getWinMetaFileFromGDI_Impl(
const GDIMetaFile* pGDIMeta,
const Size& aMetaSize )
108 void* pResult =
nullptr;
119 sal_Int32
nLength = pStream.TellEnd();
122 HMETAFILE hMeta = SetMetaFileBitsEx( nLength - 22,
123 static_cast< const unsigned char*
>( pStream.GetData() ) + 22 );
127 HGLOBAL hMemory = GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE,
sizeof( METAFILEPICT ) );
131 METAFILEPICT* pMF =
static_cast<METAFILEPICT*
>(GlobalLock( hMemory ));
136 MapMode aWinMode( MapUnit::Map100thMM );
140 pMF->xExt = aMetaSize.
Width();
141 pMF->yExt = aMetaSize.
Height();
148 pMF->xExt = aWinSize.
Width();
149 pMF->yExt = aWinSize.
Height();
152 GlobalUnlock( hMemory );
153 pResult =
static_cast<void*
>(hMemory);
156 DeleteMetaFile( hMeta );
172bool GraphicHelper::getThumbnailFormatFromBitmap_Impl(
const BitmapEx& rBitmap,
const uno::Reference<io::XStream>& xStream)
179 if (pStream->GetError())
183 bitmap.Convert(BmpConversion::N8BitColors);
190 pStream->FlushBuffer();
192 return !pStream->GetError();
196bool GraphicHelper::getThumbnailReplacement_Impl(std::u16string_view rResID,
const uno::Reference< io::XStream >& xStream )
198 bool bResult =
false;
199 if (!rResID.empty() &&
xStream.is())
201 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
204 uno::Reference< graphic::XGraphicProvider > xGraphProvider(graphic::GraphicProvider::create(xContext));
205 const OUString
aURL{OUString::Concat(
"private:graphicrepository/") + rResID};
210 uno::Reference< graphic::XGraphic > xGraphic = xGraphProvider->queryGraphic( aMediaProps );
213 uno::Sequence< beans::PropertyValue > aStoreProps{
218 xGraphProvider->storeGraphic( xGraphic, aStoreProps );
222 catch(
const uno::Exception&)
231OUString GraphicHelper::getThumbnailReplacementIDByFactoryName_Impl( std::u16string_view aFactoryShortName )
235 if ( aFactoryShortName == u
"scalc" )
237 sResult = BMP_128X128_CALC_DOC;
239 else if ( aFactoryShortName == u
"sdraw" )
241 sResult = BMP_128X128_DRAW_DOC;
243 else if ( aFactoryShortName == u
"simpress" )
245 sResult = BMP_128X128_IMPRESS_DOC;
247 else if ( aFactoryShortName == u
"smath" )
249 sResult = BMP_128X128_MATH_DOC;
251 else if ( aFactoryShortName == u
"swriter" ||
o3tl::starts_with(aFactoryShortName, u
"swriter/") )
253 sResult = BMP_128X128_WRITER_DOC;
static ErrCode Export(SvStream &rOStm, const Graphic &rGraphic, ConvertDataFormat nFormat)
static GraphicFilter & GetGraphicFilter()
ErrCode compressAsPNG(const Graphic &rGraphic, SvStream &rOutputStream)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept