require "chise/config"
require "chise/iconv"
require "chise/uconv"
-
require "chise/string"
require "chise/character"
-
-$debug = false #これはテスト用
-$debug = true #これはテスト用
-$stdout.binmode if $debug
-$stdout.sync = true if $debug
def get(char_id)
check_max
- n = @parser.parse(char_id)
- @chars[n] = Character.new(n) if @chars[n].nil?
- @chars[n]
+ mcs = @parser.parse(char_id)
+ @chars[mcs] = Character.new(mcs) if @chars[mcs].nil?
+ @chars[mcs]
end
def check_max
clear if MAX_CACHE_CHARACTER < @chars.length # clear all caches.
end
-
- def nu_length
- @chars.length
- end
end
class Character
def initialize(char_id=nil)
- @parser = CharacterParser.new
- @char_id = @parser.parse(char_id)
- @attributes = Hash.new
+ @char_id = char_id
+ @attributes = {}
@check_all_database = false
end
attr_reader :char_id
+
+
+
+
+
def to_i() @char_id end
def mcs_utf8() Character.u4itou8(@char_id) end
def mcs_hex() sprintf("%x", @char_id) end
a
end
- def get_char_attribute(b) # XEmacs UTF-2000\8cÝ\8a·API\8cQ
+ def get_char_attribute(b) # XEmacs CHISE compatible API
a = normalize_attribute_name(b)
#p [a, b]
atr = @attributes[a]
@attributes[a] = atr
return atr
end
- return get_char_attribute("="+a) unless a =~ /^=/ #\93ª\82É=\82ª\82Â\82¢\82Ä\82È\82¢\8fê\8d\87\82Í\82»\82ê\82ª\8fÈ\97ª\82³\82ê\82Ä\82¢\82é\82±\82Æ\82ð\89¼\92è\82µ\82Ä\81A\8dÄ\8bA\82·\82é
+ return get_char_attribute("="+a) unless a =~ /^=/
+ #\93ª\82É=\82ª\82Â\82¢\82Ä\82È\82¢\8fê\8d\87\82Í\82»\82ê\82ª\8fÈ\97ª\82³\82ê\82Ä\82¢\82é\82±\82Æ\82ð\89¼\92è\82µ\82Ä\81A\8dÄ\8bA\82·\82é
nil
end
# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
-require "stroke"
+require "chise/stroke"
module StrokeFont
class CodeViewer
WIDTH, HEIGHT = 256, 256
SCALE = 2
+
def initialize(cx=0, cy=0)
@cx, @cy = cx, cy
@s = SCALE
calc_code
end
attr_reader :code
+
def draw
colorHSV(0, 0, 100, 10) #まずは下敷きになる枠を書きます。
rect(@x1, @y1, @x2, @y2)
line(@px-@pw/2, @py, @px+@pw/2, @py)
line(@px, @py-@ph/2, @px, @py+@ph/2)
end
+
def onMouse(x, y)
if @onkeydown
x, y = @px, @py
return false
end
end
+
def calc_code()
x = ((@px - @x1)/@s).to_i
y = HEIGHT-1 - ((@py - @y1)/@s).to_i
return false
end
end
+
def show_list(list)
colorHSV(0, 100, 100, 100)
list.each {|code|
rect(x, y, x+2, y-2)
}
end
+
def code_to_xy(code)
cx = code % WIDTH
cy = HEIGHT - (code / WIDTH) #intになる?
y = cy * SCALE + @y1
return x, y
end
+
def length(x, y) Math.sqrt(x*x + y*y) end
+
def onMouseDown(x, y)
if length(@px-x, @py-y) < @pr
@dragging = true
end
end
+
def onMouseUp(x, y) @dragging = false end
+
def onKeyDown(key)
@onkeydown = true
case key
@csf_dir = @base_dir+"/csf"
if CHISE.windows?()
- @db_dir = @base_dir+"/char-db" # /sysmtem-char-id/ucs
+ @db_dir = @base_dir+"/chise-db" # /sysmtem-char-id/=ucs
@ids_dir = @base_dir+"/ids" # /IDS-JIS-X0208-1990.txt
else
- @db_dir = "/usr/local/lib/xemacs-21.4.12/i686-pc-linux/char-db"
- @ids_dir = "/home/eto/chise/ids"
+ @db_dir = "/usr/local/lib/xemacs-21.4.14/i686-pc-linux/chise-db"
+ @ids_dir = "/home/eto/work/chise/ids"
end
instance_variables.each {|name|
# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
require "sgl"
-#require "kconv"
-#require "uconv"
require "chise/iconv"
require "chise/config"
@strokes = Strokes.new
end
attr_reader :strokes
+
def move_to_x(x) @x = x; @nx = x; end
def draw_to_x(x) @nx = x; drawline; @x = @nx; @y = @ny; end
def next_x_to(x) @nx = x; end
def move_to_y(y) @y = y; @ny = y; end
def draw_to_y(y) @ny = y; drawline; @x = @nx; @y = @ny; end
+
def drawline()
@strokes.add_line(t(@x), t(@y), t(@nx), t(@ny))
end
+
def t(a) a*DEST_WIDTH/ORG_WIDTH; end
end
require "bdb"
require "chise/config"
require "chise/rbchise"
-require "chise/management"
require "chise/util"
module CHISE
require "uri"
require "chise"
require "chise/network" #漢字間接続のネットワークを計算する
-#require "chise/kanjilist"
-#include CHISE
+require "chise/kanjilist"
class KageServer
include Singleton
+++ /dev/null
-# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
-
-module CHISE
- class DBS_Management # DataBase file management
- OBSOLETE_ATTRIBUTES = "
-cns-radical
-cns-radical?
-kangxi-radical
-daikanwa-radical
-unicode-radical
-
-cns-strokes
-kangxi-strokes
-daikanwa-strokes
-shinjigen-1-radical
-gb-original-radical
-japanese-strokes
-jis-strokes-a
-jis-strokes-b
-jisx0208-strokes
-jis-x0213-strokes
-jisx0213-strokes
-unicode-strokes
-
-totalstrokes
-cns-total-strokes
-jis-total-strokes-b
-
-non-morohashi
-
-=>ucs*
-#=>mojikyo
-#=mojikyo
-->identical
-
-ancient-ideograph-of
-ancient-char-of-shinjigen-1
-original-ideograph-of
-original-char-of-shinjigen-1
-simplified-ideograph-of
-vulgar-ideograph-of
-vulgar-char-of-shinjigen-1
-ideograph=
-ideographic-variants
-variant-of-shinjigen-1
-
-iso-10646-comment
-".split
-
- def initialize
- dir = Config.instance.db_dir
- @odir = dir+"/system-char-id/obsolete" #\92¼\91Å\82¿\82µ\82Ä\82¢\82é\81B
- end
-
- def move_obsolete_files # move obsolete BDB files
- db = CharDB.instance
- db.close_all
- Dir.mkdir(@odir) unless FileTest.directory? @odir
- OBSOLETE_ATTRIBUTES.each {|attr|
- next if attr =~ /^#/
- filename = db.get_filename(attr)
- move_to_obsolete(filename)
- move_to_obsolete(filename+".txt")
- }
- end
-
- def move_to_obsolete(file)
- cmd = "mv \"#{file}\" #{@odir}"
- #p cmd
- system cmd
- end
- end
-end
PRIVATE_USE_AREA = 0xe000
def parse_er(s) # parse a Entity Reference and return a number (MCS)
- raise "wrong ER." unless ALL_RE =~ s # I don't use is_er? for getting $1.
+ raise "wrong ER." unless ALL_RE =~ s # don't use is_er? for getting $1.
s = $1 # extract the part of ER
def initialize(type = Berkeley_DB, location = nil)
@type, @location = type, location
@location = Config.instance.db_dir if @location.nil?
- @dbs = {}
+ @fnames = {}
+ @cnames_names = {}
at_exit {
- @dbs.each {|k, db|
- db.close
- }
+ @fnames.each {|k, db| db.close }
+ @cnames.each {|k, db| db.close }
}
end
- def open_decoding_table(ccs)
- db = open(ccs, "system-char-id")
- DecodingTable.new(ccs, db)
+ def get_feature(feature)
+ @fnames[feature] = open_feature(feature) if @fnames[feature].nil?
+ @fnames[feature]
+ end
+
+ def decode_char(name, code_point)
+ ccs = get_ccs(name)
+ ccs.decode(code_point)
+ end
+
+ def get_ccs(name)
+ db = open(name, "system-char-id")
+ CCSTable.new(name, db)
end
def open_feature_table(feature)
class AttributeTable # abstract class
end
- class DecodingTable < AttributeTable
+ class CCSTable < AttributeTable
def initialize(ccs, db)
@ccs, @db = ccs, db
end
$VERBOSE = true
+$debug = false # for test
+$debug = true # for test
+$stdout.binmode if $debug
+$stdout.sync = true if $debug
+
$LOAD_PATH.unshift("..")
require "test/unit"
require "chise/char"
require "common"
-class TestRubyChise < Test::Unit::TestCase
+class TestRbChise < Test::Unit::TestCase
def test_rbchise
+
+ end
+
+ def test_rbchise0
@ds = CHISE::DataSource.new
assert_instance_of(CHISE::DataSource, @ds)
@dt = @ds.open_decoding_table("=daikanwa")
# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
#test: ids_db
-test:
+test:
-tarball:
- ./mkdbtarball.rb /usr/local/lib/xemacs-21.4.10/i686-pc-linux/
+tarball:
+ ruby -I make-chisedb-tarball.rb /usr/local/lib/xemacs-21.4.14/i686-pc-linux
-dump:
+dump:
./dbdumpall.rb
-ids_db:
+ids_db:
./idsdbdumpall.rb
-check:
+check:
./idscheckintegrity.rb
--- /dev/null
+#!/bin/csh -f
+# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
+
+scp aqua.eto.com:work/chise/ruby/tools/chise-db.tar.gz .
exit
end
-usage if ARGV.length < 1
-dir = ARGV[0]
-unless FileTest.directory?(dir+"/chise-db")
- print "no chise-db here. #{dir}\n"
- usage
-end
-tmpdir = ARGV[1]
-tmpdir = "/var/tmp" if tmpdir.nil?
+def main(argv)
+ usage if argv.length < 1
+ dir = argv.shift
+ unless FileTest.directory?(dir+"/chise-db")
+ print "no chise-db here. #{dir}\n"
+ usage
+ end
+ tmpdir = argv.shift
+ tmpdir = "/var/tmp" if tmpdir.nil?
-orgdir = Dir.pwd
-Dir.chdir(tmpdir) # \93K\93\96\82Èdir\82É\88Ú\93®\82µ\82Ä\82©\82ç
-system "cp -a #{dir}/chise-db ." # \82Ü\82¸\82»\82Ìdirectory\82É\96â\93\9a\96³\97p\82Å\91S\95\94\83R\83s\81[\82·\82é\81B
+ orgdir = Dir.pwd
+ Dir.chdir(tmpdir) # \93K\93\96\82Èdir\82É\88Ú\93®\82µ\82Ä\82©\82ç
+ system "cp -a #{dir}/chise-db ." # \82Ü\82¸\82»\82Ìdirectory\82É\96â\93\9a\96³\97p\82Å\91S\95\94\83R\83s\81[\82·\82é\81B
-Find.find("."){|f|
- if f =~ /([*?<>])/ # Windows\82É\82¨\82¯\82é\8bÖ\8e~\95¶\8e\9a\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82ç\81A\92u\8a·\82·\82é
- nf = CHISE.unix_to_win(f)
- cmd = "mv '#{f}' '#{nf}'"
- #print cmd, "\n"
- system cmd
- end
-}
+ Find.find("."){|f|
+ if f =~ /([*?<>])/ # Windows\82É\82¨\82¯\82é\8bÖ\8e~\95¶\8e\9a\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82ç\81A\92u\8a·\82·\82é
+ nf = CHISE.unix_to_win(f)
+ cmd = "mv '#{f}' '#{nf}'"
+ #print cmd, "\n"
+ system cmd
+ end
+ }
-system "tar czf chise-db.tar.gz chise-db"
-system "mv chise-db.tar.gz #{orgdir}"
-system "rm -rf #{tmpdir}/chise-db"
+ system "tar czf chise-db.tar.gz chise-db"
+ system "mv chise-db.tar.gz #{orgdir}"
+ system "rm -rf #{tmpdir}/chise-db"
+end
+main(ARGV)
--- /dev/null
+#!/usr/bin/env ruby
+# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
+# move obsolete BDB files.
+
+$LOAD_PATH.unshift("..")
+require "chise/config"
+require "chise/util"
+
+module CHISE
+ class DBS_Management # DataBase file management
+ # from specs/char-atr.ja.txt
+ OBSOLETE_ATTRIBUTES = "
+cns-radical
+cns-radical?
+kangxi-radical
+daikanwa-radical
+
+cns-strokes
+kangxi-strokes
+daikanwa-strokes
+shinjigen-1-radical
+gb-original-radical
+japanese-strokes
+jis-strokes-a
+jisx0208-strokes
+unicode-strokes
+
+cns-total-strokes
+
+non-morohashi
+
+=>ucs*
+#=>mojikyo
+#=mojikyo
+->identical
+
+ancient-ideograph-of
+ancient-char-of-shinjigen-1
+original-ideograph-of
+original-char-of-shinjigen-1
+vulgar-ideograph-of
+vulgar-char-of-shinjigen-1
+ideographic-variants
+variant-of-shinjigen-1
+
+iso-10646-comment
+".split
+
+ def initialize
+ end
+
+ def move_obsolete_files
+ fdir = Config.instance.db_dir+"/system-char-id"
+ Dir.chdir(fdir){
+ odir = "obsolete"
+ Dir.mkdir(odir) unless FileTest.directory? odir
+
+ OBSOLETE_ATTRIBUTES.each {|attr|
+ next if attr =~ /^#/
+ f = get_filename(attr)
+ move(f, odir) if FileTest.exist?(f)
+ f = f+".txt"
+ move(f, odir) if FileTest.exist?(f)
+ }
+ }
+ end
+
+ def get_filename(t)
+ t = CHISE.unix_to_win(t) if CHISE.windows?
+ t
+ end
+
+ def move(file, dir)
+ cmd = "mv './#{file}' #{dir}"
+ p cmd
+ system cmd
+ end
+ end
+end
+
+man = CHISE::DBS_Management.new
+man.move_obsolete_files
+++ /dev/null
-#!/usr/bin/env ruby
-# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
-# obsoleteである属性のBDBファイルを移動する
-
-$LOAD_PATH.unshift("..")
-require "chise/char"
-
-man = DBS_Management.new
-man.move_obsolete_files