1 # -*- coding: utf-8 -*-
3 # template: bd2tex.rtex
5 # [1] 篆文(見出し)の表示: 暫定(SWを基本、段注にしかない文字をEBASで表示)
6 # [2] partとvolumeの表示に差を付ける
7 # [3] Ext B, C, DにTeXコマンドの追加(要refactoring)
10 # [1] 篆文(見出し、説解、段注)の表示
11 # [2] 標点符号のTeXコマンドによる表示
16 require File.join(File.dirname(__FILE__), 'lib', 'sw_seals')
17 #require File.join(File.dirname(__FILE__), 'lib', 'unicode')
18 require File.join(File.dirname(__FILE__), 'lib', 'tex_commands')
20 SOURCE_DIR = File.join(File.dirname(__FILE__), '..', 'yml', 'swjz')
21 TARGET_DIR = File.join(File.dirname(__FILE__), '..', 'tex', 'swjz')
25 def_erb_method('render()', 'bd2tex.rtex')
26 def initialize(source_path)
27 @sw_seals = SWSeals.new
28 # @unicode = UnicodeUtility.new
29 @tex_commands = TeXCommands.new
32 parse(File.open(source_path))
35 YAML::parse_documents(file) do |syck|
42 def parse_chapter(doc)
43 @title = doc['chapter'] if doc['chapter']
45 def parse_content(doc)
46 if doc['content'] then
47 doc['content'].each do |wordinfo|
49 word = wordinfo['word']
50 info = wordinfo['content']
51 wordid = wordinfo['id']
52 push_word(word, wordid, info)
57 def push_word(word, wordid, info)
58 duan_seal = @sw_seals.get_duan_seal(wordid)
64 char = @sw_seals.get_char(wordid)
66 # ext_word = @unicode.replace_extensions(word)
67 ext_word = @tex_commands.insert_extensions(word)
69 ext_info = add_extension_commands(info)
70 @wordlist.push([[type, ext_word, char], ext_info])
72 @wordlist.push([[type, ext_word, char], []]) # 十三篇上糸部 最後 w4672491
75 def parse_wordnum(doc)
76 if doc.has_key?('part') then
77 push_wordnum('part', doc)
78 elsif doc.has_key?('volume')
79 push_wordnum('volume', doc)
82 def push_wordnum(type, doc)
85 added = add_extension_commands(lines)
86 @wordlist.push([type, added])
88 @wordlist.push([type, []])
91 def add_extension_commands(lines)
92 # replace {\ext char} for char of
93 # CJK Unified Extension B, C and D
94 return "" unless lines
96 if line.has_key?('ex') then
98 line['ex'] = @tex_commands.insert_extensions(content)
99 elsif line.has_key?('dn') then
101 line['dn'] = @tex_commands.insert_extensions(content)
107 unless ARGV.empty? then
109 printf("\n%% %s\n", filename)
110 converter = TexConverter.new(filename)
111 print converter.render()
113 Dir.foreach(SOURCE_DIR) do |filename|
114 if filename =~ /^.*\.yml$/ then
115 if filename != 'v29.yml' and filename != 'v30.yml' then
116 printf("\n> %s\n", filename)
117 converter = TexConverter.new(File.join(SOURCE_DIR, filename))
118 outfile = File.basename(filename, 'yml') + 'tex'
119 out = File.open(File.join(TARGET_DIR, outfile), "w")
120 out.print converter.render()