55 lines
1.5 KiB
C++
55 lines
1.5 KiB
C++
#include "Font_Face_p.h"
|
|
|
|
namespace renderive {
|
|
|
|
Font_Face::Font_Face() : impl_(std::make_unique<Impl>()) {}
|
|
|
|
Font_Face::~Font_Face() = default;
|
|
|
|
Font_Face::Font_Face(Font_Face&&) noexcept = default;
|
|
|
|
Font_Face& Font_Face::operator=(Font_Face&&) noexcept = default;
|
|
|
|
bool Font_Face::valid() const {
|
|
return impl_->face.is_valid();
|
|
}
|
|
|
|
std::string Font_Face::family_name() const {
|
|
const BLString& name = impl_->face.family_name();
|
|
return std::string(name.data(), name.size());
|
|
}
|
|
|
|
Font_Registry::Font_Registry() : impl_(std::make_unique<Impl>()) {}
|
|
|
|
Font_Registry::~Font_Registry() {
|
|
set_default_face(nullptr);
|
|
}
|
|
|
|
std::shared_ptr<Font_Face> Font_Registry::load_file(const std::filesystem::path& path) {
|
|
auto face = std::make_shared<Font_Face>();
|
|
auto file_path = path.string();
|
|
if (face->impl_->face.create_from_file(file_path.c_str()) != BL_SUCCESS)
|
|
return nullptr;
|
|
return face;
|
|
}
|
|
|
|
std::shared_ptr<Font_Face> Font_Registry::load_memory(std::span<const std::byte> data) {
|
|
auto face = std::make_shared<Font_Face>();
|
|
BLFontData font_data;
|
|
if (font_data.create_from_data(reinterpret_cast<const void*>(data.data()), data.size()) != BL_SUCCESS)
|
|
return nullptr;
|
|
if (face->impl_->face.create_from_data(font_data, 0) != BL_SUCCESS)
|
|
return nullptr;
|
|
return face;
|
|
}
|
|
|
|
void Font_Registry::set_default_face(std::shared_ptr<Font_Face> face) {
|
|
impl_->default_face = std::move(face);
|
|
}
|
|
|
|
std::shared_ptr<Font_Face> Font_Registry::default_face() const {
|
|
return impl_->default_face;
|
|
}
|
|
|
|
} // namespace renderive
|