Example #1
0
int Font::Load(char *name)
{
	// Get the font path
	int c, i, l;
	char path[PATH_LENGTH] = { '\0' };
	l = (int) strlen(name)-1;
	while (l >= 0 && name[l] != '\\' && name[l] != '/') --l;
	for (i = 0; i <= l && i < PATH_LENGTH; ++i) path[i] = name[i];

	// Parse the font descriptor file
	Parser p;
	p.StartParseFile(name);

	// read the mapname
	p.GetToken();
	char fullmapname[PATH_LENGTH] = { '\0' };
	sprintf(fullmapname, "%s%s", path, p.token);
	if (!charmap.LoadImage(fullmapname)) return 0;

	float w = (float) charmap.GetWidth();
	float h = (float) charmap.GetHeight();

	// read the font height
	p.GetToken();
	tHeight = (float) atof(p.token);
	height = (int) tHeight;
	tHeight /= h;
	SetRatio(1.f);
	SetScale(1.f);

	// read the characters parameters
	while (p.GetToken())
	{
		p.Assert("{");
		p.GetToken(); c = (int) atoi(p.token);						// read the character value
		p.GetToken(); tPoints[c][0] = ((float) atof(p.token))/w;	// character x position
		p.GetToken(); tPoints[c][1] = 1.f-((float) atof(p.token))/h-tHeight;	// character y position
		p.GetToken(); tWidth[c] = ((float) atof(p.token));			// character width
		width[c] = (int) tWidth[c];
		tWidth[c] /= w;
		p.GetToken(); p.Assert("}");
	}

	p.StopParse();

	return 1;
}