Back to index

tetex-bin  3.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
FoFiType1 Class Reference

#include <FoFiType1.h>

Inheritance diagram for FoFiType1:
Inheritance graph
[legend]
Collaboration diagram for FoFiType1:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~FoFiType1 ()
char * getName ()
char ** getEncoding ()
void writeEncoded (char **newEncoding, FoFiOutputFunc outputFunc, void *outputStream)

Static Public Member Functions

static FoFiType1make (char *fileA, int lenA)
static FoFiType1load (char *fileName)

Protected Member Functions

int getS8 (int pos, GBool *ok)
int getU8 (int pos, GBool *ok)
int getS16BE (int pos, GBool *ok)
int getU16BE (int pos, GBool *ok)
int getS32BE (int pos, GBool *ok)
Guint getU32BE (int pos, GBool *ok)
Guint getUVarBE (int pos, int size, GBool *ok)
GBool checkRegion (int pos, int size)

Static Protected Member Functions

static char * readFile (char *fileName, int *fileLen)

Protected Attributes

GucharfileData
Gucharfile
int len
GBool freeFileData

Private Member Functions

 FoFiType1 (char *fileA, int lenA, GBool freeFileDataA)
char * getNextLine (char *line)
void parse ()

Private Attributes

char * name
char ** encoding
GBool parsed

Detailed Description

Definition at line 25 of file FoFiType1.h.


Constructor & Destructor Documentation

FoFiType1::~FoFiType1 ( ) [virtual]

Definition at line 47 of file FoFiType1.cc.

                      {
  int i;

  if (name) {
    gfree(name);
  }
  if (encoding && encoding != fofiType1StandardEncoding) {
    for (i = 0; i < 256; ++i) {
      gfree(encoding[i]);
    }
    gfree(encoding);
  }
}

Here is the call graph for this function:

FoFiType1::FoFiType1 ( char *  fileA,
int  lenA,
GBool  freeFileDataA 
) [private]

Definition at line 39 of file FoFiType1.cc.

                                                              :
  FoFiBase(fileA, lenA, freeFileDataA)
{
  name = NULL;
  encoding = NULL;
  parsed = gFalse;
}

Here is the caller graph for this function:


Member Function Documentation

GBool FoFiBase::checkRegion ( int  pos,
int  size 
) [protected, inherited]

Definition at line 152 of file FoFiBase.cc.

                                             {
  return pos >= 0 &&
         pos + size >= pos &&
         pos + size <= len;
}

Here is the caller graph for this function:

Definition at line 68 of file FoFiType1.cc.

                              {
  if (!parsed) {
    parse();
  }
  return encoding;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * FoFiType1::getName ( )

Definition at line 61 of file FoFiType1.cc.

                         {
  if (!parsed) {
    parse();
  }
  return name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * FoFiType1::getNextLine ( char *  line) [private]

Definition at line 117 of file FoFiType1.cc.

                                       {
  while (line < (char *)file + len && *line != '\x0a' && *line != '\x0d') {
    ++line;
  }
  if (line < (char *)file + len && *line == '\x0d') {
    ++line;
  }
  if (line < (char *)file + len && *line == '\x0a') {
    ++line;
  }
  if (line >= (char *)file + len) {
    return NULL;
  }
  return line;
}

Here is the caller graph for this function:

int FoFiBase::getS16BE ( int  pos,
GBool ok 
) [protected, inherited]

Definition at line 79 of file FoFiBase.cc.

                                         {
  int x;

  if (pos < 0 || pos+1 >= len) {
    *ok = gFalse;
    return 0;
  }
  x = file[pos];
  x = (x << 8) + file[pos+1];
  if (x & 0x8000) {
    x |= ~0xffff;
  }
  return x;
}

Here is the caller graph for this function:

int FoFiBase::getS32BE ( int  pos,
GBool ok 
) [protected, inherited]

Definition at line 106 of file FoFiBase.cc.

                                         {
  int x;

  if (pos < 0 || pos+3 >= len) {
    *ok = gFalse;
    return 0;
  }
  x = file[pos];
  x = (x << 8) + file[pos+1];
  x = (x << 8) + file[pos+2];
  x = (x << 8) + file[pos+3];
  if (x & 0x80000000) {
    x |= ~0xffffffff;
  }
  return x;
}

Here is the caller graph for this function:

int FoFiBase::getS8 ( int  pos,
GBool ok 
) [protected, inherited]

Definition at line 57 of file FoFiBase.cc.

                                      {
  int x;

  if (pos < 0 || pos >= len) {
    *ok = gFalse;
    return 0;
  }
  x = file[pos];
  if (x & 0x80) {
    x |= ~0xff;
  }
  return x;
}
int FoFiBase::getU16BE ( int  pos,
GBool ok 
) [protected, inherited]

Definition at line 94 of file FoFiBase.cc.

                                         {
  int x;

  if (pos < 0 || pos+1 >= len) {
    *ok = gFalse;
    return 0;
  }
  x = file[pos];
  x = (x << 8) + file[pos+1];
  return x;
}

Here is the caller graph for this function:

Guint FoFiBase::getU32BE ( int  pos,
GBool ok 
) [protected, inherited]

Definition at line 123 of file FoFiBase.cc.

                                           {
  Guint x;

  if (pos < 0 || pos+3 >= len) {
    *ok = gFalse;
    return 0;
  }
  x = file[pos];
  x = (x << 8) + file[pos+1];
  x = (x << 8) + file[pos+2];
  x = (x << 8) + file[pos+3];
  return x;
}

Here is the caller graph for this function:

int FoFiBase::getU8 ( int  pos,
GBool ok 
) [protected, inherited]

Definition at line 71 of file FoFiBase.cc.

                                      {
  if (pos < 0 || pos >= len) {
    *ok = gFalse;
    return 0;
  }
  return file[pos];
}

Here is the caller graph for this function:

Guint FoFiBase::getUVarBE ( int  pos,
int  size,
GBool ok 
) [protected, inherited]

Definition at line 137 of file FoFiBase.cc.

                                                      {
  Guint x;
  int i;

  if (pos < 0 || pos + size > len) {
    *ok = gFalse;
    return 0;
  }
  x = 0;
  for (i = 0; i < size; ++i) {
    x = (x << 8) + file[pos + i];
  }
  return x;
}

Here is the caller graph for this function:

FoFiType1 * FoFiType1::load ( char *  fileName) [static]

Definition at line 29 of file FoFiType1.cc.

                                         {
  char *fileA;
  int lenA;

  if (!(fileA = FoFiBase::readFile(fileName, &lenA))) {
    return NULL;
  }
  return new FoFiType1(fileA, lenA, gTrue);
}

Here is the call graph for this function:

Here is the caller graph for this function:

FoFiType1 * FoFiType1::make ( char *  fileA,
int  lenA 
) [static]

Definition at line 25 of file FoFiType1.cc.

                                                {
  return new FoFiType1(fileA, lenA, gFalse);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FoFiType1::parse ( ) [private]

Definition at line 133 of file FoFiType1.cc.

                      {
  char *line, *line1, *p, *p2;
  char buf[256];
  char c;
  int n, code, i, j;

  for (i = 1, line = (char *)file;
       i <= 100 && line && (!name || !encoding);
       ++i) {

    // get font name
    if (!name && !strncmp(line, "/FontName", 9)) {
      strncpy(buf, line, 255);
      buf[255] = '\0';
      if ((p = strchr(buf+9, '/')) &&
         (p = strtok(p+1, " \t\n\r"))) {
       name = copyString(p);
      }
      line = getNextLine(line);

    // get encoding
    } else if (!encoding &&
              !strncmp(line, "/Encoding StandardEncoding def", 30)) {
      encoding = fofiType1StandardEncoding;
    } else if (!encoding &&
              !strncmp(line, "/Encoding 256 array", 19)) {
      encoding = (char **)gmalloc(256 * sizeof(char *));
      for (j = 0; j < 256; ++j) {
       encoding[j] = NULL;
      }
      for (j = 0, line = getNextLine(line);
          j < 300 && line && (line1 = getNextLine(line));
          ++j, line = line1) {
       if ((n = line1 - line) > 255) {
         n = 255;
       }
       if (n < 0) n = 0;
       strncpy(buf, line, n);
       buf[n] = '\0';
       for (p = buf; *p == ' ' || *p == '\t'; ++p) ;
       if (!strncmp(p, "dup", 3)) {
         for (p += 3; *p == ' ' || *p == '\t'; ++p) ;
         for (p2 = p; *p2 >= '0' && *p2 <= '9'; ++p2) ;
         if (*p2) {
           c = *p2;
           *p2 = '\0';
           if ((code = atoi(p)) < 256) {
             *p2 = c;
             for (p = p2; *p == ' ' || *p == '\t'; ++p) ;
             if (*p == '/') {
              ++p;
              for (p2 = p; *p2 && *p2 != ' ' && *p2 != '\t'; ++p2) ;
              *p2 = '\0';
              encoding[code] = copyString(p);
             }
           }
         }
       } else {
         if (strtok(buf, " \t") &&
             (p = strtok(NULL, " \t\n\r")) && !strcmp(p, "def")) {
           break;
         }
       }
       line = line1;
      }
      //~ check for getinterval/putinterval junk

    } else {
      line = getNextLine(line);
    }

    ++i;
  }

  parsed = gTrue;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * FoFiBase::readFile ( char *  fileName,
int fileLen 
) [static, protected, inherited]

Definition at line 35 of file FoFiBase.cc.

                                                     {
  FILE *f;
  char *buf;
  int n;

  if (!(f = fopen(fileName, "rb"))) {
    return NULL;
  }
  fseek(f, 0, SEEK_END);
  n = (int)ftell(f);
  fseek(f, 0, SEEK_SET);
  buf = (char *)gmalloc(n);
  if ((int)fread(buf, 1, n, f) != n) {
    gfree(buf);
    fclose(f);
    return NULL;
  }
  fclose(f);
  *fileLen = n;
  return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FoFiType1::writeEncoded ( char **  newEncoding,
FoFiOutputFunc  outputFunc,
void outputStream 
)

Definition at line 75 of file FoFiType1.cc.

                                                                         {
  char buf[512];
  char *line;
  int i;

  // copy everything up to the encoding
  for (line = (char *)file;
       line && strncmp(line, "/Encoding", 9);
       line = getNextLine(line)) ;
  if (!line) {
    // no encoding - just copy the whole font file
    (*outputFunc)(outputStream, (char *)file, len);
    return;
  }
  (*outputFunc)(outputStream, (char *)file, line - (char *)file);

  // write the new encoding
  (*outputFunc)(outputStream, "/Encoding 256 array\n", 20);
  (*outputFunc)(outputStream,
              "0 1 255 {1 index exch /.notdef put} for\n", 40);
  for (i = 0; i < 256; ++i) {
    if (newEncoding[i]) {
      sprintf(buf, "dup %d /%s put\n", i, newEncoding[i]);
      (*outputFunc)(outputStream, buf, strlen(buf));
    }
  }
  (*outputFunc)(outputStream, "readonly def\n", 13);
  
  // copy everything after the encoding
  if (!strncmp(line, "/Encoding StandardEncoding def", 30)) {
    line = getNextLine(line);
  } else {
    for (line = getNextLine(line);
        line && strncmp(line, "readonly def", 12);
        line = getNextLine(line)) ;
  }
  if (line) {
    (*outputFunc)(outputStream, line, ((char *)file + len) - line);
  }
}

Here is the call graph for this function:


Member Data Documentation

char** FoFiType1::encoding [private]

Definition at line 55 of file FoFiType1.h.

Guchar* FoFiBase::file [protected, inherited]

Definition at line 52 of file FoFiBase.h.

Guchar* FoFiBase::fileData [protected, inherited]

Definition at line 51 of file FoFiBase.h.

GBool FoFiBase::freeFileData [protected, inherited]

Definition at line 54 of file FoFiBase.h.

int FoFiBase::len [protected, inherited]

Definition at line 53 of file FoFiBase.h.

char* FoFiType1::name [private]

Definition at line 54 of file FoFiType1.h.

Definition at line 56 of file FoFiType1.h.


The documentation for this class was generated from the following files: