示例#1
0
void    plWinFontCache::Clear( void )
{
    int     i;


    if( !fInShutdown )
        plStatusLog::AddLineS( "pipeline.log", "** Clearing Win32 font cache **" );

    for( i = 0; i < fFontCache.GetCount(); i++ )
        DeleteObject( fFontCache[ i ].fFont );
    fFontCache.Reset();

    for( i = 0; i < fFontNameCache.GetCount(); i++ )
        delete [] fFontNameCache[ i ];
    fFontNameCache.Reset();

    for( i = 0; i < fCustFonts.GetCount(); i++ )
    {
#if (_WIN32_WINNT >= 0x0500)
        if (plDynSurfaceWriter::CanHandleLotsOfThem())
            RemoveFontResourceExW(fCustFonts[i]->fFilename.AsString().ToWchar(), FR_PRIVATE, 0);
        else
#endif
            if (RemoveFontResourceW(fCustFonts[i]->fFilename.AsString().ToWchar()) == 0)
            {
                int q= 0;
                DWORD e = GetLastError();
            }
        delete fCustFonts[ i ];
    }
    fCustFonts.Reset();
}
示例#2
0
 ~BitmapDC()
 {
     prepareBitmap(0, 0);
     if (m_hDC)
     {
         DeleteDC(m_hDC);
     }
     HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
     if (hDefFont != m_hFont)
     {
         DeleteObject(m_hFont);
         m_hFont = hDefFont;
     }
     // release temp font resource
     if (m_curFontPath.size() > 0)
     {
         wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
         if (pwszBuffer)
         {
             RemoveFontResourceW(pwszBuffer);
             SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
             delete [] pwszBuffer;
             pwszBuffer = NULL;
         }
     }
 }
示例#3
0
文件: font.cpp 项目: dailin/wesnoth
void manager::deinit() const
{
#ifdef CAIRO_HAS_FT_FONT
	FcConfigAppFontClear(FcConfigGetCurrent());
#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());
				RemoveFontResourceW(wfile.c_str());
			}
		}
	}
#endif
}
示例#4
0
文件: fontview.c 项目: GYGit/reactos
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;
}
示例#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;
    }