Doxygen
DotFilePatcher类 参考

Helper class to insert a set of map file into an output file 更多...

#include <dotfilepatcher.h>

+ DotFilePatcher 的协作图:

struct  Map
 

Public 成员函数

 DotFilePatcher (const QCString &patchFile)
 
int addMap (const QCString &mapFile, const QCString &relPath, bool urlOnly, const QCString &context, const QCString &label)
 
int addFigure (const QCString &baseName, const QCString &figureName, bool heightCheck)
 
int addSVGConversion (const QCString &relPath, bool urlOnly, const QCString &context, bool zoomable, int graphId)
 
int addSVGObject (const QCString &baseName, const QCString &figureName, const QCString &relPath)
 
bool run () const
 
bool isSVGFile () const
 

静态 Public 成员函数

static bool convertMapFile (TextStream &t, const QCString &mapName, const QCString &relPath, bool urlOnly=FALSE, const QCString &context=QCString())
 
static bool writeSVGFigureLink (TextStream &out, const QCString &relPath, const QCString &baseName, const QCString &absImgName)
 Check if a reference to a SVG figure can be written and do so if possible. 更多...
 
static bool writeVecGfxFigure (TextStream &out, const QCString &baseName, const QCString &figureName)
 

Private 属性

std::vector< Mapm_maps
 
QCString m_patchFile
 

详细描述

Helper class to insert a set of map file into an output file

在文件 dotfilepatcher.h26 行定义.

构造及析构函数说明

◆ DotFilePatcher()

DotFilePatcher::DotFilePatcher ( const QCString patchFile)

在文件 dotfilepatcher.cpp248 行定义.

249  : m_patchFile(patchFile)
250 {
251 }

成员函数说明

◆ addFigure()

int DotFilePatcher::addFigure ( const QCString baseName,
const QCString figureName,
bool  heightCheck 
)

在文件 dotfilepatcher.cpp266 行定义.

268 {
269  int id = (int)m_maps.size();
270  m_maps.emplace_back(figureName,"",heightCheck,"",baseName);
271  return id;
272 }

引用了 m_maps.

◆ addMap()

int DotFilePatcher::addMap ( const QCString mapFile,
const QCString relPath,
bool  urlOnly,
const QCString context,
const QCString label 
)

在文件 dotfilepatcher.cpp258 行定义.

260 {
261  int id = (int)m_maps.size();
262  m_maps.emplace_back(mapFile,relPath,urlOnly,context,label);
263  return id;
264 }

引用了 m_maps.

◆ addSVGConversion()

int DotFilePatcher::addSVGConversion ( const QCString relPath,
bool  urlOnly,
const QCString context,
bool  zoomable,
int  graphId 
)

在文件 dotfilepatcher.cpp274 行定义.

277 {
278  int id = (int)m_maps.size();
279  m_maps.emplace_back("",relPath,urlOnly,context,"",zoomable,graphId);
280  return id;
281 }

引用了 m_maps.

被这些函数引用 writeDotImageMapFromFile().

◆ addSVGObject()

int DotFilePatcher::addSVGObject ( const QCString baseName,
const QCString figureName,
const QCString relPath 
)

在文件 dotfilepatcher.cpp283 行定义.

286 {
287  int id = (int)m_maps.size();
288  m_maps.emplace_back(absImgName,relPath,false,"",baseName);
289  return id;
290 }

引用了 m_maps.

◆ convertMapFile()

bool DotFilePatcher::convertMapFile ( TextStream t,
const QCString mapName,
const QCString relPath,
bool  urlOnly = FALSE,
const QCString context = QCString() 
)
static

converts the rectangles in a client site image map into a stream

参数
tthe stream to which the result is written.
mapNamethe name of the map file.
relPaththe relative path to the root of the output directory (used in case CREATE_SUBDIRS is enabled).
urlOnlyif FALSE the url field in the map contains an external references followed by a $ and then the URL.
contextthe context (file, class, or namespace) in which the map file was found
返回
TRUE if successful.

在文件 dotfilepatcher.cpp214 行定义.

217 {
218  std::ifstream f(mapName.str(),std::ifstream::in);
219  if (!f.is_open())
220  {
221  err("problems opening map file %s for inclusion in the docs!\n"
222  "If you installed Graphviz/dot after a previous failing run, \n"
223  "try deleting the output directory and rerun doxygen.\n",qPrint(mapName));
224  return FALSE;
225  }
226  std::string line;
227  while (getline(f,line)) // foreach line
228  {
229  QCString buf = line+'\n';
230  if (buf.left(5)=="<area")
231  {
232  QCString replBuf = replaceRef(buf,relPath,urlOnly,context);
233  // strip id="..." from replBuf since the id's are not needed and not unique.
234  int indexS = replBuf.find("id=\""), indexE;
235  if (indexS>0 && (indexE=replBuf.find('"',indexS+4))!=-1)
236  {
237  t << replBuf.left(indexS-1) << replBuf.right(replBuf.length() - indexE - 1);
238  }
239  else
240  {
241  t << replBuf;
242  }
243  }
244  }
245  return TRUE;
246 }

引用了 err(), FALSE, QCString::find(), QCString::left(), QCString::length(), qPrint(), replaceRef(), QCString::right(), QCString::str() , 以及 TRUE.

被这些函数引用 insertMapFile(), run() , 以及 writeDotImageMapFromFile().

◆ isSVGFile()

bool DotFilePatcher::isSVGFile ( ) const

在文件 dotfilepatcher.cpp253 行定义.

254 {
255  return m_patchFile.right(4)==".svg";
256 }

引用了 m_patchFile , 以及 QCString::right().

被这些函数引用 run().

◆ run()

bool DotFilePatcher::run ( ) const

在文件 dotfilepatcher.cpp292 行定义.

293 {
294  //printf("DotFilePatcher::run(): %s\n",qPrint(m_patchFile));
295  bool interactiveSVG_local = Config_getBool(INTERACTIVE_SVG);
296  bool isSVGFile = m_patchFile.right(4)==".svg";
297  int graphId = -1;
298  QCString relPath;
299  if (isSVGFile)
300  {
301  const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
302  interactiveSVG_local = interactiveSVG_local && map.zoomable;
303  graphId = map.graphId;
304  relPath = map.relPath;
305  //printf("DotFilePatcher::addSVGConversion: file=%s zoomable=%d\n",
306  // qPrint(m_patchFile),map->zoomable);
307  }
308  std::string tmpName = m_patchFile.str()+".tmp";
309  std::string patchFile = m_patchFile.str();
310  Dir thisDir;
311  if (!thisDir.rename(patchFile,tmpName))
312  {
313  err("Failed to rename file %s to %s!\n",qPrint(m_patchFile),tmpName.c_str());
314  return FALSE;
315  }
316  std::ifstream fi(tmpName, std::ifstream::in);
317  std::ofstream fo(patchFile, std::ofstream::out | std::ofstream::binary);
318  if (!fi.is_open())
319  {
320  err("problem opening file %s for patching!\n",tmpName.c_str());
321  thisDir.rename(tmpName,patchFile);
322  return FALSE;
323  }
324  if (!fo.is_open())
325  {
326  err("problem opening file %s for patching!\n",qPrint(m_patchFile));
327  thisDir.rename(tmpName,patchFile);
328  return FALSE;
329  }
330  TextStream t(&fo);
331  int width,height;
332  bool insideHeader=FALSE;
333  bool replacedHeader=FALSE;
334  bool foundSize=FALSE;
335  int lineNr=1;
336  std::string lineStr;
337  static const reg::Ex reSVG(R"([\[<]!-- SVG [0-9]+)");
338  static const reg::Ex reMAP(R"(<!-- MAP [0-9]+)");
339  static const reg::Ex reFIG(R"(% FIG [0-9]+)");
340 
341  while (getline(fi,lineStr))
342  {
343  QCString line = lineStr+'\n';
344  //printf("line=[%s]\n",qPrint(line.stripWhiteSpace()));
345  int i;
346  if (isSVGFile)
347  {
348  if (interactiveSVG_local)
349  {
350  if (line.find("<svg")!=-1 && !replacedHeader)
351  {
352  int count;
353  count = sscanf(line.data(),"<svg width=\"%dpt\" height=\"%dpt\"",&width,&height);
354  //printf("width=%d height=%d\n",width,height);
355  foundSize = count==2 && (width>500 || height>450);
356  if (foundSize) insideHeader=TRUE;
357  }
358  else if (insideHeader && !replacedHeader && line.find("<title>")!=-1)
359  {
360  if (foundSize)
361  {
362  // insert special replacement header for interactive SVGs
363  t << "<!--zoomable " << height << " -->\n";
364  t << svgZoomHeader;
365  t << "var viewWidth = " << width << ";\n";
366  t << "var viewHeight = " << height << ";\n";
367  if (graphId>=0)
368  {
369  t << "var sectionId = 'dynsection-" << graphId << "';\n";
370  }
371  t << "</script>\n";
372  t << "<script xlink:href=\"" << relPath << "svgpan.js\"/>\n";
373  t << "<svg id=\"graph\" class=\"graph\">\n";
374  t << "<g id=\"viewport\">\n";
375  }
376  insideHeader=FALSE;
377  replacedHeader=TRUE;
378  }
379  }
380  if (!insideHeader || !foundSize) // copy SVG and replace refs,
381  // unless we are inside the header of the SVG.
382  // Then we replace it with another header.
383  {
384  const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
385  t << replaceRef(line,map.relPath,map.urlOnly,map.context,"_top");
386  }
387  }
388  else if ((i=findIndex(line.str(),reSVG))!=-1)
389  {
390  //printf("Found marker at %d\n",i);
391  int mapId=-1;
392  t << line.left(i);
393  int n = sscanf(line.data()+i+1,"!-- SVG %d",&mapId);
394  if (n==1 && mapId>=0 && mapId<(int)m_maps.size())
395  {
396  int e = std::max(line.find("--]"),line.find("-->"));
397  const Map &map = m_maps.at(mapId);
398  //printf("DotFilePatcher::writeSVGFigure: file=%s zoomable=%d\n",
399  // qPrint(m_patchFile),map.zoomable);
400  if (!writeSVGFigureLink(t,map.relPath,map.label,map.mapFile))
401  {
402  err("Problem extracting size from SVG file %s\n",qPrint(map.mapFile));
403  }
404  if (e!=-1) t << line.mid(e+3);
405  }
406  else // error invalid map id!
407  {
408  err("Found invalid SVG id in file %s!\n",qPrint(m_patchFile));
409  t << line.mid(i);
410  }
411  }
412  else if ((i=findIndex(line.str(),reMAP))!=-1)
413  {
414  int mapId=-1;
415  t << line.left(i);
416  int n = sscanf(line.data()+i,"<!-- MAP %d",&mapId);
417  if (n==1 && mapId>=0 && mapId<(int)m_maps.size())
418  {
419  TextStream tt;
420  const Map &map = m_maps.at(mapId);
421  //printf("patching MAP %d in file %s with contents of %s\n",
422  // mapId,qPrint(m_patchFile),qPrint(map.mapFile));
423  convertMapFile(tt,map.mapFile,map.relPath,map.urlOnly,map.context);
424  if (!tt.empty())
425  {
426  t << "<map name=\"" << correctId(map.label) << "\" id=\"" << correctId(map.label) << "\">\n";
427  t << tt.str();
428  t << "</map>\n";
429  }
430  }
431  else // error invalid map id!
432  {
433  err("Found invalid MAP id in file %s!\n",qPrint(m_patchFile));
434  t << line.mid(i);
435  }
436  }
437  else if ((i=findIndex(line.str(),reFIG))!=-1)
438  {
439  int mapId=-1;
440  int n = sscanf(line.data()+i+2,"FIG %d",&mapId);
441  //printf("line='%s' n=%d\n",qPrint(line)+i,n);
442  if (n==1 && mapId>=0 && mapId<(int)m_maps.size())
443  {
444  const Map &map = m_maps.at(mapId);
445  //printf("patching FIG %d in file %s with contents of %s\n",
446  // mapId,qPrint(m_patchFile),qPrint(map.mapFile));
447  if (!writeVecGfxFigure(t,map.label,map.mapFile))
448  {
449  err("problem writing FIG %d figure!\n",mapId);
450  return FALSE;
451  }
452  }
453  else // error invalid map id!
454  {
455  err("Found invalid bounding FIG %d in file %s!\n",mapId,qPrint(m_patchFile));
456  t << line;
457  }
458  }
459  else
460  {
461  t << line;
462  }
463  lineNr++;
464  }
465  fi.close();
466  if (isSVGFile && interactiveSVG_local && replacedHeader)
467  {
468  QCString orgName=m_patchFile.left(m_patchFile.length()-4)+"_org.svg";
469  t << substitute(svgZoomFooter,"$orgname",stripPath(orgName));
470  t.flush();
471  fo.close();
472  // keep original SVG file so we can refer to it, we do need to replace
473  // dummy link by real ones
474  fi.open(tmpName,std::ifstream::in);
475  fo.open(orgName.str(),std::ofstream::out | std::ofstream::binary);
476  if (!fi.is_open())
477  {
478  err("problem opening file %s for reading!\n",tmpName.c_str());
479  return FALSE;
480  }
481  if (!fo.is_open())
482  {
483  err("problem opening file %s for writing!\n",qPrint(orgName));
484  return FALSE;
485  }
486  t.setStream(&fo);
487  while (getline(fi,lineStr)) // foreach line
488  {
489  std::string line = lineStr+'\n';
490  const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
491  t << replaceRef(line.c_str(),map.relPath,map.urlOnly,map.context,"_top");
492  }
493  t.flush();
494  fi.close();
495  fo.close();
496  }
497  // remove temporary file
498  thisDir.remove(tmpName);
499  return TRUE;
500 }

引用了 Config_getBool, DotFilePatcher::Map::context, convertMapFile(), correctId(), QCString::data(), TextStream::empty(), err(), FALSE, QCString::find(), findIndex(), TextStream::flush(), DotFilePatcher::Map::graphId, isSVGFile(), DotFilePatcher::Map::label, QCString::left(), QCString::length(), m_maps, m_patchFile, DotFilePatcher::Map::mapFile, QCString::mid(), qPrint(), DotFilePatcher::Map::relPath, Dir::remove(), Dir::rename(), replaceRef(), QCString::right(), TextStream::setStream(), TextStream::str(), QCString::str(), stripPath(), substitute(), svgZoomFooter, svgZoomHeader, TRUE, DotFilePatcher::Map::urlOnly, writeSVGFigureLink(), writeVecGfxFigure() , 以及 DotFilePatcher::Map::zoomable.

被这些函数引用 writeDotImageMapFromFile().

◆ writeSVGFigureLink()

bool DotFilePatcher::writeSVGFigureLink ( TextStream out,
const QCString relPath,
const QCString baseName,
const QCString absImgName 
)
static

Check if a reference to a SVG figure can be written and do so if possible.

Returns FALSE if not possible (for instance because the SVG file is not yet generated).

在文件 dotfilepatcher.cpp539 行定义.

541 {
542  int width=600,height=600;
543  if (!readSVGSize(absImgName,&width,&height))
544  {
545  return FALSE;
546  }
547  if (width==-1)
548  {
549  if (height<=60) height=300; else height+=300; // add some extra space for zooming
550  if (height>600) height=600; // clip to maximum height of 600 pixels
551  out << "<div class=\"zoom\">";
552  //out << "<object type=\"image/svg+xml\" data=\""
553  //out << "<embed type=\"image/svg+xml\" src=\""
554  out << "<iframe scrolling=\"no\" frameborder=\"0\" src=\""
555  << relPath << baseName << ".svg\" width=\"100%\" height=\"" << height << "\">";
556  }
557  else
558  {
559  //out << "<object type=\"image/svg+xml\" data=\""
560  //out << "<embed type=\"image/svg+xml\" src=\""
561  out << "<iframe scrolling=\"no\" frameborder=\"0\" src=\""
562  << relPath << baseName << ".svg\" width=\""
563  << ((width*96+48)/72) << "\" height=\""
564  << ((height*96+48)/72) << "\">";
565  }
567  //out << "</object>";
568  //out << "</embed>";
569  out << "</iframe>";
570  if (width==-1)
571  {
572  out << "</div>";
573  }
574 
575  return TRUE;
576 }

引用了 FALSE, readSVGSize(), TRUE , 以及 writeSVGNotSupported().

被这些函数引用 DotGraph::generateCode(), run() , 以及 writeDotImageMapFromFile().

◆ writeVecGfxFigure()

bool DotFilePatcher::writeVecGfxFigure ( TextStream out,
const QCString baseName,
const QCString figureName 
)
static

在文件 dotfilepatcher.cpp578 行定义.

580 {
581  int width=400,height=550;
582  if (Config_getBool(USE_PDFLATEX))
583  {
584  if (!DotRunner::readBoundingBox(figureName+".pdf",&width,&height,FALSE))
585  {
586  //printf("writeVecGfxFigure()=0\n");
587  return FALSE;
588  }
589  }
590  else
591  {
592  if (!DotRunner::readBoundingBox(figureName+".eps",&width,&height,TRUE))
593  {
594  //printf("writeVecGfxFigure()=0\n");
595  return FALSE;
596  }
597  }
598  //printf("Got PDF/EPS size %d,%d\n",width,height);
599  int maxWidth = 350; /* approx. page width in points, excl. margins */
600  int maxHeight = 550; /* approx. page height in points, excl. margins */
601  out << "\\nopagebreak\n"
602  "\\begin{figure}[H]\n"
603  "\\begin{center}\n"
604  "\\leavevmode\n";
605  if (width>maxWidth || height>maxHeight) // figure too big for page
606  {
607  // c*width/maxWidth > c*height/maxHeight, where c=maxWidth*maxHeight>0
608  if (width*maxHeight>height*maxWidth)
609  {
610  out << "\\includegraphics[width=" << maxWidth << "pt]";
611  }
612  else
613  {
614  out << "\\includegraphics[height=" << maxHeight << "pt]";
615  }
616  }
617  else
618  {
619  out << "\\includegraphics[width=" << width << "pt]";
620  }
621 
622  out << "{" << baseName << "}\n"
623  "\\end{center}\n"
624  "\\end{figure}\n";
625 
626  //printf("writeVecGfxFigure()=1\n");
627  return TRUE;
628 }

引用了 Config_getBool, FALSE, DotRunner::readBoundingBox() , 以及 TRUE.

被这些函数引用 DotGraph::generateCode() , 以及 run().

类成员变量说明

◆ m_maps

std::vector<Map> DotFilePatcher::m_maps
private

在文件 dotfilepatcher.h69 行定义.

被这些函数引用 addFigure(), addMap(), addSVGConversion(), addSVGObject() , 以及 run().

◆ m_patchFile

QCString DotFilePatcher::m_patchFile
private

在文件 dotfilepatcher.h70 行定义.

被这些函数引用 isSVGFile() , 以及 run().


该类的文档由以下文件生成:
Dir::remove
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition: dir.cpp:256
Dir
Class representing a directory in the file system
Definition: dir.h:68
QCString::length
uint length() const
Returns the length of the string, not counting the 0-terminator.
Definition: qcstring.h:147
readSVGSize
static bool readSVGSize(const QCString &fileName, int *width, int *height)
Definition: dotfilepatcher.cpp:506
svgZoomFooter
static const char svgZoomFooter[]
Definition: dotfilepatcher.cpp:72
DotFilePatcher::writeVecGfxFigure
static bool writeVecGfxFigure(TextStream &out, const QCString &baseName, const QCString &figureName)
Definition: dotfilepatcher.cpp:578
QCString::str
std::string str() const
Definition: qcstring.h:442
err
void err(const char *fmt,...)
Definition: message.cpp:203
TextStream
Text streaming class that buffers data.
Definition: textstream.h:33
DotFilePatcher::m_maps
std::vector< Map > m_maps
Definition: dotfilepatcher.h:69
QCString::find
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:38
TextStream::empty
bool empty() const
Returns true iff the buffer is empty
Definition: textstream.h:232
DotRunner::readBoundingBox
static bool readBoundingBox(const QCString &fileName, int *width, int *height, bool isEps)
Definition: dotrunner.cpp:107
Dir::rename
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition: dir.cpp:263
QCString::left
QCString left(size_t len) const
Definition: qcstring.h:212
svgZoomHeader
static const char svgZoomHeader[]
Definition: dotfilepatcher.cpp:28
stripPath
QCString stripPath(const QCString &s)
Definition: util.cpp:5318
DotFilePatcher::writeSVGFigureLink
static bool writeSVGFigureLink(TextStream &out, const QCString &relPath, const QCString &baseName, const QCString &absImgName)
Check if a reference to a SVG figure can be written and do so if possible.
Definition: dotfilepatcher.cpp:539
writeSVGNotSupported
static void writeSVGNotSupported(TextStream &out)
Definition: dotfilepatcher.cpp:532
TRUE
#define TRUE
Definition: qcstring.h:36
TextStream::str
std::string str() const
Return the contents of the buffer as a std::string object
Definition: textstream.h:208
DotFilePatcher::m_patchFile
QCString m_patchFile
Definition: dotfilepatcher.h:70
QCString::mid
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition: qcstring.h:224
substitute
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition: qcstring.cpp:465
DotFilePatcher::isSVGFile
bool isSVGFile() const
Definition: dotfilepatcher.cpp:253
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
reg::Ex
Class representing a regular expression.
Definition: regex.h:48
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
Definition: qcstring.h:153
DotFilePatcher::convertMapFile
static bool convertMapFile(TextStream &t, const QCString &mapName, const QCString &relPath, bool urlOnly=FALSE, const QCString &context=QCString())
Definition: dotfilepatcher.cpp:214
replaceRef
static QCString replaceRef(const QCString &buf, const QCString &relPath, bool urlOnly, const QCString &context, const QCString &target=QCString())
Definition: dotfilepatcher.cpp:126
QCString::right
QCString right(size_t len) const
Definition: qcstring.h:217
correctId
QCString correctId(const QCString &s)
Definition: util.cpp:3941
findIndex
int findIndex(const StringVector &sv, const std::string &s)
find the index of a string in a vector of strings, returns -1 if the string could not be found
Definition: util.cpp:7319
FALSE
#define FALSE
Definition: qcstring.h:33
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108