Fixed default cyLogical in IFont constructor to use LOGPIXELSY =

Peter Schellenbach pjs at asent.com
Thu Mar 3 16:22:34 CST 2011


instead of 72. Fixed font size tests.=0A=
=0A=
---=0A=
 dlls/oleaut32/olefont.c       |    1 +=0A=
 dlls/oleaut32/tests/olefont.c |   79 =
+++++++++++++++++++++++++++--------------=0A=
 2 files changed, 53 insertions(+), 27 deletions(-)=0A=
=0A=
diff --git a/dlls/oleaut32/olefont.c b/dlls/oleaut32/olefont.c=0A=
index 46e5f9c..6bfb0a0 100644=0A=
--- a/dlls/oleaut32/olefont.c=0A=
+++ b/dlls/oleaut32/olefont.c=0A=
@@ -1182,6 +1182,7 @@ static HRESULT WINAPI OLEFontImpl_SetRatio(=0A=
 =0A=
   this->cyLogical  =3D cyLogical;=0A=
   this->cyHimetric =3D cyHimetric;=0A=
+  this->dirty =3D TRUE;=0A=
 =0A=
   return S_OK;=0A=
 }=0A=
diff --git a/dlls/oleaut32/tests/olefont.c =
b/dlls/oleaut32/tests/olefont.c=0A=
index 57f1367..b6b9045 100644=0A=
--- a/dlls/oleaut32/tests/olefont.c=0A=
+++ b/dlls/oleaut32/tests/olefont.c=0A=
@@ -53,12 +53,23 @@ static HRESULT (WINAPI =
*pOleCreateFontIndirect)(LPFONTDESC,REFIID,LPVOID*);=0A=
 =0A=
 #define ok_ole_success(hr, func) ok(hr =3D=3D S_OK, func " failed with =
error 0x%08x\n", hr)=0A=
 =0A=
+/* Compute font height (pixels) from point size using current    */=0A=
+/* display resolution. Point size is scaled up by 10000. Formula */=0A=
+/* is documented in KB74299 - Calculating the Logical Height and */=0A=
+/* Point Size of a Font.                                         */=0A=
+static LONG expected_height(LONG point_size)=0A=
+{=0A=
+  HDC hdc =3D GetDC(0);=0A=
+  LONG font_height =3D -MulDiv( point_size, GetDeviceCaps(hdc, =
LOGPIXELSY), 72 * 10000 );=0A=
+  ReleaseDC(0, hdc);=0A=
+  return font_height;=0A=
+}=0A=
+=0A=
 /* Create a font with cySize given by lo_size, hi_size,  */=0A=
 /* SetRatio to ratio_logical, ratio_himetric,            */=0A=
 /* check that resulting hfont has height hfont_height.   */=0A=
 /* Various checks along the way.                         */=0A=
-=0A=
-static void test_ifont_sizes(LONG lo_size, LONG hi_size,=0A=
+static void test_ifont_size(LONG lo_size, LONG hi_size,=0A=
 	LONG ratio_logical, LONG ratio_himetric,=0A=
 	LONG hfont_height, const char * test_name)=0A=
 {=0A=
@@ -69,6 +80,7 @@ static void test_ifont_sizes(LONG lo_size, LONG =
hi_size,=0A=
 	LOGFONT lf;=0A=
 	CY psize;=0A=
 	HRESULT hres;=0A=
+        DWORD rtnval;=0A=
 =0A=
 	fd.cbSizeofstruct =3D sizeof(FONTDESC);=0A=
 	fd.lpstrName      =3D system_font;=0A=
@@ -91,36 +103,62 @@ static void test_ifont_sizes(LONG lo_size, LONG =
hi_size,=0A=
 	hres =3D IFont_get_Size(ifnt, &psize);=0A=
 	ok(hres =3D=3D S_OK,"%s: IFont_get_size returns 0x%08x instead of =
S_OK.\n",=0A=
 		test_name, hres);=0A=
-	ok(S(psize).Lo =3D=3D lo_size && S(psize).Hi =3D=3D 0,=0A=
-		"%s: get_Size: Lo=3D%d, Hi=3D%d; expected Lo=3D%d, Hi=3D0.\n",=0A=
-		test_name, S(psize).Lo, S(psize).Hi, lo_size);=0A=
+	ok(S(psize).Lo =3D=3D lo_size && S(psize).Hi =3D=3D hi_size,=0A=
+		"default scaling: %s: get_Size: Lo=3D%d, Hi=3D%d; expected Lo=3D%d, =
Hi=3D%d.\n",=0A=
+		test_name, S(psize).Lo, S(psize).Hi, lo_size, hi_size);=0A=
 =0A=
-	/* Change ratio, check size unchanged.  Standard is 72, 2540. */=0A=
+	/* Check hFont size */=0A=
+	hres =3D IFont_get_hFont (ifnt, &hfont);=0A=
+	ok(hres =3D=3D S_OK, "%s: IFont_get_hFont returns 0x%08x instead of =
S_OK.\n",=0A=
+		test_name, hres);=0A=
+	rtnval =3D GetObject (hfont, sizeof(LOGFONT), &lf);=0A=
+        ok(rtnval > 0, "GetObject(hfont) failed\n");=0A=
+        /* Since font scaling may encounter rouding errors, tolerate a =
1 pixel deviation. */=0A=
+	ok(abs(lf.lfHeight - expected_height(lo_size)) <=3D 1,=0A=
+		"default scaling: %s: hFont has lf.lfHeight=3D%d, expected %d.\n",=0A=
+		test_name, lf.lfHeight, expected_height(lo_size));=0A=
+=0A=
+	/* Change ratio, check size unchanged.  Standard is 72, 2540 */=0A=
+        /* assumes LOGPIXELSY =3D 72.                               */=0A=
 	hres =3D IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);=0A=
 	ok(hres =3D=3D S_OK,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",=0A=
 		test_name, hres);=0A=
 	hres =3D IFont_get_Size(ifnt, &psize);=0A=
 	ok(hres =3D=3D S_OK,"%s: IFont_get_size returns 0x%08x instead of =
S_OK.\n",=0A=
                 test_name, hres);=0A=
-	ok(S(psize).Lo =3D=3D lo_size && S(psize).Hi =3D=3D 0,=0A=
-		"%s: gS after SR: Lo=3D%d, Hi=3D%d; expected Lo=3D%d, Hi=3D0.\n",=0A=
-		test_name, S(psize).Lo, S(psize).Hi, lo_size);=0A=
+	ok(S(psize).Lo =3D=3D lo_size && S(psize).Hi =3D=3D hi_size,=0A=
+		"set ratio: %s: gS after SR: Lo=3D%d, Hi=3D%d; expected Lo=3D%d, =
Hi=3D%d.\n",=0A=
+		test_name, S(psize).Lo, S(psize).Hi, lo_size, hi_size);=0A=
 =0A=
 	/* Check hFont size with this ratio.  This tests an important 	*/=0A=
 	/* conversion for which MSDN is very wrong.			*/=0A=
 	hres =3D IFont_get_hFont (ifnt, &hfont);=0A=
 	ok(hres =3D=3D S_OK, "%s: IFont_get_hFont returns 0x%08x instead of =
S_OK.\n",=0A=
 		test_name, hres);=0A=
-	hres =3D GetObject (hfont, sizeof(LOGFONT), &lf);=0A=
-        ok(hres =3D=3D OBJ_FONT, "got obj type %d\n", hres);=0A=
-	ok(lf.lfHeight =3D=3D hfont_height,=0A=
-		"%s: hFont has lf.lfHeight=3D%d, expected %d.\n",=0A=
+	rtnval =3D GetObject (hfont, sizeof(LOGFONT), &lf);=0A=
+        ok(rtnval > 0, "GetObject(hfont) failed\n");=0A=
+        /* Since font scaling may encounter rouding errors, tolerate a =
1 pixel deviation. */=0A=
+	ok(abs(lf.lfHeight - hfont_height) <=3D 1,=0A=
+		"set ratio: %s: hFont has lf.lfHeight=3D%d, expected %d.\n",=0A=
 		test_name, lf.lfHeight, hfont_height);=0A=
 =0A=
 	/* Free IFont. */=0A=
 	IFont_Release(ifnt);=0A=
 }=0A=
 =0A=
+static void test_ifont_sizes(void)=0A=
+{=0A=
+  /* Test various size operations and conversions. */=0A=
+  /* Add more as needed. */=0A=
+  test_ifont_size(180000, 0, 72, 2540, -18, "default");=0A=
+  test_ifont_size(180000, 0, 144, 2540, -36, "ratio1");		/* change =
ratio */=0A=
+  test_ifont_size(180000, 0, 72, 1270, -36, "ratio2");		/* 2nd part of =
ratio */=0A=
+=0A=
+  /* These depend on details of how IFont rounds sizes internally. */=0A=
+  test_ifont_size(0, 0, 72, 2540, 0, "zero size");          /* zero =
size */=0A=
+  test_ifont_size(186000, 0, 72, 2540, -19, "rounding");   /* test =
rounding */=0A=
+}=0A=
+=0A=
 static void test_QueryInterface(void)=0A=
 {=0A=
         LPVOID pvObj =3D NULL;=0A=
@@ -1094,20 +1132,7 @@ START_TEST(olefont)=0A=
 =0A=
 	test_QueryInterface();=0A=
 	test_type_info();=0A=
-=0A=
-	/* Test various size operations and conversions. */=0A=
-	/* Add more as needed. */=0A=
-	if (0) /* FIXME: failing tests */=0A=
-	{=0A=
-	    test_ifont_sizes(180000, 0, 72, 2540, -18, "default");=0A=
-	    test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1");		/* change =
ratio */=0A=
-	    test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2");		/* 2nd part =
of ratio */=0A=
-=0A=
-	    /* These depend on details of how IFont rounds sizes internally. */=0A=
-	    test_ifont_sizes(0, 0, 72, 2540, 0, "zero size");          /* zero =
size */=0A=
-	    test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding");   /* test =
rounding */=0A=
-	}=0A=
-=0A=
+        test_ifont_sizes();=0A=
 	test_font_events_disp();=0A=
 	test_GetIDsOfNames();=0A=
 	test_Invoke();=0A=
-- =0A=
1.7.2.2=0A=
=0A=

------=_NextPart_000_021F_01CBD9C5.195E0D50--




More information about the wine-patches mailing list