Back to index

tetex-bin  3.0
Defines | Functions
tex-glyph.c File Reference
#include <kpathsea/config.h>
#include <kpathsea/absolute.h>
#include <kpathsea/expand.h>
#include <kpathsea/fontmap.h>
#include <kpathsea/pathsearch.h>
#include <kpathsea/tex-glyph.h>
#include <kpathsea/tex-make.h>
#include <kpathsea/variable.h>

Go to the source code of this file.

Defines

#define UNIX_BITMAP_SPEC   "$KPATHSEA_NAME.$KPATHSEA_DPI$KPATHSEA_FORMAT"
#define DPI_BITMAP_SPEC   "dpi$KPATHSEA_DPI/$KPATHSEA_NAME.$KPATHSEA_FORMAT"

Functions

static string try_format P3C (const_string, fontname, unsigned, dpi, kpse_file_format_type, format)
static string try_size P4C (const_string, fontname, unsigned, dpi, kpse_file_format_type, format, kpse_glyph_file_type *, glyph_file)
static string try_fontmap P4C (string *, fontname_ptr, unsigned, dpi, kpse_file_format_type, format, kpse_glyph_file_type *, glyph_file)
string kpse_find_glyph P4C (const_string, passed_fontname, unsigned, dpi, kpse_file_format_type, format, kpse_glyph_file_type *, glyph_file)
boolean kpse_bitmap_tolerance P2C (double, dpi1, double, dpi2)

Define Documentation

#define DPI_BITMAP_SPEC   "dpi$KPATHSEA_DPI/$KPATHSEA_NAME.$KPATHSEA_FORMAT"

Definition at line 35 of file tex-glyph.c.

#define UNIX_BITMAP_SPEC   "$KPATHSEA_NAME.$KPATHSEA_DPI$KPATHSEA_FORMAT"

Definition at line 34 of file tex-glyph.c.


Function Documentation

boolean kpse_bitmap_tolerance P2C ( double  ,
dpi1  ,
double  ,
dpi2   
)

Definition at line 329 of file tex-glyph.c.

{
  unsigned tolerance = KPSE_BITMAP_TOLERANCE (dpi2);
  unsigned lower_bound = (int) (dpi2 - tolerance) < 0 ? 0 : dpi2 - tolerance;
  unsigned upper_bound = dpi2 + tolerance;

  return lower_bound <= dpi1 && dpi1 <= upper_bound;
}
static string try_format P3C ( const_string  ,
fontname  ,
unsigned  ,
dpi  ,
kpse_file_format_type  ,
format   
) [static]

Definition at line 41 of file tex-glyph.c.

{
  static const_string bitmap_specs[]
    = { UNIX_BITMAP_SPEC, DPI_BITMAP_SPEC, NULL };
  const_string *spec;
  boolean must_exist;
  string ret = NULL;
  const_string path = kpse_format_info[format].path;
  const_string *sfx;
  if (!path)
    path = kpse_init_format (format);
  
  /* Set the suffix on the name we'll be searching for.  */
  sfx = kpse_format_info[format].suffix;
  if (sfx && *sfx) 
    xputenv ("KPATHSEA_FORMAT", *sfx);

  /* OK, the limits on this for loop are a little hokey, but it saves
     having to repeat the body.  We want to do it once with `must_exist'
     false to avoid looking on the disk for cmr10.600pk if
     dpi600/cmr10.pk is in ls-R.  (The time spent in the extra variable
     expansions and db searches is negligible.)  */
  for (must_exist = false; !ret && must_exist <= true; must_exist++)
    {
      for (spec = bitmap_specs; !ret && *spec; spec++)
        {
          string name = kpse_var_expand (*spec);
          ret = kpse_path_search (path, name, must_exist);
          if (name != ret)
            free (name);
        }
    }
    
  return ret;
}

Here is the call graph for this function:

static string try_fallback_resolutions P4C ( const_string  ,
fontname  ,
unsigned  ,
dpi  ,
kpse_file_format_type  ,
format  ,
kpse_glyph_file_type ,
glyph_file   
) [static]

Definition at line 83 of file tex-glyph.c.

{
  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;
}
static string try_fontmap P4C ( string ,
fontname_ptr  ,
unsigned  ,
dpi  ,
kpse_file_format_type  ,
format  ,
kpse_glyph_file_type ,
glyph_file   
) [static]

Definition at line 153 of file tex-glyph.c.

{
  string *mapped_names;
  string fontname = *fontname_ptr;
  string ret = NULL;

  mapped_names = kpse_fontmap_lookup (fontname);
  if (mapped_names) {
    string mapped_name;
    string first_name = *mapped_names;
    while (!ret && (mapped_name = *mapped_names++)) {
      xputenv ("KPATHSEA_NAME", mapped_name);
      ret = try_resolution (mapped_name, dpi, format, glyph_file);
    }
    if (ret) {
      /* If some alias succeeeded, return that alias.  */
      *fontname_ptr = xstrdup (mapped_name);
    /* Return first alias name, unless that itself is an alias,
       in which case do nothing.  */
    } else if (!kpse_fontmap_lookup (first_name)) {
      *fontname_ptr = xstrdup (first_name);
    }
  } 

  return ret;
}

Here is the call graph for this function:

string kpse_find_glyph P4C ( const_string  ,
passed_fontname  ,
unsigned  ,
dpi  ,
kpse_file_format_type  ,
format  ,
kpse_glyph_file_type ,
glyph_file   
)

Definition at line 255 of file tex-glyph.c.

{
  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 && glyph_file) {
      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.  */
  if (glyph_file)
    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;
}