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
28// top part of the interactive SVG header
29static const char svgZoomHeader0[] = R"svg(
30<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)">
31)svg";
32
33static const char svgZoomHeader0_noinit[] = R"svg(
34<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
35)svg";
36
37static const char svgZoomHeader1[] = R"svg(
38<style type="text/css"><![CDATA[
39.node, .edge {opacity: 0.7;}
40.node.selected, .edge.selected {opacity: 1;}
41.edge:hover path { stroke: red; }
42.edge:hover polygon { stroke: red; fill: red; }
43]]></style>
44)svg";
45
46// conditional part of the interactive SVG header in case the navigation panel is shown
47static const char svgZoomHeader2[] = R"svg(
48<defs>
49 <circle id="rim" cx="0" cy="0" r="7"/>
50 <circle id="rim2" cx="0" cy="0" r="3.5"/>
51 <g id="zoomPlus">
52 <use xlink:href="#rim" fill="#404040"><set attributeName="fill" to="#808080" begin="zoomplus.mouseover" end="zoomplus.mouseout"/></use>
53 <path d="M-4,0h8M0,-4v8" fill="none" stroke="white" stroke-width="1.5" pointer-events="none"/>
54 </g>
55 <g id="zoomMin">
56 <use xlink:href="#rim" fill="#404040"><set attributeName="fill" to="#808080" begin="zoomminus.mouseover" end="zoomminus.mouseout"/></use>
57 <path d="M-4,0h8" fill="none" stroke="white" stroke-width="1.5" pointer-events="none"/>
58 </g>
59 <g id="arrowUp" transform="translate(30 24)">
60 <use xlink:href="#rim"/>
61 <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"/>
62 </g>
63 <g id="arrowRight" transform="rotate(90) translate(36 -43)">
64 <use xlink:href="#rim"/>
65 <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"/>
66 </g>
67 <g id="arrowDown" transform="rotate(180) translate(-30 -48)">
68 <use xlink:href="#rim"/>
69 <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"/>
70 </g>
71 <g id="arrowLeft" transform="rotate(270) translate(-36 17)">
72 <use xlink:href="#rim"/>
73 <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"/>
74 </g>
75 <g id="resetDef">
76 <use xlink:href="#rim2" fill="#404040"><set attributeName="fill" to="#808080" begin="reset.mouseover" end="reset.mouseout"/></use>
77 </g>
78</defs>
79)svg";
80
81// part of the footer that is needed if the navigation panel is shown
82static const char svgZoomFooter1[] = R"svg(
83<g id="navigator" transform="translate(0 0)" fill="#404254">
84 <rect fill="#f2f5e9" fill-opacity="0.5" stroke="#606060" stroke-width=".5" x="0" y="0" width="60" height="60"/>
85 <use id="zoomplus" xlink:href="#zoomPlus" x="17" y="9" onmousedown="handleZoom(evt,'in')"/>
86 <use id="zoomminus" xlink:href="#zoomMin" x="42" y="9" onmousedown="handleZoom(evt,'out')"/>
87 <use id="reset" xlink:href="#resetDef" x="30" y="36" onmousedown="handleReset()"/>
88 <use id="arrowup" xlink:href="#arrowUp" x="0" y="0" onmousedown="handlePan(0,-1)"/>
89 <use id="arrowright" xlink:href="#arrowRight" x="0" y="0" onmousedown="handlePan(1,0)"/>
90 <use id="arrowdown" xlink:href="#arrowDown" x="0" y="0" onmousedown="handlePan(0,1)"/>
91 <use id="arrowleft" xlink:href="#arrowLeft" x="0" y="0" onmousedown="handlePan(-1,0)"/>
92</g>
93<svg viewBox="0 0 15 15" width="100%" height="30px" preserveAspectRatio="xMaxYMin meet">
94 <g id="arrow_out" transform="scale(0.3 0.3)">
95 <a xlink:href="$orgname" target="_base">
96 <rect id="button" ry="5" rx="5" y="6" x="6" height="38" width="38"
97 fill="#f2f5e9" fill-opacity="0.5" stroke="#606060" stroke-width="1.0"/>
98 <path id="arrow"
99 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"
100 style="fill:#404040;"/>
101 </a>
102 </g>
103</svg>
104)svg";
105
106// generic part of the interactive SVG footer
107static const char svgZoomFooter2[] = R"svg(
108<style type='text/css'>
109<![CDATA[
110[data-mouse-over-selected='false'] { opacity: 0.7; }
111[data-mouse-over-selected='true'] { opacity: 1.0; }
112]]>
113</style>
114<script type="application/ecmascript"><![CDATA[
115document.addEventListener('DOMContentLoaded', (event) => {
116 highlightEdges();
117 highlightAdjacentNodes();
118});
119]]></script>
120</svg>
121)svg";
122
123static QCString replaceRef(const QCString &buf,const QCString &relPath,
124 bool urlOnly,const QCString &context,const QCString &target=QCString())
125{
126 // search for href="...", store ... part in link
127 QCString href = "href";
128 //bool isXLink=FALSE;
129 int len = 6;
130 int indexS = buf.find("href=\""), indexE = 0;
131 bool targetAlreadySet = buf.find("target=")!=-1;
132 if (indexS>5 && buf.find("xlink:href=\"")!=-1) // XLink href (for SVG)
133 {
134 indexS-=6;
135 len+=6;
136 href.prepend("xlink:");
137 //isXLink=TRUE;
138 }
139 if (indexS>=0 && (indexE=buf.find('"',indexS+len))!=-1)
140 {
141 QCString link = buf.mid(indexS+len,indexE-indexS-len);
142 QCString result;
143 if (urlOnly) // for user defined dot graphs
144 {
145 if (link.startsWith("\\ref ") || link.startsWith("@ref ")) // \ref url
146 {
147 result=href+"=\"";
148 // fake ref node to resolve the url
149 auto parser { createDocParser() };
150 auto dfAst { createRef( *parser.get(), link.mid(5), context ) };
151 auto dfAstImpl = dynamic_cast<const DocNodeAST*>(dfAst.get());
152 const DocRef *df = std::get_if<DocRef>(&dfAstImpl->root);
153 result+=externalRef(relPath,df->ref(),TRUE);
154 if (!df->file().isEmpty())
155 {
156 QCString fn = df->file();
158 result += fn;
159 }
160 if (!df->anchor().isEmpty())
161 {
162 result += "#" + df->anchor();
163 }
164 result += "\"";
165 }
166 else
167 {
168 result = href+"=\"" + link + "\"";
169 }
170 }
171 else // ref$url (external ref via tag file), or $url (local ref)
172 {
173 int marker = link.find('$');
174 if (marker!=-1)
175 {
176 QCString ref = link.left(marker);
177 QCString url = link.mid(marker+1);
178 if (!ref.isEmpty())
179 {
180 result = externalLinkTarget(true);
181 if (!result.isEmpty())targetAlreadySet=true;
182 }
183 result+= href+"=\"";
184 result+=externalRef(relPath,ref,TRUE);
185 result+= url + "\"";
186 }
187 else // should not happen, but handle properly anyway
188 {
189 result = href+"=\"" + link + "\"";
190 }
191 }
192 if (!target.isEmpty() && !targetAlreadySet)
193 {
194 result+=" target=\""+target+"\"";
195 }
196 QCString leftPart = buf.left(indexS);
197 QCString rightPart = buf.mid(indexE+1);
198 //printf("replaceRef(\n'%s'\n)->\n'%s+%s+%s'\n",
199 // qPrint(buf),qPrint(leftPart),qPrint(result),qPrint(rightPart));
200 return leftPart + result + rightPart;
201 }
202 else
203 {
204 return buf;
205 }
206}
207
208/*! converts the rectangles in a client site image map into a stream
209* \param t the stream to which the result is written.
210* \param mapName the name of the map file.
211* \param relPath the relative path to the root of the output directory
212* (used in case CREATE_SUBDIRS is enabled).
213* \param urlOnly if FALSE the url field in the map contains an external
214* references followed by a $ and then the URL.
215* \param context the context (file, class, or namespace) in which the
216* map file was found
217* \returns TRUE if successful.
218*/
220 const QCString &relPath, bool urlOnly,
221 const QCString &context)
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}
260
262 : m_patchFile(patchFile)
263{
264}
265
267{
268 return m_patchFile.endsWith(".svg");
269}
270
271int DotFilePatcher::addMap(const QCString &mapFile,const QCString &relPath,
272 bool urlOnly,const QCString &context,const QCString &label)
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}
278
280 const QCString &figureName,bool heightCheck)
281{
282 size_t id = m_maps.size();
283 m_maps.emplace_back(figureName,"",heightCheck,"",baseName);
284 return static_cast<int>(id);
285}
286
287int DotFilePatcher::addSVGConversion(const QCString &relPath,bool urlOnly,
288 const QCString &context,bool zoomable,
289 int graphId)
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}
295
297 const QCString &absImgName,
298 const QCString &relPath)
299{
300 size_t id = m_maps.size();
301 m_maps.emplace_back(absImgName,relPath,false,"",baseName);
302 return static_cast<int>(id);
303}
304
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}
538
539//---------------------------------------------------------------------------------------------
540
541
542// extract size from a dot generated SVG file
543static bool readSVGSize(const QCString &fileName,int *width,int *height)
544{
545 bool found=FALSE;
546 std::ifstream f = Portable::openInputStream(fileName);
547 if (!f.is_open())
548 {
549 return false;
550 }
551 std::string line;
552 while (getline(f,line) && !found)
553 {
554 if (qstrncmp(line.c_str(),"<!--zoomable ",13)==0)
555 {
556 *width=-1;
557 *height=-1;
558 sscanf(line.c_str(),"<!--zoomable %d",height);
559 found=true;
560 }
561 else if (sscanf(line.c_str(),"<svg width=\"%dpt\" height=\"%dpt\"",width,height)==2)
562 {
563 found=true;
564 }
565 }
566 return true;
567}
568
570{
571 out << "<p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p>";
572}
573
574/// Check if a reference to a SVG figure can be written and do so if possible.
575/// Returns FALSE if not possible (for instance because the SVG file is not yet generated).
577 const QCString &baseName,const QCString &absImgName)
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}
614
616 const QCString &figureName)
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}
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:1446
Node representing a reference to some item.
Definition docnode.h:758
QCString anchor() const
Definition docnode.h:765
QCString file() const
Definition docnode.h:762
QCString ref() const
Definition docnode.h:764
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:526
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
#define Config_getBool(name)
Definition config.h:33
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:54
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:84
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
int qstrncmp(const char *str1, const char *str2, size_t len)
Definition qcstring.h:75
const char * qPrint(const char *s)
Definition qcstring.h:661
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition util.cpp:6065
QCString stripPath(const QCString &s)
Definition util.cpp:5292
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:6981
QCString correctId(const QCString &s)
Definition util.cpp:4259
QCString externalLinkTarget(const bool parent)
Definition util.cpp:6021
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5243
A bunch of utility functions.