Back to index

texmacs  1.0.7.15
Classes | Defines | Functions | Variables
tfm.c File Reference
#include <string.h>
#include "system.h"
#include "mem.h"
#include "mfileio.h"
#include "error.h"
#include "numbers.h"
#include "dpxutil.h"
#include "tfm.h"

Go to the source code of this file.

Classes

struct  tfm_font
struct  coverage
struct  range_map
struct  char_map
struct  font_metric
struct  font_metric.charmap

Defines

#define TFM_FORMAT   1
#define OFM_FORMAT   2
#define FWBASE   ((double) (1<<20))
#define JFM_ID   11
#define JFMV_ID   9
#define IS_JFM(i)   ((i) == JFM_ID || (i) == JFMV_ID)
#define SOURCE_TYPE_TFM   0
#define SOURCE_TYPE_JFM   1
#define SOURCE_TYPE_OFM   2
#define MAPTYPE_NONE   0
#define MAPTYPE_CHAR   1
#define MAPTYPE_RANGE   2
#define FONT_DIR_HORIZ   0
#define FONT_DIR_VERT   1
#define MAX_FONTS   16
#define CHECK_ID(n)

Functions

static void tfm_font_init (struct tfm_font *tfm)
static void tfm_font_clear (struct tfm_font *tfm)
static void release_char_map (struct char_map *map)
static void release_range_map (struct range_map *map)
static long lookup_char (const struct char_map *map, long charcode)
static long lookup_range (const struct range_map *map, long charcode)
static void fm_init (struct font_metric *fm)
static void fm_clear (struct font_metric *fm)
static void fms_need (unsigned n)
void tfm_set_verbose (void)
static long fread_fwords (SIGNED_QUAD *words, SIGNED_QUAD nmemb, FILE *fp)
static long fread_uquads (UNSIGNED_QUAD *quads, SIGNED_QUAD nmemb, FILE *fp)
static void tfm_check_size (struct tfm_font *tfm, SIGNED_QUAD tfm_file_size)
static void tfm_get_sizes (FILE *tfm_file, SIGNED_QUAD tfm_file_size, struct tfm_font *tfm)
static void jfm_do_char_type_array (FILE *tfm_file, struct tfm_font *tfm)
static void jfm_make_charmap (struct font_metric *fm, struct tfm_font *tfm)
static void tfm_unpack_arrays (struct font_metric *fm, struct tfm_font *tfm)
static int sput_bigendian (char *s, SIGNED_QUAD v, int n)
static void tfm_unpack_header (struct font_metric *fm, struct tfm_font *tfm)
static void ofm_check_size_one (struct tfm_font *tfm, SIGNED_QUAD ofm_file_size)
static void ofm_get_sizes (FILE *ofm_file, UNSIGNED_QUAD ofm_file_size, struct tfm_font *tfm)
static void ofm_do_char_info_zero (FILE *tfm_file, struct tfm_font *tfm)
static void ofm_do_char_info_one (FILE *tfm_file, struct tfm_font *tfm)
static void ofm_unpack_arrays (struct font_metric *fm, struct tfm_font *tfm, UNSIGNED_QUAD num_chars)
static void read_ofm (struct font_metric *fm, FILE *ofm_file, UNSIGNED_QUAD ofm_file_size)
static void read_tfm (struct font_metric *fm, FILE *tfm_file, UNSIGNED_QUAD tfm_file_size)
int tfm_open (const char *tfm_name, int must_exist)
void tfm_close_all (void)
fixword tfm_get_fw_width (int font_id, SIGNED_QUAD ch)
fixword tfm_get_fw_height (int font_id, SIGNED_QUAD ch)
fixword tfm_get_fw_depth (int font_id, SIGNED_QUAD ch)
double tfm_get_width (int font_id, SIGNED_QUAD ch)
fixword tfm_string_width (int font_id, const unsigned char *s, unsigned len)
fixword tfm_string_depth (int font_id, const unsigned char *s, unsigned len)
fixword tfm_string_height (int font_id, const unsigned char *s, unsigned len)
double tfm_get_design_size (int font_id)
int tfm_exists (const char *tfm_name)

Variables

static int verbose = 0
struct font_metricfms = NULL
static unsigned numfms = 0
static unsigned max_fms = 0

Class Documentation

struct tfm_font

Definition at line 63 of file tfm.c.

Class Members
UNSIGNED_QUAD bc
UNSIGNED_QUAD * char_info
UNSIGNED_PAIR * chartypes
SIGNED_QUAD * depth
UNSIGNED_BYTE * depth_index
UNSIGNED_QUAD ec
UNSIGNED_QUAD fontdir
SIGNED_QUAD * header
SIGNED_QUAD * height
UNSIGNED_BYTE * height_index
UNSIGNED_BYTE id
SIGNED_QUAD level
UNSIGNED_QUAD nco
UNSIGNED_QUAD ncw
UNSIGNED_QUAD ndepths
UNSIGNED_QUAD nextens
UNSIGNED_QUAD nfonparm
UNSIGNED_QUAD nheights
UNSIGNED_QUAD nitcor
UNSIGNED_QUAD nkern
UNSIGNED_QUAD nlig
UNSIGNED_QUAD npc
UNSIGNED_BYTE nt
UNSIGNED_QUAD nwidths
SIGNED_QUAD * width
UNSIGNED_PAIR * width_index
UNSIGNED_QUAD wlenfile
UNSIGNED_QUAD wlenheader
struct coverage

Definition at line 162 of file tfm.c.

Class Members
long first_char
unsigned short num_chars
struct range_map

Definition at line 172 of file tfm.c.

Collaboration diagram for range_map:
Class Members
struct coverage * coverages
unsigned short * indices
unsigned short num_coverages
struct char_map

Definition at line 179 of file tfm.c.

Class Members
unsigned short * indices
struct font_metric

Definition at line 244 of file tfm.c.

Class Members
struct font_metric charmap
char * codingscheme
fixword * depths
fixword designsize
long firstchar
int fontdir
fixword * heights
long lastchar
int source
char * tex_name
fixword * widths
struct font_metric.charmap

Definition at line 257 of file tfm.c.

Class Members
void * data
int type

Define Documentation

#define CHECK_ID (   n)
Value:
do {\
  if ((n) < 0 || (n) >= numfms)\
    ERROR("TFM: Invalid TFM ID: %d", (n));\
} while (0)

Definition at line 1030 of file tfm.c.

#define FONT_DIR_HORIZ   0

Definition at line 241 of file tfm.c.

#define FONT_DIR_VERT   1

Definition at line 242 of file tfm.c.

#define FWBASE   ((double) (1<<20))

Definition at line 44 of file tfm.c.

#define IS_JFM (   i)    ((i) == JFM_ID || (i) == JFMV_ID)

Definition at line 55 of file tfm.c.

#define JFM_ID   11

Definition at line 53 of file tfm.c.

#define JFMV_ID   9

Definition at line 54 of file tfm.c.

#define MAPTYPE_CHAR   1

Definition at line 238 of file tfm.c.

#define MAPTYPE_NONE   0

Definition at line 237 of file tfm.c.

#define MAPTYPE_RANGE   2

Definition at line 239 of file tfm.c.

#define MAX_FONTS   16

Definition at line 312 of file tfm.c.

#define OFM_FORMAT   2

Definition at line 42 of file tfm.c.

#define SOURCE_TYPE_JFM   1

Definition at line 234 of file tfm.c.

#define SOURCE_TYPE_OFM   2

Definition at line 235 of file tfm.c.

#define SOURCE_TYPE_TFM   0

Definition at line 233 of file tfm.c.

#define TFM_FORMAT   1

Definition at line 41 of file tfm.c.


Function Documentation

static void fm_clear ( struct font_metric fm) [static]

Definition at line 286 of file tfm.c.

{
  if (fm) {
    if (fm->tex_name)
      RELEASE(fm->tex_name);
    if (fm->widths)
      RELEASE(fm->widths);
    if (fm->heights)
      RELEASE(fm->heights);
    if (fm->depths)
      RELEASE(fm->depths);
    if (fm->codingscheme)
      RELEASE(fm->codingscheme);

    switch (fm->charmap.type) {
    case MAPTYPE_CHAR:
      release_char_map(fm->charmap.data);
      break;
    case MAPTYPE_RANGE:
      release_range_map(fm->charmap.data);
      break;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void fm_init ( struct font_metric fm) [static]

Definition at line 266 of file tfm.c.

{
  fm->tex_name = NULL;
  fm->firstchar = 0;
  fm->lastchar  = 0;
  fm->fontdir   = FONT_DIR_HORIZ;
  fm->codingscheme = NULL;
  fm->designsize   = 0;

  fm->widths  = NULL;
  fm->heights = NULL;
  fm->depths  = NULL;

  fm->charmap.type = MAPTYPE_NONE;
  fm->charmap.data = NULL;

  fm->source = SOURCE_TYPE_TFM;
}

Here is the caller graph for this function:

static void fms_need ( unsigned  n) [static]

Definition at line 319 of file tfm.c.

{
  if (n > max_fms) {
    max_fms = MAX(max_fms + MAX_FONTS, n);
    fms = RENEW(fms, max_fms, struct font_metric);
  }
}

Here is the caller graph for this function:

static long fread_fwords ( SIGNED_QUAD words,
SIGNED_QUAD  nmemb,
FILE *  fp 
) [static]

Definition at line 335 of file tfm.c.

{
  long i;

  for (i = 0; i < nmemb; i++)
    words[i] = get_signed_quad(fp);

  return nmemb*4;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static long fread_uquads ( UNSIGNED_QUAD quads,
SIGNED_QUAD  nmemb,
FILE *  fp 
) [static]

Definition at line 346 of file tfm.c.

{
  long i;

  for (i = 0; i < nmemb; i++) {
    quads[i] = get_unsigned_quad(fp);
  }

  return nmemb*4;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void jfm_do_char_type_array ( FILE *  tfm_file,
struct tfm_font tfm 
) [static]

Definition at line 455 of file tfm.c.

{
  UNSIGNED_PAIR charcode;
  UNSIGNED_PAIR chartype;
  long i;

  tfm->chartypes = NEW(65536, UNSIGNED_PAIR);
  for (i = 0; i < 65536; i++) {
    tfm->chartypes[i] = 0;
  }
  for (i = 0; i < tfm->nt; i++) {
    charcode = get_unsigned_pair(tfm_file);
    chartype = get_unsigned_pair(tfm_file);
    tfm->chartypes[charcode] = chartype;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void jfm_make_charmap ( struct font_metric fm,
struct tfm_font tfm 
) [static]

Definition at line 473 of file tfm.c.

{
  if (tfm->nt > 1) {
    struct char_map *map;
    long   code;

    fm->charmap.type = MAPTYPE_CHAR;
    fm->charmap.data = map = NEW(1, struct char_map);
    map->coverage.first_char = 0;
    map->coverage.num_chars  = 0xFFFFu;
    map->indices    = NEW(0x10000L, unsigned short);

    for (code = 0; code <= 0xFFFFu; code++) {
      map->indices[code] = tfm->chartypes[code];
    }
  } else {
    struct range_map *map;

    fm->charmap.type = MAPTYPE_RANGE;
    fm->charmap.data = map = NEW(1, struct range_map);
    map->num_coverages = 1;
    map->coverages     = NEW(map->num_coverages, struct coverage);
    map->coverages[0].first_char = 0;
    map->coverages[0].num_chars  = 0xFFFFu;
    map->indices = NEW(1, unsigned short);
    map->indices[0] = 0; /* Only default type used. */
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static long lookup_char ( const struct char_map map,
long  charcode 
) [static]

Definition at line 207 of file tfm.c.

{
  if (charcode >= map->coverage.first_char &&
      charcode <= map->coverage.first_char + map->coverage.num_chars)
    return map->indices[charcode - map->coverage.first_char];
  else
    return -1;

  return -1;
}

Here is the caller graph for this function:

static long lookup_range ( const struct range_map map,
long  charcode 
) [static]

Definition at line 219 of file tfm.c.

{
  long  idx;

  for (idx = map->num_coverages - 1; idx >= 0 &&
        charcode >= map->coverages[idx].first_char; idx--) {
    if (charcode <=
       map->coverages[idx].first_char + map->coverages[idx].num_chars)
      return map->indices[idx];
  }

  return -1;
}

Here is the caller graph for this function:

static void ofm_check_size_one ( struct tfm_font tfm,
SIGNED_QUAD  ofm_file_size 
) [static]

Definition at line 576 of file tfm.c.

{
  UNSIGNED_QUAD ofm_size = 14;

  ofm_size += 2*(tfm->ec - tfm->bc + 1);
  ofm_size += tfm->wlenheader;
  ofm_size += tfm->nwidths;
  ofm_size += tfm->nheights;
  ofm_size += tfm->ndepths;
  ofm_size += tfm->nitcor;
  ofm_size += 2*(tfm->nlig);
  ofm_size += tfm->nkern;
  ofm_size += 2*(tfm->nextens);
  ofm_size += tfm->nfonparm;
  if (tfm->wlenfile != ofm_file_size / 4 ||
      tfm->wlenfile != ofm_size) {
    ERROR("OFM file problem.  Table sizes don't agree.");
  }
}

Here is the caller graph for this function:

static void ofm_do_char_info_one ( FILE *  tfm_file,
struct tfm_font tfm 
) [static]

Definition at line 657 of file tfm.c.

{
  UNSIGNED_QUAD num_char_infos;
  UNSIGNED_QUAD num_chars;

  num_char_infos = tfm->ncw / (3 + (tfm->npc / 2));
  num_chars      = tfm->ec - tfm ->bc + 1;

  if (num_chars != 0) {
    UNSIGNED_QUAD i;
    UNSIGNED_QUAD char_infos_read;

    tfm->width_index  = NEW(num_chars, UNSIGNED_PAIR);
    tfm->height_index = NEW(num_chars, UNSIGNED_BYTE);
    tfm->depth_index  = NEW(num_chars, UNSIGNED_BYTE);
    char_infos_read   = 0;
    for (i = 0; i < num_chars &&
          char_infos_read < num_char_infos; i++) {
      int repeats, j;

      tfm->width_index [i] = get_unsigned_pair(tfm_file);
      tfm->height_index[i] = get_unsigned_byte(tfm_file);
      tfm->depth_index [i] = get_unsigned_byte(tfm_file);
      /* Ignore next quad */
      get_unsigned_quad(tfm_file);
      repeats = get_unsigned_pair(tfm_file);
      /* Skip params */
      for (j = 0; j < tfm->npc; j++) {
       get_unsigned_pair(tfm_file);
      }
      /* Remove word padding if necessary */
      if (ISEVEN(tfm->npc)){
       get_unsigned_pair(tfm_file);
      }
      char_infos_read++;
      if (i + repeats > num_chars) {
       ERROR("Repeats causes number of characters to be exceeded.");
      }
      for (j = 0; j < repeats; j++) {
       tfm->width_index [i+j+1] = tfm->width_index [i];
       tfm->height_index[i+j+1] = tfm->height_index[i];
       tfm->depth_index [i+j+1] = tfm->depth_index [i];
      }
      /* Skip ahead because we have already handled repeats */
      i += repeats;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ofm_do_char_info_zero ( FILE *  tfm_file,
struct tfm_font tfm 
) [static]

Definition at line 635 of file tfm.c.

{
  UNSIGNED_QUAD num_chars;

  num_chars = tfm->ec - tfm->bc + 1;
  if (num_chars != 0) {
    UNSIGNED_QUAD i;

    tfm->width_index  = NEW(num_chars, UNSIGNED_PAIR);
    tfm->height_index = NEW(num_chars, UNSIGNED_BYTE);
    tfm->depth_index  = NEW(num_chars, UNSIGNED_BYTE);
    for (i = 0; i < num_chars; i++) {
      tfm->width_index [i] = get_unsigned_pair(tfm_file);
      tfm->height_index[i] = get_unsigned_byte(tfm_file);
      tfm->depth_index [i] = get_unsigned_byte(tfm_file);
      /* Ignore remaining quad */
      get_unsigned_quad(tfm_file);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ofm_get_sizes ( FILE *  ofm_file,
UNSIGNED_QUAD  ofm_file_size,
struct tfm_font tfm 
) [static]

Definition at line 597 of file tfm.c.

{
  tfm->level = get_signed_quad(ofm_file);

  tfm->wlenfile   = get_signed_quad(ofm_file);
  tfm->wlenheader = get_signed_quad(ofm_file);
  tfm->bc = get_signed_quad(ofm_file);
  tfm->ec = get_signed_quad(ofm_file);
  if (tfm->ec < tfm->bc) {
    ERROR("OFM file error: ec(%u) < bc(%u) ???", tfm->ec, tfm->bc);
  }
  tfm->nwidths  = get_signed_quad(ofm_file);
  tfm->nheights = get_signed_quad(ofm_file);
  tfm->ndepths  = get_signed_quad(ofm_file);
  tfm->nitcor   = get_signed_quad(ofm_file);
  tfm->nlig     = get_signed_quad(ofm_file);
  tfm->nkern    = get_signed_quad(ofm_file);
  tfm->nextens  = get_signed_quad(ofm_file);
  tfm->nfonparm = get_signed_quad(ofm_file);
  tfm->fontdir  = get_signed_quad(ofm_file);
  if (tfm->fontdir) {
    WARN("I may be interpreting a font direction incorrectly.");
  }
  if (tfm->level == 0) {
    ofm_check_size_one(tfm, ofm_file_size);
  } else if (tfm->level == 1) {
    tfm->nco = get_signed_quad(ofm_file);
    tfm->ncw = get_signed_quad(ofm_file);
    tfm->npc = get_signed_quad(ofm_file);
    seek_absolute(ofm_file, 4*(tfm->nco - tfm->wlenheader));
  } else {
    ERROR("Can't handle OFM files with level > 1");
  }

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ofm_unpack_arrays ( struct font_metric fm,
struct tfm_font tfm,
UNSIGNED_QUAD  num_chars 
) [static]

Definition at line 707 of file tfm.c.

{
  long i;

  fm->widths  = NEW(tfm->bc + num_chars, fixword);
  fm->heights = NEW(tfm->bc + num_chars, fixword);
  fm->depths  = NEW(tfm->bc + num_chars, fixword);
  for (i = 0; i < num_chars; i++) {
    fm->widths [tfm->bc + i] = tfm->width [ tfm->width_index [i] ];
    fm->heights[tfm->bc + i] = tfm->height[ tfm->height_index[i] ];
    fm->depths [tfm->bc + i] = tfm->depth [ tfm->depth_index [i] ];
  }
}

Here is the caller graph for this function:

static void read_ofm ( struct font_metric fm,
FILE *  ofm_file,
UNSIGNED_QUAD  ofm_file_size 
) [static]

Definition at line 723 of file tfm.c.

{
  struct tfm_font tfm;

  tfm_font_init(&tfm);

  ofm_get_sizes(ofm_file, ofm_file_size, &tfm);

  if (tfm.level < 0 || tfm.level > 1)
    ERROR ("OFM level %d not supported.", tfm.level);

  if (tfm.wlenheader > 0) {
    tfm.header = NEW(tfm.wlenheader, fixword);
    fread_fwords(tfm.header, tfm.wlenheader, ofm_file);
  }
  if (tfm.level == 0) {
    ofm_do_char_info_zero(ofm_file, &tfm);
  } else if (tfm.level == 1) {
    ofm_do_char_info_one(ofm_file, &tfm);
  }
  if (tfm.nwidths > 0) {
    tfm.width = NEW(tfm.nwidths, fixword);
    fread_fwords(tfm.width, tfm.nwidths, ofm_file);
  }
  if (tfm.nheights > 0) {
    tfm.height = NEW(tfm.nheights, fixword);
    fread_fwords(tfm.height, tfm.nheights, ofm_file);
  }
  if (tfm.ndepths > 0) {
    tfm.depth = NEW(tfm.ndepths, fixword);
    fread_fwords(tfm.depth, tfm.ndepths, ofm_file);
  }

  ofm_unpack_arrays(fm, &tfm, tfm.ec - tfm.bc + 1);
  tfm_unpack_header(fm, &tfm);
  fm->firstchar = tfm.bc;
  fm->lastchar  = tfm.ec;
  fm->source    = SOURCE_TYPE_OFM;

  tfm_font_clear(&tfm);

  return;
}

Here is the call graph for this function:

static void read_tfm ( struct font_metric fm,
FILE *  tfm_file,
UNSIGNED_QUAD  tfm_file_size 
) [static]

Definition at line 769 of file tfm.c.

{
  struct tfm_font tfm;

  tfm_font_init(&tfm);

  tfm_get_sizes(tfm_file, tfm_file_size, &tfm);
  fm->firstchar = tfm.bc;
  fm->lastchar  = tfm.ec;
  if (tfm.wlenheader > 0) {
    tfm.header = NEW(tfm.wlenheader, fixword);
    fread_fwords(tfm.header, tfm.wlenheader, tfm_file);
  }
#ifndef WITHOUT_ASCII_PTEX
  if (IS_JFM(tfm.id)) {
    jfm_do_char_type_array(tfm_file, &tfm);
    jfm_make_charmap(fm, &tfm);
    fm->firstchar = 0;
    fm->lastchar  = 0xFFFFl;
    fm->fontdir   = (tfm.id == JFMV_ID) ? FONT_DIR_VERT : FONT_DIR_HORIZ;
    fm->source    = SOURCE_TYPE_JFM;
  }
#endif /* !WITHOUT_ASCII_PTEX */
  if (tfm.ec - tfm.bc + 1 > 0) {
    tfm.char_info = NEW(tfm.ec - tfm.bc + 1, UNSIGNED_QUAD);
    fread_uquads(tfm.char_info, tfm.ec - tfm.bc + 1, tfm_file);
  }
  if (tfm.nwidths > 0) {
    tfm.width = NEW(tfm.nwidths, fixword);
    fread_fwords(tfm.width, tfm.nwidths, tfm_file);
  }
  if (tfm.nheights > 0) {
    tfm.height = NEW(tfm.nheights, fixword);
    fread_fwords(tfm.height, tfm.nheights, tfm_file);
  }
  if (tfm.ndepths > 0) {
    tfm.depth = NEW(tfm.ndepths, fixword);
    fread_fwords(tfm.depth, tfm.ndepths, tfm_file);
  }
  tfm_unpack_arrays(fm, &tfm);
  tfm_unpack_header(fm, &tfm);

  tfm_font_clear(&tfm);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void release_char_map ( struct char_map map) [static]

Definition at line 186 of file tfm.c.

{
  if (map->indices)
    RELEASE(map->indices);
  map->indices = NULL;
  RELEASE(map);
}

Here is the caller graph for this function:

static void release_range_map ( struct range_map map) [static]

Definition at line 195 of file tfm.c.

{
  if (map->coverages)
    RELEASE(map->coverages);
  if (map->indices)
    RELEASE(map->indices);
  map->coverages = NULL;
  map->indices   = NULL;
  RELEASE(map);
}

Here is the caller graph for this function:

static int sput_bigendian ( char *  s,
SIGNED_QUAD  v,
int  n 
) [static]

Definition at line 533 of file tfm.c.

{
  int i;

  for (i = n-1; i >= 0; i--) {
    s[i] = (char) (v & 0xff);
    v >>= 8;
  }

  return n;
}

Here is the caller graph for this function:

static void tfm_check_size ( struct tfm_font tfm,
SIGNED_QUAD  tfm_file_size 
) [static]

Definition at line 361 of file tfm.c.

{
  UNSIGNED_QUAD expected_size = 6;

  /* Removed the warning message caused by EC TFM metric files.
   *
  if (tfm->wlenfile != tfm_file_size / 4) {
    WARN("TFM file size is %ld bytes but it says it is %ld bytes!",
        tfm_file_size, tfm->wlenfile * 4);
    if (tfm_file_size > tfm->wlenfile * 4) {
      WARN("Proceeding nervously...");
    } else {
      ERROR("Can't proceed...");
    }
  }
   */
  if (tfm_file_size < tfm->wlenfile * 4) {
    ERROR("Can't proceed...");
  }

  expected_size += (tfm->ec - tfm->bc + 1);
  expected_size += tfm->wlenheader;
  expected_size += tfm->nwidths;
  expected_size += tfm->nheights;
  expected_size += tfm->ndepths;
  expected_size += tfm->nitcor;
  expected_size += tfm->nlig;
  expected_size += tfm->nkern;
  expected_size += tfm->nextens;
  expected_size += tfm->nfonparm;
#ifndef WITHOUT_ASCII_PTEX
  if (IS_JFM(tfm->id)) {
    expected_size += tfm->nt + 1;
  }
#endif /* !WITHOUT_ASCII_PTEX */
  if (expected_size != tfm->wlenfile) {
    WARN("TFM file size is expected to be %ld bytes but it says it is %ld bytes!",
        expected_size * 4, tfm->wlenfile * 4);
    if (tfm_file_size > expected_size *4) {
      WARN("Proceeding nervously...");
    } else {
      ERROR("Can't proceed...");
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tfm_close_all ( void  )

Definition at line 1018 of file tfm.c.

{
  int  i;

  if (fms) {
    for (i = 0; i < numfms; i++) {
      fm_clear(&(fms[i]));
    }
    RELEASE(fms);
  }
}

Here is the call graph for this function:

int tfm_exists ( const char *  tfm_name)

Definition at line 1271 of file tfm.c.

{
#ifdef NOKPSE
  char *fullname;

  fullname = kpse_find_file(tfm_name, kpse_ofm_format, 0);
  if (fullname) {
    RELEASE(fullname);
    return 1;
  }
  fullname = kpse_find_file(tfm_name, kpse_tfm_format, 0);
  if (fullname) {
    RELEASE(fullname);
    return 1;
  }
#else
#endif
  return 0;
}
static void tfm_font_clear ( struct tfm_font tfm) [static]

Definition at line 117 of file tfm.c.

{
  if (tfm) {
    if (tfm->header) {
      RELEASE(tfm->header);
      tfm->header = NULL;
    }
    if (tfm->char_info) {
      RELEASE(tfm->char_info);
      tfm->char_info = NULL;
    }
    if (tfm->width) {
      RELEASE(tfm->width);
      tfm->width = NULL;
    }
    if (tfm->height) {
      RELEASE(tfm->height);
      tfm->height = NULL;
    }
    if (tfm->depth) {
      RELEASE(tfm->depth);
      tfm->depth = NULL;
    }
#ifndef WITHOUT_ASCII_PTEX
    if (tfm->chartypes) {
      RELEASE(tfm->chartypes);
      tfm->chartypes = NULL;
    }
#endif /* !WITHOUT_ASCII_PTEX */
    if (tfm->width_index) {
      RELEASE(tfm->width_index);
      tfm->width_index = NULL;
    }
    if (tfm->height_index) {
      RELEASE(tfm->height_index);
      tfm->height_index = NULL;
    }
    if (tfm->depth_index) {
      RELEASE(tfm->depth_index);
      tfm->depth_index = NULL;
    }
  }
}

Here is the caller graph for this function:

static void tfm_font_init ( struct tfm_font tfm) [static]

Definition at line 96 of file tfm.c.

{
  tfm->header = NULL;
#ifndef WITHOUT_ASCII_PTEX
  tfm->id = 0;
  tfm->nt = 0;
  tfm->chartypes = NULL;
#endif /* !WITHOUT_ASCII_PTEX */
#ifndef WITHOUT_OMEGA
  tfm->level   = 0;
  tfm->fontdir = 0;
  tfm->nco = tfm->ncw = tfm->npc = 0;
#endif
  tfm->char_info    = NULL;
  tfm->width_index  = NULL;
  tfm->height_index = NULL;
  tfm->depth_index  = NULL;
  tfm->width = tfm->height = tfm->depth = NULL;
}

Here is the caller graph for this function:

double tfm_get_design_size ( int  font_id)

Definition at line 1236 of file tfm.c.

{
  CHECK_ID(font_id);

  return (double) (fms[font_id].designsize)/FWBASE*(72.0/72.27);
}

Here is the caller graph for this function:

fixword tfm_get_fw_depth ( int  font_id,
SIGNED_QUAD  ch 
)

Definition at line 1098 of file tfm.c.

{
  struct font_metric *fm;
  long idx = 0;

  CHECK_ID(font_id);

  fm = &(fms[font_id]);
  if (ch >= fm->firstchar && ch <= fm->lastchar) {
    switch (fm->charmap.type) {
    case MAPTYPE_CHAR:
      idx = lookup_char(fm->charmap.data, ch);
      if (idx < 0)
       ERROR("Invalid char: %ld\n", ch);
      break;
    case MAPTYPE_RANGE:
      idx = lookup_range(fm->charmap.data, ch);
      if (idx < 0)
       ERROR("Invalid char: %ld\n", ch);
      break;
    default:
      idx = ch;
    }
  } else {
    ERROR("Invalid char: %ld\n", ch);
  }

  return fm->depths[idx];
}

Here is the call graph for this function:

Here is the caller graph for this function:

fixword tfm_get_fw_height ( int  font_id,
SIGNED_QUAD  ch 
)

Definition at line 1067 of file tfm.c.

{
  struct font_metric *fm;
  long idx = 0;

  CHECK_ID(font_id);

  fm = &(fms[font_id]);
  if (ch >= fm->firstchar && ch <= fm->lastchar) {
    switch (fm->charmap.type) {
    case MAPTYPE_CHAR:
      idx = lookup_char(fm->charmap.data, ch);
      if (idx < 0)
       ERROR("Invalid char: %ld\n", ch);
      break;
    case MAPTYPE_RANGE:
      idx = lookup_range(fm->charmap.data, ch);
      if (idx < 0)
       ERROR("Invalid char: %ld\n", ch);
      break;
    default:
      idx = ch;
    }
  } else {
    ERROR("Invalid char: %ld\n", ch);
  }

  return fm->heights[idx];
}

Here is the call graph for this function:

Here is the caller graph for this function:

fixword tfm_get_fw_width ( int  font_id,
SIGNED_QUAD  ch 
)

Definition at line 1036 of file tfm.c.

{
  struct font_metric *fm;
  long idx = 0;

  CHECK_ID(font_id);

  fm = &(fms[font_id]);
  if (ch >= fm->firstchar && ch <= fm->lastchar) {
    switch (fm->charmap.type) {
    case MAPTYPE_CHAR:
      idx = lookup_char(fm->charmap.data, ch);
      if (idx < 0)
       ERROR("Invalid char: %ld\n", ch);
      break;
    case MAPTYPE_RANGE:
      idx = lookup_range(fm->charmap.data, ch);
      if (idx < 0)
       ERROR("Invalid char: %ld\n", ch);
      break;
    default:
      idx = ch;
    }
  } else {
    ERROR("Invalid char: %ld\n", ch);
  }

  return fm->widths[idx];
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void tfm_get_sizes ( FILE *  tfm_file,
SIGNED_QUAD  tfm_file_size,
struct tfm_font tfm 
) [static]

Definition at line 408 of file tfm.c.

{
#ifndef WITHOUT_ASCII_PTEX
  {
    UNSIGNED_PAIR first_hword;

    /*
     * The first half word of TFM/JFM is TFM ID for JFM or size of
     * TFM file in word for TFM. TFM with 9*4 or 11*4 bytes is not
     * expected to be a valid TFM. So, we always assume that TFMs
     * starting with 00 09 or 00 0B is JFM.
     */
    first_hword = get_unsigned_pair(tfm_file);
    if (IS_JFM(first_hword)) {
      tfm->id = first_hword;
      tfm->nt = get_unsigned_pair(tfm_file);
      tfm->wlenfile = get_unsigned_pair(tfm_file);
    } else {
      tfm->wlenfile = first_hword;
    }
  }
#else /* WITHOUT_ASCII_PTEX */
  tfm->wlenfile = get_unsigned_pair(tfm_file);
#endif /* !WITHOUT_ASCII_PTEX */

  tfm->wlenheader = get_unsigned_pair(tfm_file);
  tfm->bc = get_unsigned_pair(tfm_file);
  tfm->ec = get_unsigned_pair(tfm_file);
  if (tfm->ec < tfm->bc) {
    ERROR("TFM file error: ec(%u) < bc(%u) ???", tfm->ec, tfm->bc);
  }
  tfm->nwidths  = get_unsigned_pair(tfm_file);
  tfm->nheights = get_unsigned_pair(tfm_file);
  tfm->ndepths  = get_unsigned_pair(tfm_file);
  tfm->nitcor   = get_unsigned_pair(tfm_file);
  tfm->nlig     = get_unsigned_pair(tfm_file);
  tfm->nkern    = get_unsigned_pair(tfm_file);
  tfm->nextens  = get_unsigned_pair(tfm_file);
  tfm->nfonparm = get_unsigned_pair(tfm_file);

  tfm_check_size(tfm, tfm_file_size);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double tfm_get_width ( int  font_id,
SIGNED_QUAD  ch 
)

Definition at line 1134 of file tfm.c.

{
  return ((double) tfm_get_fw_width(font_id, ch)/FWBASE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tfm_open ( const char *  tfm_name,
int  must_exist 
)

Definition at line 946 of file tfm.c.

{
  FILE *tfm_file;
  int i;
  UNSIGNED_QUAD tfm_file_size;
  char *tex_name = NULL;

  {
    // find tex_name
    int i = strlen(tfm_name)-1;
    while (i>=0) {
      if (tfm_name[i] != '/') i--;
      else break;
    }
    i++;
    tex_name = NEW(strlen(tfm_name+i),char);
    strcpy(tex_name,tfm_name+i);
  }
  
  
  for (i = 0; i < numfms; i++) {
    if (!strcmp(tex_name, fms[i].tex_name))
      return i;
  }

  tfm_file = MFOPEN(tfm_name, FOPEN_RBIN_MODE);
  
#if 0
  if (verbose) {
    if (format == TFM_FORMAT)
      MESG("(TFM:%s", tfm_name);
    else if (format == OFM_FORMAT)
      MESG("(OFM:%s", tfm_name);
    if (verbose > 1)
      MESG("[%s]", file_name);
  }
#endif
  
  
  tfm_file_size = file_size(tfm_file);
  if (tfm_file_size < 24) {
    ERROR("TFM file too small to be a valid file.");
  }
  
  
  if (!tfm_file) {
    ERROR("Could not open specified TFM file \"%s\".", tfm_name);
  }
  
  
  fms_need(numfms + 1);
  fm_init(fms + numfms);
  
  {
    read_tfm(&fms[numfms], tfm_file, tfm_file_size);
  }
  
  MFCLOSE(tfm_file);
  
  fms[numfms].tex_name = NEW(strlen(tex_name)+1, char);
  strcpy(fms[numfms].tex_name, tex_name);
  
  if (verbose) 
    MESG(")");
  
  RELEASE(tex_name);
  
  return numfms++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tfm_set_verbose ( void  )

Definition at line 328 of file tfm.c.

{
  verbose++;
}
fixword tfm_string_depth ( int  font_id,
const unsigned char *  s,
unsigned  len 
)

Definition at line 1182 of file tfm.c.

{
  fixword result = 0;
  struct font_metric *fm;
  unsigned i;

  CHECK_ID(font_id);

  fm = &(fms[font_id]);
#ifndef WITHOUT_ASCII_PTEX
  if (fm->source == SOURCE_TYPE_JFM) {
    for (i = 0; i < len/2; i++) {
      SIGNED_QUAD ch;

      ch = (s[2*i] << 8)|s[2*i+1];
      result += tfm_get_fw_depth(font_id, ch);
    }
  } else
#endif
    for (i = 0; i < len; i++) {
      result = MAX(result, tfm_get_fw_depth(font_id, s[i]));
    }

  return result;
}

Here is the call graph for this function:

fixword tfm_string_height ( int  font_id,
const unsigned char *  s,
unsigned  len 
)

Definition at line 1209 of file tfm.c.

{
  fixword result = 0;
  struct font_metric *fm;
  unsigned i;

  CHECK_ID(font_id);

  fm = &(fms[font_id]);
#ifndef WITHOUT_ASCII_PTEX
  if (fm->source == SOURCE_TYPE_JFM) {
    for (i = 0; i < len/2; i++) {
      SIGNED_QUAD ch;

      ch = (s[2*i] << 8)|s[2*i+1];
      result += tfm_get_fw_height(font_id, ch);
    }
  } else
#endif
    for (i = 0; i < len; i++) {
      result = MAX(result, tfm_get_fw_height(font_id, s[i]));
    }

  return result;
}

Here is the call graph for this function:

fixword tfm_string_width ( int  font_id,
const unsigned char *  s,
unsigned  len 
)

Definition at line 1155 of file tfm.c.

{
  fixword result = 0;
  struct font_metric *fm;
  unsigned i;

  CHECK_ID(font_id);

  fm = &(fms[font_id]);
#ifndef WITHOUT_ASCII_PTEX
  if (fm->source == SOURCE_TYPE_JFM) {
    for (i = 0; i < len/2; i++) {
      SIGNED_QUAD ch;

      ch = (s[2*i] << 8)|s[2*i+1];
      result += tfm_get_fw_width(font_id, ch);
    }
  } else
#endif
    for (i = 0; i < len; i++) {
      result += tfm_get_fw_width(font_id, s[i]);
    }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void tfm_unpack_arrays ( struct font_metric fm,
struct tfm_font tfm 
) [static]

Definition at line 504 of file tfm.c.

{
  UNSIGNED_QUAD charinfo;
  UNSIGNED_PAIR width_index, height_index, depth_index;
  int i;

  fm->widths  = NEW(256, fixword);
  fm->heights = NEW(256, fixword);
  fm->depths  = NEW(256, fixword);
  for (i = 0; i < 256; i++) {
    fm->widths [i] = 0;
    fm->heights[i] = 0;
    fm->depths [i] = 0;
  }

  for (i = tfm->bc; i <= tfm->ec; i++ ) {
    charinfo     = tfm->char_info[i - tfm->bc];
    width_index  = (charinfo / 16777216ul);
    height_index = (charinfo / 0x100000ul) & 0xf;
    depth_index  = (charinfo / 0x10000ul)  & 0xf;
    fm->widths [i] = tfm->width [width_index];
    fm->heights[i] = tfm->height[height_index];
    fm->depths [i] = tfm->depth [depth_index];
  }

  return;
}

Here is the caller graph for this function:

static void tfm_unpack_header ( struct font_metric fm,
struct tfm_font tfm 
) [static]

Definition at line 546 of file tfm.c.

{
  if (tfm->wlenheader < 12) {
    fm->codingscheme = NULL;
  } else {
    int   i, len;
    char *p;

    len = (tfm->header[2] >> 24);
    if (len < 0 || len > 39)
      ERROR("Invalid TFM header.");
    if (len > 0) {
      fm->codingscheme = NEW(40, char);
      p = fm->codingscheme;
      p += sput_bigendian(p, tfm->header[2], 3);
      for (i = 1; i <= len / 4; i++) {
       p += sput_bigendian(p, tfm->header[2+i], 4);
      }
      fm->codingscheme[len] = '\0';
    } else {
      fm->codingscheme = NULL;
    }
  }

  fm->designsize = tfm->header[1];
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct font_metric* fms = NULL

Definition at line 315 of file tfm.c.

unsigned max_fms = 0 [static]

Definition at line 316 of file tfm.c.

unsigned numfms = 0 [static]

Definition at line 316 of file tfm.c.

int verbose = 0 [static]

Definition at line 46 of file tfm.c.