dwrite: Implement centered text alignment.
This commit is contained in:
parent
f039e15182
commit
bb0c6f74a5
|
@ -1165,7 +1165,7 @@ static void layout_apply_trailing_alignment(struct dwrite_textlayout *layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (inrun && inrun->line == line) {
|
while (inrun && inrun->line == line) {
|
||||||
erun->align_dx = shift;
|
inrun->align_dx = shift;
|
||||||
inrun = layout_get_next_inline_run(layout, inrun);
|
inrun = layout_get_next_inline_run(layout, inrun);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1173,6 +1173,33 @@ static void layout_apply_trailing_alignment(struct dwrite_textlayout *layout)
|
||||||
layout->metrics.left = layout->metrics.layoutWidth - layout->metrics.width;
|
layout->metrics.left = layout->metrics.layoutWidth - layout->metrics.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void layout_apply_centered_alignment(struct dwrite_textlayout *layout)
|
||||||
|
{
|
||||||
|
struct layout_effective_inline *inrun;
|
||||||
|
struct layout_effective_run *erun;
|
||||||
|
UINT32 line;
|
||||||
|
|
||||||
|
erun = layout_get_next_erun(layout, NULL);
|
||||||
|
inrun = layout_get_next_inline_run(layout, NULL);
|
||||||
|
|
||||||
|
for (line = 0; line < layout->metrics.lineCount; line++) {
|
||||||
|
FLOAT width = layout_get_line_width(layout, erun, inrun, line);
|
||||||
|
FLOAT shift = (layout->metrics.layoutWidth - width) / 2.0;
|
||||||
|
|
||||||
|
while (erun && erun->line == line) {
|
||||||
|
erun->align_dx = shift;
|
||||||
|
erun = layout_get_next_erun(layout, erun);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (inrun && inrun->line == line) {
|
||||||
|
inrun->align_dx = shift;
|
||||||
|
inrun = layout_get_next_inline_run(layout, inrun);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
layout->metrics.left = (layout->metrics.layoutWidth - layout->metrics.width) / 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
static void layout_apply_text_alignment(struct dwrite_textlayout *layout)
|
static void layout_apply_text_alignment(struct dwrite_textlayout *layout)
|
||||||
{
|
{
|
||||||
switch (layout->format.textalignment)
|
switch (layout->format.textalignment)
|
||||||
|
@ -1183,8 +1210,10 @@ static void layout_apply_text_alignment(struct dwrite_textlayout *layout)
|
||||||
case DWRITE_TEXT_ALIGNMENT_TRAILING:
|
case DWRITE_TEXT_ALIGNMENT_TRAILING:
|
||||||
layout_apply_trailing_alignment(layout);
|
layout_apply_trailing_alignment(layout);
|
||||||
break;
|
break;
|
||||||
case DWRITE_TEXT_ALIGNMENT_JUSTIFIED:
|
|
||||||
case DWRITE_TEXT_ALIGNMENT_CENTER:
|
case DWRITE_TEXT_ALIGNMENT_CENTER:
|
||||||
|
layout_apply_centered_alignment(layout);
|
||||||
|
break;
|
||||||
|
case DWRITE_TEXT_ALIGNMENT_JUSTIFIED:
|
||||||
FIXME("alignment %d not implemented\n", layout->format.textalignment);
|
FIXME("alignment %d not implemented\n", layout->format.textalignment);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2889,6 +2889,7 @@ todo_wine {
|
||||||
|
|
||||||
static void test_SetTextAlignment(void)
|
static void test_SetTextAlignment(void)
|
||||||
{
|
{
|
||||||
|
static const WCHAR str2W[] = {'a','a','a','a','a',0};
|
||||||
static const WCHAR strW[] = {'a',0};
|
static const WCHAR strW[] = {'a',0};
|
||||||
DWRITE_CLUSTER_METRICS clusters[1];
|
DWRITE_CLUSTER_METRICS clusters[1];
|
||||||
DWRITE_TEXT_METRICS metrics;
|
DWRITE_TEXT_METRICS metrics;
|
||||||
|
@ -2992,6 +2993,35 @@ static void test_SetTextAlignment(void)
|
||||||
ok(metrics.lineCount == 1, "got %d\n", metrics.lineCount);
|
ok(metrics.lineCount == 1, "got %d\n", metrics.lineCount);
|
||||||
IDWriteTextLayout_Release(layout);
|
IDWriteTextLayout_Release(layout);
|
||||||
|
|
||||||
|
/* max width less than total run width, trailing alignment */
|
||||||
|
hr = IDWriteTextFormat_SetWordWrapping(format, DWRITE_WORD_WRAPPING_NO_WRAP);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDWriteFactory_CreateTextLayout(factory, str2W, 5, format, 2*clusters[0].width, 100.0, &layout);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
hr = IDWriteTextLayout_GetMetrics(layout, &metrics);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
ok(metrics.left == metrics.layoutWidth - metrics.width, "got %.2f\n", metrics.left);
|
||||||
|
todo_wine
|
||||||
|
ok(metrics.width == 5*clusters[0].width, "got %.2f\n", metrics.width);
|
||||||
|
ok(metrics.lineCount == 1, "got %d\n", metrics.lineCount);
|
||||||
|
IDWriteTextLayout_Release(layout);
|
||||||
|
|
||||||
|
/* maxwidth is 500, centered */
|
||||||
|
hr = IDWriteTextFormat_SetTextAlignment(format, DWRITE_TEXT_ALIGNMENT_CENTER);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDWriteFactory_CreateTextLayout(factory, str2W, 5, format, 500.0, 100.0, &layout);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDWriteTextLayout_GetMetrics(layout, &metrics);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
ok(metrics.left == (metrics.layoutWidth - metrics.width) / 2.0, "got %.2f\n", metrics.left);
|
||||||
|
ok(metrics.width == 5*clusters[0].width, "got %.2f\n", metrics.width);
|
||||||
|
ok(metrics.lineCount == 1, "got %d\n", metrics.lineCount);
|
||||||
|
|
||||||
|
IDWriteTextLayout_Release(layout);
|
||||||
|
|
||||||
IDWriteTextFormat_Release(format);
|
IDWriteTextFormat_Release(format);
|
||||||
IDWriteFactory_Release(factory);
|
IDWriteFactory_Release(factory);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue