olefont-fixed initial value of cyLogical in IFont construtor, =
Peter Schellenbach
pjs at asent.com
Fri Mar 4 17:09:57 CST 2011
fixed get_Size to work same as Windows. Fixed font size tests. (try 2)=0A=
=0A=
---=0A=
dlls/oleaut32/olefont.c | 18 ++++++++-=0A=
dlls/oleaut32/tests/olefont.c | 89 =
+++++++++++++++++++----------------------=0A=
2 files changed, 58 insertions(+), 49 deletions(-)=0A=
=0A=
diff --git a/dlls/oleaut32/olefont.c b/dlls/oleaut32/olefont.c=0A=
index 6bfb0a0..5d3194c 100644=0A=
--- a/dlls/oleaut32/olefont.c=0A=
+++ b/dlls/oleaut32/olefont.c=0A=
@@ -278,6 +278,11 @@ struct OLEFontImpl=0A=
LONG cyLogical;=0A=
LONG cyHimetric;=0A=
=0A=
+ /*=0A=
+ * Stash realized height (pixels) from TEXTMETRIC - used in get_Size()=0A=
+ */=0A=
+ LONG nRealHeight;=0A=
+=0A=
IConnectionPoint *pPropertyNotifyCP;=0A=
IConnectionPoint *pFontEventsCP;=0A=
};=0A=
@@ -672,6 +677,8 @@ static void realize_font(OLEFontImpl *This)=0A=
}=0A=
GetTextMetricsW(hdc, &tm);=0A=
This->description.sCharset =3D tm.tmCharSet;=0A=
+ /* While we have it handy, stash the realized font height for =
use by get_Size() */=0A=
+ This->nRealHeight =3D tm.tmHeight - tm.tmInternalLeading; /* =
corresponds to LOGFONT lfHeight */=0A=
SelectObject(hdc, old_font);=0A=
}=0A=
}=0A=
@@ -761,8 +768,14 @@ static HRESULT WINAPI OLEFontImpl_get_Size(=0A=
=0A=
if(this->dirty) realize_font(this);=0A=
=0A=
+ /*=0A=
+ * Convert realized font height in pixels to points descaled by =
current=0A=
+ * scaling ratio then scaled up by 10000.=0A=
+ */ =0A=
+ psize->s.Lo =3D MulDiv(this->nRealHeight,=0A=
+ this->cyHimetric * 72 * 10000,=0A=
+ this->cyLogical * 2540);=0A=
psize->s.Hi =3D 0;=0A=
- psize->s.Lo =3D this->description.cySize.s.Lo;=0A=
=0A=
return S_OK;=0A=
}=0A=
@@ -1180,6 +1193,9 @@ static HRESULT WINAPI OLEFontImpl_SetRatio(=0A=
OLEFontImpl *this =3D impl_from_IFont(iface);=0A=
TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);=0A=
=0A=
+ if(cyLogical =3D=3D 0 || cyHimetric =3D=3D 0)=0A=
+ return E_INVALIDARG;=0A=
+=0A=
this->cyLogical =3D cyLogical;=0A=
this->cyHimetric =3D cyHimetric;=0A=
this->dirty =3D TRUE;=0A=
diff --git a/dlls/oleaut32/tests/olefont.c =
b/dlls/oleaut32/tests/olefont.c=0A=
index b6b9045..e7d811b 100644=0A=
--- a/dlls/oleaut32/tests/olefont.c=0A=
+++ b/dlls/oleaut32/tests/olefont.c=0A=
@@ -53,18 +53,6 @@ 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=
@@ -83,7 +71,7 @@ static void test_ifont_size(LONG lo_size, LONG hi_size,=0A=
DWORD rtnval;=0A=
=0A=
fd.cbSizeofstruct =3D sizeof(FONTDESC);=0A=
- fd.lpstrName =3D system_font;=0A=
+ fd.lpstrName =3D arial_font; /* using scaleable instead of bitmap =
font reduces errors due to font realization */=0A=
S(fd.cySize).Lo =3D lo_size;=0A=
S(fd.cySize).Hi =3D hi_size;=0A=
fd.sWeight =3D 0;=0A=
@@ -99,47 +87,34 @@ static void test_ifont_size(LONG lo_size, LONG =
hi_size,=0A=
test_name, hres);=0A=
ok(pvObj !=3D NULL,"%s: OCFI returns NULL.\n", test_name);=0A=
=0A=
- /* Read back size. Hi part was ignored. */=0A=
+ /* If scaling ration specified, change ratio. */=0A=
+ if(ratio_logical && ratio_himetric)=0A=
+ {=0A=
+ hres =3D IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);=0A=
+ ok(hres =3D=3D S_OK,"%s: IFont_SetRatio returns 0x%08x =
instead of S_OK.\n",=0A=
+ test_name, hres);=0A=
+ }=0A=
+ =0A=
+ /* Read back 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 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=
- /* 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 hi_size,=0A=
- "set ratio: %s: gS after SR: Lo=3D%d, Hi=3D%d; expected Lo=3D%d, =
Hi=3D%d.\n",=0A=
+ /* Check returned size - allow for errors due to rouding & font =
realization. */=0A=
+ ok((abs(S(psize).Lo - lo_size) < 10000) && S(psize).Hi =3D=3D hi_size,=0A=
+ "%s: IFont_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=
- /* Check hFont size with this ratio. This tests an important */=0A=
- /* conversion for which MSDN is very wrong. */=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=
+=0A=
+ /* Since font scaling & may encounter rouding errors, allow 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=
+ "%s: hFont has lf.lfHeight=3D%d, expected %d.\n",=0A=
test_name, lf.lfHeight, hfont_height);=0A=
=0A=
/* Free IFont. */=0A=
@@ -150,13 +125,31 @@ 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=
+ /* Results of first 2 tests depend on display resolution. */=0A=
+ HDC hdc =3D GetDC(0);=0A=
+ LONG dpi =3D GetDeviceCaps(hdc, LOGPIXELSY); /* expected results =
depend on display DPI */=0A=
+ ReleaseDC(0, hdc);=0A=
+ if(dpi =3D=3D 96) /* normal resolution display */=0A=
+ {=0A=
+ test_ifont_size(180000, 0, 0, 0, -24, "default"); /* normal =
font */=0A=
+ test_ifont_size(186000, 0, 0, 0, -25, "rounding"); /* test =
rounding */=0A=
+ } else if(dpi =3D=3D 72) /* low resolution display */=0A=
+ {=0A=
+ test_ifont_size(180000, 0, 0, 0, -18, "default"); /* normal =
font */=0A=
+ test_ifont_size(186000, 0, 0, 0, -19, "rounding"); /* test =
rounding */=0A=
+ } else if(dpi =3D=3D 120) /* high resolution display */=0A=
+ {=0A=
+ test_ifont_size(180000, 0, 0, 0, -30, "default"); /* normal =
font */=0A=
+ test_ifont_size(186000, 0, 0, 0, -31, "rounding"); /* test =
rounding */=0A=
+ } else=0A=
+ skip("Skipping resolution dependent font size tests - display =
resolution is %d\n", dpi);=0A=
+=0A=
+ /* Next 4 tests specify a scaling ratio, so display resolution is not =
a factor. */=0A=
+ test_ifont_size(180000, 0, 72, 2540, -18, "ratio1"); /* change =
ratio */=0A=
+ test_ifont_size(180000, 0, 144, 2540, -36, "ratio2"); /* another =
ratio */=0A=
+ test_ifont_size(180000, 0, 72, 1270, -36, "ratio3"); /* yet =
another ratio */=0A=
+ test_ifont_size(186000, 0, 72, 2540, -19, "rounding+ratio"); /* =
test rounding with ratio */=0A=
}=0A=
=0A=
static void test_QueryInterface(void)=0A=
-- =0A=
1.7.2.2=0A=
=0A=
------=_NextPart_000_02C2_01CBDA91.050444B0--
More information about the wine-patches
mailing list