sawsen11 / jrfonseca

Automatically exported from code.google.com/p/jrfonseca
0 stars 0 forks source link

[gprof2dot] Fontsize is too large for viewing in firefox #96

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I'm effectively using this:

/usr/bin/python -m cProfile -o "$FNAME".pstats $TEST

gprof2dot.py --skew=.1 -wn3 -f pstats "$FNAME".pstats | dot -Tsvg -o 
"$FNAME".svg

What is the expected output? What do you see instead?

Fontsize in firefox is massive (default is 16px which is pretty useless)

What version of the product are you using? On what operating system?

Please provide any additional information below.

Here's a patch:

diff --git a/tools/gprof2dot.py b/tools/gprof2dot.py
index 0e4fe75..c8c15ad 100755
--- a/tools/gprof2dot.py
+++ b/tools/gprof2dot.py
@@ -22,6 +22,7 @@
 __author__ = "Jose Fonseca et al"

+import base64
 import sys
 import math
 import os.path
@@ -2955,7 +2956,12 @@ def graph(self, profile, theme):
         fontcolor = theme.graph_fontcolor()
         nodestyle = theme.node_style()

-        self.attr('graph', fontname=fontname, ranksep=0.25, nodesep=0.125)
+        b64style = base64.b64encode(
+            'text {'
+            '    font-size: 10px;'
+            '}'
+        )
+        self.attr('graph', fontname=fontname, ranksep=0.25, nodesep=0.125, 
stylesheet='data:text/css;charset=utf-8;base64,{0}'.format(b64style))
         self.attr('node', fontname=fontname, shape="box", style=nodestyle, fontcolor=fontcolor, width=0, height=0)
         self.attr('edge', fontname=fontname)

Original issue reported on code.google.com by asott...@yelp.com on 16 Apr 2014 at 9:02

GoogleCodeExporter commented 9 years ago
I just converted one .dot generated by gprof2dot into svg, and opened with 
firefox and the text looked fine.

Furthermore the generated .svg already has 

  font-size="10.00"

attributes all over the place.

Could it be that your firefox has some non-standard font settings? Or old 
version of firefox/graphviz?

I'm using firefox version 24.5.0 and graphviz version 2.26.3.

Original comment by Jose.R.F...@gmail.com on 28 May 2014 at 8:22

GoogleCodeExporter commented 9 years ago
The verson I have is

$ dot -V
dot - Graphviz version 2.20.2 (Tue Mar  2 19:03:41 UTC 2010)

Each firefox version I've tested has had the same behaviour.  I'm using firefox 
29.0 currently.

`style="font-size: 10.00"` isn't actually a valid css rule (there's no units).

You'll notice the difference in this simple testcase in firefox (if you change 
it to have units):

<!doctype html>
<html>
<body style="font-size: 10.00">
Hello world
</body>
</html>

Original comment by asott...@yelp.com on 28 May 2014 at 8:32

GoogleCodeExporter commented 9 years ago

Original comment by Jose.R.F...@gmail.com on 13 Mar 2015 at 7:13

GoogleCodeExporter commented 9 years ago
> `style="font-size: 10.00"` isn't actually a valid css rule (there's no units).

Instead of working around in gprof2dot, this should be fixed in graphviz. And 
indeed there have been bugs reported:

http://www.graphviz.org/mantisbt/view.php?id=1702
http://www.graphviz.org/bugs/b1561.html

Unfortunately there has been no action.

And I'm afraid that working around in gprof2dot is not sustainable: it would 
output for bakcends other than SVG.

Maybe posting a patch to graphviz developers might help making progress.

In the meanwhile my recommendation is either post-proccess the output with text 
processing tool like `sed`, or use the graphviz PDF backend.

Original comment by Jose.R.F...@gmail.com on 16 Mar 2015 at 12:14

GoogleCodeExporter commented 9 years ago
This graphviz change should fix it:

{{{
diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c
index bb2ca7f..4d4818d 100644
--- a/plugin/core/gvrender_core_svg.c
+++ b/plugin/core/gvrender_core_svg.c
@@ -440,7 +440,7 @@ static void svg_textspan(GVJ_t * job, pointf p, textspan_t 
* span)
            gvprintf(job, " baseline-shift=\"sub\"");
     }

-    gvprintf(job, " font-size=\"%.2f\"", span->font->size);
+    gvprintf(job, " font-size=\"%.2fpt\"", span->font->size);
     switch (obj->pencolor.type) {
     case COLOR_STRING:
        if (strcasecmp(obj->pencolor.u.string, "black"))
}}}

But per 
https://github.com/ellson/graphviz/blob/master/plugin/core/gvrender_core_svg.c#L
14 this might actually be a bug in firefox...

Original comment by Jose.R.F...@gmail.com on 16 Mar 2015 at 1:24