4 use vars qw($opt_in_cs $opt_order $opt_help $usage
5 $in_cs $out_cs $i @chars
7 $char $char_id $out_char
8 $ids $ids_argc %ids $idsdb
9 $idsdata_file $ids_start $font_start
15 use Chise_utils ':all';
17 my $perl="/usr/bin/perl";
18 my $makefonts="/Users/izumi/.chise/makefonts.pl";
19 my $geta=pack("S",8750|0x8080);
21 if($^V and $^V ge v5.8){
23 }elsif($^V and $^V ge v5.6){
26 print STDERR "This versin is not supported.";
30 binmode(STDIN, ':encoding(utf8)');
31 binmode(STDOUT, ':encoding(utf8)');
34 &GetOptions("in=s"=>\$opt_in_cs,
37 "order=s"=>\$opt_order,
42 Usage: $0 -i <input coding system> -o <order of kanji> <filename>
43 input coding system: (default: ucs\@mcs)
44 ucs\@mcs, ucs\@cns, ucs\@gb, ucs\@jis, ucs\@ks
45 order of kanji: (default: j)
51 m: Multi, use \\UTFM of otf.sty
52 You can also combine them, ex. jtcgkm
55 %order=('c'=>'UniCNS',
68 if(not defined($opt_in_cs)){
69 print STDERR "Assuming input coding system is ucs\@mcs.\n";
72 if(($opt_in_cs ne 'ucs@mcs')or
73 ($opt_in_cs ne 'ucs@cns')or
74 ($opt_in_cs ne 'ucs@gb')or
75 ($opt_in_cs ne 'ucs@jis')or
76 ($opt_in_cs ne 'ucs@ks')){
84 if(not defined($opt_order)){
85 print STDERR "Using only UniJIS.\n";
89 if(defined($opt_order)){
90 if($opt_order=~/^[cgjktm]+$/){
91 @order=split(//,$opt_order);
92 @order=map {$order{$_}} @order;
94 print STDERR "Invalid option!\n";
100 $idsdata_file="idsdata.pl";
104 if(-e $idsdata_file){
105 require $idsdata_file;
112 "=gt-pj-1","=gt-pj-2","=gt-pj-3","=gt-pj-4","=gt-pj-5",
113 "=gt-pj-6","=gt-pj-7","=gt-pj-8","=gt-pj-9","=gt-pj-10",
115 #,"=gt-pj-k1","=gt-pj-k2"
117 @HZK=("=hanziku-1","=hanziku-10","=hanziku-11","=hanziku-12",
118 "=hanziku-2","=hanziku-3","=hanziku-4","=hanziku-5",
119 "=hanziku-6","=hanziku-7","=hanziku-8","=hanziku-9");
123 s/&(.*?);/&de_er($1)/ge;
124 s/(.)/&get_char_in_ucsmcs($1,$in_cs)/ge if($in_cs ne 'ucs@mcs');
126 for($i=0;$i<=$#chars;$i++){
128 $char_id=unpack("U",$chars[$i]);
134 }elsif($char_id>=0x2ff0 and $char_id<=0x2fff){
135 # Ideographic Description Characters
138 }elsif($char_id >= 0x20000 && $char_id <=0x2a6df){
139 # CJK Unified Ideographs Extension B
140 if(not defined($ids{$char}) and $ids{$char}[1]>=0){
141 $ids{$char}[0]=$font_start;
142 $ids{$char}[1]=$ids_start;
149 print "{\\fontencoding{OT1}\\fontfamily{" .
150 sprintf("chise%03d",$ids{$char}[0]) .
151 "}\\selectfont\\char$ids{$char}[1]}";
154 if(($out_char=&get_output_char($char_id))){
157 print &replace_ids(&get_ids($char));
163 open(IDSDATA,">$idsdata_file") or die;
164 print IDSDATA 'use utf8;',"\n";
165 foreach $ids (keys %ids){
166 print IDSDATA '$ids{\'',$ids,'\'}='
167 ,'[',join ",",@{$ids{$ids}},"];\n" if($perl56);
168 print IDSDATA '$ids{\'',encode('utf8',$ids),'\'}='
169 ,'[',join ",",@{$ids{$ids}},"];\n" if($perl58);
171 print IDSDATA '$font_start=',$font_start,";\n";
172 print IDSDATA '$ids_start=',$ids_start,";\n";
175 ### to use makefonts scripts, please uncomment the next lines.
176 # system($perl,$makefonts) ==0
177 # or die "Could not make fonts: $?";
182 my($ids,$ids_argc)=&ids_rest("",0,$chars[$i]);
188 print STDERR "IDS parse error: $ids\n";
195 ($ids,$ids_argc)=&ids_rest($ids,$ids_argc,$chars[$i]);
197 if(($char_id=&get_char_id_for_ids($ids))
198 and($out_char=&get_output_char($char_id))){
201 print &replace_ids($ids) if($perl56);
202 print encode('utf8', &replace_ids($ids)) if($perl58);
211 my($ids,$ids_argc,$char)=@_;
213 $argc=&ids_argc($char);
215 $ids_argc+= $ids_argc==0 ? $argc : $argc-1;
219 $ids.=$char if($perl56);
220 $ids.=encode('utf8',$char) if($perl58);
221 return ($ids,$ids_argc);
226 $ids=&normalize_ids($ids,"UniJIS");
227 return $geta if(($ids!~/[$idc]/)
228 or($ids=~/[\x{10000}-]/));
230 if(not defined($ids{$ids}) and $ids{$ids}[1]>=0){
231 $ids{$ids}[0]=$font_start;
232 $ids{$ids}[1]=$ids_start;
239 return "{\\fontencoding{T1}\\fontfamily{"
240 .sprintf("chisesub%03d",$ids{$ids}[0])
241 ."}\\selectfont\\char$ids{$ids}[1]}";
246 $ids = decode('utf8', $ids) if $perl58;
247 $out_cs=~s/Uni(.+)/"ucs\@".lc($1)/e;
249 my($char,$char_id,$output_char_id);
250 while($ids=~m/(.)/g){
252 $char_id=unpack("U",$char);
255 }elsif($output_char_id=&get_char_attribute($char,"=$out_cs")){
256 $output_ids.=pack("U",$output_char_id);
257 }elsif($output_char_id=&get_char_attribute($char,"=ucs")){
258 $output_ids.=pack("U",$output_char_id);
268 my($char,$out_char,$suffix);
271 $char=pack('U',$char_id);
273 if($jis=&get_char_attribute($char,'=jis-x0208')){
274 return pack("S",$jis|0x8080);
276 foreach $out_cs (@order){
277 if($out_cs eq 'UniJIS'
278 and &get_char_attribute($char,"adobe-unijis-utf16-h")){
279 if($out_char=&get_char_attribute($char,'=ucs@jis')
280 or $out_char=&get_char_attribute($char,'=ucs')){
281 return "\\UTF{".sprintf("%X",$out_char)."}";
283 }elsif($out_cs eq 'UniGB'
284 and &get_char_attribute($char,"adobe-unigb-ucs2-h")){
285 if($out_char=&get_char_attribute($char,'=ucs@gb')
286 or $out_char=&get_char_attribute($char,'=ucs')){
287 return "\\UTFC{".sprintf("%X",$out_char)."}";
289 }elsif($out_cs eq 'UniCNS'
290 and &get_char_attribute($char,"adobe-unicns-ucs2-h")){
291 if($out_char=&get_char_attribute($char,'=ucs@cns')
292 or $out_char=&get_char_attribute($char,'=ucs')){
293 return "\\UTFT{".sprintf("%X",$out_char)."}";
295 }elsif($out_cs eq 'UniKS'
296 and &get_char_attribute($char,"adobe-uniks-ucs2-h")){
297 if($out_char=&get_char_attribute($char,'=ucs@ks')
298 or $out_char=&get_char_attribute($char,'=ucs')){
299 return "\\UTFK{".sprintf("%X",$out_char)."}";
301 }elsif($out_cs eq 'GT'){
302 return $gt if($gt=&get_macro_for_GT($char_id));
303 }elsif($out_cs eq 'Multi'){
304 if($out_char=&get_char_attribute($char,'=ucs')){
305 return "\\UTFM{".sprintf("%X",$out_char)."}";
316 $ids=&get_char_attribute($char,"ids-aggregated")
317 or &get_char_attribute($char,"ids");
318 $ids=decode('utf8', $ids) if($perl58);
322 sub get_char_id_for_ids{
325 $ids=decode('utf8', $ids) if($perl58);
327 if(&get_reverse_db("ids")){
328 if($output_char=$reverse_chardb{"ids"}->{$ids}){
329 $output_char=~s/^\?//;
330 return unpack("U",$output_char);
337 sub get_char_in_ucsmcs{
338 # argument: <character>, <input coding system>
339 # return: character in ucs@mcs.
343 if(&get_reverse_db("=$in_cs")){
344 if($output_char=$reverse_chardb{"=$in_cs"}->{$char}){
345 return $output_char=~s/^\?//;
352 sub get_macro_for_GT{
355 $char=pack("U",$char_id);
357 if($gt=&get_char_attribute($char,$_)){
358 m/gt\-pj\-(\d+)/ and $GT=$1;
363 return "{\\fontfamily{"
364 .sprintf("gto%02d",$GT)
365 ."}\\selectfont\\char".($gt|0x8080)."}";