Back to index

tetex-bin  3.0
Functions
t1enc.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char ** T1_LoadEncoding (char *FileName)
int T1_DeleteEncoding (char **encoding)
int T1_ReencodeFont (int FontID, char **Encoding)
int T1_SetDefaultEncoding (char **encoding)
char * T1_GetEncodingScheme (int FontID)

Function Documentation

int T1_DeleteEncoding ( char **  encoding)

Definition at line 602 of file t1enc.c.

{
  if (encoding){
    /* First free character names memory */
    free( encoding[0]);
    /* then, free pointer array */
    free( encoding);
  }
  return(0);
  
}
char* T1_GetEncodingScheme ( int  FontID)

Definition at line 769 of file t1enc.c.

{
  
  static char enc_scheme[256];
  
  /* First, check for valid font ID residing in memory: */
  if (T1_CheckForFontID(FontID)!=1){
    T1_errno=T1ERR_INVALID_FONTID;
    return(NULL);
  }

  if (pFontBase->pFontArray[FontID].pFontEnc==NULL){
    if (pFontBase->pFontArray[FontID].info_flags & USES_STANDARD_ENCODING){
      strcpy( enc_scheme, "StandardEncoding");
    }
    else {
      strcpy( enc_scheme, "FontSpecific");
    }
  }
  else
    strcpy( enc_scheme, pFontBase->pFontArray[FontID].pFontEnc[256]);
  
  return(enc_scheme);
  
}
char** T1_LoadEncoding ( char *  FileName)

Definition at line 579 of file t1enc.c.

{
  char **Encoding;
  char *EncFileName;
  
  if( FileName==NULL){
    T1_errno=T1ERR_INVALID_PARAMETER;
    return(NULL);
  }
  
  if ((EncFileName=intT1_Env_GetCompletePath( FileName, T1_ENC_ptr))==NULL){
    T1_errno=T1ERR_FILE_OPEN_ERR;
    return(NULL);
  }
  Encoding=ScanEncodingFile(EncFileName);
  free(EncFileName);
  
  return(Encoding);
}
int T1_ReencodeFont ( int  FontID,
char **  Encoding 
)

Definition at line 621 of file t1enc.c.

{
  int i, j, k, l, m;
  char *charname;
  PairKernData *pkd;
  METRICS_ENTRY *kern_tbl;
  int char1, char2;
  
  
  /* First, check for valid font ID residing in memory: */
  if (T1_CheckForFontID(FontID)!=1){
    T1_errno=T1ERR_INVALID_FONTID;
    return(-1);
  }
  
  /* Second, check whether size-dependent data exists: */
  if (pFontBase->pFontArray[FontID].pFontSizeDeps != NULL){
    T1_errno=T1ERR_OP_NOT_PERMITTED;
    return(-1);
  }
  
  pFontBase->pFontArray[FontID].pFontEnc=Encoding;


  /* We have to update the space_position-entry in the FONTPRIVATE. 
     If space is not found (not encoded), set it to -1: */
  pFontBase->pFontArray[FontID].space_position=-1;
  i=0;
  if (Encoding){ /* external encoding */
    while (i<256){
      if (strcmp( (char *)pFontBase->pFontArray[FontID].pFontEnc[i],
                "space")==0){
       /* space found at position i: */
       pFontBase->pFontArray[FontID].space_position=i;
       break;
      }
      i++;
    }
  }
  else{ /* reencoding to internal encoding */
    while (i<256){
      if (strcmp( (char *)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[ENCODING].value.data.arrayP[i].data.arrayP,
                "space")==0){
       /* space found at position i: */
       pFontBase->pFontArray[FontID].space_position=i;
       break;
      }
      i++;
    }
  }

  /* Now update afm index mapping: */
  if (pFontBase->pFontArray[FontID].pAFMData != NULL){
    for (i=0; i<256; i++) {
      charname=T1_GetCharName( FontID, i);
      /* in a first loop check for ordinary characters */
      for ( j=0; j<pFontBase->pFontArray[FontID].pAFMData->numOfChars; j++) {
       if (strcmp( charname,
                  pFontBase->pFontArray[FontID].pAFMData->cmi[j].name)==0) {
         pFontBase->pFontArray[FontID].pEncMap[i]=j+1; /* index 0 is reserved! */
         continue;
       }
      }
      /* if nothing has been found, check for composite characters */ 
      for ( j=0; j<pFontBase->pFontArray[FontID].pAFMData->numOfComps; j++) {
       if (strcmp( charname,
                  pFontBase->pFontArray[FontID].pAFMData->ccd[j].ccName)==0) {
         pFontBase->pFontArray[FontID].pEncMap[i]=-(j+1); /* index 0 is reserved! */
         /* Note: Metrics of composite characters already exist so that there is
            no need to recalculate them! */
         continue;
       }
      }
    }
    /* Update kerning table */
    pFontBase->pFontArray[FontID].KernMapSize=0;
    k=pFontBase->pFontArray[FontID].pAFMData->numOfPairs;
    if (k>0){ /* i.e., there are any pairs */
      /* OK, it does not suffice to alloc numOfPairs METRICS_ENTRYs, because
        a given character might be encoded at several locations and kerning
        should still work. As a worst case estimation, we allocate 256^2
        and realloc later. */ 
      if ((pFontBase->pFontArray[FontID].pKernMap=
          (METRICS_ENTRY *)malloc( (256*256) *sizeof( METRICS_ENTRY)))==NULL){
       sprintf( err_warn_msg_buf, "Error allocating memory for metrics map (FontID=%d)",
               FontID);
       T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf,
                   T1LOG_WARNING);
       T1_errno=T1ERR_ALLOC_MEM;
       return(-1);
      }
      kern_tbl=pFontBase->pFontArray[FontID].pKernMap;
      pkd=pFontBase->pFontArray[FontID].pAFMData->pkd;
      j=0;
      for ( i=0; i<k; i++) {
       /* We do not check T1_GetEncodingIndices() against the return value
          NULL because we just loading the font in question: */
       l=0;
       while ((char1=(T1_GetEncodingIndices( FontID, pkd[i].name1))[l++])!=-1) {
         /* pair could be relevant in current encoding */
         m=0;
         while ((char2=(T1_GetEncodingIndices( FontID, pkd[i].name2))[m++])!=-1) {
           /* Since we get here we have a relevant pair -->
              Put char1 in higher byte and char2 in LSB: */
           kern_tbl[j].chars=(char1 << 8) | char2;
           /* We only make use of horizontal kerning */
           kern_tbl[j].hkern=pkd[i].xamt;
           j++;
         } /* while (char2) */
       } /* while (char1) */
      } /* for */
      /* We are done, realloc memory: */
      kern_tbl=(METRICS_ENTRY*) realloc( kern_tbl, j*sizeof(METRICS_ENTRY));
      /* We now sort the kerning array with respect to char indices */
      qsort( kern_tbl, (size_t) j, sizeof(METRICS_ENTRY),
            &cmp_METRICS_ENTRY );
      /* Finally write back pointer for the case that realloc changed the
        pointer */
      pFontBase->pFontArray[FontID].pKernMap=kern_tbl;
      pFontBase->pFontArray[FontID].KernMapSize=j;
    }
    else {
      pFontBase->pFontArray[FontID].pKernMap=NULL;
    }
  }
  return(0);
}
int T1_SetDefaultEncoding ( char **  encoding)

Definition at line 754 of file t1enc.c.