Nikolay Sivov : dwrite: Reimplement ConvertFontFaceToLOGFONT().

Alexandre Julliard julliard at wine.codeweavers.com
Wed Oct 29 07:36:58 CDT 2014


Module: wine
Branch: master
Commit: 6855740a5e2980f76f3c52b0dff02e38e376a9fd
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6855740a5e2980f76f3c52b0dff02e38e376a9fd

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Tue Oct 28 08:13:51 2014 +0300

dwrite: Reimplement ConvertFontFaceToLOGFONT().

---

 dlls/dwrite/font.c       | 59 ++++++++++++++++++++++++++++++++++++++++++++++--
 dlls/dwrite/tests/font.c |  3 +++
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index 4ebe261..f8bff51 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -139,6 +139,7 @@ static HRESULT create_fontfamily(IDWriteLocalizedStrings *familyname, IDWriteFon
 static HRESULT create_fontfamily_from_data(struct dwrite_fontfamily_data *data, IDWriteFontCollection *collection, IDWriteFontFamily **family);
 static HRESULT create_font_base(IDWriteFont **font);
 static HRESULT create_font_from_data(struct dwrite_font_data*,IDWriteFontFamily*,DWRITE_FONT_SIMULATIONS,IDWriteFont**);
+static HRESULT get_filestream_from_file(IDWriteFontFile*,IDWriteFontFileStream**);
 
 static inline struct dwrite_fontface *impl_from_IDWriteFontFace2(IDWriteFontFace2 *iface)
 {
@@ -723,11 +724,65 @@ static HRESULT create_system_fontface(struct dwrite_font *font, IDWriteFontFace
     return S_OK;
 }
 
+static void get_font_properties_from_stream(IDWriteFontFileStream *stream, DWRITE_FONT_FACE_TYPE face_type,
+    UINT32 face_index, DWRITE_FONT_METRICS *metrics, DWRITE_FONT_STRETCH *stretch, DWRITE_FONT_WEIGHT *weight,
+    DWRITE_FONT_STYLE *style)
+{
+    const void *tt_os2 = NULL, *tt_head = NULL, *tt_post = NULL;
+    void *os2_context, *head_context, *post_context;
+
+    opentype_get_font_table(stream, face_type, face_index, MS_OS2_TAG, &tt_os2, &os2_context, NULL, NULL);
+    opentype_get_font_table(stream, face_type, face_index, MS_HEAD_TAG, &tt_head, &head_context, NULL, NULL);
+    opentype_get_font_table(stream, face_type, face_index, MS_POST_TAG, &tt_post, &post_context, NULL, NULL);
+
+    get_font_properties(tt_os2, tt_head, tt_post, metrics, stretch, weight, style);
+
+    if (tt_os2)
+        IDWriteFontFileStream_ReleaseFileFragment(stream, os2_context);
+    if (tt_head)
+        IDWriteFontFileStream_ReleaseFileFragment(stream, head_context);
+    if (tt_post)
+        IDWriteFontFileStream_ReleaseFileFragment(stream, post_context);
+}
+
 HRESULT convert_fontface_to_logfont(IDWriteFontFace *face, LOGFONTW *logfont)
 {
-    struct dwrite_fontface *fontface = impl_from_IDWriteFontFace2((IDWriteFontFace2*)face);
+    DWRITE_FONT_SIMULATIONS simulations;
+    DWRITE_FONT_FACE_TYPE face_type;
+    IDWriteFontFileStream *stream;
+    DWRITE_FONT_METRICS metrics;
+    DWRITE_FONT_STRETCH stretch;
+    DWRITE_FONT_STYLE style;
+    DWRITE_FONT_WEIGHT weight;
+    IDWriteFontFile *file = NULL;
+    UINT32 index;
+    HRESULT hr;
+
+    memset(logfont, 0, sizeof(*logfont));
+
+    index = 1;
+    hr = IDWriteFontFace_GetFiles(face, &index, &file);
+    if (FAILED(hr) || !file)
+        return hr;
+
+    hr = get_filestream_from_file(file, &stream);
+    if (FAILED(hr)) {
+        IDWriteFontFile_Release(file);
+        return hr;
+    }
+
+    index = IDWriteFontFace_GetIndex(face);
+    face_type = IDWriteFontFace_GetType(face);
+    get_font_properties_from_stream(stream, face_type, index, &metrics, &stretch, &weight, &style);
+    IDWriteFontFileStream_Release(stream);
+
+    simulations = IDWriteFontFace_GetSimulations(face);
 
-    *logfont = fontface->logfont;
+    logfont->lfCharSet = DEFAULT_CHARSET;
+    logfont->lfWeight = weight;
+    logfont->lfItalic = style == DWRITE_FONT_STYLE_ITALIC || (simulations | DWRITE_FONT_SIMULATIONS_OBLIQUE);
+    logfont->lfOutPrecision = OUT_OUTLINE_PRECIS;
+    /* TODO: set facename */
 
     return S_OK;
 }
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c
index 74aad58..7debdda 100644
--- a/dlls/dwrite/tests/font.c
+++ b/dlls/dwrite/tests/font.c
@@ -1013,11 +1013,14 @@ if (0) /* crashes on native */
     ok(hr == S_OK, "got 0x%08x\n", hr);
     ok(logfont.lfHeight == 0, "got %d\n", logfont.lfHeight);
     ok(logfont.lfWidth == 0, "got %d\n", logfont.lfWidth);
+todo_wine
     ok(logfont.lfWeight == FW_NORMAL, "got %d\n", logfont.lfWeight);
     ok(logfont.lfEscapement == 0, "got %d\n", logfont.lfEscapement);
+todo_wine
     ok(logfont.lfItalic == 1, "got %d\n", logfont.lfItalic);
     ok(logfont.lfUnderline == 0, "got %d\n", logfont.lfUnderline);
     ok(logfont.lfStrikeOut == 0, "got %d\n", logfont.lfStrikeOut);
+todo_wine
     ok(!lstrcmpW(logfont.lfFaceName, tahomaW), "got %s\n", wine_dbgstr_w(logfont.lfFaceName));
 
     IDWriteGdiInterop_Release(interop);




More information about the wine-cvs mailing list