filters

magickexport.cpp

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 #include <magickexport.h>
00020 #include <kgenericfactory.h>
00021 #include <KoDocument.h>
00022 #include <KoFilterChain.h>
00023 
00024 #include <kis_doc.h>
00025 #include <kis_paint_layer.h>
00026 #include <kis_image.h>
00027 #include <kis_annotation.h>
00028 #include <kis_types.h>
00029 #include <kis_image_magick_converter.h>
00030 
00031 typedef KGenericFactory<MagickExport, KoFilter> MagickExportFactory;
00032 K_EXPORT_COMPONENT_FACTORY(libkritamagickexport, MagickExportFactory("kofficefilters"))
00033 
00034 MagickExport::MagickExport(KoFilter *, const char *, const QStringList&) : KoFilter()
00035 {
00036 }
00037 
00038 MagickExport::~MagickExport()
00039 {
00040 }
00041 
00042 KoFilter::ConversionStatus MagickExport::convert(const QCString& from, const QCString& to)
00043 {
00044     kdDebug(41008) << "magick export! From: " << from << ", To: " << to << "\n";
00045     
00046     if (from != "application/x-krita")
00047         return KoFilter::NotImplemented;
00048 
00049     // XXX: Add dialog about flattening layers here
00050 
00051     KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
00052     QString filename = m_chain->outputFile();
00053     
00054     if (!output)
00055         return KoFilter::CreationError;
00056     
00057     if (filename.isEmpty()) return KoFilter::FileNotFound;
00058 
00059     KURL url;
00060     url.setPath(filename);
00061 
00062     KisImageSP img = output->currentImage();
00063 
00064     KisImageMagickConverter ib(output, output->undoAdapter());
00065 
00066     KisPaintDeviceSP pd = new KisPaintDevice(*img->projection());
00067     KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
00068     
00069     vKisAnnotationSP_it beginIt = img->beginAnnotations();
00070     vKisAnnotationSP_it endIt = img->endAnnotations();
00071     if (ib.buildFile(url, l, beginIt, endIt) == KisImageBuilder_RESULT_OK) {
00072         return KoFilter::OK;
00073     }
00074     return KoFilter::InternalError;
00075 }
00076 
00077 #include <magickexport.moc>
00078 
KDE Home | KDE Accessibility Home | Description of Access Keys