Ejemplo n.º 1
0
Archivo: vec3vecp.c Proyecto: pigay/vsg
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;
  VsgVector3d v, w, res, ref;

  if (argc > 1 && g_ascii_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  vsg_vector3d_set (&v, 1, 0, 0);
  vsg_vector3d_set (&w, 0, 1, 0);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, 0, 0, 1);
  ret += vcheck ("[1, 0, 0] ^ [0, 1, 0] == [0, 0, 1]", &res, &ref);

  vsg_vector3d_set (&v, 1, 2, 3);
  vsg_vector3d_set (&w, 0.1, 0.2, 0.3);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, 0, 0, 0);
  ret += vcheck ("[1, 2, 3] ^ [0.1, 0.2, 0.3] == [0, 0, 0]", &res, &ref);

  vsg_vector3d_set (&v, 1.2e-2, 0, 0);
  vsg_vector3d_set (&w, 1.2e-3, 0, 0);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, 0, 0, 0);
  ret += vcheck ("[1.2e-2, 0, 0] ^ [1.2e-3, 0, 0] == [0, 0, 0]", &res, &ref);

  vsg_vector3d_set (&v, 0, 0, 0);
  vsg_vector3d_set (&w, 0, 0, 0);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, 0, 0, 0);
  ret += vcheck ("[0, 0, 0] ^ [0, 0, 0] == [0, 0, 0]", &res, &ref);

  vsg_vector3d_set (&v, 1, 1, 1);
  vsg_vector3d_set (&w, 1, 2.123, 0);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, -2.123, 1, 1.123);
  ret += vcheck ("[1, 1, 1] ^ [1, 2.123, 0] == [-2.123, 1, 1.123]", &res,
                 &ref);

  return ret;
}
Ejemplo n.º 2
0
int sol(int y, int x)
{
	int s, c;

	if (y < 0 || x < 0 || y >= m || x >= n)
		return 0;

	c = a[y][x];

	for (s = 1; (y - s) >= 0 && (x - s) >= 0 && (y + s) < m && (x + s) < n; s++) {
		if (hcheck(y - s, x - s, 2 * s + 1, c) ||
		    hcheck(y + s, x - s, 2 * s + 1, c) ||
		    vcheck(y - s, x - s, 2 * s + 1, c) ||
		    vcheck(y - s, x + s, 2 * s + 1, c))
			break;
	}

	return 2 * s - 1;
}
Ejemplo n.º 3
0
void makeextent(void) {
    int c, len;
    BOOL inmetric = TRUE;
    char *key, *value, *p;
    pfm.dfFirstChar = 255;
    pfm.dfLastChar = 0;
    if (strncmp(line, "StartCharMetrics",16)!=0) {
        fprintf(stderr,"Error on line %d, expecting StartCharMetrics\n",linecount);
        exit(2);
    }
    while ( inmetric && (fgets(line, sizeof(line), inf)!=(char *)NULL) ) {
    	linecount++;
	lcheck();
    	c = 0;
        key = line;
	value = strchr(line, '\n');
	if (value)
	    *value = '\0';	/* remove trailine \n */
        if (strcmp(key, "EndCharMetrics")==0) {
            pfm.dfAvgWidth = sumwidth / (pfm.dfLastChar - pfm.dfFirstChar + 1); /* wrong - should be weighted */
            pfm.dfMaxWidth = maxwidth;
            inmetric = FALSE;
        }
	key = strtok(line, ";");
	while (inmetric && key) {
	    while (*key == ' ')
		key++;
	    value = strchr(key,' ');
	    if (value)
	        value++;
	    while (value && (*value == ' '))
		value++;
	    if (strncmp(key, "C ", 2)==0) {
	        vcheck(key, value);
	        c = atoi(value);
	        if ((c>0) && (c<pfm.dfFirstChar))
	            pfm.dfFirstChar = c;
	        if ((c>0) && (c>pfm.dfLastChar))
	            pfm.dfLastChar = c;
	        if ( (c<0) && warnflag )
	    	    fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
	    }
	    else if (strncmp(key, "WX ",3)==0) {
	        vcheck(key, value);
	        if (c>=0) {
	            extent[c] = atoi(value);
		    sumwidth += extent[c];
		    if (extent[c] > maxwidth)
		        maxwidth = extent[c];
	        }
	    }
	    else if (strncmp(key, "N ",2)==0) {
		vcheck(key, value);
	        if (c>=0) {
		    p = strchr(value, ' ');
		    if (p)
		        len = p - value;
	            else
	                len = strlen(value);
	            if ( (len+1) < BUFSIZE-(ntail-nbuffer) ) {
	                name[c] = ntail;
	                strncpy(ntail, value, len);
	                ntail += len;
	                *ntail++ = '\0';
	            }
	            else {
	                fprintf(stderr,"Error on line %d: out of memory for names\n",
	                    linecount);
	                exit(2);
	            }
		}
	    }
	    else if (strncmp(key, "B ",2)==0) {
		vcheck(key, value);
	        if (c>=0) {
	            if (sscanf(value,"%d %d %d %d", &cbbox[c].llx, &cbbox[c].lly, 
				&cbbox[c].urx, &cbbox[c].ury)!=4) {
	    	        fprintf(stderr,"Error on line %d, missing BoundingBox value\n",linecount);
		        exit(2);
	            }
		}
	    }
	    else if (strncmp(key, "L ",2)==0) {
	    	/* ignore it */
	    }
	    else {
		if (warnflag)
	    	    fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
	    }
	    key = strtok(NULL, ";");
	}
    }
    fgets(line, sizeof(line), inf);
    linecount++;
    lcheck();
    if (pfm.dfFirstChar > pfm.dfLastChar)
	pfm.dfFirstChar = pfm.dfLastChar;
    /* now fix up some dimensions */
    if (pfm.dfMaxWidth == 0)
	pfm.dfMaxWidth = fbbox.urx - fbbox.llx;	/* guess from font bbox */
    pfm.dfAscent = fbbox.ury;
    if ((pfm.dfCharSet==0) && name['d'] && *name['d'] && (strcmp(name['d'], "d")==0) && (cbbox['d'].ury))
        etm.etmLowerCaseAscent = cbbox['d'].ury;
    else {
	if (ascender) {
	    if (warnflag)
	        fprintf(stderr,"Warning: setting lower case ascent from AFM Ascender\n");
            etm.etmLowerCaseAscent = ascender;
	}
	else {
	    if (warnflag)
	        fprintf(stderr,"Warning: setting lower case ascent from font bounding box\n");
            etm.etmLowerCaseAscent = fbbox.ury;
        }
    }
    if ((pfm.dfCharSet==0) && name['p'] && *name['p'] && (strcmp(name['p'], "p")==0) && (cbbox['p'].lly))
        etm.etmUpperCaseDescent = cbbox['p'].lly;
    else {
	if (descender) {
	    if (warnflag)
	        fprintf(stderr,"Warning: setting upper case descent from AFM Descender\n");
            etm.etmUpperCaseDescent = descender;
	}
	else {
	    if (warnflag)
	        fprintf(stderr,"Warning: setting upper case descent from font bounding box\n");
            etm.etmUpperCaseDescent = fbbox.lly;
        }
    }
    if ((etm.etmXHeight==0) && (pfm.dfCharSet==0) && *name['x'] && 
        (strcmp(name['x'], "x")==0) && (cbbox['x'].ury))
        etm.etmXHeight = cbbox['x'].ury;
    if ((etm.etmCapHeight==0) && (pfm.dfCharSet==0) && *name['H'] && 
        (strcmp(name['H'], "H")==0) && (cbbox['H'].ury))
        etm.etmCapHeight = cbbox['H'].ury;
    pfm.dfPixHeight = fbbox.ury - fbbox.lly;
    pfm.dfPixWidth  = fbbox.urx - fbbox.llx;
    makeaverage();
}
Ejemplo n.º 4
0
/* ignores kern track info */
void makekern(void) {
    BOOL inkern = TRUE;
    BOOL inpair = FALSE;
    BOOL intrack = FALSE;
    char *key, *value, *p, *pair1, *pair2;
    int i, c1, c2, kerncount, kerncount2;
    key = line;
    value = strchr(line, '\n');
    if (value)
        *value = '\0';	/* remove trailine \n */
    if (strncmp(key, "StartKernData",13)!=0)
	return;
    while ( inkern && (fgets(line, sizeof(line), inf)!=(char *)NULL) ) {
    	linecount++;
	lcheck();
	value = strchr(line, '\n');
	if (value)
	    *value = '\0';	/* remove trailine \n */
        if (strcmp(key, "EndKernData")==0) {
            inkern = FALSE;
            if (inpair && warnflag)
		fprintf(stderr,"Warning on line %d, expecting EndKernPairs\n",linecount);
            continue;
        }
        else if (strncmp(key, "StartKernTrack", 14)==0) {
	    intrack = TRUE;
	    if (warnflag)
	        fprintf(stderr,"Warning on line %d, ignoring StartKernTrack\n",linecount);
	}
        else if (strcmp(key, "EndKernTrack")==0) {
	    intrack = FALSE;
	}
        else if (strncmp(key, "StartKernPairs", 14)==0) {
            inpair = TRUE;
	    value = strchr(line, ' ');
	    vcheck(key, value);
	    kerncount = atoi(value);
	    kerncount2 = 0;
	    continue;
        }
        else if (strcmp(key, "EndKernPairs")==0) {
            inpair = FALSE;
            etm.etmKernPairs = ckernpair;
            continue;
        }
        else if (inpair) {
	    key = strtok(line, " ");
	    if (!key)
	        continue;
	    if (strcmp(key, "KPX")==0) {
	        pair1 = strtok(NULL," ");
	        vcheck(key, pair1);
	        pair2 = strtok(NULL," ");
	        vcheck(key, pair2);
	        value = strtok(NULL," ");
	        vcheck(key, value);
	        c1 = c2 = -1;
	        for (i = 0; i < 256; i++)
	            if (name[i] && (strcmp(name[i],pair1)==0)) {
	                c1 = i;
	                break;
	            }
	        for (i = 0; i < 256; i++)
	            if (name[i] && (strcmp(name[i],pair2)==0)) {
	                c2 = i;
	                break;
	            }
		kerncount2++;
		if (kerncount2 > kerncount) {
		    if (warnflag)
	    	        fprintf(stderr,"Warning on line %d, too many kern pairs, ignoring extras\n",linecount);
		}
		else if (ckernpair > sizeof(kernpair)/sizeof(KERNPAIR)) {
		    if (warnflag)
	    	        fprintf(stderr,"Warning on line %d, too many kern pairs, ignoring extras\n",linecount);
		}
		else if (c1==-1) {
		    if (warnflag)
	    	        fprintf(stderr,"Warning on line %d, ignoring kerning for unencoded character: %s\n",linecount, pair1);
		}
		else if (c2==-1) {
		    if (warnflag)
	    	        fprintf(stderr,"Warning on line %d, ignoring kerning for unencoded character: %s\n",linecount, pair2);
		}
		else {
		    kernpair[ckernpair].kpPair.each[0] = c1;
		    kernpair[ckernpair].kpPair.each[1] = c2;
		    kernpair[ckernpair].kpKernAmount = atoi(value);
		    ckernpair++;
		}
	    }
	    else {
		if (warnflag)
	    	    fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
	    }
	    if (pair1)
	        value++;
	    while (value && (*value == ' '))
		value++;
        }
	else if (intrack) {
	    /* ignore it */
	}
	else {
	    if (warnflag)
    	        fprintf(stderr,"Warning on line %d, ignoring %s\n",linecount,key);
	}
    }
    fgets(line, sizeof(line), inf);
    linecount++;
    lcheck();
}
Ejemplo n.º 5
0
void makeheader(void) {
    BOOL inhdr = TRUE;
    BOOL isafm = FALSE;
    BOOL gotcopyright = FALSE;
    char *key, *value;
    key = line;
    while ( inhdr && (fgets(line, sizeof(line), inf)!=(char *)NULL) ) {
    	linecount++;
	lcheck();
	value = strchr(line, '\n');
	if (value)
	    *value = '\0';	/* remove trailine \n */
	value = strchr(line, ' ');
	if (value)
	    *value++ = '\0';	/* separate key from value */
	if (strcmp(key, "StartFontMetrics")==0) {
	    isafm = TRUE;
	    vcheck(key, value);
	    continue;
	}
	if (!isafm) {
	    fputs("Error: Not an AFM file\n", stderr);
	    exit(2);
	}
	if (strcmp(key, "FontName")==0) {
	    vcheck(key, value);
	    strcpy(fontname, value);
	    if (strstr(fontname, "Italic")!=(char *)NULL)
		pfm.dfItalic = 1;
	}
	else if (strcmp(key, "FamilyName")==0) {
	    vcheck(key, value);
	    strcpy(facename, value);
	    /* should scan name and guess dfPitchAndFamily field */
	}
	else if (strcmp(key, "Notice")==0) {
	    vcheck(key, value);
	    strncpy(pfm.dfCopyright, value, sizeof(pfm.dfCopyright)-1);
	}
	else if (strcmp(key, "EncodingScheme")==0) {
		vcheck(key, value);
		if (strcmp(value, "AdobeStandardEncoding")!=0)
		    pfm.dfCharSet = 2;   /* use Symbol */
	}
	else if (strcmp(key, "Weight")==0) {
	    vcheck(key, value);
	    if (strcmp(value,"Bold")==0)
	    	pfm.dfWeight = 700;
	    else if (strcmp(value,"Light")==0)
	        pfm.dfWeight = 300;
	    else
	        pfm.dfWeight = 400;
	}
	else if (strcmp(key, "IsFixedPitch")==0) {
	    vcheck(key, value);
	    if (strcmp(value,"false")==0) 
	        pfm.dfPitchAndFamily |= 1;	/* variable width */
	}
	else if (strcmp(key, "FontBBox")==0) {
	    vcheck(key, value);
	    if (sscanf(value,"%d %d %d %d", &fbbox.llx, &fbbox.lly, &fbbox.urx, &fbbox.ury)!=4) {
	    	fprintf(stderr,"Error on line %d, missing value\n",linecount);
		exit(2);
	    }
	}
	else if (strcmp(key, "CapHeight")==0) {
	    vcheck(key, value);
	    etm.etmCapHeight = atoi(value);
	}
	else if (strcmp(key, "XHeight")==0) {
	    vcheck(key, value);
	    etm.etmXHeight = atoi(value);
	}
	else if (strcmp(key, "Ascender")==0) {
	    vcheck(key, value);
	    ascender = atoi(value);
	}
	else if (strcmp(key, "Descender")==0) {
	    vcheck(key, value);
	    descender = atoi(value);
	}
	else if (strcmp(key, "ItalicAngle")==0) {
	    vcheck(key, value);
	    etm.etmSlant = (short)(atof(value)*10);
	    if (etm.etmSlant)
		pfm.dfItalic = 1;
	}
	else if (strcmp(key, "UnderlinePosition")==0) {
	    vcheck(key, value);
	    etm.etmUnderlineOffset = -atoi(value);
	}
	else if (strcmp(key, "UnderlineThickness")==0) {
	    vcheck(key, value);
	    etm.etmUnderlineWidth = atoi(value);
	}
	else if (strcmp(key, "StartCharMetrics")==0) {
	    vcheck(key, value);
	    charcount = atoi(value);
	    inhdr = FALSE;
	}
	else if (strcmp(key, "FullName")==0) {
	    /* nop */
	}
	else if (strcmp(key, "Comment")==0) {
	    /* nop */
	}
	else if (strcmp(key, "Version")==0) {
	    /* nop */
	}
    	else {
	    if (warnflag) {
		fprintf(stderr,"Warning on line %d: Unknown key: %s ",linecount,key);
    	        if (value)
    	           fputs(value,stderr);
	        fputc('\n',stderr);
	    }
    	}
    }
    /* time for StartCharMetric */
}