wmfimport.cpp
1/*
2 Copyright (C) 2000, S.R.Haque <shaheedhaque@hotmail.com>.
3 This file is part of the KDE project
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19
20DESCRIPTION
21*/
22
23#include <config.h>
24#include <tqdom.h>
25#include <tqcstring.h>
26#include <kdebug.h>
27#include <kgenericfactory.h>
28#include <KoFilterChain.h>
29#include <KoStoreDevice.h>
30#include <core/vdocument.h>
31
32#include "wmfimport.h"
33#include "wmfimportparser.h"
34
35typedef KGenericFactory<WMFImport, KoFilter> WMFImportFactory;
36K_EXPORT_COMPONENT_FACTORY( libwmfimport, WMFImportFactory( "kofficefilters" ) )
37
38
39WMFImport::WMFImport( KoFilter *, const char *, const TQStringList&) :
40 KoFilter()
41{
42}
43
44WMFImport::~WMFImport()
45{
46}
47
48KoFilter::ConversionStatus WMFImport::convert( const TQCString& from, const TQCString& to )
49{
50 if( to != "application/x-karbon" || from != "image/x-wmf" )
51 return KoFilter::NotImplemented;
52
53 WMFImportParser wmfParser;
54 if( !wmfParser.load( m_chain->inputFile() ) ) {
55 return KoFilter::WrongFormat;
56 }
57
58 // Do the conversion!
59 VDocument document;
60 if (!wmfParser.play( document )) {
61 return KoFilter::WrongFormat;
62 }
63
64 KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write );
65 if( !out ) {
66 kdError(3800) << "Unable to open output file!" << endl;
67 return KoFilter::StorageCreationError;
68 }
69 TQDomDocument outdoc = document.saveXML();
70 TQCString content = outdoc.toCString();
71 // kdDebug() << " content : " << content << endl;
72 out->writeBlock( content , content.length() );
73
74 return KoFilter::OK;
75}
76
77
78#include <wmfimport.moc>
WMFImportParser inherit KoWmfRead and translate WMF functions.
bool play(VDocument &doc)
play WMF file on a VDocument.