[deploy] add Font::GetFamilyNames
This commit is contained in:
parent
f4721fc3df
commit
4dce6fb506
|
|
@ -502,8 +502,36 @@ void RendererImpl::CreateFontCollection(Font& font, const String& file_path)
|
|||
ComPtr<IDWriteFontCollection> font_collection;
|
||||
hr = d2d_res_->CreateFontCollectionFromFiles(font_collection, { full_path });
|
||||
|
||||
Vector<String> family_names;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
UINT32 count = font_collection->GetFontFamilyCount();
|
||||
for (UINT32 i = 0; i < count; i++)
|
||||
{
|
||||
ComPtr<IDWriteFontFamily> family;
|
||||
if (SUCCEEDED(font_collection->GetFontFamily(i, &family)))
|
||||
{
|
||||
ComPtr<IDWriteLocalizedStrings> str;
|
||||
if (SUCCEEDED(family->GetFamilyNames(&str)))
|
||||
{
|
||||
UINT32 length = 0;
|
||||
if (SUCCEEDED(str->GetStringLength(0, &length)))
|
||||
{
|
||||
WideString name;
|
||||
name.resize(length + 1);
|
||||
if (SUCCEEDED(str->GetString(0, &name[0], UINT32(name.size()))))
|
||||
{
|
||||
family_names.emplace_back(strings::WideToNarrow(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
font.SetFamilyNames(family_names);
|
||||
NativePtr::Set(font, font_collection);
|
||||
}
|
||||
}
|
||||
|
|
@ -524,8 +552,36 @@ void RendererImpl::CreateFontCollection(Font& font, const Resource& res)
|
|||
ComPtr<IDWriteFontCollection> font_collection;
|
||||
hr = d2d_res_->CreateFontCollectionFromResources(font_collection, Vector<Resource>{ res });
|
||||
|
||||
Vector<String> family_names;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
UINT32 count = font_collection->GetFontFamilyCount();
|
||||
for (UINT32 i = 0; i < count; i++)
|
||||
{
|
||||
ComPtr<IDWriteFontFamily> family;
|
||||
if (SUCCEEDED(font_collection->GetFontFamily(i, &family)))
|
||||
{
|
||||
ComPtr<IDWriteLocalizedStrings> str;
|
||||
if (SUCCEEDED(family->GetFamilyNames(&str)))
|
||||
{
|
||||
UINT32 length = 0;
|
||||
if (SUCCEEDED(str->GetStringLength(0, &length)))
|
||||
{
|
||||
WideString name;
|
||||
name.resize(length + 1);
|
||||
if (SUCCEEDED(str->GetString(0, &name[0], UINT32(name.size()))))
|
||||
{
|
||||
family_names.emplace_back(strings::WideToNarrow(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
font.SetFamilyNames(family_names);
|
||||
NativePtr::Set(font, font_collection);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,8 +59,29 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief ¼ÓÔØ×ÖÌå×ÊÔ´
|
||||
bool Load(const Resource& resource);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief »ñÈ¡×ÖÌå×åÃû³Æ
|
||||
Vector<String> GetFamilyNames() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ÉèÖÃ×ÖÌå×åÃû³Æ
|
||||
void SetFamilyNames(const Vector<String>& names);
|
||||
|
||||
protected:
|
||||
Vector<String> family_names_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
inline Vector<String> Font::GetFamilyNames() const
|
||||
{
|
||||
return family_names_;
|
||||
}
|
||||
|
||||
inline void Font::SetFamilyNames(const Vector<String>& names)
|
||||
{
|
||||
family_names_ = names;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
Loading…
Reference in New Issue