Beispiel #1
0
void Test_AddFontResourceExW()
{
	WCHAR szFileName[MAX_PATH];
	int result;

	/* Test NULL filename */
	SetLastError(ERROR_SUCCESS);

	/* Windows crashes, need SEH here */
	_SEH2_TRY
	{
    	result = AddFontResourceExW(NULL, 0, 0);
	}
	_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
	{
	    result = -1;
	    SetLastError(_SEH2_GetExceptionCode());
	}
	_SEH2_END
	ok(result == -1, "AddFontResourceExW should throw an exception!, result == %d\n", result);
	ok(GetLastError() == 0xc0000005, "GetLastError()==%lx\n", GetLastError());

	/* Test "" filename */
	SetLastError(ERROR_SUCCESS);
	result = AddFontResourceExW(L"", 0, 0);
	ok(result == 0, "AddFontResourceExW(L"", 0, 0) succeeded, result==%d\n", result);
	ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()==%ld\n", GetLastError());

	GetEnvironmentVariableW(L"systemroot", szFileName, MAX_PATH);
	wcscat(szFileName, L"\\Fonts\\cour.ttf");

	/* Test flags = 0 */
	SetLastError(ERROR_SUCCESS);
	result = AddFontResourceExW(szFileName, 0, 0);
	ok(result == 1, "AddFontResourceExW(L"", 0, 0) failed, result==%d\n", result);
	ok(GetLastError() == ERROR_SUCCESS, "GetLastError()==%ld\n", GetLastError());

	SetLastError(ERROR_SUCCESS);
	result = AddFontResourceExW(szFileName, 256, 0);
	ok(result == 0, "AddFontResourceExW(L"", 0, 0) failed, result==%d\n", result);
	ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()==%ld\n", GetLastError());

	/* Test invalid pointer as last parameter */
	result = AddFontResourceExW(szFileName, 0, (void*)-1);
	ok(result != 0, "AddFontResourceExW(L"", 0, 0) failed, result==%d\n", result);
	ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()==%ld\n", GetLastError());

}
Beispiel #2
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() );
        }
    }
}
Beispiel #3
0
FskErr winTextAddFontFile(FskTextEngineState state, const char *path)
{
	FskErr err;
	WCHAR *nativePath = NULL;

	err = FskFilePathToNative(path, (char **)&nativePath);
	BAIL_IF_ERR(err);

	if (0 == AddFontResourceExW(nativePath, FR_PRIVATE, 0))
		BAIL(kFskErrOperationFailed);

bail:
	FskMemPtrDispose(nativePath);

	return err;
}
Beispiel #4
0
manager::manager()
{
#ifdef CAIRO_HAS_FT_FONT
    std::string font_path = game_config::path + "/fonts";
    if (!FcConfigAppFontAddDir(FcConfigGetCurrent(),
                               reinterpret_cast<const FcChar8 *>(font_path.c_str())))
    {
        ERR_FT << "Could not load the true type fonts" << std::endl;
        throw font::error("font config lib failed to add the font path: '" + font_path + "'");
    }

    std::string font_file = font_path + "/fonts.conf";
    if(!FcConfigParseAndLoad(FcConfigGetCurrent(),
                             reinterpret_cast<const FcChar8*>(font_file.c_str()),
                             FcFalse))
    {
        ERR_FT << "Could not load local font configuration\n";
        throw font::error("font config lib failed to find font.conf: '" + font_file + "'");
    }
    else
    {
        LOG_FT << "Local font configuration loaded\n";
    }
#endif

#if CAIRO_HAS_WIN32_FONT
    for(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, nullptr, filesystem::ENTIRE_FILE_PATH);
        }
        for(const std::string& file : files) {
            if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc")
            {
                const std::wstring wfile = unicode_cast<std::wstring>(file);
                AddFontResourceExW(wfile.c_str(), FR_PRIVATE, nullptr);
            }
        }
    }
#endif
}
Beispiel #5
0
// TD-2013-07-01 [[ DynamicFonts ]]
bool MCScreenDC::loadfont(MCStringRef p_path, bool p_globally, void*& r_loaded_font_handle)
{
	bool t_success = true;
    DWORD t_private = NULL;
    
    if (!p_globally)
        t_private = FR_PRIVATE;
    
	if (t_success)
		t_success = (MCS_exists(p_path, true) == True);
	
    MCAutoStringRefAsWString t_wide_path;
    if (t_success)
        t_success = t_wide_path . Lock(p_path);
    
	if (t_success)
		t_success = (AddFontResourceExW(*t_wide_path, t_private, 0) != 0);
    
	if (t_success && p_globally)
		PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
    
	return t_success;
}
 int  WINAPI MyAddFontResourceExA( __in LPCSTR name, __in DWORD fl, __reserved PVOID res        )
 {
     return AddFontResourceExW( FromUTF8( name ), fl, res );
 }
Beispiel #7
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    int fontsize = 16;
    std::string typeface;
    int map_fontwidth = 8;
    int map_fontheight = 16;
    int map_fontsize = 16;
    std::string map_typeface;
    int overmap_fontwidth = 8;
    int overmap_fontheight = 16;
    int overmap_fontsize = 16;
    std::string overmap_typeface;
    bool fontblending;

    std::ifstream jsonstream(FILENAMES["fontdata"].c_str(), std::ifstream::binary);
    if (jsonstream.good()) {
        JsonIn json(jsonstream);
        JsonObject config = json.get_object();
        // fontsize, fontblending, map_* are ignored in wincurse.
        fontwidth = config.get_int("fontwidth", fontwidth);
        fontheight = config.get_int("fontheight", fontheight);
        typeface = config.get_string("typeface", typeface);
        jsonstream.close();
    } else { // User fontdata is missed. Try to load legacy fontdata.
        // Get and save all values. With unused.
        std::ifstream InStream(FILENAMES["legacy_fontdata"].c_str(), std::ifstream::binary);
        if(InStream.good()) {
            JsonIn jIn(InStream);
            JsonObject config = jIn.get_object();
            fontwidth = config.get_int("fontwidth", fontwidth);
            fontheight = config.get_int("fontheight", fontheight);
            fontsize = config.get_int("fontsize", fontsize);
            typeface = config.get_string("typeface", typeface);
            map_fontwidth = config.get_int("map_fontwidth", fontwidth);
            map_fontheight = config.get_int("map_fontheight", fontheight);
            map_fontsize = config.get_int("map_fontsize", fontsize);
            map_typeface = config.get_string("map_typeface", typeface);
            overmap_fontwidth = config.get_int("overmap_fontwidth", fontwidth);
            overmap_fontheight = config.get_int("overmap_fontheight", fontheight);
            overmap_fontsize = config.get_int("overmap_fontsize", fontsize);
            overmap_typeface = config.get_string("overmap_typeface", typeface);
            InStream.close();
            // Save legacy as user fontdata.
            assure_dir_exist(FILENAMES["config_dir"]);
            std::ofstream OutStream(FILENAMES["fontdata"].c_str(), std::ofstream::binary);
            if(!OutStream.good()) {
                DebugLog( D_ERROR, DC_ALL ) << "Can't save user fontdata file.\n"
                << "Check permissions for: " << FILENAMES["fontdata"].c_str();
                return NULL;
            }
            JsonOut jOut(OutStream, true); // pretty-print
            jOut.start_object();
            jOut.member("fontblending", fontblending);
            jOut.member("fontwidth", fontwidth);
            jOut.member("fontheight", fontheight);
            jOut.member("fontsize", fontsize);
            jOut.member("typeface", typeface);
            jOut.member("map_fontwidth", map_fontwidth);
            jOut.member("map_fontheight", map_fontheight);
            jOut.member("map_fontsize", map_fontsize);
            jOut.member("map_typeface", map_typeface);
            jOut.member("overmap_fontwidth", overmap_fontwidth);
            jOut.member("overmap_fontheight", overmap_fontheight);
            jOut.member("overmap_fontsize", overmap_fontsize);
            jOut.member("overmap_typeface", overmap_typeface);
            jOut.end_object();
            OutStream << "\n";
            OutStream.close();
        } else {
            DebugLog( D_ERROR, DC_ALL ) << "Can't load fontdata files.\n"
            << "Check permissions for:\n" << FILENAMES["legacy_fontdata"].c_str() << "\n"
            << FILENAMES["fontdata"].c_str() << "\n";
            return NULL;
        }
    }

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= OPTIONS["TERMINAL_X"] * fontwidth;
    WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = BITMAPINFO();
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    // Load private fonts
    if (SetCurrentDirectoryW(L"data\\font")){
        WIN32_FIND_DATA findData;
        for (HANDLE findFont = FindFirstFileW(L".\\*", &findData); findFont != INVALID_HANDLE_VALUE; )
        {
            if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders
                AddFontResourceExW(findData.cFileName, FR_PRIVATE,NULL);
            }
            if (!FindNextFile(findFont, &findData)){
                FindClose(findFont);
                break;
            }
        }
        SetCurrentDirectoryW(L"..\\..");
    }

    // Use desired font, if possible
    font = CreateFontW(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, widen(typeface).c_str());

    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    init_colors();

    mainwin = newwin(OPTIONS["TERMINAL_Y"],OPTIONS["TERMINAL_X"],0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Beispiel #8
0
BOOL FASTCALL GetIniString(ALICE_INI_INFO *pIniInfo, PVOID, STL_STRINGA *pString)
{
    BOOL Result;
    LONG Type;
    WCHAR szPath[MAX_PATH];
    bool (FASTCALL *pfGetIniString)(PVOID pIniInfo, PVOID, STL_STRINGA *pString);
    enum { INI_TYPE_FACE, INI_TYPE_FONT };

    static CHAR szFaceName[] = "FaceName";
    static CHAR szFontName[] = "FontName";

    *(PVOID *)&pfGetIniString = (PVOID)0x42CA40;

    LOOP_ALWAYS
    {
        Result = pfGetIniString(pIniInfo, 0, pString);
        if (!Result)
            return Result;

        if (pString->Length == sizeof(szFaceName) - 1 &&
            !StrICompareA(pString->GetBuffer(), szFaceName))
        {
            Type = INI_TYPE_FACE;
        }
        else if (pString->Length == sizeof(szFontName) - 1 &&
            !StrICompareA(pString->GetBuffer(), szFontName))
        {
            Type = INI_TYPE_FONT;
        }
        else
        {
            return TRUE;
        }

        LOOP_ONCE
        {
            if (!pfGetIniString(pIniInfo, 0, pString) || *pString->GetBuffer() != '=')
                break;

            if (!pfGetIniString(pIniInfo, 0, pString) || pString->Length == 0)
                break;

            switch (Type)
            {
                case INI_TYPE_FACE:
                    MultiByteToWideChar(
                        CP_ACP,
                        0,
                        pString->GetBuffer(),
                        -1,
                        g_szFaceName,
                        countof(g_szFaceName));
                    break;

                case INI_TYPE_FONT:
                    MultiByteToWideChar(
                        CP_ACP,
                        0,
                        pString->GetBuffer(),
                        -1,
                        szPath,
                        countof(szPath));

                    if (AddFontResourceExW(szPath, FR_PRIVATE, NULL) == 0)
                        break;

                    GetFontNameFromFile(szPath, g_szFaceName, countof(g_szFaceName));
                    break;
            }
        }
    }
}
void loadFontFromFile(const string* file_name) {
    string* s = wstrdup(file_name);
    assert(AddFontResourceExW((LPCWSTR*)s, FR_PRIVATE, NULL) > 0);
    free(s);
}
Beispiel #10
0
TEST(NtGdiTests, FontResource) {
    /* i#1825: test NtGdiAddFontResourceW */
    /* XXX: we assume arial.ttf exists */
    int ret = AddFontResourceExW(L"C:\\Windows\\Fonts\\arial.ttf", FR_PRIVATE, NULL);
    EXPECT_EQ(ret, 1);
}
Beispiel #11
0
void sFont2D::AddResource(const sChar *filename)
{
  AddFontResourceExW(filename, FR_PRIVATE, NULL);
}