filters

pixmapFrame.cc

00001 /*
00002 ** A program to convert the XML rendered by KWord into LATEX.
00003 **
00004 ** Copyright (C) 2000, 2002 Robert JACOLIN
00005 **
00006 ** This library is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU Library General Public
00008 ** License as published by the Free Software Foundation; either
00009 ** version 2 of the License, or (at your option) any later version.
00010 **
00011 ** This library is distributed in the hope that it will be useful,
00012 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 ** Library General Public License for more details.
00015 **
00016 ** To receive a copy of the GNU Library General Public License, write to the
00017 ** Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 **
00020 */
00021 
00022 #include <qdir.h>
00023 #include <kdebug.h>     /* for kdDebug() stream */
00024 #include <config.h>
00025 /* Needed to convert picture in eps file. Use ImageMagick. */
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 /* Constructor                             */
00039 /*******************************************/
00040 PixmapFrame::PixmapFrame()
00041 {
00042 }
00043 
00044 /*******************************************/
00045 /* Destructor                              */
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 /* analyse                                 */
00061 /*******************************************/
00062 /* Get informations about a pixmap stored  */
00063 /* in the tared file.                      */
00064 /*******************************************/
00065 void PixmapFrame::analyse(const QDomNode balise)
00066 {
00067     /* MARKUP TYPE : FRAMESET INFO = TEXTE, ENTETE CONNUE */
00068 
00069     /* Parameters Analyse */
00070     Element::analyse(balise);
00071 
00072     kdDebug(30522) << "FRAME ANALYSE (Pixmap)" << endl;
00073 
00074     /* Chlidren markups Analyse */
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 /* getPixmap                               */
00092 /*******************************************/
00093 /* Get informations about a pixmap stored  */
00094 /* in the tared file.                      */
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     /* Remove the extension */
00105     int posExt = file.findRev('.');
00106     file.truncate(posExt);
00107     /* Remove the path */
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 /* analyseParamFrame                       */
00116 /*******************************************/
00117 void PixmapFrame::analyseParamFrame(const QDomNode balise)
00118 {
00119     /*<FRAME left="28" top="42" right="566" bottom="798" runaround="1" />*/
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         Initialize the image info structure and read an image.
00148     */
00149     InitializeMagick(NULL);
00150     GetExceptionInfo(&exception);
00151     image_info = CloneImageInfo((ImageInfo *) NULL);
00152     // 8 characters are deleted when readign the file picture name
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             Write the image as EPS and destroy it.
00162           Copy image file in the same directory than the tex file.
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 /* generate                                */
00188 /*******************************************/
00189 /* Generate the text formated (if needed). */
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 
KDE Home | KDE Accessibility Home | Description of Access Keys