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

📄 t1afmtool.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------------  ----- File:        t1afmtool.c   ----- Author:      Rainer Menzner (Rainer.Menzner@web.de)  ----- Date:        2001-04-01  ----- Description: This file is part of the t1-library. It contains                     functions for generating a fallback set of afm data		     from type 1 font files.  ----- Copyright:   t1lib is copyrighted (c) Rainer Menzner, 1996-2001.                     As of version 0.5, t1lib is distributed under the		     GNU General Public Library Lincense. The		     conditions can be found in the files LICENSE and		     LGPL, which should reside in the toplevel		     directory of the distribution.  Please note that 		     there are parts of t1lib that are subject to		     other licenses:		     The parseAFM-package is copyrighted by Adobe Systems		     Inc.		     The type1 rasterizer is copyrighted by IBM and the		     X11-consortium.  ----- Warranties:  Of course, there's NO WARRANTY OF ANY KIND :-)  ----- Credits:     I want to thank IBM and the X11-consortium for making                     their rasterizer freely available.		     Also thanks to Piet Tutelaers for his ps2pk, from		     which I took the rasterizer sources in a format		     independent from X11.                     Thanks to all people who make free software living!--------------------------------------------------------------------------*/  #define T1AFMTOOL_C#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#if defined(_MSC_VER)# include <io.h># include <sys/types.h># include <sys/stat.h>#else# include <unistd.h>#endif#include <stdlib.h>#include <math.h>#include <time.h>#include <string.h>#include "../type1/ffilest.h" #include "../type1/types.h"#include "parseAFM.h" #include "../type1/objects.h"#include "../type1/spaces.h"#include "../type1/util.h"#include "../type1/fontfcn.h"#include "../type1/regions.h"#include "../type1/blues.h"#include "t1types.h"#include "t1extern.h"#include "t1finfo.h"#include "t1base.h"#include "t1misc.h"#include "t1set.h"#include "t1load.h"#include "t1afmtool.h"#define DELTA_MAX    30#define ENCODINGSIZE (int) 256#ifndef T1LIB_IDENT#define T1LIB_IDENT  "???.???"#endifextern char *t1_get_abort_message( int number);  /* T1_GenerateAFMFallbackInfo(): Generate fallback information from   Type 1 font file by rasterizing every character at 1000 bp. Returns   a pointer to a generated FontInfo struct or NULL in case of an error.   */FontInfo *T1_GenerateAFMFallbackInfo( int FontID){  int i, j;  struct region *area;  struct XYspace *S;      int mode=0;  char **charnames;  int nochars=0;  FontInfo *pAFMData;      /* We return to this if something goes wrong deep in the rasterizer */  if ((i=setjmp( stck_state))!=0) {    T1_errno=T1ERR_TYPE1_ABORT;    sprintf( err_warn_msg_buf, "t1_abort: Reason: %s",	     t1_get_abort_message( i));    T1_PrintLog( "T1_GenerateAFMFallbackInfo()", err_warn_msg_buf,	       T1LOG_ERROR);    return( NULL);  }    /* Check whether font is loaded: */  if (CheckForFontID(FontID)!=1){    sprintf( err_warn_msg_buf,	     "Can't generate AFM Info from Font %d (invalid ID)\n", FontID);    T1_PrintLog( "T1_GenerateAFMFallbackInfo()", err_warn_msg_buf,		 T1LOG_WARNING);    T1_errno=T1ERR_INVALID_FONTID;    return(NULL);  }  /* Setup apropriate charspace matrix */  S=(struct XYspace *)IDENTITY;  /* Make this permanent so that scaling it in fontfcnB_ByName will     make a duplicate of it, and this duplicate can thus be safely     destroyed.  Fixes the somewhat smaller memory leak */  S=(struct XYspace *)Permanent    (Transform(S, pFontBase->pFontArray[FontID].FontTransform[0],	       pFontBase->pFontArray[FontID].FontTransform[1],	       pFontBase->pFontArray[FontID].FontTransform[2],	       pFontBase->pFontArray[FontID].FontTransform[3]));  /* Alloc memory for FontInfo: */  if ((pAFMData=(FontInfo *)malloc( sizeof(FontInfo)))==NULL){    sprintf( err_warn_msg_buf,	     "Failed to allocate memory for FontInfo in Font %d!", FontID);    T1_PrintLog( "T1_GenerateAFMFallbackInfo()", err_warn_msg_buf,		 T1LOG_WARNING);    T1_errno=T1ERR_ALLOC_MEM;    /* make sure to free S */    if (S) {      KillSpace (S);    }    return( NULL);  }  /* Initialize pointers */  pAFMData->gfi=NULL;  pAFMData->cwi=NULL;  pAFMData->numOfChars=0;  pAFMData->cmi=NULL;  pAFMData->numOfTracks=0;  pAFMData->tkd=NULL;  pAFMData->numOfPairs=0;  pAFMData->pkd=NULL;  pAFMData->numOfComps=0;  pAFMData->ccd=NULL;    /* Get list of character name */  charnames=T1_GetAllCharNames( FontID);  /* and count number of characters */  nochars=0;    while (charnames[nochars]!=NULL)     nochars++;  pAFMData->numOfChars=nochars;  /* Allocate memory for CharMetricInfo area */  if ((pAFMData->cmi=(CharMetricInfo *)       malloc( nochars * sizeof( CharMetricInfo)))==NULL){    sprintf( err_warn_msg_buf,	     "Failed to allocate memory for CharMetricsInfo area in Font %d!",	     FontID);    T1_PrintLog( "T1_GenerateAFMFallbackInfo()", err_warn_msg_buf,		 T1LOG_WARNING);    free( pAFMData);    T1_errno=T1ERR_ALLOC_MEM;    /* make sure to free S */    if (S) {      KillSpace (S);    }    return( NULL);  }  /* Get metrics values */  for (i=0; i<nochars; i++){    area=fontfcnB_ByName( FontID, 0, S, charnames[i], &mode,			  pFontBase->pFontArray[FontID].pType1Data, DO_RASTER);        if (area==NULL){      sprintf( err_warn_msg_buf,	       "Could not get charspace representation of character %d (%s) Font %d!",	       i, charnames[i], FontID);      T1_PrintLog( "T1_GenerateAFMFallbackInfo()", err_warn_msg_buf,		   T1LOG_WARNING);      /* Return since we don't know how to fill the values */      for (j=i-1; j>=0; j--)	free( pAFMData->cmi[j].name);      if (pAFMData->cmi!=NULL)	free( pAFMData->cmi);      if (pAFMData!=NULL)	free( pAFMData);      T1_errno=mode;      /* make sure to free S */      if (S) {	KillSpace (S);      }      return( NULL);    }    else if ((pAFMData->cmi[i].name=(char *)	      malloc( (size_t)(strlen( charnames[i])+1)))==NULL){      sprintf( err_warn_msg_buf,	       "Failed to allocate memory for CharName %d (%s) Font %d!",	       i, charnames[i], FontID);      T1_PrintLog( "T1_GenerateAFMFallbackInfo()", err_warn_msg_buf,		   T1LOG_WARNING);      /* NULL-ptr in charnames is prone to SIGSEGV-errors, thus,	 we have to return: */      for (j=i; j>=0; j--)	free( pAFMData->cmi[j].name);      free( pAFMData->cmi);      free( pAFMData);      T1_errno=T1ERR_ALLOC_MEM;      /* make sure to free S */      if (S) {	KillSpace (S);      }      return( NULL);    }    else{      strcpy( pAFMData->cmi[i].name, charnames[i]);      pAFMData->cmi[i].code=T1_GetEncodingIndex( FontID, charnames[i]);      pAFMData->cmi[i].wx=NEARESTPEL(area->ending.x);      pAFMData->cmi[i].wy=NEARESTPEL(area->ending.y);      /* We check for a valid BBox and set it to zero otherwise */      if ((int)area->xmax > (int)area->xmin){	pAFMData->cmi[i].charBBox.llx =(int)area->xmin;	pAFMData->cmi[i].charBBox.urx =(int)area->xmax;	pAFMData->cmi[i].charBBox.lly =(int)area->ymin;	pAFMData->cmi[i].charBBox.ury =(int)area->ymax;      }      else{	pAFMData->cmi[i].charBBox.llx =0;	pAFMData->cmi[i].charBBox.urx =0;	pAFMData->cmi[i].charBBox.lly =0;	pAFMData->cmi[i].charBBox.ury =0;      }      pAFMData->cmi[i].ligs=NULL;      /* We are done with area, so get rid of it. Solves the REALLY	 HUGE memory leak */      KillRegion (area);    }  }  sprintf( err_warn_msg_buf,	   "Generated metric information for %d characters of font %d!",	   nochars, FontID);  T1_PrintLog( "T1_GenerateAFMFallbackInfo()", err_warn_msg_buf,	       T1LOG_STATISTIC);    /* make sure to free S */  if (S) {    KillSpace (S);  }  return( pAFMData);  }/* T1_WriteAFMFallbackFile(): Write a fallback AFM-file from AFM data   genarated for font FontID. returns    0       if successful   -1       if afm-data was loaded from existent AFM-file   -2       if font is not loaded (invalid FontID)   -3       if for some reason the fonts' AFM-data has not been generated   -4       if the file could not be openend   -5       if an error occurred during write   -6       other error.   */int T1_WriteAFMFallbackFile( int FontID){  int i, j, k, l;  int nochars;  int capheight, ascender, xheight, descender;  int min=0, delta;

⌨️ 快捷键说明

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