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
26 static int vf_load_font __PROTO((DviParams *, DviFont *));
27 static void vf_free_macros __PROTO((DviFont *));
29 /* only symbol exported by this file */
30 DviFontInfo vf_font_info = {
32 1, /* virtual fonts scale just fine */
44 DviFontInfo ovf_font_info = {
46 1, /* virtual fonts scale just fine */
58 static int vf_load_font(DviParams *params, DviFont *font)
76 if(fuget1(p) != 247 || fuget1(p) != 202)
79 fseek(p, (long)mlen, SEEK_CUR);
81 if(checksum && font->checksum && checksum != font->checksum) {
82 warning(_("%s: Checksum mismatch (expected %u, got %u)\n"),
83 font->fontname, font->checksum, checksum);
84 } else if(!font->checksum)
85 font->checksum = checksum;
86 font->design = fuget4(p);
88 /* read all the fonts in the preamble */
91 /* initialize alpha, beta and z for TFM width computation */
92 TFMPREPARE(font->scale, z, alpha, beta);
95 while(op >= DVI_FNT_DEF1 && op <= DVI_FNT_DEF4) {
105 /* process fnt_def commands */
107 id = fugetn(p, op - DVI_FNT_DEF1 + 1);
108 checksum = fuget4(p);
112 /* scale this font according to our parent's scale */
113 scale = TFMSCALE(scale, z, alpha, beta);
114 design = FROUND(params->tfm_conv * design);
116 /* compute the resolution */
117 hdpi = FROUND(params->mag * params->dpi * scale / design);
118 vdpi = FROUND(params->mag * params->vdpi * scale / design);
119 n = fuget1(p) + fuget1(p);
120 name = mdvi_malloc(n + 1);
121 fread(name, 1, n, p);
123 DEBUG((DBG_FONTS, "(vf) %s: defined font `%s' at %.1fpt (%dx%d dpi)\n",
124 font->fontname, name,
125 (double)scale / (params->tfm_conv * 0x100000), hdpi, vdpi));
128 ref = font_reference(params, id, name, checksum, hdpi, vdpi, scale);
130 error(_("(vf) %s: could not load font `%s'\n"),
131 font->fontname, name);
136 font->subfonts = last = ref;
143 if(op >= DVI_FNT_DEF1 && op <= DVI_FNT_DEF4)
146 /* This function correctly reads both .vf and .ovf files */
148 font->chars = xnalloc(DviFontChar, 256);
149 for(i = 0; i < 256; i++)
150 font->chars[i].offset = 0;
153 /* now read the characters themselves */
168 if(loc < 0 || cc < loc)
170 if(hic < 0 || cc > hic)
173 font->chars = xresize(font->chars,
174 DviFontChar, cc + 16);
175 for(i = nchars; i < cc + 16; i++)
176 font->chars[i].offset = 0;
179 if(font->chars[cc].offset) {
180 error(_("(vf) %s: character %d redefined\n"),
185 DEBUG((DBG_GLYPHS, "(vf) %s: defined character %d (macro length %d)\n",
186 font->fontname, cc, pl));
187 font->chars[cc].width = pl + 1;
188 font->chars[cc].code = cc;
189 font->chars[cc].tfmwidth = TFMSCALE(tfm, z, alpha, beta);
190 font->chars[cc].offset = mlen;
191 font->chars[cc].loaded = 1;
192 if(mlen + pl + 1 > msize) {
193 msize = mlen + pl + 256;
194 macros = xresize(macros, Uchar, msize);
196 if(pl && fread(macros + mlen, 1, pl, p) != pl)
198 macros[mlen+pl] = DVI_EOP;
203 error(_("(vf) %s: no postamble\n"), font->fontname);
207 /* make macro memory just big enough */
209 macros = xresize(macros, Uchar, mlen);
213 DEBUG((DBG_FONTS|DBG_GLYPHS,
214 "(vf) %s: macros use %d bytes\n", font->fontname, msize));
216 if(loc > 0 || hic < nchars-1) {
217 memmove(font->chars, font->chars + loc,
218 (hic - loc + 1) * sizeof(DviFontChar));
219 font->chars = xresize(font->chars,
220 DviFontChar, hic - loc + 1);
224 font->private = macros;
229 error(_("%s: File corrupted, or not a VF file.\n"), font->fontname);
232 mdvi_free(font->chars);
238 static void vf_free_macros(DviFont *font)
240 mdvi_free(font->private);