Пример #1
0
FILE *
font_open(char *font, char **font_ret, double dpi, int *dpi_ret,

	  int dummy, char **filename_ret
#ifdef T1LIB
	  , int *t1id
#endif
	  )
{
    char *name;
    kpse_glyph_file_type file_ret;
    UNUSED(dummy);

    /* defaults in case of success; filename_ret will be
       non-NULL iff the fallback font is used.
    */
    *font_ret = NULL;
    /* filename_ret is NULL iff a T1 version of a font has been used */
    *filename_ret = NULL;
    *dpi_ret = dpi;
    
#ifdef Omega
    /* for omega, first try 16-bit ovf's, then 8-bit vf's. */
    name = kpse_find_ovf(font);
    if (name == NULL)
	name = kpse_find_vf(font);
#else
    name = kpse_find_vf(font);
#endif

#ifdef T1LIB
    if (resource.t1lib) {
	*t1id = -1;
    }
#endif /* T1LIB */

    if (name) { /* found a vf font */
	/* pretend it has the expected dpi value, else caller will complain */
	*dpi_ret = dpi;
	*filename_ret = name;
	return xfopen_local(name, FOPEN_R_MODE);
    }

#ifdef T1LIB
    if (resource.t1lib) {
	/* First try: T1 font of correct size */
	*t1id = find_T1_font(font);
	if (*t1id >= 0) {
	    TRACE_T1((stderr, "found T1 font %s", font));
	    return NULL;
	}
	TRACE_T1((stderr,
		  "T1 version of font %s not found, trying pixel version next, then fallback",
		  font));
    }
#endif /* T1LIB */
    /* Second try: PK/GF/... font within allowable size range */
    name = kpse_find_glyph(font, (unsigned)(dpi + .5),
			   kpse_any_glyph_format, &file_ret);

    if (name) { /* success */
	*dpi_ret = file_ret.dpi;
	*filename_ret = name;
	return xfopen_local(name, FOPEN_R_MODE);
    }
    else if (alt_font != NULL) {
	/* The strange thing about kpse_find_glyph() is that it
	   won't create a PK version of alt_font if it doesn't
	   already exist. So we invoke it explicitly a second time
	   for that one.
	*/
#ifdef T1LIB
	if (resource.t1lib) {
	    /* Third try: T1 version of fallback font */
	    *t1id = find_T1_font(alt_font);
	    if (*t1id >= 0) {
		TRACE_T1((stderr, "found fallback font %s\n", font));
		*font_ret = xstrdup(alt_font);
		return NULL;
	    }
	    TRACE_T1((stderr,
		      "Type1 version of fallback font %s not found, trying pixel version",
		      alt_font));
	}
#endif /* T1LIB */
	/* Forth try: PK version of fallback font */
	name = kpse_find_glyph(alt_font, (unsigned)(dpi + .5),
			       kpse_any_glyph_format, &file_ret);
	if (name) { /* success */
	    *dpi_ret = file_ret.dpi;
	    *filename_ret = name;
	    *font_ret = xstrdup(alt_font);
	    return xfopen_local(name, FOPEN_R_MODE);
	}
    }
    /* all other cases are failure */
    return NULL;
}
Пример #2
0
static void FontFind(struct font_entry * tfontptr)
{
  kpse_glyph_file_type font_ret;

  /* tfontptr->dpi = kpse_magstep_fix (tfontptr->dpi, resolution, NULL); */
  DEBUG_PRINT(DEBUG_DVI,("\n  FIND FONT:\t%s %d",tfontptr->n,tfontptr->dpi));

  tfontptr->name = kpse_find_vf (tfontptr->n);
  if (tfontptr->name!=NULL)
    InitVF(tfontptr);
#ifdef HAVE_FT2
  else if (option_flags & USE_FREETYPE) {
    tfontptr->psfontmap = FindPSFontMap(tfontptr->n);
    if (tfontptr->psfontmap!=NULL)
      tfontptr->name=kpse_find_t1_or_tt(tfontptr->psfontmap->psfile);
    else
      tfontptr->name=kpse_find_t1_or_tt(tfontptr->n);
    if (tfontptr->name!=NULL) {
      char* tfmname=kpse_find_file(tfontptr->n, kpse_tfm_format, false);
      if (tfmname!=NULL) {
        if (!ReadTFM(tfontptr,tfmname)) {
          Warning("unable to read tfm file %s", tfmname);
          free(tfontptr->name);
          tfontptr->name=NULL;
        } else if ((option_flags & USE_FREETYPE)==0 || !InitFT(tfontptr)) {
          /* if Freetype loading fails for some reason, fall back to PK font */
          free(tfontptr->name);
          tfontptr->name=NULL;
        }
        free(tfmname);
      }
    }
  }
#endif /* HAVE_FT2 */
  if (tfontptr->name==NULL) {
    tfontptr->name=kpse_find_pk (tfontptr->n, tfontptr->dpi, &font_ret);
    if (tfontptr->name!=NULL) {
      if (!FILESTRCASEEQ (tfontptr->n, font_ret.name)) {
        page_flags |= PAGE_GAVE_WARN;
        Warning("font %s not found, using %s at %d dpi instead",
                tfontptr->n, font_ret.name, font_ret.dpi);
        tfontptr->c = 0; /* no checksum warning */
      } else if (!kpse_bitmap_tolerance ((double)font_ret.dpi,
           (double) tfontptr->dpi)) {
        page_flags |= PAGE_GAVE_WARN;
        Warning("font %s at %d dpi not found, using %d dpi instead",
                tfontptr->n, tfontptr->dpi, font_ret.dpi);
      }
      InitPK(tfontptr);
    } else {
      page_flags |= PAGE_GAVE_WARN;
      Warning("font %s at %d dpi not found, characters will be left blank",
        tfontptr->n, tfontptr->dpi);
#ifndef WIN32
      tfontptr->fmmap.fd = 0;
#else  /* WIN32 */
      tfontptr->fmmap.hFile = INVALID_HANDLE_VALUE;
#endif
      tfontptr->magnification = 0;
      tfontptr->designsize = 0;
    }
  }
}
Пример #3
0
font_open P6C(char *,font, char **,font_ret, double, dpi, int *,dpi_ret, 
			  int, dummy, char **,filename_ret, int *,t1id)

#endif
{
  FILE *ret;
  char *name;
#ifdef WIN32
  extern void UpdateStatusBar(LPSTR lpszStatusString, 
			      WORD partNumber, WORD displayFlags);
  char szBuf[80];

  wsprintf(szBuf, "Finding font %s", font);
  UpdateStatusBar(szBuf, 0, 0);
#endif
  
#ifdef Omega
  name = kpse_find_ovf (font);
  if (!name) name = kpse_find_vf(font);
#else
  name = kpse_find_vf (font);
#endif
#if TTF
  *ttfid=-1
#endif
#if T1
  *t1id=-1;
#endif
  if (name) {
    /* VF fonts don't have a resolution, but load_font will complain if
       we don't return what it asked for.  */
    *dpi_ret = dpi;
    *font_ret = NULL;
  } else {
    kpse_glyph_file_type file_ret;

#if TTF
    /* First atempt to load it as TrueType font */

    *dpi_ret = dpi;
    *font_ret = NULL;
    *filename_ret = NULL;
    *ttfid=find_TTF_font(font);
    if (*ttfid>=0) return NULL;
#endif
#if T1
    /* First atempt to load it as T1 font */

    *dpi_ret = dpi;
    *font_ret = NULL;
    *filename_ret = NULL;
    *t1id=find_T1_font(font);
    if (*t1id>=0) return NULL;
#endif

    name = kpse_find_glyph (font, (unsigned) (dpi + .5),
			    kpse_any_glyph_format, &file_ret);

    if (name) {
      /* If we got it normally, from an alias, or from mktexpk,
	 don't fill in FONT_RET.  That tells load_font to complain.  */
      *font_ret
	= file_ret.source == kpse_glyph_source_fallback ? file_ret.name
	: NULL; /* tell load_font we found something good */
          
      *dpi_ret = file_ret.dpi;
    }
    /* If no VF and no PK, FONT_RET is irrelevant? */
  }
  
  /* If we found a name, return the stream. */
  ret = name ? xfopen_local (name, FOPEN_RBIN_MODE) : NULL;
  *filename_ret = name;

  return ret;
}