dwrite: Zero width space U+200b is not a whitespace from analyzer/layout point of view.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2016-01-26 15:44:44 +03:00 committed by Alexandre Julliard
parent 36917d8844
commit 0b7f857845
3 changed files with 66 additions and 25 deletions

View File

@ -347,7 +347,7 @@ static HRESULT analyze_linebreaks(const WCHAR *text, UINT32 count, DWRITE_LINE_B
breakpoints[i].breakConditionBefore = DWRITE_BREAK_CONDITION_CAN_BREAK;
breakpoints[i].breakConditionAfter = DWRITE_BREAK_CONDITION_CAN_BREAK;
breakpoints[i].isWhitespace = break_class[i] == b_BK || break_class[i] == b_ZW || break_class[i] == b_SP || isspaceW(text[i]);
breakpoints[i].isWhitespace = !!isspaceW(text[i]);
breakpoints[i].isSoftHyphen = FALSE;
breakpoints[i].padding = 0;

View File

@ -966,21 +966,26 @@ struct linebreaks_test {
};
static struct linebreaks_test linebreaks_tests[] = {
{ {'A','-','B',' ','C',0x58a,'D',0x2010,'E',0x2012,'F',0x2013,'\t',0},
{ {'A','-','B',' ','C',0x58a,'D',0x2010,'E',0x2012,'F',0x2013,'\t',0xc,0xb,0x2028,0x2029,0x200b,0},
{
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, TRUE, FALSE },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, FALSE, FALSE },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, TRUE, FALSE }
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, 1, 0 },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_CAN_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, 0, 0 },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, 1, 0 },
{ DWRITE_BREAK_CONDITION_MAY_NOT_BREAK, DWRITE_BREAK_CONDITION_MUST_BREAK, 1, 0 },
{ DWRITE_BREAK_CONDITION_MUST_BREAK, DWRITE_BREAK_CONDITION_MUST_BREAK, 1, 0 },
{ DWRITE_BREAK_CONDITION_MUST_BREAK, DWRITE_BREAK_CONDITION_MUST_BREAK, 1, 0 },
{ DWRITE_BREAK_CONDITION_MUST_BREAK, DWRITE_BREAK_CONDITION_MUST_BREAK, 1, 0 },
{ DWRITE_BREAK_CONDITION_MUST_BREAK, DWRITE_BREAK_CONDITION_CAN_BREAK, 0, 0 },
}
},
{ { 0 } }
@ -988,6 +993,7 @@ static struct linebreaks_test linebreaks_tests[] = {
static void compare_breakpoints(const struct linebreaks_test *test, DWRITE_LINE_BREAKPOINT *actual)
{
static const char *conditions[] = {"N","CB","NB","B"};
const WCHAR *text = test->text;
int cmp = memcmp(test->bp, actual, sizeof(*actual)*BREAKPOINT_COUNT);
ok(!cmp, "%s: got wrong breakpoint data\n", wine_dbgstr_w(test->text));
@ -995,16 +1001,16 @@ static void compare_breakpoints(const struct linebreaks_test *test, DWRITE_LINE_
int i = 0;
while (*text) {
ok(!memcmp(&test->bp[i], &actual[i], sizeof(*actual)),
"%s: got (%d, %d, %d, %d), expected (%d, %d, %d, %d)\n",
"%s: got [%s, %s] (%s, %s), expected [%s, %s] (%s, %s)\n",
wine_dbgstr_wn(&test->text[i], 1),
g_actual_bp[i].breakConditionBefore,
g_actual_bp[i].breakConditionAfter,
g_actual_bp[i].isWhitespace,
g_actual_bp[i].isSoftHyphen,
test->bp[i].breakConditionBefore,
test->bp[i].breakConditionAfter,
test->bp[i].isWhitespace,
test->bp[i].isSoftHyphen);
conditions[g_actual_bp[i].breakConditionBefore],
conditions[g_actual_bp[i].breakConditionAfter],
g_actual_bp[i].isWhitespace ? "WS" : "0",
g_actual_bp[i].isSoftHyphen ? "SHY" : "0",
conditions[test->bp[i].breakConditionBefore],
conditions[test->bp[i].breakConditionAfter],
test->bp[i].isWhitespace ? "WS" : "0",
test->bp[i].isSoftHyphen ? "SHY" : "0");
text++;
i++;
}
@ -1016,6 +1022,7 @@ static void test_AnalyzeLineBreakpoints(void)
static const WCHAR emptyW[] = {0};
const struct linebreaks_test *ptr = linebreaks_tests;
IDWriteTextAnalyzer *analyzer;
UINT32 i = 0;
HRESULT hr;
hr = IDWriteFactory_CreateTextAnalyzer(factory, &analyzer);
@ -1027,13 +1034,24 @@ static void test_AnalyzeLineBreakpoints(void)
while (*ptr->text)
{
UINT32 len;
g_source = ptr->text;
len = lstrlenW(g_source);
if (len > BREAKPOINT_COUNT) {
ok(0, "test %u: increase BREAKPOINT_COUNT to at least %u\n", i, len);
i++;
ptr++;
continue;
}
memset(g_actual_bp, 0, sizeof(g_actual_bp));
hr = IDWriteTextAnalyzer_AnalyzeLineBreakpoints(analyzer, &analysissource, 0, lstrlenW(g_source), &analysissink);
hr = IDWriteTextAnalyzer_AnalyzeLineBreakpoints(analyzer, &analysissource, 0, len, &analysissink);
ok(hr == S_OK, "got 0x%08x\n", hr);
compare_breakpoints(ptr, g_actual_bp);
i++;
ptr++;
}

View File

@ -1660,6 +1660,11 @@ static void test_typography(void)
static void test_GetClusterMetrics(void)
{
static const WCHAR str_white_spaceW[] = {
/* BK - FORM FEED, LINE TABULATION, LINE SEP, PARA SEP */ 0xc, 0xb, 0x2028, 0x2029,
/* ZW - ZERO WIDTH SPACE */ 0x200b,
/* SP - SPACE */ 0x20
};
static const WCHAR str5W[] = {'a','\r','b','\n','c','\n','\r','d','\r','\n','e',0xb,'f',0xc,
'g',0x0085,'h',0x2028,'i',0x2029,0};
static const WCHAR str3W[] = {0x2066,')',')',0x661,'(',0x627,')',0};
@ -1987,6 +1992,24 @@ todo_wine {
IDWriteTextLayout_Release(layout);
/* Test whitespace resolution from linebreaking classes BK, ZW, and SP */
hr = IDWriteFactory_CreateTextLayout(factory, str_white_spaceW, sizeof(str_white_spaceW)/sizeof(WCHAR), format,
100.0f, 200.0f, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
count = 0;
memset(metrics, 0, sizeof(metrics));
hr = IDWriteTextLayout_GetClusterMetrics(layout, metrics, 20, &count);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(count == 6, "got %u\n", count);
ok(metrics[0].isWhitespace == 1, "got %d\n", metrics[0].isWhitespace);
ok(metrics[1].isWhitespace == 1, "got %d\n", metrics[1].isWhitespace);
ok(metrics[2].isWhitespace == 1, "got %d\n", metrics[2].isWhitespace);
ok(metrics[3].isWhitespace == 1, "got %d\n", metrics[3].isWhitespace);
ok(metrics[4].isWhitespace == 0, "got %d\n", metrics[4].isWhitespace);
ok(metrics[5].isWhitespace == 1, "got %d\n", metrics[5].isWhitespace);
IDWriteInlineObject_Release(trimm);
IDWriteTextFormat_Release(format);
IDWriteFactory_Release(factory);