blockdiag / blockdiag

Apache License 2.0
219 stars 51 forks source link

seqdiag, label and -T pdf #50

Closed tk0miya closed 6 years ago

tk0miya commented 6 years ago

Hi,

it seems there is a problem with seqdiag 0.8.2 and the usage of label. I can create png file without problem, but if I try to create a pdf file, I get:

ERROR: 'NoneType' object has no attribute 'stringWidth'

I have no clue, what is going wrong. With blockdiag there are no problems...

It happens even with this:

setdiag { browser -> server [ label = "GET / HTTP/1.0" ]; }

The png is ok, the pdf shows the above error message and no file is created.

Best regards

Dirk


tk0miya commented 6 years ago

From Kevin Mitchell on 2013-04-04 15:45:17+00:00

Creating the metrics seems to need the canvas to exist, which is done for PDF by setting the canvas size. Any size will do; it'll get fixed up a few lines later.

This patch seems to get past that spot. (I'm having other troubles, but they're font related and seem to be in reportlab).


diff -ur ./drawer.py ../../../../../eggs/blockdiag-1.2.4-py2.7.egg/blockdiag/drawer.py
--- ./drawer.py 2012-11-17 01:41:01.000000000 -0600
+++ ../../../../../eggs/blockdiag-1.2.4-py2.7.egg/blockdiag/drawer.py   2013-04-04 10:15:08.000000000 -0500
@@ -15,6 +15,7 @@

 from blockdiag import imagedraw, noderenderer
 from blockdiag.metrics import AutoScaler, DiagramMetrics
+from blockdiag.utils import XY
 from blockdiag.utils.collections import defaultdict

@@ -42,6 +43,7 @@
                                        scale_ratio=self.scale_ratio,
                                        **kwargs)

+        self.drawer.set_canvas_size(XY(320,320))
         self.metrics = self.create_metrics(kwargs.get('basediagram', diagram),
                                            drawer=self.drawer, **kwargs)
         if self.scale_ratio == 2:
tk0miya commented 6 years ago

From Dirk Geschke on 2013-04-05 10:00:08+00:00

Hi Kevin,

thank you for responding but that seems not to work, although it is another error:

ERROR: invalid literal for int() with base 10: '333.33333', while looking for faceName='/usr/share/fonts/truetype/vlgothic/VL-PGothic-Regular.ttf'

Do you have any further ideas?

Best regards

Dirk

tk0miya commented 6 years ago

From Kevin Mitchell on 2013-04-05 14:34:54+00:00

If you run with --debug, you'll get a full traceback for the exception that caused that. That's similar to the other problem I had, and seems to be coming from reportlab.

In other words, patching the canvas size allows blockdiag to get farther along in rendering, then there's another problem.

I was going to try it on Linux, because sometimes Freetype is tricky on my Mac, but haven't yet.

tk0miya commented 6 years ago

From Dirk Geschke on 2013-04-05 22:15:13+00:00

Hi Kevin,

you are right, with --debug I see problems with reportlab.

I am not familar with python, so I can't see the real problem. The last lines of the backtrace are:

File "/usr/lib/python2.7/dist-packages/reportlab/pdfgen/canvas.py", line 1564, in stringWidth (fontSize,self._fontsize)[fontSize is None]) File "/usr/lib/python2.7/dist-packages/reportlab/pdfbase/pdfmetrics.py", line 723, in stringWidth return getFont(fontName).stringWidth(text, fontSize, encoding=encoding) File "/usr/lib/python2.7/dist-packages/reportlab/pdfbase/pdfmetrics.py", line 689, in getFont return findFontAndRegister(fontName) File "/usr/lib/python2.7/dist-packages/reportlab/pdfbase/pdfmetrics.py", line 671, in findFontAndRegister face = getTypeFace(fontName) File "/usr/lib/python2.7/dist-packages/reportlab/pdfbase/pdfmetrics.py", line 642, in getTypeFace afm = bruteForceSearchForAFM(faceName) File "/usr/lib/python2.7/dist-packages/reportlab/pdfbase/pdfmetrics.py", line 228, in bruteForceSearchForAFM topDict, glyphDict = parseAFMFile(possible) File "/usr/lib/python2.7/dist-packages/reportlab/pdfbase/pdfmetrics.py", line 110, in parseAFMFile width = string.atoi(r) File "/usr/lib/python2.7/string.py", line 403, in atoi return _int(s, base)

Maybe you get a clue out of these lines?

Best regards

Dirk

tk0miya commented 6 years ago

From Kevin Mitchell on 2013-04-06 02:47:52+00:00

Hello, Dirk

Definitely a reportlab bug. The WX parameter of an AFM file is a "number", i.e., float. Reportlab is expecting an integer. This is a common mistake in writing AFM parsers. Ref: http://partners.adobe.com/public/developer/en/font/5004.AFM_Spec.pdf

Probably you should report it to the reportlab people with a small test case, if you can get one together.

Kevin

tk0miya commented 6 years ago

From Takeshi KOMIYA on 2013-11-03 08:05:58+00:00

In blockdiag-1.3.0 and seqdiag-0.9.0, we use integer for all coordinates. So this problem is fixed.