Doxygen
Loading...
Searching...
No Matches
dotfilepatcher.cpp
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright (C) 1997-2019 by Dimitri van Heesch.
4*
5* Permission to use, copy, modify, and distribute this software and its
6* documentation under the terms of the GNU General Public License is hereby
7* granted. No representations are made about the suitability of this software
8* for any purpose. It is provided "as is" without express or implied warranty.
9* See the GNU General Public License for more details.
10*
11* Documents produced by Doxygen are derivative works derived from the
12* input used in their production; they are not affected by this license.
13*
14*/
15
16#include "dotfilepatcher.h"
17#include "dotrunner.h"
18#include "config.h"
19#include "message.h"
20#include "docparser.h"
21#include "docnode.h"
22#include "doxygen.h"
23#include "util.h"
24#include "dot.h"
25#include "dir.h"
26#include "portable.h"
27#include "stringutil.h"
28
29// top part of the interactive SVG header
30static const char svgZoomHeader0[] = R"svg(
31<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
32)svg";
33
34static const char svgZoomHeader0_noinit[] = R"svg(
35<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
36)svg";
37
38static const char svgZoomHeader1[] = R"svg(
39<style type="text/css"><![CDATA[
40.node, .edge {opacity: 0.7;}
41.node.selected, .edge.selected {opacity: 1;}
42.edge:hover path { stroke: red; }
43.edge:hover polygon { stroke: red; fill: red; }
44]]></style>
45)svg";
46
47// conditional part of the interactive SVG header in case the navigation panel is shown
48static const char svgZoomHeader2[] = R"svg(
49<defs>
50 <circle id="rim" cx="0" cy="0" r="7"/>
51 <circle id="rim2" cx="0" cy="0" r="3.5"/>
52 <g id="zoomPlus">
53 <use xlink:href="#rim" fill="#404040"><set attributeName="fill" to="#808080" begin="zoomplus.mouseover" end="zoomplus.mouseout"/></use>
54 <path d="M-4,0h8M0,-4v8" fill="none" stroke="white" stroke-width="1.5" pointer-events="none"/>
55 </g>
56 <g id="zoomMin">
57 <use xlink:href="#rim" fill="#404040"><set attributeName="fill" to="#808080" begin="zoomminus.mouseover" end="zoomminus.mouseout"/></use>
58 <path d="M-4,0h8" fill="none" stroke="white" stroke-width="1.5" pointer-events="none"/>
59 </g>
60 <g id="arrowUp" transform="translate(30 24)">
61 <use xlink:href="#rim"/>
62 <path pointer-events="none" fill="none" stroke="white" stroke-width="1.5" d="M0,-3.0v7 M-2.5,-0.5L0,-3.0L2.5,-0.5"/>
63 </g>
64 <g id="arrowRight" transform="rotate(90) translate(36 -43)">
65 <use xlink:href="#rim"/>
66 <path pointer-events="none" fill="none" stroke="white" stroke-width="1.5" d="M0,-3.0v7 M-2.5,-0.5L0,-3.0L2.5,-0.5"/>
67 </g>
68 <g id="arrowDown" transform="rotate(180) translate(-30 -48)">
69 <use xlink:href="#rim"/>
70 <path pointer-events="none" fill="none" stroke="white" stroke-width="1.5" d="M0,-3.0v7 M-2.5,-0.5L0,-3.0L2.5,-0.5"/>
71 </g>
72 <g id="arrowLeft" transform="rotate(270) translate(-36 17)">
73 <use xlink:href="#rim"/>
74 <path pointer-events="none" fill="none" stroke="white" stroke-width="1.5" d="M0,-3.0v7 M-2.5,-0.5L0,-3.0L2.5,-0.5"/>
75 </g>
76 <g id="resetDef">
77 <use xlink:href="#rim2" fill="#404040"><set attributeName="fill" to="#808080" begin="reset.mouseover" end="reset.mouseout"/></use>
78 </g>
79</defs>
80)svg";
81
82// part of the footer that is needed if the navigation panel is shown
83static const char svgZoomFooter1[] = R"svg(
84<g id="navigator" transform="translate(0 0)" fill="#404254">
85 <rect fill="#f2f5e9" fill-opacity="0.5" stroke="#606060" stroke-width=".5" x="0" y="0" width="60" height="60"/>
86 <use id="zoomplus" xlink:href="#zoomPlus" x="17" y="9" data-zoom="in"/>
87 <use id="zoomminus" xlink:href="#zoomMin" x="42" y="9" data-zoom="out"/>
88 <use id="reset" xlink:href="#resetDef" x="30" y="36" data-reset="true"/>
89 <use id="arrowup" xlink:href="#arrowUp" x="0" y="0" data-pan-x="0" data-pan-y="-1"/>
90 <use id="arrowright" xlink:href="#arrowRight" x="0" y="0" data-pan-x="1" data-pan-y="0"/>
91 <use id="arrowdown" xlink:href="#arrowDown" x="0" y="0" data-pan-x="0" data-pan-y="1"/>
92 <use id="arrowleft" xlink:href="#arrowLeft" x="0" y="0" data-pan-x="-1" data-pan-y="0"/>
93</g>
94<svg viewBox="0 0 15 15" width="100%" height="30px" preserveAspectRatio="xMaxYMin meet">
95 <g id="arrow_out" transform="scale(0.3 0.3)">
96 <a xlink:href="$orgname" target="_base">
97 <rect id="button" ry="5" rx="5" y="6" x="6" height="38" width="38"
98 fill="#f2f5e9" fill-opacity="0.5" stroke="#606060" stroke-width="1.0"/>
99 <path id="arrow"
100 d="M 11.500037,31.436501 C 11.940474,20.09759 22.043105,11.32322 32.158766,21.979434 L 37.068811,17.246167 C 37.068811,17.246167 37.088388,32 37.088388,32 L 22.160133,31.978069 C 22.160133,31.978069 26.997745,27.140456 26.997745,27.140456 C 18.528582,18.264221 13.291696,25.230495 11.500037,31.436501 z"
101 style="fill:#404040;"/>
102 </a>
103 </g>
104</svg>
105)svg";
106
107// generic part of the interactive SVG footer
108static const char svgZoomFooter2[] = R"svg(
109<style type='text/css'>
110<![CDATA[
111[data-mouse-over-selected='false'] { opacity: 0.7; }
112[data-mouse-over-selected='true'] { opacity: 1.0; }
113]]>
114</style>
115</svg>
116)svg";
117
118static DString replaceRef(const DString &buf,const DString &relPath,
119 bool urlOnly,const DString &context,const DString &target=DString())
120{
121 // search for href="...", store ... part in link
122 DString href = "href";
123 //bool isXLink=false;
124 int len = 6;
125 size_t indexS = buf.find("href=\""), indexE = 0;
126 bool targetAlreadySet = buf.find("target=")!=DString::npos;
127 if (indexS>5 && buf.find("xlink:href=\"")!=DString::npos) // XLink href (for SVG)
128 {
129 indexS-=6;
130 len+=6;
131 href.prepend("xlink:");
132 //isXLink=true;
133 }
134 if (indexS!=DString::npos && (indexE=buf.find('"',indexS+len))!=DString::npos)
135 {
136 DString link = buf.mid(indexS+len,indexE-indexS-len);
137 DString result;
138 if (urlOnly) // for user defined dot graphs
139 {
140 if (link.startsWith("\\ref ") || link.startsWith("@ref ")) // \ref url
141 {
142 result=href+"=\"";
143 // fake ref node to resolve the url
144 auto parser { createDocParser() };
145 auto dfAst { createRef( *parser.get(), link.mid(5), context ) };
146 auto dfAstImpl = dynamic_cast<const DocNodeAST*>(dfAst.get());
147 const DocRef *df = std::get_if<DocRef>(&dfAstImpl->root);
148 result+=externalRef(relPath,df->ref(),true);
149 if (!df->file().empty())
150 {
151 DString fn = df->file();
153 result += fn;
154 }
155 if (!df->anchor().empty())
156 {
157 result += "#" + df->anchor();
158 }
159 result += "\"";
160 }
161 else
162 {
163 result = href+"=\"" + link + "\"";
164 }
165 }
166 else // ref$url (external ref via tag file), or $url (local ref)
167 {
168 size_t marker = link.find('$');
169 if (marker!=DString::npos)
170 {
171 DString ref = link.left(marker);
172 DString url = link.mid(marker+1);
173 if (!ref.empty())
174 {
175 result = externalLinkTarget(true);
176 if (!result.empty())targetAlreadySet=true;
177 }
178 result+= href+"=\"";
179 result+=externalRef(relPath,ref,true);
180 result+= url + "\"";
181 }
182 else // should not happen, but handle properly anyway
183 {
184 result = href+"=\"" + link + "\"";
185 }
186 }
187 if (!target.empty() && !targetAlreadySet)
188 {
189 result+=" target=\""+target+"\"";
190 }
191 DString leftPart = buf.left(indexS);
192 DString rightPart = buf.mid(indexE+1);
193 //printf("replaceRef(\n'%s'\n)->\n'%s+%s+%s'\n",
194 // qPrint(buf),qPrint(leftPart),qPrint(result),qPrint(rightPart));
195 return leftPart + result + rightPart;
196 }
197 else
198 {
199 return buf;
200 }
201}
202
203/*! converts the rectangles in a client site image map into a stream
204* \param t the stream to which the result is written.
205* \param mapName the name of the map file.
206* \param relPath the relative path to the root of the output directory
207* (used in case CREATE_SUBDIRS is enabled).
208* \param urlOnly if false the url field in the map contains an external
209* references followed by a $ and then the URL.
210* \param context the context (file, class, or namespace) in which the
211* map file was found
212* \returns true if successful.
213*/
215 const DString &relPath, bool urlOnly,
216 const DString &context)
217{
218 std::ifstream f = Portable::openInputStream(mapName);
219 if (!f.is_open())
220 {
221 err("problems opening map file {} 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",mapName);
224 return false;
225 }
226 std::string line;
227 while (getline(f,line)) // foreach line
228 {
229 DString buf = line+'\n';
230 if (buf.startsWith("<area"))
231 {
232 DString replBuf = replaceRef(buf,relPath,urlOnly,context);
233 // in dot version 7.0.2 the alt attribute is, incorrectly, removed.
234 // see https://gitlab.com/graphviz/graphviz/-/issues/265
235 if (size_t indexA = replBuf.find("alt="); indexA==DString::npos)
236 {
237 replBuf = replBuf.left(5) + " alt=\"\"" + replBuf.mid(5);
238 }
239
240 // strip id="..." from replBuf since the id's are not needed and not unique.
241 if (size_t indexS = replBuf.find("id=\""), indexE = 0;
242 indexS!=DString::npos && indexS>0 && (indexE=replBuf.find('"',indexS+4))!=DString::npos)
243 {
244 t << replBuf.left(indexS-1) << replBuf.mid(indexE+1);
245 }
246 else
247 {
248 t << replBuf;
249 }
250 }
251 }
252 return true;
253}
254
256 : m_patchFile(patchFile)
257{
258}
259
261{
262 return m_patchFile.endsWith(".svg");
263}
264
265int DotFilePatcher::addMap(const DString &mapFile,const DString &relPath,
266 bool urlOnly,const DString &context,const DString &label)
267{
268 size_t id = m_maps.size();
269 m_maps.emplace_back(mapFile,relPath,urlOnly,context,label);
270 return static_cast<int>(id);
271}
272
274 const DString &figureName,bool heightCheck)
275{
276 size_t id = m_maps.size();
277 m_maps.emplace_back(figureName,"",heightCheck,"",baseName);
278 return static_cast<int>(id);
279}
280
281int DotFilePatcher::addSVGConversion(const DString &relPath,bool urlOnly,
282 const DString &context,bool zoomable,
283 int graphId)
284{
285 size_t id = m_maps.size();
286 m_maps.emplace_back("",relPath,urlOnly,context,"",zoomable,graphId);
287 return static_cast<int>(id);
288}
289
291 const DString &absImgName,
292 const DString &relPath)
293{
294 size_t id = m_maps.size();
295 m_maps.emplace_back(absImgName,relPath,false,"",baseName);
296 return static_cast<int>(id);
297}
298
300{
301 //printf("DotFilePatcher::run(): %s\n",qPrint(m_patchFile));
302 bool interactiveSVG = Config_getBool(INTERACTIVE_SVG);
303 bool isSVGFile = m_patchFile.endsWith(".svg");
304 int graphId = -1;
305 DString relPath;
306 if (isSVGFile)
307 {
308 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
309 interactiveSVG = interactiveSVG && map.zoomable;
310 graphId = map.graphId;
311 relPath = map.relPath;
312 //printf("DotFilePatcher::addSVGConversion: file=%s zoomable=%d\n",
313 // qPrint(m_patchFile),map->zoomable);
314 }
315 DString tmpName = m_patchFile+".tmp";
316 Dir thisDir;
317 if (!thisDir.rename(m_patchFile.str(),tmpName.str()))
318 {
319 err("Failed to rename file {} to {}!\n",m_patchFile,tmpName);
320 return false;
321 }
322 std::ifstream fi = Portable::openInputStream(tmpName);
323 std::ofstream fo = Portable::openOutputStream(m_patchFile);
324 if (!fi.is_open())
325 {
326 err("problem opening file {} for patching!\n",tmpName);
327 thisDir.rename(tmpName.str(),m_patchFile.str());
328 return false;
329 }
330 if (!fo.is_open())
331 {
332 err("problem opening file {} for patching!\n",m_patchFile);
333 thisDir.rename(tmpName.str(),m_patchFile.str());
334 return false;
335 }
336 TextStream t(&fo);
337 int width=0,height=0;
338 bool insideHeader=false;
339 bool replacedHeader=false;
340 bool useNagivation=false;
341 std::string lineStr;
342 static const reg::Ex reSVG(R"([\‍[<]!-- SVG [0-9]+)");
343 static const reg::Ex reMAP(R"(<!-- MAP [0-9]+)");
344 static const reg::Ex reFIG(R"(% FIG [0-9]+)");
345
346 while (getline(fi,lineStr))
347 {
348 // replace id="page0,1_graph0" with id="graph0" to work around graphviz page numbering bug
349 {
350 auto pos = lineStr.find("id=\"page0,1_graph0\"");
351 if (pos != std::string::npos)
352 lineStr.replace(pos, 19, "id=\"graph0\"");
353 }
354 DString line = lineStr+'\n';
355 //printf("line=[%s]\n",qPrint(line.stripWhiteSpace()));
356 size_t i = 0;
357 if (isSVGFile)
358 {
359 if (interactiveSVG)
360 {
361 if (line.find("<svg")!=DString::npos && !replacedHeader)
362 {
363 int count = sscanf(line.data(),"<svg width=\"%dpt\" height=\"%dpt\"",&width,&height);
364 if (count != 2) count = sscanf(line.data(),"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%d\" height=\"%d\"",&width,&height);
365 //printf("width=%d height=%d\n",width,height);
366 useNagivation = count==2 && (width>500 || height>450);
367 insideHeader = count==2;
368 }
369 else if (insideHeader && !replacedHeader && line.find("<g id=\"graph")!=DString::npos)
370 {
371 if (useNagivation)
372 {
373 // insert special replacement header for interactive SVGs
374 t << "<!--zoomable " << height << " -->\n";
375 t << svgZoomHeader0;
376 }
377 else
378 {
380 }
381 t << svgZoomHeader1;
382 if (useNagivation)
383 {
384 t << svgZoomHeader2;
385 }
386 t << "<script type=\"application/ecmascript\" xlink:href=\"" << relPath << "svg.min.js\"/>\n";
387 t << "<svg id=\"graph\" class=\"graph\"";
388 if (useNagivation)
389 {
390 t << " data-view-width=\"" << width << "\" data-view-height=\"" << height << "\"";
391 if (graphId>=0)
392 {
393 t << " data-section-id=\"dynsection-" << graphId << "\"";
394 }
395 }
396 t << ">\n";
397
398 if (useNagivation)
399 {
400 t << "<g id=\"viewport\">\n";
401 }
402 else
403 {
404 t << line;
405 }
406 line="";
407 insideHeader=false;
408 replacedHeader=true;
409 }
410 }
411 if (!insideHeader || !useNagivation) // copy SVG and replace refs,
412 // unless we are inside the header of the SVG.
413 // Then we replace it with another header.
414 {
415 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
416 t << replaceRef(line,map.relPath,map.urlOnly,map.context,"_top");
417 }
418 }
419 else if (line.find("SVG")!=DString::npos && (i=findIndex(line.str(),reSVG))!=std::string::npos)
420 {
421 //printf("Found marker at %d\n",i);
422 int mapId=-1;
423 t << line.left(i);
424 int n = sscanf(line.data()+i+1,"!-- SVG %d",&mapId);
425 if (n==1 && mapId>=0 && mapId<static_cast<int>(m_maps.size()))
426 {
427 size_t e0 = line.find("--]");
428 size_t e1 = line.find("-->");
429 size_t e = e0!=DString::npos && e1!=DString::npos ? std::max(e0,e1) :
430 e0!=DString::npos ? e0 : e1;
431 const Map &map = m_maps.at(mapId);
432 //printf("DotFilePatcher::writeSVGFigure: file=%s zoomable=%d\n",
433 // qPrint(m_patchFile),map.zoomable);
434 if (!writeSVGFigureLink(t,map.relPath,map.label,map.mapFile))
435 {
436 err("Problem extracting size from SVG file {}\n",map.mapFile);
437 }
438 if (e!=DString::npos) t << line.mid(e+3);
439 }
440 else // error invalid map id!
441 {
442 err("Found invalid SVG id in file {}!\n",m_patchFile);
443 t << line.mid(i);
444 }
445 }
446 else if (line.find("MAP")!=DString::npos && (i=findIndex(line.str(),reMAP))!=std::string::npos)
447 {
448 int mapId=-1;
449 t << line.left(i);
450 int n = sscanf(line.data()+i,"<!-- MAP %d",&mapId);
451 if (n==1 && mapId>=0 && mapId<static_cast<int>(m_maps.size()))
452 {
453 TextStream tt;
454 const Map &map = m_maps.at(mapId);
455 //printf("patching MAP %d in file %s with contents of %s\n",
456 // mapId,qPrint(m_patchFile),qPrint(map.mapFile));
457 convertMapFile(tt,map.mapFile,map.relPath,map.urlOnly,map.context);
458 if (!tt.empty())
459 {
460 t << "<map name=\"" << mapLabelToId(map.label) << "\" id=\"" << mapLabelToId(map.label) << "\">\n";
461 t << tt.str();
462 t << "</map>\n";
463 }
464 }
465 else // error invalid map id!
466 {
467 err("Found invalid MAP id in file {}!\n",m_patchFile);
468 t << line.mid(i);
469 }
470 }
471 else if (line.find("FIG")!=DString::npos && (i=findIndex(line.str(),reFIG))!=std::string::npos)
472 {
473 int mapId=-1;
474 int n = sscanf(line.data()+i+2,"FIG %d",&mapId);
475 //printf("line='%s' n=%d\n",qPrint(line)+i,n);
476 if (n==1 && mapId>=0 && mapId<static_cast<int>(m_maps.size()))
477 {
478 const Map &map = m_maps.at(mapId);
479 //printf("patching FIG %d in file %s with contents of %s\n",
480 // mapId,qPrint(m_patchFile),qPrint(map.mapFile));
481 if (!writeVecGfxFigure(t,map.label,map.mapFile))
482 {
483 err("problem writing FIG {} figure!\n",mapId);
484 return false;
485 }
486 }
487 else // error invalid map id!
488 {
489 err("Found invalid bounding FIG {} in file {}!\n",mapId,m_patchFile);
490 t << line;
491 }
492 }
493 else
494 {
495 t << line;
496 }
497 }
498 if (isSVGFile && interactiveSVG && !useNagivation) t << "</svg>\n";
499
500 fi.close();
501 if (isSVGFile && interactiveSVG && replacedHeader)
502 {
503 DString orgName=m_patchFile.left(m_patchFile.length()-4)+"_org.svg";
504 if (useNagivation)
505 {
506 t << substitute(svgZoomFooter1,"$orgname",stripPath(orgName));
507 }
508 t << svgZoomFooter2;
509 t.flush();
510 fo.close();
511 // keep original SVG file so we can refer to it, we do need to replace
512 // dummy link by real ones
513 fi = Portable::openInputStream(tmpName);
514 fo = Portable::openOutputStream(orgName);
515 if (!fi.is_open())
516 {
517 err("problem opening file {} for reading!\n",tmpName);
518 return false;
519 }
520 if (!fo.is_open())
521 {
522 err("problem opening file {} for writing!\n",orgName);
523 return false;
524 }
525 t.setStream(&fo);
526 while (getline(fi,lineStr)) // foreach line
527 {
528 DString line = lineStr+'\n';
529 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
530 t << replaceRef(line,map.relPath,map.urlOnly,map.context,"_top");
531 }
532 t.flush();
533 fi.close();
534 fo.close();
535 }
536 // remove temporary file
537 thisDir.remove(tmpName.str());
538 return true;
539}
540
541//---------------------------------------------------------------------------------------------
542
543
544// extract size from a dot generated SVG file
545static bool readSVGSize(const DString &fileName,int *width,int *height)
546{
547 bool found=false;
548 std::ifstream f = Portable::openInputStream(fileName);
549 if (!f.is_open())
550 {
551 return false;
552 }
553 std::string line;
554 while (getline(f,line) && !found)
555 {
556 if (literal_at(line.c_str(),"<!--zoomable "))
557 {
558 *width=-1;
559 *height=-1;
560 sscanf(line.c_str(),"<!--zoomable %d",height);
561 found=true;
562 }
563 else if (sscanf(line.c_str(),"<svg width=\"%dpt\" height=\"%dpt\"",width,height)==2)
564 {
565 found=true;
566 }
567 else if (sscanf(line.c_str(),"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%d\" height=\"%d\"",width,height)==2)
568 {
569 found=true;
570 }
571 }
572 return true;
573}
574
576{
577 out << "<p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p>";
578}
579
580/// Check if a reference to a SVG figure can be written and do so if possible.
581/// Returns false if not possible (for instance because the SVG file is not yet generated).
583 const DString &baseName,const DString &absImgName)
584{
585 int width=600,height=600;
586 if (!readSVGSize(absImgName,&width,&height))
587 {
588 return false;
589 }
590 if (width==-1)
591 {
592 if (height<=60) height=300; else height+=300; // add some extra space for zooming
593 if (height>600) height=600; // clip to maximum height of 600 pixels
594 out << "<div class=\"zoom\">";
595 //out << "<object type=\"image/svg+xml\" data=\""
596 //out << "<embed type=\"image/svg+xml\" src=\""
597 out << "<iframe scrolling=\"no\" loading=\"lazy\" frameborder=\"0\" src=\""
598 << relPath << baseName << ".svg\" width=\"100%\" height=\"" << height << "\">";
599 }
600 else
601 {
602 //out << "<object type=\"image/svg+xml\" data=\""
603 //out << "<embed type=\"image/svg+xml\" src=\""
604 out << "<iframe scrolling=\"no\" loading=\"lazy\" frameborder=\"0\" src=\""
605 << relPath << baseName << ".svg\" width=\""
606 << ((width*96+48)/72) << "\" height=\""
607 << ((height*96+48)/72) << "\">";
608 }
610 //out << "</object>";
611 //out << "</embed>";
612 out << "</iframe>";
613 if (width==-1)
614 {
615 out << "</div>";
616 }
617
618 return true;
619}
620
622 const DString &figureName)
623{
624 int width=400,height=550;
625 if (Config_getBool(USE_PDFLATEX))
626 {
627 if (!DotRunner::readBoundingBox(figureName+".pdf",&width,&height,false))
628 {
629 //printf("writeVecGfxFigure()=0\n");
630 return false;
631 }
632 }
633 else
634 {
635 if (!DotRunner::readBoundingBox(figureName+".eps",&width,&height,true))
636 {
637 //printf("writeVecGfxFigure()=0\n");
638 return false;
639 }
640 }
641 //printf("Got PDF/EPS size %d,%d\n",width,height);
642 int maxWidth = 350; /* approx. page width in points, excl. margins */
643 int maxHeight = 550; /* approx. page height in points, excl. margins */
644 out << "\\nopagebreak\n"
645 "\\begin{figure}[H]\n"
646 "\\begin{center}\n"
647 "\\leavevmode\n";
648 if (width>maxWidth || height>maxHeight) // figure too big for page
649 {
650 // c*width/maxWidth > c*height/maxHeight, where c=maxWidth*maxHeight>0
651 if (width*maxHeight>height*maxWidth)
652 {
653 out << "\\includegraphics[width=" << maxWidth << "pt]";
654 }
655 else
656 {
657 out << "\\includegraphics[height=" << maxHeight << "pt]";
658 }
659 }
660 else
661 {
662 out << "\\includegraphics[width=" << width << "pt]";
663 }
664
665 out << "{" << baseName << "}\n"
666 "\\end{center}\n"
667 "\\end{figure}\n";
668
669 //printf("writeVecGfxFigure()=1\n");
670 return true;
671}
672
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:89
DString()=default
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:323
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:153
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:183
DString & prepend(const char *s)
Definition dstring.h:504
size_t find(char c, size_t pos=0) const
Definition dstring.h:244
DString left(size_t len) const
Definition dstring.h:311
const std::string & str() const
Definition dstring.h:634
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:162
bool startsWith(const char *s) const
Definition dstring.h:589
bool endsWith(const char *s) const
Definition dstring.h:606
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:156
Class representing a directory in the file system.
Definition dir.h:75
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
Class representing the abstract syntax tree of a documentation block.
Definition docnode.h:1471
Node representing a reference to some item.
Definition docnode.h:787
DString ref() const
Definition docnode.h:793
DString file() const
Definition docnode.h:791
DString anchor() const
Definition docnode.h:794
int addMap(const DString &mapFile, const DString &relPath, bool urlOnly, const DString &context, const DString &label)
static DString mapLabelToId(const DString &mapLabel)
bool isSVGFile() const
std::vector< Map > m_maps
DotFilePatcher(const DString &patchFile)
static bool writeVecGfxFigure(TextStream &out, const DString &baseName, const DString &figureName)
int addSVGConversion(const DString &relPath, bool urlOnly, const DString &context, bool zoomable, int graphId)
static bool writeSVGFigureLink(TextStream &out, const DString &relPath, const DString &baseName, const DString &absImgName)
Check if a reference to a SVG figure can be written and do so if possible.
static bool convertMapFile(TextStream &t, const DString &mapName, const DString &relPath, bool urlOnly=false, const DString &context=DString())
int addSVGObject(const DString &baseName, const DString &figureName, const DString &relPath)
int addFigure(const DString &baseName, const DString &figureName, bool heightCheck)
static bool readBoundingBox(const DString &fileName, int *width, int *height, bool isEps)
Text streaming class that buffers data.
Definition textstream.h:36
bool empty() const
Returns true iff the buffer is empty.
Definition textstream.h:256
void setStream(std::ostream *s)
Sets or changes the std::ostream to write to.
Definition textstream.h:67
void flush()
Flushes the buffer.
Definition textstream.h:212
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:232
Class representing a regular expression.
Definition regex.h:39
#define Config_getBool(name)
Definition config.h:33
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:56
IDocNodeASTPtr createRef(IDocParser &parserIntf, const DString &target, const DString &context, const DString &srcFile, int srcLine)
static void writeSVGNotSupported(TextStream &out)
static const char svgZoomHeader1[]
static const char svgZoomHeader2[]
static DString replaceRef(const DString &buf, const DString &relPath, bool urlOnly, const DString &context, const DString &target=DString())
static const char svgZoomHeader0_noinit[]
static const char svgZoomFooter2[]
static bool readSVGSize(const DString &fileName, int *width, int *height)
static const char svgZoomHeader0[]
static const char svgZoomFooter1[]
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:480
#define err(fmt,...)
Definition message.h:127
std::ifstream openInputStream(const DString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:659
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:648
Portable versions of functions that are platform dependent.
Some helper functions for std::string.
size_t findIndex(const StringVector &sv, const std::string &s)
find the index of a string in a vector of strings, returns std::string::npos if the string could not ...
Definition stringutil.h:167
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
Definition stringutil.h:101
DString externalLinkTarget(const bool parent)
Definition util.cpp:5049
DString externalRef(const DString &relPath, const DString &ref, bool href)
Definition util.cpp:5097
void addHtmlExtensionIfMissing(DString &fName)
Definition util.cpp:4260
DString stripPath(const DString &s)
Definition util.cpp:4289
A bunch of utility functions.