예제 #1
0
파일: olefont.c 프로젝트: Strongc/reactos
/* Various checks along the way.                         */
static void test_ifont_size(LONG lo_size, LONG hi_size,
	LONG ratio_logical, LONG ratio_himetric,
	LONG hfont_height, const char * test_name)
{
	FONTDESC fd;
	LPVOID pvObj = NULL;
	IFont* ifnt = NULL;
	HFONT hfont;
	LOGFONTA lf;
	CY psize;
	HRESULT hres;
        DWORD rtnval;

	fd.cbSizeofstruct = sizeof(FONTDESC);
	fd.lpstrName      = arial_font; /* using scalable instead of bitmap font reduces errors due to font realization */
	S(fd.cySize).Lo   = lo_size;
	S(fd.cySize).Hi   = hi_size;
	fd.sWeight        = 0;
	fd.sCharset       = 0;
        fd.fItalic        = FALSE;
        fd.fUnderline     = FALSE;
        fd.fStrikethrough = FALSE;

	/* Create font, test that it worked. */
	hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
	ifnt = pvObj;
	ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
		test_name, hres);
	ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);

        /* Change the scaling ratio */
        hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
        ok((ratio_logical && ratio_himetric) ? hres == S_OK : hres == E_FAIL,
           "%s: IFont_SetRatio unexpectedly returned 0x%08x.\n", test_name, hres);

	/* Read back size. */
	hres = IFont_get_Size(ifnt, &psize);
	ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
		test_name, hres);

        /* Check returned size - allow for errors due to rounding & font realization. */
	ok((abs(S(psize).Lo - lo_size) < 10000) && S(psize).Hi == hi_size,
		"%s: IFont_get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=%d.\n",
		test_name, S(psize).Lo, S(psize).Hi, lo_size, hi_size);

	/* Check hFont size. */
	hres = IFont_get_hFont (ifnt, &hfont);
	ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
		test_name, hres);
	rtnval = GetObjectA(hfont, sizeof(LOGFONTA), &lf);
        ok(rtnval > 0, "GetObject(hfont) failed\n");

        /* Since font scaling may encounter rounding errors, allow 1 pixel deviation. */
	ok(abs(lf.lfHeight - hfont_height) <= 1,
		"%s: hFont has lf.lfHeight=%d, expected %d.\n",
		test_name, lf.lfHeight, hfont_height);

	/* Free IFont. */
	IFont_Release(ifnt);
}
예제 #2
0
파일: olefont.c 프로젝트: reactos/reactos
static void test_hfont_lifetime(void)
{
    IFont *font, *font2;
    FONTDESC fontdesc;
    HRESULT hr;
    HFONT hfont, first_hfont = NULL;
    CY size;
    DWORD obj_type;
    int i;

    fontdesc.cbSizeofstruct = sizeof(fontdesc);
    fontdesc.lpstrName = arial_font;
    fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
    fontdesc.sWeight = FW_NORMAL;
    fontdesc.sCharset = ANSI_CHARSET;
    fontdesc.fItalic = FALSE;
    fontdesc.fUnderline = FALSE;
    fontdesc.fStrikethrough = FALSE;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
    EXPECT_HR(hr, S_OK);

    hr = IFont_get_hFont(font, &hfont);
    EXPECT_HR(hr, S_OK);

    /* show that if the font is updated the old hfont is deleted when the
       new font is realized */
    for(i = 0; i < 100; i++)
    {
        HFONT last_hfont = hfont;

        size.int64 = (i + 10) * 20000;

        obj_type = GetObjectType(hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_put_Size(font, size);
        EXPECT_HR(hr, S_OK);

        /* put_Size doesn't cause the new font to be realized */
        obj_type = GetObjectType(last_hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_get_hFont(font, &hfont);
        EXPECT_HR(hr, S_OK);

        obj_type = GetObjectType(last_hfont);
        ok(obj_type == 0, "%d: got obj type %d\n", i, obj_type);
    }

    /* now show that if we take a reference on the hfont, it persists
       until the font object is released */
    for(i = 0; i < 100; i++)
    {
        size.int64 = (i + 10) * 20000;

        obj_type = GetObjectType(hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_put_Size(font, size);
        EXPECT_HR(hr, S_OK);

        hr = IFont_get_hFont(font, &hfont);
        EXPECT_HR(hr, S_OK);

        hr = IFont_AddRefHfont(font, hfont);
        EXPECT_HR(hr, S_OK);

        if(i == 0) first_hfont = hfont;
        obj_type = GetObjectType(first_hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
    }

    IFont_Release(font);

    obj_type = GetObjectType(first_hfont);
    ok(obj_type == 0, "got obj type %d\n", obj_type);

    /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
       through re-realization */

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
    EXPECT_HR(hr, S_OK);

    hr = IFont_get_hFont(font, &hfont);
    EXPECT_HR(hr, S_OK);

    for(i = 0; i < 100; i++)
    {
        HFONT last_hfont = hfont;

        size.int64 = (i + 10) * 20000;

        obj_type = GetObjectType(hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_put_Size(font, size);
        EXPECT_HR(hr, S_OK);

        /* put_Size doesn't cause the new font to be realized */
        obj_type = GetObjectType(last_hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_get_hFont(font, &hfont);
        EXPECT_HR(hr, S_OK);

        hr = IFont_AddRefHfont(font, hfont);
        EXPECT_HR(hr, S_OK);

        hr = IFont_ReleaseHfont(font, hfont);
        EXPECT_HR(hr, S_OK);

        obj_type = GetObjectType(last_hfont);
        ok(obj_type == 0, "%d: got obj type %d\n", i, obj_type);
    }

    /* Interestingly if we release a nonexistent reference on the hfont,
     * it persists until the font object is released
     */
    for(i = 0; i < 100; i++)
    {
        size.int64 = (i + 10) * 20000;

        obj_type = GetObjectType(hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_put_Size(font, size);
        EXPECT_HR(hr, S_OK);

        hr = IFont_get_hFont(font, &hfont);
        EXPECT_HR(hr, S_OK);

        hr = IFont_ReleaseHfont(font, hfont);
        EXPECT_HR(hr, S_OK);

        if(i == 0) first_hfont = hfont;
        obj_type = GetObjectType(first_hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
    }

    IFont_Release(font);

    obj_type = GetObjectType(first_hfont);
    ok(obj_type == 0, "got obj type %d\n", obj_type);

    /* If we take two internal references on a hfont then we can release
       it twice.  So it looks like there's a total reference count
       that includes internal and external references */

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
    EXPECT_HR(hr, S_OK);
    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font2);
    EXPECT_HR(hr, S_OK);

    hr = IFont_get_hFont(font, &hfont);
    EXPECT_HR(hr, S_OK);
    hr = IFont_get_hFont(font2, &first_hfont);
    EXPECT_HR(hr, S_OK);
todo_wine
    ok(hfont == first_hfont, "fonts differ\n");
    hr = IFont_ReleaseHfont(font, hfont);
    EXPECT_HR(hr, S_OK);
    hr = IFont_ReleaseHfont(font, hfont);
todo_wine
    EXPECT_HR(hr, S_OK);
    hr = IFont_ReleaseHfont(font, hfont);
    EXPECT_HR(hr, S_FALSE);

    obj_type = GetObjectType(hfont);
    ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

    IFont_Release(font);

    obj_type = GetObjectType(hfont);
    ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

    IFont_Release(font2);

    obj_type = GetObjectType(hfont);
    ok(obj_type == 0, "got obj type %d\n", obj_type);
}
예제 #3
0
파일: olefont.c 프로젝트: reactos/reactos
static void test_AddRefHfont(void)
{
    FONTDESC fd;
    IFont* ifnt1 = NULL;
    IFont* ifnt2 = NULL;
    IFont* ifnt3 = NULL;
    HFONT hfnt1 = 0;
    HFONT hfnt2 = 0;
    HFONT hfnt3 = 0;
    HRESULT hres;

    /* Basic font description */
    fd.cbSizeofstruct = sizeof(FONTDESC);
    fd.lpstrName      = system_font;
    S(fd.cySize).Lo   = 100;
    S(fd.cySize).Hi   = 100;
    fd.sWeight        = 0;
    fd.sCharset       = 0;
    fd.fItalic        = FALSE;
    fd.fUnderline     = FALSE;
    fd.fStrikethrough = FALSE;

    /* Create HFONTs and IFONTs */
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
    IFont_get_hFont(ifnt1,&hfnt1);
    fd.lpstrName = arial_font;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    IFont_get_hFont(ifnt2,&hfnt2);

    /* Try invalid HFONT */
    hres = IFont_AddRefHfont(ifnt1,NULL);
    ok(hres == E_INVALIDARG,
        "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
        hres);

    /* Try to add a bad HFONT */
    hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* Add simple IFONT HFONT pair */
    hres = IFont_AddRefHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
    hres = IFont_AddRefHfont(ifnt2,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Release all hfnt1 refs */
    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Check if hfnt1 is empty */
    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* Release all hfnt2 refs */
    hres = IFont_ReleaseHfont(ifnt2,hfnt2);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Check if hfnt2 is empty */
    hres = IFont_ReleaseHfont(ifnt2,hfnt2);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* Show that releasing an IFONT does not always release it from the HFONT cache. */

    IFont_Release(ifnt1);

    /* Add a reference for destroyed hfnt1 */
    hres = IFont_AddRefHfont(ifnt2,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Decrement reference for destroyed hfnt1 */
    hres = IFont_ReleaseHfont(ifnt2,hfnt1);
    ok(hres == S_OK ||
       hres == S_FALSE, /* <= win2k */
        "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
        hres);

    /* Shows that releasing all IFONT's does clear the HFONT cache. */

    IFont_Release(ifnt2);

    /* Need to make a new IFONT for testing */
    fd.fUnderline = TRUE;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
    IFont_get_hFont(ifnt3,&hfnt3);

    /* Add a reference for destroyed hfnt1 */
    hres = IFont_AddRefHfont(ifnt3,hfnt1);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Decrement reference for destroyed hfnt1 */
    hres = IFont_ReleaseHfont(ifnt3,hfnt1);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    IFont_Release(ifnt3);
}
예제 #4
0
파일: olefont.c 프로젝트: reactos/reactos
static void test_ReleaseHfont(void)
{
    FONTDESC fd;
    LPVOID pvObj1 = NULL;
    LPVOID pvObj2 = NULL;
    IFont* ifnt1 = NULL;
    IFont* ifnt2 = NULL;
    HFONT hfnt1 = 0;
    HFONT hfnt2 = 0;
    HRESULT hres;

    /* Basic font description */
    fd.cbSizeofstruct = sizeof(FONTDESC);
    fd.lpstrName      = system_font;
    S(fd.cySize).Lo   = 100;
    S(fd.cySize).Hi   = 100;
    fd.sWeight        = 0;
    fd.sCharset       = 0;
    fd.fItalic        = FALSE;
    fd.fUnderline     = FALSE;
    fd.fStrikethrough = FALSE;

    /* Create HFONTs and IFONTs */
    pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
    ifnt1 = pvObj1;
    IFont_get_hFont(ifnt1,&hfnt1);
    fd.lpstrName = arial_font;
    pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
    ifnt2 = pvObj2;
    IFont_get_hFont(ifnt2,&hfnt2);

    /* Try invalid HFONT */
    hres = IFont_ReleaseHfont(ifnt1,NULL);
    ok(hres == E_INVALIDARG,
        "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
        hres);

    /* Try to add a bad HFONT */
    hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
    ok(hres == S_FALSE,
        "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* Release all refs */
    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    hres = IFont_ReleaseHfont(ifnt2,hfnt2);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Check that both lists are empty */
    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* The list should be empty */
    hres = IFont_ReleaseHfont(ifnt2,hfnt2);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
        hres);

    IFont_Release(ifnt1);
    IFont_Release(ifnt2);
}
예제 #5
0
파일: olefont.c 프로젝트: r6144/wine
static void test_ifont_sizes(LONG lo_size, LONG hi_size,
                             LONG ratio_logical, LONG ratio_himetric,
                             LONG hfont_height, const char * test_name)
{
    FONTDESC fd;
    LPVOID pvObj = NULL;
    IFont* ifnt = NULL;
    HFONT hfont;
    LOGFONT lf;
    CY psize;
    HRESULT hres;

    fd.cbSizeofstruct = sizeof(FONTDESC);
    fd.lpstrName      = system_font;
    S(fd.cySize).Lo   = lo_size;
    S(fd.cySize).Hi   = hi_size;
    fd.sWeight        = 0;
    fd.sCharset       = 0;
    fd.fItalic        = 0;
    fd.fUnderline     = 0;
    fd.fStrikethrough = 0;

    /* Create font, test that it worked. */
    hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
    ifnt = pvObj;
    ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);

    /* Read back size.  Hi part was ignored. */
    hres = IFont_get_Size(ifnt, &psize);
    ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
       "%s: get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=0.\n",
       test_name, S(psize).Lo, S(psize).Hi, lo_size);

    /* Change ratio, check size unchanged.  Standard is 72, 2540. */
    hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
    ok(hres == S_OK,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    hres = IFont_get_Size(ifnt, &psize);
    ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
       "%s: gS after SR: Lo=%d, Hi=%d; expected Lo=%d, Hi=0.\n",
       test_name, S(psize).Lo, S(psize).Hi, lo_size);

    /* Check hFont size with this ratio.  This tests an important 	*/
    /* conversion for which MSDN is very wrong.			*/
    hres = IFont_get_hFont (ifnt, &hfont);
    ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    hres = GetObject (hfont, sizeof(LOGFONT), &lf);
    ok(lf.lfHeight == hfont_height,
       "%s: hFont has lf.lfHeight=%d, expected %d.\n",
       test_name, lf.lfHeight, hfont_height);

    /* Free IFont. */
    IFont_Release(ifnt);
}