The only effect SAL_CALL effectively has on LO-internal code is to change non-
static member functions from __thiscall to __cdecl in MSVC (where all other
functions are __cdecl by default, anyway). (For 3rd-party code, it could be
argued that SAL_CALL is useful on function declarations in the URE stable
interface other than non-static member functions, too, in case 3rd-party code
uses a compiler switch to change the default calling convention to something
other than __cdecl. But loplugin:salcall exempts the URE stable interface,
anyway.)
One could argue that SAL_CALL, even if today it effectively only affects non-
static member functions in MSVC, could be extended in the future to affect more
functions on more platforms. However, the current code would already not
support that. For example, 3af500580b
"loplugin:salcall fix functions" changed FrameControl_createInstance in
UnoControls/source/base/registercontrols.cxx to no longer be SAL_CALL, even
though its address (in ctl_component_getFacrory, in the same file) is passed to
cppuhelper::createSingleFactory as an argument of type
cppu::ComponentInstantiation, which is a pointer to SAL_CALL function.
Change-Id: I3acbf7314a3d7868ed70e35bb5c47bc11a0b7ff6
Reviewed-on: https://gerrit.libreoffice.org/46436
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
156 lines
5.1 KiB
C++
156 lines
5.1 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* This file incorporates work covered by the following license notice:
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
* with this work for additional information regarding copyright
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
* except in compliance with the License. You may obtain a copy of
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
*/
|
|
|
|
#include "smdetect.hxx"
|
|
#include <cppuhelper/supportsservice.hxx>
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
|
#include <sfx2/docfile.hxx>
|
|
#include <unotools/mediadescriptor.hxx>
|
|
|
|
#include "eqnolefilehdr.hxx"
|
|
|
|
using namespace ::com::sun::star;
|
|
using namespace ::com::sun::star::uno;
|
|
using namespace ::com::sun::star::io;
|
|
using namespace ::com::sun::star::task;
|
|
using namespace ::com::sun::star::beans;
|
|
using namespace ::com::sun::star::lang;
|
|
using utl::MediaDescriptor;
|
|
|
|
SmFilterDetect::SmFilterDetect( const Reference < XMultiServiceFactory >& /*xFactory*/ )
|
|
{
|
|
}
|
|
|
|
SmFilterDetect::~SmFilterDetect()
|
|
{
|
|
}
|
|
|
|
OUString SAL_CALL SmFilterDetect::detect( Sequence< PropertyValue >& lDescriptor )
|
|
{
|
|
MediaDescriptor aMediaDesc( lDescriptor );
|
|
uno::Reference< io::XInputStream > xInStream ( aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY );
|
|
if ( !xInStream.is() )
|
|
return OUString();
|
|
|
|
SfxMedium aMedium;
|
|
aMedium.UseInteractionHandler( false );
|
|
aMedium.setStreamToLoadFrom( xInStream, true );
|
|
|
|
SvStream *pInStrm = aMedium.GetInStream();
|
|
if ( !pInStrm || pInStrm->GetError() )
|
|
return OUString();
|
|
|
|
// Do not attempt to create an SotStorage on a
|
|
// 0-length stream as that would create the compound
|
|
// document header on the stream and effectively write to
|
|
// disk!
|
|
pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
|
|
if ( pInStrm->remainingSize() == 0 )
|
|
return OUString();
|
|
|
|
bool bStorageOk = false;
|
|
try
|
|
{
|
|
tools::SvRef<SotStorage> aStorage = new SotStorage( pInStrm, false );
|
|
bStorageOk = !aStorage->GetError();
|
|
if (bStorageOk)
|
|
{
|
|
if ( aStorage->IsStream("Equation Native") )
|
|
{
|
|
sal_uInt8 nVersion;
|
|
if ( GetMathTypeVersion( aStorage.get(), nVersion ) && nVersion <=3 )
|
|
return OUString("math_MathType_3x");
|
|
}
|
|
}
|
|
}
|
|
catch (const css::ucb::ContentCreationException &e)
|
|
{
|
|
SAL_WARN("starmath", "SmFilterDetect::detect caught " << e);
|
|
}
|
|
|
|
if (!bStorageOk)
|
|
{
|
|
// 200 should be enough for the XML
|
|
// version, encoding and !DOCTYPE
|
|
// stuff I hope?
|
|
static const sal_uInt16 nBufferSize = 200;
|
|
char aBuffer[nBufferSize+1];
|
|
pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
|
|
pInStrm->StartReadingUnicodeText( RTL_TEXTENCODING_DONTKNOW ); // avoid BOM marker
|
|
auto nBytesRead = pInStrm->ReadBytes( aBuffer, nBufferSize );
|
|
if (nBytesRead >= 6)
|
|
{
|
|
aBuffer[nBytesRead] = 0;
|
|
bool bIsMathType = false;
|
|
if (0 == strncmp( "<?xml", aBuffer, 5))
|
|
bIsMathType = (strstr( aBuffer, "<math>" ) ||
|
|
strstr( aBuffer, "<math " ) ||
|
|
strstr( aBuffer, "<math:math " ));
|
|
else
|
|
// this is the old <math tag to MathML in the beginning of the XML file
|
|
bIsMathType = (0 == strncmp( "<math ", aBuffer, 6) ||
|
|
0 == strncmp( "<math> ", aBuffer, 7) ||
|
|
0 == strncmp( "<math:math> ", aBuffer, 12));
|
|
|
|
if ( bIsMathType )
|
|
return OUString("math_MathML_XML_Math");
|
|
}
|
|
}
|
|
|
|
return OUString();
|
|
}
|
|
|
|
/* XServiceInfo */
|
|
OUString SAL_CALL SmFilterDetect::getImplementationName()
|
|
{
|
|
return impl_getStaticImplementationName();
|
|
}
|
|
|
|
/* XServiceInfo */
|
|
sal_Bool SAL_CALL SmFilterDetect::supportsService( const OUString& sServiceName )
|
|
{
|
|
return cppu::supportsService(this, sServiceName);
|
|
}
|
|
|
|
/* XServiceInfo */
|
|
Sequence< OUString > SAL_CALL SmFilterDetect::getSupportedServiceNames()
|
|
{
|
|
return impl_getStaticSupportedServiceNames();
|
|
}
|
|
|
|
/* Helper for XServiceInfo */
|
|
Sequence< OUString > SmFilterDetect::impl_getStaticSupportedServiceNames()
|
|
{
|
|
return Sequence< OUString >{ "com.sun.star.frame.ExtendedTypeDetection" };
|
|
}
|
|
|
|
/* Helper for XServiceInfo */
|
|
OUString SmFilterDetect::impl_getStaticImplementationName()
|
|
{
|
|
return OUString("com.sun.star.comp.math.FormatDetector");
|
|
}
|
|
|
|
/* Helper for registry */
|
|
Reference< XInterface > SmFilterDetect::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager )
|
|
{
|
|
return Reference< XInterface >( *new SmFilterDetect( xServiceManager ) );
|
|
}
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|