コード例 #1
0
ファイル: Text.cpp プロジェクト: vsemionov/solar-space
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;
}
コード例 #2
0
ファイル: truetype.c プロジェクト: howard5888/wineT
/*******************************************************************************
 *  PSDRV_GetTrueTypeMetrics
 *
 *  Reads font metrics from TrueType font files in directories listed in the
 *  [TrueType Font Directories] section of the Wine configuration file.
 *
 *  If this function fails (returns FALSE), the driver will fail to initialize
 *  and the driver heap will be destroyed, so it's not necessary to HeapFree
 *  everything in that event.
 *
 */
BOOL PSDRV_GetTrueTypeMetrics(void)
{
    static const WCHAR pathW[] = {'P','a','t','h',0};
    FT_Error	error;
    FT_Library	library;
    HKEY hkey;
    DWORD len;
    LPWSTR valueW;
    LPSTR valueA, ptr;

    /* @@ Wine registry key: HKCU\Software\Wine\Fonts */
    if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Fonts", &hkey) != ERROR_SUCCESS)
        return TRUE;

    ft_handle = wine_dlopen(SONAME_LIBFREETYPE, RTLD_NOW, NULL, 0);
    if(!ft_handle) {
        WINE_MESSAGE(
      "Wine cannot find the FreeType font library.  To enable Wine to\n"
      "use TrueType fonts please install a version of FreeType greater than\n"
      "or equal to 2.0.5.\n"
      "http://www.freetype.org\n");
        RegCloseKey(hkey);
	return TRUE;
    }

#define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(ft_handle, #f, NULL, 0)) == NULL) goto sym_not_found;
    LOAD_FUNCPTR(FT_Done_Face)
    LOAD_FUNCPTR(FT_Done_FreeType)
    LOAD_FUNCPTR(FT_Get_Char_Index)
    LOAD_FUNCPTR(FT_Get_Glyph_Name)
    LOAD_FUNCPTR(FT_Get_Sfnt_Name)
    LOAD_FUNCPTR(FT_Get_Sfnt_Name_Count)
    LOAD_FUNCPTR(FT_Get_Sfnt_Table)
    LOAD_FUNCPTR(FT_Init_FreeType)
    LOAD_FUNCPTR(FT_Load_Glyph)
    LOAD_FUNCPTR(FT_New_Face)
    LOAD_FUNCPTR(FT_Set_Charmap)
#undef LOAD_FUNCPTR

    error = pFT_Init_FreeType(&library);
    if (error != FT_Err_Ok)
    {
    	ERR("%s returned %i\n", "FT_Init_FreeType", error);
	wine_dlclose(ft_handle, NULL, 0);
	RegCloseKey(hkey);
	return FALSE;
    }

    if (RegQueryValueExW( hkey, pathW, NULL, NULL, NULL, &len ) == ERROR_SUCCESS)
    {
        len += sizeof(WCHAR);
        valueW = HeapAlloc( GetProcessHeap(), 0, len );
        if (RegQueryValueExW( hkey, pathW, NULL, NULL, (LPBYTE)valueW, &len ) == ERROR_SUCCESS)
        {
            len = WideCharToMultiByte( CP_UNIXCP, 0, valueW, -1, NULL, 0, NULL, NULL );
            valueA = HeapAlloc( GetProcessHeap(), 0, len );
            WideCharToMultiByte( CP_UNIXCP, 0, valueW, -1, valueA, len, NULL, NULL );
            TRACE( "got font path %s\n", debugstr_a(valueA) );
            ptr = valueA;
            while (ptr)
            {
                LPSTR next = strchr( ptr, ':' );
                if (next) *next++ = 0;
                ReadTrueTypeDir( library, ptr );
                ptr = next;
            }
            HeapFree( GetProcessHeap(), 0, valueA );
        }
        HeapFree( GetProcessHeap(), 0, valueW );
    }

    RegCloseKey(hkey);
    pFT_Done_FreeType(library);
    wine_dlclose(ft_handle, NULL, 0);
    ft_handle = NULL;
    return TRUE;

sym_not_found:
    WINE_MESSAGE(
      "Wine cannot find certain functions that it needs inside the FreeType\n"
      "font library.  To enable Wine to use TrueType fonts please upgrade\n"
      "FreeType to at least version 2.0.5.\n"
      "http://www.freetype.org\n");
    RegCloseKey(hkey);
    wine_dlclose(ft_handle, NULL, 0);
    ft_handle = NULL;
    return TRUE;
}