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

📄 gs_ttf.ps

📁 GhostScript的源代码
💻 PS
📖 第 1 页 / 共 2 页
字号:

% Read a big table (one that may exceed 64K).
% <file> <length> .readbigtable <string[s]>
/.readbigtable {
  dup 65400 lt {
    .readtable
  } {
    currentuserparams /VMReclaim get -2 vmreclaim
    [ 4 2 roll {
		% Stack: mark ... f left
      dup maxstring le { exit } if
      1 index maxstring string readstring pop 3 1 roll maxstring sub
    } loop .readtable ]
    exch vmreclaim
  } ifelse
} bind def

.dicttomark readonly def                % .loadttfontdict

% <tab> .printtab -
/.printtab {
  dup 0 4 getinterval print ( ) print
  dup 8 getu32 =only ( ) print
  12 getu32 =
} bind def

% <file> .loadttfonttables -
% Pushes .loadttfontdict & scratch dict on d-stack.
% Defines f, offsets, tables, tabdict, tabs.
/.loadttfonttables {
  .loadttfontdict begin
  40 dict begin
  /f exch def
  /offsets f 12 string readstring pop def
  /tables f offsets 4 getu16 16 mul string readstring pop def
  /tabdict tables length 16 idiv dict def
	% tabs = tables we want to keep, sorted by file position.
  /tabs [ 0 16 tables length 1 sub {
    tables exch 16 getinterval
    DEBUG { dup .printtab } if
    dup 0 4 getinterval readtables 1 index known {
      tabdict exch 2 index put
    } {
      pop pop
    } ifelse
  } for ] {
    exch 8 getu32 exch 8 getu32 lt
  } sort def
} bind def

% - .readttdata -
% Read data.  Updates offsets, tabs; stores data in tabdict.
/.readttdata {
  /fpos offsets length tables length add def
  /sfpos offsets length tabs length 16 mul add def
  offsets 4 tabs length putu16
  tabs {
    dup 0 4 getinterval /tname exch def
    dup 8 getu32 /tpos exch def
    dup 12 getu32 /tlen exch def
    8 sfpos putu32
	% Skip data between the end of the previous table and
	% the beginning of this one, if any.
    tpos fpos gt {
      f tpos fpos sub () /SubFileDecode filter dup flushfile closefile
      /fpos tpos def
    } if
    f tlen readtables tname get exec
    tabdict tname 3 -1 roll put
    /fpos fpos tlen add def
	% Round up the table length to an even value.
    /sfpos sfpos tlen dup 1 and add add def
  } forall
} bind def

% Find the string in a list of strings that includes a given index.
% <strings> <index> .findseg <string> <index'>
/.findseg {
  exch {
    dup length 2 index gt { exch exit } if
    length sub
  } forall
} bind def

% - .makesfnts -
% Defines checksum, getloca, head, locatable, numglyphs, post, sfnts, upem
/.makesfnts {
  .readttdata
  /head tabdict /head get def
   /checksum head 8 getu32 def
  /locatable tabdict /loca get def
  /post tabdict /post .knownget not { null } if def
  /numglyphs
    locatable dup type /stringtype eq
     { length }
     { 0 exch { length add } forall }
    ifelse	% no def yet
  locatable type /stringtype eq {
    /.indexloca {} def
  } {
    /.indexloca /.findseg load def
  } ifelse
  head 50 getu16 0 ne {
    /getloca {
      2 bitshift locatable exch .indexloca getu32
    } def
    4 idiv 1 sub
  } {
    /getloca {
      dup add locatable exch .indexloca getu16 dup add
    } def
    2 idiv 1 sub
  } ifelse def		% numglyphs
	% If necessary, re-partition the glyfs.
  tabdict /glyf get dup type /stringtype ne {
    .dividesfnts tabdict /glyf 3 -1 roll put
  } {
    pop
  } ifelse
  /sfnts [
    offsets tabs { concatstrings } forall
    tabs {
      0 4 getinterval tabdict exch get
      dup type /stringtype ne { aload pop } if
    } forall
  ] def
} bind def

% - .getcmap -
% Defines cmapsub, cmaptab
/.getcmap {
   tabdict /cmap get
		% The Apple cmap format is no help in determining the encoding.
		% Look for a Microsoft table.  If we can't find one,
		% just use the first table, whatever it is.
   dup 4 8 getinterval exch             % the default
   0 1 2 index 2 getu16 1 sub
    { 8 mul 4 add 1 index exch 8 getinterval
      dup 0 getu16 3 eq { exch 3 -1 roll pop exit } if pop
    }
   for
		% Stack: subentry table
   /cmapsub 2 index def
   exch 4 getu32 1 index length 1 index sub getinterval
   /cmaptab exch def
} bind def

% <glyfs> .dividesfnts <glyfs'>
/.dividesfnts {
  /glyfs exch def
  /len1 0 glyfs { length add } forall def
		% Determine where to split the glyfs by scanning loca.
		% The very last entry in loca may be bogus.
		%
		% Construct splitarray, the array of final lengths of
		% the sfnts entries covering the glyfs (i.e., all but
		% the first and last sfnts entries).
    /prevsplit 0 def
    /prevboundary 0 def
    /splitarray [
      0 1 numglyphs 1 sub {
	getloca dup prevsplit maxstring add gt {
	  prevboundary prevsplit sub exch
	  /prevsplit prevboundary def
	} if
	/prevboundary exch def
      } for
      len1 prevsplit sub
    ] def
    currentuserparams /VMReclaim get -2 vmreclaim
    [
		% Re-split the sfnts glyfs strings according to splitarray.
		% We do this by iterating over the final segments defined
		% by splitarray, and constructing them from pieces of the
		% current glyfs strings.  We recycle the current strings
		% when possible, to avoid stressing the allocator.
      /sfnt_idx 0 def
      /strpos 0 def
      /avail () def
      splitarray {
	/seglen exch def
	/segpos 0 def
	avail length seglen ge
	  { avail 0 seglen getinterval /avail () def } { seglen string }
	ifelse
	{
	  /str glyfs sfnt_idx get def
	  /strlen str length def
	  /strleft strlen strpos sub def
	  seglen segpos sub strleft lt { exit } if
		% Copy the (rest of the) string into the new segment.
		% We know strleft <= segleft.
	  dup segpos str strpos strleft getinterval putinterval
	  /segpos segpos strleft add def
	  /avail str def
	  /sfnt_idx sfnt_idx 1 add def
	  /strpos 0 def
	  segpos seglen eq { exit } if
	} loop
		% Fill up the segment with an initial piece of the next
		% existing glyfs string.  We know strleft > segleft.
	/segleft seglen segpos sub def
	dup segpos str strpos segleft getinterval putinterval
	/strpos strpos segleft add def
      } forall
    ]
    exch vmreclaim
} bind def

% - .ttkeys <key> <value> ...
/.ttkeys {
  /upem head 18 getu16 def
  /FontMatrix matrix
  /FontBBox [ 36 2 42 { head exch gets16 upem div } for ]
  tabdict /name .knownget {
		% Find the names from the 'name' table.
    /names exch def
    /FontName names 6 findname not { checksum 16 8 string cvrs } if
      /fontname 1 index def
    /FontInfo mark
      names 0 findname { /Notice exch } if
      names 1 findname { /FamilyName exch } if
      names 4 findname { /FullName exch } if
      names 5 findname { /Version exch } if
  } {
		% No name table, fabricate a FontName.
    /FontName checksum 16 8 string cvrs
      /fontname 1 index def
    /FontInfo mark
  } ifelse
		% Stack: ... /FontInfo mark key1 value1 ...
  post null ne {
    /ItalicAngle post 4 gets32 65536.0 div
    /isFixedPitch post 12 getu32 0 ne
    /UnderlinePosition post 8 gets16 upem div
    /UnderlineThickness post 10 gets16 upem div
  } if
  counttomark 0 ne { .dicttomark } { pop pop } ifelse
  /XUID [orgXUID 42 checksum]
  /sfnts sfnts
  DEBUG {
    tabs { .printtab } forall
    [ sfnts { length } forall ] ==
  } if
} bind def

% -mark- <key> <value> ... .definettfont <font>
/.definettfont {
  /FontType 42
  /PaintType 0
		% See if we have PostScript glyph name information.
   /glyphencoding post null eq {
     [ ]
   } {
     postformats post 0 getu32 .knownget { post exch exec } { [ ] } ifelse
   } ifelse
		% If necessary, fabricate additional glyphencoding entries
		% to cover all of loca.
   dup length numglyphs lt {
     [ exch aload pop
     counttomark 1 numglyphs 1 sub {
	=string cvs (_) exch concatstrings cvn
     } for ]
   } if def
  /Encoding
    cmaptab cmaparray
    counttomark array astore
    { glyphencoding exch get } forall
    counttomark 256 sub dup 0 ge {
      { pop } repeat
    } { neg { /.notdef } repeat
    } ifelse ]
		% Until we can compute the MD5 fingerprint,
		% just use the precomputed checksum.
  /CharStrings glyphencoding dup length dict
    0 1 3 index length 1 sub {
		% Stack: glyphencoding dict index
      2 index 1 index get 2 index 1 index known {
	pop pop
      } {
	2 index exch 3 -1 roll put
      } ifelse
    } for exch pop readonly
  .dicttomark
  end end dup /FontName get exch definefont
} bind def

% Create a string with N CIDs from the top of the stack.
% <cid1> ... <cidN> <N> .makecidmap <string>
/.makecidmap {
  dup 2 mul string dup 3 -1 roll 1 sub 2 mul -2 0 {
		% Stack: cids str str i2
    2 copy 5 index -8 bitshift put
    1 add 4 -1 roll 16#ff and put dup
  } for pop
} bind def

% -mark- <key> <value> ... .definettcidfont <font>
/.definettcidfont {
  /CIDFontName fontname
  /CIDFontType 2
  /CIDSystemInfo mark
    /Registry (Adobe)
    /Ordering (Japan1)		% adhoc
    /Supplement 0
  .dicttomark
  /CharStrings mark /.notdef 0 .dicttomark
  cmaptab cmaparray
  counttomark /cidcount exch def
  cidcount maxstring le {
		% Use a single string.
    cidcount .makecidmap exch pop
  } {
		% We must use 2 strings.
    maxstring .makecidmap counttomark 1 add 1 roll
    counttomark .makecidmap exch pop exch 2 array astore
  } ifelse
  /CIDMap exch
  /CIDCount cidcount
  /GDBytes 2
  .dicttomark
  end end dup /CIDFontName get exch /CIDFont defineresource
} bind def

% <file> .loadttfont <type42font>
/.loadttfont {
  .loadttfonttables
  .makesfnts
  .getcmap
  mark
  .ttkeys
  .definettfont
} bind def

% <file> .loadttcidfont <cidtype2font>
/.loadttcidfont {
  .loadttfonttables
  .makesfnts
  .getcmap
  mark
  .ttkeys
  .definettcidfont
} bind def

⌨️ 快捷键说明

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