summaryrefslogtreecommitdiffstats
path: root/src/dot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dot.cpp')
-rw-r--r--src/dot.cpp63
1 files changed, 54 insertions, 9 deletions
diff --git a/src/dot.cpp b/src/dot.cpp
index b952ce2..e178ef1 100644
--- a/src/dot.cpp
+++ b/src/dot.cpp
@@ -1484,23 +1484,68 @@ void DotNode::setDistance(int distance)
static QCString convertLabel(const QCString &l)
{
QCString result;
+ QCString bBefore("\\_/<({[: =-+@%#~?$");
+ QCString bAfter(">]),;|");
const char *p=l.data();
if (p==0) return result;
char c;
+ char cs[2];
+ cs[1]=0;
+ int len=l.length();
+ int charsLeft=len;
+ int sinceLast=0;
+ int foldLen=17; // ideal text length
while ((c=*p++))
{
+ QCString replacement;
switch(c)
{
- case '\\': result+="\\\\"; break;
- case '\n': result+="\\n"; break;
- case '<': result+="\\<"; break;
- case '>': result+="\\>"; break;
- case '|': result+="\\|"; break;
- case '{': result+="\\{"; break;
- case '}': result+="\\}"; break;
- case '"': result+="\\\""; break;
- default: result+=c; break;
+ case '\\': replacement="\\\\"; break;
+ case '\n': replacement="\\n"; break;
+ case '<': replacement="\\<"; break;
+ case '>': replacement="\\>"; break;
+ case '|': replacement="\\|"; break;
+ case '{': replacement="\\{"; break;
+ case '}': replacement="\\}"; break;
+ case '"': replacement="\\\""; break;
+ default: cs[0]=c; replacement=cs; break;
}
+ // Some heuristics to insert newlines to prevent too long
+ // boxes and at the same time prevent ugly breaks
+ if (c=='\n')
+ {
+ result+=replacement;
+ foldLen = (3*foldLen+sinceLast+2)/4;
+ sinceLast=1;
+ }
+ else if (charsLeft>foldLen/3 && sinceLast>foldLen && bBefore.contains(c))
+ {
+ result+="\\n";
+ result+=replacement;
+ foldLen = (foldLen+sinceLast+1)/2;
+ sinceLast=1;
+ }
+ else if (charsLeft>1+foldLen/4 && sinceLast>foldLen+foldLen/3 &&
+ !isupper(c) && isupper(*p))
+ {
+ result+=replacement;
+ result+="\\n";
+ foldLen = (foldLen+sinceLast+1)/2;
+ sinceLast=0;
+ }
+ else if (charsLeft>foldLen/3 && sinceLast>foldLen && bAfter.contains(c))
+ {
+ result+=replacement;
+ result+="\\n";
+ foldLen = (foldLen+sinceLast+1)/2;
+ sinceLast=0;
+ }
+ else
+ {
+ result+=replacement;
+ sinceLast++;
+ }
+ charsLeft--;
}
return result;
}