⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 afont.pm

📁 PDF-API2-0.2.3.7_dev.tar.gz
💻 PM
📖 第 1 页 / 共 4 页
字号:
		}		seek(INF,$l2,1);		read(INF,$line,2);		@lines=unpack('C*',$line);		if(($lines[0]==0x80) && ($lines[1]==1)) {			read(INF,$line,4);			$l3=unpack('V',$line);		} else {			die "corrupt pfb in file '$file' at marker='3'.";		}		seek(INF,0,0);		@lines=<INF>;		close(INF);		$stream=join('',@lines);	} elsif($line eq '%!') {		seek(INF,0,0);		while($line=<INF>) {			if(!$l1) {				$head.=$line;				if($line=~/eexec$/){					chomp($head);					$head.="\x0d";					$l1=length($head);				}			} elsif(!$l2) {				if($line=~/^0+$/) {					$l2=length($body);					$tail=$line;				} else {					chomp($line);					$body.=pack('H*',$line);				}			} else {				$tail.=$line;			}		}		$l3=length($tail);		$stream=pack('C2V',0x80,1,$l1).$head;		$stream.=pack('C2V',0x80,2,$l2).$body;		$stream.=pack('C2V',0x80,1,$l3).$tail;	} else {		die "unsupported font-format in file '$file' at marker='1'.";	}	if($noFM) {		# now we process the portions to return a hash which makes data available		# if we dont have a good enough afm or pfm file to parse (especially pfm :)		my %h=$self->readPSF(			substr($stream,6,$l1) ,  	# this is the ascii portion of the font			substr($stream,12+$l1,$l2)	# this is the binary portion of the font		);		return($l1,$l2,$l3,$stream,%h);	} else {		return($l1,$l2,$l3,$stream);	} }sub encodeProper {	my ($self, $encoding, $first,$last, @glyphs) = @_;	my (@w);	if($encoding) {		$self->{'Encoding'}=PDFDict();		$self->{'Encoding'}->{'Type'}=PDFName('Encoding');		if( $encoding eq 'MacRomanEncoding' ) {			@{$self->{' AFM'}->{'char'}}=@mac_enc;		} elsif( $encoding eq 'WinAnsiEncoding' ) {			@{$self->{' AFM'}->{'char'}}=@win_enc;		} elsif( $encoding=~/StandardEncoding$/ ) {			$encoding='WinAnsiEncoding';			@{$self->{' AFM'}->{'char'}}=@std_enc;		} elsif( lc($encoding) eq 'latin1' ) {			$encoding='WinAnsiEncoding';			@{$self->{' AFM'}->{'char'}}=@latin1_enc;			@glyphs = @latin1_enc;		} elsif( lc($encoding) eq 'custom' ) {			$encoding='WinAnsiEncoding';			@{$self->{' AFM'}->{'char'}}=@glyphs;		} elsif( lc($encoding) eq 'asis' ) {			undef($encoding);		} else {			$encoding='WinAnsiEncoding';			@{$self->{' AFM'}->{'char'}}=@win_enc;		}		$self->{'Encoding'}->{'BaseEncoding'}=PDFName($encoding) if($encoding);		my $notdefbefore=1;		@w=();		if(@glyphs){			foreach my $w ($first..$last) {				if($glyphs[$w] eq '.notdef') {					$notdefbefore=1;					next;				} else {					if($notdefbefore) {						push(@w,PDFNum($w))					}					$notdefbefore=0;					push(@w,PDFName($glyphs[$w]));				}			}			$self->{'Encoding'}->{'Differences'}=PDFArray(@w);		}	}	@w = map { 		PDFNum($self->{' AFM'}->{'wx'}{$_ || '.notdef'} || 300) 	} map {		$self->{' AFM'}->{'char'}[$_]		} ($first..$last);	$self->{'Widths'}=PDFArray(@w);	return($self);}sub newNonEmbed {	my ($class, $parent, $file2, $pdfname, $encoding, @glyphs) = @_;	my ($self);	my (@w);		$self = $file2 ? $class->SUPER::new : $class;	$self->readAFM($file2) if($file2);	$self->{' AFM'}->{'fontname'}=~s/[\x00-\x1f]+//cgm;	$self->{'Type'} = PDFName("Font");	$self->{'Subtype'} = PDFName("Type1");	$self->{'BaseFont'} = PDFName($self->{' AFM'}->{'fontname'});	$self->{'FirstChar'} = PDFNum(32);	$self->{'LastChar'} = PDFNum(255);	$self->{'Name'} = PDFName($pdfname);	$self->encodeProper( $file2 ? $encoding : 'WinAnsiEncoding' , 32, 255, @glyphs);		$self->{'FontDescriptor'}=PDFDict();	$self->{'FontDescriptor'}->{'Type'}=PDFName('FontDescriptor');	$self->{'FontDescriptor'}->{'FontName'}=PDFName($self->{' AFM'}->{'fontname'});	$self->{'FontDescriptor'}->{'Ascent'}=PDFNum($self->{' AFM'}->{'ascender'}||0);	$self->{'FontDescriptor'}->{'Descent'}=PDFNum($self->{' AFM'}->{'descender'}||0);	$self->{'FontDescriptor'}->{'ItalicAngle'}=PDFNum($self->{' AFM'}->{'italicangle'}||0);	@w = map { PDFNum($_ || 0) } split(/\s+/,$self->{' AFM'}->{'fontbbox'});	$self->{'FontDescriptor'}->{'CapHeight'}=PDFNum($self->{' AFM'}->{'capheight'}||$w[3]->val||0);	$self->{'FontDescriptor'}->{'FontBBox'}=PDFArray(@w);	$self->{'FontDescriptor'}->{'StemV'}=PDFNum(0);	$self->{'FontDescriptor'}->{'StemH'}=PDFNum(0);	$self->{'FontDescriptor'}->{'XHeight'}=PDFNum($self->{' AFM'}->{'xheight'}||$w[3]->val||0);	$self->{' ascent'}=$self->{' AFM'}->{'ascender'}||0;	$self->{' descent'}=$self->{' AFM'}->{'descender'}||0;	$self->{' italicangle'}=$self->{' AFM'}->{'italicangle'}||0;	$self->{' fontbbox'}=[ split(/\s+/,$self->{' AFM'}->{'fontbbox'}) ];	$self->{' capheight'}=$self->{' AFM'}->{'capheight'}||$w[3]->val||0;	$self->{' xheight'}=$self->{' AFM'}->{'xheight'}||$w[3]->val||0;		my $flags=0;	$self->{' AFM'}->{'encoding'}=$self->{' AFM'}->{'encoding'}||'';	$flags|=1 if(lc($self->{' AFM'}->{'isfixedpitch'}) ne 'false');	if($self->{' AFM'}->{'encoding'}=~/standardencoding/cgi){		$flags|=1<<5 ;	} else {		$flags|=1<<2 ;		$flags|=1<<3 ;	}	$flags|=1<<6 if(!$self->{' AFM'}->{'italicangle'});	$flags|=1<<17 if($self->{' AFM'}->{'fontname'}=~/SC$/);	$flags|=1<<16 if($self->{' AFM'}->{'fontname'}=~/Caps/);	$flags|=1<<18 if($self->{' AFM'}->{'fontname'}=~/(Heavy|Bold)/);	$self->{'FontDescriptor'}->{'Flags'}=PDFNum($flags);		if(defined($parent) && !$self->is_obj($parent)) {		$parent->new_obj($self);	}	return($self);}sub newCore {	my ($class, $parent, $name, $pdfname, $encoding, @glyphs) = @_;	my ($file,$file2,$file3);		$file=resolveFontFile("$name.afm");	$file2=resolveFontFile("$name.pfa");	$file3=resolveFontFile("$name.pfb");		if(! -e $file) {die "file='$file' (was '$name.afm') not existant.";}	if(defined $file2 && -e $file2) {		return(new($class, $parent, $file2, $file, $pdfname, $encoding, @glyphs));	}	if(defined $file3 && -e $file3) {		return(new($class, $parent, $file3, $file, $pdfname, $encoding, @glyphs));	}	$self=newNonEmbed($class, $parent, $file, $pdfname, $encoding, @glyphs);	return($self);}sub newNonEmbedLight {	my ($class, $parent, $file2, $pdfname,$name) = @_;	my ($self);	my (@w);		$self = $class->SUPER::new;	$self->readAFM($file2) if($file2);	$self->{' AFM'}->{'fontname'}=~s/[\x00-\x1f]+//cgm;	$self->{'Type'} = PDFName("Font");	$self->{'Subtype'} = PDFName("Type1");	$self->{'BaseFont'} = PDFName($self->{' AFM'}->{'fontname'} || $name);	$self->{'Name'} = PDFName($pdfname);	@w=split(/\s+/,$self->{' AFM'}->{'fontbbox'});	$self->{' ascent'}=$self->{' AFM'}->{'ascender'}||0;	$self->{' descent'}=$self->{' AFM'}->{'descender'}||0;	$self->{' italicangle'}=$self->{' AFM'}->{'italicangle'}||0;	$self->{' fontbbox'}=[ @w ];	$self->{' capheight'}=$self->{' AFM'}->{'capheight'}||$w[3]||0;	$self->{' xheight'}=$self->{' AFM'}->{'xheight'}||($w[3]/2)||0;		if(defined($parent) && !$self->is_obj($parent)) {		$parent->new_obj($self);	}	return($self);}sub encodeProperLight {	my ($self, $encoding,$first,$last, @glyphs) = @_;	my (@w);	if($encoding) {		if( $encoding eq 'MacRomanEncoding' ) {			@{$self->{' AFM'}->{'char'}}=@mac_enc;		} elsif( $encoding eq 'WinAnsiEncoding' ) {			@{$self->{' AFM'}->{'char'}}=@win_enc;		} elsif( $encoding=~/StandardEncoding$/ ) {			$encoding='WinAnsiEncoding';			@{$self->{' AFM'}->{'char'}}=@std_enc;		} elsif( lc($encoding) eq 'latin1' ) {			$encoding='WinAnsiEncoding';			@{$self->{' AFM'}->{'char'}}=@latin1_enc;			@glyphs = @latin1_enc;		} elsif( lc($encoding) eq 'custom' ) {			$encoding='WinAnsiEncoding';			@{$self->{' AFM'}->{'char'}}=@glyphs;		} elsif( lc($encoding) eq 'asis' ) {			undef($encoding);		} else {			$encoding='WinAnsiEncoding';			@{$self->{' AFM'}->{'char'}}=@win_enc;		}		$self->{'Encoding'}=PDFDict();		$self->{'Encoding'}->{'Type'}=PDFName('Encoding');		$self->{'Encoding'}->{'BaseEncoding'}=PDFName($encoding) if($encoding);		my $notdefbefore=1;		@w=();		if(@glyphs){			foreach my $w ($first..$last) {				if($glyphs[$w] eq '.notdef') {					$notdefbefore=1;					next;				} else {					if($notdefbefore) {						push(@w,PDFNum($w))					}					$notdefbefore=0;					push(@w,PDFName($glyphs[$w]));				}			}			$self->{'Encoding'}->{'Differences'}=PDFArray(@w);		}	}}sub newCoreLight {	my ($class, $parent, $name, $pdfname) = @_;	my ($file);		$file=resolveFontFile("$name.afm");	if(! -e $file) {	#	print STDERR "could not find '$name.afm' resolving gracefully.\n"; 		$file=undef;	}	$self=newNonEmbedLight($class, $parent, $file, $pdfname, $name);	$self->{' light'}=1;	return($self);}sub new {	my ($class, $parent, $file1, $file2, $pdfname, $encoding, @glyphs) = @_;	my (@w);	my ($l1,$l2,$l3,$stream);	if($file1) {		if($file2) {			$self=newNonEmbed($class, $parent, $file2, $pdfname, $encoding, @glyphs);			($l1,$l2,$l3,$stream)=$self->parsePS($file1,0);		} else {			$self=$class->SUPER::new();			($l1,$l2,$l3,$stream)=$self->parsePS($file1,1);			$self->newNonEmbed($parent, $file2, $pdfname, $encoding, @glyphs);		}		my $s = PDFDict();		$self->{'FontDescriptor'}->{'FontFile'} = $s;		$s->{'Length1'} = PDFNum($l1);		$s->{'Length2'} = PDFNum($l2);		$s->{'Length3'} = PDFNum($l3);		$s->{'Filter'} = PDFArray(PDFName("FlateDecode"));		$s->{' stream'} = $stream;		if(defined $parent) {			$parent->new_obj($s);		}	} else {		$self=newNonEmbed($class, $parent, $file2, $pdfname, $encoding, @glyphs);	}		if(defined($parent) && !$self->is_obj($parent)) {	##	$parent->new_obj($self->{'FontDescriptor'});		$parent->new_obj($self);	}	return($self);}=head2 $f->reencode $parentpdf $pdfname $encoding [@glyphs]Reencodes the current font $f with encoding $encoding (optional variant @glyphs)to be used with name $pdfname.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -