2 # CSF module by eto 2002-1115
3 # $Id: csf.rb,v 1.1 2003-11-10 08:11:46 eto Exp $
4 # Copyright (C) 2002-2003 Kouichirou Eto, All rights reserved.
5 # This is free software with ABSOLUTELY NO WARRANTY.
6 # You can redistribute it and/or modify it under the terms of the GNU GPL2.
13 CSF_FONT_DIR = 'd:/work/chise/csf/'
14 CSF_DEFAULT_FILE = 'KST32B.CSF1'
15 CSF_KOUKOTSU_FILE = 'KST32ZX.CSF1'
17 class CSFStrokeMaker #======================================================================
18 DEST_WIDTH = 1000 #
\91å
\82«
\82³
\82ð
\82¨
\82¨
\82æ
\82»1000x1000
\82É
\90³
\8bK
\89»
\82·
\82é
\81B
19 ORG_WIDTH = 32 #
\8c³
\82Ì
\83T
\83C
\83Y
\82Í
\81A
\89¡30
\81~
\8fc32
21 @x, @y, @nx, @ny = 0, 0, 0, 0
22 @strokes = Strokes.new
25 def move_to_x(x) @x = x; @nx = x; end
26 def draw_to_x(x) @nx = x; drawline; @x = @nx; @y = @ny; end
27 def next_x_to(x) @nx = x; end
28 def move_to_y(y) @y = y; @ny = y; end
29 def draw_to_y(y) @ny = y; drawline; @x = @nx; @y = @ny; end
31 @strokes.add_line(t(@x), t(@y), t(@nx), t(@ny))
33 def t(a) a*DEST_WIDTH/ORG_WIDTH; end
36 class CSFParser #======================================================================
37 def self.parse(str) #Strokes
\82ð
\95Ô
\82·
38 return Strokes.new if str == nil
39 sm = CSFStrokeMaker.new
40 (0...str.length).each {|i|
42 if 0x21 <= n && n <= 0x26
43 sm.move_to_x(n - 0x21)
44 elsif 0x28 <= n && n <= 0x3f
45 sm.move_to_x(n - 0x28 + 6)
46 elsif 0x40 <= n && n <= 0x5b
47 sm.draw_to_x(n - 0x40)
48 elsif 0x5e <= n && n <= 0x5f
49 sm.draw_to_x(n - 0x5e + 28)
50 elsif 0x60 <= n && n <= 0x7d
51 sm.next_x_to(n - 0x60)
53 sm.move_to_y(n - 0x7e)
54 elsif 0xa1 <= n && n <= 0xbf
55 sm.move_to_y(n - 0xa1 + 1)
56 elsif 0xc0 <= n && n <= 0xdf
57 sm.draw_to_y(n - 0xc0)
64 class CSFGlyph #======================================================================
65 def initialize(code, stroke)
73 @strokes = CSFParser.parse(@stroke_str)
76 parse if @strokes.nil?
80 class CSFFont #======================================================================
81 def initialize(file=CSF_DEFAULT_FILE)
82 @file = CSF_FONT_DIR + file
86 @rend = StrokesRenderer.new
87 @rend.hsv = [50, 100, 100]
94 code = c.hex #JIS
\82Ì
\92l
\82ª
\90\94\92l
\82Å
\82Í
\82¢
\82é
95 @glyphs[code] = CSFGlyph.new(code, s)
100 glyph = @glyphs[code]
101 return if glyph == nil
104 @rend.set_strokes(glyph.strokes)
106 def draw(code) #
\88ø
\90\94\82É
\82ÍJIS
\82ð
\90\94\92l
\89»
\82µ
\82½
\82à
\82Ì
\82ª
\82Í
\82¢
\82é
107 glyph = @glyphs[code]
108 return if glyph == nil
113 char = jis.get_char(code)
114 printf("[%s][%04x]\n", char.nil? ? "nil" : char.map_sjis, code)
117 char = Character.get(ucs)
118 j = char.japanese_jisx0208
125 #----------------------------------------------------------------------
\8fI
\97¹