Back to index

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

#include <GfxFont.h>

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

List of all members.

Public Member Functions

 GfxFont (char *tagA, Ref idA, GString *nameA)
virtual ~GfxFont ()
GBool isOk ()
GStringgetTag ()
RefgetID ()
GBool matches (char *tagA)
GStringgetName ()
GStringgetOrigName ()
GfxFontType getType ()
virtual GBool isCIDFont ()
GBool getEmbeddedFontID (Ref *embID)
GStringgetEmbeddedFontName ()
GStringgetExtFontFile ()
GBool isFixedWidth ()
GBool isSerif ()
GBool isSymbolic ()
GBool isItalic ()
GBool isBold ()
double * getFontMatrix ()
double * getFontBBox ()
double getAscent ()
double getDescent ()
virtual int getWMode ()
char * readExtFontFile (int *len)
char * readEmbFontFile (XRef *xref, int *len)
virtual int getNextChar (char *s, int len, CharCode *code, Unicode *u, int uSize, int *uLen, double *dx, double *dy, double *ox, double *oy)=0

Static Public Member Functions

static GfxFontmakeFont (XRef *xref, char *tagA, Ref idA, Dict *fontDict)

Protected Member Functions

void readFontDescriptor (XRef *xref, Dict *fontDict)
CharCodeToUnicodereadToUnicodeCMap (Dict *fontDict, int nBits, CharCodeToUnicode *ctu)
void findExtFontFile ()

Protected Attributes

GStringtag
Ref id
GStringname
GStringorigName
GfxFontType type
int flags
GStringembFontName
Ref embFontID
GStringextFontFile
double fontMat [6]
double fontBBox [4]
double missingWidth
double ascent
double descent
GBool ok

Detailed Description

Definition at line 84 of file GfxFont.h.


Constructor & Destructor Documentation

GfxFont::GfxFont ( char *  tagA,
Ref  idA,
GString nameA 
)

Definition at line 139 of file GfxFont.cc.

                                                    {
  ok = gFalse;
  tag = new GString(tagA);
  id = idA;
  name = nameA;
  origName = nameA;
  embFontName = NULL;
  extFontFile = NULL;
}
GfxFont::~GfxFont ( ) [virtual]

Definition at line 149 of file GfxFont.cc.

                  {
  delete tag;
  if (origName && origName != name) {
    delete origName;
  }
  if (name) {
    delete name;
  }
  if (embFontName) {
    delete embFontName;
  }
  if (extFontFile) {
    delete extFontFile;
  }
}

Member Function Documentation

void GfxFont::findExtFontFile ( ) [protected]

Definition at line 324 of file GfxFont.cc.

                              {
  static char *type1Exts[] = { ".pfa", ".pfb", ".ps", "", NULL };
  static char *ttExts[] = { ".ttf", NULL };

  if (name) {
    if (type == fontType1) {
      extFontFile = globalParams->findFontFile(name, type1Exts);
    } else if (type == fontTrueType) {
      extFontFile = globalParams->findFontFile(name, ttExts);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

double GfxFont::getAscent ( ) [inline]

Definition at line 143 of file GfxFont.h.

{ return ascent; }
double GfxFont::getDescent ( ) [inline]

Definition at line 144 of file GfxFont.h.

{ return descent; }
GBool GfxFont::getEmbeddedFontID ( Ref embID) [inline]

Definition at line 118 of file GfxFont.h.

    { *embID = embFontID; return embFontID.num >= 0; }

Definition at line 123 of file GfxFont.h.

{ return embFontName; }

Definition at line 127 of file GfxFont.h.

{ return extFontFile; }
double* GfxFont::getFontBBox ( ) [inline]

Definition at line 140 of file GfxFont.h.

{ return fontBBox; }
double* GfxFont::getFontMatrix ( ) [inline]

Definition at line 137 of file GfxFont.h.

{ return fontMat; }

Here is the caller graph for this function:

Ref* GfxFont::getID ( ) [inline]

Definition at line 100 of file GfxFont.h.

{ return &id; }
GString* GfxFont::getName ( ) [inline]

Definition at line 106 of file GfxFont.h.

{ return name; }

Here is the caller graph for this function:

virtual int GfxFont::getNextChar ( char *  s,
int  len,
CharCode code,
Unicode u,
int  uSize,
int uLen,
double *  dx,
double *  dy,
double *  ox,
double *  oy 
) [pure virtual]

Implemented in GfxCIDFont, and Gfx8BitFont.

Here is the caller graph for this function:

Definition at line 110 of file GfxFont.h.

{ return origName; }
GString* GfxFont::getTag ( ) [inline]

Definition at line 97 of file GfxFont.h.

{ return tag; }

Here is the caller graph for this function:

Definition at line 113 of file GfxFont.h.

{ return type; }

Here is the caller graph for this function:

virtual int GfxFont::getWMode ( ) [inline, virtual]

Reimplemented in GfxCIDFont.

Definition at line 147 of file GfxFont.h.

{ return 0; }

Here is the caller graph for this function:

GBool GfxFont::isBold ( ) [inline]

Definition at line 134 of file GfxFont.h.

{ return flags & fontBold; }

Here is the caller graph for this function:

virtual GBool GfxFont::isCIDFont ( ) [inline, virtual]

Reimplemented in GfxCIDFont.

Definition at line 114 of file GfxFont.h.

{ return gFalse; }

Here is the caller graph for this function:

Definition at line 130 of file GfxFont.h.

{ return flags & fontFixedWidth; }

Here is the caller graph for this function:

GBool GfxFont::isItalic ( ) [inline]

Definition at line 133 of file GfxFont.h.

{ return flags & fontItalic; }

Here is the caller graph for this function:

GBool GfxFont::isOk ( ) [inline]

Definition at line 94 of file GfxFont.h.

{ return ok; }
GBool GfxFont::isSerif ( ) [inline]

Definition at line 131 of file GfxFont.h.

{ return flags & fontSerif; }

Here is the caller graph for this function:

GBool GfxFont::isSymbolic ( ) [inline]

Definition at line 132 of file GfxFont.h.

{ return flags & fontSymbolic; }
GfxFont * GfxFont::makeFont ( XRef xref,
char *  tagA,
Ref  idA,
Dict fontDict 
) [static]

Definition at line 103 of file GfxFont.cc.

                                                                          {
  GString *nameA;
  GfxFont *font;
  Object obj1;

  // get base font name
  nameA = NULL;
  fontDict->lookup("BaseFont", &obj1);
  if (obj1.isName()) {
    nameA = new GString(obj1.getName());
  }
  obj1.free();

  // get font type
  font = NULL;
  fontDict->lookup("Subtype", &obj1);
  if (obj1.isName("Type1") || obj1.isName("MMType1")) {
    font = new Gfx8BitFont(xref, tagA, idA, nameA, fontType1, fontDict);
  } else if (obj1.isName("Type1C")) {
    font = new Gfx8BitFont(xref, tagA, idA, nameA, fontType1C, fontDict);
  } else if (obj1.isName("Type3")) {
    font = new Gfx8BitFont(xref, tagA, idA, nameA, fontType3, fontDict);
  } else if (obj1.isName("TrueType")) {
    font = new Gfx8BitFont(xref, tagA, idA, nameA, fontTrueType, fontDict);
  } else if (obj1.isName("Type0")) {
    font = new GfxCIDFont(xref, tagA, idA, nameA, fontDict);
  } else {
    error(-1, "Unknown font type: '%s'",
         obj1.isName() ? obj1.getName() : "???");
    font = new Gfx8BitFont(xref, tagA, idA, nameA, fontUnknownType, fontDict);
  }
  obj1.free();

  return font;
}

Here is the call graph for this function:

Here is the caller graph for this function:

GBool GfxFont::matches ( char *  tagA) [inline]

Definition at line 103 of file GfxFont.h.

{ return !tag->cmp(tagA); }

Here is the call graph for this function:

char * GfxFont::readEmbFontFile ( XRef xref,
int len 
)

Definition at line 357 of file GfxFont.cc.

                                                   {
  char *buf;
  Object obj1, obj2;
  Stream *str;
  int c;
  int size, i;

  obj1.initRef(embFontID.num, embFontID.gen);
  obj1.fetch(xref, &obj2);
  if (!obj2.isStream()) {
    error(-1, "Embedded font file is not a stream");
    obj2.free();
    obj1.free();
    embFontID.num = -1;
    return NULL;
  }
  str = obj2.getStream();

  buf = NULL;
  i = size = 0;
  str->reset();
  while ((c = str->getChar()) != EOF) {
    if (i == size) {
      size += 4096;
      buf = (char *)grealloc(buf, size);
    }
    buf[i++] = c;
  }
  *len = i;
  str->close();

  obj2.free();
  obj1.free();

  return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * GfxFont::readExtFontFile ( int len)

Definition at line 337 of file GfxFont.cc.

                                       {
  FILE *f;
  char *buf;

  if (!(f = fopen(extFontFile->getCString(), "rb"))) {
    error(-1, "External font file '%s' vanished", extFontFile->getCString());
    return NULL;
  }
  fseek(f, 0, SEEK_END);
  *len = (int)ftell(f);
  fseek(f, 0, SEEK_SET);
  buf = (char *)gmalloc(*len);
  if ((int)fread(buf, 1, *len, f) != *len) {
    error(-1, "Error reading external font file '%s'",
         extFontFile->getCString());
  }
  fclose(f);
  return buf;
}

Here is the call graph for this function:

void GfxFont::readFontDescriptor ( XRef xref,
Dict fontDict 
) [protected]

Definition at line 165 of file GfxFont.cc.

                                                           {
  Object obj1, obj2, obj3, obj4;
  double t;
  int i;

  // assume Times-Roman by default (for substitution purposes)
  flags = fontSerif;

  embFontID.num = -1;
  embFontID.gen = -1;
  missingWidth = 0;

  if (fontDict->lookup("FontDescriptor", &obj1)->isDict()) {

    // get flags
    if (obj1.dictLookup("Flags", &obj2)->isInt()) {
      flags = obj2.getInt();
    }
    obj2.free();

    // get name
    obj1.dictLookup("FontName", &obj2);
    if (obj2.isName()) {
      embFontName = new GString(obj2.getName());
    }
    obj2.free();

    // look for embedded font file
    if (obj1.dictLookupNF("FontFile", &obj2)->isRef()) {
      if (type == fontType1) {
       embFontID = obj2.getRef();
      } else {
       error(-1, "Mismatch between font type and embedded font file");
      }
    }
    obj2.free();
    if (embFontID.num == -1 &&
       obj1.dictLookupNF("FontFile2", &obj2)->isRef()) {
      if (type == fontTrueType || type == fontCIDType2) {
       embFontID = obj2.getRef();
      } else {
       error(-1, "Mismatch between font type and embedded font file");
      }
    }
    obj2.free();
    if (embFontID.num == -1 &&
       obj1.dictLookupNF("FontFile3", &obj2)->isRef()) {
      if (obj2.fetch(xref, &obj3)->isStream()) {
       obj3.streamGetDict()->lookup("Subtype", &obj4);
       if (obj4.isName("Type1")) {
         if (type == fontType1) {
           embFontID = obj2.getRef();
         } else {
           error(-1, "Mismatch between font type and embedded font file");
         }
       } else if (obj4.isName("Type1C")) {
         if (type == fontType1) {
           type = fontType1C;
           embFontID = obj2.getRef();
         } else if (type == fontType1C) {
           embFontID = obj2.getRef();
         } else {
           error(-1, "Mismatch between font type and embedded font file");
         }
       } else if (obj4.isName("TrueType")) {
         if (type == fontTrueType) {
           embFontID = obj2.getRef();
         } else {
           error(-1, "Mismatch between font type and embedded font file");
         }
       } else if (obj4.isName("CIDFontType0C")) {
         if (type == fontCIDType0) {
           type = fontCIDType0C;
           embFontID = obj2.getRef();
         } else {
           error(-1, "Mismatch between font type and embedded font file");
         }
       } else {
         error(-1, "Unknown embedded font type '%s'",
              obj4.isName() ? obj4.getName() : "???");
       }
       obj4.free();
      }
      obj3.free();
    }
    obj2.free();

    // look for MissingWidth
    obj1.dictLookup("MissingWidth", &obj2);
    if (obj2.isNum()) {
      missingWidth = obj2.getNum();
    }
    obj2.free();

    // get Ascent and Descent
    obj1.dictLookup("Ascent", &obj2);
    if (obj2.isNum()) {
      t = 0.001 * obj2.getNum();
      // some broken font descriptors set ascent and descent to 0
      if (t != 0) {
       ascent = t;
      }
    }
    obj2.free();
    obj1.dictLookup("Descent", &obj2);
    if (obj2.isNum()) {
      t = 0.001 * obj2.getNum();
      // some broken font descriptors set ascent and descent to 0
      if (t != 0) {
       descent = t;
      }
      // some broken font descriptors specify a positive descent
      if (descent > 0) {
       descent = -descent;
      }
    }
    obj2.free();

    // font FontBBox
    if (obj1.dictLookup("FontBBox", &obj2)->isArray()) {
      for (i = 0; i < 4 && i < obj2.arrayGetLength(); ++i) {
       if (obj2.arrayGet(i, &obj3)->isNum()) {
         fontBBox[i] = 0.001 * obj3.getNum();
       }
       obj3.free();
      }
    }
    obj2.free();

  }
  obj1.free();
}

Here is the call graph for this function:

Here is the caller graph for this function:

CharCodeToUnicode * GfxFont::readToUnicodeCMap ( Dict fontDict,
int  nBits,
CharCodeToUnicode ctu 
) [protected]

Definition at line 298 of file GfxFont.cc.

                                                                 {
  GString *buf;
  Object obj1;
  int c;

  if (!fontDict->lookup("ToUnicode", &obj1)->isStream()) {
    obj1.free();
    return NULL;
  }
  buf = new GString();
  obj1.streamReset();
  while ((c = obj1.streamGetChar()) != EOF) {
    buf->append(c);
  }
  obj1.streamClose();
  obj1.free();
  if (ctu) {
    ctu->mergeCMap(buf, nBits);
  } else {
    ctu = CharCodeToUnicode::parseCMap(buf, nBits);
  }
  delete buf;
  return ctu;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

double GfxFont::ascent [protected]

Definition at line 182 of file GfxFont.h.

double GfxFont::descent [protected]

Definition at line 183 of file GfxFont.h.

Ref GfxFont::embFontID [protected]

Definition at line 177 of file GfxFont.h.

Definition at line 176 of file GfxFont.h.

Definition at line 178 of file GfxFont.h.

int GfxFont::flags [protected]

Definition at line 175 of file GfxFont.h.

double GfxFont::fontBBox[4] [protected]

Definition at line 180 of file GfxFont.h.

double GfxFont::fontMat[6] [protected]

Definition at line 179 of file GfxFont.h.

Ref GfxFont::id [protected]

Definition at line 171 of file GfxFont.h.

double GfxFont::missingWidth [protected]

Definition at line 181 of file GfxFont.h.

GString* GfxFont::name [protected]

Definition at line 172 of file GfxFont.h.

GBool GfxFont::ok [protected]

Definition at line 184 of file GfxFont.h.

GString* GfxFont::origName [protected]

Definition at line 173 of file GfxFont.h.

GString* GfxFont::tag [protected]

Definition at line 170 of file GfxFont.h.

Definition at line 174 of file GfxFont.h.


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