LibreOffice Module vcl (master) 1
UnoGraphicDescriptor.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21
23#include <vcl/graphicfilter.hxx>
25
26#include <com/sun/star/beans/PropertyAttribute.hpp>
27#include <com/sun/star/awt/Size.hpp>
28#include <com/sun/star/graphic/GraphicType.hpp>
29#include <com/sun/star/io/XInputStream.hpp>
30
31#include <vcl/outdev.hxx>
32#include <vcl/graph.hxx>
33#include <vcl/svapp.hxx>
34#include <memory>
35
36namespace {
37
38enum class UnoGraphicProperty
39{
40 GraphicType = 1
41 , MimeType = 2
42 , SizePixel = 3
43 , Size100thMM = 4
44 , BitsPerPixel = 5
45 , Transparent = 6
46 , Alpha = 7
47 , Animated = 8
48 , Linked = 9
49 , OriginURL = 10
50};
51
52}
53
54using namespace ::com::sun::star;
55
56namespace unographic {
57
58
60 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
61 mpGraphic( nullptr ),
63 mnBitsPerPixel ( 0 ),
64 mbTransparent ( false )
65{
66}
67
69 noexcept
70{
71}
72
73void GraphicDescriptor::init( const ::Graphic& rGraphic )
74{
75 mpGraphic = &rGraphic;
76}
77
78void GraphicDescriptor::init( const OUString& rURL )
79{
80 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( rURL, StreamMode::READ ));
81
82 if( pIStm )
83 implCreate( *pIStm, &rURL );
84}
85
86void GraphicDescriptor::init( const uno::Reference< io::XInputStream >& rxIStm, const OUString& rURL )
87{
88 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( rxIStm ));
89
90 if( pIStm )
91 implCreate( *pIStm, &rURL );
92}
93
94void GraphicDescriptor::implCreate( SvStream& rIStm, const OUString* pURL )
95{
96 OUString aURL;
97 if( pURL )
98 aURL = *pURL;
99 ::GraphicDescriptor aDescriptor( rIStm, &aURL );
100
101 mpGraphic = nullptr;
102 maMimeType.clear();
104 mnBitsPerPixel = 0;
105 mbTransparent = false;
106
107 if( !(aDescriptor.Detect( true ) && aDescriptor.GetFileFormat() != GraphicFileFormat::NOT) )
108 return;
109
110 OUString aMimeType;
111 sal_uInt8 cType = graphic::GraphicType::EMPTY;
112
113 switch( aDescriptor.GetFileFormat() )
114 {
115 case GraphicFileFormat::BMP: aMimeType = MIMETYPE_BMP; cType = graphic::GraphicType::PIXEL; break;
116 case GraphicFileFormat::GIF: aMimeType = MIMETYPE_GIF; cType = graphic::GraphicType::PIXEL; break;
117 case GraphicFileFormat::JPG: aMimeType = MIMETYPE_JPG; cType = graphic::GraphicType::PIXEL; break;
118 case GraphicFileFormat::PCD: aMimeType = MIMETYPE_PCD; cType = graphic::GraphicType::PIXEL; break;
119 case GraphicFileFormat::PCX: aMimeType = MIMETYPE_PCX; cType = graphic::GraphicType::PIXEL; break;
120 case GraphicFileFormat::PNG: aMimeType = MIMETYPE_PNG; cType = graphic::GraphicType::PIXEL; break;
121 case GraphicFileFormat::TIF: aMimeType = MIMETYPE_TIF; cType = graphic::GraphicType::PIXEL; break;
122 case GraphicFileFormat::XBM: aMimeType = MIMETYPE_XBM; cType = graphic::GraphicType::PIXEL; break;
123 case GraphicFileFormat::XPM: aMimeType = MIMETYPE_XPM; cType = graphic::GraphicType::PIXEL; break;
124 case GraphicFileFormat::PBM: aMimeType = MIMETYPE_PBM; cType = graphic::GraphicType::PIXEL; break;
125 case GraphicFileFormat::PGM: aMimeType = MIMETYPE_PGM; cType = graphic::GraphicType::PIXEL; break;
126 case GraphicFileFormat::PPM: aMimeType = MIMETYPE_PPM; cType = graphic::GraphicType::PIXEL; break;
127 case GraphicFileFormat::RAS: aMimeType = MIMETYPE_RAS; cType = graphic::GraphicType::PIXEL; break;
128 case GraphicFileFormat::TGA: aMimeType = MIMETYPE_TGA; cType = graphic::GraphicType::PIXEL; break;
129 case GraphicFileFormat::PSD: aMimeType = MIMETYPE_PSD; cType = graphic::GraphicType::PIXEL; break;
130 case GraphicFileFormat::WEBP: aMimeType = MIMETYPE_WEBP; cType = graphic::GraphicType::PIXEL; break;
131
132 case GraphicFileFormat::EPS: aMimeType = MIMETYPE_EPS; cType = graphic::GraphicType::VECTOR; break;
133 case GraphicFileFormat::DXF: aMimeType = MIMETYPE_DXF; cType = graphic::GraphicType::VECTOR; break;
134 case GraphicFileFormat::MET: aMimeType = MIMETYPE_MET; cType = graphic::GraphicType::VECTOR; break;
135 case GraphicFileFormat::PCT: aMimeType = MIMETYPE_PCT; cType = graphic::GraphicType::VECTOR; break;
136 case GraphicFileFormat::SVM: aMimeType = MIMETYPE_SVM; cType = graphic::GraphicType::VECTOR; break;
137 case GraphicFileFormat::WMF: aMimeType = MIMETYPE_WMF; cType = graphic::GraphicType::VECTOR; break;
138 case GraphicFileFormat::WMZ: aMimeType = MIMETYPE_WMF; cType = graphic::GraphicType::VECTOR; break;
139 case GraphicFileFormat::EMF: aMimeType = MIMETYPE_EMF; cType = graphic::GraphicType::VECTOR; break;
140 case GraphicFileFormat::EMZ: aMimeType = MIMETYPE_EMF; cType = graphic::GraphicType::VECTOR; break;
141 case GraphicFileFormat::SVG: aMimeType = MIMETYPE_SVG; cType = graphic::GraphicType::VECTOR; break;
142 case GraphicFileFormat::SVGZ: aMimeType = MIMETYPE_SVG; cType = graphic::GraphicType::VECTOR; break;
143
144 default:
145 break;
146 }
147
148 if( graphic::GraphicType::EMPTY != cType )
149 {
150 meType = ( ( graphic::GraphicType::PIXEL == cType ) ? GraphicType::Bitmap : GraphicType::GdiMetafile );
152 maSizePixel = aDescriptor.GetSizePixel();
153 maSize100thMM = aDescriptor.GetSize_100TH_MM();
154 mnBitsPerPixel = aDescriptor.GetBitsPerPixel();
155 mbTransparent = ( graphic::GraphicType::VECTOR == cType );
156 }
157}
158
159
161{
162 uno::Any aAny;
163
165 aAny <<= uno::Reference< lang::XServiceInfo >(this);
166 else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
167 aAny <<= uno::Reference< lang::XTypeProvider >(this);
168 else if( rType == cppu::UnoType<beans::XPropertySet>::get())
169 aAny <<= uno::Reference< beans::XPropertySet >(this);
171 aAny <<= uno::Reference< beans::XPropertyState >(this);
173 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
174 else
175 aAny = OWeakObject::queryInterface( rType );
176
177 return aAny;
178}
179
180
182 noexcept
183{
184 OWeakObject::acquire();
185}
186
187
189 noexcept
190{
191 OWeakObject::release();
192}
193
194
196{
197 return "com.sun.star.comp.graphic.GraphicDescriptor";
198}
199
200sal_Bool SAL_CALL GraphicDescriptor::supportsService( const OUString& ServiceName )
201{
203}
204
205
206uno::Sequence< OUString > SAL_CALL GraphicDescriptor::getSupportedServiceNames()
207{
208 return { "com.sun.star.graphic.GraphicDescriptor" };
209}
210
211
212uno::Sequence< uno::Type > SAL_CALL GraphicDescriptor::getTypes()
213{
214 static const uno::Sequence< uno::Type > aTypes {
221 return aTypes;
222}
223
224uno::Sequence< sal_Int8 > SAL_CALL GraphicDescriptor::getImplementationId()
225{
226 return css::uno::Sequence<sal_Int8>();
227}
228
229
231{
232 static ::comphelper::PropertyMapEntry const aEntries[] =
233 {
234 { OUString( "GraphicType" ), static_cast< sal_Int32 >( UnoGraphicProperty::GraphicType ), cppu::UnoType< sal_Int8 >::get(), beans::PropertyAttribute::READONLY, 0 },
235 { OUString( "MimeType" ), static_cast< sal_Int32 >( UnoGraphicProperty::MimeType ), cppu::UnoType< OUString >::get(), beans::PropertyAttribute::READONLY, 0 },
236 { OUString( "SizePixel" ), static_cast< sal_Int32 >( UnoGraphicProperty::SizePixel ), cppu::UnoType< awt::Size >::get(), beans::PropertyAttribute::READONLY, 0 },
237 { OUString( "Size100thMM" ), static_cast< sal_Int32 >( UnoGraphicProperty::Size100thMM ), cppu::UnoType< awt::Size >::get(), beans::PropertyAttribute::READONLY, 0 },
238 { OUString( "BitsPerPixel" ), static_cast< sal_Int32 >( UnoGraphicProperty::BitsPerPixel ), cppu::UnoType< sal_uInt8 >::get(), beans::PropertyAttribute::READONLY, 0 },
239 { OUString( "Transparent" ), static_cast< sal_Int32 >( UnoGraphicProperty::Transparent ), cppu::UnoType< sal_Bool >::get(), beans::PropertyAttribute::READONLY, 0 },
240 { OUString( "Alpha" ), static_cast< sal_Int32 >( UnoGraphicProperty::Alpha ), cppu::UnoType< sal_Bool >::get(), beans::PropertyAttribute::READONLY, 0 },
241 { OUString( "Animated" ), static_cast< sal_Int32 >( UnoGraphicProperty::Animated ), cppu::UnoType< sal_Bool >::get(), beans::PropertyAttribute::READONLY, 0 },
242 { OUString("Linked"), sal_Int32(UnoGraphicProperty::Linked), cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY, 0 },
243 { OUString("OriginURL"), sal_Int32(UnoGraphicProperty::OriginURL), cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
244 };
245
246 return rtl::Reference<::comphelper::PropertySetInfo>( new ::comphelper::PropertySetInfo(aEntries) );
247}
248
249
250void GraphicDescriptor::_setPropertyValues( const comphelper::PropertyMapEntry** /*ppEntries*/, const uno::Any* /*pValues*/ )
251{
252 // we only have readonly attributes
253}
254
255
257{
258 SolarMutexGuard aGuard;
259
260 while( *ppEntries )
261 {
262 UnoGraphicProperty theProperty = static_cast< UnoGraphicProperty >( (*ppEntries)->mnHandle );
263 switch( theProperty )
264 {
266 {
267 const GraphicType eType( mpGraphic ? mpGraphic->GetType() : meType );
268
269 *pValues <<= ( eType == GraphicType::Bitmap ? graphic::GraphicType::PIXEL :
270 ( eType == GraphicType::GdiMetafile ? graphic::GraphicType::VECTOR :
271 graphic::GraphicType::EMPTY ) );
272 }
273 break;
274
275 case UnoGraphicProperty::MimeType:
276 {
277 OUString aMimeType;
278
279 if( mpGraphic )
280 {
281 if( mpGraphic->IsGfxLink() )
282 {
283 GfxLink aLink = mpGraphic->GetGfxLink();
284 switch (aLink.GetType())
285 {
287
288 // #i15508# added BMP type for better exports (checked, works)
290
294 case GfxLinkType::NativeWmf: aMimeType = aLink.IsEMF() ? OUString(MIMETYPE_EMF) : OUString(MIMETYPE_WMF); break;
298
299 // added Svg mimetype support
302
303 default:
304 break;
305 }
306 }
307
308 if( aMimeType.isEmpty() && ( mpGraphic->GetType() != GraphicType::NONE ) )
310 }
311 else
313
314 *pValues <<= aMimeType;
315 }
316 break;
317
318 case UnoGraphicProperty::SizePixel:
319 {
320 awt::Size aAWTSize( 0, 0 );
321
322 if( mpGraphic )
323 {
324 if( mpGraphic->GetType() == GraphicType::Bitmap )
325 {
326 const Size aSizePix( mpGraphic->GetSizePixel() );
327 aAWTSize = awt::Size( aSizePix.Width(), aSizePix.Height() );
328 }
329 }
330 else
331 aAWTSize = awt::Size( maSizePixel.Width(), maSizePixel.Height() );
332
333 *pValues <<= aAWTSize;
334 }
335 break;
336
337 case UnoGraphicProperty::Size100thMM:
338 {
339 awt::Size aAWTSize( 0, 0 );
340
341 if( mpGraphic )
342 {
343 if( mpGraphic->GetPrefMapMode().GetMapUnit() != MapUnit::MapPixel )
344 {
345 const Size aSizeLog( OutputDevice::LogicToLogic(
346 mpGraphic->GetPrefSize(),
347 mpGraphic->GetPrefMapMode(),
348 MapMode(MapUnit::Map100thMM)) );
349 aAWTSize = awt::Size( aSizeLog.Width(), aSizeLog.Height() );
350 }
351 }
352 else
353 aAWTSize = awt::Size( maSize100thMM.Width(), maSize100thMM.Height() );
354
355 *pValues <<= aAWTSize;
356 }
357 break;
358
359 case UnoGraphicProperty::BitsPerPixel:
360 {
361 sal_uInt16 nBitsPerPixel = 0;
362
363 if( mpGraphic )
364 {
365 if( mpGraphic->GetType() == GraphicType::Bitmap )
366 {
367 auto ePixelFormat = mpGraphic->GetBitmapEx().GetBitmap().getPixelFormat();
368 nBitsPerPixel = vcl::pixelFormatBitCount(ePixelFormat);
369 }
370 }
371 else
372 nBitsPerPixel = mnBitsPerPixel;
373
374 *pValues <<= sal::static_int_cast< sal_Int8 >(nBitsPerPixel);
375 }
376 break;
377
378 case UnoGraphicProperty::Transparent:
379 {
380 *pValues <<= mpGraphic ? mpGraphic->IsTransparent() : mbTransparent;
381 }
382 break;
383
384 case UnoGraphicProperty::Alpha:
385 {
386 *pValues <<= mpGraphic && mpGraphic->IsAlpha();
387 }
388 break;
389
390 case UnoGraphicProperty::Animated:
391 {
392 *pValues <<= mpGraphic && mpGraphic->IsAnimated();
393 }
394 break;
395
396 case UnoGraphicProperty::Linked:
397 {
398 *pValues <<= mpGraphic && !mpGraphic->getOriginURL().isEmpty();
399 }
400 break;
401
402 case UnoGraphicProperty::OriginURL:
403 {
404 OUString aOriginURL;
405 if (mpGraphic)
406 aOriginURL = mpGraphic->getOriginURL();
407
408 *pValues <<= aOriginURL;
409 }
410 break;
411 }
412
413 ++ppEntries;
414 ++pValues;
415 }
416}
417
418}
419
420/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
constexpr OUStringLiteral MIMETYPE_MET
constexpr OUStringLiteral MIMETYPE_TIF
constexpr OUStringLiteral MIMETYPE_EPS
constexpr OUStringLiteral MIMETYPE_JPG
constexpr OUStringLiteral MIMETYPE_XPM
constexpr OUStringLiteral MIMETYPE_PDF
constexpr OUStringLiteral MIMETYPE_DXF
constexpr OUStringLiteral MIMETYPE_SVG
constexpr OUStringLiteral MIMETYPE_WMF
constexpr OUStringLiteral MIMETYPE_WEBP
constexpr OUStringLiteral MIMETYPE_TGA
constexpr OUStringLiteral MIMETYPE_RAS
constexpr OUStringLiteral MIMETYPE_PNG
constexpr OUStringLiteral MIMETYPE_XBM
constexpr OUStringLiteral MIMETYPE_VCLGRAPHIC
constexpr OUStringLiteral MIMETYPE_PCX
constexpr OUStringLiteral MIMETYPE_PBM
constexpr OUStringLiteral MIMETYPE_PSD
constexpr OUStringLiteral MIMETYPE_PGM
constexpr OUStringLiteral MIMETYPE_EMF
constexpr OUStringLiteral MIMETYPE_PCD
constexpr OUStringLiteral MIMETYPE_PPM
constexpr OUStringLiteral MIMETYPE_BMP
constexpr OUStringLiteral MIMETYPE_GIF
constexpr OUStringLiteral MIMETYPE_PCT
constexpr OUStringLiteral MIMETYPE_SVM
sal_uInt16 GetBitsPerPixel() const
bool Detect(bool bExtendedInfo=false)
starts the detection
const Size & GetSize_100TH_MM() const
GraphicFileFormat GetFileFormat() const
const Size & GetSizePixel() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
Definition: map.cxx:1580
constexpr tools::Long Height() const
constexpr tools::Long Width() const
css::uno::Type const & get()
virtual void _setPropertyValues(const comphelper::PropertyMapEntry **ppEntries, const css::uno::Any *pValues) override
static rtl::Reference<::comphelper::PropertySetInfo > createPropertySetInfo()
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual void SAL_CALL release() noexcept override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual ~GraphicDescriptor() noexcept override
void init(const ::Graphic &rGraphic)
virtual void _getPropertyValues(const comphelper::PropertyMapEntry **ppEntries, css::uno::Any *pValue) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL acquire() noexcept override
void implCreate(SvStream &rIStm, const OUString *pPath)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
URL aURL
ScXMLEditAttributeMap::Entry const aEntries[]
DocumentType eType
GraphicType
Definition: graph.hxx:35
NONE
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr sal_uInt16 pixelFormatBitCount(PixelFormat ePixelFormat)
Definition: BitmapTypes.hxx:34
const sal_Unicode *const aMimeType[]
unsigned char sal_uInt8
unsigned char sal_Bool
RedlineType meType
const SvXMLTokenMapEntry aTypes[]