require "singleton"
require "net/http"
require "uri"
-$LOAD_PATH << "../../lib"
require "chise"
require "chise/network" #漢字間接続のネットワークを計算する
#require "chise/kanjilist"
-include CHISE
+#include CHISE
class KageServer
include Singleton
- TYPES = "skeleton mincho gothic".split
+
+ TYPES = %w(skeleton mincho gothic)
SKELETON = 0
MINCHO = 1
GOTHIC = 2
URL = "http://192.168.2.60:5100/"
+
def initialize(url=URL)
@url = url
@glyphs = []
Dir.mkdir(@cache_dir) unless FileTest.directory?(@cache_dir)
end
attr_accessor :url, :use_cache, :offline
- def filename(num, type=SKELETON) sprintf("u%04x.%s", num, TYPES[type]) end
- def cache_file(num, type=SKELETON) @cache_dir+"/"+filename(num, type)+".svg" end
+
+ def filename(num, type=SKELETON)
+ sprintf("u%04x.%s", num, TYPES[type])
+ end
+
+ def cache_file(num, type=SKELETON)
+ @cache_dir+"/"+filename(num, type)+".svg"
+ end
def list_cache
ar = []
end
def get(num, type=SKELETON)
- return open(cache_file(num, type)).read if FileTest.exist?(cache_file(num, type))
+ if FileTest.exist?(cache_file(num, type))
+ return open(cache_file(num, type)) {|f| f.read }
+ end
svg = get_http(num, type)
- return svg if svg
- return nil
+ svg
end
+
def get_http(num, type=SKELETON)
return nil if @offline
+
uri = URI.parse(URL + filename(num, type))
p ["uri", uri.to_s]
+
Net::HTTP.version_1_1 # declear to use 1.1 features.
Net::HTTP.start( uri.host, uri.port ) {|http|
response, body = http.get("/"+filename(num, type)+".svg")
end
end
}
- return nil
+ nil
end
+
def store_cache(num, type, svg)
#p ["store", num]
open(cache_file(num, type), "w") {|f|
f.print svg
}
end
+
def error?(svg)
(svg =~ /<!-- error -->/)
end
+
def read_list
h = {}
open("kage-list.txt"){|f|
}
return h
end
+
def get_all
#error_h = read_list
STDOUT.binmode
}
get_ar(ar)
end
+
def get_ar(ar)
ar.each {|num| #intの数列
char = Character.get(num)
}
}
end
+
def test_kanji
char = "&CDP-8BA5;".de_er
#p char.inspect_all