home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gs-2.6.1.4-bin.lha
/
lib
/
ghostscript
/
gs_fonts.ps
< prev
next >
Wrap
Text File
|
1994-07-11
|
21KB
|
695 lines
% Copyright (C) 1990, 1992, 1993 Aladdin Enterprises. All rights reserved.
%
% This file is part of Ghostscript.
%
% Ghostscript is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
% to anyone for the consequences of using it or for whether it serves any
% particular purpose or works at all, unless he says so in writing. Refer
% to the Ghostscript General Public License for full details.
%
% Everyone is granted permission to copy, modify and redistribute
% Ghostscript, but only under the conditions described in the Ghostscript
% General Public License. A copy of this license is supposed to have been
% given to you along with Ghostscript so you can know your rights and
% responsibilities. It should be in a file named COPYING. Among other
% things, the copyright notice and this notice must be preserved on all
% copies.
% Font initialization and management code.
% The standard representation for PostScript compatible fonts is described
% in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
% Define the default font.
/defaultfontname /Ugly def
% Load the font name -> font file name map.
userdict /Fontmap FontDirectory maxlength dict put
/.loadFontmap % <filename> .loadFontmap -
{ 2 dict begin
mark Fontmap
/;
{ % The stack contains a mark, the dictionary, the font name,
% the file or alias name, and possibly additional information
% about the font.
counttomark 3 sub { pop } repeat .growput
Fontmap
} bind def
3 -1 roll run
end
pop pop % pop the mark and the copy of the dictionary
} bind def
(Fontmap) .loadFontmap
% Parse a font file just enough to find the FontName.
/.findfontname % <file> .findfontname <name> true
% <file> .findfontname false
% Closes the file in either case.
{ { dup token not { false exit } if % end of file
dup /eexec eq { pop false exit } if % reached eexec section
dup /FontName eq
{ xcheck not { dup token exit } if } % found /FontName
{ pop }
ifelse
} loop
dup { 3 } { 2 } ifelse -1 roll closefile
} bind def
(GS_FONTPATH) getenv not { (%END GS_FONTPATH) .skipeof } if
pop
% Scan directories looking for plausible fonts. "Plausible" means that
% the file begins either with %!PS-AdobeFont-, or with \200\001
% followed by four arbitrary bytes and then "%!PS-AdobeFont-".
% To speed up the search, we skip any file whose name appears in
% the Fontmap (with any extension and upper/lower case variation) already.
%
% NOTE: The current implementation of this procedure is Unix/DOS-
% specific. It assumes that '/' and '\' are directory separators; that
% the part of a file name following the last '.' is the extension;
% that ';' cannot appear in a file name; and that ':' can appear in a
% file name only if the file name doesn't begin with '/', '\', or '.'.
% (this is so that Unix systems can use ':' as the separator).
%
/.lowerstring % <string> .lowerstring <lowerstring>
{ 0 1 2 index length 1 sub
{ 2 copy get dup 65 ge exch 90 le and
{ 2 copy 2 copy get 32 add put }
if pop
}
for
} bind def
/.splitfilename % <dir.../base.extn> .basename <base> <extn>
{ { (/) search { true } { (\\) search } ifelse
{ pop pop }
{ exit }
ifelse
}
loop
dup { (.) search { pop pop } { exit } ifelse } loop
2 copy eq
{ pop () }
{ exch dup length 2 index length 1 add sub 0 exch getinterval exch }
ifelse
} bind def
/.scanfontdict Fontmap maxlength dict def
/.scanfontbegin
{ % Construct the table of all file names already in Fontmap.
Fontmap
{ exch pop dup type /stringtype eq
{ .splitfilename pop =string copy .lowerstring cvn
.scanfontdict exch true .growput
}
{ pop
}
ifelse
}
forall
} bind def
/.scanfontskip 4 dict dup begin
(afm) true def
(pfm) true def
end def
/.scan1fontstring 128 string def
/.fontheader (\200\001????%!PS-AdobeFont-*) def
/.scan1fontfirst .fontheader length string def
/.scan1fontdir % <dirname> .scan1fontdir -
{ QUIET not { (Scanning ) print dup print ( for fonts... ) print flush } if
0 exch (/*) concatstrings
{ dup .splitfilename
.scanfontskip exch known exch .scanfontdict exch known or
{ pop
}
{ dup (r) file
dup .scan1fontfirst readstring pop
dup .fontheader 6 16 getinterval .stringmatch
{ pop true }
{ .fontheader .stringmatch }
ifelse
{ dup 0 setfileposition .findfontname
{ dup Fontmap exch known
{ pop pop
}
{ exch copystring exch
Fontmap exch 2 index .growput
.splitfilename pop true .scanfontdict 3 1 roll .growput
1 add
}
ifelse
}
if
}
{ closefile pop
}
ifelse
}
ifelse
}
.scan1fontstring filenameforall
QUIET { pop } { =only ( found.\n) print flush } ifelse
} bind def
% Scan all the directories mentioned in GS_FONTPATH.
(GS_FONTPATH) getenv
{ .scanfontbegin
% Parsing the list of dictionaries is messy, since we have to
% handle both the Unix : and the other-system ; as separators.
% See the earlier comment for the restrictions that make this work.
{ dup length 0 eq { pop exit } if
(;) search
{ exch pop
}
{ dup 0 1 getinterval (/\\.) exch search
{ pop pop pop (:) search
{ exch pop }
{ () exch }
ifelse
}
{ pop () exch
}
ifelse
}
ifelse .scan1fontdir
}
loop
}
if
%END GS_FONTPATH
% If DISKFONTS is true, we load individual CharStrings as they are needed.
% (This is intended primarily for machines with very small memories.)
% In this case, we define another dictionary, parallel to FontDirectory,
% that retains an open file for every font loaded.
/FontFileDirectory 10 dict def
% Define an augmented version of .buildfont1 that inserts UnderlinePosition
% and UnderlineThickness entries in FontInfo if they aren't there already.
% (This works around the incorrect assumption, made by many word processors,
% that these entries are present in the built-in fonts.)
/.buildfont1x
{ dup /FontInfo known not
{ dup /FontInfo 2 dict .growput }
if
dup dup /FontInfo get dup dup
/UnderlinePosition known exch /UnderlineThickness known and
{ pop pop % entries already present
}
{ dup length 2 add dict copy
dup /UnderlinePosition known not
{ dup /UnderlinePosition 3 index /FontBBox get
1 get 2 div put % 1/2 the font descent
}
if
dup /UnderlineThickness known not
{ dup /UnderlineThickness 3 index /FontBBox get
dup 3 get exch 1 get sub 20 div put % 1/20 the font height
}
if
1 index /FontInfo get wcheck not { readonly } if
/FontInfo exch put
}
ifelse .buildfont1
} bind def
% Define definefont. This is a procedure built on a set of operators
% that do all the error checking and key insertion.
mark
/.buildfont0 where { pop 0 /.buildfont0 load } if
/.buildfont1 where { pop 1 /.buildfont1x load } if
/.buildfont3 where { pop 3 /.buildfont3 load } if
.dicttomark /.buildfontdict exch def
/definefont
{ 1 dict begin count /d exch def % save stack depth in case of error
{ % Check for disabled platform fonts.
NOPLATFONTS
{ dup maxlength 1 index length sub 2 lt { dup .growdict } if
dup /ExactSize 0 put
}
{ % Hack: if the Encoding looks like it might be the
% Symbol or Dingbats encoding, load those now (for the
% benefit of platform font matching) just in case
% the font didn't actually reference them.
dup /Encoding get length 65 ge
{ dup /Encoding get 64 get
dup /congruent eq { SymbolEncoding pop } if
/a9 eq { DingbatsEncoding pop } if
}
if
}
ifelse
dup /FontType get //.buildfontdict exch get exec
DISKFONTS
{ FontFileDirectory 2 index known
{ dup /FontFile FontFileDirectory 4 index get .growput
}
if
}
if
readonly
}
stopped
{ count d sub { pop } repeat end /invalidfont signalerror }
{ end dup FontDirectory 4 2 roll .growput }
ifelse
} odef
% If