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

📄 bdftops.ps

📁 GhostScript的源代码
💻 PS
📖 第 1 页 / 共 2 页
字号:
      keyword (STARTPROPERTIES) eq
       { iarg
          { nextline
	    properties keyword known
	     { FontInfo properties keyword get sarg readonly put
	     } if
	  } repeat
         (ENDPROPERTIES) getline
	 nextline
       } if

%  Compute and set the FontMatrix.
      Font /FontMatrix
       [ 0.001 0 0 0.001 xres mul yres div 0 0 ] readonly
      dup setmatrix put

%  Read and process the header for the bitmaps.
      (CHARS) checkline
	/ccount iarg def

%  Initialize the CharStrings dictionary.
      /charstrings ccount
	composites length add
	aliases length add
	accentedchars length add
	1 add dict def		% 1 add for .notdef
      /isfixedwidth true def
      /fixedwidth null def
      /subrcount 0 def
      /subrs [] def

%  Read the bitmap data.  This reads the remainder of the file.
%  We do this before processing the bitmaps so that we can compute
%  the correct FontBBox first.
      /chardata ccount dict def
      ccount -1 1
       { (STARTCHAR) getline
           /charname remarg def
	 (ENCODING) getline
	   /eindex iarg def
	   eindex 0 ge
	    { charname /charname StandardEncoding eindex get def
	      charname /.notdef eq eindex 0 gt and
	       { /charname (A) eindex =string cvs concatstrings cvn def
	       }
	      if
	      (/) print charname =string cvs print (,) print print
	    }
	    { (/) print charname print
	    }
	   ifelse
	   10 mod 1 eq { (\n) print flush } if
	 (SWIDTH) getline
	   /swx iarg pointsize mul 1000 div xres mul 72 div def
	   /swy iarg pointsize mul 1000 div xres mul 72 div def
	 (DWIDTH) getline		% Ignore, use SWIDTH instead
	 (BBX) getline
	   /bbw iarg def  /bbh iarg def  /bbox iarg def  /bboy iarg def
	 nextline
	 keyword (ATTRIBUTES) eq
	  { nextline
	  } if
	 (BITMAP) checkline

% Update the font bounding box.
	 /fbbxo fbbxo bbox min def
	 /fbbyo fbbyo bboy min def
	 /fbbxe fbbxe bbox bbw add max def
	 /fbbye fbbye bboy bbh add max def

% Read the bits for this character.
	 /raster bbw 7 add 8 idiv def
	 /cbits raster bbh mul string def
	 0 raster cbits length raster sub
	  { cbits exch raster getinterval
	    bdfile buffer readline not
	     { (EOF in bitmap\n) print stop } if
		% stack has <cbits.interval> <buffer.interval>
	    0 () /SubFileDecode filter
	    exch 2 copy readhexstring pop pop pop closefile
	  } for
	 (ENDCHAR) getline

% Save the character data.
	 chardata charname [swx swy bbw bbh bbox bboy cbits] put
       } for

      (ENDFONT) getline

% Allocate the buffers for the bitmap and the outline,
% according to the font bounding box.
      /fbbw fbbxe fbbxo sub def
      /fbbh fbbye fbbyo sub def
      /fraster fbbw 7 add 8 idiv def
      /bits fraster fbbh mul 200 max 65535 min string def
      /outline bits length 6 mul 65535 min string def

%  Process the characters.
      chardata
       { exch /charname exch def  aload pop
	 /cbits exch def
	 /bboy exch def   /bbox exch def
	 /bbh exch def   /bbw exch def
	 /swy exch def   /swx exch def

% The bitmap handed to type1imagepath must have the correct height,
% because type1imagepath uses this to compute the scale factor,
% so we have to clear the unused parts of it.
	 /raster bbw 7 add 8 idiv def
	 bits dup 0 1 raster fbbh mul 1 sub
	  { 0 put dup } for
	 pop pop
	 bits raster fbbh bbh sub mul cbits putinterval

%  Compute the font entry, converting the bitmap to an outline.
	 bits 0 raster fbbh mul getinterval	% the bitmap image
	 bbw   fbbh				% bitmap width & height
	 swx   swy				% width x & y
	 bbox neg   bboy neg			% origin x & y
	 	% Account for lenIV when converting the outline.
	 outline  lenIV  outline length lenIV sub  getinterval
	 type1imagepath
	 length lenIV add
	 outline exch 0 exch getinterval

% Check for a fixed width font.
	 isfixedwidth
	  { fixedwidth null eq
	     { /fixedwidth swx def }
	     { fixedwidth swx ne { /isfixedwidth false def } if }
	    ifelse
	  } if

% Finish up the character.
	 copystring
	 charname exch charstrings 3 1 roll put
       } forall

%  Add CharStrings entries for aliases.
      aliases
       { charstrings 2 index known not charstrings 2 index known and
          { charstrings exch get charstrings 3 1 roll put
	  }
	  { pop pop
	  }
	 ifelse
       }
      forall

%  If this is not a fixed-width font, synthesize missing characters
%  out of available ones.
      isfixedwidth not
       { false composites
	  { 1 index charstrings exch known not
	    1 index { decoding exch known and } forall
	     { ( /) print 1 index bits cvs print
	       /combine exch def
	       0 1 combine length 1 sub
		{ dup combine exch get decoding exch get
		  bits 3 1 roll put
		} for
	       bits 0 combine length getinterval copystring
	       [ exch /compose_proc load aload pop ] cvx
	       charstrings 3 1 roll put
	       pop true
	     }
	     { pop pop }
	    ifelse
	  }
	 forall flush
	  { Private /composematrix matrix put
	    Private /compose /compose load put
	  }
	 if
       }
      if

%  Synthesize accented characters with seac if needed and possible.
      accentedchars
       { aload pop /accent exch def /base exch def
         buffer cvs /accented exch def
	 charstrings accented known not
	 charstrings base known and
	 charstrings accent known and
	 StandardDecoding base known and
	 StandardDecoding accent known and
	 encoding StandardDecoding base get get base eq and
	 encoding StandardDecoding accent get get accent eq and
	  { ( /) print accented print
	    charstrings base get findsbw 0 exch getinterval
	    /acstring exch def		% start with sbw of base
	    charstrings accent get parsesbw
	    4 { pop } repeat		% just leave sbx
	    acstring exch concatnum
	    0 concatnum 0 concatnum		% adx ady
	    decoding base get concatnum		% bchar
	    decoding accent get concatnum	% achar
	    s_seac concatstrings
	    charstrings exch accented copystring exch put
	  } if
       } forall

%  Make a CharStrings entry for .notdef.
      outline lenIV <8b8b0d0e> putinterval	% 0 0 hsbw endchar
      charstrings /.notdef outline 0 lenIV 4 add getinterval copystring put

%  Encrypt the CharStrings and Subrs (in place).
      charstrings
       {	% Be careful not to encrypt aliased characters twice,
		% since they share their CharString.
	 aliases 2 index known
	  { charstrings aliases 3 index get .knownget
	     { 1 index ne }
	     { true }
	    ifelse
	  }
	  { true
	  }
	 ifelse
	 1 index type /stringtype eq and
          { 4330 exch dup .type1encrypt exch pop
	    readonly charstrings 3 1 roll put
	  }
	  { pop pop
	  }
	 ifelse
       }
      forall
      0 1 subrcount 1 sub
       { dup subrs exch get
	 4330 exch dup .type1encrypt exch pop
	 subrs 3 1 roll put
       }
      for

%  Make most of the remaining entries in the font dictionaries.

% The Type 1 font machinery really only works with a 1000 unit
% character coordinate system.  Set this up here, by computing the factor
% to make the X entry in the FontMatrix come out at exactly 0.001.
      /fontscale 1000 fbbh div yres mul xres div def
      Font /FontBBox
       [ fbbxo fontscale mul
	 fbbyo fontscale mul
	 fbbxe fontscale mul
	 fbbye fontscale mul
       ] cvx readonly put
      Font /CharStrings charstrings readonly put
      FontInfo /FullName known not
       { % Some programs insist on FullName being present.
         FontInfo /FullName FontName dup length string cvs put
       }
      if
      FontInfo /isFixedPitch isfixedwidth put
      subrcount 0 gt
       { Private /Subrs subrs 0 subrcount getinterval readonly put
       } if

%  Determine the italic angle and underline position
%  by actually installing the font.
      save
      /_temp_ Font definefont setfont
      [1000 0 0 1000 0 0] setmatrix		% mitigate rounding problems
% The italic angle is the multiple of -5 degrees
% that minimizes the width of the 'I'.
      0 9999 0 5 85
       { dup rotate
         newpath 0 0 moveto (I) false charpath
	 dup neg rotate
         pathbbox pop exch pop exch sub
	 dup 3 index lt { 4 -2 roll } if
	 pop pop
       }
      for pop
% The underline position is halfway between the bottom of the 'A'
% and the bottom of the FontBBox.
      newpath 0 0 moveto (A) false charpath
      FontMatrix concat
      pathbbox pop pop exch pop
%  Put the values in FontInfo.
      3 -1 roll
      restore
      Font /FontBBox get 1 get add 2 div cvi
      dup FontInfo /UnderlinePosition 3 -1 roll put
      2 div abs FontInfo /UnderlineThickness 3 -1 roll put
      FontInfo /ItalicAngle 3 -1 roll put

%  Clean up and finish.
      grestore
      bdfile closefile
      Font currentdict end end begin		% remove font from dict stack
      (\n) print flush

    } bind def

% ------ Reader for AFM files ------ %

% Dictionary for looking up character keywords
   /cmdict 6 dict dup begin
      /C { /c iarg def } def
      /N { /n warg copystring def } def
      /WX { /w narg def } def
      /W0X /WX load def
      /W /WX load def
      /W0 /WX load def
   end def

   /readAFM		% fontdict afmfilename readAFM -> fontdict
    { (r) file /bdfile exch def
      /Font exch def
      /commentword (Comment) def

%  Check for the StartFontMetrics.
      (StartFontMetrics) getline
      args cvr 2.0 lt { (Not version 2.0 or greater\n) print stop } if

%  Look for StartCharMetrics, then parse the character metrics.
%  The only information we care about is the X width.
      /metrics 0 dict def
       { nextline
         keyword (EndFontMetrics) eq { exit } if
	 keyword (StartCharMetrics) eq
	  { iarg dup dict /metrics exch def
	     { /c -1 def /n null def /w null def
	       nextline buffer
		{ token not { exit } if
		  dup cmdict exch known
		   { exch /args exch def   cmdict exch get exec   args }
		   { pop }
		  ifelse
		} loop
	       c 0 ge n null ne or w null ne and
		{ n null eq { /n Font /Encoding get c get def } if
		  metrics n w put
		}
	       if
	     }
	    repeat
	    (EndCharMetrics) getline
	  } if
       } loop

%  Insert the metrics in the font.
       metrics length 0 ne
	{ Font /Metrics metrics readonly put
	} if
      Font
    } bind def

end		% envBDF

% Enter the main program in the current dictionary.
/bdfafmtops		% infilename afmfilename* outfilename fontname
			%   encodingname uniqueID xuid
 { envBDF begin
     7 -2 roll exch 7 2 roll	% afm* in out fontname encodingname uniqueID xuid
     readBDF		% afm* font
     exch { readAFM } forall
     save exch
     dup /FontName get exch definefont
     setfont
     psfile writefont
     restore
     psfile closefile
   end
 } bind def

% If the program was invoked from the command line, run it now.
[ shellarguments
 { counttomark 4 ge
    { dup 0 get
      dup 48 ge exch 57 le and		% last arg starts with a digit?
       { /StandardEncoding }		% no encodingname
       { cvn }				% have encodingname
      ifelse
      exch (.) search			% next-to-last arg has . in it?
       { mark 4 1 roll			% have xuid
          { cvi exch pop exch (.) search not { exit } if }
	 loop cvi ]
	 3 -1 roll cvi exch
       }
       { cvi null			% no xuid
       }
      ifelse
      counttomark 5 roll
      counttomark 6 sub array astore
      7 -2 roll cvn 7 -3 roll		% make sure fontname is a name
      bdfafmtops
    }
    { cleartomark
      (Usage:\n  bdftops xx.bdf [yy1.afm ...] zz.gsf fontname uniqueID [xuid] [encodingname]\n) print flush
      mark
    }
   ifelse
 }
if pop

⌨️ 快捷键说明

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