Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/font.c | 166 ++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 84 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 5a3afefb27..7532aa090d 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -99,14 +99,16 @@ struct dwrite_font_data { BOOL oblique_sim_tested : 1; };
-struct dwrite_fontfamily_data { - LONG ref; +struct dwrite_fontfamily_data +{ + LONG refcount;
IDWriteLocalizedStrings *familyname;
struct dwrite_font_data **fonts; - UINT32 font_count; - UINT32 font_alloc; + size_t size; + size_t count; + BOOL has_normal_face : 1; BOOL has_oblique_face : 1; BOOL has_italic_face : 1; @@ -428,12 +430,12 @@ static void release_font_data(struct dwrite_font_data *data)
static void release_fontfamily_data(struct dwrite_fontfamily_data *data) { - int i; + size_t i;
- if (InterlockedDecrement(&data->ref) > 0) + if (InterlockedDecrement(&data->refcount) > 0) return;
- for (i = 0; i < data->font_count; i++) + for (i = 0; i < data->count; ++i) release_font_data(data->fonts[i]); heap_free(data->fonts); IDWriteLocalizedStrings_Release(data->familyname); @@ -2043,26 +2045,28 @@ static HRESULT WINAPI dwritefontfamily_GetFontCollection(IDWriteFontFamily1 *ifa
static UINT32 WINAPI dwritefontfamily_GetFontCount(IDWriteFontFamily1 *iface) { - struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily1(iface); - TRACE("(%p)\n", This); - return This->data->font_count; + struct dwrite_fontfamily *family = impl_from_IDWriteFontFamily1(iface); + + TRACE("%p.\n", iface); + + return family->data->count; }
static HRESULT WINAPI dwritefontfamily_GetFont(IDWriteFontFamily1 *iface, UINT32 index, IDWriteFont **font) { - struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily1(iface); + struct dwrite_fontfamily *family = impl_from_IDWriteFontFamily1(iface);
- TRACE("(%p)->(%u %p)\n", This, index, font); + TRACE("%p, %u, %p.\n", iface, index, font);
*font = NULL;
- if (This->data->font_count == 0) + if (!family->data->count) return S_FALSE;
- if (index >= This->data->font_count) + if (index >= family->data->count) return E_INVALIDARG;
- return create_font(This, index, (IDWriteFont3 **)font); + return create_font(family, index, (IDWriteFont3 **)font); }
static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily1 *iface, IDWriteLocalizedStrings **names) @@ -2115,13 +2119,14 @@ static BOOL is_better_font_match(const struct dwrite_font_propvec *next, const s static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily1 *iface, DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFont **font) { - struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily1(iface); + struct dwrite_fontfamily *family = impl_from_IDWriteFontFamily1(iface); struct dwrite_font_propvec req; - UINT32 i, match; + size_t i, match;
- TRACE("(%p)->(%d %d %d %p)\n", This, weight, stretch, style, font); + TRACE("%p, %d, %d, %d, %p.\n", iface, weight, stretch, style, font);
- if (This->data->font_count == 0) { + if (!family->data->count) + { *font = NULL; return DWRITE_E_NOFONT; } @@ -2129,12 +2134,13 @@ static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily1 * init_font_prop_vec(weight, stretch, style, &req); match = 0;
- for (i = 1; i < This->data->font_count; i++) { - if (is_better_font_match(&This->data->fonts[i]->propvec, &This->data->fonts[match]->propvec, &req)) + for (i = 1; i < family->data->count; ++i) + { + if (is_better_font_match(&family->data->fonts[i]->propvec, &family->data->fonts[match]->propvec, &req)) match = i; }
- return create_font(This, match, (IDWriteFont3 **)font); + return create_font(family, match, (IDWriteFont3 **)font); }
typedef BOOL (*matching_filter_func)(const struct dwrite_font_data*); @@ -2174,13 +2180,13 @@ static void matchingfonts_sort(struct dwrite_fontlist *fonts, const struct dwrit static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily1 *iface, DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFontList **ret) { - struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily1(iface); + struct dwrite_fontfamily *family = impl_from_IDWriteFontFamily1(iface); matching_filter_func func = NULL; struct dwrite_font_propvec req; struct dwrite_fontlist *fonts; - UINT32 i; + size_t i;
- TRACE("(%p)->(%d %d %d %p)\n", This, weight, stretch, style, ret); + TRACE("%p, %d, %d, %d, %p.\n", iface, weight, stretch, style, ret);
*ret = NULL;
@@ -2189,7 +2195,7 @@ static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily1 *ifac return E_OUTOFMEMORY;
/* Allocate as many as family has, not all of them will be necessary used. */ - fonts->fonts = heap_calloc(This->data->font_count, sizeof(*fonts->fonts)); + fonts->fonts = heap_calloc(family->data->count, sizeof(*fonts->fonts)); if (!fonts->fonts) { heap_free(fonts); return E_OUTOFMEMORY; @@ -2197,24 +2203,26 @@ static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily1 *ifac
fonts->IDWriteFontList1_iface.lpVtbl = &dwritefontlistvtbl; fonts->ref = 1; - fonts->family = This; + fonts->family = family; IDWriteFontFamily1_AddRef(&fonts->family->IDWriteFontFamily1_iface); fonts->font_count = 0;
/* Normal style accepts Normal or Italic, Oblique and Italic - both Oblique and Italic styles */ if (style == DWRITE_FONT_STYLE_NORMAL) { - if (This->data->has_normal_face || This->data->has_italic_face) + if (family->data->has_normal_face || family->data->has_italic_face) func = is_font_acceptable_for_normal; } else /* requested oblique or italic */ { - if (This->data->has_oblique_face || This->data->has_italic_face) + if (family->data->has_oblique_face || family->data->has_italic_face) func = is_font_acceptable_for_oblique_italic; }
- for (i = 0; i < This->data->font_count; i++) { - if (!func || func(This->data->fonts[i])) { - fonts->fonts[fonts->font_count] = This->data->fonts[i]; - addref_font_data(This->data->fonts[i]); + for (i = 0; i < family->data->count; ++i) + { + if (!func || func(family->data->fonts[i])) + { + fonts->fonts[fonts->font_count] = family->data->fonts[i]; + addref_font_data(family->data->fonts[i]); fonts->font_count++; } } @@ -2223,7 +2231,7 @@ static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily1 *ifac init_font_prop_vec(weight, stretch, style, &req); matchingfonts_sort(fonts, &req);
- *ret = (IDWriteFontList*)&fonts->IDWriteFontList1_iface; + *ret = (IDWriteFontList *)&fonts->IDWriteFontList1_iface; return S_OK; }
@@ -2238,19 +2246,19 @@ static DWRITE_LOCALITY WINAPI dwritefontfamily1_GetFontLocality(IDWriteFontFamil
static HRESULT WINAPI dwritefontfamily1_GetFont(IDWriteFontFamily1 *iface, UINT32 index, IDWriteFont3 **font) { - struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily1(iface); + struct dwrite_fontfamily *family = impl_from_IDWriteFontFamily1(iface);
- TRACE("(%p)->(%u %p)\n", This, index, font); + TRACE("%p, %u, %p.\n", iface, index, font);
*font = NULL;
- if (This->data->font_count == 0) + if (!family->data->count) return S_FALSE;
- if (index >= This->data->font_count) + if (index >= family->data->count) return E_FAIL;
- return create_font(This, index, font); + return create_font(family, index, font); }
static HRESULT WINAPI dwritefontfamily1_GetFontFaceReference(IDWriteFontFamily1 *iface, UINT32 index, @@ -2359,22 +2367,23 @@ static const IDWriteFontList1Vtbl fontfamilylistvtbl = {
static HRESULT create_fontfamily(struct dwrite_fontcollection *collection, UINT32 index, IDWriteFontFamily1 **family) { - struct dwrite_fontfamily *This; + struct dwrite_fontfamily *object;
*family = NULL;
- This = heap_alloc(sizeof(struct dwrite_fontfamily)); - if (!This) return E_OUTOFMEMORY; + object = heap_alloc(sizeof(*object)); + if (!object) + return E_OUTOFMEMORY;
- This->IDWriteFontFamily1_iface.lpVtbl = &fontfamilyvtbl; - This->IDWriteFontList1_iface.lpVtbl = &fontfamilylistvtbl; - This->ref = 1; - This->collection = collection; + object->IDWriteFontFamily1_iface.lpVtbl = &fontfamilyvtbl; + object->IDWriteFontList1_iface.lpVtbl = &fontfamilylistvtbl; + object->ref = 1; + object->collection = collection; IDWriteFontCollection1_AddRef(&collection->IDWriteFontCollection1_iface); - This->data = collection->family_data[index]; - InterlockedIncrement(&This->data->ref); + object->data = collection->family_data[index]; + InterlockedIncrement(&object->data->refcount);
- *family = &This->IDWriteFontFamily1_iface; + *family = &object->IDWriteFontFamily1_iface;
return S_OK; } @@ -2535,10 +2544,11 @@ static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollec { struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection1(iface); IDWriteFontFamily1 *family; - UINT32 i, j, face_index; BOOL found_font = FALSE; IDWriteFontFile *file; + UINT32 i, face_index; HRESULT hr; + size_t j;
TRACE("(%p)->(%p %p)\n", This, face, font);
@@ -2557,7 +2567,8 @@ static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollec 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++) { + for (j = 0; j < family_data->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)) { @@ -2632,20 +2643,13 @@ static const IDWriteFontCollection1Vtbl systemfontcollectionvtbl = {
static HRESULT fontfamily_add_font(struct dwrite_fontfamily_data *family_data, struct dwrite_font_data *font_data) { - if (family_data->font_count + 1 >= family_data->font_alloc) { - struct dwrite_font_data **new_list; - UINT32 new_alloc; - - new_alloc = family_data->font_alloc * 2; - new_list = heap_realloc(family_data->fonts, sizeof(*family_data->fonts) * new_alloc); - if (!new_list) - return E_OUTOFMEMORY; - family_data->fonts = new_list; - family_data->font_alloc = new_alloc; + if (!dwrite_array_reserve((void **)&family_data->fonts, &family_data->size, family_data->count + 1, + sizeof(*family_data->fonts))) + { + return E_OUTOFMEMORY; }
- family_data->fonts[family_data->font_count] = font_data; - family_data->font_count++; + family_data->fonts[family_data->count++] = font_data; if (font_data->style == DWRITE_FONT_STYLE_NORMAL) family_data->has_normal_face = 1; else if (font_data->style == DWRITE_FONT_STYLE_OBLIQUE) @@ -3518,35 +3522,25 @@ static HRESULT init_fontfamily_data(IDWriteLocalizedStrings *familyname, struct { struct dwrite_fontfamily_data *data;
- data = heap_alloc(sizeof(*data)); + data = heap_alloc_zero(sizeof(*data)); if (!data) return E_OUTOFMEMORY;
- data->ref = 1; - data->font_count = 0; - data->font_alloc = 2; - data->has_normal_face = 0; - data->has_oblique_face = 0; - data->has_italic_face = 0; - - data->fonts = heap_calloc(data->font_alloc, sizeof(*data->fonts)); - if (!data->fonts) { - heap_free(data); - return E_OUTOFMEMORY; - } - + data->refcount = 1; data->familyname = familyname; IDWriteLocalizedStrings_AddRef(familyname);
*ret = data; + return S_OK; }
static void fontfamily_add_bold_simulated_face(struct dwrite_fontfamily_data *family) { - UINT32 i, j, heaviest; + size_t i, j, heaviest;
- for (i = 0; i < family->font_count; i++) { + for (i = 0; i < family->count; ++i) + { DWRITE_FONT_WEIGHT weight = family->fonts[i]->weight; heaviest = i;
@@ -3554,7 +3548,8 @@ static void fontfamily_add_bold_simulated_face(struct dwrite_fontfamily_data *fa continue;
family->fonts[i]->bold_sim_tested = 1; - for (j = i; j < family->font_count; j++) { + for (j = i; j < family->count; ++j) + { if (family->fonts[j]->bold_sim_tested) continue;
@@ -3616,9 +3611,10 @@ static void fontfamily_add_bold_simulated_face(struct dwrite_fontfamily_data *fa
static void fontfamily_add_oblique_simulated_face(struct dwrite_fontfamily_data *family) { - UINT32 i, j; + size_t i, j;
- for (i = 0; i < family->font_count; i++) { + for (i = 0; i < family->count; ++i) + { UINT32 regular = ~0u, oblique = ~0u; struct dwrite_font_data *obliqueface; WCHAR facenameW[255]; @@ -3633,7 +3629,8 @@ static void fontfamily_add_oblique_simulated_face(struct dwrite_fontfamily_data oblique = i;
/* find regular style with same weight/stretch values */ - for (j = i; j < family->font_count; j++) { + for (j = i; j < family->count; ++j) + { if (family->fonts[j]->oblique_sim_tested) continue;
@@ -3701,7 +3698,8 @@ static BOOL fontcollection_add_replacement(struct dwrite_fontcollection *collect struct dwrite_fontfamily_data *replacement = collection->family_data[i]; WCHAR nameW[255];
- for (i = 0; i < replacement->font_count; i++) { + for (i = 0; i < replacement->count; ++i) + { fontfamily_add_font(target, replacement->fonts[i]); addref_font_data(replacement->fonts[i]); }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/font.c | 138 +++++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 66 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 7532aa090d..9f642f9c91 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -114,14 +114,15 @@ struct dwrite_fontfamily_data BOOL has_italic_face : 1; };
-struct dwrite_fontcollection { +struct dwrite_fontcollection +{ IDWriteFontCollection1 IDWriteFontCollection1_iface; - LONG ref; + LONG refcount;
IDWriteFactory5 *factory; struct dwrite_fontfamily_data **family_data; - UINT32 family_count; - UINT32 family_alloc; + size_t size; + size_t count; };
struct dwrite_fontfamily { @@ -2441,58 +2442,65 @@ static HRESULT WINAPI dwritefontcollection_QueryInterface(IDWriteFontCollection1
static ULONG WINAPI dwritefontcollection_AddRef(IDWriteFontCollection1 *iface) { - struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection1(iface); - ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p)->(%d)\n", This, ref); - return ref; + struct dwrite_fontcollection *collection = impl_from_IDWriteFontCollection1(iface); + ULONG refcount = InterlockedIncrement(&collection->refcount); + + TRACE("%p, refcount %d.\n", collection, refcount); + + return refcount; }
static ULONG WINAPI dwritefontcollection_Release(IDWriteFontCollection1 *iface) { - struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection1(iface); - ULONG ref = InterlockedDecrement(&This->ref); - - TRACE("(%p)->(%d)\n", This, ref); + struct dwrite_fontcollection *collection = impl_from_IDWriteFontCollection1(iface); + ULONG refcount = InterlockedDecrement(&collection->refcount); + size_t i;
- if (!ref) { - int i; + TRACE("%p, refcount %d.\n", iface, refcount);
- factory_detach_fontcollection(This->factory, iface); - for (i = 0; i < This->family_count; i++) - release_fontfamily_data(This->family_data[i]); - heap_free(This->family_data); - heap_free(This); + if (!refcount) + { + factory_detach_fontcollection(collection->factory, iface); + for (i = 0; i < collection->count; ++i) + release_fontfamily_data(collection->family_data[i]); + heap_free(collection->family_data); + heap_free(collection); }
- return ref; + return refcount; }
static UINT32 WINAPI dwritefontcollection_GetFontFamilyCount(IDWriteFontCollection1 *iface) { - struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection1(iface); - TRACE("(%p)\n", This); - return This->family_count; + struct dwrite_fontcollection *collection = impl_from_IDWriteFontCollection1(iface); + + TRACE("%p.\n", iface); + + return collection->count; }
-static HRESULT WINAPI dwritefontcollection_GetFontFamily(IDWriteFontCollection1 *iface, UINT32 index, IDWriteFontFamily **family) +static HRESULT WINAPI dwritefontcollection_GetFontFamily(IDWriteFontCollection1 *iface, UINT32 index, + IDWriteFontFamily **family) { - struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection1(iface); + struct dwrite_fontcollection *collection = impl_from_IDWriteFontCollection1(iface);
- TRACE("(%p)->(%u %p)\n", This, index, family); + TRACE("%p, %u, %p.\n", iface, index, family);
- if (index >= This->family_count) { + if (index >= collection->count) + { *family = NULL; return E_FAIL; }
- return create_fontfamily(This, index, (IDWriteFontFamily1 **)family); + return create_fontfamily(collection, index, (IDWriteFontFamily1 **)family); }
static UINT32 collection_find_family(struct dwrite_fontcollection *collection, const WCHAR *name) { - UINT32 i; + size_t i;
- for (i = 0; i < collection->family_count; i++) { + for (i = 0; i < collection->count; ++i) + { IDWriteLocalizedStrings *family_name = collection->family_data[i]->familyname; UINT32 j, count = IDWriteLocalizedStrings_GetCount(family_name); HRESULT hr; @@ -2540,17 +2548,18 @@ static BOOL is_same_fontfile(IDWriteFontFile *left, IDWriteFontFile *right) return !memcmp(left_key, right_key, left_key_size); }
-static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollection1 *iface, IDWriteFontFace *face, IDWriteFont **font) +static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollection1 *iface, IDWriteFontFace *face, + IDWriteFont **font) { - struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection1(iface); + struct dwrite_fontcollection *collection = impl_from_IDWriteFontCollection1(iface); IDWriteFontFamily1 *family; BOOL found_font = FALSE; IDWriteFontFile *file; - UINT32 i, face_index; + UINT32 face_index; + size_t i, j; HRESULT hr; - size_t j;
- TRACE("(%p)->(%p %p)\n", This, face, font); + TRACE("%p, %p, %p.\n", iface, face, font);
*font = NULL;
@@ -2564,8 +2573,9 @@ static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollec 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 (i = 0; i < collection->count; ++i) + { + struct dwrite_fontfamily_data *family_data = collection->family_data[i];
for (j = 0; j < family_data->count; ++j) { @@ -2585,7 +2595,7 @@ static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollec if (!found_font) return DWRITE_E_NOFONT;
- hr = create_fontfamily(This, i, &family); + hr = create_fontfamily(collection, i, &family); if (FAILED(hr)) return hr;
@@ -2603,18 +2613,20 @@ static HRESULT WINAPI dwritefontcollection1_GetFontSet(IDWriteFontCollection1 *i return E_NOTIMPL; }
-static HRESULT WINAPI dwritefontcollection1_GetFontFamily(IDWriteFontCollection1 *iface, UINT32 index, IDWriteFontFamily1 **family) +static HRESULT WINAPI dwritefontcollection1_GetFontFamily(IDWriteFontCollection1 *iface, UINT32 index, + IDWriteFontFamily1 **family) { - struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection1(iface); + struct dwrite_fontcollection *collection = impl_from_IDWriteFontCollection1(iface);
- TRACE("(%p)->(%u %p)\n", This, index, family); + TRACE("%p, %u, %p.\n", iface, index, family);
- if (index >= This->family_count) { + if (index >= collection->count) + { *family = NULL; return E_FAIL; }
- return create_fontfamily(This, index, family); + return create_fontfamily(collection, index, family); }
static const IDWriteFontCollection1Vtbl fontcollectionvtbl = { @@ -2659,34 +2671,26 @@ static HRESULT fontfamily_add_font(struct dwrite_fontfamily_data *family_data, s return S_OK; }
-static HRESULT fontcollection_add_family(struct dwrite_fontcollection *collection, struct dwrite_fontfamily_data *family) +static HRESULT fontcollection_add_family(struct dwrite_fontcollection *collection, + struct dwrite_fontfamily_data *family) { - if (collection->family_alloc < collection->family_count + 1) { - struct dwrite_fontfamily_data **new_list; - UINT32 new_alloc; - - new_alloc = collection->family_alloc * 2; - new_list = heap_realloc(collection->family_data, sizeof(*new_list) * new_alloc); - if (!new_list) - return E_OUTOFMEMORY; - - collection->family_alloc = new_alloc; - collection->family_data = new_list; + if (!dwrite_array_reserve((void **)&collection->family_data, &collection->size, collection->count + 1, + sizeof(*collection->family_data))) + { + return E_OUTOFMEMORY; }
- collection->family_data[collection->family_count++] = family; + collection->family_data[collection->count++] = family; return S_OK; }
static HRESULT init_font_collection(struct dwrite_fontcollection *collection, BOOL is_system) { collection->IDWriteFontCollection1_iface.lpVtbl = is_system ? &systemfontcollectionvtbl : &fontcollectionvtbl; - collection->ref = 1; - collection->family_count = 0; - collection->family_alloc = is_system ? 30 : 5; - collection->family_data = heap_calloc(collection->family_alloc, sizeof(*collection->family_data)); - if (!collection->family_data) - return E_OUTOFMEMORY; + collection->refcount = 1; + collection->count = 0; + collection->size = 0; + collection->family_data = NULL;
return S_OK; } @@ -3772,7 +3776,7 @@ HRESULT create_font_collection(IDWriteFactory5 *factory, IDWriteFontFileEnumerat struct list scannedfiles; BOOL current = FALSE; HRESULT hr = S_OK; - UINT32 i; + size_t i;
*ret = NULL;
@@ -3906,7 +3910,8 @@ HRESULT create_font_collection(IDWriteFactory5 *factory, IDWriteFontFileEnumerat heap_free(fileenum); }
- for (i = 0; i < collection->family_count; i++) { + for (i = 0; i < collection->count; ++i) + { fontfamily_add_bold_simulated_face(collection->family_data[i]); fontfamily_add_oblique_simulated_face(collection->family_data[i]); } @@ -4229,7 +4234,7 @@ HRESULT get_eudc_fontcollection(IDWriteFactory5 *factory, IDWriteFontCollection1 BOOL exists; LONG retval; HRESULT hr; - UINT32 i; + size_t i;
TRACE("building EUDC font collection for factory %p, ACP %u\n", factory, GetACP());
@@ -4283,7 +4288,8 @@ HRESULT get_eudc_fontcollection(IDWriteFactory5 *factory, IDWriteFontCollection1 }
/* EUDC collection offers simulated faces too */ - for (i = 0; i < collection->family_count; i++) { + for (i = 0; i < collection->count; ++i) + { fontfamily_add_bold_simulated_face(collection->family_data[i]); fontfamily_add_oblique_simulated_face(collection->family_data[i]); }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/font.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 9f642f9c91..a5caf7ea2a 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -4588,8 +4588,8 @@ struct dwrite_inmemory_fileloader LONG ref;
struct dwrite_inmemory_stream_data **streams; - UINT32 filecount; - UINT32 capacity; + size_t size; + size_t count; };
static inline struct dwrite_localfontfileloader *impl_from_IDWriteLocalFontFileLoader(IDWriteLocalFontFileLoader *iface) @@ -6208,13 +6208,12 @@ static ULONG WINAPI inmemoryfontfileloader_Release(IDWriteInMemoryFontFileLoader { struct dwrite_inmemory_fileloader *loader = impl_from_IDWriteInMemoryFontFileLoader(iface); ULONG ref = InterlockedDecrement(&loader->ref); + size_t i;
TRACE("(%p)->(%u)\n", loader, ref);
if (!ref) { - UINT32 i; - - for (i = 0; i < loader->filecount; i++) + for (i = 0; i < loader->count; ++i) release_inmemory_stream(loader->streams[i]); heap_free(loader->streams); heap_free(loader); @@ -6239,7 +6238,7 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateStreamFromKey(IDWriteInMemory
index = *(DWORD *)key;
- if (index >= loader->filecount) + if (index >= loader->count) return E_INVALIDARG;
if (!(stream = heap_alloc(sizeof(*stream)))) @@ -6266,21 +6265,8 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW
*fontfile = NULL;
- if (loader->filecount == loader->capacity) { - if (loader->streams) { - struct dwrite_inmemory_stream_data **ptr; - - if (!(ptr = heap_realloc(loader->streams, 2 * loader->capacity * sizeof(*loader->streams)))) - return E_OUTOFMEMORY; - - loader->streams = ptr; - loader->capacity *= 2; - } - else { - loader->capacity = 16; - loader->streams = heap_calloc(loader->capacity, sizeof(*loader->streams)); - } - } + if (!dwrite_array_reserve((void **)&loader->streams, &loader->size, loader->count + 1, sizeof(*loader->streams))) + return E_OUTOFMEMORY;
if (!(stream = heap_alloc(sizeof(*stream)))) return E_OUTOFMEMORY; @@ -6300,8 +6286,8 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW memcpy(stream->data, data, data_size); }
- key = loader->filecount; - loader->streams[loader->filecount++] = stream; + key = loader->count; + loader->streams[loader->count++] = stream;
return IDWriteFactory_CreateCustomFontFileReference(factory, &key, sizeof(key), (IDWriteFontFileLoader *)&loader->IDWriteInMemoryFontFileLoader_iface, fontfile); @@ -6311,9 +6297,9 @@ static UINT32 WINAPI inmemoryfontfileloader_GetFileCount(IDWriteInMemoryFontFile { struct dwrite_inmemory_fileloader *loader = impl_from_IDWriteInMemoryFontFileLoader(iface);
- TRACE("(%p)\n", loader); + TRACE("%p.\n", iface);
- return loader->filecount; + return loader->count; }
static const IDWriteInMemoryFontFileLoaderVtbl inmemoryfontfileloadervtbl =
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/analyzer.c | 70 +++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 41 deletions(-)
diff --git a/dlls/dwrite/analyzer.c b/dlls/dwrite/analyzer.c index ca6dca1e4d..679e1ed0ff 100644 --- a/dlls/dwrite/analyzer.c +++ b/dlls/dwrite/analyzer.c @@ -236,13 +236,14 @@ struct dwrite_fontfallback { UINT32 mappings_count; };
-struct dwrite_fontfallback_builder { +struct dwrite_fontfallback_builder +{ IDWriteFontFallbackBuilder IDWriteFontFallbackBuilder_iface; - LONG ref; + LONG refcount; IDWriteFactory5 *factory; struct fallback_mapping *mappings; - UINT32 mappings_count; - UINT32 mappings_capacity; + size_t size; + size_t count; };
struct dwrite_numbersubstitution { @@ -2228,9 +2229,7 @@ static const IDWriteFontFallbackVtbl customfontfallbackvtbl =
static HRESULT WINAPI fontfallbackbuilder_QueryInterface(IDWriteFontFallbackBuilder *iface, REFIID riid, void **obj) { - struct dwrite_fontfallback_builder *fallbackbuilder = impl_from_IDWriteFontFallbackBuilder(iface); - - TRACE("(%p)->(%s %p)\n", fallbackbuilder, debugstr_guid(riid), obj); + TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
if (IsEqualIID(riid, &IID_IDWriteFontFallbackBuilder) || IsEqualIID(riid, &IID_IUnknown)) { *obj = iface; @@ -2247,22 +2246,25 @@ static HRESULT WINAPI fontfallbackbuilder_QueryInterface(IDWriteFontFallbackBuil static ULONG WINAPI fontfallbackbuilder_AddRef(IDWriteFontFallbackBuilder *iface) { struct dwrite_fontfallback_builder *fallbackbuilder = impl_from_IDWriteFontFallbackBuilder(iface); - ULONG ref = InterlockedIncrement(&fallbackbuilder->ref); - TRACE("(%p)->(%d)\n", fallbackbuilder, ref); - return ref; + ULONG refcount = InterlockedIncrement(&fallbackbuilder->refcount); + + TRACE("%p, refcount %d.\n", iface, refcount); + + return refcount; }
static ULONG WINAPI fontfallbackbuilder_Release(IDWriteFontFallbackBuilder *iface) { struct dwrite_fontfallback_builder *fallbackbuilder = impl_from_IDWriteFontFallbackBuilder(iface); - ULONG ref = InterlockedDecrement(&fallbackbuilder->ref); - - TRACE("(%p)->(%d)\n", fallbackbuilder, ref); + ULONG refcount = InterlockedDecrement(&fallbackbuilder->refcount); + size_t i;
- if (!ref) { - UINT32 i; + TRACE("%p, refcount %d.\n", iface, refcount);
- for (i = 0; i < fallbackbuilder->mappings_count; i++) { + if (!refcount) + { + for (i = 0; i < fallbackbuilder->count; ++i) + { struct fallback_mapping *mapping = &fallbackbuilder->mappings[i]; UINT32 j;
@@ -2281,7 +2283,7 @@ static ULONG WINAPI fontfallbackbuilder_Release(IDWriteFontFallbackBuilder *ifac heap_free(fallbackbuilder); }
- return ref; + return refcount; }
static HRESULT WINAPI fontfallbackbuilder_AddMapping(IDWriteFontFallbackBuilder *iface, @@ -2292,8 +2294,8 @@ static HRESULT WINAPI fontfallbackbuilder_AddMapping(IDWriteFontFallbackBuilder struct fallback_mapping *mapping; UINT32 i;
- TRACE("(%p)->(%p, %u, %p, %u, %p, %s, %s, %f)\n", fallbackbuilder, ranges, ranges_count, target_families, - families_count, collection, debugstr_w(locale), debugstr_w(base_family), scale); + TRACE("%p, %p, %u, %p, %u, %p, %s, %s, %f.\n", iface, ranges, ranges_count, target_families, families_count, + collection, debugstr_w(locale), debugstr_w(base_family), scale);
if (!ranges || ranges_count == 0 || !target_families || families_count == 0 || scale < 0.0f) return E_INVALIDARG; @@ -2301,25 +2303,13 @@ static HRESULT WINAPI fontfallbackbuilder_AddMapping(IDWriteFontFallbackBuilder if (base_family) FIXME("base family ignored.\n");
- if (fallbackbuilder->mappings_count == fallbackbuilder->mappings_capacity) { - struct fallback_mapping *mappings; - - if (fallbackbuilder->mappings_capacity == 0) { - if ((mappings = heap_calloc(16, sizeof(*mappings)))) - fallbackbuilder->mappings_capacity = 16; - } - else { - if ((mappings = heap_realloc(fallbackbuilder->mappings, sizeof(*fallbackbuilder->mappings) * - fallbackbuilder->mappings_capacity * 2))) - fallbackbuilder->mappings_capacity *= 2; - } - if (!mappings) - return E_OUTOFMEMORY; - - fallbackbuilder->mappings = mappings; + if (!dwrite_array_reserve((void **)&fallbackbuilder->mappings, &fallbackbuilder->size, fallbackbuilder->count + 1, + sizeof(*fallbackbuilder->mappings))) + { + return E_OUTOFMEMORY; }
- mapping = &fallbackbuilder->mappings[fallbackbuilder->mappings_count++]; + mapping = &fallbackbuilder->mappings[fallbackbuilder->count++];
mapping->ranges = heap_calloc(ranges_count, sizeof(*mapping->ranges)); memcpy(mapping->ranges, ranges, sizeof(*mapping->ranges) * ranges_count); @@ -2339,9 +2329,7 @@ static HRESULT WINAPI fontfallbackbuilder_AddMapping(IDWriteFontFallbackBuilder
static HRESULT WINAPI fontfallbackbuilder_AddMappings(IDWriteFontFallbackBuilder *iface, IDWriteFontFallback *fallback) { - struct dwrite_fontfallback_builder *fallbackbuilder = impl_from_IDWriteFontFallbackBuilder(iface); - - FIXME("(%p)->(%p): stub\n", fallbackbuilder, fallback); + FIXME("%p, %p stub.\n", iface, fallback);
return E_NOTIMPL; } @@ -2352,7 +2340,7 @@ static HRESULT WINAPI fontfallbackbuilder_CreateFontFallback(IDWriteFontFallback struct dwrite_fontfallback_builder *fallbackbuilder = impl_from_IDWriteFontFallbackBuilder(iface); struct dwrite_fontfallback *fallback;
- FIXME("(%p)->(%p): stub\n", fallbackbuilder, ret); + FIXME("%p, %p stub.\n", iface, ret);
*ret = NULL;
@@ -2390,7 +2378,7 @@ HRESULT create_fontfallback_builder(IDWriteFactory5 *factory, IDWriteFontFallbac return E_OUTOFMEMORY;
builder->IDWriteFontFallbackBuilder_iface.lpVtbl = &fontfallbackbuildervtbl; - builder->ref = 1; + builder->refcount = 1; builder->factory = factory; IDWriteFactory5_AddRef(builder->factory);
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/main.c | 146 ++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 74 deletions(-)
diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c index 1816fbc8f1..3fe2b7eaa7 100644 --- a/dlls/dwrite/main.c +++ b/dlls/dwrite/main.c @@ -241,13 +241,14 @@ struct localizedpair { WCHAR *string; };
-struct localizedstrings { +struct localizedstrings +{ IDWriteLocalizedStrings IDWriteLocalizedStrings_iface; - LONG ref; + LONG refcount;
struct localizedpair *data; - UINT32 count; - UINT32 alloc; + size_t size; + size_t count; };
static inline struct localizedstrings *impl_from_IDWriteLocalizedStrings(IDWriteLocalizedStrings *iface) @@ -275,54 +276,61 @@ static HRESULT WINAPI localizedstrings_QueryInterface(IDWriteLocalizedStrings *i
static ULONG WINAPI localizedstrings_AddRef(IDWriteLocalizedStrings *iface) { - struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); - ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p)->(%d)\n", This, ref); - return ref; + struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface); + ULONG refcount = InterlockedIncrement(&strings->refcount); + + TRACE("%p, refcount %d.\n", iface, refcount); + + return refcount; }
static ULONG WINAPI localizedstrings_Release(IDWriteLocalizedStrings *iface) { - struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); - ULONG ref = InterlockedDecrement(&This->ref); - - TRACE("(%p)->(%d)\n", This, ref); + struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface); + ULONG refcount = InterlockedDecrement(&strings->refcount); + size_t i;
- if (!ref) { - unsigned int i; + TRACE("%p, refcount %d.\n", iface, refcount);
- for (i = 0; i < This->count; i++) { - heap_free(This->data[i].locale); - heap_free(This->data[i].string); + if (!refcount) + { + for (i = 0; i < strings->count; ++i) + { + heap_free(strings->data[i].locale); + heap_free(strings->data[i].string); }
- heap_free(This->data); - heap_free(This); + heap_free(strings->data); + heap_free(strings); }
- return ref; + return refcount; }
static UINT32 WINAPI localizedstrings_GetCount(IDWriteLocalizedStrings *iface) { - struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); - TRACE("(%p)\n", This); - return This->count; + struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface); + + TRACE("%p.\n", iface); + + return strings->count; }
static HRESULT WINAPI localizedstrings_FindLocaleName(IDWriteLocalizedStrings *iface, WCHAR const *locale_name, UINT32 *index, BOOL *exists) { - struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); - UINT32 i; + struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface); + size_t i;
- TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(locale_name), index, exists); + TRACE("%p, %s, %p, %p.\n", iface, debugstr_w(locale_name), index, exists);
*exists = FALSE; *index = ~0;
- for (i = 0; i < This->count; i++) { - if (!strcmpiW(This->data[i].locale, locale_name)) { + for (i = 0; i < strings->count; ++i) + { + if (!strcmpiW(strings->data[i].locale, locale_name)) + { *exists = TRUE; *index = i; break; @@ -334,16 +342,17 @@ static HRESULT WINAPI localizedstrings_FindLocaleName(IDWriteLocalizedStrings *i
static HRESULT WINAPI localizedstrings_GetLocaleNameLength(IDWriteLocalizedStrings *iface, UINT32 index, UINT32 *length) { - struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); + struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
- TRACE("(%p)->(%u %p)\n", This, index, length); + TRACE("%p, %u, %p.\n", iface, index, length);
- if (index >= This->count) { + if (index >= strings->count) + { *length = (UINT32)-1; return E_FAIL; }
- *length = strlenW(This->data[index].locale); + *length = strlenW(strings->data[index].locale); return S_OK; }
@@ -416,58 +425,45 @@ static const IDWriteLocalizedStringsVtbl localizedstringsvtbl = {
HRESULT create_localizedstrings(IDWriteLocalizedStrings **strings) { - struct localizedstrings *This; + struct localizedstrings *object;
*strings = NULL;
- This = heap_alloc(sizeof(struct localizedstrings)); - if (!This) return E_OUTOFMEMORY; - - This->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl; - This->ref = 1; - This->count = 0; - This->data = heap_alloc_zero(sizeof(struct localizedpair)); - if (!This->data) { - heap_free(This); + object = heap_alloc_zero(sizeof(*object)); + if (!object) return E_OUTOFMEMORY; - } - This->alloc = 1;
- *strings = &This->IDWriteLocalizedStrings_iface; + object->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl; + object->refcount = 1; + + *strings = &object->IDWriteLocalizedStrings_iface;
return S_OK; }
HRESULT add_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *locale, const WCHAR *string) { - struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); - UINT32 i; + struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface); + size_t i, count = strings->count;
/* make sure there's no duplicates */ - for (i = 0; i < This->count; i++) - if (!strcmpW(This->data[i].locale, locale)) + for (i = 0; i < count; i++) + if (!strcmpW(strings->data[i].locale, locale)) return S_OK;
- if (This->count == This->alloc) { - void *ptr; - - ptr = heap_realloc(This->data, 2*This->alloc*sizeof(struct localizedpair)); - if (!ptr) - return E_OUTOFMEMORY; - - This->alloc *= 2; - This->data = ptr; - } + if (!dwrite_array_reserve((void **)&strings->data, &strings->size, strings->count + 1, sizeof(*strings->data))) + return E_OUTOFMEMORY;
- This->data[This->count].locale = heap_strdupW(locale); - This->data[This->count].string = heap_strdupW(string); - if (!This->data[This->count].locale || !This->data[This->count].string) { - heap_free(This->data[This->count].locale); - heap_free(This->data[This->count].string); + strings->data[count].locale = heap_strdupW(locale); + strings->data[count].string = heap_strdupW(string); + if (!strings->data[count].locale || !strings->data[count].string) + { + heap_free(strings->data[count].locale); + heap_free(strings->data[count].string); return E_OUTOFMEMORY; }
- This->count++; + strings->count++;
return S_OK; } @@ -475,7 +471,7 @@ HRESULT add_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *locale, HRESULT clone_localizedstring(IDWriteLocalizedStrings *iface, IDWriteLocalizedStrings **ret) { struct localizedstrings *strings, *strings_clone; - int i; + size_t i;
*ret = NULL;
@@ -483,24 +479,26 @@ HRESULT clone_localizedstring(IDWriteLocalizedStrings *iface, IDWriteLocalizedSt return S_FALSE;
strings = impl_from_IDWriteLocalizedStrings(iface); - strings_clone = heap_alloc(sizeof(*strings_clone)); + strings_clone = heap_alloc_zero(sizeof(*strings_clone)); if (!strings_clone) return E_OUTOFMEMORY;
- strings_clone->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl; - strings_clone->ref = 1; - strings_clone->count = strings->count; - strings_clone->data = heap_calloc(strings_clone->count, sizeof(*strings_clone->data)); - if (!strings_clone->data) { + if (!dwrite_array_reserve((void **)&strings_clone->data, &strings_clone->size, strings->count, + sizeof(*strings_clone->data))) + { heap_free(strings_clone); return E_OUTOFMEMORY; } - for (i = 0; i < strings_clone->count; i++) + + strings_clone->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl; + strings_clone->refcount = 1; + strings_clone->count = strings->count; + + for (i = 0; i < strings_clone->count; ++i) { strings_clone->data[i].locale = heap_strdupW(strings->data[i].locale); strings_clone->data[i].string = heap_strdupW(strings->data[i].string); } - strings_clone->alloc = strings_clone->count;
*ret = &strings_clone->IDWriteLocalizedStrings_iface;
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/layout.c | 116 +++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 65 deletions(-)
diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c index 4e9ce14f61..5140decbfa 100644 --- a/dlls/dwrite/layout.c +++ b/dlls/dwrite/layout.c @@ -227,9 +227,11 @@ struct layout_cluster { UINT32 position; /* relative to run, first cluster has 0 position */ };
-struct layout_line { - FLOAT height; /* height based on content */ - FLOAT baseline; /* baseline based on content */ +struct layout_line +{ + float height; /* height based on content */ + float baseline; /* baseline based on content */ + DWRITE_LINE_METRICS1 metrics; };
enum layout_recompute_mask { @@ -276,8 +278,7 @@ struct dwrite_textlayout { FLOAT minwidth;
struct layout_line *lines; - DWRITE_LINE_METRICS1 *linemetrics; - UINT32 line_alloc; + size_t lines_size;
DWRITE_TEXT_METRICS1 metrics; DWRITE_OVERHANG_METRICS overhangs; @@ -1364,16 +1365,16 @@ static void layout_apply_line_spacing(struct dwrite_textlayout *layout, UINT32 l switch (layout->format.spacing.method) { case DWRITE_LINE_SPACING_METHOD_DEFAULT: - layout->linemetrics[line].height = layout->lines[line].height; - layout->linemetrics[line].baseline = layout->lines[line].baseline; + layout->lines[line].metrics.height = layout->lines[line].height; + layout->lines[line].metrics.baseline = layout->lines[line].baseline; break; case DWRITE_LINE_SPACING_METHOD_UNIFORM: - layout->linemetrics[line].height = layout->format.spacing.height; - layout->linemetrics[line].baseline = layout->format.spacing.baseline; + layout->lines[line].metrics.height = layout->format.spacing.height; + layout->lines[line].metrics.baseline = layout->format.spacing.baseline; break; case DWRITE_LINE_SPACING_METHOD_PROPORTIONAL: - layout->linemetrics[line].height = layout->lines[line].height * layout->format.spacing.height; - layout->linemetrics[line].baseline = layout->lines[line].baseline * layout->format.spacing.baseline; + layout->lines[line].metrics.height = layout->lines[line].height * layout->format.spacing.height; + layout->lines[line].metrics.baseline = layout->lines[line].baseline * layout->format.spacing.baseline; break; default: ERR("Unknown spacing method %u\n", layout->format.spacing.method); @@ -1382,37 +1383,15 @@ static void layout_apply_line_spacing(struct dwrite_textlayout *layout, UINT32 l
static HRESULT layout_set_line_metrics(struct dwrite_textlayout *layout, DWRITE_LINE_METRICS1 *metrics) { - UINT32 i = layout->metrics.lineCount; - - if (!layout->line_alloc) { - layout->line_alloc = 5; - layout->linemetrics = heap_calloc(layout->line_alloc, sizeof(*layout->linemetrics)); - layout->lines = heap_calloc(layout->line_alloc, sizeof(*layout->lines)); - if (!layout->linemetrics || !layout->lines) { - heap_free(layout->linemetrics); - heap_free(layout->lines); - layout->linemetrics = NULL; - layout->lines = NULL; - return E_OUTOFMEMORY; - } - } - - if (layout->metrics.lineCount == layout->line_alloc) { - DWRITE_LINE_METRICS1 *metrics; - struct layout_line *lines; - - if ((metrics = heap_realloc(layout->linemetrics, layout->line_alloc * 2 * sizeof(*layout->linemetrics)))) - layout->linemetrics = metrics; - if ((lines = heap_realloc(layout->lines, layout->line_alloc * 2 * sizeof(*layout->lines)))) - layout->lines = lines; + size_t i = layout->metrics.lineCount;
- if (!metrics || !lines) - return E_OUTOFMEMORY; - - layout->line_alloc *= 2; + if (!dwrite_array_reserve((void **)&layout->lines, &layout->lines_size, layout->metrics.lineCount + 1, + sizeof(*layout->lines))) + { + return E_OUTOFMEMORY; }
- layout->linemetrics[i] = *metrics; + layout->lines[i].metrics = *metrics; layout->lines[i].height = metrics->height; layout->lines[i].baseline = metrics->baseline;
@@ -1674,8 +1653,9 @@ static void layout_apply_par_alignment(struct dwrite_textlayout *layout)
erun = layout_get_next_erun(layout, NULL); inrun = layout_get_next_inline_run(layout, NULL); - for (line = 0; line < layout->metrics.lineCount; line++) { - FLOAT pos_y = origin_y + layout->linemetrics[line].baseline; + for (line = 0; line < layout->metrics.lineCount; line++) + { + float pos_y = origin_y + layout->lines[line].metrics.baseline;
while (erun && erun->line == line) { erun->origin.y = pos_y; @@ -1687,7 +1667,7 @@ static void layout_apply_par_alignment(struct dwrite_textlayout *layout) inrun = layout_get_next_inline_run(layout, inrun); }
- origin_y += layout->linemetrics[line].height; + origin_y += layout->lines[line].metrics.height; } }
@@ -1992,8 +1972,9 @@ static void layout_set_line_positions(struct dwrite_textlayout *layout) erun = layout_get_next_erun(layout, NULL); inrun = layout_get_next_inline_run(layout, NULL);
- for (line = 0, origin_y = 0.0f; line < layout->metrics.lineCount; line++) { - FLOAT pos_y = origin_y + layout->linemetrics[line].baseline; + for (line = 0, origin_y = 0.0f; line < layout->metrics.lineCount; line++) + { + float pos_y = origin_y + layout->lines[line].metrics.baseline;
/* For all runs on this line */ while (erun && erun->line == line) { @@ -2007,7 +1988,7 @@ static void layout_set_line_positions(struct dwrite_textlayout *layout) inrun = layout_get_next_inline_run(layout, inrun); }
- origin_y += layout->linemetrics[line].height; + origin_y += layout->lines[line].metrics.height; }
layout->metrics.height = origin_y; @@ -2862,7 +2843,6 @@ static ULONG WINAPI dwritetextlayout_Release(IDWriteTextLayout3 *iface) heap_free(This->actual_breakpoints); heap_free(This->clustermetrics); heap_free(This->clusters); - heap_free(This->linemetrics); heap_free(This->lines); heap_free(This->str); heap_free(This); @@ -3574,23 +3554,25 @@ static HRESULT WINAPI dwritetextlayout_Draw(IDWriteTextLayout3 *iface, static HRESULT WINAPI dwritetextlayout_GetLineMetrics(IDWriteTextLayout3 *iface, DWRITE_LINE_METRICS *metrics, UINT32 max_count, UINT32 *count) { - struct dwrite_textlayout *This = impl_from_IDWriteTextLayout3(iface); + struct dwrite_textlayout *layout = impl_from_IDWriteTextLayout3(iface); + unsigned int line_count; HRESULT hr; + size_t i;
- TRACE("(%p)->(%p %u %p)\n", This, metrics, max_count, count); + TRACE("%p, %p, %u, %p.\n", iface, metrics, max_count, count);
- hr = layout_compute_effective_runs(This); - if (FAILED(hr)) + if (FAILED(hr = layout_compute_effective_runs(layout))) return hr;
- if (metrics) { - UINT32 i, c = min(max_count, This->metrics.lineCount); - for (i = 0; i < c; i++) - memcpy(metrics + i, This->linemetrics + i, sizeof(*metrics)); + if (metrics) + { + line_count = min(max_count, layout->metrics.lineCount); + for (i = 0; i < line_count; ++i) + memcpy(&metrics[i], &layout->lines[i].metrics, sizeof(*metrics)); }
- *count = This->metrics.lineCount; - return max_count >= This->metrics.lineCount ? S_OK : E_NOT_SUFFICIENT_BUFFER; + *count = layout->metrics.lineCount; + return max_count >= layout->metrics.lineCount ? S_OK : E_NOT_SUFFICIENT_BUFFER; }
static HRESULT layout_update_metrics(struct dwrite_textlayout *layout) @@ -4061,20 +4043,25 @@ static HRESULT WINAPI dwritetextlayout3_GetLineSpacing(IDWriteTextLayout3 *iface static HRESULT WINAPI dwritetextlayout3_GetLineMetrics(IDWriteTextLayout3 *iface, DWRITE_LINE_METRICS1 *metrics, UINT32 max_count, UINT32 *count) { - struct dwrite_textlayout *This = impl_from_IDWriteTextLayout3(iface); + struct dwrite_textlayout *layout = impl_from_IDWriteTextLayout3(iface); + unsigned int line_count; HRESULT hr; + size_t i;
- TRACE("(%p)->(%p %u %p)\n", This, metrics, max_count, count); + TRACE("%p, %p, %u, %p.\n", iface, metrics, max_count, count);
- hr = layout_compute_effective_runs(This); - if (FAILED(hr)) + if (FAILED(hr = layout_compute_effective_runs(layout))) return hr;
if (metrics) - memcpy(metrics, This->linemetrics, sizeof(*metrics) * min(max_count, This->metrics.lineCount)); + { + line_count = min(max_count, layout->metrics.lineCount); + for (i = 0; i < line_count; ++i) + metrics[i] = layout->lines[i].metrics; + }
- *count = This->metrics.lineCount; - return max_count >= This->metrics.lineCount ? S_OK : E_NOT_SUFFICIENT_BUFFER; + *count = layout->metrics.lineCount; + return max_count >= layout->metrics.lineCount ? S_OK : E_NOT_SUFFICIENT_BUFFER; }
static const IDWriteTextLayout3Vtbl dwritetextlayoutvtbl = { @@ -4978,9 +4965,8 @@ static HRESULT init_textlayout(const struct textlayout_desc *desc, struct dwrite layout->cluster_count = 0; layout->clustermetrics = NULL; layout->clusters = NULL; - layout->linemetrics = NULL; layout->lines = NULL; - layout->line_alloc = 0; + layout->lines_size = 0; layout->minwidth = 0.0f; list_init(&layout->eruns); list_init(&layout->inlineobjects);
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com ---
Thanks, Gijs.
dlls/dwrite/tests/layout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c index 8337ce7be7..2c90e31a85 100644 --- a/dlls/dwrite/tests/layout.c +++ b/dlls/dwrite/tests/layout.c @@ -3307,7 +3307,7 @@ todo_wine ok(metrics.layoutWidth == 500.0, "Unexpected box width %f.\n", metrics.layoutWidth); ok(metrics.layoutHeight == 1000.0, "Unexpected box height %f.\n", metrics.layoutHeight); ok(metrics.maxBidiReorderingDepth == 1, "Unexpected reordering depth %u.\n", metrics.maxBidiReorderingDepth); - ok(metrics.lineCount == 1, "Unexpected line coun %u.\n", metrics.lineCount); + ok(metrics.lineCount == 1, "Unexpected line count %u.\n", metrics.lineCount); IDWriteTextLayout_Release(layout);
IDWriteTextFormat_Release(format);