magick/magickexport.cpp
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19#include <magickexport.h>
20#include <kgenericfactory.h>
21#include <KoDocument.h>
22#include <KoFilterChain.h>
23
24#include <kis_doc.h>
25#include <kis_paint_layer.h>
26#include <kis_image.h>
27#include <kis_annotation.h>
28#include <kis_types.h>
29#include <kis_image_magick_converter.h>
30
31typedef KGenericFactory<MagickExport, KoFilter> MagickExportFactory;
32K_EXPORT_COMPONENT_FACTORY(libchalkmagickexport, MagickExportFactory("kofficefilters"))
33
34MagickExport::MagickExport(KoFilter *, const char *, const TQStringList&) : KoFilter()
35{
36}
37
38MagickExport::~MagickExport()
39{
40}
41
42KoFilter::ConversionStatus MagickExport::convert(const TQCString& from, const TQCString& to)
43{
44 kdDebug(41008) << "magick export! From: " << from << ", To: " << to << "\n";
45
46 if (from != "application/x-chalk")
47 return KoFilter::NotImplemented;
48
49 // XXX: Add dialog about flattening layers here
50
51 KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
52 TQString filename = m_chain->outputFile();
53
54 if (!output)
55 return KoFilter::CreationError;
56
57 if (filename.isEmpty()) return KoFilter::FileNotFound;
58
59 KURL url;
60 url.setPath(filename);
61
62 KisImageSP img = output->currentImage();
63
64 KisImageMagickConverter ib(output, output->undoAdapter());
65
66 KisPaintDeviceSP pd = new KisPaintDevice(*img->projection());
67 KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
68
69 vKisAnnotationSP_it beginIt = img->beginAnnotations();
70 vKisAnnotationSP_it endIt = img->endAnnotations();
71 if (ib.buildFile(url, l, beginIt, endIt) == KisImageBuilder_RESULT_OK) {
72 return KoFilter::OK;
73 }
74 return KoFilter::InternalError;
75}
76
77#include <magickexport.moc>
78
Build a KisImage representation of an image file.