Exemplo n.º 1
0
void    plWinFontCache::ILoadCustomFonts( void )
{
    if( fCustFontDir == nil )
        return;

    // Iterate through all the custom fonts in our dir
    int numAdded;

    std::vector<plFileName> fonts = plFileSystem::ListDir(fCustFontDir, kCustFontExtension);
    for (auto iter = fonts.begin(); iter != fonts.end(); ++iter)
    {
        // Note that this call can be translated as "does my OS suck?"
#if (_WIN32_WINNT >= 0x0500)
        if( plDynSurfaceWriter::CanHandleLotsOfThem() )
            numAdded = AddFontResourceExW(iter->AsString().ToWchar(), FR_PRIVATE, 0);
        else
#endif
            numAdded = AddFontResourceW(iter->AsString().ToWchar());

        if( numAdded > 0 )
        {
            plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Added custom font %s, %d fonts", iter->GetFileName().c_str(), numAdded );
            fCustFonts.Append(new plCustFont(*iter));
        }
        else
        {
            plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Unable to load custom font %s", iter->GetFileName().c_str() );
        }
    }
}
Exemplo n.º 2
0
void manager::init() const
{
	LOG_FT << "Cairo version: " << cairo_version_string() << std::endl;
	LOG_FT << "Pango version: " << pango_version_string() << std::endl;

#ifdef CAIRO_HAS_FT_FONT
	if (!FcConfigAppFontAddDir(FcConfigGetCurrent(),
		reinterpret_cast<const FcChar8 *>((game_config::path + "/fonts").c_str())))
	{
		ERR_FT << "Could not load the true type fonts" << std::endl;
		throw error();
	}
#endif

#if CAIRO_HAS_WIN32_FONT
	BOOST_FOREACH(const std::string& path, filesystem::get_binary_paths("fonts")) {
		std::vector<std::string> files;
		if(filesystem::is_directory(path))
			filesystem::get_files_in_dir(path, &files, NULL, filesystem::ENTIRE_FILE_PATH);
		BOOST_FOREACH(const std::string& file, files) {
			if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc")
			{
				utf16::string ufile = unicode_cast<utf16::string>(file);
				std::wstring wfile(ufile.begin(), ufile.end());
				AddFontResourceW(wfile.c_str());
			}
		}
	}
#endif
}
Exemplo n.º 3
0
LOGFONTW* GetFontNameFromFile(LPCWSTR Filename)	//获得一个字体文件内包含的所有字体名称s
{
	LOGFONTW* logfonts = NULL;
	DWORD bufsize=0;
	if (GetFontResourceInfo(Filename, &bufsize, NULL, 2))
	{
		logfonts = (LOGFONTW*)malloc(bufsize+1);
		if (GetFontResourceInfo(Filename, &bufsize, logfonts, 2))
		{
			((char*)logfonts)[bufsize]=0;
			return logfonts;
		}
		else
		{
			free(logfonts);
			return NULL;
		}
	}
	else
	{
		AddFontResourceW(Filename);
		if (GetFontResourceInfo(Filename, &bufsize, NULL, 2))
		{
			logfonts = (LOGFONTW*)malloc(bufsize+1);
			if (GetFontResourceInfo(Filename, &bufsize, logfonts, 2))
			{
				((char*)logfonts)[bufsize]=0;
				ORIG_RemoveFontResourceExW(Filename,0,NULL);
				return logfonts;
			}
			else
			{
				free(logfonts);
				ORIG_RemoveFontResourceExW(Filename,0,NULL);
				return NULL;
			}
		}
		ORIG_RemoveFontResourceExW(Filename,0,NULL);
		return NULL;
	}
}
Exemplo n.º 4
0
int WINAPI
WinMain (HINSTANCE hThisInstance,
         HINSTANCE hPrevInstance,
         LPSTR lpCmdLine,
         int nCmdShow)
{
	int argc;
	WCHAR** argv;
	WCHAR szFileName[MAX_PATH] = L"";
	DWORD dwSize;
	HWND hMainWnd;
	MSG msg;
	WNDCLASSEXW wincl;
	LPCWSTR fileName;

    switch (GetUserDefaultUILanguage())
    {
    case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
      SetProcessDefaultLayout(LAYOUT_RTL);
      break;

    default:
      break;
    }

	g_hInstance = hThisInstance;

	/* Get unicode command line */
	argv = CommandLineToArgvW(GetCommandLineW(), &argc);
	if (argc < 2)
	{
		OPENFILENAMEW fontOpen;
        WCHAR filter[MAX_PATH], dialogTitle[MAX_PATH];

		LoadStringW(NULL, IDS_OPEN, dialogTitle, MAX_PATH);
		LoadStringW(NULL, IDS_FILTER_LIST, filter, MAX_PATH);

		/* Clears out any values of fontOpen before we use it */
		ZeroMemory(&fontOpen, sizeof(fontOpen));

		/* Sets up the open dialog box */
		fontOpen.lStructSize = sizeof(fontOpen);
		fontOpen.hwndOwner = NULL;
		fontOpen.lpstrFilter = filter;
		fontOpen.lpstrFile = szFileName;
		fontOpen.lpstrTitle = dialogTitle;
		fontOpen.nMaxFile = MAX_PATH;
		fontOpen.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
		fontOpen.lpstrDefExt = L"ttf";

		/* Opens up the Open File dialog box in order to chose a font file. */
		if(GetOpenFileNameW(&fontOpen))
		{
			fileName = fontOpen.lpstrFile;
			g_fileName = fileName;
		} else {
			/* If the user decides to close out of the open dialog effectively
			exiting the program altogether */
			return 0;
		}
	}
	else
	{
		/* Try to add the font resource from command line */
		fileName = argv[1];
		g_fileName = fileName;
	}

	if (!AddFontResourceW(fileName))
	{
		ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
		return -1;
	}

	/* Get the font name */
	dwSize = sizeof(g_ExtLogFontW.elfFullName);
	if (!GetFontResourceInfoW(fileName, &dwSize, g_ExtLogFontW.elfFullName, 1))
	{
		ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
		return -1;
	}

	dwSize = sizeof(LOGFONTW);
	if (!GetFontResourceInfoW(fileName, &dwSize, &g_ExtLogFontW.elfLogFont, 2))
	{
		ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
		return -1;
	}

	if (!Display_InitClass(hThisInstance))
	{
		ErrorMsgBox(0, IDS_ERROR_NOCLASS);
		return -1;
	}

	/* The main window class */
	wincl.cbSize = sizeof (WNDCLASSEXW);
	wincl.style = CS_DBLCLKS;
	wincl.lpfnWndProc = MainWndProc;
	wincl.cbClsExtra = 0;
	wincl.cbWndExtra = 0;
	wincl.hInstance = hThisInstance;
	wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT));
	wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
	wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
	wincl.lpszMenuName = NULL;
	wincl.lpszClassName = g_szFontViewClassName;
	wincl.hIconSm = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT));

	/* Register the window class, and if it fails quit the program */
	if (!RegisterClassExW (&wincl))
	{
		ErrorMsgBox(0, IDS_ERROR_NOCLASS);
		return 0;
	}

	/* The class is registered, let's create the main window */
	hMainWnd = CreateWindowExW(
				0,						/* Extended possibilites for variation */
				g_szFontViewClassName,	/* Classname */
				g_ExtLogFontW.elfFullName,/* Title Text */
				WS_OVERLAPPEDWINDOW,	/* default window */
				CW_USEDEFAULT,			/* Windows decides the position */
				CW_USEDEFAULT,			/* where the window ends up on the screen */
				544,					/* The programs width */
				375,					/* and height in pixels */
				HWND_DESKTOP,			/* The window is a child-window to desktop */
				NULL,					/* No menu */
				hThisInstance,			/* Program Instance handler */
				NULL					/* No Window Creation data */
			);
	ShowWindow(hMainWnd, nCmdShow);

	/* Main message loop */
	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	RemoveFontResourceW(argv[1]);

	return (int)msg.wParam;
}
Exemplo n.º 5
0
    bool setFont(const char * pFontName = NULL, int nSize = 0)
    {
        bool bRet = false;
        do
        {
            std::string fontName = pFontName;
            std::string fontPath;
            HFONT       hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
            LOGFONTA    tNewFont = {0};
            LOGFONTA    tOldFont = {0};
            GetObjectA(hDefFont, sizeof(tNewFont), &tNewFont);
            if (fontName.c_str())
            {
                // create font from ttf file
                int nFindttf = fontName.find(".ttf");
                int nFindTTF = fontName.find(".TTF");
                if (nFindttf >= 0 || nFindTTF >= 0)
                {
                    fontPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(fontName.c_str());
                    int nFindPos = fontName.rfind("/");
                    fontName = &fontName[nFindPos+1];
                    nFindPos = fontName.rfind(".");
                    fontName = fontName.substr(0,nFindPos);
                }
                else
                {
                    size_t nFindPos = fontName.rfind("/");
                    if (nFindPos != fontName.npos)
                    {
                        if (fontName.length() == nFindPos + 1)
                        {
                            fontName = "";
                        }
                        else
                        {
                            fontName = &fontName[nFindPos+1];
                        }
                    }
                }
                tNewFont.lfCharSet = DEFAULT_CHARSET;
#if defined(__MINGW32__)
                strcpy(tNewFont.lfFaceName, fontName.c_str());
#elif defined(_MSC_VER) && _MSC_VER <= 1200
                strcpy(tNewFont.lfFaceName, fontName.c_str());
#else
                strcpy_s(tNewFont.lfFaceName, LF_FACESIZE, fontName.c_str());
#endif
            }
            if (nSize)
            {
                tNewFont.lfHeight = -nSize;
            }
            GetObjectA(m_hFont,  sizeof(tOldFont), &tOldFont);

            if (tOldFont.lfHeight == tNewFont.lfHeight
                    && 0 == strcmp(tOldFont.lfFaceName, tNewFont.lfFaceName))
            {
                // already has the font
                bRet = true;
                break;
            }

            // delete old font
            if (m_hFont != hDefFont)
            {
                DeleteObject(m_hFont);
                // release old font register
                if (m_curFontPath.size() > 0)
                {
                    wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
                    if (pwszBuffer)
                    {
                        if(RemoveFontResourceW(pwszBuffer))
                        {
                            SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
                        }
                        delete [] pwszBuffer;
                        pwszBuffer = NULL;
                    }
                }
                if (fontPath.size() > 0)
                    m_curFontPath = fontPath;
                else
#if defined(_MSC_VER) && _MSC_VER <= 1200
                    m_curFontPath.erase();
#else
                    m_curFontPath.clear();
#endif
                // register temp font
                if (m_curFontPath.size() > 0)
                {
                    wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
                    if (pwszBuffer)
                    {
                        if(AddFontResourceW(pwszBuffer))
                        {
                            SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
                        }
                        delete [] pwszBuffer;
                        pwszBuffer = NULL;
                    }
                }
            }
            m_hFont = NULL;

            // disable Cleartype
            tNewFont.lfQuality = ANTIALIASED_QUALITY;

            // create new font
            m_hFont = CreateFontIndirectA(&tNewFont);
            if (! m_hFont)
            {
                // create failed, use default font
                m_hFont = hDefFont;
                break;
            }

            bRet = true;
        } while (0);
        return bRet;
    }