Пример #1
0
Файл: fonts.c Проект: Lopo/Lotos
/****************************************************************************
  readfont

  Allocates memory, initializes variables, and reads in the font.
  Called near beginning of main().
****************************************************************************/
int readfont(char *fontname)
{
	int i,row,numsread;
	long theord;
	int maxlen,cmtlines,ffright2left;
	char *fileline,magicnum[5];
	FILE *fontfile;
	char fontpath[FNAME_LEN];

	set_crash();
	sprintf(fontpath, "%s/%s.flf", FIGLET_FONTS, fontname);

	fontfile=fopen(fontpath,"r");

	if (!fontfile) return -1;

	fscanf(fontfile,"%4s",magicnum);
	fileline = (char*)myalloc(sizeof(char)*(MAXFIRSTLINELEN+1));
	if (fgets(fileline,MAXFIRSTLINELEN+1,fontfile)==NULL) fileline[0] = '\0';

	if (MYSTRLEN(fileline)>0 ? fileline[MYSTRLEN(fileline)-1]!='\n' : 0)
		skiptoeol(stdin);

	numsread = sscanf(fileline,"%*c%c %d %*d %d %d %d%*[ \t]%d",
		&hardblank, &charheight, &maxlen,
		&defaultmode, &cmtlines, &ffright2left
		);
	free(fileline);

	for (i=1;i<=cmtlines;i++)
		skiptoeol(fontfile);

	if (numsread<6) ffright2left = 0;
	if (charheight<1) charheight = 1;
	if (maxlen<1) maxlen = 1;
	maxlen += 100; /* Give ourselves some extra room */

	if (right2left<0) right2left = ffright2left;
	if (justification<0) justification = 2*right2left;

	fileline = (char*)myalloc(sizeof(char)*(maxlen+1));
	/* Allocate "missing" character */
	fcharlist = (fcharnode*)myalloc(sizeof(fcharnode));
	fcharlist->ord = 0;
	fcharlist->thechar = (char**)myalloc(sizeof(char*)*charheight);
	fcharlist->next = NULL;
	for (row=0;row<charheight;row++) {
		fcharlist->thechar[row] = (char*)myalloc(sizeof(char));
		fcharlist->thechar[row][0] = '\0';
		}
	for (theord=' ';theord<='~';theord++)
		readfontchar(fontfile,theord,fileline,maxlen);
	for (theord= -255;theord<= -249;theord++)
		readfontchar(fontfile,theord,fileline,maxlen);
	while (fgets(fileline,maxlen+1,fontfile)==NULL?0:sscanf(fileline,"%li",&theord)==1)
		readfontchar(fontfile,theord,fileline,maxlen);
	fclose(fontfile);
	free(fileline);
	return 0;
}
Пример #2
0
/*
 * Setup state for decoding a strip.
 */
int
DECLARE1(FaxPreDecode, TIFF*, tif)
{
    Fax3DecodeState *sp = &fax;

    sp->b.bit = 0;            /* force initial read */
    sp->b.data = 0;
    sp->b.tag = G3_1D;
    if (sp->b.refline)
        bset(sp->b.refline, sp->b.rowbytes, sp->b.white ? 0xff : 0x00);
    /*
     * If image has EOL codes, they precede each line
     * of data.  We skip over the first one here so that
     * when we decode rows, we can use an EOL to signal
     * that less than the expected number of pixels are
     * present for the scanline.
     */
    if ((fax.options & FAX3_NOEOL) == 0) {
        skiptoeol(tif, 0);
        if (is2DEncoding(tif))
            /* tag should always be 1D! */
            sp->b.tag = nextbit(tif) ? G3_1D : G3_2D;
    }
    return (1);
}
Пример #3
0
static void readfont(CString strName)
{
#define MAXFIRSTLINELEN 1000
  int i,row,numsread;
  inchr theord;
  int maxlen,cmtlines,ffright2left;
  int smush,smush2;
  char *fileline,magicnum[5];


  CStdioFile fontfile (strName, 
                        CFile::modeRead|CFile::shareDenyNone|CFile::typeText);

  readmagic(fontfile,magicnum);
  fileline = (char*)myalloc(sizeof(char)*(MAXFIRSTLINELEN+1));
  if (fontfile.ReadString(fileline,MAXFIRSTLINELEN+1)==NULL) {
    fileline[0] = '\0';
    }
  if (MYSTRLEN(fileline)>0 ? fileline[MYSTRLEN(fileline)-1]!='\n' : 0) {
    skiptoeol(fontfile);
    }
  numsread = sscanf(fileline,"%*c%c %d %*d %d %d %d %d %d",
    &hardblank,&charheight,&maxlen,&smush,&cmtlines,
    &ffright2left,&smush2);
  myfree(fileline);
  if (strcmp(magicnum,FONTFILEMAGICNUMBER) || numsread<5)
    ThrowErrorException ("Not a FIGlet 2 font file");
  for (i=1;i<=cmtlines;i++) {
    skiptoeol(fontfile);
    }

  if (numsread<6) {
    ffright2left = 0;
    }

  if (numsread<7) { /* if no smush2, decode smush into smush2 */
    if (smush == 0) smush2 = SM_KERN;
    else if (smush < 0) smush2 = 0;
    else smush2 = (smush & 31) | SM_SMUSH;
    }

  if (charheight<1) {
    charheight = 1;
    }

  if (maxlen<1) {
    maxlen = 1;
    }

  maxlen += 100; /* Give ourselves some extra room */

  if (smushoverride == SMO_NO)
     smushmode = smush2;
  else if (smushoverride == SMO_FORCE)
     smushmode |= smush2;

  if (right2left<0) {
    right2left = ffright2left;
    }

  if (justification<0) {
    justification = 2*right2left;
    }

  fileline = (char*)myalloc(sizeof(char)*(maxlen+1));
  /* Allocate "missing" character */
  fcharlist = (fcharnode*)myalloc(sizeof(fcharnode));
  fcharlist->ord = 0;
  fcharlist->thechar = (char**)myalloc(sizeof(char*)*charheight);
  fcharlist->next = NULL;
  for (row=0;row<charheight;row++) {
    fcharlist->thechar[row] = (char*)myalloc(sizeof(char));
    fcharlist->thechar[row][0] = '\0';
    }
  for (theord=' ';theord<='~';theord++) {
    readfontchar(fontfile,theord,fileline,maxlen);
    }
  for (theord=0;theord<=6;theord++) {
    readfontchar(fontfile,deutsch[theord],fileline,maxlen);
    }
  while (fontfile.ReadString(fileline,maxlen+1)==NULL?0:
    sscanf(fileline,"%li",&theord)==1) {
    readfontchar(fontfile,theord,fileline,maxlen);
    }
  myfree(fileline);
}