26 #include FT_FREETYPE_H
47 this->weight = weight;
57 if (FT_Error error = FT_Init_FreeType(&library))
59 throw std::runtime_error(
"Failed to init FreeType library (error code " + std::to_string(error) +
")");
63 std::unique_ptr<std::vector<FT_Byte>> file_buffer = std::make_unique<std::vector<FT_Byte>>(ctx.
size());
64 ctx.
read8(
reinterpret_cast<std::byte*
>(file_buffer->data()), ctx.
size());
68 if (FT_Error error = FT_New_Memory_Face(library, file_buffer->data(),
static_cast<FT_Long
>(file_buffer->size()), 0, &face))
70 FT_Done_FreeType(library);
71 throw deserialize_error(
"Failed to load FreeType face (error code " + std::to_string(error) +
")");
74 return std::make_unique<type::ft_typeface>(library, face, std::move(file_buffer));
An exception of this type is thrown when an error occurs during deserialization.
static std::unique_ptr< T > load(::resource_manager &resource_manager, deserialize_context &ctx)
Loads a resource.
Manages the loading, caching, and saving of resources.
void set_weight(int weight)
Sets the weight of the typeface.
void set_style(typeface_style style)
Sets the style of the typeface.
typeface()
Creates an empty typeface.
typeface_style
Emumerates typeface styles.
Provides access to a deserialization state.
virtual std::size_t size() const noexcept=0
Returns the size of the file, in bytes.
virtual std::size_t read8(std::byte *data, std::size_t count) noexcept(false)=0
Reads 8-bit (byte) data.