Back to index

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

#include <GfxFont.h>

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

List of all members.

Public Member Functions

 Gfx8BitFont (XRef *xref, char *tagA, Ref idA, GString *nameA, GfxFontType typeA, Dict *fontDict)
virtual ~Gfx8BitFont ()
virtual int getNextChar (char *s, int len, CharCode *code, Unicode *u, int uSize, int *uLen, double *dx, double *dy, double *ox, double *oy)
char ** getEncoding ()
CharCodeToUnicodegetToUnicode ()
char * getCharName (int code)
GBool getHasEncoding ()
GBool getUsesMacRomanEnc ()
double getWidth (Guchar c)
GushortgetCodeToGIDMap (FoFiTrueType *ff)
DictgetCharProcs ()
ObjectgetCharProc (int code, Object *proc)
DictgetResources ()
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)

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

char * enc [256]
char encFree [256]
CharCodeToUnicodectu
GBool hasEncoding
GBool usesMacRomanEnc
double widths [256]
Object charProcs
Object resources

Detailed Description

Definition at line 191 of file GfxFont.h.


Constructor & Destructor Documentation

Gfx8BitFont::Gfx8BitFont ( XRef xref,
char *  tagA,
Ref  idA,
GString nameA,
GfxFontType  typeA,
Dict fontDict 
)

Definition at line 398 of file GfxFont.cc.

                                                        :
  GfxFont(tagA, idA, nameA)
{
  BuiltinFont *builtinFont;
  char **baseEnc;
  GBool baseEncFromFontFile;
  char *buf;
  int len;
  FoFiType1 *ffT1;
  FoFiType1C *ffT1C;
  int code, code2;
  char *charName;
  GBool missing, hex;
  Unicode toUnicode[256];
  CharCodeToUnicode *utu, *ctu2;
  Unicode uBuf[8];
  double mul;
  int firstChar, lastChar;
  Gushort w;
  Object obj1, obj2, obj3;
  int n, i, a, b, m;

  type = typeA;
  ctu = NULL;

  // do font name substitution for various aliases of the Base 14 font
  // names
  if (name) {
    a = 0;
    b = sizeof(stdFontMap) / sizeof(StdFontMapEntry);
    // invariant: stdFontMap[a].altName <= name < stdFontMap[b].altName
    while (b - a > 1) {
      m = (a + b) / 2;
      if (name->cmp(stdFontMap[m].altName) >= 0) {
       a = m;
      } else {
       b = m;
      }
    }
    if (!name->cmp(stdFontMap[a].altName)) {
      name = new GString(stdFontMap[a].properName);
    }
  }

  // is it a built-in font?
  builtinFont = NULL;
  if (name) {
    for (i = 0; i < nBuiltinFonts; ++i) {
      if (!name->cmp(builtinFonts[i].name)) {
       builtinFont = &builtinFonts[i];
       break;
      }
    }
  }

  // default ascent/descent values
  if (builtinFont) {
    ascent = 0.001 * builtinFont->ascent;
    descent = 0.001 * builtinFont->descent;
    fontBBox[0] = 0.001 * builtinFont->bbox[0];
    fontBBox[1] = 0.001 * builtinFont->bbox[1];
    fontBBox[2] = 0.001 * builtinFont->bbox[2];
    fontBBox[3] = 0.001 * builtinFont->bbox[3];
  } else {
    ascent = 0.95;
    descent = -0.35;
    fontBBox[0] = fontBBox[1] = fontBBox[2] = fontBBox[3] = 0;
  }

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

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

  // get font matrix
  fontMat[0] = fontMat[3] = 1;
  fontMat[1] = fontMat[2] = fontMat[4] = fontMat[5] = 0;
  if (fontDict->lookup("FontMatrix", &obj1)->isArray()) {
    for (i = 0; i < 6 && i < obj1.arrayGetLength(); ++i) {
      if (obj1.arrayGet(i, &obj2)->isNum()) {
       fontMat[i] = obj2.getNum();
      }
      obj2.free();
    }
  }
  obj1.free();

  // get Type 3 bounding box, font definition, and resources
  if (type == fontType3) {
    if (fontDict->lookup("FontBBox", &obj1)->isArray()) {
      for (i = 0; i < 4 && i < obj1.arrayGetLength(); ++i) {
       if (obj1.arrayGet(i, &obj2)->isNum()) {
         fontBBox[i] = obj2.getNum();
       }
       obj2.free();
      }
    }
    obj1.free();
    if (!fontDict->lookup("CharProcs", &charProcs)->isDict()) {
      error(-1, "Missing or invalid CharProcs dictionary in Type 3 font");
      charProcs.free();
    }
    if (!fontDict->lookup("Resources", &resources)->isDict()) {
      resources.free();
    }
  }

  //----- build the font encoding -----

  // Encodings start with a base encoding, which can come from
  // (in order of priority):
  //   1. FontDict.Encoding or FontDict.Encoding.BaseEncoding
  //        - MacRoman / MacExpert / WinAnsi / Standard
  //   2. embedded or external font file
  //   3. default:
  //        - builtin --> builtin encoding
  //        - TrueType --> MacRomanEncoding
  //        - others --> StandardEncoding
  // and then add a list of differences (if any) from
  // FontDict.Encoding.Differences.

  // check FontDict for base encoding
  hasEncoding = gFalse;
  usesMacRomanEnc = gFalse;
  baseEnc = NULL;
  baseEncFromFontFile = gFalse;
  fontDict->lookup("Encoding", &obj1);
  if (obj1.isDict()) {
    obj1.dictLookup("BaseEncoding", &obj2);
    if (obj2.isName("MacRomanEncoding")) {
      hasEncoding = gTrue;
      usesMacRomanEnc = gTrue;
      baseEnc = macRomanEncoding;
    } else if (obj2.isName("MacExpertEncoding")) {
      hasEncoding = gTrue;
      baseEnc = macExpertEncoding;
    } else if (obj2.isName("WinAnsiEncoding")) {
      hasEncoding = gTrue;
      baseEnc = winAnsiEncoding;
    } else if (obj2.isName("StandardEncoding")) {
      hasEncoding = gTrue;
      baseEnc = standardEncoding;
    }
    obj2.free();
  } else if (obj1.isName("MacRomanEncoding")) {
    hasEncoding = gTrue;
    usesMacRomanEnc = gTrue;
    baseEnc = macRomanEncoding;
  } else if (obj1.isName("MacExpertEncoding")) {
    hasEncoding = gTrue;
    baseEnc = macExpertEncoding;
  } else if (obj1.isName("WinAnsiEncoding")) {
    hasEncoding = gTrue;
    baseEnc = winAnsiEncoding;
  } else if (obj1.isName("StandardEncoding")) {
    hasEncoding = gTrue;
    baseEnc = standardEncoding;
  }

  // check embedded or external font file for base encoding
  // (only for Type 1 fonts - trying to get an encoding out of a
  // TrueType font is a losing proposition)
  ffT1 = NULL;
  ffT1C = NULL;
  buf = NULL;
  if (type == fontType1 && (extFontFile || embFontID.num >= 0)) {
    if (extFontFile) {
      ffT1 = FoFiType1::load(extFontFile->getCString());
    } else {
      buf = readEmbFontFile(xref, &len);
      ffT1 = FoFiType1::make(buf, len);
    }
    if (ffT1) {
      if (ffT1->getName()) {
       if (embFontName) {
         delete embFontName;
       }
       embFontName = new GString(ffT1->getName());
      }
      if (!baseEnc) {
       baseEnc = ffT1->getEncoding();
       baseEncFromFontFile = gTrue;
      }
    }
  } else if (type == fontType1C && (extFontFile || embFontID.num >= 0)) {
    if (extFontFile) {
      ffT1C = FoFiType1C::load(extFontFile->getCString());
    } else {
      buf = readEmbFontFile(xref, &len);
      ffT1C = FoFiType1C::make(buf, len);
    }
    if (ffT1C) {
      if (ffT1C->getName()) {
       if (embFontName) {
         delete embFontName;
       }
       embFontName = new GString(ffT1C->getName());
      }
      if (!baseEnc) {
       baseEnc = ffT1C->getEncoding();
       baseEncFromFontFile = gTrue;
      }
    }
  }
  if (buf) {
    gfree(buf);
  }

  // get default base encoding
  if (!baseEnc) {
    if (builtinFont) {
      baseEnc = builtinFont->defaultBaseEnc;
      hasEncoding = gTrue;
    } else if (type == fontTrueType) {
      baseEnc = winAnsiEncoding;
    } else {
      baseEnc = standardEncoding;
    }
  }

  // copy the base encoding
  for (i = 0; i < 256; ++i) {
    enc[i] = baseEnc[i];
    if ((encFree[i] = baseEncFromFontFile) && enc[i]) {
      enc[i] = copyString(baseEnc[i]);
    }
  }

  // some Type 1C font files have empty encodings, which can break the
  // T1C->T1 conversion (since the 'seac' operator depends on having
  // the accents in the encoding), so we fill in any gaps from
  // StandardEncoding
  if (type == fontType1C && (extFontFile || embFontID.num >= 0) &&
      baseEncFromFontFile) {
    for (i = 0; i < 256; ++i) {
      if (!enc[i] && standardEncoding[i]) {
       enc[i] = standardEncoding[i];
       encFree[i] = gFalse;
      }
    }
  }

  // merge differences into encoding
  if (obj1.isDict()) {
    obj1.dictLookup("Differences", &obj2);
    if (obj2.isArray()) {
      hasEncoding = gTrue;
      code = 0;
      for (i = 0; i < obj2.arrayGetLength(); ++i) {
       obj2.arrayGet(i, &obj3);
       if (obj3.isInt()) {
         code = obj3.getInt();
       } else if (obj3.isName()) {
         if (code >= 0 && code < 256) {
           if (encFree[code]) {
             gfree(enc[code]);
           }
           enc[code] = copyString(obj3.getName());
           encFree[code] = gTrue;
         }
         ++code;
       } else {
         error(-1, "Wrong type in font encoding resource differences (%s)",
              obj3.getTypeName());
       }
       obj3.free();
      }
    }
    obj2.free();
  }
  obj1.free();
  if (ffT1) {
    delete ffT1;
  }
  if (ffT1C) {
    delete ffT1C;
  }

  //----- build the mapping to Unicode -----

  // pass 1: use the name-to-Unicode mapping table
  missing = hex = gFalse;
  for (code = 0; code < 256; ++code) {
    if ((charName = enc[code])) {
      if (!(toUnicode[code] = globalParams->mapNameToUnicode(charName)) &&
         strcmp(charName, ".notdef")) {
       // if it wasn't in the name-to-Unicode table, check for a
       // name that looks like 'Axx' or 'xx', where 'A' is any letter
       // and 'xx' is two hex digits
       if ((strlen(charName) == 3 &&
            isalpha(charName[0]) &&
            isxdigit(charName[1]) && isxdigit(charName[2]) &&
            ((charName[1] >= 'a' && charName[1] <= 'f') ||
             (charName[1] >= 'A' && charName[1] <= 'F') ||
             (charName[2] >= 'a' && charName[2] <= 'f') ||
             (charName[2] >= 'A' && charName[2] <= 'F'))) ||
           (strlen(charName) == 2 &&
            isxdigit(charName[0]) && isxdigit(charName[1]) &&
            ((charName[0] >= 'a' && charName[0] <= 'f') ||
             (charName[0] >= 'A' && charName[0] <= 'F') ||
             (charName[1] >= 'a' && charName[1] <= 'f') ||
             (charName[1] >= 'A' && charName[1] <= 'F')))) {
         hex = gTrue;
       }
       missing = gTrue;
      }
    } else {
      toUnicode[code] = 0;
    }
  }

  // pass 2: try to fill in the missing chars, looking for names of
  // the form 'Axx', 'xx', 'Ann', 'ABnn', or 'nn', where 'A' and 'B'
  // are any letters, 'xx' is two hex digits, and 'nn' is 2-4
  // decimal digits
  if (missing && globalParams->getMapNumericCharNames()) {
    for (code = 0; code < 256; ++code) {
      if ((charName = enc[code]) && !toUnicode[code] &&
         strcmp(charName, ".notdef")) {
       n = strlen(charName);
       code2 = -1;
       if (hex && n == 3 && isalpha(charName[0]) &&
           isxdigit(charName[1]) && isxdigit(charName[2])) {
         sscanf(charName+1, "%x", &code2);
       } else if (hex && n == 2 &&
                 isxdigit(charName[0]) && isxdigit(charName[1])) {
         sscanf(charName, "%x", &code2);
       } else if (!hex && n >= 2 && n <= 4 &&
                 isdigit(charName[0]) && isdigit(charName[1])) {
         code2 = atoi(charName);
       } else if (n >= 3 && n <= 5 &&
                 isdigit(charName[1]) && isdigit(charName[2])) {
         code2 = atoi(charName+1);
       } else if (n >= 4 && n <= 6 &&
                 isdigit(charName[2]) && isdigit(charName[3])) {
         code2 = atoi(charName+2);
       }
       if (code2 >= 0 && code2 <= 0xff) {
         toUnicode[code] = (Unicode)code2;
       }
      }
    }
  }

  // construct the char code -> Unicode mapping object
  ctu = CharCodeToUnicode::make8BitToUnicode(toUnicode);

  // merge in a ToUnicode CMap, if there is one -- this overwrites
  // existing entries in ctu, i.e., the ToUnicode CMap takes
  // precedence, but the other encoding info is allowed to fill in any
  // holes
  readToUnicodeCMap(fontDict, 8, ctu);

  // look for a Unicode-to-Unicode mapping
  if (name && (utu = globalParams->getUnicodeToUnicode(name))) {
    for (i = 0; i < 256; ++i) {
      toUnicode[i] = 0;
    }
    ctu2 = CharCodeToUnicode::make8BitToUnicode(toUnicode);
    for (i = 0; i < 256; ++i) {
      n = ctu->mapToUnicode((CharCode)i, uBuf, 8);
      if (n >= 1) {
       n = utu->mapToUnicode((CharCode)uBuf[0], uBuf, 8);
       if (n >= 1) {
         ctu2->setMapping((CharCode)i, uBuf, n);
       }
      }
    }
    utu->decRefCnt();
    delete ctu;
    ctu = ctu2;
  }

  //----- get the character widths -----

  // initialize all widths
  for (code = 0; code < 256; ++code) {
    widths[code] = missingWidth * 0.001;
  }

  // use widths from font dict, if present
  fontDict->lookup("FirstChar", &obj1);
  firstChar = obj1.isInt() ? obj1.getInt() : 0;
  obj1.free();
  if (firstChar < 0 || firstChar > 255) {
    firstChar = 0;
  }
  fontDict->lookup("LastChar", &obj1);
  lastChar = obj1.isInt() ? obj1.getInt() : 255;
  obj1.free();
  if (lastChar < 0 || lastChar > 255) {
    lastChar = 255;
  }
  mul = (type == fontType3) ? fontMat[0] : 0.001;
  fontDict->lookup("Widths", &obj1);
  if (obj1.isArray()) {
    flags |= fontFixedWidth;
    if (obj1.arrayGetLength() < lastChar - firstChar + 1) {
      lastChar = firstChar + obj1.arrayGetLength() - 1;
    }
    for (code = firstChar; code <= lastChar; ++code) {
      obj1.arrayGet(code - firstChar, &obj2);
      if (obj2.isNum()) {
       widths[code] = obj2.getNum() * mul;
       if (widths[code] != widths[firstChar]) {
         flags &= ~fontFixedWidth;
       }
      }
      obj2.free();
    }

  // use widths from built-in font
  } else if (builtinFont) {
    // this is a kludge for broken PDF files that encode char 32
    // as .notdef
    if (builtinFont->widths->getWidth("space", &w)) {
      widths[32] = 0.001 * w;
    }
    for (code = 0; code < 256; ++code) {
      if (enc[code] && builtinFont->widths->getWidth(enc[code], &w)) {
       widths[code] = 0.001 * w;
      }
    }

  // couldn't find widths -- use defaults 
  } else {
    // this is technically an error -- the Widths entry is required
    // for all but the Base-14 fonts -- but certain PDF generators
    // apparently don't include widths for Arial and TimesNewRoman
    if (isFixedWidth()) {
      i = 0;
    } else if (isSerif()) {
      i = 8;
    } else {
      i = 4;
    }
    if (isBold()) {
      i += 2;
    }
    if (isItalic()) {
      i += 1;
    }
    builtinFont = builtinFontSubst[i];
    // this is a kludge for broken PDF files that encode char 32
    // as .notdef
    if (builtinFont->widths->getWidth("space", &w)) {
      widths[32] = 0.001 * w;
    }
    for (code = 0; code < 256; ++code) {
      if (enc[code] && builtinFont->widths->getWidth(enc[code], &w)) {
       widths[code] = 0.001 * w;
      }
    }
  }
  obj1.free();

  ok = gTrue;
}

Definition at line 859 of file GfxFont.cc.

                          {
  int i;

  for (i = 0; i < 256; ++i) {
    if (encFree[i] && enc[i]) {
      gfree(enc[i]);
    }
  }
  ctu->decRefCnt();
  if (charProcs.isDict()) {
    charProcs.free();
  }
  if (resources.isDict()) {
    resources.free();
  }
}

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; }
char* Gfx8BitFont::getCharName ( int  code) [inline]

Definition at line 210 of file GfxFont.h.

{ return enc[code]; }
Object * Gfx8BitFont::getCharProc ( int  code,
Object proc 
)

Definition at line 1011 of file GfxFont.cc.

                                                       {
  if (enc[code] && charProcs.isDict()) {
    charProcs.dictLookup(enc[code], proc);
  } else {
    proc->initNull();
  }
  return proc;
}

Here is the call graph for this function:

Definition at line 1007 of file GfxFont.cc.

                                {
  return charProcs.isDict() ? charProcs.getDict() : (Dict *)NULL;
}

Here is the call graph for this function:

Definition at line 893 of file GfxFont.cc.

                                                      {
  Gushort *map;
  int cmapPlatform, cmapEncoding;
  int unicodeCmap, macRomanCmap, msSymbolCmap, cmap;
  GBool useMacRoman, useUnicode;
  char *charName;
  Unicode u;
  int code, i, n;

  map = (Gushort *)gmalloc(256 * sizeof(Gushort));
  for (i = 0; i < 256; ++i) {
    map[i] = 0;
  }

  // To match up with the Adobe-defined behaviour, we choose a cmap
  // like this:
  // 1. If the PDF font has an encoding:
  //    1a. If the PDF font specified MacRomanEncoding and the
  //        TrueType font has a Macintosh Roman cmap, use it, and
  //        reverse map the char names through MacRomanEncoding to
  //        get char codes.
  //    1b. If the TrueType font has a Microsoft Unicode cmap or a
  //        non-Microsoft Unicode cmap, use it, and use the Unicode
  //        indexes, not the char codes.
  //    1c. If the PDF font is symbolic and the TrueType font has a
  //        Microsoft Symbol cmap, use it, and use char codes
  //        directly (possibly with an offset of 0xf000).
  //    1d. If the TrueType font has a Macintosh Roman cmap, use it,
  //        as in case 1a.
  // 2. If the PDF font does not have an encoding:
  //    2a. If the TrueType font has a Macintosh Roman cmap, use it,
  //        and use char codes directly (possibly with an offset of
  //        0xf000).
  //    2b. If the TrueType font has a Microsoft Symbol cmap, use it,
  //        and use char codes directly (possible with an offset of
  //        0xf000).
  // 3. If none of these rules apply, use the first cmap and hope for
  //    the best (this shouldn't happen).
  unicodeCmap = macRomanCmap = msSymbolCmap = -1;
  for (i = 0; i < ff->getNumCmaps(); ++i) {
    cmapPlatform = ff->getCmapPlatform(i);
    cmapEncoding = ff->getCmapEncoding(i);
    if ((cmapPlatform == 3 && cmapEncoding == 1) ||
       cmapPlatform == 0) {
      unicodeCmap = i;
    } else if (cmapPlatform == 1 && cmapEncoding == 0) {
      macRomanCmap = i;
    } else if (cmapPlatform == 3 && cmapEncoding == 0) {
      msSymbolCmap = i;
    }
  }
  cmap = 0;
  useMacRoman = gFalse;
  useUnicode = gFalse;
  if (hasEncoding) {
    if (usesMacRomanEnc && macRomanCmap >= 0) {
      cmap = macRomanCmap;
      useMacRoman = gTrue;
    } else if (unicodeCmap >= 0) {
      cmap = unicodeCmap;
      useUnicode = gTrue;
    } else if ((flags & fontSymbolic) && msSymbolCmap >= 0) {
      cmap = msSymbolCmap;
    } else if (macRomanCmap >= 0) {
      cmap = macRomanCmap;
      useMacRoman = gTrue;
    }
  } else {
    if (macRomanCmap >= 0) {
      cmap = macRomanCmap;
    } else if (msSymbolCmap >= 0) {
      cmap = msSymbolCmap;
    }
  }

  // reverse map the char names through MacRomanEncoding, then map the
  // char codes through the cmap
  if (useMacRoman) {
    for (i = 0; i < 256; ++i) {
      if ((charName = enc[i])) {
       if ((code = globalParams->getMacRomanCharCode(charName))) {
         map[i] = ff->mapCodeToGID(cmap, code);
       }
      }
    }

  // map Unicode through the cmap
  } else if (useUnicode) {
    for (i = 0; i < 256; ++i) {
      if ((n = ctu->mapToUnicode((CharCode)i, &u, 1))) {
       map[i] = ff->mapCodeToGID(cmap, u);
      }
    }

  // map the char codes through the cmap, possibly with an offset of
  // 0xf000
  } else {
    for (i = 0; i < 256; ++i) {
      if (!(map[i] = ff->mapCodeToGID(cmap, i))) {
       map[i] = ff->mapCodeToGID(cmap, 0xf000 + i);
      }
    }
  }

  // try the TrueType 'post' table to handle any unmapped characters
  for (i = 0; i < 256; ++i) {
    if (!map[i] && (charName = enc[i])) {
      map[i] = (Gushort)(int)ff->mapNameToGID(charName);
    }
  }

  return map;
}

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; }
char** Gfx8BitFont::getEncoding ( ) [inline]

Definition at line 204 of file GfxFont.h.

{ return enc; }
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:

Definition at line 213 of file GfxFont.h.

{ return hasEncoding; }
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 Gfx8BitFont::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 876 of file GfxFont.cc.

                                                                          {
  CharCode c;

  *code = c = (CharCode)(*s & 0xff);
  *uLen = ctu->mapToUnicode(c, u, uSize);
  *dx = widths[c];
  *dy = *ox = *oy = 0;
  return 1;
}

Here is the call graph for this function:

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

Definition at line 110 of file GfxFont.h.

{ return origName; }

Definition at line 1020 of file GfxFont.cc.

                                {
  return resources.isDict() ? resources.getDict() : (Dict *)NULL;
}

Here is the call graph for this function:

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 888 of file GfxFont.cc.

                                             {
  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:

Definition at line 216 of file GfxFont.h.

{ return usesMacRomanEnc; }
double Gfx8BitFont::getWidth ( Guchar  c) [inline]

Definition at line 219 of file GfxFont.h.

{ return widths[c]; }
virtual int GfxFont::getWMode ( ) [inline, virtual, inherited]

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

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

Reimplemented in GfxCIDFont.

Definition at line 114 of file GfxFont.h.

{ return gFalse; }

Here is the caller graph for this function:

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 243 of file GfxFont.h.

Definition at line 239 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.

char* Gfx8BitFont::enc[256] [private]

Definition at line 236 of file GfxFont.h.

char Gfx8BitFont::encFree[256] [private]

Definition at line 237 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.

Definition at line 240 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.

Definition at line 244 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 241 of file GfxFont.h.

double Gfx8BitFont::widths[256] [private]

Definition at line 242 of file GfxFont.h.


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