void test_make_tex (kpse_file_format_type fmt, const_string base) { string answer; printf ("\nAttempting %s in format %d:\n", base, fmt); answer = kpse_make_tex (fmt, base); puts (answer ? answer : "(nil)"); }
string kpse_find_glyph P4C(const_string, passed_fontname, unsigned, dpi, kpse_file_format_type, format, kpse_glyph_file_type *, glyph_file) { string ret; kpse_glyph_source_type source; string fontname = (string) passed_fontname; /* discard const */ /* Start the search: try the name we're given. */ source = kpse_glyph_source_normal; xputenv ("KPATHSEA_NAME", fontname); ret = try_resolution (fontname, dpi, format, glyph_file); /* Try all the various possibilities in order of preference. */ if (!ret) { /* Maybe FONTNAME was an alias. */ source = kpse_glyph_source_alias; ret = try_fontmap (&fontname, dpi, format, glyph_file); /* If not an alias, try creating it on the fly with mktexpk, unless FONTNAME is absolute or explicitly relative. */ if (!ret && !kpse_absolute_p (fontname, true)) { source = kpse_glyph_source_maketex; /* `try_resolution' leaves the envvar set randomly. */ xputenv_int ("KPATHSEA_DPI", dpi); ret = kpse_make_tex (format, fontname); } /* If mktex... succeeded, set return struct. Doesn't make sense for `kpse_make_tex' to set it, since it can only succeed or fail, unlike the other routines. */ if (ret) { KPSE_GLYPH_FILE_DPI (*glyph_file) = dpi; KPSE_GLYPH_FILE_NAME (*glyph_file) = fontname; } /* If mktex... failed, try any fallback resolutions. */ else { if (kpse_fallback_resolutions) ret = try_fallback_resolutions (fontname, dpi, format, glyph_file); /* We're down to the font of last resort. */ if (!ret && kpse_fallback_font) { const_string name = kpse_fallback_font; source = kpse_glyph_source_fallback; xputenv ("KPATHSEA_NAME", name); /* As before, first try it at the given size. */ ret = try_resolution (name, dpi, format, glyph_file); /* The fallback font at the fallback resolutions. */ if (!ret && kpse_fallback_resolutions) ret = try_fallback_resolutions (name, dpi, format, glyph_file); } } } /* If RET is null, then the caller is not supposed to look at GLYPH_FILE, so it doesn't matter if we assign something incorrect. */ KPSE_GLYPH_FILE_SOURCE (*glyph_file) = source; /* FIXME: fontname may have been allocated, but (worse) it may also have been assigned to struct that's passed out of this function. if (fontname != passed_fontname) free (fontname); */ return ret; }
string kpse_find_glyph_format P4C(const_string, font_name, unsigned, dpi, kpse_file_format_type, format, kpse_font_file_type *, font_file) { string glyph_paths[kpse_any_glyph_format]; string ret; kpse_source_type source; /* Initialize the path strings for the glyph formats we will try. */ glyph_paths[kpse_gf_format] = format == kpse_any_glyph_format || format == kpse_gf_format ? KPSE_GF_PATH () : NULL; glyph_paths[kpse_pk_format] = format == kpse_any_glyph_format || format == kpse_pk_format ? KPSE_PK_PATH () : NULL; /* Start the search: try the name we're given. */ source = kpse_source_normal; xputenv ("KPATHSEA_NAME", font_name); ret = try_resolution (font_name, dpi, glyph_paths, font_file); /* Sorry for the spaghetti logic. How to improve? */ if (!ret) { /* Maybe FONT_NAME was an alias. */ source = kpse_source_alias; ret = try_fontmap (font_name, dpi, glyph_paths, font_file); /* OK, maybe we can create it on the fly with MakeTeXPK. */ if (!ret) { source = kpse_source_maketex; /* `try_resolution' leaves the envvar set randomly. */ xputenv_int ("KPATHSEA_DPI", dpi); ret = kpse_make_tex (format, font_name); } /* If MakeTeX... succeeded, set return struct. (Doesn't make sense for `kpse_make_tex' to set it, since it can only succeed or fail, unlike the other routines.) */ if (ret) { KPSE_FONT_FILE_DPI (*font_file) = dpi; /* Discarding const here. */ KPSE_FONT_FILE_NAME (*font_file) = (string) font_name; } /* If MakeTeX... failed, try any fallback resolutions. */ else { if (kpse_fallback_resolutions) ret = try_fallback_resolutions (font_name, dpi, glyph_paths, font_file); /* We're down to the font of last resort. */ if (!ret && kpse_fallback_font) { /* As before, first try it at the given size. */ source = kpse_source_fallback; xputenv ("KPATHSEA_NAME", kpse_fallback_font); ret = try_resolution (kpse_fallback_font, dpi, glyph_paths, font_file); /* The fallback font at the fallback resolutions. */ if (!ret && kpse_fallback_resolutions) ret = try_fallback_resolutions (kpse_fallback_font, dpi, glyph_paths, font_file); } } } /* If RET is null, then the caller must not look at FONT_FILE, so it doesn't matter if we assign something incorrect to it. */ KPSE_FONT_FILE_SOURCE (*font_file) = source; return ret; }