[2/3] dwrite: Implement GetWeight() for IDWriteFont
Nikolay Sivov
nsivov at codeweavers.com
Fri Oct 12 06:34:40 CDT 2012
Implement GetWeight() for IDWriteFont
-------------- next part --------------
>From 7151c47f6ad95074883d700bdb7c968472590928 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov at codeweavers.com>
Date: Fri, 12 Oct 2012 08:43:57 -0400
Subject: [PATCH 2/3] Implement GetWeight() for IDWriteFont
---
dlls/dwrite/font.c | 55 +++++++++++++++++++++++++---------------------
dlls/dwrite/tests/font.c | 3 ---
2 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index d91a424..e7beee5 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -105,6 +105,7 @@ struct dwrite_font {
IDWriteFontFace *face;
DWRITE_FONT_STYLE style;
DWRITE_FONT_STRETCH stretch;
+ DWRITE_FONT_WEIGHT weight;
};
struct dwrite_fontface {
@@ -371,8 +372,8 @@ static HRESULT WINAPI dwritefont_GetFontFamily(IDWriteFont *iface, IDWriteFontFa
static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface)
{
struct dwrite_font *This = impl_from_IDWriteFont(iface);
- FIXME("(%p): stub\n", This);
- return 0;
+ TRACE("(%p)\n", This);
+ return This->weight;
}
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;
}
-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;
LONG size;
- /* default stretch to normal */
- stretch = DWRITE_FONT_STRETCH_NORMAL;
+ /* default stretch and weight to normal */
+ font->stretch = DWRITE_FONT_STRETCH_NORMAL;
+ font->weight = DWRITE_FONT_WEIGHT_NORMAL;
size = GetFontData(hdc, MS_OS2_TAG, 0, NULL, 0);
- if (size == GDI_ERROR) return stretch;
-
- if (size > sizeof(tt_os2)) size = sizeof(tt_os2);
+ if (size != GDI_ERROR)
+ {
+ 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 stretch;
+ memset(&tt_os2, 0, sizeof(tt_os2));
+ if (GetFontData(hdc, MS_OS2_TAG, 0, &tt_os2, size) != size) return;
- /* DWRITE_FONT_STRETCH enumeration values directly match font data values */
- if (GET_BE_WORD(tt_os2.usWidthClass) <= DWRITE_FONT_STRETCH_ULTRA_EXPANDED)
- stretch = GET_BE_WORD(tt_os2.usWidthClass);
+ /* DWRITE_FONT_STRETCH enumeration values directly match font data values */
+ if (GET_BE_WORD(tt_os2.usWidthClass) <= DWRITE_FONT_STRETCH_ULTRA_EXPANDED)
+ font->stretch = GET_BE_WORD(tt_os2.usWidthClass);
- return stretch;
+ font->weight = GET_BE_WORD(tt_os2.usWeightClass);
+ TRACE("stretch=%d, weight=%d\n", font->stretch, font->weight);
+ }
}
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;
IDWriteFontFamily *family;
OUTLINETEXTMETRICW *otm;
- DWRITE_FONT_STRETCH stretch;
HRESULT hr;
HFONT hfont;
HDC hdc;
@@ -630,8 +632,15 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
*font = NULL;
+ This = heap_alloc(sizeof(struct dwrite_font));
+ if (!This) return E_OUTOFMEMORY;
+
hfont = CreateFontIndirectW(logfont);
- if (!hfont) return DWRITE_E_NOFONT;
+ if (!hfont)
+ {
+ heap_free(This);
+ return DWRITE_E_NOFONT;
+ }
hdc = CreateCompatibleDC(0);
SelectObject(hdc, hfont);
@@ -641,7 +650,7 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
otm->otmSize = ret;
ret = GetOutlineTextMetricsW(hdc, otm->otmSize, otm);
- stretch = get_font_stretch(hdc);
+ get_font_properties(This, hdc);
DeleteDC(hdc);
DeleteObject(hfont);
@@ -652,13 +661,10 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
hr = create_fontfamily(familyname, &family);
heap_free(otm);
- if (hr != S_OK) return hr;
-
- This = heap_alloc(sizeof(struct dwrite_font));
- if (!This)
+ if (hr != S_OK)
{
- IDWriteFontFamily_Release(family);
- return E_OUTOFMEMORY;
+ heap_free(This);
+ return hr;
}
This->IDWriteFont_iface.lpVtbl = &dwritefontvtbl;
@@ -666,7 +672,6 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
This->face = NULL;
This->family = family;
This->style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
- This->stretch = stretch;
*font = &This->IDWriteFont_iface;
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c
index 81e17fd..70c714c 100644
--- a/dlls/dwrite/tests/font.c
+++ b/dlls/dwrite/tests/font.c
@@ -91,7 +91,6 @@ if (0)
/* now check properties */
weight = IDWriteFont_GetWeight(font);
-todo_wine
ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "got %d\n", weight);
style = IDWriteFont_GetStyle(font);
@@ -115,7 +114,6 @@ todo_wine
EXPECT_HR(hr, S_OK);
weight = IDWriteFont_GetWeight(font);
- todo_wine
ok(weight == weights[i][1],
"%d: got %d, expected %d\n", i, weight, weights[i][1]);
IDWriteFont_Release(font);
@@ -132,7 +130,6 @@ todo_wine
EXPECT_HR(hr, S_OK);
weight = IDWriteFont_GetWeight(font);
-todo_wine
ok(weight == DWRITE_FONT_WEIGHT_NORMAL || broken(weight == DWRITE_FONT_WEIGHT_BOLD) /* win7 w/o SP */,
"got %d\n", weight);
IDWriteFont_Release(font);
--
1.7.10.4
More information about the wine-patches
mailing list