filters
pixmapFrame.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qdir.h>
00023 #include <kdebug.h>
00024 #include <config.h>
00025
00026 #ifdef HAVE_MAGICK
00027 # include <stdio.h>
00028 # include <time.h>
00029 # include <sys/types.h>
00030 # include <magick/api.h>
00031 #endif
00032
00033 #include "document.h"
00034 #include "pixmapFrame.h"
00035 #include "fileheader.h"
00036
00037
00038
00039
00040 PixmapFrame::PixmapFrame()
00041 {
00042 }
00043
00044
00045
00046
00047 PixmapFrame::~PixmapFrame()
00048 {
00049 kdDebug(30522) << "Destruction of a pixmap" << endl;
00050 }
00051 void PixmapFrame::setKeepAspectRatio(const QString ratio)
00052 {
00053 if(ratio == "true")
00054 _keepAspectRatio = true;
00055 else
00056 _keepAspectRatio = false;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 void PixmapFrame::analyse(const QDomNode balise)
00066 {
00067
00068
00069
00070 Element::analyse(balise);
00071
00072 kdDebug(30522) << "FRAME ANALYSE (Pixmap)" << endl;
00073
00074
00075 for(int index = 0; index < getNbChild(balise); index++)
00076 {
00077 if(getChildName(balise, index).compare("FRAME")== 0)
00078 {
00079 analyseParamFrame(balise);
00080 }
00081 else if(getChildName(balise, index).compare("PICTURE")== 0)
00082 {
00083 getPixmap(getChild(balise, "PICTURE"));
00084 }
00085
00086 }
00087 kdDebug(30522) << "END OF A FRAME" << endl;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 void PixmapFrame::getPixmap(const QDomNode balise_initiale)
00097 {
00098 kdDebug(30522) << "PIXMAP" << endl;
00099 setKeepAspectRatio(getAttr(balise_initiale, "keepAspectRatio"));
00100 QDomNode balise = getChild(balise_initiale, "KEY");
00101 setKey(getAttr(balise, "filename"));
00102 FileHeader::instance()->useGraphics();
00103 QString file = getKey();
00104
00105 int posExt = file.findRev('.');
00106 file.truncate(posExt);
00107
00108 file = file.section('/', -1);
00109 setFilenamePS(file + ".eps");
00110 kdDebug(30522) << "PS : " << getFilenamePS() << endl;
00111 kdDebug(30522) << "END PIXMAP" << endl;
00112 }
00113
00114
00115
00116
00117 void PixmapFrame::analyseParamFrame(const QDomNode balise)
00118 {
00119
00120
00121 _left = getAttr(balise, "left").toInt();
00122 _top = getAttr(balise, "top").toInt();
00123 _right = getAttr(balise, "right").toInt();
00124 _bottom = getAttr(balise, "bottom").toInt();
00125 setRunAround(getAttr(balise, "runaround").toInt());
00126 setAroundGap(getAttr(balise, "runaroundGap").toInt());
00127 setAutoCreate(getAttr(balise, "autoCreateNewFrame").toInt());
00128 setNewFrame(getAttr(balise, "newFrameBehaviour").toInt());
00129 setSheetSide(getAttr(balise, "sheetside").toInt());
00130 }
00131
00135 void PixmapFrame::convert()
00136 {
00137 #ifdef HAVE_MAGICK
00138 kdDebug(30522) << "CONVERT PICTURE IN EPS" << endl;
00139 ExceptionInfo exception;
00140
00141 Image* image;
00142
00143 ImageInfo
00144 *image_info;
00145
00146
00147
00148
00149 InitializeMagick(NULL);
00150 GetExceptionInfo(&exception);
00151 image_info = CloneImageInfo((ImageInfo *) NULL);
00152
00153 QString filename = "file:///" + getRoot()->extractData(getKey());
00154 strncpy(image_info->filename, filename.latin1(), filename.length());
00155 image = ReadImage(image_info, &exception);
00156 if (image == (Image *) NULL)
00157 MagickError(exception.severity, exception.reason, exception.description);
00158 else
00159 {
00160
00161
00162
00163
00164 QString dir = "";
00165 if( Config::instance()->getPicturesDir().isEmpty() ||
00166 Config::instance()->getPicturesDir() == NULL)
00167 {
00168 dir = getFilename();
00169 dir.truncate(getFilename().findRev('/'));
00170 }
00171 else
00172 dir = Config::instance()->getPicturesDir();
00173 kdDebug(30522) << "file " << getFilename() << endl;
00174 kdDebug(30522) << "path " << dir << endl;
00175 (void) strcpy(image->filename, (dir + "/" + getFilenamePS()).latin1());
00176 WriteImage(image_info, image);
00177 DestroyImage(image);
00178 }
00179 DestroyImageInfo(image_info);
00180 DestroyExceptionInfo(&exception);
00181 DestroyMagick();
00182 kdDebug(30522) << "CONVERTION DONE" << endl;
00183 #endif
00184 }
00185
00186
00187
00188
00189
00190
00191 void PixmapFrame::generate(QTextStream &out)
00192 {
00193 if(Config::instance()->convertPictures())
00194 convert();
00195
00196 Config::instance()->writeIndent(out);
00197 out << "\\includegraphics{" << getFilenamePS()<< "}" << endl;
00198
00199 }
00200
|