Ejemplo n.º 1
0
void InitPSFontMap(void)
{
  char* psfont_name=NULL;
  /* Prefer ps2pk.map, fonts are present more often */
  psfont_name=find_format("ps2pk.map");
  if (psfont_name==NULL)
    psfont_name=find_format("psfonts.map");
  if (psfont_name==NULL) {
    Warning("cannot find ps2pk.map, nor psfonts.map");
  } else {
    DEBUG_PRINT(DEBUG_FT,
		("\n  OPEN PSFONT MAP:\t'%s'", psfont_name));
    if (MmapFile(psfont_name,&psfont_mmap)) {
      Warning("psfonts map %s could not be opened", psfont_name);
    }
    free(psfont_name);
  }
#ifdef HAVE_FT2
  psfont_name=find_format("ttfonts.map");
  if (psfont_name!=NULL) {
    DEBUG_PRINT(DEBUG_FT,("\n  OPEN TTFONT MAP:\t'%s'", psfont_name));
    if (MmapFile(psfont_name,&ttfont_mmap)) {
      Warning("ttfonts map %s could not be opened", psfont_name);
    }
    free(psfont_name);
  }
#endif
}
Ejemplo n.º 2
0
Archivo: tfm.c Proyecto: MiKTeX/miktex
bool ReadTFM(struct font_entry * tfontp, char* tfmname)
{
  struct filemmap fmmap;
  struct char_entry *tcharptr;
  unsigned char *position;
  int lh,bc,ec,nw, c;
  dviunits* width;

  DEBUG_PRINT((DEBUG_DVI|DEBUG_FT|DEBUG_TFM),
	      ("\n  OPEN METRICS:\t'%s'", tfmname));
  if (MmapFile(tfmname,&fmmap)) return(false);
  position=(unsigned char*)fmmap.data;
  if (fmmap.size<10) Fatal("TFM file %s ends prematurely",tfmname);
  lh = UNumRead(position+2,2);
  bc = UNumRead(position+4,2);
  ec = UNumRead(position+6,2);
  nw = UNumRead(position+8,2);
  DEBUG_PRINT(DEBUG_TFM,(" %d %d %d %d",lh,bc,ec,nw));
  if (nw>0) {
    unsigned char *end=(unsigned char *) fmmap.data+fmmap.size;
    if ((width=malloc(nw*sizeof(dviunits)))==NULL)
      Fatal("cannot allocate memory for TFM widths");
    c=0;
    position=position+24+(lh+ec-bc+1)*4;
    while( c < nw ) {
      if (position >= end - 4) Fatal("TFM file %s ends prematurely",tfmname);
      width[c] = SNumRead(position,4);
      c++;
      position += 4;
    }
    /* Read char widths */
    c=bc;
    position=(unsigned char*)fmmap.data+24+lh*4;
    while(c <= ec) {
      if (position >= end) Fatal("TFM file %s ends prematurely",tfmname);
      DEBUG_PRINT(DEBUG_TFM,("\n@%ld TFM METRICS:\t",
			     (long)((char *)position - fmmap.data)));
      if ((tcharptr=malloc(sizeof(struct char_entry)))==NULL)
        Fatal("cannot allocate memory for TFM char entry");
      tcharptr->data=NULL;
      if (*position < nw) {
        tcharptr->tfmw=width[*position];
      } else {
        Fatal("TFM file %s lacks width for char %u", tfmname, *position);
      }
      DEBUG_PRINT(DEBUG_TFM,("%d [%d] %d",c,*position,tcharptr->tfmw));
      tcharptr->tfmw = (dviunits)
        ((int64_t) tcharptr->tfmw * tfontp->s / (1 << 20));
      DEBUG_PRINT(DEBUG_TFM,(" (%d)",tcharptr->tfmw));
      if (c >= NFNTCHARS) /* Only positive for now */
        Fatal("tfm file %s exceeds char numbering limit %u",tfmname,NFNTCHARS);
      tfontp->chr[c] = tcharptr;
      c++;
      position += 4;
    }
    free(width);
  }
  UnMmapFile(&fmmap);
  return(true);
}
Ejemplo n.º 3
0
static struct colorname* LoadXColorPrologue(void)
{
  struct colorname *list=NULL,*tmp=NULL;
  char *filepath,*pos,*max;
  const char *prefix="";
  char *name,*values,*model;
  int nprefix=0,nname,nvalues,nmodel;
  struct filemmap fmmap;
  boolean mmapfailed;

  filepath=kpse_find_file(xcpname,kpse_program_text_format,false);
  if (filepath == NULL)
    return NULL;
  DEBUG_PRINT(DEBUG_COLOR,("\n  OPEN XCOLOR PROLOGUE:\t'%s'", filepath));
  mmapfailed = MmapFile(filepath,&fmmap);
  free(filepath);
  if (mmapfailed)
    return NULL;
  pos=fmmap.data;
  max=fmmap.data+fmmap.size;
  while(pos<max) {
    while (pos<max && *pos!='/') pos++;
    if (*pos=='/') {
      nname=nmodel=nvalues=0;
      name=++pos;                /* first argument: color name */
      FINDPSNAMEEND(pos,nname);
      values=++pos;              /* second argument: color values */
      FINDVALEND(pos,nvalues);
      model=pos+3;               /* third argument: color model, prefixed by 'XC' */
      while(pos<max && *pos!=' ' && *pos!='\r' && *pos!='\n') pos++;
      nmodel=pos-model;
      tmp=NewColor(prefix,nprefix,name,nname,model,nmodel,values,nvalues);
      tmp->next=list;
      list=tmp;
    }
  }
  UnMmapFile(&fmmap);
  return(list);
}
Ejemplo n.º 4
0
void InitPK(struct font_entry * tfontp)
{
  unsigned char* position;
  struct char_entry *tcharptr; /* temporary char_entry pointer  */
  uint32_t    hppp, vppp, packet_length;
  uint32_t    c;

  DEBUG_PRINT((DEBUG_DVI|DEBUG_PK),("\n  OPEN FONT:\t'%s'", tfontp->name));
  Message(BE_VERBOSE,"<%s>", tfontp->name);
  if (MmapFile(tfontp->name,&(tfontp->fmmap)))
    Fatal("font file %s unusable", tfontp->name);
  position=(unsigned char*)tfontp->fmmap.data;
  if (tfontp->fmmap.size < 2 || tfontp->fmmap.size < 3+*(position+2)+16)
    Fatal("PK file %s ends prematurely",tfontp->name);
  if (*position++ != PK_PRE)
    Fatal("unknown font format in file %s",tfontp->name);
  if (*position++ != PK_ID)
    Fatal( "wrong version %d of PK file %s (should be 89)",
	   (int)*(position-1),tfontp->name);
  DEBUG_PRINT(DEBUG_PK,("\n  PK_PRE:\t'%.*s'",(int)*position, position+1));
  position += *position + 1;

  tfontp->designsize = UNumRead(position, 4);
  DEBUG_PRINT(DEBUG_PK,(" %d", tfontp->designsize));
  tfontp->type = FONT_TYPE_PK;

  c = UNumRead(position+4, 4);
  DEBUG_PRINT(DEBUG_PK,(" %d", c));
  CheckChecksum (tfontp->c, c, tfontp->name);

  hppp = UNumRead(position+8, 4);
  vppp = UNumRead(position+12, 4);
  DEBUG_PRINT(DEBUG_PK,(" %d %d", hppp,vppp));
  if (hppp != vppp)
    Warning("aspect ratio is %d:%d (should be 1:1)", hppp, vppp);
  tfontp->magnification = (uint32_t)((uint64_t)hppp * 7227 * 5 / 65536l + 50)/100;
  position+=16;
  /* Read char definitions */
  position = skip_specials(position);
  while (*position != PK_POST) {
    DEBUG_PRINT(DEBUG_PK,("\n  @%ld PK CHAR:\t%d",
			  (long)((char *)position - tfontp->fmmap.data), *position));
    if ((tcharptr = malloc(sizeof(struct char_entry))) == NULL)
      Fatal("cannot allocate space for char_entry");
    tcharptr->flag_byte = *position;
    tcharptr->data = NULL;
    tcharptr->tfmw = 0;
    if ((*position & 7) == 7) {
      packet_length = UNumRead(position+1,4);
      c = UNumRead(position+5, 4);
      position += 9;
    } else if (*position & 4) {
      packet_length = (*position & 3) * 65536l +
	UNumRead(position+1, 2);
      c = UNumRead(position+3, 1);
      position += 4;
    } else {
      packet_length = (*position & 3) * 256 +
	UNumRead(position+1, 1);
      c = UNumRead(position+2, 1);
      position += 3;
    }
  DEBUG_PRINT(DEBUG_PK,(" %d %d",packet_length,c));
  if (c > (LASTFNTCHAR))
    Fatal("PK font %s exceeds char numbering limit",tfontp->name);
  tcharptr->length = packet_length;
  tcharptr->pkdata = position;
  tfontp->chr[c]=tcharptr;
  position += packet_length;
  position = skip_specials(position);
  }
}
Ejemplo n.º 5
0
Archivo: enc.c Proyecto: MiKTeX/miktex
static struct encoding* InitEncoding(char* encoding) 
{
  char *pos,*max,*buf,*enc_file;
  int i;
  struct encoding* encp=NULL;
  struct filemmap fmmap;
  boolean mmapfailed;
  
#ifdef HAVE_KPSE_ENC_FORMATS
  enc_file=kpse_find_file(encoding,kpse_enc_format,false);
#else
  enc_file=kpse_find_file(encoding,kpse_tex_ps_header_format,false);
#endif
  if (enc_file == NULL) {
    Warning("encoding file %s could not be found",encoding);
    return(NULL);
  }
  DEBUG_PRINT((DEBUG_FT|DEBUG_ENC),("\n  OPEN ENCODING:\t'%s'", enc_file));
  mmapfailed = MmapFile(enc_file,&fmmap);
  free(enc_file);
  if (mmapfailed) 
    return(NULL);
  if ((encp = calloc(sizeof(struct encoding)+strlen(encoding)+1
		     +fmmap.size,1))==NULL) {
    Warning("cannot alloc space for encoding",encoding);
    UnMmapFile(&fmmap);
    return(NULL);
  }
  encp->name=(char*)encp+sizeof(struct encoding);
  strcpy(encp->name,encoding);
  pos=fmmap.data;
  max=fmmap.data+fmmap.size;
  buf=encp->name+strlen(encoding)+1;
#define SKIPCOMMENT(x) if (*x=='%') while (x<max && *x!='\r' && *x!='\n') x++;
  while(pos<max && *pos!='/') {
    SKIPCOMMENT(pos);
    pos++;
  }
  pos++;
  encp->charname[256]=buf;
  while(pos<max && *pos!='[' && *pos!='%'
	&& *pos!=' ' && *pos!='\t' && *pos!='\r' && *pos!='\n')
    *buf++=*pos++;
  *buf++='\0';
  DEBUG_PRINT(DEBUG_ENC,("\n  PS ENCODING '%s'",
			 encp->charname[256])); 
  while (pos < max && *pos!='[') {
    SKIPCOMMENT(pos);
    pos++;
  }
  while(pos<max && *pos!='/') {
    SKIPCOMMENT(pos);
    pos++;
  }
  i=0;
  while(pos<max && *pos!=']') {
    pos++;
    encp->charname[i++]=buf;
    while(pos<max && *pos!='%' && *pos!=' ' \
	  && *pos!='\t' && *pos!='\r' && *pos!='\n') 
      *buf++=*pos++;
    *buf++='\0';
    DEBUG_PRINT(DEBUG_ENC,("\n  PS ENCODING %d '%s'",
		 i-1,encp->charname[i-1])); 
    while(pos<max && *pos!='/' && *pos!=']') {
      SKIPCOMMENT(pos);
      pos++;
    }
  }
  UnMmapFile(&fmmap);
  return(encp);
}
Ejemplo n.º 6
0
static struct colorname* LoadColornameFile(const char* filename)
{
  struct colorname *list=NULL,*tmp=NULL;
  char *filepath,*pos,*max;
  const char *prefix="";
  char *name,*values,*model;
  int nprefix=0,nname,nvalues,nmodel;
  struct filemmap fmmap;
  boolean mmapfailed;

  filepath=kpse_find_file(filename,kpse_tex_format,false);
  if (filepath == NULL)
    return NULL;
  DEBUG_PRINT(DEBUG_COLOR,("\n  OPEN COLOR NAMES:\t'%s'", filepath));
  mmapfailed=MmapFile(filepath,&fmmap);
  free(filepath);
  if (mmapfailed)
    return NULL;
  pos=fmmap.data;
  max=fmmap.data+fmmap.size;
  while (pos<max && *pos!='\\') pos++;
  while(pos+9<max && strncmp(pos,"\\endinput",9)!=0) {
    if ((pos+20<max && strncmp(pos,"\\def\\colornameprefix",20)==0)
	|| (pos+32<max
	    && strncmp(pos,"\\providecommand*\\colornameprefix",32)==0)) {
      DEBUG_PRINT(DEBUG_COLOR,("\n  \t'%.20s'", pos));
      FINDARG(pos);
      prefix=pos;
      FINDNAMEEND(pos,nprefix);
      DEBUG_PRINT(DEBUG_COLOR,("\n  \tCOLOR PREFIX '%.*s'",nprefix,prefix));
    } else if (pos+17<max && strncmp(pos,"\\DefineNamedColor",17)==0) {
      DEBUG_PRINT(DEBUG_COLOR,("\n  \t'%.17s'", pos));
      model=NULL;
      nname=nmodel=nvalues=0;
      FINDARG(pos);             /* skip first argument */
      FINDARG(pos);             /* find second argument: color name */
      name=pos;
      FINDNAMEEND(pos,nname);
      FINDARG(pos);             /* find third argument: color model */
      model=pos;
      FINDMODELEND(pos,nmodel);
      FINDARG(pos);             /* find fourth argument: color values */
      values=pos;
      FINDVALEND(pos,nvalues);
      tmp=NewColor(prefix,nprefix,name,nname,model,nmodel,values,nvalues);
      tmp->next=list;
      list=tmp;
    } else if ((pos+15<max && strncmp(pos,"\\definecolorset",15)==0)
	       || (pos+16<max && strncmp(pos,"\\preparecolorset",16)==0)) {
      char *model;
      DEBUG_PRINT(DEBUG_COLOR,("\n  \t'%.15s'", pos));
      FINDARG(pos);             /* find first argument: color model */
      model=pos;
      FINDMODELEND(pos,nmodel);
      FINDARG(pos);             /* skip second argument */
      FINDARG(pos);             /* skip third argument */
      FINDARG(pos);             /* find fourth argument: names, values */
      while(pos<max && *pos!='}'){
	name=pos;
	FINDNAMEEND(pos,nname);
	pos++;
	values=pos;
	FINDVALEND(pos,nvalues);
	FINDLASTVALEND(pos);
	tmp=NewColor(prefix,nprefix,name,nname,model,nmodel,values,nvalues);
	tmp->next=list;
	list=tmp;
	FINDWORD(pos);
      }
    } else {
      pos++;
      while (pos<max && *pos!='\\') pos++;
    }
  }
  UnMmapFile(&fmmap);
  return(list);
}