Doxygen
Loading...
Searching...
No Matches
DotFilePatcher Class Reference

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

#include <src/dotfilepatcher.h>

+ Collaboration diagram for DotFilePatcher:

Classes

struct  Map
 

Public Member Functions

 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
 

Static Public Member Functions

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 Attributes

std::vector< Mapm_maps
 
QCString m_patchFile
 

Detailed Description

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

Definition at line 26 of file dotfilepatcher.h.

Constructor & Destructor Documentation

◆ DotFilePatcher()

DotFilePatcher::DotFilePatcher ( const QCString & patchFile)

Definition at line 261 of file dotfilepatcher.cpp.

262 : m_patchFile(patchFile)
263{
264}
QCString m_patchFile

References m_patchFile.

Member Function Documentation

◆ addFigure()

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

Definition at line 279 of file dotfilepatcher.cpp.

281{
282 size_t id = m_maps.size();
283 m_maps.emplace_back(figureName,"",heightCheck,"",baseName);
284 return static_cast<int>(id);
285}
std::vector< Map > m_maps

References m_maps.

◆ addMap()

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

Definition at line 271 of file dotfilepatcher.cpp.

273{
274 size_t id = m_maps.size();
275 m_maps.emplace_back(mapFile,relPath,urlOnly,context,label);
276 return static_cast<int>(id);
277}

References m_maps.

◆ addSVGConversion()

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

Definition at line 287 of file dotfilepatcher.cpp.

290{
291 size_t id = m_maps.size();
292 m_maps.emplace_back("",relPath,urlOnly,context,"",zoomable,graphId);
293 return static_cast<int>(id);
294}

References m_maps.

Referenced by writeDotImageMapFromFile().

◆ addSVGObject()

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

Definition at line 296 of file dotfilepatcher.cpp.

299{
300 size_t id = m_maps.size();
301 m_maps.emplace_back(absImgName,relPath,false,"",baseName);
302 return static_cast<int>(id);
303}

References 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

Parameters
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
Returns
TRUE if successful.

Definition at line 219 of file dotfilepatcher.cpp.

222{
223 std::ifstream f = Portable::openInputStream(mapName);
224 if (!f.is_open())
225 {
226 err("problems opening map file %s for inclusion in the docs!\n"
227 "If you installed Graphviz/dot after a previous failing run, \n"
228 "try deleting the output directory and rerun doxygen.\n",qPrint(mapName));
229 return FALSE;
230 }
231 std::string line;
232 while (getline(f,line)) // foreach line
233 {
234 QCString buf = line+'\n';
235 if (buf.startsWith("<area"))
236 {
237 QCString replBuf = replaceRef(buf,relPath,urlOnly,context);
238 // in dot version 7.0.2 the alt attribute is, incorrectly, removed.
239 // see https://gitlab.com/graphviz/graphviz/-/issues/265
240 int indexA = replBuf.find("alt=");
241 if (indexA == -1)
242 {
243 replBuf = replBuf.left(5) + " alt=\"\"" + replBuf.right(replBuf.length() - 5);
244 }
245
246 // strip id="..." from replBuf since the id's are not needed and not unique.
247 int indexS = replBuf.find("id=\""), indexE = 0;
248 if (indexS>0 && (indexE=replBuf.find('"',indexS+4))!=-1)
249 {
250 t << replBuf.left(indexS-1) << replBuf.right(replBuf.length() - indexE - 1);
251 }
252 else
253 {
254 t << replBuf;
255 }
256 }
257 }
258 return TRUE;
259}
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
bool startsWith(const char *s) const
Definition qcstring.h:492
QCString right(size_t len) const
Definition qcstring.h:219
QCString left(size_t len) const
Definition qcstring.h:214
static QCString replaceRef(const QCString &buf, const QCString &relPath, bool urlOnly, const QCString &context, const QCString &target=QCString())
#define err(fmt,...)
Definition message.h:84
std::ifstream openInputStream(const QCString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:676
const char * qPrint(const char *s)
Definition qcstring.h:672
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34

References err, FALSE, QCString::find(), QCString::left(), QCString::length(), Portable::openInputStream(), qPrint(), replaceRef(), QCString::right(), QCString::startsWith(), and TRUE.

Referenced by insertMapFile(), run(), and writeDotImageMapFromFile().

◆ isSVGFile()

bool DotFilePatcher::isSVGFile ( ) const

Definition at line 266 of file dotfilepatcher.cpp.

267{
268 return m_patchFile.endsWith(".svg");
269}

References m_patchFile.

Referenced by run().

◆ run()

bool DotFilePatcher::run ( ) const

Definition at line 305 of file dotfilepatcher.cpp.

306{
307 //printf("DotFilePatcher::run(): %s\n",qPrint(m_patchFile));
308 bool interactiveSVG = Config_getBool(INTERACTIVE_SVG);
309 bool isSVGFile = m_patchFile.endsWith(".svg");
310 int graphId = -1;
311 QCString relPath;
312 if (isSVGFile)
313 {
314 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
315 interactiveSVG = interactiveSVG && map.zoomable;
316 graphId = map.graphId;
317 relPath = map.relPath;
318 //printf("DotFilePatcher::addSVGConversion: file=%s zoomable=%d\n",
319 // qPrint(m_patchFile),map->zoomable);
320 }
321 QCString tmpName = m_patchFile+".tmp";
322 Dir thisDir;
323 if (!thisDir.rename(m_patchFile.str(),tmpName.str()))
324 {
325 err("Failed to rename file %s to %s!\n",qPrint(m_patchFile),qPrint(tmpName));
326 return FALSE;
327 }
328 std::ifstream fi = Portable::openInputStream(tmpName);
329 std::ofstream fo = Portable::openOutputStream(m_patchFile);
330 if (!fi.is_open())
331 {
332 err("problem opening file %s for patching!\n",qPrint(tmpName));
333 thisDir.rename(tmpName.str(),m_patchFile.str());
334 return FALSE;
335 }
336 if (!fo.is_open())
337 {
338 err("problem opening file %s for patching!\n",qPrint(m_patchFile));
339 thisDir.rename(tmpName.str(),m_patchFile.str());
340 return FALSE;
341 }
342 TextStream t(&fo);
343 int width=0,height=0;
344 bool insideHeader=FALSE;
345 bool replacedHeader=FALSE;
346 bool useNagivation=FALSE;
347 std::string lineStr;
348 static const reg::Ex reSVG(R"([\[<]!-- SVG [0-9]+)");
349 static const reg::Ex reMAP(R"(<!-- MAP [0-9]+)");
350 static const reg::Ex reFIG(R"(% FIG [0-9]+)");
351
352 while (getline(fi,lineStr))
353 {
354 QCString line = lineStr+'\n';
355 //printf("line=[%s]\n",qPrint(line.stripWhiteSpace()));
356 int i = 0;
357 if (isSVGFile)
358 {
359 if (interactiveSVG)
360 {
361 if (line.find("<svg")!=-1 && !replacedHeader)
362 {
363 int count = sscanf(line.data(),"<svg width=\"%dpt\" height=\"%dpt\"",&width,&height);
364 //printf("width=%d height=%d\n",width,height);
365 useNagivation = count==2 && (width>500 || height>450);
366 insideHeader = count==2;
367 }
368 else if (insideHeader && !replacedHeader && line.find("<g id=\"graph")!=-1)
369 {
370 if (useNagivation)
371 {
372 // insert special replacement header for interactive SVGs
373 t << "<!--zoomable " << height << " -->\n";
374 t << svgZoomHeader0;
375 }
376 else
377 {
379 }
380 t << svgZoomHeader1;
381 if (useNagivation)
382 {
383 t << svgZoomHeader2;
384 }
385 if (useNagivation)
386 {
387 t << "<script type=\"application/ecmascript\">\n";
388 t << "var viewWidth = " << width << ";\n";
389 t << "var viewHeight = " << height << ";\n";
390 if (graphId>=0)
391 {
392 t << "var sectionId = 'dynsection-" << graphId << "';\n";
393 }
394 t << "</script>\n";
395 }
396 t << "<script type=\"application/ecmascript\" xlink:href=\"" << relPath << "svg.min.js\"/>\n";
397 t << "<svg id=\"graph\" class=\"graph\">\n";
398
399 if (useNagivation)
400 {
401 t << "<g id=\"viewport\">\n";
402 }
403 else
404 {
405 t << line;
406 }
407 line="";
408 insideHeader=FALSE;
409 replacedHeader=TRUE;
410 }
411 }
412 if (!insideHeader || !useNagivation) // copy SVG and replace refs,
413 // unless we are inside the header of the SVG.
414 // Then we replace it with another header.
415 {
416 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
417 t << replaceRef(line,map.relPath,map.urlOnly,map.context,"_top");
418 }
419 }
420 else if (line.find("SVG")!=-1 && (i=findIndex(line.str(),reSVG))!=-1)
421 {
422 //printf("Found marker at %d\n",i);
423 int mapId=-1;
424 t << line.left(i);
425 int n = sscanf(line.data()+i+1,"!-- SVG %d",&mapId);
426 if (n==1 && mapId>=0 && mapId<static_cast<int>(m_maps.size()))
427 {
428 int e = std::max(line.find("--]"),line.find("-->"));
429 const Map &map = m_maps.at(mapId);
430 //printf("DotFilePatcher::writeSVGFigure: file=%s zoomable=%d\n",
431 // qPrint(m_patchFile),map.zoomable);
432 if (!writeSVGFigureLink(t,map.relPath,map.label,map.mapFile))
433 {
434 err("Problem extracting size from SVG file %s\n",qPrint(map.mapFile));
435 }
436 if (e!=-1) t << line.mid(e+3);
437 }
438 else // error invalid map id!
439 {
440 err("Found invalid SVG id in file %s!\n",qPrint(m_patchFile));
441 t << line.mid(i);
442 }
443 }
444 else if (line.find("MAP")!=-1 && (i=findIndex(line.str(),reMAP))!=-1)
445 {
446 int mapId=-1;
447 t << line.left(i);
448 int n = sscanf(line.data()+i,"<!-- MAP %d",&mapId);
449 if (n==1 && mapId>=0 && mapId<static_cast<int>(m_maps.size()))
450 {
451 TextStream tt;
452 const Map &map = m_maps.at(mapId);
453 //printf("patching MAP %d in file %s with contents of %s\n",
454 // mapId,qPrint(m_patchFile),qPrint(map.mapFile));
455 convertMapFile(tt,map.mapFile,map.relPath,map.urlOnly,map.context);
456 if (!tt.empty())
457 {
458 t << "<map name=\"" << correctId(map.label) << "\" id=\"" << correctId(map.label) << "\">\n";
459 t << tt.str();
460 t << "</map>\n";
461 }
462 }
463 else // error invalid map id!
464 {
465 err("Found invalid MAP id in file %s!\n",qPrint(m_patchFile));
466 t << line.mid(i);
467 }
468 }
469 else if (line.find("FIG")!=-1 && (i=findIndex(line.str(),reFIG))!=-1)
470 {
471 int mapId=-1;
472 int n = sscanf(line.data()+i+2,"FIG %d",&mapId);
473 //printf("line='%s' n=%d\n",qPrint(line)+i,n);
474 if (n==1 && mapId>=0 && mapId<static_cast<int>(m_maps.size()))
475 {
476 const Map &map = m_maps.at(mapId);
477 //printf("patching FIG %d in file %s with contents of %s\n",
478 // mapId,qPrint(m_patchFile),qPrint(map.mapFile));
479 if (!writeVecGfxFigure(t,map.label,map.mapFile))
480 {
481 err("problem writing FIG %d figure!\n",mapId);
482 return FALSE;
483 }
484 }
485 else // error invalid map id!
486 {
487 err("Found invalid bounding FIG %d in file %s!\n",mapId,qPrint(m_patchFile));
488 t << line;
489 }
490 }
491 else
492 {
493 t << line;
494 }
495 }
496 if (isSVGFile && interactiveSVG && !useNagivation) t << "</svg>\n";
497
498 fi.close();
499 if (isSVGFile && interactiveSVG && replacedHeader)
500 {
501 QCString orgName=m_patchFile.left(m_patchFile.length()-4)+"_org.svg";
502 if (useNagivation)
503 {
504 t << substitute(svgZoomFooter1,"$orgname",stripPath(orgName));
505 }
506 t << svgZoomFooter2;
507 t.flush();
508 fo.close();
509 // keep original SVG file so we can refer to it, we do need to replace
510 // dummy link by real ones
511 fi = Portable::openInputStream(tmpName);
512 fo = Portable::openOutputStream(orgName);
513 if (!fi.is_open())
514 {
515 err("problem opening file %s for reading!\n",qPrint(tmpName));
516 return FALSE;
517 }
518 if (!fo.is_open())
519 {
520 err("problem opening file %s for writing!\n",qPrint(orgName));
521 return FALSE;
522 }
523 t.setStream(&fo);
524 while (getline(fi,lineStr)) // foreach line
525 {
526 std::string line = lineStr+'\n';
527 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
528 t << replaceRef(line.c_str(),map.relPath,map.urlOnly,map.context,"_top");
529 }
530 t.flush();
531 fi.close();
532 fo.close();
533 }
534 // remove temporary file
535 thisDir.remove(tmpName.str());
536 return TRUE;
537}
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:314
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition dir.cpp:321
static bool writeVecGfxFigure(TextStream &out, const QCString &baseName, const QCString &figureName)
static bool convertMapFile(TextStream &t, const QCString &mapName, const QCString &relPath, bool urlOnly=FALSE, const QCString &context=QCString())
bool isSVGFile() const
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.
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
const std::string & str() const
Definition qcstring.h:537
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:159
bool empty() const
Returns true iff the buffer is empty.
Definition textstream.h:253
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:229
#define Config_getBool(name)
Definition config.h:33
static const char svgZoomHeader1[]
static const char svgZoomHeader2[]
static const char svgZoomHeader0_noinit[]
static const char svgZoomFooter2[]
static const char svgZoomHeader0[]
static const char svgZoomFooter1[]
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:665
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
QCString stripPath(const QCString &s)
Definition util.cpp:5292
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:6982
QCString correctId(const QCString &s)
Definition util.cpp:4259

References 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(), m_maps, m_patchFile, DotFilePatcher::Map::mapFile, QCString::mid(), Portable::openInputStream(), Portable::openOutputStream(), qPrint(), DotFilePatcher::Map::relPath, Dir::remove(), Dir::rename(), replaceRef(), TextStream::setStream(), QCString::str(), TextStream::str(), stripPath(), substitute(), svgZoomFooter1, svgZoomFooter2, svgZoomHeader0, svgZoomHeader0_noinit, svgZoomHeader1, svgZoomHeader2, TRUE, DotFilePatcher::Map::urlOnly, writeSVGFigureLink(), writeVecGfxFigure(), and DotFilePatcher::Map::zoomable.

Referenced by 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).

Definition at line 576 of file dotfilepatcher.cpp.

578{
579 int width=600,height=600;
580 if (!readSVGSize(absImgName,&width,&height))
581 {
582 return FALSE;
583 }
584 if (width==-1)
585 {
586 if (height<=60) height=300; else height+=300; // add some extra space for zooming
587 if (height>600) height=600; // clip to maximum height of 600 pixels
588 out << "<div class=\"zoom\">";
589 //out << "<object type=\"image/svg+xml\" data=\""
590 //out << "<embed type=\"image/svg+xml\" src=\""
591 out << "<iframe scrolling=\"no\" frameborder=\"0\" src=\""
592 << relPath << baseName << ".svg\" width=\"100%\" height=\"" << height << "\">";
593 }
594 else
595 {
596 //out << "<object type=\"image/svg+xml\" data=\""
597 //out << "<embed type=\"image/svg+xml\" src=\""
598 out << "<iframe scrolling=\"no\" frameborder=\"0\" src=\""
599 << relPath << baseName << ".svg\" width=\""
600 << ((width*96+48)/72) << "\" height=\""
601 << ((height*96+48)/72) << "\">";
602 }
604 //out << "</object>";
605 //out << "</embed>";
606 out << "</iframe>";
607 if (width==-1)
608 {
609 out << "</div>";
610 }
611
612 return TRUE;
613}
static bool readSVGSize(const QCString &fileName, int *width, int *height)
static void writeSVGNotSupported(TextStream &out)

References FALSE, readSVGSize(), TRUE, and writeSVGNotSupported().

Referenced by DotGraph::generateCode(), run(), and writeDotImageMapFromFile().

◆ writeVecGfxFigure()

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

Definition at line 615 of file dotfilepatcher.cpp.

617{
618 int width=400,height=550;
619 if (Config_getBool(USE_PDFLATEX))
620 {
621 if (!DotRunner::readBoundingBox(figureName+".pdf",&width,&height,FALSE))
622 {
623 //printf("writeVecGfxFigure()=0\n");
624 return FALSE;
625 }
626 }
627 else
628 {
629 if (!DotRunner::readBoundingBox(figureName+".eps",&width,&height,TRUE))
630 {
631 //printf("writeVecGfxFigure()=0\n");
632 return FALSE;
633 }
634 }
635 //printf("Got PDF/EPS size %d,%d\n",width,height);
636 int maxWidth = 350; /* approx. page width in points, excl. margins */
637 int maxHeight = 550; /* approx. page height in points, excl. margins */
638 out << "\\nopagebreak\n"
639 "\\begin{figure}[H]\n"
640 "\\begin{center}\n"
641 "\\leavevmode\n";
642 if (width>maxWidth || height>maxHeight) // figure too big for page
643 {
644 // c*width/maxWidth > c*height/maxHeight, where c=maxWidth*maxHeight>0
645 if (width*maxHeight>height*maxWidth)
646 {
647 out << "\\includegraphics[width=" << maxWidth << "pt]";
648 }
649 else
650 {
651 out << "\\includegraphics[height=" << maxHeight << "pt]";
652 }
653 }
654 else
655 {
656 out << "\\includegraphics[width=" << width << "pt]";
657 }
658
659 out << "{" << baseName << "}\n"
660 "\\end{center}\n"
661 "\\end{figure}\n";
662
663 //printf("writeVecGfxFigure()=1\n");
664 return TRUE;
665}
static bool readBoundingBox(const QCString &fileName, int *width, int *height, bool isEps)

References Config_getBool, FALSE, DotRunner::readBoundingBox(), and TRUE.

Referenced by DotGraph::generateCode(), and run().

Member Data Documentation

◆ m_maps

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

Definition at line 69 of file dotfilepatcher.h.

Referenced by addFigure(), addMap(), addSVGConversion(), addSVGObject(), and run().

◆ m_patchFile

QCString DotFilePatcher::m_patchFile
private

Definition at line 70 of file dotfilepatcher.h.

Referenced by DotFilePatcher(), isSVGFile(), and run().


The documentation for this class was generated from the following files: