Skip to content

Commit fcf690b

Browse files
committed
Merge branch 'albert-github-feature/issue_11492'
2 parents 5e717bf + e099909 commit fcf690b

File tree

7 files changed

+201
-94
lines changed

7 files changed

+201
-94
lines changed

src/docbookvisitor.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,15 @@ DB_VIS_C
433433
case DocVerbatim::PlantUML:
434434
{
435435
QCString docbookOutput = Config_getString(DOCBOOK_OUTPUT);
436-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(docbookOutput,
436+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(docbookOutput,
437437
s.exampleFile(),s.text(),PlantumlManager::PUML_BITMAP,
438438
s.engine(),s.srcFile(),s.srcLine(),true);
439-
QCString shortName = makeShortName(baseName);
440-
m_t << "<para>\n";
441-
writePlantUMLFile(baseName,s);
442-
m_t << "</para>\n";
439+
for (const auto &baseName: baseNameVector)
440+
{
441+
m_t << "<para>\n";
442+
writePlantUMLFile(QCString(baseName),s);
443+
m_t << "</para>\n";
444+
}
443445
}
444446
break;
445447
}
@@ -1577,12 +1579,18 @@ DB_VIS_C
15771579
QCString outDir = Config_getString(DOCBOOK_OUTPUT);
15781580
std::string inBuf;
15791581
readInputFile(fileName,inBuf);
1580-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(outDir,
1581-
QCString(),inBuf.c_str(),PlantumlManager::PUML_BITMAP,QCString(),srcFile,srcLine,false);
1582-
baseName=makeBaseName(baseName);
1583-
PlantumlManager::instance().generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_BITMAP);
1584-
m_t << "<para>\n";
1585-
visitPreStart(m_t, children, hasCaption, relPath + baseName + ".png", width, height);
1582+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(outDir,
1583+
QCString(),inBuf.c_str(),PlantumlManager::PUML_BITMAP,QCString(),srcFile,srcLine,false);
1584+
bool first = true;
1585+
for (const auto &bName: baseNameVector)
1586+
{
1587+
QCString baseName=makeBaseName(QCString(bName));
1588+
PlantumlManager::instance().generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_BITMAP);
1589+
if (!first) endPlantUmlFile(hasCaption);
1590+
first = false;
1591+
m_t << "<para>\n";
1592+
visitPreStart(m_t, children, hasCaption, relPath + baseName + ".png", width, height);
1593+
}
15861594
}
15871595

15881596
void DocbookDocVisitor::endPlantUmlFile(bool hasCaption)

src/htmldocvisitor.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,16 @@ void HtmlDocVisitor::operator()(const DocVerbatim &s)
690690
{
691691
format = PlantumlManager::PUML_SVG;
692692
}
693-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(
693+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(
694694
htmlOutput,s.exampleFile(),
695695
s.text(),format,s.engine(),s.srcFile(),s.srcLine(),true);
696-
m_t << "<div class=\"plantumlgraph\">\n";
697-
writePlantUMLFile(baseName,s.relPath(),s.context(),s.srcFile(),s.srcLine());
698-
visitCaption(m_t, s);
699-
m_t << "</div>\n";
696+
for (const auto &baseName: baseNameVector)
697+
{
698+
m_t << "<div class=\"plantumlgraph\">\n";
699+
writePlantUMLFile(QCString(baseName),s.relPath(),s.context(),s.srcFile(),s.srcLine());
700+
visitCaption(m_t, s);
701+
m_t << "</div>\n";
702+
}
700703
forceStartParagraph(s);
701704
}
702705
break;
@@ -1849,22 +1852,24 @@ void HtmlDocVisitor::operator()(const DocPlantUmlFile &df)
18491852
}
18501853
std::string inBuf;
18511854
readInputFile(df.file(),inBuf);
1852-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(
1853-
htmlOutput,QCString(),
1855+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(htmlOutput,QCString(),
18541856
inBuf.c_str(),format,QCString(),df.srcFile(),df.srcLine(),false);
1855-
baseName=makeBaseName(baseName);
1856-
m_t << "<div class=\"plantumlgraph\">\n";
1857-
writePlantUMLFile(baseName,df.relPath(),QCString(),df.srcFile(),df.srcLine());
1858-
if (df.hasCaption())
1859-
{
1860-
m_t << "<div class=\"caption\">\n";
1861-
}
1862-
visitChildren(df);
1863-
if (df.hasCaption())
1857+
for (const auto &bName: baseNameVector)
18641858
{
1859+
QCString baseName=makeBaseName(QCString(bName));
1860+
m_t << "<div class=\"plantumlgraph\">\n";
1861+
writePlantUMLFile(baseName,df.relPath(),QCString(),df.srcFile(),df.srcLine());
1862+
if (df.hasCaption())
1863+
{
1864+
m_t << "<div class=\"caption\">\n";
1865+
}
1866+
visitChildren(df);
1867+
if (df.hasCaption())
1868+
{
1869+
m_t << "</div>\n";
1870+
}
18651871
m_t << "</div>\n";
18661872
}
1867-
m_t << "</div>\n";
18681873
forceStartParagraph(df);
18691874
}
18701875

src/latexdocvisitor.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,15 @@ void LatexDocVisitor::operator()(const DocVerbatim &s)
550550
case DocVerbatim::PlantUML:
551551
{
552552
QCString latexOutput = Config_getString(LATEX_OUTPUT);
553-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(
553+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(
554554
latexOutput,s.exampleFile(),s.text(),
555555
s.useBitmap() ? PlantumlManager::PUML_BITMAP : PlantumlManager::PUML_EPS,
556556
s.engine(),s.srcFile(),s.srcLine(),true);
557557

558-
writePlantUMLFile(baseName, s);
558+
for (const auto &baseName: baseNameVector)
559+
{
560+
writePlantUMLFile(QCString(baseName), s);
561+
}
559562
}
560563
break;
561564
}
@@ -2119,19 +2122,25 @@ void LatexDocVisitor::startPlantUmlFile(const QCString &fileName,
21192122
readInputFile(fileName,inBuf);
21202123

21212124
bool useBitmap = inBuf.find("@startditaa") != std::string::npos;
2122-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(
2125+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(
21232126
outDir,QCString(),inBuf.c_str(),
21242127
useBitmap ? PlantumlManager::PUML_BITMAP : PlantumlManager::PUML_EPS,
21252128
QCString(),srcFile,srcLine,false);
2126-
baseName=makeBaseName(baseName);
2127-
QCString shortName = makeShortName(baseName);
2128-
if (useBitmap)
2129+
bool first = true;
2130+
for (const auto &bName: baseNameVector)
21292131
{
2130-
if (shortName.find('.')==-1) shortName += ".png";
2132+
QCString baseName = makeBaseName(QCString(bName));
2133+
QCString shortName = makeShortName(baseName);
2134+
if (useBitmap)
2135+
{
2136+
if (shortName.find('.')==-1) shortName += ".png";
2137+
}
2138+
PlantumlManager::instance().generatePlantUMLOutput(baseName,outDir,
2139+
useBitmap ? PlantumlManager::PUML_BITMAP : PlantumlManager::PUML_EPS);
2140+
if (!first) endPlantUmlFile(hasCaption);
2141+
first = false;
2142+
visitPreStart(m_t,hasCaption, shortName, width, height);
21312143
}
2132-
PlantumlManager::instance().generatePlantUMLOutput(baseName,outDir,
2133-
useBitmap ? PlantumlManager::PUML_BITMAP : PlantumlManager::PUML_EPS);
2134-
visitPreStart(m_t,hasCaption, shortName, width, height);
21352144
}
21362145

21372146
void LatexDocVisitor::endPlantUmlFile(bool hasCaption)

src/plantuml.cpp

Lines changed: 115 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
*/
1515

16+
#include <mutex>
1617
#include "plantuml.h"
1718
#include "util.h"
1819
#include "portable.h"
@@ -25,15 +26,17 @@
2526
#include "indexlist.h"
2627
#include "stringutil.h"
2728

28-
QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
29+
static std::mutex g_PlantUmlMutex;
30+
31+
StringVector PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
2932
const QCString &content,OutputFormat format, const QCString &engine,
3033
const QCString &srcFile,int srcLine,bool inlineCode)
3134
{
35+
StringVector baseNameVector;
3236
QCString baseName;
3337
QCString puName;
3438
QCString imgName;
3539
QCString outDir(outDirArg);
36-
static int umlindex=1;
3740

3841
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource fileName: {}\n",fileName);
3942
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource outDir: {}\n",outDir);
@@ -45,32 +48,7 @@ QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QC
4548
outDir = outDir.left(l-1);
4649
}
4750

48-
if (fileName.isEmpty()) // generate name
49-
{
50-
puName = "inline_umlgraph_"+QCString().setNum(umlindex);
51-
baseName = outDir+"/inline_umlgraph_"+QCString().setNum(umlindex++);
52-
}
53-
else // user specified name
54-
{
55-
baseName = fileName;
56-
int i=baseName.findRev('.');
57-
if (i!=-1) baseName = baseName.left(i);
58-
puName = baseName;
59-
baseName.prepend(outDir+"/");
60-
}
61-
62-
switch (format)
63-
{
64-
case PUML_BITMAP:
65-
imgName =puName+".png";
66-
break;
67-
case PUML_EPS:
68-
imgName =puName+".eps";
69-
break;
70-
case PUML_SVG:
71-
imgName =puName+".svg";
72-
break;
73-
}
51+
generatePlantUmlFileNames(fileName,format,outDir,baseName,puName,imgName);
7452

7553
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSourcebaseName: {}\n",baseName);
7654
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSourcebaseName puName: {}\n",puName);
@@ -84,7 +62,7 @@ QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QC
8462
{
8563
char c = 0;
8664
bool insideComment = false;
87-
bool initial = true;
65+
QCString locEngine;
8866
while ((c=*p++))
8967
{
9068
text+=c;
@@ -95,34 +73,130 @@ QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QC
9573
case '\t': break;
9674
case ' ': break;
9775
case '@':
98-
if (initial && literal_at(p,"start")) // @start...
76+
if (!insideComment && literal_at(p,"start")) // @start...
9977
{
100-
while ((c=*p++) && isId(c)) text+=c;
78+
locEngine.clear();
79+
p+=5;
80+
text += "start";
81+
while ((c=*p++) && isId(c))
82+
{
83+
locEngine += c;
84+
text+=c;
85+
}
86+
QCString inpName;
87+
QCString rest;
88+
89+
// skip leading whitespace
90+
if (*p && (c==' ' || c=='\t'))
91+
{
92+
while ((c=*p++) && (c==' ' || c=='\t')) {}
93+
}
94+
// get everything till end or endOfLine, and split into inpName (without extension) and rest
95+
enum State { InName, InExt, InRest };
96+
State state = InName;
97+
while (*p && c!='\n')
98+
{
99+
switch (state)
100+
{
101+
case InName: // looking for the name part
102+
if (isId(c) || c=='-') inpName+=c;
103+
else if (c=='.') state=InExt;
104+
else rest+=c, state=InRest;
105+
break;
106+
case InExt: // skipping over extension part
107+
if (!isId(c) && c!='-') rest+=c, state=InRest;
108+
break;
109+
case InRest: // gather rest until new line
110+
rest+=c;
111+
break;
112+
}
113+
c = *p++;
114+
}
115+
//printf("inpName='%s' rest='%s'\n",qPrint(inpName),qPrint(rest));
116+
generatePlantUmlFileNames(inpName,format,outDir,baseName,puName,imgName);
117+
101118
// insert the image name
102119
text+=' ';
103120
text+=imgName;
121+
122+
if (!rest.isEmpty())
123+
{
124+
text += '\n';
125+
text += rest;
126+
}
104127
if (c) text+=c;
105128
}
129+
else if (!insideComment && strncmp(p,("end"+locEngine).data(), 3+strlen(engine.data()))==0) // @end...
130+
{
131+
text += "end"+locEngine+"\n";
132+
p+=3+locEngine.length();
133+
if (!inlineCode)
134+
{
135+
QCString qcOutDir(substitute(outDir,"\\","/"));
136+
uint32_t pos = qcOutDir.findRev("/");
137+
QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) );
138+
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
139+
PlantumlManager::instance().insert(generateType.str(),puName.str(),outDir,format,text,srcFile,srcLine);
140+
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
141+
baseNameVector.push_back(baseName.str());
142+
text.clear();
143+
}
144+
}
106145
break;
107146
default:
108-
if (!insideComment) initial=false;
109147
break;
110148
}
111149
}
112150
text+='\n';
113151
}
114-
if (inlineCode) text +="@end"+engine+"\n";
152+
if (inlineCode)
153+
{
154+
text +="@end"+engine+"\n";
155+
//printf("content\n====\n%s\n=====\n->\n-----\n%s\n------\n",qPrint(content),qPrint(text));
156+
QCString qcOutDir(substitute(outDir,"\\","/"));
157+
uint32_t pos = qcOutDir.findRev("/");
158+
QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) );
159+
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
160+
PlantumlManager::instance().insert(generateType.str(),puName.str(),outDir,format,text,srcFile,srcLine);
161+
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
162+
baseNameVector.push_back(baseName.str());
163+
}
115164

116-
//printf("content\n====\n%s\n=====\n->\n-----\n%s\n------\n",qPrint(content),qPrint(text));
165+
return baseNameVector;
166+
}
117167

118-
QCString qcOutDir(substitute(outDir,"\\","/"));
119-
uint32_t pos = qcOutDir.findRev("/");
120-
QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) );
121-
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
122-
PlantumlManager::instance().insert(generateType.str(),puName.str(),outDir,format,text,srcFile,srcLine);
123-
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
168+
void PlantumlManager::generatePlantUmlFileNames(const QCString &fileName,OutputFormat format,const QCString &outDir,
169+
QCString &baseName,QCString &puName,QCString &imgName)
170+
{
171+
static int umlindex=1;
124172

125-
return baseName;
173+
if (fileName.isEmpty()) // generate name
174+
{
175+
std::lock_guard<std::mutex> lock(g_PlantUmlMutex);
176+
puName = "inline_umlgraph_"+QCString().setNum(umlindex);
177+
baseName = outDir+"/inline_umlgraph_"+QCString().setNum(umlindex++);
178+
}
179+
else // user specified name
180+
{
181+
baseName = fileName;
182+
int i=baseName.findRev('.');
183+
if (i!=-1) baseName = baseName.left(i);
184+
puName = baseName;
185+
baseName.prepend(outDir+"/");
186+
}
187+
188+
switch (format)
189+
{
190+
case PUML_BITMAP:
191+
imgName =puName+".png";
192+
break;
193+
case PUML_EPS:
194+
imgName =puName+".eps";
195+
break;
196+
case PUML_SVG:
197+
imgName =puName+".svg";
198+
break;
199+
}
126200
}
127201

128202
void PlantumlManager::generatePlantUMLOutput(const QCString &baseName,const QCString &/* outDir */,OutputFormat format)

src/plantuml.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class PlantumlManager
5858
* @param[in] srcLine the line number resulting in the write command.
5959
* @param[in] inlineCode the code is coming from the `\statuml ... \enduml` (`true`) command or
6060
* from the `\planumlfile` command (`false`)
61-
* @returns The name of the generated file.
61+
* @returns The names of the generated files.
6262
*/
63-
QCString writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
64-
const QCString &content, OutputFormat format,
65-
const QCString &engine,const QCString &srcFile,
66-
int srcLine,bool inlineCode);
63+
StringVector writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
64+
const QCString &content, OutputFormat format,
65+
const QCString &engine,const QCString &srcFile,
66+
int srcLine,bool inlineCode);
6767

6868
/** Convert a PlantUML file to an image.
6969
* @param[in] baseName the name of the generated file (as returned by writePlantUMLSource())
@@ -83,6 +83,8 @@ class PlantumlManager
8383
const QCString &puContent,
8484
const QCString &srcFile,
8585
int srcLine);
86+
void generatePlantUmlFileNames(const QCString &fileName,OutputFormat format,const QCString &outDir,
87+
QCString &baseName,QCString &puName,QCString &imgName);
8688

8789
FilesMap m_pngPlantumlFiles;
8890
FilesMap m_svgPlantumlFiles;

0 commit comments

Comments
 (0)