1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
7 def method_missing(mid, *args) #
\8eQ
\8dl:ostruct.rb
9 return @attr[mname] if args.length == 0
10 @attr[mname.chop] = args[0] if mname =~ /=$/ #
\91ã
\93ü
13 str = " #{mainstr()} "
14 str << "[" + @attr.map {|k, v| %Q|#{k}="#{v}"| }.join(" ") + "]" if 0 < @attr.length
20 class DotPage < DotElement
26 def mainstr() @name.to_s; end
28 return unless node.is_a? DotNode
32 return unless edge.is_a? DotEdge
37 # str << %Q| size="6, 6"\n|
38 str << @attr.map {|k, v| %Q| #{k}="#{v}"\n| }.join("")
50 class DotNode < DotElement
55 def mainstr() @name.to_s; end
58 class DotEdge < DotElement
59 def initialize(from, to)
63 def mainstr() "#{@from.to_s} -> #{@to.to_s}"; end
66 class Graphviz # abstract class
71 def initialize(type=DOT)
78 attr_accessor :type, :codepage, :target, :in, :out
80 def post_process() #
\93¯
\82¶
\83t
\83@
\83C
\83\8b\82É
\8fã
\8f\91\82«
\82É
\82·
\82é
\81B
82 str.gsub!(/&#x/, "&#x")
83 #str.gsub!(/font-family:MS Gothic;/, "")
84 #str.gsub!(/font-family:MS Gothic;/, "font-family:MS-Mincho;")
85 str.gsub!(/font-family:Times New Roman;/, "")
86 open(@out, "w"){|out| out.print str}
90 class GraphvizCLI < Graphviz
91 # COMMAND_DIR = "c:\Program Files\ATT\Graphviz\bin"
92 COMMAND_DIR = "" #PATH
\82ª
\82Æ
\82¨
\82Á
\82Ä
\82È
\82¢
\82Æ
\82¾
\82ß
\82Ý
\82½
\82¢
\81B
93 NAMES = "dot twopi neato".split
94 def generate(debug=false)
96 #ar << COMMAND_DIR + NAMES[@type] + ".exe"
97 ar << COMMAND_DIR + NAMES[@type]
112 class GraphvizOLE < Graphviz
113 #NAMES = "DOT TWOPI NEATO".split
114 def generate(debug=false)
116 names = "DOT TWOPI NEATO".split
117 @ole = WIN32OLE.new("Wingraphviz." + names[@type])
118 @ole.codepage = cp if @codepage #neato.codepage = 65001 #codepage: 65001 Unicode UTF-8
119 @instr = open(@in).read
121 result = @ole.toSVG(@instr)
122 open(@out, "w"){|out| out.print result}
124 elsif @target =~ /svg/i
125 result = @ole.toPNG(@dot)
129 def nu_to_png(filename=nil)
130 return "" unless @dot.is_a?(String)
131 png = @ole.toPNG(@dot)
132 png.save(filename) unless filename.nil?
135 #p neato.validate(str)
136 #ps = neato.toPS(str)
137 #open("test.ps", "w"){|out| out.print ps }