nwdiag from a python app, font problem

198 views
Skip to first unread message

Tim Stoop

unread,
Mar 21, 2016, 6:24:59 PM3/21/16
to blockdiag-discuss
Hi,

I'm trying to use nwdiag from a python app, but I keep hitting a wall with fonts. Everything I try ends up in:


Traceback (most recent call last):
  File "./nwdiag-test.py", line 32, in <module>
    draw.save()
  File "/home/tim/code/kumireport/local/lib/python2.7/site-packages/blockdiag/drawer.py", line 187, in save
    return self.drawer.save(self.filename, size, self.format)
  File "/home/tim/code/kumireport/local/lib/python2.7/site-packages/blockdiag/imagedraw/filters/linejump.py", line 181, in save
    self._run()
  File "/home/tim/code/kumireport/local/lib/python2.7/site-packages/blockdiag/imagedraw/filters/linejump.py", line 108, in _run
    method(self.target, *args, **kwargs)
  File "/home/tim/code/kumireport/local/lib/python2.7/site-packages/blockdiag/imagedraw/pdf.py", line 159, in textarea
    self.set_font(font)
  File "/home/tim/code/kumireport/local/lib/python2.7/site-packages/blockdiag/imagedraw/pdf.py", line 46, in set_font
    raise RuntimeError(msg)
RuntimeError: Could not detect fonts, use --font opiton

This is the code I'm currently using (just a test to see if I can get it to work):

#!/usr/bin/env python

example = """
nwdiag {
  network dmz {
      address = "210.x.x.x/24"

      web01 [address = "210.x.x.1"];
      web02 [address = "210.x.x.2"];
  }
  network internal {
      address = "172.x.x.x/24";

      web01 [address = "172.x.x.1"];
      web02 [address = "172.x.x.2"];
      db01;
      db02;
  }
}
"""

import nwdiag.parser
from nwdiag.drawer import DiagramDraw
from nwdiag.builder import ScreenNodeBuilder

with open('test.pdf','w') as f:
    tree = nwdiag.parser.parse_string(example)
    diagram = ScreenNodeBuilder.build(tree)
    draw = DiagramDraw('PDF', diagram, 'out.pdf',
        fontmap=None, antialias=False, nodoctype=True)
    draw.draw()
    draw.save()
    font.close()


Trying this on Debian Jessie. I installed the fontconfig package, but that doesn't seem to help very much. Any help is appreciated! It must be something simple, as I cannot find anyone else with this problem...

--
Kind regards,
Tim Stoop

Komiya Takeshi

unread,
Mar 21, 2016, 10:05:32 PM3/21/16
to blockdia...@googlegroups.com
Hi,

PDF driver requires font settings like following:

```
from blockdiag.utils.fontmap import FontMap

...

fontmap = FontMap()
fontmap.set_default_font('/Library/Fonts/AppleGothic.ttf')
draw = DiagramDraw('PDF', diagram, 'out.pdf',
fontmap=fontmap, antialias=False, nodoctype=True)
```

Please specify a path to OpenType font to `FontMap.set_default_font()`
and give it to constructor of DiagramDraw.

Thanks,
> --
> このメールは Google グループのグループ「blockdiag-discuss」に登録しているユーザーに送られています。
> このグループから退会し、グループからのメールの配信を停止するには
> blockdiag-disc...@googlegroups.com にメールを送信してください。
> その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。

Tim Stoop

unread,
Mar 22, 2016, 5:33:17 AM3/22/16
to blockdiag-discuss
Hi,


On Tuesday, March 22, 2016 at 3:05:32 AM UTC+1, Komiya Takeshi wrote:
PDF driver requires font settings like following:


That worked! Thank you!
Reply all
Reply to author
Forward
0 new messages