Back to index

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

#include <GfxFont.h>

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

List of all members.

Public Member Functions

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

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

Private Attributes

CMapcMap
CharCodeToUnicodectu
GfxFontCIDWidths widths
GushortcidToGID
int cidToGIDLen

Detailed Description

Definition at line 251 of file GfxFont.h.


Constructor & Destructor Documentation

GfxCIDFont::GfxCIDFont ( XRef xref,
char *  tagA,
Ref  idA,
GString nameA,
Dict fontDict 
)

Definition at line 1038 of file GfxFont.cc.

                                    :
  GfxFont(tagA, idA, nameA)
{
  Dict *desFontDict;
  GString *collection, *cMapName;
  Object desFontDictObj;
  Object obj1, obj2, obj3, obj4, obj5, obj6;
  int c1, c2;
  int excepsSize, i, j, k;

  ascent = 0.95;
  descent = -0.35;
  fontBBox[0] = fontBBox[1] = fontBBox[2] = fontBBox[3] = 0;
  cMap = NULL;
  ctu = NULL;
  widths.defWidth = 1.0;
  widths.defHeight = -1.0;
  widths.defVY = 0.880;
  widths.exceps = NULL;
  widths.nExceps = 0;
  widths.excepsV = NULL;
  widths.nExcepsV = 0;
  cidToGID = NULL;
  cidToGIDLen = 0;

  // get the descendant font
  if (!fontDict->lookup("DescendantFonts", &obj1)->isArray()) {
    error(-1, "Missing DescendantFonts entry in Type 0 font");
    obj1.free();
    goto err1;
  }
  if (!obj1.arrayGet(0, &desFontDictObj)->isDict()) {
    error(-1, "Bad descendant font in Type 0 font");
    goto err3;
  }
  obj1.free();
  desFontDict = desFontDictObj.getDict();

  // font type
  if (!desFontDict->lookup("Subtype", &obj1)) {
    error(-1, "Missing Subtype entry in Type 0 descendant font");
    goto err3;
  }
  if (obj1.isName("CIDFontType0")) {
    type = fontCIDType0;
  } else if (obj1.isName("CIDFontType2")) {
    type = fontCIDType2;
  } else {
    error(-1, "Unknown Type 0 descendant font type '%s'",
         obj1.isName() ? obj1.getName() : "???");
    goto err3;
  }
  obj1.free();

  // get info from font descriptor
  readFontDescriptor(xref, desFontDict);

  // look for an external font file
  findExtFontFile();

  //----- encoding info -----

  // char collection
  if (!desFontDict->lookup("CIDSystemInfo", &obj1)->isDict()) {
    error(-1, "Missing CIDSystemInfo dictionary in Type 0 descendant font");
    goto err3;
  }
  obj1.dictLookup("Registry", &obj2);
  obj1.dictLookup("Ordering", &obj3);
  if (!obj2.isString() || !obj3.isString()) {
    error(-1, "Invalid CIDSystemInfo dictionary in Type 0 descendant font");
    goto err4;
  }
  collection = obj2.getString()->copy()->append('-')->append(obj3.getString());
  obj3.free();
  obj2.free();
  obj1.free();

  // look for a ToUnicode CMap
  if (!(ctu = readToUnicodeCMap(fontDict, 16, NULL))) {

    // the "Adobe-Identity" and "Adobe-UCS" collections don't have
    // cidToUnicode files
    if (collection->cmp("Adobe-Identity") &&
       collection->cmp("Adobe-UCS")) {

      // look for a user-supplied .cidToUnicode file
      if (!(ctu = globalParams->getCIDToUnicode(collection))) {
       error(-1, "Unknown character collection '%s'",
             collection->getCString());
       delete collection;
       goto err2;
      }
    }
  }

  // encoding (i.e., CMap)
  //~ need to handle a CMap stream here
  //~ also need to deal with the UseCMap entry in the stream dict
  if (!fontDict->lookup("Encoding", &obj1)->isName()) {
    error(-1, "Missing or invalid Encoding entry in Type 0 font");
    delete collection;
    goto err3;
  }
  cMapName = new GString(obj1.getName());
  obj1.free();
  if (!(cMap = globalParams->getCMap(collection, cMapName))) {
    error(-1, "Unknown CMap '%s' for character collection '%s'",
         cMapName->getCString(), collection->getCString());
    delete collection;
    delete cMapName;
    goto err2;
  }
  delete collection;
  delete cMapName;

  // CIDToGIDMap (for embedded TrueType fonts)
  if (type == fontCIDType2) {
    desFontDict->lookup("CIDToGIDMap", &obj1);
    if (obj1.isStream()) {
      cidToGIDLen = 0;
      i = 64;
      cidToGID = (Gushort *)gmalloc(i * sizeof(Gushort));
      obj1.streamReset();
      while ((c1 = obj1.streamGetChar()) != EOF &&
            (c2 = obj1.streamGetChar()) != EOF) {
       if (cidToGIDLen == i) {
         i *= 2;
         cidToGID = (Gushort *)grealloc(cidToGID, i * sizeof(Gushort));
       }
       cidToGID[cidToGIDLen++] = (Gushort)((c1 << 8) + c2);
      }
    } else if (!obj1.isName("Identity") && !obj1.isNull()) {
      error(-1, "Invalid CIDToGIDMap entry in CID font");
    }
    obj1.free();
  }

  //----- character metrics -----

  // default char width
  if (desFontDict->lookup("DW", &obj1)->isInt()) {
    widths.defWidth = obj1.getInt() * 0.001;
  }
  obj1.free();

  // char width exceptions
  if (desFontDict->lookup("W", &obj1)->isArray()) {
    excepsSize = 0;
    i = 0;
    while (i + 1 < obj1.arrayGetLength()) {
      obj1.arrayGet(i, &obj2);
      obj1.arrayGet(i + 1, &obj3);
      if (obj2.isInt() && obj3.isInt() && i + 2 < obj1.arrayGetLength()) {
       if (obj1.arrayGet(i + 2, &obj4)->isNum()) {
         if (widths.nExceps == excepsSize) {
           excepsSize += 16;
           widths.exceps = (GfxFontCIDWidthExcep *)
             grealloc(widths.exceps,
                     excepsSize * sizeof(GfxFontCIDWidthExcep));
         }
         widths.exceps[widths.nExceps].first = obj2.getInt();
         widths.exceps[widths.nExceps].last = obj3.getInt();
         widths.exceps[widths.nExceps].width = obj4.getNum() * 0.001;
         ++widths.nExceps;
       } else {
         error(-1, "Bad widths array in Type 0 font");
       }
       obj4.free();
       i += 3;
      } else if (obj2.isInt() && obj3.isArray()) {
       if (widths.nExceps + obj3.arrayGetLength() > excepsSize) {
         excepsSize = (widths.nExceps + obj3.arrayGetLength() + 15) & ~15;
         widths.exceps = (GfxFontCIDWidthExcep *)
           grealloc(widths.exceps,
                   excepsSize * sizeof(GfxFontCIDWidthExcep));
       }
       j = obj2.getInt();
       for (k = 0; k < obj3.arrayGetLength(); ++k) {
         if (obj3.arrayGet(k, &obj4)->isNum()) {
           widths.exceps[widths.nExceps].first = j;
           widths.exceps[widths.nExceps].last = j;
           widths.exceps[widths.nExceps].width = obj4.getNum() * 0.001;
           ++j;
           ++widths.nExceps;
         } else {
           error(-1, "Bad widths array in Type 0 font");
         }
         obj4.free();
       }
       i += 2;
      } else {
       error(-1, "Bad widths array in Type 0 font");
       ++i;
      }
      obj3.free();
      obj2.free();
    }
    qsort(widths.exceps, widths.nExceps, sizeof(GfxFontCIDWidthExcep),
         &cmpWidthExcep);
  }
  obj1.free();

  // default metrics for vertical font
  if (desFontDict->lookup("DW2", &obj1)->isArray() &&
      obj1.arrayGetLength() == 2) {
    if (obj1.arrayGet(0, &obj2)->isNum()) {
      widths.defVY = obj2.getNum() * 0.001;
    }
    obj2.free();
    if (obj1.arrayGet(1, &obj2)->isNum()) {
      widths.defHeight = obj2.getNum() * 0.001;
    }
    obj2.free();
  }
  obj1.free();

  // char metric exceptions for vertical font
  if (desFontDict->lookup("W2", &obj1)->isArray()) {
    excepsSize = 0;
    i = 0;
    while (i + 1 < obj1.arrayGetLength()) {
      obj1.arrayGet(i, &obj2);
      obj1.arrayGet(i+ 1, &obj3);
      if (obj2.isInt() && obj3.isInt() && i + 4 < obj1.arrayGetLength()) {
       if (obj1.arrayGet(i + 2, &obj4)->isNum() &&
           obj1.arrayGet(i + 3, &obj5)->isNum() &&
           obj1.arrayGet(i + 4, &obj6)->isNum()) {
         if (widths.nExcepsV == excepsSize) {
           excepsSize += 16;
           widths.excepsV = (GfxFontCIDWidthExcepV *)
             grealloc(widths.excepsV,
                     excepsSize * sizeof(GfxFontCIDWidthExcepV));
         }
         widths.excepsV[widths.nExcepsV].first = obj2.getInt();
         widths.excepsV[widths.nExcepsV].last = obj3.getInt();
         widths.excepsV[widths.nExcepsV].height = obj4.getNum() * 0.001;
         widths.excepsV[widths.nExcepsV].vx = obj5.getNum() * 0.001;
         widths.excepsV[widths.nExcepsV].vy = obj6.getNum() * 0.001;
         ++widths.nExcepsV;
       } else {
         error(-1, "Bad widths (W2) array in Type 0 font");
       }
       obj6.free();
       obj5.free();
       obj4.free();
       i += 5;
      } else if (obj2.isInt() && obj3.isArray()) {
       if (widths.nExcepsV + obj3.arrayGetLength() / 3 > excepsSize) {
         excepsSize =
           (widths.nExcepsV + obj3.arrayGetLength() / 3 + 15) & ~15;
         widths.excepsV = (GfxFontCIDWidthExcepV *)
           grealloc(widths.excepsV,
                   excepsSize * sizeof(GfxFontCIDWidthExcepV));
       }
       j = obj2.getInt();
       for (k = 0; k < obj3.arrayGetLength(); k += 3) {
         if (obj3.arrayGet(k, &obj4)->isNum() &&
             obj3.arrayGet(k+1, &obj5)->isNum() &&
             obj3.arrayGet(k+2, &obj6)->isNum()) {
           widths.excepsV[widths.nExceps].first = j;
           widths.excepsV[widths.nExceps].last = j;
           widths.excepsV[widths.nExceps].height = obj4.getNum() * 0.001;
           widths.excepsV[widths.nExceps].vx = obj5.getNum() * 0.001;
           widths.excepsV[widths.nExceps].vy = obj6.getNum() * 0.001;
           ++j;
           ++widths.nExcepsV;
         } else {
           error(-1, "Bad widths (W2) array in Type 0 font");
         }
         obj6.free();
         obj5.free();
         obj4.free();
       }
       i += 2;
      } else {
       error(-1, "Bad widths (W2) array in Type 0 font");
       ++i;
      }
      obj3.free();
      obj2.free();
    }
    qsort(widths.excepsV, widths.nExcepsV, sizeof(GfxFontCIDWidthExcepV),
         &cmpWidthExcepV);
  }
  obj1.free();

  desFontDictObj.free();
  ok = gTrue;
  return;

 err4:
  obj3.free();
  obj2.free();
 err3:
  obj1.free();
 err2:
  desFontDictObj.free();
 err1:;
}

Here is the call graph for this function:

GfxCIDFont::~GfxCIDFont ( ) [virtual]

Definition at line 1340 of file GfxFont.cc.

                        {
  if (cMap) {
    cMap->decRefCnt();
  }
  if (ctu) {
    ctu->decRefCnt();
  }
  gfree(widths.exceps);
  gfree(widths.excepsV);
  if (cidToGID) {
    gfree(cidToGID);
  }
}

Here is the call graph for this function:


Member Function Documentation

void GfxFont::findExtFontFile ( ) [protected, inherited]

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, inherited]

Definition at line 143 of file GfxFont.h.

{ return ascent; }

Definition at line 276 of file GfxFont.h.

{ return cidToGID; }

Definition at line 277 of file GfxFont.h.

{ return cidToGIDLen; }

Definition at line 1441 of file GfxFont.cc.

                                   {
  return cMap ? cMap->getCollection() : (GString *)NULL;
}

Here is the call graph for this function:

double GfxFont::getDescent ( ) [inline, inherited]

Definition at line 144 of file GfxFont.h.

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

Definition at line 118 of file GfxFont.h.

    { *embID = embFontID; return embFontID.num >= 0; }
GString* GfxFont::getEmbeddedFontName ( ) [inline, inherited]

Definition at line 123 of file GfxFont.h.

{ return embFontName; }
GString* GfxFont::getExtFontFile ( ) [inline, inherited]

Definition at line 127 of file GfxFont.h.

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

Definition at line 140 of file GfxFont.h.

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

Definition at line 137 of file GfxFont.h.

{ return fontMat; }

Here is the caller graph for this function:

Ref* GfxFont::getID ( ) [inline, inherited]

Definition at line 100 of file GfxFont.h.

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

Definition at line 106 of file GfxFont.h.

{ return name; }

Here is the caller graph for this function:

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

Implements GfxFont.

Definition at line 1354 of file GfxFont.cc.

                                                                         {
  CID cid;
  double w, h, vx, vy;
  int n, a, b, m;

  if (!cMap) {
    *code = 0;
    *uLen = 0;
    *dx = *dy = 0;
    return 1;
  }

  *code = (CharCode)(cid = cMap->getCID(s, len, &n));
  if (ctu) {
    *uLen = ctu->mapToUnicode(cid, u, uSize);
  } else {
    *uLen = 0;
  }

  // horizontal
  if (cMap->getWMode() == 0) {
    w = widths.defWidth;
    h = vx = vy = 0;
    if (widths.nExceps > 0 && cid >= widths.exceps[0].first) {
      a = 0;
      b = widths.nExceps;
      // invariant: widths.exceps[a].first <= cid < widths.exceps[b].first
      while (b - a > 1) {
       m = (a + b) / 2;
       if (widths.exceps[m].first <= cid) {
         a = m;
       } else {
         b = m;
       }
      }
      if (cid <= widths.exceps[a].last) {
       w = widths.exceps[a].width;
      }
    }

  // vertical
  } else {
    w = 0;
    h = widths.defHeight;
    vx = widths.defWidth / 2;
    vy = widths.defVY;
    if (widths.nExcepsV > 0 && cid >= widths.excepsV[0].first) {
      a = 0;
      b = widths.nExcepsV;
      // invariant: widths.excepsV[a].first <= cid < widths.excepsV[b].first
      while (b - a > 1) {
       m = (a + b) / 2;
       if (widths.excepsV[m].last <= cid) {
         a = m;
       } else {
         b = m;
       }
      }
      if (cid <= widths.excepsV[a].last) {
       h = widths.excepsV[a].height;
       vx = widths.excepsV[a].vx;
       vy = widths.excepsV[a].vy;
      }
    }
  }

  *dx = w;
  *dy = h;
  *ox = vx;
  *oy = vy;

  return n;
}

Here is the call graph for this function:

GString* GfxFont::getOrigName ( ) [inline, inherited]

Definition at line 110 of file GfxFont.h.

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

Definition at line 97 of file GfxFont.h.

{ return tag; }

Here is the caller graph for this function:

Definition at line 1434 of file GfxFont.cc.

                                            {
  if (ctu) {
    ctu->incRefCnt();
  }
  return ctu;
}

Here is the call graph for this function:

GfxFontType GfxFont::getType ( ) [inline, inherited]

Definition at line 113 of file GfxFont.h.

{ return type; }

Here is the caller graph for this function:

int GfxCIDFont::getWMode ( ) [virtual]

Reimplemented from GfxFont.

Definition at line 1430 of file GfxFont.cc.

                         {
  return cMap ? cMap->getWMode() : 0;
}

Here is the call graph for this function:

GBool GfxFont::isBold ( ) [inline, inherited]

Definition at line 134 of file GfxFont.h.

{ return flags & fontBold; }

Here is the caller graph for this function:

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

Reimplemented from GfxFont.

Definition at line 259 of file GfxFont.h.

{ return gTrue; }
GBool GfxFont::isFixedWidth ( ) [inline, inherited]

Definition at line 130 of file GfxFont.h.

{ return flags & fontFixedWidth; }

Here is the caller graph for this function:

GBool GfxFont::isItalic ( ) [inline, inherited]

Definition at line 133 of file GfxFont.h.

{ return flags & fontItalic; }

Here is the caller graph for this function:

GBool GfxFont::isOk ( ) [inline, inherited]

Definition at line 94 of file GfxFont.h.

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

Definition at line 131 of file GfxFont.h.

{ return flags & fontSerif; }

Here is the caller graph for this function:

GBool GfxFont::isSymbolic ( ) [inline, inherited]

Definition at line 132 of file GfxFont.h.

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

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, inherited]

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 
) [inherited]

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) [inherited]

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, inherited]

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, inherited]

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, inherited]

Definition at line 182 of file GfxFont.h.

Definition at line 284 of file GfxFont.h.

Definition at line 286 of file GfxFont.h.

CMap* GfxCIDFont::cMap [private]

Definition at line 281 of file GfxFont.h.

Definition at line 282 of file GfxFont.h.

double GfxFont::descent [protected, inherited]

Definition at line 183 of file GfxFont.h.

Ref GfxFont::embFontID [protected, inherited]

Definition at line 177 of file GfxFont.h.

GString* GfxFont::embFontName [protected, inherited]

Definition at line 176 of file GfxFont.h.

GString* GfxFont::extFontFile [protected, inherited]

Definition at line 178 of file GfxFont.h.

int GfxFont::flags [protected, inherited]

Definition at line 175 of file GfxFont.h.

double GfxFont::fontBBox[4] [protected, inherited]

Definition at line 180 of file GfxFont.h.

double GfxFont::fontMat[6] [protected, inherited]

Definition at line 179 of file GfxFont.h.

Ref GfxFont::id [protected, inherited]

Definition at line 171 of file GfxFont.h.

double GfxFont::missingWidth [protected, inherited]

Definition at line 181 of file GfxFont.h.

GString* GfxFont::name [protected, inherited]

Definition at line 172 of file GfxFont.h.

GBool GfxFont::ok [protected, inherited]

Definition at line 184 of file GfxFont.h.

GString* GfxFont::origName [protected, inherited]

Definition at line 173 of file GfxFont.h.

GString* GfxFont::tag [protected, inherited]

Definition at line 170 of file GfxFont.h.

GfxFontType GfxFont::type [protected, inherited]

Definition at line 174 of file GfxFont.h.

Definition at line 283 of file GfxFont.h.


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