浏览该文件的文档.
38 #define RM_TMP_FILES (true)
73 std::ifstream f(dir.
str()+
"/formula.repository",std::ifstream::in);
77 msg(
"Reading formula repository...\n");
80 while (getline(f,line))
83 size_t hi=line.find(
'#');
84 size_t ei=line.find(
'=');
85 size_t se=line.find(
':');
86 if (ei==std::string::npos || hi==std::string::npos || se==std::string::npos || hi>se || ei<hi || ei>se)
88 warn_uncond(
"%s/formula.repository is corrupted at line %d!\n",
qPrint(dir),lineNr);
93 std::string formName = line.substr(0,se);
94 std::string formText = line.substr(se+1);
96 size_t xi=formName.find(
'x',ei);
97 if (xi!=std::string::npos)
99 w=std::stoi(formName.substr(ei+1,xi-ei-1));
100 h=std::stoi(formName.substr(xi+1));
102 formName = formName.substr(0,ei);
105 int formId = std::stoi(formName.substr(hi+1));
107 if (storedFormText!=formText)
109 term(
"discrepancy between formula repositories! Remove "
110 "formula.repository and from_* files from output directories.\n");
117 p->storeDisplaySize(
id,w,h);
122 if (doCompare && formulaCount!=
p->formulas.size())
124 term(
"size discrepancy between formula repositories! Remove "
125 "formula.repository and from_* files from output directories.\n");
136 term(
"Output directory '%s' does not exist!\n",
qPrint(path));
154 std::ofstream f(texName.
str(),std::ofstream::out | std::ofstream::binary);
158 t <<
"\\documentclass{article}\n";
159 t <<
"\\usepackage{ifthen}\n";
160 t <<
"\\usepackage{epsfig}\n";
161 t <<
"\\usepackage[utf8]{inputenc}\n";
167 t <<
"\\input{" << stripMacroFile <<
"}\n";
169 t <<
"\\pagestyle{empty}\n";
170 t <<
"\\begin{document}\n";
171 for (
int i=0; i<(int)
p->formulas.size(); i++)
180 t <<
p->formulas[i].c_str() <<
"\n\\pagebreak\n\n";
181 formulasToGenerate.push_back(i);
185 t <<
"\\end{document}\n";
189 if (!formulasToGenerate.empty())
201 err(
"Problems running latex. Check your installation or look "
202 "for typos in _formulas.tex and check _formulas.log!\n");
210 (logFile.
find(
"Rerun to get cross-references right")==-1 && logFile.
find(
"Rerun LaTeX")==-1))
219 for (
int pageNum : formulasToGenerate)
221 msg(
"Generating image form_%d.%s for formula\n",pageNum,(format==
Format::Vector) ?
"svg" :
"png");
223 formBase.
sprintf(
"_form%d",pageNum);
226 sprintf(args,
"-q -D 600 -n 1 -p %d -o %s_tmp.ps _formulas.dvi",
227 pageIndex,
qPrint(formBase));
231 err(
"Problems running dvips. Check your installation!\n");
239 sprintf(args,
"-q -dBATCH -dNOPAUSE -P- -dNOSAFER -sDEVICE=bbox %s_tmp.ps 2>%s_tmp.epsi",
252 int x1=0,y1=0,x2=0,y2=0;
253 FileInfo fi((formBase+
"_tmp.epsi").str());
257 int i = eps.
find(
"%%BoundingBox:");
260 sscanf(eps.
data()+i,
"%%%%BoundingBox:%d %d %d %d",&x1,&y1,&x2,&y2);
264 err(
"Couldn't extract bounding box from %s_tmp.epsi",
qPrint(formBase));
270 double scaleFactor = 1.25;
272 if (zoomFactor<8 || zoomFactor>50) zoomFactor=10;
273 scaleFactor *= zoomFactor/10.0;
275 int width = (int)((x2-x1)*scaleFactor+0.5);
276 int height = (int)((y2-y1)*scaleFactor+0.5);
277 p->storeDisplaySize(pageNum,width,height);
282 sprintf(args,
"-q -dBATCH -dNOPAUSE -P- -dNOSAFER -sDEVICE=pdfwrite"
283 " -o %s_tmp.pdf -c \"[/CropBox [%d %d %d %d] /PAGES pdfmark\" -f %s_tmp.ps",
298 sprintf(args,
"%s_tmp.pdf form_%d.svg",
qPrint(formBase),pageNum);
302 err(
"Problems running pdf2svg. Check your installation!\n");
312 if (inkscapeVersion == -1)
314 err(
"Problems determining the version of inkscape. Check your installation!\n");
318 else if (inkscapeVersion == 0)
324 sprintf(args,
"--export-type=svg --export-filename=form_%d.svg %s_tmp.pdf 2>%s",pageNum,
qPrint(formBase),
Portable::devNull());
329 err(
"Problems running inkscape. Check your installation!\n");
338 err(
"Neither 'pdf2svg' nor 'inkscape' present for conversion of formula to 'svg'\n");
344 thisDir.
remove(formBase.
str()+
"_tmp.pdf");
350 sprintf(args,
"-q -dBATCH -dNOPAUSE -P- -dNOSAFER -sDEVICE=eps2write"
351 " -o %s_tmp.eps -f %s_tmp.ps",
qPrint(formBase),
qPrint(formBase));
363 std::ifstream epsIn(formBase.
str()+
"_tmp.eps",std::ifstream::in);
364 std::ofstream epsOut(formBase.
str()+
"_tmp_corr.eps",std::ofstream::out | std::ofstream::binary);
365 if (epsIn.is_open() && epsOut.is_open())
368 while (getline(epsIn,line))
370 if (line.rfind(
"%%BoundingBox",0)==0)
372 epsOut <<
"%%BoundingBox: " << x1 <<
" " << y1 <<
" " << x2 <<
" " << y2 <<
"\n";
374 else if (line.rfind(
"%%HiResBoundingBox",0)==0)
379 epsOut << line <<
"\n";
387 err(
"Problems correcting the eps files from %s_tmp.eps to %s_tmp_corr.eps\n",
400 sprintf(args,
"-q -dNOSAFER -dBATCH -dNOPAUSE -dEPSCrop -sDEVICE=pnggray -dGraphicsAlphaBits=4 -dTextAlphaBits=4 "
401 "-r%d -sOutputFile=form_%d.png %s_tmp_corr.eps",(
int)(scaleFactor*72),pageNum,
qPrint(formBase));
414 thisDir.
remove(formBase.
str()+
"_tmp.eps");
415 thisDir.
remove(formBase.
str()+
"_tmp_corr.eps");
422 thisDir.
remove(formBase.
str()+
"_tmp.ps");
423 thisDir.
remove(formBase.
str()+
"_tmp.epsi");
430 thisDir.
remove(
"_formulas.dvi");
431 thisDir.
remove(
"_formulas.log");
432 thisDir.
remove(
"_formulas.aux");
442 f.open(
"formula.repository",std::ofstream::out | std::ofstream::binary);
446 for (
int i=0; i<(int)
p->formulas.size(); i++)
449 t <<
"\\_form#" << i;
454 t <<
":" <<
p->formulas[i].c_str() <<
"\n";
464 p->formulaMap.clear();
469 auto it =
p->formulaMap.find(formulaText);
470 if (it!=
p->formulaMap.end())
475 int id = (int)
p->formulas.size();
476 p->formulaMap.insert(std::pair<std::string,int>(formulaText,
id));
477 p->formulas.push_back(formulaText);
483 if (formulaId>=0 && formulaId<(
int)
p->formulas.size())
485 return p->formulas[formulaId];
487 return std::string();
492 return !
p->formulas.empty();
497 return p->getDisplaySize(formulaId);
507 static int inkscapeVersion = -2;
508 if (inkscapeVersion == -2)
510 QCString inkscapeVersionFile =
"inkscape_version" ;
511 inkscapeVersion = -1;
525 std::ifstream inkscapeVersionIn(inkscapeVersionFile.
str(),std::ifstream::in);
526 if (inkscapeVersionIn.is_open())
529 while (getline(inkscapeVersionIn,line))
531 size_t dotPos = line.find(
'.');
532 if (line.rfind(
"Inkscape ",0)==0 && dotPos>0)
535 inkscapeVersion = std::stoi(line.substr(9,dotPos-9));
539 inkscapeVersionIn.close();
548 thisDir.
remove(inkscapeVersionFile.
str());
552 return inkscapeVersion;
std::vector< std::string > StringVector
static std::string currentDirPath()
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Class representing a directory in the file system
bool isEmpty() const
Returns TRUE iff the string is empty
static IndexList * indexList
bool copyFile(const QCString &src, const QCString &dest)
Copies the contents of file with name src to the newly created file with name dest.
std::vector< int > IntVector
void err(const char *fmt,...)
Text streaming class that buffers data.
int find(char c, int index=0, bool cs=TRUE) const
void flush()
Flushes the buffer.
void warn_uncond(const char *fmt,...)
#define Config_getInt(name)
const char * ghostScriptCommand()
void addImageFile(const QCString &name)
std::string absPath() const
QCString fileToString(const QCString &name, bool filter, bool isSourceCode)
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
static bool setCurrent(const std::string &path)
void writeLatexSpecialFormulaChars(TextStream &t)
void writeExtraLatexPackages(TextStream &t)
bool checkForExecutable(const QCString &fileName)
std::map< std::string, int > IntMap
void msg(const char *fmt,...)
void term(const char *fmt,...)
Minimal replacement for QFileInfo.
std::string absFilePath() const
const char * qPrint(const char *s)
#define Config_getString(name)
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
std::string fileName() const
Portable versions of functions that are platform dependent.
A bunch of utility functions.
QCString & sprintf(const char *format,...)
This is an alternative implementation of QCString.