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

📄 t1io.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XConsortium: t1io.c,v 1.4 91/10/10 11:19:41 rws Exp $ *//* Copyright International Business Machines,Corp. 1991 * All Rights Reserved * * License to use, copy, modify, and distribute this software * and its documentation for any purpose and without fee is * hereby granted, provided that the above copyright notice * appear in all copies and that both that copyright notice and * this permission notice appear in supporting documentation, * and that the name of IBM not be used in advertising or * publicity pertaining to distribution of the software without * specific, written prior permission. * * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. * * Author: Carol H. Thompson  IBM Almaden Research Center *//********************************************************************  I/O package for Type 1 font reading********************************************************************/ #ifndef STATIC#define STATIC static#endif #if defined(_MSC_VER)# include <io.h># include <sys/types.h># include <sys/stat.h>#else# include <unistd.h>#endif#include <stdio.h>#include <fcntl.h>#include <string.h>#include <ctype.h>#include <stdlib.h>#include "t1stdio.h"#include "t1hdigit.h"/* we define this to switch to decrypt-debugging mode. The stream of   decrypted bytes will be written to stdout! This contains binary   charstring data *//* #define DEBUG_DECRYPTION  *//* #define DEBUG_PFB_BLOCKS  *//* Constants and variables used in the decryption */#define c1 ((unsigned short)52845)#define c2 ((unsigned short)22719)static unsigned short r;static int asc, Decrypt;static int extrach;static int haveextrach;static int starthex80=0;static long pfbblocklen=0;static long accu=0;static unsigned long bytecnt=0;static int eexec_startOK=0;static int eexec_endOK=0;static int in_eexec=0; /* Our single FILE structure and buffer for this package */STATIC F_FILE TheFile;STATIC unsigned char TheBuffer[F_BUFSIZ]; /* Our routines */F_FILE *T1Open(), *T1eexec();int T1Close();int T1Read(), T1Getc(), T1Ungetc();void T1io_reset(void);STATIC int T1Decrypt(), T1Fill(); /* -------------------------------------------------------------- *//*ARGSUSED*/F_FILE *T1Open(fn, mode)  char *fn;    /* Pointer to filename */  char *mode;  /* Pointer to open mode string */{  F_FILE *of = &TheFile;  char c;     Decrypt = 0;  eexec_startOK=0;  eexec_endOK=0;   /* We know we are only reading */  /* cygwin32 also needs the binary flag to be set */#if defined(MSDOS) | defined(_WIN32) | defined (__EMX__)  if ((of->fd=open(fn, O_RDONLY | O_BINARY)) < 0) return NULL;#else  if ((of->fd=open(fn, O_RDONLY)) < 0) return NULL;#endif  /* We check for pfa/pfb file */  if (read( of->fd, &c, 1)!=1) {    close( of->fd);    return(NULL);  }  else    if (c==(char)0x80){      starthex80=1;    }  lseek( of->fd, 0, SEEK_SET);    /* Initialize the buffer information of our file descriptor */  of->b_base = TheBuffer;  of->b_size = F_BUFSIZ;  of->b_ptr = NULL;  of->b_cnt = 0;  of->flags = 0;  of->error = 0;  haveextrach = 0;  return &TheFile;} /* end Open */ /* -------------------------------------------------------------- */int T1Getc(f)        /* Read one character */  F_FILE *f;         /* Stream descriptor */{  if (f->b_base == NULL) return EOF;  /* already closed */   if (f->flags & UNGOTTENC) { /* there is an ungotten c */    f->flags &= ~UNGOTTENC;    return (int) f->ungotc;  }   if (f->b_cnt == 0)  /* Buffer needs to be (re)filled */    f->b_cnt = T1Fill(f);  if (f->b_cnt > 0) return (f->b_cnt--, (int) *(f->b_ptr++));  else {    f->flags |= FIOEOF;    return EOF;  }} /* end Getc */ /*  This function is added by RMz:    T1Gets(): Read a line of the file and save it to string. At most,    (size-1) bytes are read. The user *must* ensure (by making size large    enough) that "eexec" does not get split between two calls because    in this case, eexec-encryption does not set in.    ------------------------------------------------------------ */int T1Gets(char *string,	   int size,	   F_FILE *f) /* Read a line */{  int i=0;  char *eexecP;    if (string == NULL) {    return( i);  }  if (f->b_base == NULL)    return( i);  /* already closed */  if (size<2)   /* no bytes to be read. For size = 1 we only had		   room for the \0-character. */    return( i);    if (f->flags & UNGOTTENC) { /* there is an ungotten c */    f->flags &= ~UNGOTTENC;    string[i++]=f->ungotc;    size--;  }  size--; /* we have to leave room for one \0-character */    while ( size>0) {    if (f->b_cnt == 0) { /* Buffer needs to be (re)filled */      f->b_cnt = T1Fill(f);    }    if (f->b_cnt == 0) { /* no more bytes available. Put \0-char			    and return. */      if ( i==0) { /* we did not already store one single char to string */	f->flags |= FIOEOF;	return( i);      }      else {	f->flags |= FIOEOF;	string[i]='\0';	return( i);      }    }    /* do not skip white space as required by Adobe spec, because       if have found fonts where the first encrypted byte was of       white space type. */    if ( (eexec_startOK==1) && (eexec_endOK==1)) {      T1eexec( f);      eexec_startOK=0;      eexec_endOK=0;      in_eexec=1;      /* we are now in the encrypted portion. */    }    string[i]=*(f->b_ptr);        /* Check whether eexec appears in the string just setup */    if ( (Decrypt==0) &&	 ((eexecP=strstr( string, "eexec"))!=NULL) ) {      /* if eexec is an isolated token, start decryption */      if ( (eexec_startOK==1) &&	   (isspace( (int)string[i])!=0) ) {	eexec_endOK=1;      }      if ( (eexec_startOK==0) &&	   (isspace( (int)string[i-5])!=0) ) {	eexec_startOK=1;      }    }    i++;    /* Under UNIX, '\n' is the accepted newline. For pfb-files it is also       common to use '\r' as the newline indicator. I have, however, never       seen a pfb-file which uses the sequence '\r''\n' as a newline       indicator, as known from DOS. So we don't take care for this case       and simply map both single characters \r and \n into \n. Of course,       this can only be done in the ASCII section of the font. */    if ( *(f->b_ptr)=='\n' || *(f->b_ptr)=='\r') {      if (in_eexec==0)	string[i-1]='\n';        string[i]='\0';       f->b_cnt--;      f->b_ptr++;      return( i);    }        f->b_cnt--;    f->b_ptr++;    size--;  } /* end of while (size>0) */    string[i]='\0'; /* finish string */  return( i);  } /* end of T1Gets() */int T1GetDecrypt( void) {  return( in_eexec);}/* Return the optional contents after the final cleartomark token.   There might appear some PostScript code which is not important   for t1lib, but which becomes important if subsetted fonts are   embedded in PostScript files. */int T1GetTrailer(char *string,		 int size,		 F_FILE *f){  unsigned long off_save;  char *buf;  char *ctmP;  int i=0, j;  int datasize;    datasize=size;    off_save=lseek( f->fd, 0, SEEK_CUR);  if ((buf=(char *)malloc( size+1))==NULL ) {    return( -1);  }  lseek( f->fd, -size, SEEK_END);  read(f->fd, buf, size);  buf[size]='\0';   /* to be ablo perform a strstr() on this memory */    i=datasize;  j=datasize-11;   /* length of "cleartomark" plus terminating white		      space or newline */     while ((j--)>-1) {    if ((unsigned char)buf[i]==0x80) {      datasize=i; /* we skip the segment marker of pfb-files */    }    if ((ctmP=strstr( &(buf[j]), "cleartomark"))!=NULL) {      memcpy( string, &(buf[i]), datasize-i);      string[datasize-i]='\0';      lseek( f->fd, off_save, SEEK_SET);      free( buf);      return( datasize-i);    }    i--;  }  lseek( f->fd, off_save, SEEK_SET);  free( buf);  return( -1);}unsigned long T1GetFileSize( F_FILE *f) {

⌨️ 快捷键说明

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