From f5b6563bec818edcbf0d2561a61ece0e234e765d Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 11 Apr 2017 14:21:33 +0300 Subject: [PATCH] dwrite: Pass index directly to font and family creation helpers. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/dwrite/font.c | 49 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index aeebb0d7493..d8ffa14a38a 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -1737,7 +1737,7 @@ void get_logfont_from_fontface(IDWriteFontFace *iface, LOGFONTW *lf) *lf = fontface->lf; } -static HRESULT create_font(struct dwrite_font_data *data, struct dwrite_fontfamily *family, IDWriteFont3 **font) +static HRESULT create_font(struct dwrite_fontfamily *family, UINT32 index, IDWriteFont3 **font) { struct dwrite_font *This; @@ -1751,8 +1751,8 @@ static HRESULT create_font(struct dwrite_font_data *data, struct dwrite_fontfami This->ref = 1; This->family = family; IDWriteFontFamily1_AddRef(&family->IDWriteFontFamily1_iface); - This->style = data->style; - This->data = data; + This->data = family->data->fonts[index]; + This->style = This->data->style; InterlockedIncrement(&This->data->ref); *font = &This->IDWriteFont3_iface; @@ -1835,7 +1835,7 @@ static HRESULT WINAPI dwritefontlist_GetFont(IDWriteFontList1 *iface, UINT32 ind if (index >= This->font_count) return E_INVALIDARG; - return create_font(This->fonts[index], This->family, (IDWriteFont3 **)font); + return create_font(This->family, index, (IDWriteFont3 **)font); } static DWRITE_LOCALITY WINAPI dwritefontlist1_GetFontLocality(IDWriteFontList1 *iface, UINT32 index) @@ -1861,7 +1861,7 @@ static HRESULT WINAPI dwritefontlist1_GetFont(IDWriteFontList1 *iface, UINT32 in if (index >= This->font_count) return E_FAIL; - return create_font(This->fonts[index], This->family, font); + return create_font(This->family, index, font); } static HRESULT WINAPI dwritefontlist1_GetFontFaceReference(IDWriteFontList1 *iface, UINT32 index, @@ -1974,7 +1974,7 @@ static HRESULT WINAPI dwritefontfamily_GetFont(IDWriteFontFamily1 *iface, UINT32 if (index >= This->data->font_count) return E_INVALIDARG; - return create_font(This->data->fonts[index], This, (IDWriteFont3 **)font); + return create_font(This, index, (IDWriteFont3 **)font); } static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily1 *iface, IDWriteLocalizedStrings **names) @@ -2029,8 +2029,7 @@ static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily1 * { struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily1(iface); struct dwrite_font_propvec req; - struct dwrite_font_data *match; - UINT32 i; + UINT32 i, match; TRACE("(%p)->(%d %d %d %p)\n", This, weight, stretch, style, font); @@ -2040,14 +2039,14 @@ static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily1 * } init_font_prop_vec(weight, stretch, style, &req); - match = This->data->fonts[0]; + match = 0; for (i = 1; i < This->data->font_count; i++) { - if (is_better_font_match(&This->data->fonts[i]->propvec, &match->propvec, &req)) - match = This->data->fonts[i]; + if (is_better_font_match(&This->data->fonts[i]->propvec, &This->data->fonts[match]->propvec, &req)) + match = i; } - return create_font(match, This, (IDWriteFont3 **)font); + return create_font(This, match, (IDWriteFont3 **)font); } typedef BOOL (*matching_filter_func)(const struct dwrite_font_data*); @@ -2163,7 +2162,7 @@ static HRESULT WINAPI dwritefontfamily1_GetFont(IDWriteFontFamily1 *iface, UINT3 if (index >= This->data->font_count) return E_FAIL; - return create_font(This->data->fonts[index], This, font); + return create_font(This, index, font); } static HRESULT WINAPI dwritefontfamily1_GetFontFaceReference(IDWriteFontFamily1 *iface, UINT32 index, @@ -2202,8 +2201,7 @@ static const IDWriteFontFamily1Vtbl fontfamilyvtbl = { dwritefontfamily1_GetFontFaceReference }; -static HRESULT create_fontfamily(struct dwrite_fontfamily_data *data, struct dwrite_fontcollection *collection, - IDWriteFontFamily1 **family) +static HRESULT create_fontfamily(struct dwrite_fontcollection *collection, UINT32 index, IDWriteFontFamily1 **family) { struct dwrite_fontfamily *This; @@ -2216,7 +2214,7 @@ static HRESULT create_fontfamily(struct dwrite_fontfamily_data *data, struct dwr This->ref = 1; This->collection = collection; IDWriteFontCollection1_AddRef(&collection->IDWriteFontCollection1_iface); - This->data = data; + This->data = collection->family_data[index]; InterlockedIncrement(&This->data->ref); *family = &This->IDWriteFontFamily1_iface; @@ -2317,7 +2315,7 @@ static HRESULT WINAPI dwritefontcollection_GetFontFamily(IDWriteFontCollection1 return E_FAIL; } - return create_fontfamily(This->family_data[index], This, (IDWriteFontFamily1 **)family); + return create_fontfamily(This, index, (IDWriteFontFamily1 **)family); } static UINT32 collection_find_family(struct dwrite_fontcollection *collection, const WCHAR *name) @@ -2375,10 +2373,9 @@ static BOOL is_same_fontfile(IDWriteFontFile *left, IDWriteFontFile *right) static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollection1 *iface, IDWriteFontFace *face, IDWriteFont **font) { struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection1(iface); - struct dwrite_fontfamily_data *found_family = NULL; - struct dwrite_font_data *found_font = NULL; IDWriteFontFamily1 *family; UINT32 i, j, face_index; + BOOL found_font = FALSE; IDWriteFontFile *file; HRESULT hr; @@ -2395,27 +2392,31 @@ static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollec return hr; face_index = IDWriteFontFace_GetIndex(face); + found_font = FALSE; for (i = 0; i < This->family_count; i++) { struct dwrite_fontfamily_data *family_data = This->family_data[i]; + for (j = 0; j < family_data->font_count; j++) { struct dwrite_font_data *font_data = family_data->fonts[j]; if (face_index == font_data->face_index && is_same_fontfile(file, font_data->file)) { - found_font = font_data; - found_family = family_data; + found_font = TRUE; break; } } + + if (found_font) + break; } if (!found_font) return DWRITE_E_NOFONT; - hr = create_fontfamily(found_family, This, &family); + hr = create_fontfamily(This, i, &family); if (FAILED(hr)) return hr; - hr = create_font(found_font, impl_from_IDWriteFontFamily1(family), (IDWriteFont3 **)font); + hr = create_font(impl_from_IDWriteFontFamily1(family), j, (IDWriteFont3 **)font); IDWriteFontFamily1_Release(family); return hr; } @@ -2440,7 +2441,7 @@ static HRESULT WINAPI dwritefontcollection1_GetFontFamily(IDWriteFontCollection1 return E_FAIL; } - return create_fontfamily(This->family_data[index], This, family); + return create_fontfamily(This, index, family); } static const IDWriteFontCollection1Vtbl fontcollectionvtbl = {