Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
nsAFMObject Class Reference

#include <nsAFMObject.h>

List of all members.

Public Member Functions

 nsAFMObject ()
 
Construct and AFMObject 2/26/99 dwc
virtual ~nsAFMObject ()
 
delete an AFMObject 2/26/99 dwc
void Init (nscoord aFontHeight)
 
Initialize an AFM object.
PRBool AFM_ReadFile (const nsFont &aFontName)
 
Read in and parse and AFM file 2/26/99 dwc
PRInt16 CheckBasicFonts (const nsFont &aFont, PRBool aPrimaryOnly=PR_FALSE)
 
Check to see if this font is one of our basic fonts, if so create an AFMObject from it 2/26/99 dwc
PRInt16 CreateSubstituteFont (const nsFont &aFont)
 
Create a substitute Font 2/26/99 dwc
void SetFontSize (nscoord aFontHeight)
 
Set the font size, which is used to calculate the distances for the font 9/30/2003 kherron
void GetStringWidth (const PRUnichar *aString, nscoord &aWidth, nscoord aLength)
 
Calculate the width of a unicharacter string 2/26/99 dwc
void GetStringWidth (const char *aString, nscoord &aWidth, nscoord aLength)
 
Calculate the width of a C style string 2/26/99 dwc
void WriteFontHeaderInformation (FILE *aOutFile)
 
Write out the AFMFontInformation Header from the currently parsed AFM file, this will write a ASCII file so you can use it as a head if need be.
void WriteFontCharInformation (FILE *aOutFile)
 
Write out the AFMFontInformation character data from the currently parsed AFM file, this will write a ASCII file so you can use it as a head if need be.

Public Attributes

AFMFontInformation * mPSFontInfo

Protected Member Functions

void GetKey (AFMKey *aTheKey)
 
Get a Keyword in the AFM file being parsed 2/26/99 dwc
PRInt32 GetToken (void)
 
Get a token from the AFM file 2/26/99 dwc
PRInt32 MatchKey (char *aKey)
 
For a given token, find the keyword it represents 2/26/99 dwc
PRInt32 GetLine (void)
 
Get a line from the currently parsed file 2/26/99 dwc
char * GetAFMString (void)
 
Get a string from the currently parsed file 2/26/99 dwc
char * GetAFMName (void)
 
Get a word from the currently parsed file 2/26/99 dwc
void GetAFMInt (PRInt32 *aInt)
 
Get an integer from the currently parsed file 2/26/99 dwc
void GetAFMNumber (double *aFloat)
 
Get a floating point number from the currently parsed file 2/26/99 dwc
void GetAFMNumber (float *aFloat)
void GetAFMBool (PRBool *aBool)
 
Get a boolean from the currently parsed file 2/26/99 dwc
void ReadCharMetrics (AFMFontInformation *aFontInfo, PRInt32 aNumCharacters)
 
Read in the AFMFontInformation from the currently parsed AFM file 2/26/99 dwc

Protected Attributes

FILEmAFMFile
char mToken [256]
nscoord mFontHeight

Detailed Description

Definition at line 228 of file nsAFMObject.h.


Constructor & Destructor Documentation


Construct and AFMObject 2/26/99 dwc


See documentation in nsAFMParser.h 2/25/99 dwc

Definition at line 208 of file nsAFMObject.cpp.


delete an AFMObject 2/26/99 dwc


See documentation in nsAFMParser.h 2/25/99 dwc

Definition at line 217 of file nsAFMObject.cpp.

{

  if(mPSFontInfo->mAFMCharMetrics){
    delete [] mPSFontInfo->mAFMCharMetrics;
  }

  if(mPSFontInfo){
    delete mPSFontInfo;
  }
}

Member Function Documentation


Read in and parse and AFM file 2/26/99 dwc


See documentation in nsAFMParser.h 2/25/99 dwc

Parameters:
aFontName-- The name of the font we want to read in
Returns:
VOID

Definition at line 377 of file nsAFMObject.cpp.

{
PRBool  done=PR_FALSE;
PRBool  success = PR_FALSE;
PRBool  bvalue;
AFMKey  key;
double  value;
PRInt32 ivalue;
char* AFMFileName= ToNewUTF8String(aFontName.name); // file we will open

  if(nsnull == AFMFileName) 
    return (success);

    if((0==strcmp(AFMFileName,"..")) || (0==strcmp(AFMFileName,"."))) {
      Recycle(AFMFileName);
      return (success);
    }

   // Open the file
  mAFMFile = fopen((const char *)AFMFileName,"r");
  Recycle(AFMFileName);

  if(nsnull != mAFMFile) {
    // create the structure to put the information in
    mPSFontInfo = new AFMFontInformation;
    memset(mPSFontInfo,0,sizeof(AFMFontInformation));

    // Check for valid AFM file
    GetKey(&key);
    if(key == kStartFontMetrics){
      GetAFMNumber(&mPSFontInfo->mFontVersion);

      while(!done){
        GetKey(&key);
        switch (key){
          case kComment:
            GetLine();
            break;
          case kStartFontMetrics:
            GetAFMNumber(&mPSFontInfo->mFontVersion);
            break;
          case kEndFontMetrics:
            done = PR_TRUE;
            break;
          case kStartCompFontMetrics:
          case kEndCompFontMetrics:
          case kStartMasterFontMetrics:
          case kEndMasterFontMetrics:
            break;
          case kFontName:
            mPSFontInfo->mFontName = GetAFMString();
            break;
          case kFullName:
            mPSFontInfo->mFullName = GetAFMString();
            break;
          case kFamilyName:
            mPSFontInfo->mFamilyName = GetAFMString();
            break;
          case kWeight:
            mPSFontInfo->mWeight = GetAFMString();
            break;
          case kFontBBox:
            GetAFMNumber(&mPSFontInfo->mFontBBox_llx);
            GetAFMNumber(&mPSFontInfo->mFontBBox_lly);
            GetAFMNumber(&mPSFontInfo->mFontBBox_urx);
            GetAFMNumber(&mPSFontInfo->mFontBBox_ury);
            break;
          case kVersion:
            mPSFontInfo->mVersion = GetAFMString();
            break;
               case kNotice:
                 mPSFontInfo->mNotice = GetAFMString();
            // we really dont want to keep this around...
            delete [] mPSFontInfo->mNotice;
            mPSFontInfo->mNotice = 0;
                 break;
               case kEncodingScheme:
                 mPSFontInfo->mEncodingScheme = GetAFMString();
                 break;
               case kMappingScheme:
                 GetAFMInt(&mPSFontInfo->mMappingScheme);
                 break;
               case kEscChar:
                 GetAFMInt(&mPSFontInfo->mEscChar);
                 break;
               case kCharacterSet:
                 mPSFontInfo->mCharacterSet = GetAFMString();
                 break;
               case kCharacters:
                 GetAFMInt(&mPSFontInfo->mCharacters);
                 break;
               case kIsBaseFont:
                 GetAFMBool (&mPSFontInfo->mIsBaseFont);
                 break;
               case kVVector:
                 GetAFMNumber(&mPSFontInfo->mVVector_0);
                 GetAFMNumber(&mPSFontInfo->mVVector_1);
                 break;
               case kIsFixedV:
                 GetAFMBool (&mPSFontInfo->mIsFixedV);
                 break;
               case kCapHeight:
                 GetAFMNumber(&mPSFontInfo->mCapHeight);
                 break;
               case kXHeight:
                 GetAFMNumber(&mPSFontInfo->mXHeight);
                 break;
               case kAscender:
                 GetAFMNumber(&mPSFontInfo->mAscender);
                 break;
               case kDescender:
                 GetAFMNumber(&mPSFontInfo->mDescender);
                 break;
               case kStartDirection:
                 GetAFMInt(&ivalue);
                 break;
               case kUnderlinePosition:
                 GetAFMNumber(&mPSFontInfo->mUnderlinePosition);
                 break;
               case kUnderlineThickness:
                 GetAFMNumber(&mPSFontInfo->mUnderlineThickness);
                 break;
               case kItalicAngle:
                 GetAFMNumber(&value);
                 break;
               case kCharWidth:
                 GetAFMNumber(&value);   // x
                 GetAFMNumber(&value);   // y
                 break;
               case kIsFixedPitch:
                 GetAFMBool (&bvalue);
                 break;
               case kEndDirection:
                 break;
               case kStartCharMetrics:
                 GetAFMInt(&mPSFontInfo->mNumCharacters);     // number of charaters that follow
            mPSFontInfo->mAFMCharMetrics = new AFMscm[mPSFontInfo->mNumCharacters];
            memset(mPSFontInfo->mAFMCharMetrics,0,sizeof(AFMscm)*mPSFontInfo->mNumCharacters);
                 ReadCharMetrics (mPSFontInfo,mPSFontInfo->mNumCharacters);
                 break;
               case kStartKernData:
                 break;
               case kStartKernPairs:
            break;
          default:
            break;
        }
      }
    }
  fclose(mAFMFile);
  success = PR_TRUE;
  } else {
  // put in default AFM data, can't find the correct AFM file
  //memcpy(mPSFontInfo,&HelveticaAFM,sizeof(AFMFontInformation));
 // mPSFontInfo->mAFMCharMetrics = new AFMscm[mPSFontInfo->mNumCharacters];
  //memset(mPSFontInfo->mAFMCharMetrics,0,sizeof(AFMscm)*mPSFontInfo->mNumCharacters);
  //memcpy(mPSFontInfo->mAFMCharMetrics,AFMHelveticaChars,HelveticaAFM.mNumCharacters*sizeof(AFMscm));
  }

  return(success);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt16 nsAFMObject::CheckBasicFonts ( const nsFont aFont,
PRBool  aPrimaryOnly = PR_FALSE 
)


Check to see if this font is one of our basic fonts, if so create an AFMObject from it 2/26/99 dwc


See documentation in nsAFMParser.h 2/25/99 dwc

Parameters:
aFont-- The font to be constructed (family name, weight, style)
aPrimaryOnly-- if true, only looking for the first font name in aFontName
Returns:
-- the font index into our table if a native font was found, -1 otherwise

Definition at line 246 of file nsAFMObject.cpp.

{
PRInt16     ourfont = -1;
PRInt32     i,curIndex,score;
nsAutoString    psfontname;

  // have to find the correct fontfamily, weight and style
  psfontname = aFont.name;
  
  // look in the font table for one of the fonts in the passed in list
  for(i=0,curIndex=-1;i<NUM_AFM_FONTS;i++){
    gSubstituteFonts[i].mIndex = psfontname.RFind((const char*)gSubstituteFonts[i].mFamily,PR_TRUE);

    // if a font was found matching this criteria
    if((gSubstituteFonts[i].mIndex==0) || (!aPrimaryOnly && gSubstituteFonts[i].mIndex>=0)){
      // give it a score
      score = abs(PRInt32(aFont.weight)-PRInt32(gSubstituteFonts[i].mWeight));
      score+= abs(PRInt32(aFont.style)-PRInt32(gSubstituteFonts[i].mStyle));
      if(score == 0){
        curIndex = i;
        break;
      }
      gSubstituteFonts[i].mIndex = score;
    }
  }
  
  // if its ok to look for the second best, and we did not find a perfect match
  score = 32000;
  if((PR_FALSE == aPrimaryOnly)&&(curIndex !=0)) {
    for(i=0;i<NUM_AFM_FONTS;i++){
      if((gSubstituteFonts[i].mIndex>0) && (gSubstituteFonts[i].mIndex<score)){
        score = gSubstituteFonts[i].mIndex;
        curIndex = i;
      }   
    }
  }


  if(curIndex>=0){
    mPSFontInfo = new AFMFontInformation;
    memset(mPSFontInfo,0,sizeof(AFMFontInformation));
    
    memcpy(mPSFontInfo,(gSubstituteFonts[curIndex].mFontInfo),sizeof(AFMFontInformation));
    mPSFontInfo->mAFMCharMetrics = new AFMscm[mPSFontInfo->mNumCharacters];
    memset(mPSFontInfo->mAFMCharMetrics,0,sizeof(AFMscm)*mPSFontInfo->mNumCharacters);
    memcpy(mPSFontInfo->mAFMCharMetrics,gSubstituteFonts[curIndex].mCharInfo,gSubstituteFonts[curIndex].mFontInfo->mNumCharacters*sizeof(AFMscm));
    ourfont = curIndex;
  }
  
  return ourfont;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Create a substitute Font 2/26/99 dwc


See documentation in nsAFMParser.h 2/25/99 dwc

Parameters:
aFont-- The font to create a substitute for (family name, weight, style)
Returns:
-- the font index into our table if a native font was found, -1 otherwise

Definition at line 318 of file nsAFMObject.cpp.

{
PRInt16     ourfont = 0;
PRUint32    i = gNumSubstituteMap;

  // Get Font List
  nsVoidArray fontNames;
  // Iterate over the list of names using the callback mechanism of nsFont...
  aFontName.EnumerateFamilies(GenericFontEnumCallback, &fontNames); // ignore return value

  PRInt32 k;
  PRBool found = PR_FALSE;
  for (k=0;k<fontNames.Count() && !found;k++) {
    char * fontName = (char*)fontNames[k];
    for(i=0;i<gNumSubstituteMap;i++) {
      //printf("Looking for Name[%s] Checking [%s]\n", NS_LossyConvertUCS2toASCII(name).get(),gSubstituteMap[i].name);
      if(!nsCRT::strcasecmp(fontName, gSubstituteMap[i].name) && 
         (aFontName.style != NS_FONT_STYLE_NORMAL)== gSubstituteMap[i].italic &&
         NS_IS_BOLD(aFontName.weight) == gSubstituteMap[i].bold) {
        ourfont = gSubstituteMap[i].index;
        found = PR_TRUE;
        break;
      }
    }
  } // for

  for (k=0;k<fontNames.Count();k++) {
    nsMemory::Free((char*)fontNames[k]);
  }

  // no matches in the substitution table -- default to times
  if(i == gNumSubstituteMap){

#ifdef DEBUG
    printf(" NO FONT WAS FOUND Name[%s]\n", NS_LossyConvertUCS2toASCII(aFontName.name).get());
#endif
    if(aFontName.style == NS_FONT_STYLE_NORMAL){
      ourfont = NS_IS_BOLD(aFontName.weight) ? 1 : 0;
    } else {
      ourfont = NS_IS_BOLD(aFontName.weight) ? 2 : 3;
    }
  }

  mPSFontInfo = new AFMFontInformation;
  memset(mPSFontInfo,0,sizeof(AFMFontInformation));

  // put in default AFM data, can't find the correct AFM file
  memcpy(mPSFontInfo,gSubstituteFonts[ourfont].mFontInfo,sizeof(AFMFontInformation));
  mPSFontInfo->mAFMCharMetrics = new AFMscm[mPSFontInfo->mNumCharacters];
  memset(mPSFontInfo->mAFMCharMetrics,0,sizeof(AFMscm)*mPSFontInfo->mNumCharacters);
  memcpy(mPSFontInfo->mAFMCharMetrics,gSubstituteFonts[ourfont].mCharInfo,Times_RomanAFM.mNumCharacters*sizeof(AFMscm));
  return ourfont;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAFMObject::GetAFMBool ( PRBool aBool) [protected]


Get a boolean from the currently parsed file 2/26/99 dwc


See documentation in nsAFMParser.h 2/26/99 dwc

Parameters:
--The current boolean found is passed back

Definition at line 679 of file nsAFMObject.cpp.

{

  GetToken();
  if (strcmp (mToken, "true") == 0) {
         *aBool = PR_TRUE;
  }else if(strcmp (mToken, "false")){
    *aBool = PR_FALSE;
  }else {
    *aBool = PR_FALSE;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAFMObject::GetAFMInt ( PRInt32 aInt) [inline, protected]


Get an integer from the currently parsed file 2/26/99 dwc

Returns:
-- the current integer

Definition at line 372 of file nsAFMObject.h.

{GetToken();*aInt = atoi (mToken);}

Here is the call graph for this function:

Here is the caller graph for this function:

char * nsAFMObject::GetAFMName ( void  ) [protected]


Get a word from the currently parsed file 2/26/99 dwc


See documentation in nsAFMParser.h 2/26/99 dwc

Returns:
-- a string with the name

Definition at line 813 of file nsAFMObject.cpp.

{
PRInt32 len;
char    *thestring;

  GetToken();
  len = strlen(mToken);
  thestring = new char[len+1];
  strcpy(thestring,mToken);
  return(thestring);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAFMObject::GetAFMNumber ( double *  aFloat) [inline, protected]


Get a floating point number from the currently parsed file 2/26/99 dwc

Returns:
-- the current floating point

Definition at line 379 of file nsAFMObject.h.

{GetToken();*aFloat = atof (mToken);}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAFMObject::GetAFMNumber ( float *  aFloat) [inline, protected]

Definition at line 380 of file nsAFMObject.h.

{GetToken();*aFloat = atof (mToken);}

Here is the call graph for this function:

char * nsAFMObject::GetAFMString ( void  ) [protected]


Get a string from the currently parsed file 2/26/99 dwc


See documentation in nsAFMParser.h 2/26/99 dwc

Returns:
-- the current string

Definition at line 796 of file nsAFMObject.cpp.

{
PRInt32 len;
char    *thestring;

  GetLine();
  len = strlen(mToken);
  thestring = new char[len+1];
  strcpy(thestring,mToken);
  return(thestring);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAFMObject::GetKey ( AFMKey aTheKey) [protected]


Get a Keyword in the AFM file being parsed 2/26/99 dwc


See documentation in nsAFMParser.h 2/26/99 dwc

Returns:
VOID

Definition at line 545 of file nsAFMObject.cpp.

{
PRInt32   key,len;

  while(1){
    len = GetToken(); 
    if(len>0) {
      key = MatchKey(mToken);
      if(key >=0){
        *aKey = (AFMKey)key;
        return;
      }

    GetLine(); // skip the entire line, and key
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsAFMObject::GetLine ( void  ) [protected]


Get a line from the currently parsed file 2/26/99 dwc


See documentation in nsAFMParser.h 2/26/99 dwc

Returns:
-- The current line

Definition at line 640 of file nsAFMObject.cpp.

{
PRInt32 i, ch;

  // Skip the leading whitespace. 
  while ((ch = getc (mAFMFile)) != EOF){
      if (!ISSPACE (ch))
        break;
  }

  if (ch == EOF)
    return 0;

  ungetc (ch, mAFMFile);

  // Read to the end of the line. 
  for (i = 0, ch = getc (mAFMFile);((PRUint32)i) < sizeof (mToken) - 1 && ch != EOF && ch != '\n';i++, ch = getc (mAFMFile)){
    mToken[i] = ch;
  }

  if (((PRUint32)i) >= sizeof (mToken) - 1){
    //parse_error (handle, AFM_ERROR_SYNTAX);
  }

  // Skip all trailing whitespace. 
  for (i--; i >= 0 && ISSPACE (mToken[i]); i--)
    ;
  i++;

  mToken[i] = '\0';

  return i;
}

Here is the caller graph for this function:

void nsAFMObject::GetStringWidth ( const PRUnichar aString,
nscoord aWidth,
nscoord  aLength 
)


Calculate the width of a unicharacter string 2/26/99 dwc


Calculate the width of the string.

Parameters:
aString- The unicharacter string to get the width for
aWidth- Where the width of the string will be put.
aLenth- The length of the passed in string
Returns:
VOID

9/30/2003 kherron

Parameters:
aStringThe source string aWidth Container for the resulting width aLength Number of characters in aString

Definition at line 862 of file nsAFMObject.cpp.

{
PRUint8   asciichar;
PRUnichar *cptr;
PRInt32   i ,fwidth,idx;
float     totallen=0.0f;

 //XXX This needs to get the aString converted to a normal cstring  DWC
 aWidth = 0;
 cptr = (PRUnichar*)aString;

  for(i=0;i<aLength;i++,cptr++){
    fwidth = 0;
    if (*cptr & 0xff00)
    {
      if (0x0400 == (*cptr & 0xff00)) { // Cyrillic
        fwidth = 600;
      } else {
        fwidth = 1056;
      }
    } else {
      // < 0x0100
      asciichar = (*cptr)&0x00ff;
      idx = asciichar-32;
      if(idx >= 0 )
        fwidth = (PRInt32)(mPSFontInfo->mAFMCharMetrics[idx].mW0x);
      else if (*cptr  == 0x0020) 
        fwidth = 1056;
    }

    totallen += fwidth;
  }

  // totallen is in 1/1000ths of a point for a one-point-high version of the
  // font. Scale by the desired font height (which is in twips).
  aWidth = NSToCoordRound((totallen * mFontHeight)/1000.0f);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAFMObject::GetStringWidth ( const char *  aString,
nscoord aWidth,
nscoord  aLength 
)


Calculate the width of a C style string 2/26/99 dwc


Calculate the width of the string.

Parameters:
aString- The C string to get the width for
aWidth- Where the width of the string will be put.
aLenth- The length of the passed in string

9/30/2003 kherron

Parameters:
aStringThe source string aWidth Container for the resulting width aLength Number of characters in aString

Definition at line 833 of file nsAFMObject.cpp.

{
char    *cptr;
PRInt32 i,idx,fwidth;
float   totallen=0.0f;

  // add up the length of the character widths, in floating to avoid roundoff
  aWidth = 0;
  cptr = (char*) aString;
  for(i=0;i<aLength;i++,cptr++){
    idx = *cptr-32;
    fwidth = (PRInt32)(mPSFontInfo->mAFMCharMetrics[idx].mW0x);
    totallen += fwidth;
  }

  // totallen is in 1/1000's of a point for a one-point-high version of the
  // font. Scale by the desired font height (which is in twips).
  aWidth = NSToCoordRound((totallen * mFontHeight)/1000.0f);
}

Here is the call graph for this function:

PRInt32 nsAFMObject::GetToken ( void  ) [protected]


Get a token from the AFM file 2/26/99 dwc


See documentation in nsAFMParser.h 2/26/99 dwc

Returns:
-- The found token

Definition at line 603 of file nsAFMObject.cpp.

{
PRInt32   ch;
PRInt32   i;
PRInt32   len;

  // skip leading whitespace
  while((ch=getc(mAFMFile)) != EOF) {
    if(!ISSPACE(ch))
      break;
  }

  if(ch == EOF)
    return 0;

  ungetc(ch,mAFMFile);

  // get name
  len = (PRInt32)sizeof(mToken);
  for(i=0,ch=getc(mAFMFile);i<len && ch!=EOF && !ISSPACE(ch);i++,ch=getc(mAFMFile)){
      mToken[i] = ch;
  }

  // is line longer than the AFM specifications
  if(((PRUint32)i)>=sizeof(mToken))
    return 0;

  mToken[i] = '\0';
  return i;
}

Here is the caller graph for this function:

void nsAFMObject::Init ( nscoord  aFontHeight)


Initialize an AFM object.

9/30/2003 kherron

Parameters:
aFontHeightFont height in twips
Returns:
VOID

9/30/2003 kherron

Parameters:
aFontHeightFont height in twips

Definition at line 235 of file nsAFMObject.cpp.

{
  // read the file asked for
  mFontHeight = aFontHeight;
}

Here is the caller graph for this function:

PRInt32 nsAFMObject::MatchKey ( char *  aKey) [protected]


For a given token, find the keyword it represents 2/26/99 dwc


See documentation in nsAFMParser.h 2/26/99 dwc

Returns:
-- The key found

Definition at line 568 of file nsAFMObject.cpp.

{
PRInt32 lower = 0;
PRInt32 upper = NUM_KEYS;
PRInt32 midpoint,cmpvalue;
PRBool  found = PR_FALSE;

  while((upper >=lower) && !found) {
    midpoint = (lower+upper)/2;
    if(keynames[midpoint].name == nsnull) {
      break;
    }
    cmpvalue = strcmp(aKey,keynames[midpoint].name);
    if(cmpvalue == 0){
      found = PR_TRUE;
    }else{
     if (cmpvalue <0){
        upper = midpoint-1;
      }else{
        lower = midpoint+1;
      }
    }
  }

  if(found)
    return keynames[midpoint].key;
  else
    return -1;
}

Here is the caller graph for this function:

void nsAFMObject::ReadCharMetrics ( AFMFontInformation *  aFontInfo,
PRInt32  aNumCharacters 
) [protected]


Read in the AFMFontInformation from the currently parsed AFM file 2/26/99 dwc


See documentation in nsAFMParser.h 2/26/99 dwc

Parameters:
aFontInfo-- The header structure to read the caracter info from
aNumCharacters-- The number of characters to look for

Definition at line 697 of file nsAFMObject.cpp.

{
PRInt32 i = 0,ivalue,first=1;
AFMscm  *cm = nsnull;
AFMKey  key;
PRBool  done = PR_FALSE;
double  notyet;
char    *name;

  while (done!=PR_TRUE && i<aNumCharacters){
    GetKey (&key);
    switch (key){
      case kC:
        if (first){
          first = 0;
        }else{
          i++;
        }
        if (i >= aNumCharacters){
          done = PR_TRUE;
          //parse_error (handle, AFM_ERROR_SYNTAX);
        }

        cm = &(aFontInfo->mAFMCharMetrics[i]);
        // character code
        GetAFMInt(&ivalue);          // character code
        cm->mCharacter_Code = ivalue;
        //if (cm->mCharacter_Code >= 0 && cm->mCharacter_Code <= 255)
          //font->encoding[cm->character_code] = cm;
        break;
      case kCH:
        break;
      case kWX:
      case kW0X:
        GetAFMNumber(&(cm->mW0x));
        cm->mW0y = 0.0;
        break;
      case kW1X:
        GetAFMNumber(&(cm->mW1x));
        cm->mW1y = 0.0;
        break;
      case kWY:
      case kW0Y:
        GetAFMNumber(&(cm->mW0y));
        cm->mW0x = 0.0;
        break;
      case kW1Y:
        GetAFMNumber(&(cm->mW1y));
        cm->mW1x = 0.0;
        break;
      case kW:
      case kW0:
        GetAFMNumber(&(cm->mW0x));
        GetAFMNumber(&(cm->mW0y));
        break;

      case kW1:
        GetAFMNumber(&(cm->mW1x));
        GetAFMNumber(&(cm->mW1y));
        break;
      case kVV:
        //GetAFMNumber(&(cm->mVv_x));
        //GetAFMNumber(&(cm->mVv_y));
        GetAFMNumber(&notyet);
        GetAFMNumber(&notyet);
        break;
      case kN:
        //cm->mName = GetAFMName();
        name = GetAFMName();
        delete [] name;
        break;

      case kB:
        GetAFMNumber(&(cm->mLlx));
        GetAFMNumber(&(cm->mLly));
        GetAFMNumber(&(cm->mUrx));
        GetAFMNumber(&(cm->mUry));
        break;
      case kL:
        // XXX Skip ligatures.
        GetLine ();
      break;

      case kEndCharMetrics:
        //  SYNTAX ERROR???
        done = PR_TRUE;
        break;
      default:
        break;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAFMObject::SetFontSize ( nscoord  aFontHeight) [inline]


Set the font size, which is used to calculate the distances for the font 9/30/2003 kherron

Parameters:
aFontHeight- The height of the font, in twips.
Returns:
VOID

Definition at line 284 of file nsAFMObject.h.

{ mFontHeight = aFontHeight; }


Write out the AFMFontInformation character data from the currently parsed AFM file, this will write a ASCII file so you can use it as a head if need be.


See documentation in nsAFMParser.h 3/05/99 dwc

3/09/99 dwc

Parameters:
aOutFile-- File to write to
Returns:
VOID

Definition at line 948 of file nsAFMObject.cpp.

{
PRInt32 i;


  // individual font characteristics
  for(i=0;i<mPSFontInfo->mNumCharacters;i++) {
    fprintf(aOutFile,"{\n");
    fprintf(aOutFile,"%d, \n",mPSFontInfo->mAFMCharMetrics[i].mCharacter_Code);
    fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mW0x);
    fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mW0y);
    fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mW1x);
    fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mW1y);
    //fprintf(aOutFile,"\"%s\", \n", CORRECTSTRING(mPSFontInfo->mAFMCharMetrics[i].mName));
    //fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mVv_x);
    //fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mVv_y);
    fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mLlx);
    fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mLly);
    fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].mUrx);
    fprintf(aOutFile,"%f \n",mPSFontInfo->mAFMCharMetrics[i].mUry);
    //fprintf(aOutFile,"%f, \n",mPSFontInfo->mAFMCharMetrics[i].num_ligatures);
    fprintf(aOutFile,"}\n");
    if ( i != mPSFontInfo->mNumCharacters - 1 )
       fputc( ',', aOutFile ); 
    fputc( '\n', aOutFile );
  }
}

Here is the call graph for this function:


Write out the AFMFontInformation Header from the currently parsed AFM file, this will write a ASCII file so you can use it as a head if need be.


See documentation in nsAFMParser.h 3/05/99 dwc

3/09/99 dwc

Parameters:
aOutFile-- File to write to
Returns:
VOID

Definition at line 910 of file nsAFMObject.cpp.

{

  // main information of the font
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mFontVersion);
  fprintf(aOutFile,"\"%s\",\n",CORRECTSTRING(mPSFontInfo->mFontName));
  fprintf(aOutFile,"\"%s\",\n",CORRECTSTRING(mPSFontInfo->mFullName));
  fprintf(aOutFile,"\"%s\",\n",CORRECTSTRING(mPSFontInfo->mFamilyName));
  fprintf(aOutFile,"\"%s\",\n",CORRECTSTRING(mPSFontInfo->mWeight));
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mFontBBox_llx);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mFontBBox_lly);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mFontBBox_urx);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mFontBBox_ury);
  fprintf(aOutFile,"\"%s\",\n",CORRECTSTRING(mPSFontInfo->mVersion));
  fprintf(aOutFile,"\"%s\",\n",CORRECTSTRING(mPSFontInfo->mNotice));
  fprintf(aOutFile,"\"%s\",\n",CORRECTSTRING(mPSFontInfo->mEncodingScheme));
  fprintf(aOutFile,"%d,\n",mPSFontInfo->mMappingScheme);
  fprintf(aOutFile,"%d,\n",mPSFontInfo->mEscChar);
  fprintf(aOutFile,"\"%s\",\n", CORRECTSTRING(mPSFontInfo->mCharacterSet));
  fprintf(aOutFile,"%d,\n",mPSFontInfo->mCharacters);
  fprintf(aOutFile,"%s,\n",BOOLOUT(mPSFontInfo->mIsBaseFont));
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mVVector_0);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mVVector_1);
  fprintf(aOutFile,"%s,\n",BOOLOUT(mPSFontInfo->mIsFixedV));
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mCapHeight);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mXHeight);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mAscender);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mDescender);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mUnderlinePosition);
  fprintf(aOutFile,"%f,\n",mPSFontInfo->mUnderlineThickness);
  fprintf(aOutFile,"%d\n",mPSFontInfo->mNumCharacters);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 403 of file nsAFMObject.h.

Definition at line 405 of file nsAFMObject.h.

AFMFontInformation* nsAFMObject::mPSFontInfo

Definition at line 399 of file nsAFMObject.h.

char nsAFMObject::mToken[256] [protected]

Definition at line 404 of file nsAFMObject.h.


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