dwrite: Added ability to specify multiple families per fallback range.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2017-07-19 14:42:31 +03:00 committed by Alexandre Julliard
parent a1b563f41c
commit f4b7e4b5ed

View File

@ -189,7 +189,8 @@ static const struct dwritescript_properties dwritescripts_properties[Script_Last
const char *debugstr_sa_script(UINT16 script) const char *debugstr_sa_script(UINT16 script)
{ {
return script < Script_LastId ? debugstr_an((char*)&dwritescripts_properties[script].props.isoScriptCode, 4): "not defined"; return script < Script_LastId ? debugstr_an((char*)&dwritescripts_properties[script].props.isoScriptCode, 4):
"undefined";
} }
/* system font falback configuration */ /* system font falback configuration */
@ -197,13 +198,13 @@ static const WCHAR meiryoW[] = {'M','e','i','r','y','o',0};
struct fallback_mapping { struct fallback_mapping {
DWRITE_UNICODE_RANGE range; DWRITE_UNICODE_RANGE range;
const WCHAR *family; const WCHAR *families[5];
}; };
static const struct fallback_mapping fontfallback_neutral_data[] = { static const struct fallback_mapping fontfallback_neutral_data[] = {
{ { 0x3000, 0x30ff }, meiryoW }, /* CJK Symbols and Punctuation, Hiragana, Katakana */ { { 0x3000, 0x30ff }, { meiryoW } }, /* CJK Symbols and Punctuation, Hiragana, Katakana */
{ { 0x31f0, 0x31ff }, meiryoW }, /* Katakana Phonetic Extensions */ { { 0x31f0, 0x31ff }, { meiryoW } }, /* Katakana Phonetic Extensions */
{ { 0x4e00, 0x9fff }, meiryoW }, /* CJK Unified Ideographs */ { { 0x4e00, 0x9fff }, { meiryoW } }, /* CJK Unified Ideographs */
}; };
struct dwrite_fontfallback { struct dwrite_fontfallback {
@ -2026,28 +2027,41 @@ static HRESULT fallback_map_characters(IDWriteFont *font, const WCHAR *text, UIN
} }
static HRESULT fallback_get_fallback_font(struct dwrite_fontfallback *fallback, const WCHAR *text, UINT32 length, static HRESULT fallback_get_fallback_font(struct dwrite_fontfallback *fallback, const WCHAR *text, UINT32 length,
DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style, DWRITE_FONT_STRETCH stretch, UINT32 *mapped_length, IDWriteFont **mapped_font) DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style, DWRITE_FONT_STRETCH stretch, UINT32 *mapped_length,
IDWriteFont **mapped_font)
{ {
const struct fallback_mapping *mapping; const struct fallback_mapping *mapping;
UINT32 i = 0;
HRESULT hr; HRESULT hr;
*mapped_font = NULL;
mapping = find_fallback_mapping(fallback, text[0]); mapping = find_fallback_mapping(fallback, text[0]);
if (!mapping) { if (!mapping) {
WARN("no mapping for 0x%x\n", text[0]); WARN("No mapping range for %#x.\n", text[0]);
return E_FAIL; return E_FAIL;
} }
/* now let's see what fallback can handle */ /* Now let's see what fallback can handle. Pick first font that could be created. */
hr = create_matching_font((IDWriteFontCollection*)fallback->systemcollection, mapping->family, weight, style, stretch, mapped_font); while (mapping->families[i]) {
if (FAILED(hr)) { hr = create_matching_font((IDWriteFontCollection *)fallback->systemcollection, mapping->families[i],
WARN("failed to create fallback font %s for range [0x%x,0x%x], 0x%08x\n", debugstr_w(mapping->family), weight, style, stretch, mapped_font);
mapping->range.first, mapping->range.last, hr); if (hr == S_OK) {
return hr; TRACE("Created fallback font for range [%#x, %#x], using family %s.\n", mapping->range.first,
mapping->range.last, debugstr_w(mapping->families[i]));
break;
}
i++;
}
if (!*mapped_font) {
WARN("Failed to create fallback font for range [%#x, %#x].\n", mapping->range.first, mapping->range.last);
return E_FAIL;
} }
hr = fallback_map_characters(*mapped_font, text, length, mapped_length); hr = fallback_map_characters(*mapped_font, text, length, mapped_length);
if (FAILED(hr)) if (FAILED(hr))
WARN("mapping with fallback font %s failed, 0x%08x\n", debugstr_w(mapping->family), hr); WARN("Mapping with fallback family %s failed, hr %#x.\n", debugstr_w(mapping->families[i]), hr);
if (!*mapped_length) { if (!*mapped_length) {
IDWriteFont_Release(*mapped_font); IDWriteFont_Release(*mapped_font);