54 if (!
d.exists()) {
err(
"Output dir %s does not exist!\n",path); exit(1); }
66 bool formulaError=
FALSE;
71 t <<
"\\documentclass{article}" <<
endl;
72 t <<
"\\usepackage{epsfig}" <<
endl;
76 t <<
"\\usepackage{" << s <<
"}\n";
79 t <<
"\\pagestyle{empty}" <<
endl;
80 t <<
"\\begin{document}" <<
endl;
82 for (fli.toFirst();(formula=fli.current());++fli)
92 pagesToGenerate.
append(
new int(page));
97 t <<
"\\end{document}" <<
endl;
100 if (pagesToGenerate.
count()>0)
105 if (latexCmd.
isEmpty()) latexCmd=
"latex";
109 err(
"Problems running latex. Check your installation or look " 110 "for typos in _formulas.tex and check _formulas.log!\n");
119 for (;(pagePtr=pli.current());++pli,++pageIndex)
121 int pageNum=*pagePtr;
122 msg(
"Generating image form_%d.png for formula\n",pageNum);
125 formBase.
sprintf(
"_form%d",pageNum);
128 sprintf(dviArgs,
"-q -D 600 -E -n 1 -p %d -o %s.eps _formulas.dvi",
129 pageIndex,formBase.
data());
133 err(
"Problems running dvips. Check your installation!\n");
144 int i=eps.
find(
"%%BoundingBox:");
147 sscanf(eps.
data()+i,
"%%%%BoundingBox:%d %d %d %d",&
x1,&y1,&
x2,&y2);
151 err(
"Couldn't extract bounding box!\n");
156 f.setName(formBase+
".ps");
160 t <<
"1 1 1 setrgbcolor" <<
endl;
161 t <<
"newpath" <<
endl;
162 t <<
"-1 -1 moveto" <<
endl;
163 t << (x2-x1+2) <<
" -1 lineto" << endl;
164 t << (x2-x1+2) <<
" " << (y2-y1+2) <<
" lineto" <<
endl;
165 t <<
"-1 " << (y2-y1+2) <<
" lineto" <<endl;
166 t <<
"closepath" <<
endl;
168 t << -x1 <<
" " << -y1 <<
" translate" <<
endl;
169 t <<
"0 0 0 setrgbcolor" <<
endl;
170 t <<
"(" << formBase <<
".eps) run" <<
endl;
175 double scaleFactor = 16.0/3.0;
177 if (zoomFactor<8 || zoomFactor>50) zoomFactor=10;
178 scaleFactor *= zoomFactor/10.0;
179 int gx = (((
int)((x2-x1)*scaleFactor))+3)&~1;
180 int gy = (((
int)((y2-y1)*scaleFactor))+3)&~1;
186 sprintf(gsArgs,
"-q -g%dx%d -r%dx%dx -sDEVICE=ppmraw " 187 "-sOutputFile=%s.pnm -dNOPAUSE -dBATCH -- %s.ps",
188 gx,gy,(
int)(scaleFactor*72),(
int)(scaleFactor*72),
200 f.setName(formBase+
".pnm");
201 uint imageX=0,imageY=0;
208 s=
t.readLine().utf8();
210 err(
"ghostscript produced an illegal image format!");
215 while (!
t.eof() && (s=
t.readLine().utf8()) && !s.
isEmpty() && s.
at(0)==
'#') { }
216 sscanf(s,
"%d %d",&imageX,&imageY);
218 if (imageX>0 && imageY>0)
221 char *
data =
new char[imageX*imageY*3];
223 f.readBlock(data,imageX*imageY*3);
224 Image srcImage(imageX,imageY),
225 filteredImage(imageX,imageY),
226 dstImage(imageX/4,imageY/4);
229 for (i=0;i<imageX*imageY;i++) *ps++= (data[i*3]==0 ? 1 : 0);
231 static int filterMask[]={1,2,1,2,8,2,1,2,1};
232 for (y=0;y<srcImage.getHeight();y++)
234 for (x=0;x<srcImage.getWidth();x++)
241 s+=srcImage.getPixel(x+ix-1,y+iy-1)*filterMask[iy*3+ix];
244 filteredImage.setPixel(x,y,s);
250 for (y=0;y<dstImage.getHeight();y++)
252 for (x=0;x<dstImage.getWidth();x++)
256 int c=filteredImage.getPixel(xp+0,yp+0)+
257 filteredImage.getPixel(xp+1,yp+0)+
258 filteredImage.getPixel(xp+2,yp+0)+
259 filteredImage.getPixel(xp+3,yp+0)+
260 filteredImage.getPixel(xp+0,yp+1)+
261 filteredImage.getPixel(xp+1,yp+1)+
262 filteredImage.getPixel(xp+2,yp+1)+
263 filteredImage.getPixel(xp+3,yp+1)+
264 filteredImage.getPixel(xp+0,yp+2)+
265 filteredImage.getPixel(xp+1,yp+2)+
266 filteredImage.getPixel(xp+2,yp+2)+
267 filteredImage.getPixel(xp+3,yp+2)+
268 filteredImage.getPixel(xp+0,yp+3)+
269 filteredImage.getPixel(xp+1,yp+3)+
270 filteredImage.getPixel(xp+2,yp+3)+
271 filteredImage.getPixel(xp+3,yp+3);
274 dstImage.setPixel(x,y,
QMIN(15,(c*15)/(16*10)));
279 resultName.
sprintf(
"form_%d.png",pageNum);
282 dstImage.save(resultName,1);
288 thisDir.remove(formBase+
".eps");
289 thisDir.remove(formBase+
".pnm");
290 thisDir.remove(formBase+
".ps");
293 thisDir.remove(
"_formulas.dvi");
294 if (!formulaError) thisDir.remove(
"_formulas.log");
295 thisDir.remove(
"_formulas.aux");
298 if (!formulaError) thisDir.remove(
"_formulas.tex");
303 f.setName(
"formula.repository");
307 for (fli.toFirst();(formula=fli.current());++fli)
Traverses directory structures and contents in a platform-independent way.
void portable_sysTimerStop()
QCString fileToString(const char *name, bool filter, bool isSourceCode)
void msg(const char *fmt,...)
void append(const type *d)
#define Config_getList(val)
QCString left(uint len) const
Simplified and optimized version of QTextStream.
const char * portable_ghostScriptCommand()
int find(char c, int index=0, bool cs=TRUE) const
void portable_sysTimerStart()
#define Config_getInt(val)
static QString currentDirPath()
const char * data() const
void addImageFile(const char *name)
#define Config_getString(val)
#define Config_getBool(val)
static constexpr double ps
void err(const char *fmt,...)
The QFile class is an I/O device that operates on files.
QCString & sprintf(const char *format,...)
The QTextStream class provides basic functions for reading and writing text using a QIODevice...
The QFileInfo class provides system-independent file information.
void setAutoDelete(bool enable)
static IndexList * indexList
static bool setCurrent(const QString &path)
QTextStream & endl(QTextStream &s)
int portable_system(const char *command, const char *args, bool commandHasConsole)