28 #ifdef WITH_TYPE1_FONTS
34 static int t1lib_initialized = 0;
36 typedef struct t1info {
47 static void t1_font_remove
__PROTO((T1Info *));
50 static void t1_font_shrink_glyph
72 #define T1_HASH_SIZE 31
76 static int t1lib_xdpi = -1;
77 static int t1lib_ydpi = -1;
79 static ListHead t1fonts = {NULL, NULL, 0};
109 filename = kpse_find_file(name, kpse_type1_format, 1);
110 if(filename != NULL) {
115 DEBUG((
DBG_TYPE1,
"(t1) %s: not found, querying font maps\n", name));
136 if(ext && !
STREQ(ext,
"pfa") && !
STREQ(ext,
"pfb")) {
138 "(t1) %s: associated name `%s' is not Type1\n",
147 newname[ext - info.
fontfile - 1] = 0;
149 newname = (
char *)name;
154 filename = kpse_find_file(newname, kpse_type1_format, 1);
159 if(filename == NULL) {
170 static void t1_reset_resolution(
int xdpi,
int ydpi)
175 DEBUG((
DBG_TYPE1,
"(t1) resetting device resolution (current: (%d,%d))\n",
176 t1lib_xdpi, t1lib_ydpi));
177 #if T1LIB_VERSION < 5
178 nfonts = T1_Get_no_fonts();
180 nfonts = T1_GetNoFonts();
183 for(i = 0; i < nfonts; i++)
184 T1_DeleteAllSizes(i);
186 if(T1_SetDeviceResolutions((
float)xdpi, (
float)ydpi) < 0)
190 "(t1) reset successful, new resolution is (%d, %d)\n",
196 static void t1_reset_font(
DviFont *font)
198 T1Info *info = (T1Info *)font->
private;
205 info->hasmetrics = 0;
208 static void t1_transform_font(T1Info *info)
210 if(!info->hasmetrics && info->encoding != NULL) {
212 info->fontname, info->encoding->name));
213 T1_DeleteAllSizes(info->t1id);
214 if(T1_ReencodeFont(info->t1id, info->encoding->vector) < 0)
215 mdvi_warning(
_(
"%s: could not encode font\n"), info->fontname);
217 if(info->mapinfo.slant) {
221 T1_SlantFont(info->t1id,
224 if(info->mapinfo.extend) {
228 T1_ExtendFont(info->t1id,
234 static int t1_really_load_font(
DviParams *params,
DviFont *font, T1Info *info)
242 DEBUG((
DBG_TYPE1,
"(t1) really_load_font(%s)\n", info->fontname));
245 if(t1lib_xdpi != params->
dpi || t1lib_ydpi != params->
vdpi)
246 t1_reset_resolution(params->
dpi, params->
vdpi);
249 if(info->t1id != -1) {
250 info->hasmetrics = 1;
252 t1_transform_font(info);
259 if(info->tfminfo == NULL) {
261 "(t1) %s: no metric data, font ignored\n",
266 font->
design = info->tfminfo->design;
274 if(old && old->t1id != -1) {
276 t1id = T1_CopyFont(old->t1id);
278 info->fontname, t1id));
283 info->fontname, t1id));
295 if(old && old->t1id == -1) {
304 if(!copied && T1_LoadFont(info->t1id) < 0) {
306 info->t1id, T1_errno));
313 if(!status && info->mapinfo.encoding)
315 t1_transform_font(info);
317 i = info->tfminfo->hic - info->tfminfo->loc + 1;
318 if(i != font->
hic - font->
loc + 1) {
325 info->hasmetrics = 1;
327 DEBUG((
DBG_TYPE1,
"(t1) font `%s' really-loaded\n", info->fontname));
336 t1_font_remove(info);
340 font->
loc = font->
hic = 0;
348 #ifdef WORD_LITTLE_ENDIAN
353 T1_SetDeviceResolutions((
float)params->
dpi, (
float)params->
vdpi);
354 t1flags = IGNORE_CONFIGFILE|IGNORE_FONTDATABASE|T1_NO_AFM;
357 if(T1_InitLib(t1flags) == NULL)
358 return (t1lib_initialized = -1);
360 DEBUG((
DBG_TYPE1,
"T1lib debugging output saved in t1lib.log\n"));
361 T1_SetLogLevel(T1LOG_DEBUG);
366 DEBUG((
DBG_TYPE1,
"(t1) t1lib %s initialized -- resolution is (%d, %d), pad is %d bits\n",
367 T1_GetLibIdent(), params->
dpi, params->
vdpi, T1_GetBitmapPad()));
368 t1lib_initialized = 1;
369 t1lib_xdpi = params->
dpi;
370 t1lib_ydpi = params->
vdpi;
379 if(t1lib_initialized < 0)
381 else if(t1lib_initialized == 0 && init_t1lib(params) < 0)
384 if(font->
in != NULL) {
400 info->hasmetrics = 0;
401 info->encoding = NULL;
402 info->mapinfo.psname = NULL;
403 info->mapinfo.encoding = NULL;
404 info->mapinfo.fontfile = NULL;
405 info->mapinfo.extend = 0;
406 info->mapinfo.slant = 0;
407 info->encoding = NULL;
421 for(i = 0; i < 256; i++) {
433 #define GLYPH_WIDTH(g) \
434 ((g)->metrics.rightSideBearing - (g)->metrics.leftSideBearing)
435 #define GLYPH_HEIGHT(g) \
436 ((g)->metrics.ascent - (g)->metrics.descent)
438 static inline BITMAP *t1_glyph_bitmap(GLYPH *glyph)
442 w = GLYPH_WIDTH(glyph);
443 h = GLYPH_HEIGHT(glyph);
448 pad = T1_GetBitmapPad();
459 info = (T1Info *)font->
private;
462 DEBUG((
DBG_TYPE1,
"(t1) shrinking glyph for character %d in `%s' (%d,%d)\n",
465 size = 72.0 * size / 72.27;
470 glyph = T1_SetChar(info->t1id, ch->
code, (
float)size, &matrix);
472 dest->
data = t1_glyph_bitmap(glyph);
473 dest->
x = -glyph->metrics.leftSideBearing;
474 dest->
y = glyph->metrics.ascent;
475 dest->
w = GLYPH_WIDTH(glyph);
476 dest->
h = GLYPH_HEIGHT(glyph);
481 "(t1) %s: t1_shrink_glyph(%d): (%dw,%dh,%dx,%dy) -> (%dw,%dh,%dx,%dy)\n",
483 dest->
w, dest->
h, dest->
x, dest->
y));
494 T1Info *info = (T1Info *)font->
private;
502 if(!info->hasmetrics && t1_really_load_font(params, font, info) < 0)
522 size = 72.0 * size / 72.27;
528 matrix.cxx = (double)font->
hdpi / dpi;
529 matrix.cyy = (
double)font->
vdpi / dpi;
530 matrix.cxy = matrix.cyx = 0.0;
531 glyph = T1_SetChar(info->t1id, ch->
code, (
float)size, &matrix);
543 ch->
glyph.
x = -glyph->metrics.leftSideBearing;
544 ch->
glyph.
y = glyph->metrics.ascent;
545 ch->
glyph.
w = GLYPH_WIDTH(glyph);
546 ch->
glyph.
h = GLYPH_HEIGHT(glyph);
559 static void t1_font_remove(T1Info *info)
572 for(old = (T1Info *)t1fonts.
head; old; old = old->
next)
573 if(
STREQ(old->fontname, info->fontname))
582 info->fontname, info->encoding->name));
587 if(info->t1id != -1) {
589 info->fontname, info->t1id));
590 T1_DeleteFont(info->t1id);
592 DEBUG((
DBG_TYPE1,
"(t1) %s: not loaded yet, DeleteFont skipped\n",
601 static void t1_free_data(
DviFont *font)
613 t1_font_remove((T1Info *)font->
private);
621 if(t1fonts.
count == 0) {
624 t1lib_initialized = 0;