Back to index

texmacs  1.0.7.15
Defines | Functions | Variables
tt_post.c File Reference
#include "system.h"
#include "error.h"
#include "mem.h"
#include "dpxfile.h"
#include "sfnt.h"
#include "tt_post.h"

Go to the source code of this file.

Defines

#define NAME_STR_OFFSET   32

Functions

static int read_v2_post_names (struct tt_post_table *post, sfnt *sfont)
struct tt_post_tablett_read_post_table (sfnt *sfont)
USHORT tt_lookup_post_table (struct tt_post_table *post, const char *glyphname)
void tt_release_post_table (struct tt_post_table *post)

Variables

static const char *const macglyphorder [258]

Define Documentation

#define NAME_STR_OFFSET   32

Definition at line 36 of file tt_post.c.


Function Documentation

static int read_v2_post_names ( struct tt_post_table post,
sfnt sfont 
) [static]

Definition at line 39 of file tt_post.c.

{
  USHORT i, idx, *indices;
  int    len;

  post->numberOfGlyphs = sfnt_get_ushort(sfont);

  indices     = NEW(post->numberOfGlyphs, USHORT);
  post->count = 0;
  for (i = 0;
       i < post->numberOfGlyphs; i++) {
    idx = sfnt_get_ushort(sfont);
    if (idx >= 258) {
      if (idx > 32767) {
       WARN("TrueTypes post table name index %u > 32767", idx);
       idx = 0;
      }
      post->count++;
    }
    indices[i] = idx;
  }

  if (post->count < 1) {
    post->names = NULL;
  } else {
    post->names = NEW(post->count, char *);
    for (i = 0; i < post->count; i++) { /* read Pascal strings */
      len = sfnt_get_byte(sfont);
      if (len > 0) {
       post->names[i] = NEW(len + 1, char);
       sfnt_read(post->names[i], len, sfont);
       post->names[i][len] = 0;
      } else {
       post->names[i] = NULL;
      }
    }
  }

  post->glyphNamePtr = NEW(post->numberOfGlyphs, char *);
  for (i = 0; i < post->numberOfGlyphs; i++) {
    idx = indices[i];
    if (idx < 258) {
      post->glyphNamePtr[i] = (char *) macglyphorder[idx];
    } else if (idx - 258 < post->count) {
      post->glyphNamePtr[i] = post->names[idx - 258];
    } else {
      WARN("Invalid glyph name index number: %u (>= %u)",
          idx, post->count + 258);
      RELEASE(indices);
      return -1;
    }
  }
  RELEASE(indices);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

USHORT tt_lookup_post_table ( struct tt_post_table post,
const char *  glyphname 
)

Definition at line 153 of file tt_post.c.

{
  USHORT  gid;

  ASSERT(post && glyphname);

  for (gid = 0; gid < post->count; gid++) {
    if (post->glyphNamePtr[gid] &&
       !strcmp(glyphname, post->glyphNamePtr[gid])) {
      return  gid;
    }
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct tt_post_table* tt_read_post_table ( sfnt sfont) [read]

Definition at line 97 of file tt_post.c.

{
  struct tt_post_table *post;
  ULONG  offset;

  offset = sfnt_locate_table(sfont, "post");

  post   = NEW(1, struct tt_post_table);

  post->Version            = sfnt_get_ulong(sfont); /* Fixed */
  post->italicAngle        = sfnt_get_ulong(sfont); /* Fixed */
  post->underlinePosition  = sfnt_get_short(sfont); /* FWord */
  post->underlineThickness = sfnt_get_short(sfont); /* FWord */
  post->isFixedPitch       = sfnt_get_ulong(sfont);
  post->minMemType42       = sfnt_get_ulong(sfont);
  post->maxMemType42       = sfnt_get_ulong(sfont);
  post->minMemType1        = sfnt_get_ulong(sfont);
  post->maxMemType1        = sfnt_get_ulong(sfont);

  post->numberOfGlyphs    = 0;
  post->glyphNamePtr      = NULL;
  post->count             = 0;
  post->names             = NULL;

  if (post->Version == 0x00010000UL) {
    post->numberOfGlyphs  = 258; /* wrong */
    post->glyphNamePtr    = (char **) macglyphorder;
    post->count           = 0;
    post->names           = NULL;
  } else if (post->Version == 0x00025000UL) {
    WARN("TrueType 'post' version 2.5 found (deprecated)");
    post->numberOfGlyphs  = 0; /* wrong */
    post->glyphNamePtr    = NULL;
    post->count           = 0;
    post->names           = NULL;
  } else if (post->Version == 0x00020000UL) {
    if (read_v2_post_names(post, sfont) < 0) {
      WARN("Invalid TrueType 'post' table...");
      tt_release_post_table(post);
      post = NULL;
    }
  } else if (post->Version == 0x00030000UL) {
    post->numberOfGlyphs  = 0; /* wrong */
    post->glyphNamePtr    = NULL;
    post->count           = 0;
    post->names           = NULL;
  } else {
    WARN("Unknown 'post' version: %08X", post->Version);
    tt_release_post_table(post);
    post = NULL;
  }

  return post;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tt_release_post_table ( struct tt_post_table post)

Definition at line 170 of file tt_post.c.

{
  USHORT i;

  ASSERT(post);

  if (post->glyphNamePtr && post->Version != 0x00010000UL)
    RELEASE(post->glyphNamePtr);
  if (post->names) {
    for (i = 0; i < post->count; i++) {
      if (post->names[i])
       RELEASE(post->names[i]);
    }
    RELEASE(post->names);
  }
  post->count        = 0;
  post->glyphNamePtr = NULL;
  post->names        = NULL;

  RELEASE(post);

  return;
}

Here is the caller graph for this function:


Variable Documentation

static const char *const macglyphorder [static]

Definition at line 33 of file tt_post.c.