/src/libreoffice/sd/source/ui/unoidl/sddetect.cxx
Line | Count | Source |
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 | | |
20 | | #include "sddetect.hxx" |
21 | | |
22 | | #include <com/sun/star/beans/PropertyValue.hpp> |
23 | | #include <cppuhelper/supportsservice.hxx> |
24 | | #include <com/sun/star/io/XInputStream.hpp> |
25 | | #include <com/sun/star/ucb/ContentCreationException.hpp> |
26 | | #include <com/sun/star/uno/XComponentContext.hpp> |
27 | | #include <rtl/ref.hxx> |
28 | | #include <vcl/graphicfilter.hxx> |
29 | | #include <sfx2/docfile.hxx> |
30 | | #include <sfx2/docfilt.hxx> |
31 | | #include <sfx2/fcontnr.hxx> |
32 | | #include <vcl/FilterConfigItem.hxx> |
33 | | #include <sot/storage.hxx> |
34 | | #include <comphelper/sequenceashashmap.hxx> |
35 | | #include <unotools/mediadescriptor.hxx> |
36 | | #include <tools/urlobj.hxx> |
37 | | |
38 | | using namespace ::com::sun::star; |
39 | | using namespace ::com::sun::star::uno; |
40 | | using namespace ::com::sun::star::io; |
41 | | using namespace ::com::sun::star::task; |
42 | | using namespace ::com::sun::star::beans; |
43 | | using namespace ::com::sun::star::lang; |
44 | | |
45 | | SdFilterDetect::SdFilterDetect() |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | SdFilterDetect::~SdFilterDetect() |
50 | 0 | { |
51 | 0 | } |
52 | | |
53 | | OUString SAL_CALL SdFilterDetect::detect( Sequence< beans::PropertyValue >& lDescriptor ) |
54 | 0 | { |
55 | 0 | comphelper::SequenceAsHashMap aMediaDesc(lDescriptor); |
56 | 0 | OUString aTypeName = aMediaDesc.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_TYPENAME, OUString() ); |
57 | 0 | uno::Reference< io::XInputStream > xInStream ( aMediaDesc[utl::MediaDescriptor::PROP_INPUTSTREAM], uno::UNO_QUERY ); |
58 | 0 | if ( !xInStream.is() ) |
59 | 0 | return OUString(); |
60 | | |
61 | 0 | SfxMedium aMedium; |
62 | 0 | aMedium.UseInteractionHandler( false ); |
63 | 0 | aMedium.setStreamToLoadFrom( xInStream, true ); |
64 | |
|
65 | 0 | SvStream *pInStrm = aMedium.GetInStream(); |
66 | 0 | if ( !pInStrm || pInStrm->GetError() ) |
67 | 0 | return OUString(); |
68 | | |
69 | 0 | if ( aTypeName.startsWith( "impress_MS_PowerPoint_97" ) ) |
70 | 0 | { |
71 | | // Do not attempt to create an SotStorage on a |
72 | | // 0-length stream as that would create the compound |
73 | | // document header on the stream and effectively write to |
74 | | // disk! |
75 | 0 | pInStrm->Seek( STREAM_SEEK_TO_BEGIN ); |
76 | 0 | if ( pInStrm->remainingSize() == 0 ) |
77 | 0 | return OUString(); |
78 | | |
79 | 0 | try |
80 | 0 | { |
81 | 0 | rtl::Reference<SotStorage> aStorage = new SotStorage(pInStrm, false); |
82 | 0 | if ( !aStorage->GetError() && aStorage->IsStream( u"PowerPoint Document"_ustr ) ) |
83 | 0 | return aTypeName; |
84 | 0 | } |
85 | 0 | catch (const css::ucb::ContentCreationException&) |
86 | 0 | { |
87 | 0 | } |
88 | 0 | } |
89 | 0 | else |
90 | 0 | { |
91 | 0 | pInStrm->Seek( STREAM_SEEK_TO_BEGIN ); |
92 | |
|
93 | 0 | const OUString aFileName( aMediaDesc.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_URL, OUString() ) ); |
94 | 0 | GraphicDescriptor aDesc( *pInStrm, &aFileName ); |
95 | 0 | if( !aDesc.Detect() ) |
96 | 0 | { |
97 | 0 | INetURLObject aCheckURL( aFileName ); |
98 | 0 | if( aCheckURL.getExtension().equalsIgnoreAsciiCase("cgm") ) |
99 | 0 | { |
100 | 0 | sal_uInt8 n8; |
101 | 0 | pInStrm->Seek( STREAM_SEEK_TO_BEGIN ); |
102 | 0 | pInStrm->ReadUChar( n8 ); |
103 | 0 | if ( ( n8 & 0xf0 ) == 0 ) |
104 | | // we are supporting binary cgm format only, so |
105 | | // this is a small test to exclude cgm text |
106 | 0 | return u"impress_CGM_Computer_Graphics_Metafile"_ustr; |
107 | 0 | } |
108 | 0 | } |
109 | 0 | else |
110 | 0 | { |
111 | 0 | OUString aShortName( GraphicDescriptor::GetImportFormatShortName( aDesc.GetFileFormat() ) ); |
112 | 0 | GraphicFilter &rGrfFilter = GraphicFilter::GetGraphicFilter(); |
113 | 0 | const OUString aName( rGrfFilter.GetImportFormatTypeName( rGrfFilter.GetImportFormatNumberForShortName( aShortName ) ) ); |
114 | |
|
115 | 0 | if ( aShortName.equalsIgnoreAsciiCase( "PCD" ) ) // there is a multiple pcd selection possible |
116 | 0 | { |
117 | 0 | sal_Int32 nBase = 2; // default Base0 |
118 | 0 | if ( aTypeName == "pcd_Photo_CD_Base4" ) |
119 | 0 | nBase = 1; |
120 | 0 | else if ( aTypeName == "pcd_Photo_CD_Base16" ) |
121 | 0 | nBase = 0; |
122 | 0 | FilterConfigItem aFilterConfigItem( u"Office.Common/Filter/Graphic/Import/PCD" ); |
123 | 0 | aFilterConfigItem.WriteInt32( u"Resolution"_ustr , nBase ); |
124 | 0 | } |
125 | |
|
126 | 0 | SfxFilterMatcher aMatch(u"sdraw"_ustr); |
127 | 0 | std::shared_ptr<const SfxFilter> pFilter = aMatch.GetFilter4FilterName( aName ); |
128 | 0 | if ( pFilter ) |
129 | 0 | return pFilter->GetRealTypeName(); |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | 0 | return OUString(); |
134 | 0 | } |
135 | | |
136 | | // XServiceInfo |
137 | | OUString SAL_CALL SdFilterDetect::getImplementationName() |
138 | 0 | { |
139 | 0 | return u"com.sun.star.comp.draw.FormatDetector"_ustr; |
140 | 0 | } |
141 | | |
142 | | // XServiceInfo |
143 | | sal_Bool SAL_CALL SdFilterDetect::supportsService( const OUString& sServiceName ) |
144 | 0 | { |
145 | 0 | return cppu::supportsService(this, sServiceName); |
146 | 0 | } |
147 | | |
148 | | // XServiceInfo |
149 | | Sequence< OUString > SAL_CALL SdFilterDetect::getSupportedServiceNames() |
150 | 0 | { |
151 | 0 | return { u"com.sun.star.frame.ExtendedTypeDetection"_ustr }; |
152 | 0 | } |
153 | | |
154 | | |
155 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
156 | | com_sun_star_comp_draw_FormatDetector_get_implementation(css::uno::XComponentContext*, |
157 | | css::uno::Sequence<css::uno::Any> const &) |
158 | 0 | { |
159 | 0 | return cppu::acquire(new SdFilterDetect()); |
160 | 0 | } |
161 | | |
162 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |