HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFormat *format, IDWriteTextLayout **layout) { struct dwrite_textlayout *This; UINT32 locale_len; *layout = NULL; This = heap_alloc(sizeof(struct dwrite_textlayout)); if (!This) return E_OUTOFMEMORY; This->IDWriteTextLayout_iface.lpVtbl = &dwritetextlayoutvtbl; This->ref = 1; This->str = heap_strdupnW(str, len); This->len = len; memset(&This->format, 0, sizeof(This->format)); /* reference is not kept here, instead copy all underlying data */ IDWriteTextFormat_GetFontCollection(format, &This->format.collection); /* locale name and length */ locale_len = IDWriteTextFormat_GetLocaleNameLength(format); This->format.locale = heap_alloc((locale_len+1)*sizeof(WCHAR)); IDWriteTextFormat_GetLocaleName(format, This->format.locale, locale_len+1); This->format.locale_len = locale_len; This->format.weight = IDWriteTextFormat_GetFontWeight(format); This->format.style = IDWriteTextFormat_GetFontStyle(format); This->format.stretch = IDWriteTextFormat_GetFontStretch(format); This->format.size = IDWriteTextFormat_GetFontSize(format); *layout = &This->IDWriteTextLayout_iface; return S_OK; }
HRESULT opentype_get_font_strings_from_id(const void *table_data, DWRITE_INFORMATIONAL_STRING_ID id, IDWriteLocalizedStrings **strings) { const TT_NAME_V0 *header; BYTE *storage_area = 0; USHORT count = 0; UINT16 name_id; BOOL exists; HRESULT hr; int i; if (!table_data) return E_FAIL; hr = create_localizedstrings(strings); if (FAILED(hr)) return hr; header = table_data; storage_area = (LPBYTE)table_data + GET_BE_WORD(header->stringOffset); count = GET_BE_WORD(header->count); name_id = dwriteid_to_opentypeid[id]; exists = FALSE; for (i = 0; i < count; i++) { const TT_NameRecord *record = &header->nameRecord[i]; USHORT lang_id, length, offset, encoding, platform; if (GET_BE_WORD(record->nameID) != name_id) continue; exists = TRUE; /* Right now only accept unicode and windows encoded fonts */ platform = GET_BE_WORD(record->platformID); if (platform != OPENTYPE_PLATFORM_UNICODE && platform != OPENTYPE_PLATFORM_MAC && platform != OPENTYPE_PLATFORM_WIN) { FIXME("platform %i not supported\n", platform); continue; } lang_id = GET_BE_WORD(record->languageID); length = GET_BE_WORD(record->length); offset = GET_BE_WORD(record->offset); encoding = GET_BE_WORD(record->encodingID); if (lang_id < 0x8000) { WCHAR locale[LOCALE_NAME_MAX_LENGTH]; WCHAR *name_string; UINT codepage; codepage = get_name_record_codepage(platform, encoding); get_name_record_locale(platform, lang_id, locale, sizeof(locale)/sizeof(WCHAR)); if (codepage) { DWORD len = MultiByteToWideChar(codepage, 0, (LPSTR)(storage_area + offset), length, NULL, 0); name_string = heap_alloc(sizeof(WCHAR) * (len+1)); MultiByteToWideChar(codepage, 0, (LPSTR)(storage_area + offset), length, name_string, len); name_string[len] = 0; } else { int i; length /= sizeof(WCHAR); name_string = heap_strdupnW((LPWSTR)(storage_area + offset), length); for (i = 0; i < length; i++) name_string[i] = GET_BE_WORD(name_string[i]); } TRACE("string %s for locale %s found\n", debugstr_w(name_string), debugstr_w(locale)); add_localizedstring(*strings, locale, name_string); heap_free(name_string); } else { FIXME("handle NAME format 1"); continue; } } if (!exists) { IDWriteLocalizedStrings_Release(*strings); *strings = NULL; } return hr; }