Saturday, February 19, 2011

Mac OSX10.6 blockdiag ブロックダイアグラム生成 Python

blockdiag

ブロックダイアグラム画像を簡単なテキストファイルから生成することができます

http://pypi.python.org/pypi/blockdiag/0.6.7

http://tk0miya.bitbucket.org/blockdiag/build/html/index.html

Mac OSX 10.6 MacBookAir へインストールしました。
freetype2を入れていなかったせいで、チュートリアル通りにはうまく入りませんでしたので、
インストールメモします。

easy_install で blockdiag をいれていきます。

$ sudo easy_install blockdiag


そうするとインストールが正しくおわったように見えるのですが、

.
.
.
i686-apple-darwin10-gcc-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: Tk: linker input file unused because linking not done
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)]
--------------------------------------------------------------------
--- TKINTER support available
*** JPEG support not available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.
zip_safe flag not set; analyzing archive contents...
Image: module references __file__
Adding PIL 1.1.7 to easy-install.pth file
Installing pilconvert.py script to /usr/local/bin
Installing pildriver.py script to /usr/local/bin
Installing pilfile.py script to /usr/local/bin
Installing pilfont.py script to /usr/local/bin
Installing pilprint.py script to /usr/local/bin

Installed /Library/Python/2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.6-universal.egg
Finished processing dependencies for blockdiag

上のPILを入れる部分で、

*** FREETYPE2 support not available

というように、Freetype2のサポートができないとかかれているところが肝です。
このまま先に進むと、とりあえずsample.diagを作成して、

diagファイルは簡単な文法でブロックダイアグラムを表現できるテキストファイルになります

diagram {
A -> B -> C -> D;
A -> E -> F -> G;
}

このdiagファイルをもとにblockdiagで画像を生成しようとすると
先ほどのPILのインストール部分の肝のせいで、失敗します。

[~] $ blockdiag simple.diag
Traceback (most recent call last):
File "/usr/local/bin/blockdiag", line 8, in
load_entry_point('blockdiag==0.6.7', 'console_scripts', 'blockdiag')()
File "/Library/Python/2.6/site-packages/blockdiag-0.6.7-py2.6.egg/blockdiag/blockdiag.py", line 429, in main
draw.draw()
File "/Library/Python/2.6/site-packages/blockdiag-0.6.7-py2.6.egg/blockdiag/DiagramDraw.py", line 105, in draw
self.node(node, **kwargs)
File "/Library/Python/2.6/site-packages/blockdiag-0.6.7-py2.6.egg/blockdiag/DiagramDraw.py", line 225, in node
font=self.font, badgeFill=self.badgeFill)
File "/Library/Python/2.6/site-packages/blockdiag-0.6.7-py2.6.egg/blockdiag/noderenderer/__init__.py", line 47, in render
self.render_shape(drawer, format, **kwargs)
File "/Library/Python/2.6/site-packages/blockdiag-0.6.7-py2.6.egg/blockdiag/noderenderer/box.py", line 33, in render_shape
lineSpacing=self.metrix.lineSpacing)
File "/Library/Python/2.6/site-packages/blockdiag-0.6.7-py2.6.egg/blockdiag/ImageDrawEx.py", line 247, in textarea
lines = TextFolder(box, string, scale=self.scale_ratio, **kwargs)
File "/Library/Python/2.6/site-packages/blockdiag-0.6.7-py2.6.egg/blockdiag/utils/PILTextFolder.py", line 14, in __init__
self.ttfont = ImageFont.truetype(font, fontsize)
File "/Library/Python/2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.6-universal.egg/ImageFont.py", line 218, in truetype
return FreeTypeFont(filename, size, index, encoding)
File "/Library/Python/2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.6-universal.egg/ImageFont.py", line 134, in __init__
self.font = core.getfont(file, size, index, encoding)
File "/Library/Python/2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.6-universal.egg/ImageFont.py", line 34, in __getattr__
raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed


http://www.freetype.org/ からfreetype2をダウンロードしてきます
freetype-2.4.4.tar.gzにしました。


$ ./configure
$ make
$ sudo make install


インストールした後もう一度PILを入れ直すと
freetype2のサポートがokになっているはずです。

--------------------------------------------------------------------
PIL 1.1.6 BUILD SUMMARY
--------------------------------------------------------------------
version 1.1.6
platform darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)]
--------------------------------------------------------------------
--- TKINTER support ok
*** JPEG support not available
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.
changing mode of build/scripts-2.6/pilconvert.py from 644 to 755
changing mode of build/scripts-2.6/pildriver.py from 644 to 755
changing mode of build/scripts-2.6/pilfile.py from 644 to 755
changing mode of build/scripts-2.6/pilfont.py from 644 to 755
changing mode of build/scripts-2.6/pilprint.py from 644 to 755
changing mode of /usr/local/bin/pilconvert.py to 755
changing mode of /usr/local/bin/pildriver.py to 755
changing mode of /usr/local/bin/pilfile.py to 755
changing mode of /usr/local/bin/pilfont.py to 755
changing mode of /usr/local/bin/pilprint.py to 755
Successfully installed PIL


これでblockdiagが動きました!!

$ blockdiag simple.diag


ページ遷移とかの記述がすごく楽になるなー!
生成された画像

0 comments: