pixmapFrame.cpp
1/*
2** A program to convert the XML rendered by KWord into LATEX.
3**
4** Copyright (C) 2000, 2002 Robert JACOLIN
5**
6** This library is free software; you can redistribute it and/or
7** modify it under the terms of the GNU Library General Public
8** License as published by the Free Software Foundation; either
9** version 2 of the License, or (at your option) any later version.
10**
11** This library is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14** Library General Public License for more details.
15**
16** To receive a copy of the GNU Library General Public License, write to the
17** Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19**
20*/
21
22#include <tqdir.h>
23#include <kdebug.h> /* for kdDebug() stream */
24#include <config.h>
25/* Needed to convert picture in eps file. Use ImageMagick. */
26#ifdef HAVE_MAGICK
27# include <stdio.h>
28# include <time.h>
29# include <sys/types.h>
30# include <magick/api.h>
31#endif
32
33#include "document.h"
34#include "pixmapFrame.h"
35#include "fileheader.h"
36
37/*******************************************/
38/* Constructor */
39/*******************************************/
40PixmapFrame::PixmapFrame()
41{
42}
43
44/*******************************************/
45/* Destructor */
46/*******************************************/
47PixmapFrame::~PixmapFrame()
48{
49 kdDebug(30522) << "Destruction of a pixmap" << endl;
50}
51void PixmapFrame::setKeepAspectRatio(const TQString ratio)
52{
53 if(ratio == "true")
54 _keepAspectRatio = true;
55 else
56 _keepAspectRatio = false;
57}
58
59/*******************************************/
60/* analyse */
61/*******************************************/
62/* Get informations about a pixmap stored */
63/* in the tared file. */
64/*******************************************/
65void PixmapFrame::analyse(const TQDomNode balise)
66{
67 /* MARKUP TYPE : FRAMESET INFO = TEXTE, ENTETE CONNUE */
68
69 /* Parameters Analyse */
70 Element::analyse(balise);
71
72 kdDebug(30522) << "FRAME ANALYSE (Pixmap)" << endl;
73
74 /* Chlidren markups Analyse */
75 for(int index = 0; index < getNbChild(balise); index++)
76 {
77 if(getChildName(balise, index).compare("FRAME")== 0)
78 {
79 analyseParamFrame(balise);
80 }
81 else if(getChildName(balise, index).compare("PICTURE")== 0)
82 {
83 getPixmap(getChild(balise, "PICTURE"));
84 }
85
86 }
87 kdDebug(30522) << "END OF A FRAME" << endl;
88}
89
90/*******************************************/
91/* getPixmap */
92/*******************************************/
93/* Get informations about a pixmap stored */
94/* in the tared file. */
95/*******************************************/
96void PixmapFrame::getPixmap(const TQDomNode balise_initiale)
97{
98 kdDebug(30522) << "PIXMAP" << endl;
99 setKeepAspectRatio(getAttr(balise_initiale, "keepAspectRatio"));
100 TQDomNode balise = getChild(balise_initiale, "KEY");
101 setKey(getAttr(balise, "filename"));
102 FileHeader::instance()->useGraphics();
103 TQString file = getKey();
104 /* Remove the extension */
105 int posExt = file.findRev('.');
106 file.truncate(posExt);
107 /* Remove the path */
108 file = file.section('/', -1);
109 setFilenamePS(file + ".eps");
110 kdDebug(30522) << "PS : " << getFilenamePS() << endl;
111 kdDebug(30522) << "END PIXMAP" << endl;
112}
113
114/*******************************************/
115/* analyseParamFrame */
116/*******************************************/
117void PixmapFrame::analyseParamFrame(const TQDomNode balise)
118{
119 /*<FRAME left="28" top="42" right="566" bottom="798" runaround="1" />*/
120
121 _left = getAttr(balise, "left").toInt();
122 _top = getAttr(balise, "top").toInt();
123 _right = getAttr(balise, "right").toInt();
124 _bottom = getAttr(balise, "bottom").toInt();
125 setRunAround(getAttr(balise, "runaround").toInt());
126 setAroundGap(getAttr(balise, "runaroundGap").toInt());
127 setAutoCreate(getAttr(balise, "autoCreateNewFrame").toInt());
128 setNewFrame(getAttr(balise, "newFrameBehaviour").toInt());
129 setSheetSide(getAttr(balise, "sheetside").toInt());
130}
131
136{
137#ifdef HAVE_MAGICK
138 kdDebug(30522) << "CONVERT PICTURE IN EPS" << endl;
139 ExceptionInfo exception;
140
141 Image* image;
142
143 ImageInfo
144 *image_info;
145
146 /*
147 Initialize the image info structure and read an image.
148 */
149 InitializeMagick(NULL);
150 GetExceptionInfo(&exception);
151 image_info = CloneImageInfo((ImageInfo *) NULL);
152 // 8 characters are deleted when readign the file picture name
153 TQString filename = "file:///" + getRoot()->extractData(getKey());
154 strncpy(image_info->filename, filename.latin1(), filename.length());
155 image = ReadImage(image_info, &exception);
156 if (image == (Image *) NULL)
157 MagickError(exception.severity, exception.reason, exception.description);
158 else
159 {
160 /*
161 Write the image as EPS and destroy it.
162 Copy image file in the same directory than the tex file.
163 */
164 TQString dir = "";
165 if( Config::instance()->getPicturesDir().isEmpty() ||
166 Config::instance()->getPicturesDir() == NULL)
167 {
168 dir = getFilename();
169 dir.truncate(getFilename().findRev('/'));
170 }
171 else
172 dir = Config::instance()->getPicturesDir();
173 kdDebug(30522) << "file " << getFilename() << endl;
174 kdDebug(30522) << "path " << dir << endl;
175 (void) strcpy(image->filename, (dir + "/" + getFilenamePS()).latin1());
176 WriteImage(image_info, image);
177 DestroyImage(image);
178 }
179 DestroyImageInfo(image_info);
180 DestroyExceptionInfo(&exception);
181 DestroyMagick();
182 kdDebug(30522) << "CONVERTION DONE" << endl;
183#endif
184}
185
186/*******************************************/
187/* generate */
188/*******************************************/
189/* Generate the text formated (if needed). */
190/*******************************************/
191void PixmapFrame::generate(TQTextStream &out)
192{
193 if(Config::instance()->convertPictures())
194 convert();
195
196 Config::instance()->writeIndent(out);
197 out << "\\includegraphics{" << getFilenamePS()<< "}" << endl;
198
199}
200
TQString extractData(TQString key)
Save the file in a temp file.
virtual void analyse(const TQDomNode)
Helpfull functions.
void convert()
Convert a pixmap file in eps file.
void setRunAround(const int a)
Modifiers.
Definition pixmapFrame.h:78
void analyse(const TQDomNode)
Helpfull functions.