Commit 7dd90faa authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite: Fix Unknown/Common/Inherited script categories handling.

parent 6992f865
......@@ -235,13 +235,17 @@ static inline UINT32 decode_surrogate_pair(const WCHAR *str, UINT32 index, UINT3
static inline UINT16 get_char_script(WCHAR c)
{
UINT16 script = get_table_entry(wine_scripts_table, c);
if (script == Script_Unknown) {
WORD type;
if (GetStringTypeW(CT_CTYPE1, &c, 1, &type) && (type & C1_CNTRL))
script = Script_Common;
}
return script;
return get_table_entry(wine_scripts_table, c);
}
static DWRITE_SCRIPT_ANALYSIS get_char_sa(WCHAR c)
{
DWRITE_SCRIPT_ANALYSIS sa;
sa.script = get_char_script(c);
sa.shapes = iscntrlW(c) || c == 0x2028 /* LINE SEPARATOR */ || c == 0x2029 /* PARAGRAPH SEPARATOR */ ?
DWRITE_SCRIPT_SHAPES_NO_VISUAL : DWRITE_SCRIPT_SHAPES_DEFAULT;
return sa;
}
static HRESULT analyze_script(const WCHAR *text, UINT32 position, UINT32 length, IDWriteTextAnalysisSink *sink)
......@@ -251,36 +255,46 @@ static HRESULT analyze_script(const WCHAR *text, UINT32 position, UINT32 length,
if (!length) return S_OK;
sa.script = get_char_script(*text);
sa = get_char_sa(*text);
pos = position;
seq_length = 1;
for (i = 1; i < length; i++)
{
UINT16 script = get_char_script(text[i]);
DWRITE_SCRIPT_ANALYSIS cur_sa = get_char_sa(text[i]);
/* Unknown type is ignored when preceded or followed by another script */
if (sa.script == Script_Unknown) sa.script = script;
if (script == Script_Unknown && sa.script != Script_Common) script = sa.script;
/* this is a length of a sequence to be reported next */
if (sa.script == script) seq_length++;
switch (sa.script) {
case Script_Unknown:
sa.script = cur_sa.script;
break;
case Script_Common:
if (cur_sa.script == Script_Unknown)
cur_sa.script = sa.script;
else if (cur_sa.script != Script_Common)
sa.script = cur_sa.script;
break;
default:
if (cur_sa.script == Script_Unknown || cur_sa.script == Script_Common)
cur_sa.script = sa.script;
}
if (sa.script != script)
{
/* this is a length of a sequence to be reported next */
if (sa.script == cur_sa.script && sa.shapes == cur_sa.shapes)
seq_length++;
else {
HRESULT hr;
sa.shapes = sa.script != Script_Common ? DWRITE_SCRIPT_SHAPES_DEFAULT : DWRITE_SCRIPT_SHAPES_NO_VISUAL;
hr = IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, seq_length, &sa);
if (FAILED(hr)) return hr;
pos = position + i;
seq_length = 1;
sa.script = script;
sa = cur_sa;
}
}
/* one char length case or normal completion call */
sa.shapes = sa.script != Script_Common ? DWRITE_SCRIPT_SHAPES_DEFAULT : DWRITE_SCRIPT_SHAPES_NO_VISUAL;
return IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, seq_length, &sa);
}
......
......@@ -2057,8 +2057,7 @@ todo_wine
if (metrics[i].isSoftHyphen)
ok(!metrics[i].isWhitespace, "%u: got %d\n", i, metrics[i].isWhitespace);
if (metrics[i].isNewline) {
todo_wine_if (i == 17 || i == 19)
ok(metrics[i].width == 0.0f, "%u: got width %f\n", i, metrics[i].width);
ok(metrics[i].width == 0.0f, "%u: got width %f\n", i, metrics[i].width);
ok(metrics[i].isWhitespace == 1, "%u: got %d\n", i, metrics[i].isWhitespace);
ok(metrics[i].canWrapLineAfter == 1, "%u: got %d\n", i, metrics[i].canWrapLineAfter);
}
......
......@@ -1331,7 +1331,7 @@ sub dump_scripts($)
}
# ignore some scripts
if ($type eq "" || $type eq "Common" || $type eq "Inherited")
if ($type eq "Common" || $type eq "Inherited")
{
next;
}
......@@ -1339,10 +1339,16 @@ sub dump_scripts($)
$scripts{$type} = -1;
}
# assign script indices, starting from index 2
$script_index = 1;
foreach my $script (sort keys %scripts) {
$scripts{$script} = ++$script_index;
}
# indices change when new scripts are added to the standard,
# keep Unknown/Common at fixed positions, Inherited is treated as Unknown
$scripts{"Unknown"} = 0;
$scripts{"Inherited"} = 0;
$scripts{"Common"} = 1;
# now fill a table
seek $INPUT, 0, 0;
......@@ -1385,11 +1391,10 @@ sub dump_scripts($)
print OUTPUT "/* generated from $UNIDATA/Scripts.txt */\n";
print OUTPUT "/* DO NOT EDIT!! */\n\n";
# reserve Unknown and Common ids
# Inherited was consumed by Unknown, we don't need it as a separate enum memeber
delete $scripts{"Inherited"};
print OUTPUT "enum unicode_script_id {\n";
print OUTPUT " Script_Unknown = 0,\n";
print OUTPUT " Script_Common = 1,\n";
foreach my $script (sort keys %scripts)
foreach my $script (sort { $scripts{$a} <=> $scripts{$b} } keys %scripts)
{
print OUTPUT " Script_$script = $scripts{$script},\n";
}
......
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