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" onload="init(evt)">
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" onmousedown="handleZoom(evt,'in')"/>
87 <use id="zoomminus" xlink:href="#zoomMin" x="42" y="9" onmousedown="handleZoom(evt,'out')"/>
88 <use id="reset" xlink:href="#resetDef" x="30" y="36" onmousedown="handleReset()"/>
89 <use id="arrowup" xlink:href="#arrowUp" x="0" y="0" onmousedown="handlePan(0,-1)"/>
90 <use id="arrowright" xlink:href="#arrowRight" x="0" y="0" onmousedown="handlePan(1,0)"/>
91 <use id="arrowdown" xlink:href="#arrowDown" x="0" y="0" onmousedown="handlePan(0,1)"/>
92 <use id="arrowleft" xlink:href="#arrowLeft" x="0" y="0" onmousedown="handlePan(-1,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<script type="application/ecmascript"><![CDATA[
116document.addEventListener('DOMContentLoaded', (event) => {
117 highlightEdges();
118 highlightAdjacentNodes();
119});
120]]></script>
121</svg>
122)svg";
123
124static QCString replaceRef(const QCString &buf,const QCString &relPath,
125 bool urlOnly,const QCString &context,const QCString &target=QCString())
126{
127 // search for href="...", store ... part in link
128 QCString href = "href";
129 //bool isXLink=FALSE;
130 int len = 6;
131 int indexS = buf.find("href=\""), indexE = 0;
132 bool targetAlreadySet = buf.find("target=")!=-1;
133 if (indexS>5 && buf.find("xlink:href=\"")!=-1) // XLink href (for SVG)
134 {
135 indexS-=6;
136 len+=6;
137 href.prepend("xlink:");
138 //isXLink=TRUE;
139 }
140 if (indexS>=0 && (indexE=buf.find('"',indexS+len))!=-1)
141 {
142 QCString link = buf.mid(indexS+len,indexE-indexS-len);
143 QCString result;
144 if (urlOnly) // for user defined dot graphs
145 {
146 if (link.startsWith("\\ref ") || link.startsWith("@ref ")) // \ref url
147 {
148 result=href+"=\"";
149 // fake ref node to resolve the url
150 auto parser { createDocParser() };
151 auto dfAst { createRef( *parser.get(), link.mid(5), context ) };
152 auto dfAstImpl = dynamic_cast<const DocNodeAST*>(dfAst.get());
153 const DocRef *df = std::get_if<DocRef>(&dfAstImpl->root);
154 result+=externalRef(relPath,df->ref(),TRUE);
155 if (!df->file().isEmpty())
156 {
157 QCString fn = df->file();
159 result += fn;
160 }
161 if (!df->anchor().isEmpty())
162 {
163 result += "#" + df->anchor();
164 }
165 result += "\"";
166 }
167 else
168 {
169 result = href+"=\"" + link + "\"";
170 }
171 }
172 else // ref$url (external ref via tag file), or $url (local ref)
173 {
174 int marker = link.find('$');
175 if (marker!=-1)
176 {
177 QCString ref = link.left(marker);
178 QCString url = link.mid(marker+1);
179 if (!ref.isEmpty())
180 {
181 result = externalLinkTarget(true);
182 if (!result.isEmpty())targetAlreadySet=true;
183 }
184 result+= href+"=\"";
185 result+=externalRef(relPath,ref,TRUE);
186 result+= url + "\"";
187 }
188 else // should not happen, but handle properly anyway
189 {
190 result = href+"=\"" + link + "\"";
191 }
192 }
193 if (!target.isEmpty() && !targetAlreadySet)
194 {
195 result+=" target=\""+target+"\"";
196 }
197 QCString leftPart = buf.left(indexS);
198 QCString rightPart = buf.mid(indexE+1);
199 //printf("replaceRef(\n'%s'\n)->\n'%s+%s+%s'\n",
200 // qPrint(buf),qPrint(leftPart),qPrint(result),qPrint(rightPart));
201 return leftPart + result + rightPart;
202 }
203 else
204 {
205 return buf;
206 }
207}
208
209/*! converts the rectangles in a client site image map into a stream
210* \param t the stream to which the result is written.
211* \param mapName the name of the map file.
212* \param relPath the relative path to the root of the output directory
213* (used in case CREATE_SUBDIRS is enabled).
214* \param urlOnly if FALSE the url field in the map contains an external
215* references followed by a $ and then the URL.
216* \param context the context (file, class, or namespace) in which the
217* map file was found
218* \returns TRUE if successful.
219*/
221 const QCString &relPath, bool urlOnly,
222 const QCString &context)
223{
224 std::ifstream f = Portable::openInputStream(mapName);
225 if (!f.is_open())
226 {
227 err("problems opening map file {} for inclusion in the docs!\n"
228 "If you installed Graphviz/dot after a previous failing run, \n"
229 "try deleting the output directory and rerun doxygen.\n",mapName);
230 return FALSE;
231 }
232 std::string line;
233 while (getline(f,line)) // foreach line
234 {
235 QCString buf = line+'\n';
236 if (buf.startsWith("<area"))
237 {
238 QCString replBuf = replaceRef(buf,relPath,urlOnly,context);
239 // in dot version 7.0.2 the alt attribute is, incorrectly, removed.
240 // see https://gitlab.com/graphviz/graphviz/-/issues/265
241 int indexA = replBuf.find("alt=");
242 if (indexA == -1)
243 {
244 replBuf = replBuf.left(5) + " alt=\"\"" + replBuf.right(replBuf.length() - 5);
245 }
246
247 // strip id="..." from replBuf since the id's are not needed and not unique.
248 int indexS = replBuf.find("id=\""), indexE = 0;
249 if (indexS>0 && (indexE=replBuf.find('"',indexS+4))!=-1)
250 {
251 t << replBuf.left(indexS-1) << replBuf.right(replBuf.length() - indexE - 1);
252 }
253 else
254 {
255 t << replBuf;
256 }
257 }
258 }
259 return TRUE;
260}
261
263 : m_patchFile(patchFile)
264{
265}
266
268{
269 return m_patchFile.endsWith(".svg");
270}
271
272int DotFilePatcher::addMap(const QCString &mapFile,const QCString &relPath,
273 bool urlOnly,const QCString &context,const QCString &label)
274{
275 size_t id = m_maps.size();
276 m_maps.emplace_back(mapFile,relPath,urlOnly,context,label);
277 return static_cast<int>(id);
278}
279
281 const QCString &figureName,bool heightCheck)
282{
283 size_t id = m_maps.size();
284 m_maps.emplace_back(figureName,"",heightCheck,"",baseName);
285 return static_cast<int>(id);
286}
287
288int DotFilePatcher::addSVGConversion(const QCString &relPath,bool urlOnly,
289 const QCString &context,bool zoomable,
290 int graphId)
291{
292 size_t id = m_maps.size();
293 m_maps.emplace_back("",relPath,urlOnly,context,"",zoomable,graphId);
294 return static_cast<int>(id);
295}
296
298 const QCString &absImgName,
299 const QCString &relPath)
300{
301 size_t id = m_maps.size();
302 m_maps.emplace_back(absImgName,relPath,false,"",baseName);
303 return static_cast<int>(id);
304}
305
307{
308 //printf("DotFilePatcher::run(): %s\n",qPrint(m_patchFile));
309 bool interactiveSVG = Config_getBool(INTERACTIVE_SVG);
310 bool isSVGFile = m_patchFile.endsWith(".svg");
311 int graphId = -1;
312 QCString relPath;
313 if (isSVGFile)
314 {
315 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
316 interactiveSVG = interactiveSVG && map.zoomable;
317 graphId = map.graphId;
318 relPath = map.relPath;
319 //printf("DotFilePatcher::addSVGConversion: file=%s zoomable=%d\n",
320 // qPrint(m_patchFile),map->zoomable);
321 }
322 QCString tmpName = m_patchFile+".tmp";
323 Dir thisDir;
324 if (!thisDir.rename(m_patchFile.str(),tmpName.str()))
325 {
326 err("Failed to rename file {} to {}!\n",m_patchFile,tmpName);
327 return FALSE;
328 }
329 std::ifstream fi = Portable::openInputStream(tmpName);
330 std::ofstream fo = Portable::openOutputStream(m_patchFile);
331 if (!fi.is_open())
332 {
333 err("problem opening file {} for patching!\n",tmpName);
334 thisDir.rename(tmpName.str(),m_patchFile.str());
335 return FALSE;
336 }
337 if (!fo.is_open())
338 {
339 err("problem opening file {} for patching!\n",m_patchFile);
340 thisDir.rename(tmpName.str(),m_patchFile.str());
341 return FALSE;
342 }
343 TextStream t(&fo);
344 int width=0,height=0;
345 bool insideHeader=FALSE;
346 bool replacedHeader=FALSE;
347 bool useNagivation=FALSE;
348 std::string lineStr;
349 static const reg::Ex reSVG(R"([\[<]!-- SVG [0-9]+)");
350 static const reg::Ex reMAP(R"(<!-- MAP [0-9]+)");
351 static const reg::Ex reFIG(R"(% FIG [0-9]+)");
352
353 while (getline(fi,lineStr))
354 {
355 QCString line = lineStr+'\n';
356 //printf("line=[%s]\n",qPrint(line.stripWhiteSpace()));
357 int i = 0;
358 if (isSVGFile)
359 {
360 if (interactiveSVG)
361 {
362 if (line.find("<svg")!=-1 && !replacedHeader)
363 {
364 int count = sscanf(line.data(),"<svg width=\"%dpt\" height=\"%dpt\"",&width,&height);
365 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);
366 //printf("width=%d height=%d\n",width,height);
367 useNagivation = count==2 && (width>500 || height>450);
368 insideHeader = count==2;
369 }
370 else if (insideHeader && !replacedHeader && line.find("<g id=\"graph")!=-1)
371 {
372 if (useNagivation)
373 {
374 // insert special replacement header for interactive SVGs
375 t << "<!--zoomable " << height << " -->\n";
376 t << svgZoomHeader0;
377 }
378 else
379 {
381 }
382 t << svgZoomHeader1;
383 if (useNagivation)
384 {
385 t << svgZoomHeader2;
386 }
387 if (useNagivation)
388 {
389 t << "<script type=\"application/ecmascript\">\n";
390 t << "var viewWidth = " << width << ";\n";
391 t << "var viewHeight = " << height << ";\n";
392 if (graphId>=0)
393 {
394 t << "var sectionId = 'dynsection-" << graphId << "';\n";
395 }
396 t << "</script>\n";
397 }
398 t << "<script type=\"application/ecmascript\" xlink:href=\"" << relPath << "svg.min.js\"/>\n";
399 t << "<svg id=\"graph\" class=\"graph\">\n";
400
401 if (useNagivation)
402 {
403 t << "<g id=\"viewport\">\n";
404 }
405 else
406 {
407 t << line;
408 }
409 line="";
410 insideHeader=FALSE;
411 replacedHeader=TRUE;
412 }
413 }
414 if (!insideHeader || !useNagivation) // copy SVG and replace refs,
415 // unless we are inside the header of the SVG.
416 // Then we replace it with another header.
417 {
418 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
419 t << replaceRef(line,map.relPath,map.urlOnly,map.context,"_top");
420 }
421 }
422 else if (line.find("SVG")!=-1 && (i=findIndex(line.str(),reSVG))!=-1)
423 {
424 //printf("Found marker at %d\n",i);
425 int mapId=-1;
426 t << line.left(i);
427 int n = sscanf(line.data()+i+1,"!-- SVG %d",&mapId);
428 if (n==1 && mapId>=0 && mapId<static_cast<int>(m_maps.size()))
429 {
430 int e = std::max(line.find("--]"),line.find("-->"));
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!=-1) 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")!=-1 && (i=findIndex(line.str(),reMAP))!=-1)
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=\"" << correctId(map.label) << "\" id=\"" << correctId(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")!=-1 && (i=findIndex(line.str(),reFIG))!=-1)
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 QCString 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 std::string line = lineStr+'\n';
529 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
530 t << replaceRef(line.c_str(),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 QCString &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 QCString &baseName,const QCString &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\" 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\" 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 QCString &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}
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:1460
Node representing a reference to some item.
Definition docnode.h:772
QCString anchor() const
Definition docnode.h:779
QCString file() const
Definition docnode.h:776
QCString ref() const
Definition docnode.h:778
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
DotFilePatcher(const QCString &patchFile)
std::vector< Map > m_maps
int addSVGObject(const QCString &baseName, const QCString &figureName, const QCString &relPath)
int addMap(const QCString &mapFile, const QCString &relPath, bool urlOnly, const QCString &context, const QCString &label)
int addSVGConversion(const QCString &relPath, bool urlOnly, const QCString &context, bool zoomable, int graphId)
QCString m_patchFile
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.
int addFigure(const QCString &baseName, const QCString &figureName, bool heightCheck)
static bool readBoundingBox(const QCString &fileName, int *width, int *height, bool isEps)
This is an alternative implementation of QCString.
Definition qcstring.h:101
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
QCString & prepend(const char *s)
Definition qcstring.h:407
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 mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:537
QCString right(size_t len) const
Definition qcstring.h:219
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
QCString left(size_t len) const
Definition qcstring.h:214
Text streaming class that buffers data.
Definition textstream.h:36
bool empty() const
Returns true iff the buffer is empty.
Definition textstream.h:253
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:209
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:229
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:55
IDocNodeASTPtr createRef(IDocParser &parserIntf, const QCString &target, const QCString &context, const QCString &srcFile, int srcLine)
static bool readSVGSize(const QCString &fileName, int *width, int *height)
static void writeSVGNotSupported(TextStream &out)
static const char svgZoomHeader1[]
static const char svgZoomHeader2[]
static QCString replaceRef(const QCString &buf, const QCString &relPath, bool urlOnly, const QCString &context, const QCString &target=QCString())
static const char svgZoomHeader0_noinit[]
static const char svgZoomFooter2[]
static const char svgZoomHeader0[]
static const char svgZoomFooter1[]
#define err(fmt,...)
Definition message.h:127
std::ifstream openInputStream(const QCString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:676
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:665
Portable versions of functions that are platform dependent.
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
Some helper functions for std::string.
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:98
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition util.cpp:6222
QCString stripPath(const QCString &s)
Definition util.cpp:5448
bool found
Definition util.cpp:984
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:7141
QCString correctId(const QCString &s)
Definition util.cpp:4405
QCString externalLinkTarget(const bool parent)
Definition util.cpp:6178
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5399
A bunch of utility functions.