Doxygen
Loading...
Searching...
No Matches
dotfilepatcher.cpp File Reference
#include "dotfilepatcher.h"
#include "dotrunner.h"
#include "config.h"
#include "message.h"
#include "docparser.h"
#include "docnode.h"
#include "doxygen.h"
#include "util.h"
#include "dot.h"
#include "dir.h"
#include "portable.h"
#include "stringutil.h"
#include "textstream.h"
Include dependency graph for dotfilepatcher.cpp:

Go to the source code of this file.

Functions

static DString replaceRef (const DString &buf, const DString &relPath, bool urlOnly, const DString &context, const DString &target=DString())
static bool readSVGSize (const DString &fileName, int *width, int *height)
static void writeSVGNotSupported (TextStream &out)

Variables

static const char svgZoomHeader0 []
static const char svgZoomHeader0_noinit []
static const char svgZoomHeader1 []
static const char svgZoomHeader2 []
static const char svgZoomFooter1 []
static const char svgZoomFooter2 []

Function Documentation

◆ readSVGSize()

bool readSVGSize ( const DString & fileName,
int * width,
int * height )
static

Definition at line 546 of file dotfilepatcher.cpp.

547{
548 bool found=false;
549 std::ifstream f = Portable::openInputStream(fileName);
550 if (!f.is_open())
551 {
552 return false;
553 }
554 std::string line;
555 while (getline(f,line) && !found)
556 {
557 if (literal_at(line.c_str(),"<!--zoomable "))
558 {
559 *width=-1;
560 *height=-1;
561 sscanf(line.c_str(),"<!--zoomable %d",height);
562 found=true;
563 }
564 else if (sscanf(line.c_str(),"<svg width=\"%dpt\" height=\"%dpt\"",width,height)==2)
565 {
566 found=true;
567 }
568 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)
569 {
570 found=true;
571 }
572 }
573 return true;
574}
std::ifstream openInputStream(const DString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:676
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

References literal_at(), and Portable::openInputStream().

Referenced by DotFilePatcher::writeSVGFigureLink().

◆ replaceRef()

DString replaceRef ( const DString & buf,
const DString & relPath,
bool urlOnly,
const DString & context,
const DString & target = DString() )
static

Definition at line 119 of file dotfilepatcher.cpp.

121{
122 // search for href="...", store ... part in link
123 DString href = "href";
124 //bool isXLink=false;
125 int len = 6;
126 size_t indexS = buf.find("href=\""), indexE = 0;
127 bool targetAlreadySet = buf.find("target=")!=DString::npos;
128 if (indexS>5 && buf.find("xlink:href=\"")!=DString::npos) // XLink href (for SVG)
129 {
130 indexS-=6;
131 len+=6;
132 href.prepend("xlink:");
133 //isXLink=true;
134 }
135 if (indexS!=DString::npos && (indexE=buf.find('"',indexS+len))!=DString::npos)
136 {
137 DString link = buf.mid(indexS+len,indexE-indexS-len);
138 DString result;
139 if (urlOnly) // for user defined dot graphs
140 {
141 if (link.startsWith("\\ref ") || link.startsWith("@ref ")) // \ref url
142 {
143 result=href+"=\"";
144 // fake ref node to resolve the url
145 auto parser { createDocParser() };
146 auto dfAst { createRef( *parser.get(), link.mid(5), context ) };
147 auto dfAstImpl = dynamic_cast<const DocNodeAST*>(dfAst.get());
148 const DocRef *df = std::get_if<DocRef>(&dfAstImpl->root);
149 result+=externalRef(relPath,df->ref());
150 if (!df->file().empty())
151 {
152 DString fn = df->file();
154 result += fn;
155 }
156 if (!df->anchor().empty())
157 {
158 result += "#" + df->anchor();
159 }
160 result += "\"";
161 }
162 else
163 {
164 result = href+"=\"" + link + "\"";
165 }
166 }
167 else // ref$url (external ref via tag file), or $url (local ref)
168 {
169 size_t marker = link.find('$');
170 if (marker!=DString::npos)
171 {
172 DString ref = link.left(marker);
173 DString url = link.mid(marker+1);
174 if (!ref.empty())
175 {
176 result = externalLinkTarget(true);
177 if (!result.empty())targetAlreadySet=true;
178 }
179 result+= href+"=\"";
180 result+=externalRef(relPath,ref);
181 result+= url + "\"";
182 }
183 else // should not happen, but handle properly anyway
184 {
185 result = href+"=\"" + link + "\"";
186 }
187 }
188 if (!target.empty() && !targetAlreadySet)
189 {
190 result+=" target=\""+target+"\"";
191 }
192 DString leftPart = buf.left(indexS);
193 DString rightPart = buf.mid(indexE+1);
194 //printf("replaceRef(\n'%s'\n)->\n'%s+%s+%s'\n",
195 // qPrint(buf),qPrint(leftPart),qPrint(result),qPrint(rightPart));
196 return leftPart + result + rightPart;
197 }
198 else
199 {
200 return buf;
201 }
202}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:322
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
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:182
DString & prepend(const char *s)
Definition dstring.h:519
size_t find(char c, size_t pos=0) const
Definition dstring.h:243
DString left(size_t len) const
Definition dstring.h:310
bool startsWith(const char *s) const
Definition dstring.h:604
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
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:59
IDocNodeASTPtr createRef(IDocParser &parserIntf, const DString &target, const DString &context, const DString &srcFile, int srcLine)
DString externalLinkTarget(const bool parent)
Definition util.cpp:4493
void addHtmlExtensionIfMissing(DString &fName)
Definition util.cpp:3933
DString externalRef(const DString &relPath, const DString &ref)
Definition util.cpp:4540

References addHtmlExtensionIfMissing(), DocRef::anchor(), createDocParser(), createRef(), DString::empty(), externalLinkTarget(), externalRef(), DocRef::file(), DString::find(), DString::left(), DString::mid(), DString::npos, DString::prepend(), DocRef::ref(), and DString::startsWith().

Referenced by DotFilePatcher::convertMapFile(), and DotFilePatcher::run().

◆ writeSVGNotSupported()

void writeSVGNotSupported ( TextStream & out)
static

Definition at line 576 of file dotfilepatcher.cpp.

577{
578 out << "<p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p>";
579}

Referenced by DotFilePatcher::writeSVGFigureLink().

Variable Documentation

◆ svgZoomFooter1

const char svgZoomFooter1[]
static
Initial value:
= R"svg(
<g id="navigator" transform="translate(0 0)" fill="#404254">
<rect fill="#f2f5e9" fill-opacity="0.5" stroke="#606060" stroke-width=".5" x="0" y="0" width="60" height="60"/>
<use id="zoomplus" xlink:href="#zoomPlus" x="17" y="9" data-zoom="in"/>
<use id="zoomminus" xlink:href="#zoomMin" x="42" y="9" data-zoom="out"/>
<use id="reset" xlink:href="#resetDef" x="30" y="36" data-reset="true"/>
<use id="arrowup" xlink:href="#arrowUp" x="0" y="0" data-pan-x="0" data-pan-y="-1"/>
<use id="arrowright" xlink:href="#arrowRight" x="0" y="0" data-pan-x="1" data-pan-y="0"/>
<use id="arrowdown" xlink:href="#arrowDown" x="0" y="0" data-pan-x="0" data-pan-y="1"/>
<use id="arrowleft" xlink:href="#arrowLeft" x="0" y="0" data-pan-x="-1" data-pan-y="0"/>
</g>
<svg viewBox="0 0 15 15" width="100%" height="30px" preserveAspectRatio="xMaxYMin meet">
<g id="arrow_out" transform="scale(0.3 0.3)">
<a xlink:href="$orgname" target="_base">
<rect id="button" ry="5" rx="5" y="6" x="6" height="38" width="38"
fill="#f2f5e9" fill-opacity="0.5" stroke="#606060" stroke-width="1.0"/>
<path id="arrow"
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"
style="fill:#404040;"/>
</a>
</g>
</svg>
)svg"

Definition at line 84 of file dotfilepatcher.cpp.

Referenced by DotFilePatcher::run().

◆ svgZoomFooter2

const char svgZoomFooter2[]
static
Initial value:
= R"svg(
<style type='text/css'>
<![CDATA[
[data-mouse-over-selected='false'] { opacity: 0.7; }
[data-mouse-over-selected='true'] { opacity: 1.0; }
]]>
</style>
</svg>
)svg"

Definition at line 109 of file dotfilepatcher.cpp.

Referenced by DotFilePatcher::run().

◆ svgZoomHeader0

const char svgZoomHeader0[]
static
Initial value:
= R"svg(
<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
)svg"

Definition at line 31 of file dotfilepatcher.cpp.

Referenced by DotFilePatcher::run().

◆ svgZoomHeader0_noinit

const char svgZoomHeader0_noinit[]
static
Initial value:
= R"svg(
<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
)svg"

Definition at line 35 of file dotfilepatcher.cpp.

Referenced by DotFilePatcher::run().

◆ svgZoomHeader1

const char svgZoomHeader1[]
static
Initial value:
= R"svg(
<style type="text/css"><![CDATA[
.node, .edge {opacity: 0.7;}
.node.selected, .edge.selected {opacity: 1;}
.edge:hover path { stroke: red; }
.edge:hover polygon { stroke: red; fill: red; }
]]></style>
)svg"

Definition at line 39 of file dotfilepatcher.cpp.

Referenced by DotFilePatcher::run().

◆ svgZoomHeader2

const char svgZoomHeader2[]
static

Definition at line 49 of file dotfilepatcher.cpp.

Referenced by DotFilePatcher::run().