Exemple #1
0
static string
try_size P4C(const_string, fontname,  unsigned, dpi,
             kpse_file_format_type, format,
             kpse_glyph_file_type *, glyph_file)
{
  kpse_file_format_type format_found;
  string ret;
  boolean try_gf = format == kpse_gf_format || format == kpse_any_glyph_format;
  boolean try_pk = format == kpse_pk_format || format == kpse_any_glyph_format;

  xputenv_int ("KPATHSEA_DPI", dpi);
  
  /* Look for PK first (since it's more likely to be found), then GF.  */
  ret = try_pk ? try_format (fontname, dpi, kpse_pk_format) : NULL;

  if (ret != NULL)
    format_found = kpse_pk_format;
  else
    {
      if (try_gf)
        {
          ret = try_format (fontname, dpi, kpse_gf_format);
          format_found = kpse_gf_format;
        }
    }
  
  if (ret != NULL && glyph_file)
    { /* Success.  Fill in the return info.  Discard const.  */
      glyph_file->name = (string) fontname;
      glyph_file->dpi = dpi;
      glyph_file->format = format_found;
    }
    
  return ret;
}
Exemple #2
0
void
kpse_init_prog P4C(const_string, prefix,  unsigned, dpi,  const_string, mode,
                   const_string, fallback)
{
  string font_var = concat (prefix, "FONTS");
  string header_var = concat (prefix, "HEADERS");
  string makepk_var = concat (prefix, "MAKEPK");
  string size_var = concat (prefix, "SIZES");
  
  /* Do both `pk_format' and `any_glyph_format' for the sake of xdvi; in
     general, mktexpk might apply to either, and the program will ask
     for the one it wants.  */
     
  /* Might have a program-specific name for mktexpk itself.  */
  if (getenv (makepk_var)) {
  /* If we did, we want to enable the program, I think.  */
    kpse_set_program_enabled (kpse_pk_format, 1, kpse_src_env);
    kpse_set_program_enabled (kpse_any_glyph_format, 1, kpse_src_env);

    kpse_format_info[kpse_pk_format].program
      = kpse_format_info[kpse_any_glyph_format].program
      = getenv (makepk_var);
  }

  /* A couple font paths have traditionally had application-specific
     environment variables to override all else; namely, XDVIFONTS and
     DVIPSHEADERS.  So set those if we have them.  */
  kpse_format_info[kpse_pk_format].override_path
    = kpse_format_info[kpse_gf_format].override_path
    = kpse_format_info[kpse_any_glyph_format].override_path
    = kpse_format_info[kpse_tfm_format].override_path
    = getenv (font_var);

  kpse_format_info[kpse_tex_ps_header_format].override_path
    = getenv (header_var);

  kpse_init_fallback_resolutions (size_var);
  xputenv_int ("MAKETEX_BASE_DPI", dpi);
  kpse_fallback_font = fallback;
  
  /* Ugliness.  See comments in kpse_make_tex in kpathsea/tex-make.c.  */
  xputenv ("MAKETEX_MODE", mode ? mode : DIR_SEP_STRING);
  
  free (font_var);
  free (header_var);
  free (makepk_var);
  free (size_var);
}
static string
try_size P4C(const_string, font_name,
             unsigned, dpi,
             string *, glyph_paths,
             kpse_font_file_type *, font_file)
{
  kpse_file_format_type format_found;
  string ret;
  string gf_path = glyph_paths[kpse_gf_format];
  string pk_path = glyph_paths[kpse_pk_format];

  xputenv_int ("KPATHSEA_DPI", dpi);
  
  /* Look for PK first (since it's more likely to be found), then GF.  */
  ret = pk_path ? try_format (font_name, dpi, pk_path, "pk") : NULL;

  if (ret != NULL)
    format_found = kpse_pk_format;
  else
    {
      if (gf_path)
        {
          ret = try_format (font_name, dpi, gf_path, "gf");
          format_found = kpse_gf_format;
        }
    }
  
  if (ret != NULL && font_file)
    { /* Success.  Fill in the return info.  Discard const.  */
      font_file->name = (string) font_name;
      font_file->dpi = dpi;
      font_file->format = format_found;
    }
    
  return ret;
}
Exemple #4
0
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;
}