/* Copyright (C) 2000, S.R.Haque . This file is part of the KDE project This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. DESCRIPTION */ #include #include #include #include #include #include #include #include typedef KGenericFactory MSODImportFactory; K_EXPORT_COMPONENT_FACTORY( libmsodimport, MSODImportFactory( "kofficefilters" ) ) const int MSODImport::s_area = 30505; MSODImport::MSODImport( KoFilter *, const char *, const TQStringList&) : KoEmbeddingFilter(), Msod(100) { } MSODImport::~MSODImport() { } KoFilter::ConversionStatus MSODImport::convert( const TQCString& from, const TQCString& to ) { if (to != "application/x-karbon" || from != "image/x-msod") return KoFilter::NotImplemented; // Get configuration data: the shape id, and any delay stream that we were given. unsigned shapeId; emit commSignalShapeID( shapeId ); const char *delayStream = 0L; emit commSignalDelayStream( delayStream ); kdDebug( s_area ) << "##################################################################" << endl; kdDebug( s_area ) << "shape id: " << shapeId << endl; kdDebug( s_area ) << "delay stream: " << delayStream << endl; kdDebug( s_area ) << "##################################################################" << endl; /* TQString config = ""; // ###### FIXME: We aren't able to pass config data right now TQStringList args = TQStringList::split(";", config); unsigned i; kdDebug(s_area) << "MSODImport::filter: config: " << config << endl; for (i = 0; i < args.count(); i++) { if (args[i].startsWith("shape-id=")) { shapeId = args[i].mid(9).toUInt(); } else if (args[i].startsWith("delay-stream=")) { delayStream = (const char *)args[i].mid(13).toULong(); } else { kdError(s_area) << "Invalid argument: " << args[i] << endl; return KoFilter::StupidError; } } */ // doc header m_text = ""; m_text += "\n"; m_text += "\n"; m_text += "\n"; m_text += " \n"; if (!parse(shapeId, m_chain->inputFile(), delayStream)) return KoFilter::WrongFormat; // close doc m_text += " \n"; m_text += "\n"; emit sigProgress(100); KoStoreDevice* dev = m_chain->storageFile( "root", KoStore::Write ); if (!dev) { kdError(s_area) << "Cannot open output file" << endl; return KoFilter::StorageCreationError; } TQCString cstring ( m_text.utf8() ); dev->writeBlock(cstring.data(), cstring.size()-1); return KoFilter::OK; } void MSODImport::gotEllipse( const DrawContext &/*dc*/, TQString /*type*/, TQPoint /*topLeft*/, TQSize /*halfAxes*/, unsigned /*startAngle*/, unsigned /*stopAngle*/) { // ### TODO #if 0 m_text += "\n"; m_text += " \n"; m_text += " \n"; m_text += " \n"; m_text += "\n"; #endif } static void toRGB(int c, double &r, double &g, double &b) { r = (c >> 16) / 255.0; g = ((c >> 8) & 0xFF) / 255.0; b = (c & 0xFF) / 255.0; } void MSODImport::gotPicture( unsigned key, TQString extension, unsigned length, const char *data) { // ### TODO #if 0 kdDebug() << "##########################################MSODImport::gotPicture" << endl; kdDebug() << "MSODImport::gotPicture -- " << extension << endl; if ((extension == "wmf") || (extension == "emf") || (extension == "pict")) { int partRef = internalPartReference( TQString::number( key ) ); if (partRef == -1) { m_embeddeeData = data; m_embeddeeLength = length; TQString srcMime( KoEmbeddingFilter::mimeTypeByExtension( extension ) ); if ( srcMime == KMimeType::defaultMimeType() ) kdWarning( s_area ) << "Couldn't determine the mimetype from the extension" << endl; TQCString destMime; // intentionally empty, the filter manager will do the rest KoFilter::ConversionStatus status; partRef = embedPart( srcMime.latin1(), destMime, status, TQString::number( key ) ); m_embeddeeData = 0; m_embeddeeLength = 0; if ( status != KoFilter::OK ) { kdWarning(s_area) << "Couldn't convert the image!" << endl; return; } } m_text += "\n"; } else { // We could not import it as a part. Try as an image. KTempFile tempFile( TQString(), '.' + extension ); tempFile.file()->writeBlock( data, length ); tempFile.close(); m_text += "\n" " \n" " \n" " \n" "\n"; // Note that we cannot delete the file... } #endif } void MSODImport::gotPolygon( const DrawContext &dc, const TQPointArray &points) { kdDebug(s_area) << "MSODImport::gotPolygon" << endl; kdDebug(s_area) << TQString::number(dc.m_penWidth, 16) << endl; kdDebug(s_area) << dc.m_penStyle << endl; m_text += "\n"; if( dc.m_penWidth > 0 ) { m_text += "\n";// + TQString::number(dc.m_penWidth, 16) + "\">\n"; double r, g, b; toRGB(dc.m_penColour, r, g, b); m_text += "\n"; m_text += "\n"; } else m_text += "\n"; m_text += "\n"; double r, g, b; toRGB(dc.m_brushColour, r, g, b); m_text += "\n"; m_text += "\n"; m_text += "\n"; pointArray(points); m_text += "\n"; m_text += "\n"; } void MSODImport::gotPolyline( const DrawContext &dc, const TQPointArray &points) { kdDebug(s_area) << "MSODImport::gotPolyline" << endl; return; // ### TODO m_text += "\n"; m_text += "\n"; m_text += "\n"; m_text += "\n"; pointArray(points); m_text += "\n"; m_text += "\n"; } void MSODImport::gotRectangle( const DrawContext &dc, const TQPointArray &points) { // ### TODO #if 0 TQRect bounds = points.boundingRect(); m_text += "\n"; m_text += "\n"; pointArray(points); m_text += " \n"; m_text += " \n"; m_text += " \n"; m_text += "\n"; m_text += "\n"; #endif } void MSODImport::savePartContents( TQIODevice* file ) { if ( m_embeddeeData != 0 && m_embeddeeLength != 0 ) file->writeBlock( m_embeddeeData, m_embeddeeLength ); } void MSODImport::pointArray( const TQPointArray &points) { m_text += "\n"; kdDebug(s_area) << "\n" << endl; for (unsigned int i = 1; i < points.count(); i++) { m_text += "\n"; kdDebug(s_area) << "" << endl; } } #include