Ejemplo n.º 1
0
/*******************************************************************************
 *  ReadTrueTypeFile
 *
 *  Reads font metrics from TrueType font file.  Only returns FALSE for
 *  unexpected errors (memory allocation failure or FreeType error).
 *
 */
static BOOL ReadTrueTypeFile(FT_Library library, LPCSTR filename)
{
    FT_Error	    error;
    FT_Face 	    face;

    TRACE("%s\n", filename);

    error = pFT_New_Face(library, filename, 0, &face);
    if (error != FT_Err_Ok)
    {
    	WARN("FreeType error %i opening %s\n", error, filename);
	return TRUE;
    }

    if ((face->face_flags & REQUIRED_FACE_FLAGS) == REQUIRED_FACE_FLAGS)
    {
    	if (BuildTrueTypeAFM(face) == FALSE)
	{
	    pFT_Done_Face(face);
	    return FALSE;
	}
    }
    else
    {
    	WARN("Required information missing from %s\n", filename);
    }

    error = pFT_Done_Face(face);
    if (error != FT_Err_Ok)
    {
    	ERR("%s returned %i\n", "FT_Done_Face", error);
	return FALSE;
    }

    return TRUE;
}
Ejemplo n.º 2
0
bool CText::BuildFTFont(const char *name, int size)
{
	if (!FreeType_loaded)
		return false;

	if (loaded)
	{
		Free();
	}

	UseFT=true;

	bool smallfont=(size<FT_FONT_SIZE_THRESHOLD && ALLOW_FONT_SCALING==true);
	if (smallfont)
	{
		sizescale=(float)((double)size/(double)FT_FONT_SIZE_THRESHOLD);
		size=FT_FONT_SIZE_THRESHOLD;
	}

	char fontpath[MAX_PATH];
	GetWindowsDirectory(fontpath,sizeof(fontpath));
	strcat(fontpath,"\\FONTS\\");
	strcat(fontpath,name);
	strcat(fontpath,".TTF");

	FT_Library library;
	if (pFT_Init_FreeType(&library))
		return false;

	FT_Face face;
	if (pFT_New_Face(library,fontpath,0,&face))
	{
		pFT_Done_FreeType(library);
		return false;
	}
	pFT_Set_Char_Size(face,size<<6,size<<6,96,96);

	listbase=glGenLists(NUM_CHARS);
	glGenTextures(NUM_CHARS,(GLuint*)FT_tex);

	loaded=true;
	for(int i=0;i<NUM_CHARS;i++)
	{
		if (!MakeFTChar(face, i, listbase, FT_tex, charsize, smallfont))
		{
			loaded=false;
			break;
		}
	}

	pFT_Done_Face(face);
	pFT_Done_FreeType(library);

	if (loaded)
	{
		charheight=(float)size;
	}
	else
	{
		Free();
	}

	return loaded;
}