3 # CSF module by eto 2002-1115
4 # Copyright (C) 2002-2003 Kouichirou Eto
6 # This is free software with ABSOLUTELY NO WARRANTY.
8 # You can redistribute it and/or modify it under the terms of
9 # the GNU General Public License version 2.
17 CSF_FONT_DIR = 'd:/work/chise/csf/'
18 CSF_DEFAULT_FILE = 'KST32B.CSF1'
19 CSF_KOUKOTSU_FILE = 'KST32ZX.CSF1'
21 class CSFStrokeMaker #======================================================================
22 DEST_WIDTH = 1000 #
\91å
\82«
\82³
\82ð
\82¨
\82¨
\82æ
\82»1000x1000
\82É
\90³
\8bK
\89»
\82·
\82é
\81B
23 ORG_WIDTH = 32 #
\8c³
\82Ì
\83T
\83C
\83Y
\82Í
\81A
\89¡30
\81~
\8fc32
25 @x, @y, @nx, @ny = 0, 0, 0, 0
26 @strokes = Strokes.new
29 def move_to_x(x) @x = x; @nx = x; end
30 def draw_to_x(x) @nx = x; drawline; @x = @nx; @y = @ny; end
31 def next_x_to(x) @nx = x; end
32 def move_to_y(y) @y = y; @ny = y; end
33 def draw_to_y(y) @ny = y; drawline; @x = @nx; @y = @ny; end
35 @strokes.add_line(t(@x), t(@y), t(@nx), t(@ny))
37 def t(a) a*DEST_WIDTH/ORG_WIDTH; end
40 class CSFParser #======================================================================
41 def self.parse(str) #Strokes
\82ð
\95Ô
\82·
42 return Strokes.new if str == nil
43 sm = CSFStrokeMaker.new
44 (0...str.length).each {|i|
46 if 0x21 <= n && n <= 0x26
47 sm.move_to_x(n - 0x21)
48 elsif 0x28 <= n && n <= 0x3f
49 sm.move_to_x(n - 0x28 + 6)
50 elsif 0x40 <= n && n <= 0x5b
51 sm.draw_to_x(n - 0x40)
52 elsif 0x5e <= n && n <= 0x5f
53 sm.draw_to_x(n - 0x5e + 28)
54 elsif 0x60 <= n && n <= 0x7d
55 sm.next_x_to(n - 0x60)
57 sm.move_to_y(n - 0x7e)
58 elsif 0xa1 <= n && n <= 0xbf
59 sm.move_to_y(n - 0xa1 + 1)
60 elsif 0xc0 <= n && n <= 0xdf
61 sm.draw_to_y(n - 0xc0)
68 class CSFGlyph #======================================================================
69 def initialize(code, stroke)
77 @strokes = CSFParser.parse(@stroke_str)
80 parse if @strokes.nil?
84 class CSFFont #======================================================================
85 def initialize(file=CSF_DEFAULT_FILE)
86 @file = CSF_FONT_DIR + file
90 @rend = StrokesRenderer.new
91 @rend.hsv = [50, 100, 100]
98 code = c.hex #JIS
\82Ì
\92l
\82ª
\90\94\92l
\82Å
\82Í
\82¢
\82é
99 @glyphs[code] = CSFGlyph.new(code, s)
104 glyph = @glyphs[code]
105 return if glyph == nil
108 @rend.set_strokes(glyph.strokes)
110 def draw(code) #
\88ø
\90\94\82É
\82ÍJIS
\82ð
\90\94\92l
\89»
\82µ
\82½
\82à
\82Ì
\82ª
\82Í
\82¢
\82é
111 glyph = @glyphs[code]
112 return if glyph == nil
117 char = jis.get_char(code)
118 printf("[%s][%04x]\n", char.nil? ? "nil" : char.map_sjis, code)
121 char = Character.get(ucs)
122 j = char.japanese_jisx0208
129 #----------------------------------------------------------------------
\8fI
\97¹