⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t1afmtool.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 2 页
字号:
  time_t s_clock, *tp;    char *afmfilename;  FILE *afmfile;  CharMetricInfo **cmi;    /* Check for valid font */  if (CheckForFontID(FontID)!=1){    sprintf( err_warn_msg_buf,	     "Warning: Invalid FontID, font %d not loaded!",	     FontID);    T1_PrintLog( "T1_WriteAFMFallbackFile()", err_warn_msg_buf,	       T1LOG_WARNING);    T1_errno=T1ERR_INVALID_FONTID;    return(-2);  }  /* Check for AFM-data to be existent */  if (pFontBase->pFontArray[FontID].pAFMData==NULL){    sprintf( err_warn_msg_buf,	     "Warning: No AFM-Data available for font %d",	     FontID);    T1_PrintLog( "T1_WriteAFMFallbackFile()", err_warn_msg_buf,	       T1LOG_WARNING);    return(-3);  }  /* Check if AFM data has been generated from existent afm file -->     no need to generate a new one. */  if ((pFontBase->pFontArray[FontID].info_flags & AFM_SUCCESS)       || (pFontBase->pFontArray[FontID].info_flags & AFM_SLOPPY_SUCCESS)){    sprintf( err_warn_msg_buf,	     "Alert:  Available AFM-Data for font %d is generated from existent AFM-file!",	     FontID);    T1_PrintLog( "T1_WriteAFMFallbackFile()", err_warn_msg_buf,		 T1LOG_STATISTIC);    return(-1);  }    /* Construct AFM-filename */  i=strlen(pFontBase->pFontArray[FontID].pFontFileName);  if ((afmfilename=(char *)malloc((size_t)(i + 1) ))==NULL){    sprintf( err_warn_msg_buf,	     "Memory allocation error (fontID = %d)",	     FontID);    T1_PrintLog( "T1_WriteAFMFallbackFile()", err_warn_msg_buf,		 T1LOG_WARNING);    T1_errno=T1ERR_ALLOC_MEM;    return(-6);  }  strcpy( afmfilename, pFontBase->pFontArray[FontID].pFontFileName);  while (afmfilename[i]!='.')    i--;  afmfilename[i+1]='a';  afmfilename[i+2]='f';  afmfilename[i+3]='m';    if ((afmfile=fopen( afmfilename, "w"))==NULL){    sprintf( err_warn_msg_buf,	     "Could not open %s, (FontID = %d)",	     afmfilename, FontID);    T1_PrintLog( "T1_WriteAFMFallbackFile()", err_warn_msg_buf,		 T1LOG_WARNING);    free( afmfilename);    T1_errno=T1ERR_FILE_OPEN_ERR;    return(-4);  }  /* Set the creation time of afm file */  tp=&s_clock;  s_clock=time( tp);  /* Allocate a pointer-array to the metrics information,      of the size 256 + number of characters. */  nochars=pFontBase->pFontArray[FontID].pAFMData->numOfChars;  if ((cmi=(CharMetricInfo **)calloc( nochars+ENCODINGSIZE,				     sizeof(CharMetricInfo *)))==NULL){    sprintf( err_warn_msg_buf,	     "Memory allocation error (fontID = %d)",	     FontID);    T1_PrintLog( "T1_WriteAFMFallbackFile()", err_warn_msg_buf,		 T1LOG_WARNING);    T1_errno=T1ERR_ALLOC_MEM;    return(-6);  }  /* Reset area */  for ( i=0; i<(nochars+ENCODINGSIZE); i++)    cmi[i]=NULL;  /* First half of array is dedicated to encoded characters, the     second half for unencoded characters */  k=ENCODINGSIZE;  for ( i=0; i<nochars; i++){    j=T1_GetEncodingIndex( FontID,			   pFontBase->pFontArray[FontID].pAFMData->cmi[i].name);    if (j>=0)      cmi[j]=&(pFontBase->pFontArray[FontID].pAFMData->cmi[i]);    else      cmi[k++]=&(pFontBase->pFontArray[FontID].pAFMData->cmi[i]);  }    fprintf(afmfile, "StartFontMetrics 4.0\n");  fprintf(afmfile, "Comment This is %s created from %s by t1lib V. %s.\n",	  afmfilename, pFontBase->pFontArray[FontID].pFontFileName,	  T1LIB_IDENT);  fprintf(afmfile, "Comment File creation date: %s", ctime(&s_clock));  fprintf(afmfile, "Comment t1lib is copyright (c) Rainer Menzner, 1996-2001.\n");  fprintf(afmfile, "Comment t1lib is distributed under the GNU General Public Library License (LGPL)\n");  fprintf(afmfile, "FontName %s\n", T1_GetFontName( FontID));  fprintf(afmfile, "FullName %s\n", T1_GetFullName( FontID));  fprintf(afmfile, "FamilyName %s\n", T1_GetFamilyName( FontID));  fprintf(afmfile, "Weight %s\n", T1_GetWeight( FontID));  fprintf(afmfile, "ItalicAngle %d\n", (int)T1_GetItalicAngle( FontID));  fprintf(afmfile, "IsFixedPitch %s\n", T1_GetIsFixedPitch( FontID) ? "true" : "false" );  fprintf(afmfile, "FontBBox %d %d %d %d\n",	  T1_GetFontBBox( FontID).llx,	  T1_GetFontBBox( FontID).lly,	  T1_GetFontBBox( FontID).urx,	  T1_GetFontBBox( FontID).ury);  fprintf(afmfile, "UnderlinePosition %d\n",	  (int)T1_GetUnderlinePosition( FontID));  fprintf(afmfile, "UnderlineThickness %d\n",	  (int)T1_GetUnderlineThickness( FontID));  fprintf(afmfile, "Version %s\n", T1_GetVersion( FontID));  fprintf(afmfile, "Notice %s\n", T1_GetNotice( FontID));  /* Encoding */  if (pFontBase->pFontArray[FontID].pFontEnc==NULL){    if (pFontBase->pFontArray[FontID].info_flags & USES_STANDARD_ENCODING){      fprintf( afmfile, "EncodingScheme AdobeStandardEncoding\n");    }    else{      fprintf( afmfile, "EncodingScheme FontSpecific\n");    }  }  else    fprintf( afmfile, "EncodingScheme FontSpecific\n");  /* Values like capheight ascender xheight and descender */  /* We start with the overshoot positions */  i=pFontBase->pFontArray[FontID].pType1Data->BluesP->numBlueValues;  if (i>0){    /* Capheight */    if ((k=T1_GetEncodingIndex( FontID, "H"))!=-1){      l=T1_GetCharBBox( FontID, (char) k).ury;      delta=10000;      for (j=0; j<i; j++){	if (delta > abs(pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[j] - l)){	  min=j;	  delta=abs(pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[j] - l);	}      }      if (min % 2) /* index is odd */ 	min--;      /* Check for plausibility */      if (abs( pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[min] - l)	  > DELTA_MAX) /* We probably did not found the right position */	capheight=0;      else	capheight=pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[min];    }    else      capheight=0;    /* XHeight */    if ((k=T1_GetEncodingIndex( FontID, "x"))!=-1){      l=T1_GetCharBBox( FontID, (char) k).ury;      delta=10000;      for (j=0; j<i; j++){	if (delta > abs(pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[j] - l)){	  min=j;	  delta=abs(pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[j] - l);	}      }      if (min % 2) /* index is odd */ 	min--;      /* Check for plausibility */      if (abs( pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[min] - l)	  > DELTA_MAX) /* We probably did not found the right position */	xheight=0;      else	xheight=pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[min];    }    else{      xheight=0;    }    /* Ascender */    if ((k=T1_GetEncodingIndex( FontID, "d"))!=-1){      l=T1_GetCharBBox( FontID, (char) k).ury;      delta=10000;      for (j=0; j<i; j++){	if (delta > abs(pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[j] - l)){	  min=j;	  delta=abs(pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[j] - l);	}      }      if (min % 2) /* index is odd */ 	min--;      /* Check for plausibility */      if (abs( pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[min] - l)	  > DELTA_MAX) /* We probably did not found the right position */	ascender=0;      else	ascender=pFontBase->pFontArray[FontID].pType1Data->BluesP->BlueValues[min];    }    else{      ascender=0;    }  }  else{    capheight=0;    xheight=0;    ascender=0;  }  /* And now comes under shoot alignment position */  i=pFontBase->pFontArray[FontID].pType1Data->BluesP->numOtherBlues;  if (i>0){    /* Descender */    if ((k=T1_GetEncodingIndex( FontID, "p"))!=-1){      l=T1_GetCharBBox( FontID, (char) k).lly;      delta=10000;      for (j=0; j<i; j++){	if (delta > abs(pFontBase->pFontArray[FontID].pType1Data->BluesP->OtherBlues[j] - l)){	  min=j;	  delta=abs(pFontBase->pFontArray[FontID].pType1Data->BluesP->OtherBlues[j] - l);	}      }      if ((min % 2)==0) /* index is even */ 	min++;      /* Check for plausibility */      if (abs( pFontBase->pFontArray[FontID].pType1Data->BluesP->OtherBlues[min] - l)	  > DELTA_MAX) /* We probably did not found the right position */	descender=0;      else	descender=pFontBase->pFontArray[FontID].pType1Data->BluesP->OtherBlues[min];    }    else{      descender=0;    }  }  else{    descender=0;  }  if (capheight != 0)    fprintf( afmfile, "CapHeight %d\n", capheight);  if (xheight != 0)    fprintf( afmfile, "XHeight %d\n", xheight);  if (ascender != 0)    fprintf( afmfile, "Ascender %d\n", ascender);  if (descender != 0)    fprintf( afmfile, "Descender %d\n", descender);  if (pFontBase->pFontArray[FontID].pType1Data->BluesP->StdHW != 0.0)    fprintf( afmfile, "StdHW %d\n",	     (int) pFontBase->pFontArray[FontID].pType1Data->BluesP->StdHW);  if (pFontBase->pFontArray[FontID].pType1Data->BluesP->StdVW != 0.0)    fprintf( afmfile, "StdVW %d\n",	     (int) pFontBase->pFontArray[FontID].pType1Data->BluesP->StdVW);  /* Now fill in the values (we omit the .notdef) */  fprintf(afmfile, "StartCharMetrics %d\n", nochars-1);  for ( i=0; i<(nochars+ENCODINGSIZE); i++){    if (cmi[i]!=NULL && strcmp(cmi[i]->name,".notdef"))      fprintf( afmfile, "C %3d ; WX %4d ; N %-20s ; B %5d %5d %5d %5d ;\n",	       cmi[i]->code, cmi[i]->wx, cmi[i]->name,	       cmi[i]->charBBox.llx, cmi[i]->charBBox.lly,	       cmi[i]->charBBox.urx, cmi[i]->charBBox.ury);  }  fprintf(afmfile, "EndCharMetrics\nEndFontMetrics\n");     free(cmi);  fclose( afmfile);  return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -