dwrite: Implement initial script itemization for AnalyzeScript().
This commit is contained in:
parent
45c7798c36
commit
89fcb11539
|
@ -27,6 +27,91 @@
|
|||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
|
||||
|
||||
enum scriptcode {
|
||||
Script_Arabic = 0,
|
||||
Script_Latin = 38,
|
||||
Script_Latin_Symb = 77,
|
||||
Script_Unknown = (UINT16)-1
|
||||
};
|
||||
|
||||
struct script_range {
|
||||
UINT16 script;
|
||||
DWORD first;
|
||||
DWORD last;
|
||||
};
|
||||
|
||||
static const struct script_range script_ranges[] = {
|
||||
/* C0 Controls: U+0000–U+001F */
|
||||
/* ASCII punctuation and symbols: U+0020–U+002F */
|
||||
/* ASCII digits: U+0030–U+0039 */
|
||||
/* ASCII punctuation and symbols: U+003A–U+0040 */
|
||||
{ Script_Latin_Symb, 0x00, 0x040 },
|
||||
/* Latin uppercase: U+0041–U+005A */
|
||||
{ Script_Latin, 0x41, 0x5a },
|
||||
/* ASCII punctuation and symbols: U+005B–U+0060 */
|
||||
{ Script_Latin_Symb, 0x5b, 0x060 },
|
||||
/* Latin lowercase: U+0061–U+007A */
|
||||
{ Script_Latin, 0x61, 0x7a },
|
||||
/* ASCII punctuation and symbols, control char DEL: U+007B–U+007F */
|
||||
{ Script_Latin_Symb, 0x7b, 0x7f },
|
||||
/* Arabic: U+0600–U+06FF */
|
||||
{ Script_Arabic, 0x600, 0x6ef },
|
||||
/* unsuppoted range */
|
||||
{ Script_Unknown }
|
||||
};
|
||||
|
||||
static UINT16 get_char_script( WCHAR c )
|
||||
{
|
||||
DWORD ch = c;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(script_ranges)/sizeof(struct script_range); i++)
|
||||
{
|
||||
const struct script_range *range = &script_ranges[i];
|
||||
if (range->script == Script_Unknown || (range->first <= ch && range->last >= ch))
|
||||
return range->script;
|
||||
}
|
||||
|
||||
return Script_Unknown;
|
||||
}
|
||||
|
||||
static HRESULT analyze_script(const WCHAR *text, UINT32 len, IDWriteTextAnalysisSink *sink)
|
||||
{
|
||||
DWRITE_SCRIPT_ANALYSIS sa;
|
||||
UINT32 pos, i, length;
|
||||
|
||||
if (!len) return S_OK;
|
||||
|
||||
sa.script = get_char_script(*text);
|
||||
sa.shapes = DWRITE_SCRIPT_SHAPES_DEFAULT;
|
||||
|
||||
pos = 0;
|
||||
length = 1;
|
||||
|
||||
for (i = 1; i < len; i++)
|
||||
{
|
||||
UINT16 script = get_char_script(text[i]);
|
||||
|
||||
/* Script_Latin_Symb script type is ignored when preceded or followed by another script */
|
||||
if (sa.script == Script_Latin_Symb) sa.script = script;
|
||||
if (script == Script_Latin_Symb) script = sa.script;
|
||||
/* this is a length of a sequence to be reported next */
|
||||
if (sa.script == script) length++;
|
||||
|
||||
if (sa.script != script)
|
||||
{
|
||||
HRESULT hr = IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, length, &sa);
|
||||
if (FAILED(hr)) return hr;
|
||||
pos = i;
|
||||
length = 1;
|
||||
sa.script = script;
|
||||
}
|
||||
}
|
||||
|
||||
/* 1 length case or normal completion call */
|
||||
return IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, length, &sa);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI dwritetextanalyzer_QueryInterface(IDWriteTextAnalyzer *iface, REFIID riid, void **obj)
|
||||
{
|
||||
TRACE("(%s %p)\n", debugstr_guid(riid), obj);
|
||||
|
@ -55,8 +140,16 @@ static ULONG WINAPI dwritetextanalyzer_Release(IDWriteTextAnalyzer *iface)
|
|||
static HRESULT WINAPI dwritetextanalyzer_AnalyzeScript(IDWriteTextAnalyzer *iface,
|
||||
IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
|
||||
{
|
||||
FIXME("(%p %u %u %p): stub\n", source, position, length, sink);
|
||||
return E_NOTIMPL;
|
||||
const WCHAR *text;
|
||||
HRESULT hr;
|
||||
UINT32 len;
|
||||
|
||||
TRACE("(%p %u %u %p)\n", source, position, length, sink);
|
||||
|
||||
hr = IDWriteTextAnalysisSource_GetTextAtPosition(source, position, &text, &len);
|
||||
if (FAILED(hr)) return hr;
|
||||
|
||||
return analyze_script(text, len, sink);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI dwritetextanalyzer_AnalyzeBidi(IDWriteTextAnalyzer *iface,
|
||||
|
|
|
@ -403,6 +403,11 @@ enum scriptcode {
|
|||
};
|
||||
|
||||
static struct sa_test sa_tests[] = {
|
||||
{
|
||||
/* just 1 char string */
|
||||
{'t',0}, 1,
|
||||
{ { 0, 1, { Script_Latin, DWRITE_SCRIPT_SHAPES_DEFAULT } }}
|
||||
},
|
||||
{
|
||||
{'t','e','s','t',0}, 1,
|
||||
{ { 0, 4, { Script_Latin, DWRITE_SCRIPT_SHAPES_DEFAULT } }}
|
||||
|
@ -451,7 +456,7 @@ static struct sa_test sa_tests[] = {
|
|||
{ 7, 4, { Script_Arabic, DWRITE_SCRIPT_SHAPES_DEFAULT } },
|
||||
}
|
||||
},
|
||||
|
||||
/* keep this as end marker */
|
||||
{ {0} }
|
||||
};
|
||||
|
||||
|
@ -493,9 +498,7 @@ static void test_AnalyzeScript(void)
|
|||
|
||||
init_expected_sa(expected_seq, ptr);
|
||||
hr = IDWriteTextAnalyzer_AnalyzeScript(analyzer, &analysissource, 0, lstrlenW(g_source), &analysissink);
|
||||
todo_wine
|
||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||
if (hr == E_NOTIMPL) break;
|
||||
ok_sequence(sequences, ANALYZER_ID, expected_seq[0]->sequence, "AnalyzeScript", FALSE);
|
||||
ptr++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue