1 /* vf.c -- VF font support */
3 * Copyright (C) 2000, Matias Atria
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 static int vf_load_font __PROTO((DviParams *, DviFont *));
26 static void vf_free_macros __PROTO((DviFont *));
28 /* only symbol exported by this file */
29 DviFontInfo vf_font_info = {
31 1, /* virtual fonts scale just fine */
43 DviFontInfo ovf_font_info = {
45 1, /* virtual fonts scale just fine */
57 static int vf_load_font(DviParams *params, DviFont *font)
75 if(fuget1(p) != 247 || fuget1(p) != 202)
78 fseek(p, (long)mlen, SEEK_CUR);
80 if(checksum && font->checksum && checksum != font->checksum) {
81 warning(_("%s: Checksum mismatch (expected %u, got %u)\n"),
82 font->fontname, font->checksum, checksum);
83 } else if(!font->checksum)
84 font->checksum = checksum;
85 font->design = fuget4(p);
87 /* read all the fonts in the preamble */
90 /* initialize alpha, beta and z for TFM width computation */
91 TFMPREPARE(font->scale, z, alpha, beta);
94 while(op >= DVI_FNT_DEF1 && op <= DVI_FNT_DEF4) {
104 /* process fnt_def commands */
106 id = fugetn(p, op - DVI_FNT_DEF1 + 1);
107 checksum = fuget4(p);
111 /* scale this font according to our parent's scale */
112 scale = TFMSCALE(scale, z, alpha, beta);
113 design = FROUND(params->tfm_conv * design);
115 /* compute the resolution */
116 hdpi = FROUND(params->mag * params->dpi * scale / design);
117 vdpi = FROUND(params->mag * params->vdpi * scale / design);
118 n = fuget1(p) + fuget1(p);
119 name = mdvi_malloc(n + 1);
120 fread(name, 1, n, p);
122 DEBUG((DBG_FONTS, "(vf) %s: defined font `%s' at %.1fpt (%dx%d dpi)\n",
123 font->fontname, name,
124 (double)scale / (params->tfm_conv * 0x100000), hdpi, vdpi));
127 ref = font_reference(params, id, name, checksum, hdpi, vdpi, scale);
129 error(_("(vf) %s: could not load font `%s'\n"),
130 font->fontname, name);
135 font->subfonts = last = ref;
142 if(op >= DVI_FNT_DEF1 && op <= DVI_FNT_DEF4)
145 /* This function correctly reads both .vf and .ovf files */
147 font->chars = xnalloc(DviFontChar, 256);
148 for(i = 0; i < 256; i++)
149 font->chars[i].offset = 0;
152 /* now read the characters themselves */
167 if(loc < 0 || cc < loc)
169 if(hic < 0 || cc > hic)
172 font->chars = xresize(font->chars,
173 DviFontChar, cc + 16);
174 for(i = nchars; i < cc + 16; i++)
175 font->chars[i].offset = 0;
178 if(font->chars[cc].offset) {
179 error(_("(vf) %s: character %d redefined\n"),
184 DEBUG((DBG_GLYPHS, "(vf) %s: defined character %d (macro length %d)\n",
185 font->fontname, cc, pl));
186 font->chars[cc].width = pl + 1;
187 font->chars[cc].code = cc;
188 font->chars[cc].tfmwidth = TFMSCALE(tfm, z, alpha, beta);
189 font->chars[cc].offset = mlen;
190 font->chars[cc].loaded = 1;
191 if(mlen + pl + 1 > msize) {
192 msize = mlen + pl + 256;
193 macros = xresize(macros, Uchar, msize);
195 if(pl && fread(macros + mlen, 1, pl, p) != pl)
197 macros[mlen+pl] = DVI_EOP;
202 error(_("(vf) %s: no postamble\n"), font->fontname);
206 /* make macro memory just big enough */
208 macros = xresize(macros, Uchar, mlen);
212 DEBUG((DBG_FONTS|DBG_GLYPHS,
213 "(vf) %s: macros use %d bytes\n", font->fontname, msize));
215 if(loc > 0 || hic < nchars-1) {
216 memmove(font->chars, font->chars + loc,
217 (hic - loc + 1) * sizeof(DviFontChar));
218 font->chars = xresize(font->chars,
219 DviFontChar, hic - loc + 1);
223 font->private = macros;
228 error(_("%s: File corrupted, or not a VF file.\n"), font->fontname);
231 mdvi_free(font->chars);
237 static void vf_free_macros(DviFont *font)
239 mdvi_free(font->private);