Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/LibreOffice/starmath/source/   (Office von Apache Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 4 kB image not shown  

Quelle  smdetect.cxx   Sprache: 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 <com/sun/star/ucb/ContentCreationException.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <sfx2/docfile.hxx>
#include <unotools/mediadescriptor.hxx>
#include <sot/storage.hxx>
#include <comphelper/diagnose_ex.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()
{
}

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
    {
        rtl::Reference<SotStorage> aStorage = new SotStorage(pInStrm, false);
        bStorageOk = !aStorage->GetError();
        if (bStorageOk)
        {
            if ( aStorage->IsStream(u"Equation Native"_ustr) )
            {
                sal_uInt8 nVersion;
                if ( GetMathTypeVersion( aStorage.get(), nVersion ) && nVersion <=3 )
                    return u"math_MathType_3x"_ustr;
            }
        }
    }
    catch (const css::ucb::ContentCreationException &)
    {
        TOOLS_WARN_EXCEPTION("starmath""SmFilterDetect::detect caught" );
    }

    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( ", aBuffer, 5))
                bIsMathType = (strstr( aBuffer, "" ) ||
                               strstr( aBuffer, " ) ||
                               strstr( aBuffer, " ));
            else
                // this is the old <math tag to MathML in the beginning of the XML file
                bIsMathType = (0 == strncmp( ", aBuffer, 6) ||
                               0 == strncmp( " ", aBuffer, 7) ||
                               0 == strncmp( " ", aBuffer, 12));

            if ( bIsMathType )
                return u"math_MathML_XML_Math"_ustr;
        }
    }

    return OUString();
}

/* XServiceInfo */
OUString SAL_CALL SmFilterDetect::getImplementationName()
{
    return u"com.sun.star.comp.math.FormatDetector"_ustr;
}

/* XServiceInfo */
sal_Bool SAL_CALL SmFilterDetect::supportsService( const OUString& sServiceName )
{
    return cppu::supportsService(this, sServiceName);
}

/* XServiceInfo */
Sequence< OUString > SAL_CALL SmFilterDetect::getSupportedServiceNames()
{
    return { u"com.sun.star.frame.ExtendedTypeDetection"_ustr };
}

extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
math_FormatDetector_get_implementation(uno::XComponentContext* /*pCtx*/,
                                       uno::Sequence<uno::Any> const/*rSeq*/)
{
    return cppu::acquire(new SmFilterDetect);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Messung V0.5
C=92 H=100 G=95

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.