From 4d3e0ba0a5ca7c3d59a5941965d19cbcecfeef89 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 27 Jan 2020 08:52:49 +0300 Subject: [PATCH] dwrite: Implement IDWriteFont::Equals(). Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/dwrite/font.c | 63 ++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 847070816b3..a3af30afe57 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -295,6 +295,8 @@ static inline struct dwrite_font *impl_from_IDWriteFont3(IDWriteFont3 *iface) return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont3_iface); } +static struct dwrite_font *unsafe_impl_from_IDWriteFont(IDWriteFont *iface); + static inline struct dwrite_fontfile *impl_from_IDWriteFontFile(IDWriteFontFile *iface) { return CONTAINING_RECORD(iface, struct dwrite_fontfile, IDWriteFontFile_iface); @@ -467,6 +469,29 @@ void fontface_detach_from_cache(IDWriteFontFace5 *iface) fontface->cached = NULL; } +static BOOL is_same_fontfile(IDWriteFontFile *left, IDWriteFontFile *right) +{ + UINT32 left_key_size, right_key_size; + const void *left_key, *right_key; + HRESULT hr; + + if (left == right) + return TRUE; + + hr = IDWriteFontFile_GetReferenceKey(left, &left_key, &left_key_size); + if (FAILED(hr)) + return FALSE; + + hr = IDWriteFontFile_GetReferenceKey(right, &right_key, &right_key_size); + if (FAILED(hr)) + return FALSE; + + if (left_key_size != right_key_size) + return FALSE; + + return !memcmp(left_key, right_key, left_key_size); +} + static HRESULT WINAPI dwritefontface_QueryInterface(IDWriteFontFace5 *iface, REFIID riid, void **obj) { struct dwrite_fontface *fontface = impl_from_IDWriteFontFace5(iface); @@ -1814,11 +1839,18 @@ static HRESULT WINAPI dwritefont3_CreateFontFace(IDWriteFont3 *iface, IDWriteFon return get_fontface_from_font(font, (IDWriteFontFace5 **)fontface); } -static BOOL WINAPI dwritefont3_Equals(IDWriteFont3 *iface, IDWriteFont *font) +static BOOL WINAPI dwritefont3_Equals(IDWriteFont3 *iface, IDWriteFont *other) { - struct dwrite_font *This = impl_from_IDWriteFont3(iface); - FIXME("(%p)->(%p): stub\n", This, font); - return FALSE; + struct dwrite_font *font = impl_from_IDWriteFont3(iface), *other_font; + + TRACE("%p, %p.\n", iface, other); + + if (!(other_font = unsafe_impl_from_IDWriteFont(other))) + return FALSE; + + return font->data->face_index == other_font->data->face_index + && font->data->simulations == other_font->data->simulations + && is_same_fontfile(font->data->file, other_font->data->file); } static HRESULT WINAPI dwritefont3_GetFontFaceReference(IDWriteFont3 *iface, IDWriteFontFaceReference **reference) @@ -2687,29 +2719,6 @@ static HRESULT WINAPI dwritefontcollection_FindFamilyName(IDWriteFontCollection3 return S_OK; } -static BOOL is_same_fontfile(IDWriteFontFile *left, IDWriteFontFile *right) -{ - UINT32 left_key_size, right_key_size; - const void *left_key, *right_key; - HRESULT hr; - - if (left == right) - return TRUE; - - hr = IDWriteFontFile_GetReferenceKey(left, &left_key, &left_key_size); - if (FAILED(hr)) - return FALSE; - - hr = IDWriteFontFile_GetReferenceKey(right, &right_key, &right_key_size); - if (FAILED(hr)) - return FALSE; - - if (left_key_size != right_key_size) - return FALSE; - - return !memcmp(left_key, right_key, left_key_size); -} - static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollection3 *iface, IDWriteFontFace *face, IDWriteFont **font) {