[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(DTPtechNote:464) Re: イラストレータのテキスト



>Perl大名をやめて、バイナリ部分をとばすようにしないとダメだろうねぇ。

こんな感じだね。

#!perl -w

use strict;

# フォントパラメータの入力
my %kFonts = (
	' 全て'				=> '[\w\-]+',
	'細明朝体'			=> 'Ryumin-Light-83pv-RKSJ-H',
	'中ゴシック体'		=> 'GothicBBB-Medium-83pv-RKSJ-H',
	'B 太ゴ B101'		=> 'FutoGoB101-Bold-83pv-RKSJ-H',
	'新ゴM'				=> 'ShinGo-Medium-83pv-RKSJ-H',
	'ロダン-DB'			=> 'Rodin-Demi-83pv-RKSJ-H',
	'リュウミンR-KL'	=> 'Ryumin-regular-83pv-RKSJ-H',
	'ゴシックMB101 B'	=> 'GothicMB101-Bold-83pv-RKSJ-H',
	'見出ゴMB31'		=> 'MidashiGo-MB31-83pv-RKSJ-H',
	'B 太ミン A101'		=> 'FutoMinA101-Bold-83pv-RKSJ-H',
	'じゅん501'			=> 'Jun501-Bold-83pv-RKSJ-H',
	'新正楷書CBSK1'		=> 'ShinseiKai-CBSK1-83pv-RKSJ-H',
	'L じゅん 101'		=> 'Jun101-Light-83pv-RKSJ-H',
	'見出ミンMA31'		=> 'MidashiMin-MA31-83pv-RKSJ-H',
	'じゅん34'			=> 'Jun34-Medium-83pv-RKSJ-H',
	'リュウミンH-KL'	=> 'Ryumin-heavy-83pv-RKSJ-H',
	'リュウミンU-KL'	=> 'Ryumin-Ultra-83pv-RKSJ-H',
	'リュウミンB-KL'	=> 'Ryumin-Bold-83pv-RKSJ-H',
	'新ゴB'				=> 'ShinGo-Bold-83pv-RKSJ-H',
	'セザンヌ-EB'		=> 'Cezanne-ExB-83pv-RKSJ-H',
	'新ゴL'				=> 'ShinGo-Light-83pv-RKSJ-H',
	'リュウミンM-KL'	=> 'Ryumin-Medium-83pv-RKSJ-H',
	'新ゴU'				=> 'ShinGo-Ultra-83pv-RKSJ-H',
	'新ゴR'				=> 'ShinGo-regular-83pv-RKSJ-H',
	'ゴシックMB101 U'	=> 'GothicMB101-Ult-83pv-RKSJ-H',
	'ゴシックMB101 H'	=> 'GothicMB101-hea-83pv-RKSJ-H'
);
my $kReal = '-?\d+(?:\.\d+)?';
my(
$kPIC_font,
$kPIC_size
);
exit unless $kPIC_font = $kFonts{MacPerl::Pick
("抜き出す書体を選んでください。", sort keys %kFonts)};

exit unless $kPIC_size = MacPerl::Ask
("抜き出す文字のサイズを入力して下さい。(pt)", 7);


foreach my $myfile (@ARGV){
	my $f = 0;	#ターゲット内であることのフラグ
	
	open(IN, "$myfile") || die "can't open $1 \n";
	open(OUT, ">$myfile.txt") || die "can't open $myfile.txt \n";
	
	while(<IN>){
		if(/^%%Begin(?:Data|Binary):\s+(\d+)/) {
			seek IN, $1, 1;
		} elsif(/^\/_([-\w]+) ($kReal) $kReal $kReal Tf\b/o) {
			my($font, $size) = ($1, $2);
			$f = ($font =~ /^$kPIC_font$/o) and
				 ($size =~ /^$kPIC_size$/o);
		} elsif($f) {
			PP($1) if /^\((.+)\) +Tx\b/;
		} 
	} 
	close(IN);
	close(OUT);
}

sub PP {	#デコードとプリント
	local $_ = shift;
	s/\\\\/\\134/g;
	s/\\([\(\)])/$1/g;
	s/\\([0-8]{3})\\([0-8]{3})/pack("CC",oct($1),oct($2))/eg;
	s/\\([0-8]{3})/pack("C",oct($1))/eg;
	s/\\r/\n/g;
	print OUT;
}