2 * Copyright (C) 2000, Matias Atria
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 static int tfm_load_font __PROTO((DviParams *, DviFont *));
30 static int tfm_font_get_glyph __PROTO((DviParams *, DviFont *, int));
32 DviFontInfo tfm_font_info = {
34 0, /* scaling not supported by format */
46 DviFontInfo ofm_font_info = {
48 0, /* scaling not supported by format */
60 DviFontInfo afm_font_info = {
62 0, /* scaling not supported by format */
74 #define TYPENAME(font) \
75 ((font)->search.info ? (font)->search.info : "none")
78 * Although it does not seem that way, this conversion is independent of the
79 * shrinking factors, within roundoff (that's because `conv' and `vconv'
80 * have already been scaled by hshrink and vshrink, repsectively). We
81 * should really use `dviconv' and `dvivconv', but I'm not so sure those
82 * should be moved to the DviParams structure.
84 #define XCONV(x) FROUND(params->conv * (x) * params->hshrink)
85 #define YCONV(y) FROUND(params->vconv * (y) * params->vshrink)
87 /* this is used quite often in several places, so I made it standalone */
88 int get_tfm_chars(DviParams *params, DviFont *font, TFMInfo *info, int loaded)
95 n = info->hic - info->loc + 1;
96 if(n != FONT_GLYPH_COUNT(font)) {
97 font->chars = mdvi_realloc(font->chars,
98 n * sizeof(DviFontChar));
100 font->loc = info->loc;
101 font->hic = info->hic;
105 /* Prepare z, alpha and beta for TFM width computation */
106 TFMPREPARE(font->scale, z, alpha, beta);
108 /* get the character metrics */
109 for(n = info->loc; n <= info->hic; ch++, ptr++, n++) {
112 ch->offset = ptr->present;
115 /* this is what we came here for */
116 ch->tfmwidth = TFMSCALE(z, ptr->advance, alpha, beta);
117 /* scale all other TFM units (so they are in DVI units) */
118 a = TFMSCALE(z, ptr->left, alpha, beta);
119 b = TFMSCALE(z, ptr->right, alpha, beta);
120 c = TFMSCALE(z, ptr->height, alpha, beta);
121 d = TFMSCALE(z, ptr->depth, alpha, beta);
123 /* now convert to unscaled pixels */
124 ch->width = XCONV(b - a);
125 ch->height = YCONV(c - d);
126 if(ch->height < 0) ch->height = -ch->height;
130 * the offset is not used, but we might as well set it to
131 * something meaningful (and it MUST be non-zero)
135 ch->glyph.data = NULL;
136 ch->grey.data = NULL;
137 ch->shrunk.data = NULL;
145 * We use this function as a last resort to find the character widths in a
146 * font The DVI rendering code can correctly skip over a glyph if it knows
147 * its TFM width, which is what we try to find here.
149 static int tfm_load_font(DviParams *params, DviFont *font)
154 switch(font->search.info->kpse_type) {
155 case kpse_tfm_format:
158 case kpse_afm_format:
161 case kpse_ofm_format:
168 /* we don't need this */
173 tfm = get_font_metrics(font->fontname, type, font->filename);
177 if(tfm->checksum && font->checksum && tfm->checksum != font->checksum) {
178 mdvi_warning(_("%s: Checksum mismatch (got %u, expected %u)\n"),
179 font->fontname, (unsigned)tfm->checksum,
180 (unsigned)font->checksum);
182 font->checksum = tfm->checksum;
183 font->design = tfm->design;
187 get_tfm_chars(params, font, tfm, 1);
189 /* free everything */
190 free_font_metrics(tfm);
195 static int tfm_font_get_glyph(DviParams *params, DviFont *font, int code)
199 ch = FONTCHAR(font, code);
200 if(!glyph_present(ch))
204 ch->glyph.w = ch->width;
205 ch->glyph.h = ch->height;
207 * This has two purposes: (1) avoid unnecessary calls to this function,
208 * and (2) detect when the glyph data for a TFM font is actually used
209 * (we'll get a SEGV). Any occurrence of that is a bug.
211 ch->glyph.data = MDVI_GLYPH_EMPTY;