dwrite: Implement GetWeight() for IDWriteFont.
This commit is contained in:
parent
ab91abd755
commit
0358413e35
|
@ -105,6 +105,7 @@ struct dwrite_font {
|
||||||
IDWriteFontFace *face;
|
IDWriteFontFace *face;
|
||||||
DWRITE_FONT_STYLE style;
|
DWRITE_FONT_STYLE style;
|
||||||
DWRITE_FONT_STRETCH stretch;
|
DWRITE_FONT_STRETCH stretch;
|
||||||
|
DWRITE_FONT_WEIGHT weight;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dwrite_fontface {
|
struct dwrite_fontface {
|
||||||
|
@ -371,8 +372,8 @@ static HRESULT WINAPI dwritefont_GetFontFamily(IDWriteFont *iface, IDWriteFontFa
|
||||||
static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface)
|
static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface)
|
||||||
{
|
{
|
||||||
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
||||||
FIXME("(%p): stub\n", This);
|
TRACE("(%p)\n", This);
|
||||||
return 0;
|
return This->weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont *iface)
|
static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont *iface)
|
||||||
|
@ -592,28 +593,30 @@ static HRESULT create_fontfamily(const WCHAR *familyname, IDWriteFontFamily **fa
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWRITE_FONT_STRETCH get_font_stretch(HDC hdc)
|
static void get_font_properties(struct dwrite_font *font, HDC hdc)
|
||||||
{
|
{
|
||||||
DWRITE_FONT_STRETCH stretch;
|
|
||||||
TT_OS2_V2 tt_os2;
|
TT_OS2_V2 tt_os2;
|
||||||
LONG size;
|
LONG size;
|
||||||
|
|
||||||
/* default stretch to normal */
|
/* default stretch and weight to normal */
|
||||||
stretch = DWRITE_FONT_STRETCH_NORMAL;
|
font->stretch = DWRITE_FONT_STRETCH_NORMAL;
|
||||||
|
font->weight = DWRITE_FONT_WEIGHT_NORMAL;
|
||||||
|
|
||||||
size = GetFontData(hdc, MS_OS2_TAG, 0, NULL, 0);
|
size = GetFontData(hdc, MS_OS2_TAG, 0, NULL, 0);
|
||||||
if (size == GDI_ERROR) return stretch;
|
if (size != GDI_ERROR)
|
||||||
|
{
|
||||||
|
if (size > sizeof(tt_os2)) size = sizeof(tt_os2);
|
||||||
|
|
||||||
if (size > sizeof(tt_os2)) size = sizeof(tt_os2);
|
memset(&tt_os2, 0, sizeof(tt_os2));
|
||||||
|
if (GetFontData(hdc, MS_OS2_TAG, 0, &tt_os2, size) != size) return;
|
||||||
|
|
||||||
memset(&tt_os2, 0, sizeof(tt_os2));
|
/* DWRITE_FONT_STRETCH enumeration values directly match font data values */
|
||||||
if (GetFontData(hdc, MS_OS2_TAG, 0, &tt_os2, size) != size) return stretch;
|
if (GET_BE_WORD(tt_os2.usWidthClass) <= DWRITE_FONT_STRETCH_ULTRA_EXPANDED)
|
||||||
|
font->stretch = GET_BE_WORD(tt_os2.usWidthClass);
|
||||||
|
|
||||||
/* DWRITE_FONT_STRETCH enumeration values directly match font data values */
|
font->weight = GET_BE_WORD(tt_os2.usWeightClass);
|
||||||
if (GET_BE_WORD(tt_os2.usWidthClass) <= DWRITE_FONT_STRETCH_ULTRA_EXPANDED)
|
TRACE("stretch=%d, weight=%d\n", font->stretch, font->weight);
|
||||||
stretch = GET_BE_WORD(tt_os2.usWidthClass);
|
}
|
||||||
|
|
||||||
return stretch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
|
HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
|
||||||
|
@ -622,7 +625,6 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
|
||||||
struct dwrite_font *This;
|
struct dwrite_font *This;
|
||||||
IDWriteFontFamily *family;
|
IDWriteFontFamily *family;
|
||||||
OUTLINETEXTMETRICW *otm;
|
OUTLINETEXTMETRICW *otm;
|
||||||
DWRITE_FONT_STRETCH stretch;
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
HFONT hfont;
|
HFONT hfont;
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
|
@ -630,8 +632,15 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
|
||||||
|
|
||||||
*font = NULL;
|
*font = NULL;
|
||||||
|
|
||||||
|
This = heap_alloc(sizeof(struct dwrite_font));
|
||||||
|
if (!This) return E_OUTOFMEMORY;
|
||||||
|
|
||||||
hfont = CreateFontIndirectW(logfont);
|
hfont = CreateFontIndirectW(logfont);
|
||||||
if (!hfont) return DWRITE_E_NOFONT;
|
if (!hfont)
|
||||||
|
{
|
||||||
|
heap_free(This);
|
||||||
|
return DWRITE_E_NOFONT;
|
||||||
|
}
|
||||||
|
|
||||||
hdc = CreateCompatibleDC(0);
|
hdc = CreateCompatibleDC(0);
|
||||||
SelectObject(hdc, hfont);
|
SelectObject(hdc, hfont);
|
||||||
|
@ -641,7 +650,7 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
|
||||||
otm->otmSize = ret;
|
otm->otmSize = ret;
|
||||||
ret = GetOutlineTextMetricsW(hdc, otm->otmSize, otm);
|
ret = GetOutlineTextMetricsW(hdc, otm->otmSize, otm);
|
||||||
|
|
||||||
stretch = get_font_stretch(hdc);
|
get_font_properties(This, hdc);
|
||||||
|
|
||||||
DeleteDC(hdc);
|
DeleteDC(hdc);
|
||||||
DeleteObject(hfont);
|
DeleteObject(hfont);
|
||||||
|
@ -652,13 +661,10 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
|
||||||
|
|
||||||
hr = create_fontfamily(familyname, &family);
|
hr = create_fontfamily(familyname, &family);
|
||||||
heap_free(otm);
|
heap_free(otm);
|
||||||
if (hr != S_OK) return hr;
|
if (hr != S_OK)
|
||||||
|
|
||||||
This = heap_alloc(sizeof(struct dwrite_font));
|
|
||||||
if (!This)
|
|
||||||
{
|
{
|
||||||
IDWriteFontFamily_Release(family);
|
heap_free(This);
|
||||||
return E_OUTOFMEMORY;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
This->IDWriteFont_iface.lpVtbl = &dwritefontvtbl;
|
This->IDWriteFont_iface.lpVtbl = &dwritefontvtbl;
|
||||||
|
@ -666,7 +672,6 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
|
||||||
This->face = NULL;
|
This->face = NULL;
|
||||||
This->family = family;
|
This->family = family;
|
||||||
This->style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
|
This->style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
|
||||||
This->stretch = stretch;
|
|
||||||
|
|
||||||
*font = &This->IDWriteFont_iface;
|
*font = &This->IDWriteFont_iface;
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,6 @@ if (0)
|
||||||
|
|
||||||
/* now check properties */
|
/* now check properties */
|
||||||
weight = IDWriteFont_GetWeight(font);
|
weight = IDWriteFont_GetWeight(font);
|
||||||
todo_wine
|
|
||||||
ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "got %d\n", weight);
|
ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "got %d\n", weight);
|
||||||
|
|
||||||
style = IDWriteFont_GetStyle(font);
|
style = IDWriteFont_GetStyle(font);
|
||||||
|
@ -115,7 +114,6 @@ todo_wine
|
||||||
EXPECT_HR(hr, S_OK);
|
EXPECT_HR(hr, S_OK);
|
||||||
|
|
||||||
weight = IDWriteFont_GetWeight(font);
|
weight = IDWriteFont_GetWeight(font);
|
||||||
todo_wine
|
|
||||||
ok(weight == weights[i][1],
|
ok(weight == weights[i][1],
|
||||||
"%d: got %d, expected %d\n", i, weight, weights[i][1]);
|
"%d: got %d, expected %d\n", i, weight, weights[i][1]);
|
||||||
IDWriteFont_Release(font);
|
IDWriteFont_Release(font);
|
||||||
|
@ -132,7 +130,6 @@ todo_wine
|
||||||
EXPECT_HR(hr, S_OK);
|
EXPECT_HR(hr, S_OK);
|
||||||
|
|
||||||
weight = IDWriteFont_GetWeight(font);
|
weight = IDWriteFont_GetWeight(font);
|
||||||
todo_wine
|
|
||||||
ok(weight == DWRITE_FONT_WEIGHT_NORMAL || broken(weight == DWRITE_FONT_WEIGHT_BOLD) /* win7 w/o SP */,
|
ok(weight == DWRITE_FONT_WEIGHT_NORMAL || broken(weight == DWRITE_FONT_WEIGHT_BOLD) /* win7 w/o SP */,
|
||||||
"got %d\n", weight);
|
"got %d\n", weight);
|
||||||
IDWriteFont_Release(font);
|
IDWriteFont_Release(font);
|
||||||
|
|
Loading…
Reference in New Issue