📄 fonts.htm
字号:
"<b><tt>TimesNewRoman</tt></b>". The name may even be completely
different: the usual Helvetica-equivalent TrueType font is called
"<b><tt>Arial</tt></b>". It is possible to deal with this situation by
introducing aliases in Fontmap, but there are two reasons why Ghostscript
does not currently do this:
<ol>
<li>Methods of naming in different systems are so unstandardized that there
seems to be no small set of alternative names likely to cover most
situations. All five of the names above for Times Roman have been seen
under Windows and OS/2, depending on the version of the system, whether it
uses TrueType or ATM, and other unknown factors.
<li>Each alias takes up space at run time. If each of the standard fonts
has three additional aliases, this might amount to 50KB of wasted space,
which may be a lot on some smaller systems.
</ol>
<p>
If you don't seem to be getting nice characters on the screen under MS
Windows, you can try adding aliases to Fontmap, according to the
documentation you'll find in there.
<hr>
<h2><a name="Add_fonts"></a>Adding your own fonts</h2>
<p>
Ghostscript can use any Type 0, 1, 3, 4, or 42 font acceptable to
other PostScript language interpreters or to ATM, including MultiMaster
fonts. Beginning with release 4.0, Ghostscript can also use TrueType fonts
if it was compiled with the "ttfont" option.
<p>
To add fonts of your own, you must edit Fontmap to include at the end an
entry for your new font; the format for entries is documented
in Fontmap itself. Since later entries in Fontmap override earlier
entries, a font you add at the end supersedes any corresponding fonts supplied
with Ghostscript and defined earlier in the file.
<p>
In the PC world, Type 1 fonts are customarily given names ending in
<tt><b>.PFA</b></tt> or <tt><b>.PFB</b></tt>.
Ghostscript can use these directly: you just need to make the entry in
Fontmap. If you want to use with Ghostscript a commercial Type 1 font
(such as fonts obtained in conjunction with Adobe Type Manager), please
read carefully the license that accompanies the font to satisfy yourself
that you may do so legally; Aladdin Enterprises takes no responsibility for
any possible violations of such licenses. The same applies to TrueType
fonts.
<h3><a name="Convert_BDF"></a>Converting BDF fonts</h3>
<p>
Ghostscript provides a way to construct a (low-quality) Type 1 font from a
bitmap font in the BDF format popular in the Unix world. The shell script
<tt><b>bdftops</b></tt> (Unix) or the command file
<tt><b>bdftops.bat</b></tt> (DOS) converts a BDF file to a
scalable outline using <tt><b>bdftops.ps</b></tt> . Run the
shell command
<blockquote><tt><b>
bdftops BDF_filename [AFM_file1_name ...] gsf_filename fontname<br> UniqueID [XUID] [encodingname]
</b></tt></blockquote>
<p>
The arguments have these meanings:
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=top> <td><tt><b>BDF_filename</b></tt>
<td>
<td>Input bitmap file in BDF format
<td>
<td>
<tr valign=top> <td><tt><b>AFM_file1_name</b></tt>
<td>
<td>AFM files giving metrics
<td>
<td>(Optional)
<tr valign=top> <td><tt><b>gsf_filename</b></tt>
<td>
<td>Output file
<td>
<td>
<tr valign=top> <td><tt><b>fontname</b></tt>
<td>
<td>Name of the font
<td>
<td>
<tr valign=top> <td><tt><b>UniqueID</b></tt>
<td>
<td>UniqueID (<a href="#Unique_IDs">as described below</a>)
<td>
<td>
<tr valign=top> <td><tt><b>XUID</b></tt>
<td>
<td>XUID, in the form <tt><b>n1.n2.n3...</b></tt> (<a href="#Unique_IDs">as described below</a>)
<td>
<td>(Optional)
<tr valign=top> <td><tt><b>encodingname</b></tt>
<td>
<td>"StandardEncoding" (the default), "ISOLatin1Encoding",<br>"SymbolEncoding", "DingbatsEncoding"
<td>
<td>(Optional)
</table></blockquote>
<p>
For instance
<blockquote><tt><b>
bdftops pzdr.bdf ZapfDingbats.afm pzdr.gsf ZapfDingbats 4100000 1000000.1.41
</b></tt></blockquote>
<p>
Then make an entry in Fontmap for the <tt><b>.gsf</b></tt>
file (<tt><b>pzdr.gsf</b></tt> in the example) as
<a href="#Add_fonts">described above</a>.
<hr>
<h2><a name="For_developers"></a>For developers only</h2>
<p>
The rest of this document is very unlikely to be of value to ordinary
users.
<h3><a name="Font_contents"></a>Contents of fonts</h3>
<p>
As noted above, Ghostscript accepts fonts in the same formats as PostScript
interpreters. Type 0, 1, and 3 fonts are documented in the PostScript
Language Reference Manual (Second Edition); detailed documentation for Type
1 fonts appears in a separate Adobe book. Type 2 (compressed format) fonts
are documented in separate Adobe publications. Type 4 fonts are not
documented anywhere; they are essentially Type 1 fonts with a BuildChar or
BuildGlyph procedure. Types 9, 10, and 11 (CIDFontType 0, 1, and 2) and
Type 32 (downloaded bitmap) fonts are documented in Adobe supplements.
Type 42 (encapsulated TrueType) fonts are documented in an Adobe
supplement; the TrueType format is documented in publications available
from Apple and Microsoft. Ghostscript does not support Type 14 (Chameleon)
fonts, which use a proprietary Adobe format.
<h3><a name="Precompiling"></a>Precompiling fonts</h3>
<p>
You can precompile -- convert -- any Type 1 font into C, then compile and
build it into the Ghostscript executable. (Type 1 fonts include any font
whose name ends with <tt><b>.pfa</b></tt> or
<tt><b>.pfb</b></tt>, and it also includes all the
Ghostscript <tt><b>.gsf</b></tt> fonts except the Hershey
fonts.) This has no effect on rendering speed, but it eliminates the time
to load the font dynamically, which may make a big improvement in total
rendering time, especially for multi-page documents. It also reduces the
number of auxiliary files required at run time. Fonts precompiled and
built into Ghostscript this way need not appear in Fontmap, although if
they do appear there, no harm is done.
<p><a name="font2c"></a> The utility for precompiling fonts is
"<tt><b>font2c</b></tt>". Note that since
<tt><b>font2c</b></tt> uses the PostScript language program
"<tt><b>font2c.ps</b></tt>", Ghostscript must already be
available to run it, and Fontmap must contain entries for the fonts you
want to compile. For example, to precompile the Times-Italic font,
<blockquote><tt><b>
font2c Times-Italic ptmri.c
</b></tt></blockquote>
<p>
The first argument ("<b><tt>Times-Italic</tt></b>" above) is the font's
name and the second ("<b><tt>ptmri.c</tt></b>") is the name of the
resulting C file. You can use any file name you want, as long as it ends
in "<tt><b>.c</b></tt>". It needn't be limited to eight characters unless
your operating system requires this. If "<b><tt>XYZ.gsf</tt></b>" or
"<b><tt>XYZ.pfa</tt></b>" is the font file's name in Fontmap,
"<b><tt>XYZ.c</tt></b>" is a good choice for the C file.
<p>
Under VMS, or other systems whose the C compilers limit the length of
identifiers, you must do something slightly more complicated; for that see
the section on <a href="#Short_identifiers">short identifiers in C</a>. On
VMS also, you must quote the font name ("{font name}") to preserve the
name's mixed upper and lower case. For VMS environments in general see
<a href="Make.htm#VMS">the VMS directions</a> in the documentation on
building Ghostscript, and ignore the rest of this section.
<p>
Note that fonts are not supplied with Ghostscript in precompiled form,
since those files are quite large and can easily be recreated
<a href="#font2c">using <tt><b>font2c</b></tt></a>. A makefile
"<b><tt>cfonts.mak</tt></b>" runs <tt><b>font2c</b></tt> on all the
fonts supplied with Ghostscript. Invoke it with
<blockquote><tt><b>
make -f cfonts.mak</b></tt> (on some systems <tt><b>make -fcfonts.mak</b></tt>)
</blockquote>
<p>Besides running <tt><b>font2c</b></tt>, you must compile the fonts and
link them into the executable. To do this, add the compiled fonts feature
to your platform-specific makefile. See the
<a href="Make.htm#Makefile_overview">overview of makefiles</a> in the
documentation on building Ghostscript for the list of makefiles for each
platform. Find the definition of the <tt><b>FEATURE_DEVS</b></tt> macro in
the makefile, which looks something like this:
<blockquote><tt><b>
FEATURE_DEVS=psl3.dev pdf.dev dpsnext.dev pipe.dev rasterop.dev
</b></tt></blockquote>
<p>
and add "ccfonts.dev":
<blockquote><tt><b>
FEATURE_DEVS=psl3.dev pdf.dev dpsnext.dev pipe.dev rasterop.dev ccfonts.dev
</b></tt></blockquote>
<p>
Next you must add the specific fonts to <tt><b>int.mak</b></tt>, the
platform-independent makefile for the interpreter. This makefile already
has rules for the standard fonts supplied with Ghostscript, so if you just
want to compile the standard fonts, you needn't do anything else. Now we
describe how to compile other fonts into the executable, such as the Utopia
or Kana fonts, or your own fonts.
<p>
Suppose you want to compile the Kana fonts into the executable. First pick
one of <b><tt>ccfonts10</tt></b>" through <b><tt>ccfonts15</tt></b> as the
place you will do this, say <b><tt>ccfonts10</tt></b>. Add your compiled
font file names, for instance
<blockquote><tt><b>
ccfonts10_=fhirw.$(OBJ)
</b></tt></blockquote>
<p>
(Note the underscore "_".) If this makes the line too long, use another
line of the same form, for instance,
<blockquote><tt><b>
ccfonts11_=fkarw.$(OBJ)
</b></tt></blockquote>
<p>
Just below the <b><tt>ccfonts10_=</tt></b> line is a line
<blockquote><tt><b>
ccfonts10=
</b></tt></blockquote>
<p>
(Note no underscore.) Add your own fonts to the end of this line, replacing
dashes ("-") with underscores ("_") in the font names. For instance:
<blockquote><tt><b>
ccfonts10=Calligraphic_Hiragana
</b></tt></blockquote>
<p>
Again, if a line becomes too long, add another line of the same form, for
instance,
<blockquote><tt><b>
ccfonts10=Calligraphic_Hiragana<br>
ccfonts11=Calligraphic_Katakana
</b></tt></blockquote>
<p>
After all the lines of this form, add a pair of lines to compile each font,
separating these entries from the "ccfonts*" lines and from each other with
a blank line. In our example this becomes
<blockquote><b><tt>
<pre>fhirw.$(OBJ):
fhirw.c $(CCFONT)
$(CCCF) fhirw.c
fkarw.$(OBJ):
fkarw.c $(CCFONT)
$(CCCF) fkarw.c</pre>
</tt></b></blockquote>
<p>
Finally, run <tt><b>make</b></tt> to build an executable that includes the
fonts you added. They are present in <b><tt>FontDirectory</tt></b> when
Ghostscript starts up.
<h3><a name="Short_identifiers"></a>Precompiling fonts on platforms with identifier length limits</h3>
<p>
On some platforms the C compiler or linker limits the number of significant
characters usable in an identifier. On such platforms, you must do a
little extra work.
<p>
Let <em><b>N</b></em> be the maximum number of significant characters in an
identifier (typically 31). For each font whose name is longer than
<em><b>N</b></em>-5 characters, pick an arbitrary identifier that we will
call the "short name". This can be any string you want, as long as it
contains only letters, digits, and underscores; is no longer than
<em><b>N</b></em>-5 characters; and is different from all other font names
and short names. A good choice for this is the name of the C file. There
is no harm in doing this for fonts with names shorter than
<em><b>N</b></em>-5 characters, but it's unnecessary.
<p>
You must do two different things for fonts that require a short name.
<ol>
<li>You must supply the short name as a third argument to
<tt><b>font2c</b></tt>. For example, to compile
<b><tt>NewCenturySchlbk-BoldItalic</tt></b> using the short name
<b><tt>pncbi</tt></b>,
<blockquote><tt><b>
font2c NewCenturySchlbk-BoldItalic pncbi.c pncbi
</b></tt></blockquote>
<li>
Then when you add the font name to the definition of one of the ccfonts*
macros in the makefile, use the short name, not the actual font name, for
instance,
<blockquote><table cellpadding=0 cellspacing=0>
<tr> <td>Use
<td>
<td><tt><b>ccfonts12=pncbi</b></tt>
<tr> <td>Rather than
<td>
<td><tt><b>ccfonts12=NewCenturySchlbk_BoldItalic</b></tt>
</table></blockquote>
</ol>
<p>
Everything else is as described above. This procedure doesn't change the
name of the font in Fontmap or as seen from within Ghostscript; it just
works around a limitation of some older compilers.
<hr>
<h3><a name="Unique_IDs"></a>Font names and unique IDs</h3>
<p>
If you create your own fonts and will use them only within your own
organization, you should use <tt><b>UniqueID</b></tt> values between
4000000 and 4999999, coded like this (see the <a href="#Codes">tables of
codes</a> for font file names below):
<blockquote><table cellpadding=0 cellspacing=0>
<tr><th colspan=5 bgcolor="#CCCC00"><hr><font size="+1">Coding of UniqueID "<tt><b>4TTWVE0</b></tt>"</font><hr>
<tr> <td><tt><b>TT</b></tt>
<td>
<td><a href="#Typeface">Typeface</a>
<td>
<td>two-digit identifier
<tr> <td><tt><b>W</b></tt>
<td>
<td><a href="#Weight">Weight</a>
<td>
<td>normal, bold, etc.
<tr> <td><tt><b>V</b></tt>
<td>
<td><a href="#Variant">Variant</a>
<td>
<td>normal, italic, etc.
<tr> <td><tt><b>E</b></tt>
<td>
<td><a href="#Expansion">Expansion</a>
<td>
<td>normal, condensed, etc.
</table></blockquote>
<p>
This scheme will not work forever: as soon there are more than 99
typefaces, or more than 9 weights or variants, we will have to do something
else. But it suffices for the near future.
<p>
If you plan to distribute fonts, ask Adobe to assign you some UniqueIDs and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -