olefont-fixed initial value of cyLogical in IFont constructor. =
Peter Schellenbach
pjs at asent.com
Mon Mar 7 16:35:44 CST 2011
Fixed get_Size to work same as Windows.=0A=
=0A=
---=0A=
dlls/oleaut32/olefont.c | 21 +++++++++-=0A=
dlls/oleaut32/tests/olefont.c | 90 =
++++++++++++++++++++++++----------------=0A=
2 files changed, 73 insertions(+), 38 deletions(-)=0A=
=0A=
diff --git a/dlls/oleaut32/olefont.c b/dlls/oleaut32/olefont.c=0A=
index e65504c..f128270 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=
@@ -671,6 +676,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=
@@ -760,8 +767,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=
@@ -1179,8 +1192,12 @@ 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=
=0A=
return S_OK;=0A=
}=0A=
@@ -2401,7 +2418,7 @@ static OLEFontImpl* OLEFontImpl_Construct(const =
FONTDESC *fontDesc)=0A=
*/=0A=
newObject->gdiFont =3D 0;=0A=
newObject->dirty =3D TRUE;=0A=
- newObject->cyLogical =3D 72L;=0A=
+ newObject->cyLogical =3D GetDeviceCaps(get_dc(), LOGPIXELSY);=0A=
newObject->cyHimetric =3D 2540L;=0A=
newObject->pPropertyNotifyCP =3D NULL;=0A=
newObject->pFontEventsCP =3D NULL;=0A=
diff --git a/dlls/oleaut32/tests/olefont.c =
b/dlls/oleaut32/tests/olefont.c=0A=
index 57f1367..e9720bb 100644=0A=
--- a/dlls/oleaut32/tests/olefont.c=0A=
+++ b/dlls/oleaut32/tests/olefont.c=0A=
@@ -57,8 +57,7 @@ static HRESULT (WINAPI =
*pOleCreateFontIndirect)(LPFONTDESC,REFIID,LPVOID*);=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,9 +68,10 @@ 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=
+ 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=
@@ -87,33 +87,33 @@ static void test_ifont_sizes(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 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=
=0A=
- /* Change ratio, check size unchanged. Standard is 72, 2540. */=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=
+ /* 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=
- 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=
+ rtnval =3D GetObject (hfont, sizeof(LOGFONT), &lf);=0A=
+ ok(rtnval > 0, "GetObject(hfont) failed\n");=0A=
+=0A=
+ /* Since font scaling may encounter rouding errors, allow 1 =
pixel deviation. */=0A=
+ ok(abs(lf.lfHeight - hfont_height) <=3D 1,=0A=
"%s: hFont has lf.lfHeight=3D%d, expected %d.\n",=0A=
test_name, lf.lfHeight, hfont_height);=0A=
=0A=
@@ -121,6 +121,37 @@ static void test_ifont_sizes(LONG lo_size, LONG =
hi_size,=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=
+=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=
LPVOID pvObj =3D NULL;=0A=
@@ -1094,20 +1125,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_0428_01CBDCE6.F2EB5950--
More information about the wine-patches
mailing list