% $Id: tfmin.w 1682 2011-05-30 07:24:45Z taco $
%
% Copyright 2008-2009 Taco Hoekwater.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public License
% along with this program. If not, see .
%
% TeX is a trademark of the American Mathematical Society.
% METAFONT is a trademark of Addison-Wesley Publishing Company.
% PostScript is a trademark of Adobe Systems Incorporated.
% Here is TeX material that gets inserted after \input webmac
\font\tenlogo=logo10 % font used for the METAFONT logo
\font\logos=logosl10
\def\MF{{\tenlogo META}\-{\tenlogo FONT}}
\def\MP{{\tenlogo META}\-{\tenlogo POST}}
\def\title{Reading TEX metrics files}
\pdfoutput=1
@ Introduction.
@ Needed headers and macros
@d qi(A) (quarterword)(A) /* to store eight bits in a quarterword */
@d null_font 0 /* the |font_number| for an empty font */
@d false 0
@d true 1
@d hlp1(A) mp->help_line[0]=A; }
@d hlp2(A,B) mp->help_line[1]=A; hlp1(B)
@d hlp3(A,B,C) mp->help_line[2]=A; hlp2(B,C)
@d help3 { mp->help_ptr=3; hlp3 /* use this with three help lines */
@c
#include
#include
#include
#include
#include "mplib.h"
#include "mpmp.h" /* internal header */
#include "mpmath.h" /* internal header */
#include "mpstrings.h" /* internal header */
@;
@h
@ The |font_ps_name| for a built-in font should be what PostScript expects.
A preliminary name is obtained here from the \.{TFM} name as given in the
|fname| argument. This gets updated later from an external table if necessary.
@=
font_number mp_read_font_info (MP mp, char *fname);
@ @c
font_number mp_read_font_info (MP mp, char *fname) {
boolean file_opened; /* has |tfm_infile| been opened? */
font_number n; /* the number to return */
halfword lf,tfm_lh,bc,ec,nw,nh,nd; /* subfile size parameters */
size_t whd_size; /* words needed for heights, widths, and depths */
int i,ii; /* |font_info| indices */
int jj; /* counts bytes to be ignored */
int z; /* used to compute the design size */
int d; /* height, width, or depth as a fraction of design size times $2^{-8}$ */
int h_and_d; /* height and depth indices being unpacked */
int tfbyte = 0; /* a byte read from the file */
n=null_font;
@;
@;
BAD_TFM:
@;
DONE:
if ( file_opened ) (mp->close_file)(mp,mp->tfm_infile);
if ( n!=null_font ) {
mp->font_ps_name[n]=mp_xstrdup(mp,fname);
mp->font_name[n]=mp_xstrdup(mp,fname);
}
return n;
}
@ \MP\ doesn't bother to check the entire \.{TFM} file for errors or explain
precisely what is wrong if it does find a problem. Programs called \.{TFtoPL}
@.TFtoPL@> @.PLtoTF@>
and \.{PLtoTF} can be used to debug \.{TFM} files.
@=
{
char msg[256];
const char *hlp[] = {
"I wasn't able to read the size data for this font so this",
"`infont' operation won't produce anything. If the font name",
"is right, you might ask an expert to make a TFM file",
NULL };
if ( file_opened )
hlp[2]="is right, try asking an expert to fix the TFM file";
mp_snprintf(msg, 256, "Font %s not usable: TFM file %s", fname,
( file_opened ? "is bad" : "not found"));
mp_error(mp, msg, hlp, true);
}
@ @=
@;
@