riched20: Convert from twips to points when tomUsePoints is used.

This commit is contained in:
Nikolay Sivov 2015-05-27 23:52:05 +03:00 committed by Alexandre Julliard
parent a921941a17
commit eecb757248
2 changed files with 46 additions and 3 deletions

View File

@ -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, static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid,
textfont_prop_val *value) 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; value->l = fmt.dwEffects & CFE_AUTOCOLOR ? GetSysColor(COLOR_WINDOWTEXT) : fmt.crTextColor;
break; break;
case FONT_KERNING: case FONT_KERNING:
value->f = fmt.wKerning; value->f = twips_to_points(fmt.wKerning);
break; break;
case FONT_LANGID: case FONT_LANGID:
value->l = fmt.lcid; value->l = fmt.lcid;
@ -471,10 +476,10 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
break; break;
case FONT_POSITION: case FONT_POSITION:
value->f = fmt.yOffset; value->f = twips_to_points(fmt.yOffset);
break; break;
case FONT_SIZE: case FONT_SIZE:
value->f = fmt.yHeight; value->f = twips_to_points(fmt.yHeight);
break; break;
case FONT_SPACING: case FONT_SPACING:
value->f = fmt.sSpacing; value->f = fmt.sSpacing;

View File

@ -2111,11 +2111,17 @@ static void test_textfont_undefined(ITextFont *font)
ok(value == tomUndefined, "got %d\n", value); 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 void test_ITextFont(void)
{ {
static const WCHAR arialW[] = {'A','r','i','a','l',0}; static const WCHAR arialW[] = {'A','r','i','a','l',0};
static const CHAR test_text1[] = "TestSomeText"; static const CHAR test_text1[] = "TestSomeText";
ITextFont *font, *font2, *font3; ITextFont *font, *font2, *font3;
FLOAT size, position, kerning;
IRichEditOle *reOle = NULL; IRichEditOle *reOle = NULL;
ITextDocument *doc = NULL; ITextDocument *doc = NULL;
ITextRange *range = NULL; ITextRange *range = NULL;
@ -2138,6 +2144,38 @@ static void test_ITextFont(void)
hr = ITextFont_GetName(font, NULL); hr = ITextFont_GetName(font, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); 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 */ /* default font name */
str = NULL; str = NULL;
hr = ITextFont_GetName(font, &str); hr = ITextFont_GetName(font, &str);