Commit 1cbc74a3 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite/layout: Implement axis values property for the format object.

parent 24e41be1
......@@ -62,6 +62,9 @@ struct dwrite_textformat_data
IDWriteFontCollection *collection;
IDWriteFontFallback *fallback;
DWRITE_FONT_AXIS_VALUE *axis_values;
unsigned int axis_values_count;
};
enum layout_range_attr_kind {
......@@ -328,6 +331,7 @@ static void release_format_data(struct dwrite_textformat_data *data)
if (data->trimmingsign) IDWriteInlineObject_Release(data->trimmingsign);
heap_free(data->family_name);
heap_free(data->locale);
heap_free(data->axis_values);
}
static inline struct dwrite_textlayout *impl_from_IDWriteTextLayout4(IDWriteTextLayout4 *iface)
......@@ -465,6 +469,41 @@ static inline HRESULT format_set_linespacing(struct dwrite_textformat_data *form
return S_OK;
}
static HRESULT format_set_font_axisvalues(struct dwrite_textformat_data *format,
DWRITE_FONT_AXIS_VALUE const *axis_values, unsigned int num_values)
{
heap_free(format->axis_values);
format->axis_values = NULL;
format->axis_values_count = 0;
if (num_values)
{
if (!(format->axis_values = heap_calloc(num_values, sizeof(*axis_values))))
return E_OUTOFMEMORY;
memcpy(format->axis_values, axis_values, num_values * sizeof(*axis_values));
format->axis_values_count = num_values;
}
return S_OK;
}
static HRESULT format_get_font_axisvalues(struct dwrite_textformat_data *format,
DWRITE_FONT_AXIS_VALUE *axis_values, unsigned int num_values)
{
if (!format->axis_values_count)
{
if (num_values) memset(axis_values, 0, num_values * sizeof(*axis_values));
return S_OK;
}
if (num_values < format->axis_values_count)
return E_NOT_SUFFICIENT_BUFFER;
memcpy(axis_values, format->axis_values, min(num_values, format->axis_values_count) * sizeof(*axis_values));
return S_OK;
}
static HRESULT get_fontfallback_from_format(const struct dwrite_textformat_data *format, IDWriteFontFallback **fallback)
{
*fallback = format->fallback;
......@@ -4922,24 +4961,30 @@ static HRESULT WINAPI dwritetextformat2_layout_GetLineSpacing(IDWriteTextFormat3
static HRESULT WINAPI dwritetextformat3_layout_SetFontAxisValues(IDWriteTextFormat3 *iface,
DWRITE_FONT_AXIS_VALUE const *axis_values, UINT32 num_values)
{
FIXME("%p, %p, %u.\n", iface, axis_values, num_values);
struct dwrite_textlayout *layout = impl_layout_from_IDWriteTextFormat3(iface);
return E_NOTIMPL;
TRACE("%p, %p, %u.\n", iface, axis_values, num_values);
return format_set_font_axisvalues(&layout->format, axis_values, num_values);
}
static UINT32 WINAPI dwritetextformat3_layout_GetFontAxisValueCount(IDWriteTextFormat3 *iface)
{
FIXME("%p.\n", iface);
struct dwrite_textlayout *layout = impl_layout_from_IDWriteTextFormat3(iface);
return 0;
TRACE("%p.\n", iface);
return layout->format.axis_values_count;
}
static HRESULT WINAPI dwritetextformat3_layout_GetFontAxisValues(IDWriteTextFormat3 *iface,
DWRITE_FONT_AXIS_VALUE const *axis_values, UINT32 num_values)
DWRITE_FONT_AXIS_VALUE *axis_values, UINT32 num_values)
{
FIXME("%p, %p, %u.\n", iface, axis_values, num_values);
struct dwrite_textlayout *layout = impl_layout_from_IDWriteTextFormat3(iface);
return E_NOTIMPL;
TRACE("%p, %p, %u.\n", iface, axis_values, num_values);
return format_get_font_axisvalues(&layout->format, axis_values, num_values);
}
static DWRITE_AUTOMATIC_FONT_AXES WINAPI dwritetextformat3_layout_GetAutomaticFontAxes(IDWriteTextFormat3 *iface)
......@@ -6042,24 +6087,30 @@ static HRESULT WINAPI dwritetextformat2_GetLineSpacing(IDWriteTextFormat3 *iface
static HRESULT WINAPI dwritetextformat3_SetFontAxisValues(IDWriteTextFormat3 *iface,
DWRITE_FONT_AXIS_VALUE const *axis_values, UINT32 num_values)
{
FIXME("%p, %p, %u.\n", iface, axis_values, num_values);
struct dwrite_textformat *format = impl_from_IDWriteTextFormat3(iface);
return E_NOTIMPL;
TRACE("%p, %p, %u.\n", iface, axis_values, num_values);
return format_set_font_axisvalues(&format->format, axis_values, num_values);
}
static UINT32 WINAPI dwritetextformat3_GetFontAxisValueCount(IDWriteTextFormat3 *iface)
{
FIXME("%p.\n", iface);
struct dwrite_textformat *format = impl_from_IDWriteTextFormat3(iface);
return 0;
TRACE("%p.\n", iface);
return format->format.axis_values_count;
}
static HRESULT WINAPI dwritetextformat3_GetFontAxisValues(IDWriteTextFormat3 *iface,
DWRITE_FONT_AXIS_VALUE const *axis_values, UINT32 num_values)
DWRITE_FONT_AXIS_VALUE *axis_values, UINT32 num_values)
{
FIXME("%p, %p, %u.\n", iface, axis_values, num_values);
struct dwrite_textformat *format = impl_from_IDWriteTextFormat3(iface);
return E_NOTIMPL;
TRACE("%p, %p, %u.\n", iface, axis_values, num_values);
return format_get_font_axisvalues(&format->format, axis_values, num_values);
}
static DWRITE_AUTOMATIC_FONT_AXES WINAPI dwritetextformat3_GetAutomaticFontAxes(IDWriteTextFormat3 *iface)
......
......@@ -5894,7 +5894,7 @@ static void test_text_format_axes(void)
{
IDWriteFontCollection *collection;
IDWriteFontCollection2 *collection2;
DWRITE_FONT_AXIS_VALUE axis;
DWRITE_FONT_AXIS_VALUE axes[2];
IDWriteTextFormat3 *format3;
DWRITE_FONT_STRETCH stretch;
DWRITE_FONT_WEIGHT weight;
......@@ -5944,9 +5944,9 @@ if (SUCCEEDED(hr))
ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "Unexpected font weight %d.\n", weight);
/* Regular properties are not set from axis values. */
axis.axisTag = DWRITE_FONT_AXIS_TAG_WEIGHT;
axis.value = 200.0f;
hr = IDWriteTextFormat3_SetFontAxisValues(format3, &axis, 1);
axes[0].axisTag = DWRITE_FONT_AXIS_TAG_WEIGHT;
axes[0].value = 200.0f;
hr = IDWriteTextFormat3_SetFontAxisValues(format3, axes, 1);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
weight = IDWriteTextFormat3_GetFontWeight(format3);
......@@ -5965,6 +5965,36 @@ if (SUCCEEDED(hr))
count = IDWriteTextFormat3_GetFontAxisValueCount(format3);
ok(!count, "Unexpected axis count %u.\n", count);
axes[0].axisTag = DWRITE_FONT_AXIS_TAG_WEIGHT;
hr = IDWriteTextFormat3_GetFontAxisValues(format3, axes, 1);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(axes[0].axisTag == 0 && axes[0].value == 0.0f, "Unexpected value.\n");
axes[0].axisTag = DWRITE_FONT_AXIS_TAG_WEIGHT;
axes[0].value = 200.0f;
axes[1].axisTag = DWRITE_FONT_AXIS_TAG_WIDTH;
axes[1].value = 2.0f;
hr = IDWriteTextFormat3_SetFontAxisValues(format3, axes, 2);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IDWriteTextFormat3_GetFontAxisValueCount(format3);
ok(count == 2, "Unexpected axis count %u.\n", count);
hr = IDWriteTextFormat3_GetFontAxisValues(format3, axes, 1);
ok(hr == E_NOT_SUFFICIENT_BUFFER, "Unexpected hr %#x.\n", hr);
hr = IDWriteTextFormat3_GetFontAxisValues(format3, axes, 0);
ok(hr == E_NOT_SUFFICIENT_BUFFER, "Unexpected hr %#x.\n", hr);
hr = IDWriteTextFormat3_GetFontAxisValues(format3, axes, 2);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IDWriteTextFormat3_SetFontAxisValues(format3, axes, 0);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IDWriteTextFormat3_GetFontAxisValueCount(format3);
ok(!count, "Unexpected axis count %u.\n", count);
IDWriteTextFormat3_Release(format3);
IDWriteTextFormat_Release(format);
......
......@@ -562,7 +562,7 @@ interface IDWriteTextFormat3 : IDWriteTextFormat2
UINT32 num_values);
UINT32 GetFontAxisValueCount();
HRESULT GetFontAxisValues(
DWRITE_FONT_AXIS_VALUE const *axis_values,
DWRITE_FONT_AXIS_VALUE *axis_values,
UINT32 num_values);
DWRITE_AUTOMATIC_FONT_AXES GetAutomaticFontAxes();
HRESULT SetAutomaticFontAxes(DWRITE_AUTOMATIC_FONT_AXES axes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment