1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
8 def method_missing(mid, *args) #
\8eQ
\8dl:ostruct.rb
10 return @attr[mname] if args.length == 0
11 @attr[mname.chop] = args[0] if mname =~ /=$/ #
\91ã
\93ü
15 str = " #{mainstr()} "
16 str << "[" + @attr.map {|k, v| %Q|#{k}="#{v}"| }.join(" ") + "]" if 0 < @attr.length
22 class DotPage < DotElement
29 def mainstr() @name.to_s; end
32 return unless node.is_a? DotNode
37 return unless edge.is_a? DotEdge
43 # str << %Q| size="6, 6"\n|
44 str << @attr.map {|k, v| %Q| #{k}="#{v}"\n| }.join("")
56 class DotNode < DotElement
62 def mainstr() @name.to_s; end
65 class DotEdge < DotElement
66 def initialize(from, to)
71 def mainstr() "#{@from.to_s} -> #{@to.to_s}"; end
74 class Graphviz # abstract class
79 def initialize(type=DOT)
86 attr_accessor :type, :codepage, :target, :in, :out
88 def post_process() #
\93¯
\82¶
\83t
\83@
\83C
\83\8b\82É
\8fã
\8f\91\82«
\82É
\82·
\82é
\81B
90 str.gsub!(/&#x/, "&#x")
91 #str.gsub!(/font-family:MS Gothic;/, "")
92 #str.gsub!(/font-family:MS Gothic;/, "font-family:MS-Mincho;")
93 str.gsub!(/font-family:Times New Roman;/, "")
94 open(@out, "w"){|out| out.print str}
98 class GraphvizCLI < Graphviz
99 # COMMAND_DIR = "c:\Program Files\ATT\Graphviz\bin"
100 COMMAND_DIR = "" #PATH
\82ª
\82Æ
\82¨
\82Á
\82Ä
\82È
\82¢
\82Æ
\82¾
\82ß
\82Ý
\82½
\82¢
\81B
101 # NAMES = "dot twopi neato".split
102 NAMES = %w(dot twopi neato)
104 def generate(debug=false)
106 #ar << COMMAND_DIR + NAMES[@type] + ".exe"
107 ar << COMMAND_DIR + NAMES[@type]
122 class GraphvizOLE < Graphviz
123 #NAMES = "DOT TWOPI NEATO".split
125 def generate(debug=false)
127 names = "DOT TWOPI NEATO".split
128 @ole = WIN32OLE.new("Wingraphviz." + names[@type])
129 @ole.codepage = cp if @codepage #neato.codepage = 65001 #codepage: 65001 Unicode UTF-8
130 @instr = open(@in).read
133 result = @ole.toSVG(@instr)
134 open(@out, "w"){|out| out.print result}
136 elsif @target =~ /svg/i
137 result = @ole.toPNG(@dot)
142 def nu_to_png(filename=nil)
143 return "" unless @dot.is_a?(String)
144 png = @ole.toPNG(@dot)
145 png.save(filename) unless filename.nil?
149 #p neato.validate(str)
150 #ps = neato.toPS(str)
151 #open("test.ps", "w"){|out| out.print ps }