diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index 63926e22243..008c1241b0e 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -416,6 +416,11 @@ static inline void init_textfont_prop_value(enum textfont_prop_id propid, textfo } } +static inline FLOAT twips_to_points(LONG value) +{ + return value * 72.0 / 1440; +} + static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid, textfont_prop_val *value) { @@ -459,7 +464,7 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, value->l = fmt.dwEffects & CFE_AUTOCOLOR ? GetSysColor(COLOR_WINDOWTEXT) : fmt.crTextColor; break; case FONT_KERNING: - value->f = fmt.wKerning; + value->f = twips_to_points(fmt.wKerning); break; case FONT_LANGID: value->l = fmt.lcid; @@ -471,10 +476,10 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, return E_OUTOFMEMORY; break; case FONT_POSITION: - value->f = fmt.yOffset; + value->f = twips_to_points(fmt.yOffset); break; case FONT_SIZE: - value->f = fmt.yHeight; + value->f = twips_to_points(fmt.yHeight); break; case FONT_SPACING: value->f = fmt.sSpacing; diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 3e41ede1bca..327b3acf7f1 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -2111,11 +2111,17 @@ static void test_textfont_undefined(ITextFont *font) ok(value == tomUndefined, "got %d\n", value); } +static inline FLOAT twips_to_points(LONG value) +{ + return value * 72.0 / 1440; +} + static void test_ITextFont(void) { static const WCHAR arialW[] = {'A','r','i','a','l',0}; static const CHAR test_text1[] = "TestSomeText"; ITextFont *font, *font2, *font3; + FLOAT size, position, kerning; IRichEditOle *reOle = NULL; ITextDocument *doc = NULL; ITextRange *range = NULL; @@ -2138,6 +2144,38 @@ static void test_ITextFont(void) hr = ITextFont_GetName(font, NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); + /* default font size unit is point */ + size = 0.0; + hr = ITextFont_GetSize(font, &size); + ok(hr == S_OK, "got 0x%08x\n", hr); + + /* set to some non-zero values */ + hr = ITextFont_SetPosition(font, 20.0); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = ITextFont_SetKerning(font, 10.0); + ok(hr == S_OK, "got 0x%08x\n", hr); + + position = 0.0; + hr = ITextFont_GetPosition(font, &position); + ok(hr == S_OK, "got 0x%08x\n", hr); + + kerning = 0.0; + hr = ITextFont_GetKerning(font, &kerning); + ok(hr == S_OK, "got 0x%08x\n", hr); + + memset(&cf, 0, sizeof(cf)); + cf.cbSize = sizeof(cf); + cf.dwMask = CFM_SIZE|CFM_OFFSET|CFM_KERNING; + + /* CHARFORMAT members are in twips */ + SendMessageA(hwnd, EM_SETSEL, 0, 10); + ret = SendMessageA(hwnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + ok(ret, "got %d\n", ret); + ok(size == twips_to_points(cf.yHeight), "got yHeight %d, size %.2f\n", cf.yHeight, size); + ok(position == twips_to_points(cf.yOffset), "got yOffset %d, position %.2f\n", cf.yOffset, position); + ok(kerning == twips_to_points(cf.wKerning), "got wKerning %d, kerning %.2f\n", cf.wKerning, kerning); + /* default font name */ str = NULL; hr = ITextFont_GetName(font, &str);