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 QCString replaceRef(const QCString &buf,const QCString &relPath,
119 bool urlOnly,const QCString &context,const QCString &target=QCString())
120{
121 // search for href="...", store ... part in link
122 QCString href = "href";
123 //bool isXLink=FALSE;
124 int len = 6;
125 int indexS = buf.find("href=\""), indexE = 0;
126 bool targetAlreadySet = buf.find("target=")!=-1;
127 if (indexS>5 && buf.find("xlink:href=\"")!=-1) // XLink href (for SVG)
128 {
129 indexS-=6;
130 len+=6;
131 href.prepend("xlink:");
132 //isXLink=TRUE;
133 }
134 if (indexS>=0 && (indexE=buf.find('"',indexS+len))!=-1)
135 {
136 QCString link = buf.mid(indexS+len,indexE-indexS-len);
137 QCString 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().isEmpty())
150 {
151 QCString fn = df->file();
153 result += fn;
154 }
155 if (!df->anchor().isEmpty())
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 int marker = link.find('$');
169 if (marker!=-1)
170 {
171 QCString ref = link.left(marker);
172 QCString url = link.mid(marker+1);
173 if (!ref.isEmpty())
174 {
175 result = externalLinkTarget(true);
176 if (!result.isEmpty())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.isEmpty() && !targetAlreadySet)
188 {
189 result+=" target=\""+target+"\"";
190 }
191 QCString leftPart = buf.left(indexS);
192 QCString 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 QCString &relPath, bool urlOnly,
216 const QCString &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 QCString buf = line+'\n';
230 if (buf.startsWith("<area"))
231 {
232 QCString 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 int indexA = replBuf.find("alt=");
236 if (indexA == -1)
237 {
238 replBuf = replBuf.left(5) + " alt=\"\"" + replBuf.right(replBuf.length() - 5);
239 }
240
241 // strip id="..." from replBuf since the id's are not needed and not unique.
242 int indexS = replBuf.find("id=\""), indexE = 0;
243 if (indexS>0 && (indexE=replBuf.find('"',indexS+4))!=-1)
244 {
245 t << replBuf.left(indexS-1) << replBuf.right(replBuf.length() - indexE - 1);
246 }
247 else
248 {
249 t << replBuf;
250 }
251 }
252 }
253 return TRUE;
254}
255
257 : m_patchFile(patchFile)
258{
259}
260
262{
263 return m_patchFile.endsWith(".svg");
264}
265
266int DotFilePatcher::addMap(const QCString &mapFile,const QCString &relPath,
267 bool urlOnly,const QCString &context,const QCString &label)
268{
269 size_t id = m_maps.size();
270 m_maps.emplace_back(mapFile,relPath,urlOnly,context,label);
271 return static_cast<int>(id);
272}
273
275 const QCString &figureName,bool heightCheck)
276{
277 size_t id = m_maps.size();
278 m_maps.emplace_back(figureName,"",heightCheck,"",baseName);
279 return static_cast<int>(id);
280}
281
282int DotFilePatcher::addSVGConversion(const QCString &relPath,bool urlOnly,
283 const QCString &context,bool zoomable,
284 int graphId)
285{
286 size_t id = m_maps.size();
287 m_maps.emplace_back("",relPath,urlOnly,context,"",zoomable,graphId);
288 return static_cast<int>(id);
289}
290
292 const QCString &absImgName,
293 const QCString &relPath)
294{
295 size_t id = m_maps.size();
296 m_maps.emplace_back(absImgName,relPath,false,"",baseName);
297 return static_cast<int>(id);
298}
299
301{
302 //printf("DotFilePatcher::run(): %s\n",qPrint(m_patchFile));
303 bool interactiveSVG = Config_getBool(INTERACTIVE_SVG);
304 bool isSVGFile = m_patchFile.endsWith(".svg");
305 int graphId = -1;
306 QCString relPath;
307 if (isSVGFile)
308 {
309 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
310 interactiveSVG = interactiveSVG && map.zoomable;
311 graphId = map.graphId;
312 relPath = map.relPath;
313 //printf("DotFilePatcher::addSVGConversion: file=%s zoomable=%d\n",
314 // qPrint(m_patchFile),map->zoomable);
315 }
316 QCString tmpName = m_patchFile+".tmp";
317 Dir thisDir;
318 if (!thisDir.rename(m_patchFile.str(),tmpName.str()))
319 {
320 err("Failed to rename file {} to {}!\n",m_patchFile,tmpName);
321 return FALSE;
322 }
323 std::ifstream fi = Portable::openInputStream(tmpName);
324 std::ofstream fo = Portable::openOutputStream(m_patchFile);
325 if (!fi.is_open())
326 {
327 err("problem opening file {} for patching!\n",tmpName);
328 thisDir.rename(tmpName.str(),m_patchFile.str());
329 return FALSE;
330 }
331 if (!fo.is_open())
332 {
333 err("problem opening file {} for patching!\n",m_patchFile);
334 thisDir.rename(tmpName.str(),m_patchFile.str());
335 return FALSE;
336 }
337 TextStream t(&fo);
338 int width=0,height=0;
339 bool insideHeader=FALSE;
340 bool replacedHeader=FALSE;
341 bool useNagivation=FALSE;
342 std::string lineStr;
343 static const reg::Ex reSVG(R"([\‍[<]!-- SVG [0-9]+)");
344 static const reg::Ex reMAP(R"(<!-- MAP [0-9]+)");
345 static const reg::Ex reFIG(R"(% FIG [0-9]+)");
346
347 while (getline(fi,lineStr))
348 {
349 // replace id="page0,1_graph0" with id="graph0" to work around graphviz page numbering bug
350 {
351 auto pos = lineStr.find("id=\"page0,1_graph0\"");
352 if (pos != std::string::npos)
353 lineStr.replace(pos, 19, "id=\"graph0\"");
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 t << "<script type=\"application/ecmascript\" xlink:href=\"" << relPath << "svg.min.js\"/>\n";
388 t << "<svg id=\"graph\" class=\"graph\"";
389 if (useNagivation)
390 {
391 t << " data-view-width=\"" << width << "\" data-view-height=\"" << height << "\"";
392 if (graphId>=0)
393 {
394 t << " data-section-id=\"dynsection-" << graphId << "\"";
395 }
396 }
397 t << ">\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 {}\n",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 {}!\n",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 {}!\n",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 {} figure!\n",mapId);
482 return FALSE;
483 }
484 }
485 else // error invalid map id!
486 {
487 err("Found invalid bounding FIG {} in file {}!\n",mapId,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 {} for reading!\n",tmpName);
516 return FALSE;
517 }
518 if (!fo.is_open())
519 {
520 err("problem opening file {} for writing!\n",orgName);
521 return FALSE;
522 }
523 t.setStream(&fo);
524 while (getline(fi,lineStr)) // foreach line
525 {
526 QCString line = lineStr+'\n';
527 const Map &map = m_maps.front(); // there is only one 'map' for a SVG file
528 t << replaceRef(line,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 (literal_at(line.c_str(),"<!--zoomable "))
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 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)
566 {
567 found=true;
568 }
569 }
570 return true;
571}
572
574{
575 out << "<p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p>";
576}
577
578/// Check if a reference to a SVG figure can be written and do so if possible.
579/// Returns FALSE if not possible (for instance because the SVG file is not yet generated).
581 const QCString &baseName,const QCString &absImgName)
582{
583 int width=600,height=600;
584 if (!readSVGSize(absImgName,&width,&height))
585 {
586 return FALSE;
587 }
588 if (width==-1)
589 {
590 if (height<=60) height=300; else height+=300; // add some extra space for zooming
591 if (height>600) height=600; // clip to maximum height of 600 pixels
592 out << "<div class=\"zoom\">";
593 //out << "<object type=\"image/svg+xml\" data=\""
594 //out << "<embed type=\"image/svg+xml\" src=\""
595 out << "<iframe scrolling=\"no\" loading=\"lazy\" frameborder=\"0\" src=\""
596 << relPath << baseName << ".svg\" width=\"100%\" height=\"" << height << "\">";
597 }
598 else
599 {
600 //out << "<object type=\"image/svg+xml\" data=\""
601 //out << "<embed type=\"image/svg+xml\" src=\""
602 out << "<iframe scrolling=\"no\" loading=\"lazy\" frameborder=\"0\" src=\""
603 << relPath << baseName << ".svg\" width=\""
604 << ((width*96+48)/72) << "\" height=\""
605 << ((height*96+48)/72) << "\">";
606 }
608 //out << "</object>";
609 //out << "</embed>";
610 out << "</iframe>";
611 if (width==-1)
612 {
613 out << "</div>";
614 }
615
616 return TRUE;
617}
618
620 const QCString &figureName)
621{
622 int width=400,height=550;
623 if (Config_getBool(USE_PDFLATEX))
624 {
625 if (!DotRunner::readBoundingBox(figureName+".pdf",&width,&height,FALSE))
626 {
627 //printf("writeVecGfxFigure()=0\n");
628 return FALSE;
629 }
630 }
631 else
632 {
633 if (!DotRunner::readBoundingBox(figureName+".eps",&width,&height,TRUE))
634 {
635 //printf("writeVecGfxFigure()=0\n");
636 return FALSE;
637 }
638 }
639 //printf("Got PDF/EPS size %d,%d\n",width,height);
640 int maxWidth = 350; /* approx. page width in points, excl. margins */
641 int maxHeight = 550; /* approx. page height in points, excl. margins */
642 out << "\\nopagebreak\n"
643 "\\begin{figure}[H]\n"
644 "\\begin{center}\n"
645 "\\leavevmode\n";
646 if (width>maxWidth || height>maxHeight) // figure too big for page
647 {
648 // c*width/maxWidth > c*height/maxHeight, where c=maxWidth*maxHeight>0
649 if (width*maxHeight>height*maxWidth)
650 {
651 out << "\\includegraphics[width=" << maxWidth << "pt]";
652 }
653 else
654 {
655 out << "\\includegraphics[height=" << maxHeight << "pt]";
656 }
657 }
658 else
659 {
660 out << "\\includegraphics[width=" << width << "pt]";
661 }
662
663 out << "{" << baseName << "}\n"
664 "\\end{center}\n"
665 "\\end{figure}\n";
666
667 //printf("writeVecGfxFigure()=1\n");
668 return TRUE;
669}
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
QCString anchor() const
Definition docnode.h:794
QCString file() const
Definition docnode.h:791
QCString ref() const
Definition docnode.h:793
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:422
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
bool startsWith(const char *s) const
Definition qcstring.h:507
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:241
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
const std::string & str() const
Definition qcstring.h:552
QCString right(size_t len) const
Definition qcstring.h:234
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:172
QCString left(size_t len) const
Definition qcstring.h:229
Text streaming class that buffers data.
Definition textstream.h:36
bool empty() const
Returns true iff the buffer is empty.
Definition textstream.h:240
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:196
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:216
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:659
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:648
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:571
#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:5793
QCString stripPath(const QCString &s)
Definition util.cpp:4969
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:6672
QCString correctId(const QCString &s)
Definition util.cpp:3926
QCString externalLinkTarget(const bool parent)
Definition util.cpp:5745
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:4942
A bunch of utility functions.