mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibGfx: Add Core::File
variant of BitmapFont::write_to_file
This commit is contained in:
parent
0d2ca125b3
commit
c43295b668
2 changed files with 14 additions and 5 deletions
|
@ -245,6 +245,14 @@ ErrorOr<NonnullRefPtr<BitmapFont>> BitmapFont::try_load_from_mapped_file(RefPtr<
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> BitmapFont::write_to_file(DeprecatedString const& path)
|
ErrorOr<void> BitmapFont::write_to_file(DeprecatedString const& path)
|
||||||
|
{
|
||||||
|
auto stream = TRY(Core::File::open(path, Core::File::OpenMode::Write));
|
||||||
|
TRY(write_to_file(move(stream)));
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> BitmapFont::write_to_file(NonnullOwnPtr<Core::File> file)
|
||||||
{
|
{
|
||||||
FontFileHeader header;
|
FontFileHeader header;
|
||||||
memset(&header, 0, sizeof(FontFileHeader));
|
memset(&header, 0, sizeof(FontFileHeader));
|
||||||
|
@ -262,12 +270,11 @@ ErrorOr<void> BitmapFont::write_to_file(DeprecatedString const& path)
|
||||||
memcpy(header.name, m_name.characters(), min(m_name.length(), sizeof(header.name) - 1));
|
memcpy(header.name, m_name.characters(), min(m_name.length(), sizeof(header.name) - 1));
|
||||||
memcpy(header.family, m_family.characters(), min(m_family.length(), sizeof(header.family) - 1));
|
memcpy(header.family, m_family.characters(), min(m_family.length(), sizeof(header.family) - 1));
|
||||||
|
|
||||||
auto stream = TRY(Core::File::open(path, Core::File::OpenMode::Write));
|
|
||||||
size_t bytes_per_glyph = sizeof(u32) * m_glyph_height;
|
size_t bytes_per_glyph = sizeof(u32) * m_glyph_height;
|
||||||
TRY(stream->write_until_depleted({ &header, sizeof(header) }));
|
TRY(file->write_until_depleted({ &header, sizeof(header) }));
|
||||||
TRY(stream->write_until_depleted({ m_range_mask, m_range_mask_size }));
|
TRY(file->write_until_depleted({ m_range_mask, m_range_mask_size }));
|
||||||
TRY(stream->write_until_depleted({ m_rows, m_glyph_count * bytes_per_glyph }));
|
TRY(file->write_until_depleted({ m_rows, m_glyph_count * bytes_per_glyph }));
|
||||||
TRY(stream->write_until_depleted({ m_glyph_widths, m_glyph_count }));
|
TRY(file->write_until_depleted({ m_glyph_widths, m_glyph_count }));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,9 @@ public:
|
||||||
static RefPtr<BitmapFont> load_from_file(DeprecatedString const& path);
|
static RefPtr<BitmapFont> load_from_file(DeprecatedString const& path);
|
||||||
static ErrorOr<NonnullRefPtr<BitmapFont>> try_load_from_file(DeprecatedString const& path);
|
static ErrorOr<NonnullRefPtr<BitmapFont>> try_load_from_file(DeprecatedString const& path);
|
||||||
static ErrorOr<NonnullRefPtr<BitmapFont>> try_load_from_mapped_file(RefPtr<Core::MappedFile> const&);
|
static ErrorOr<NonnullRefPtr<BitmapFont>> try_load_from_mapped_file(RefPtr<Core::MappedFile> const&);
|
||||||
|
|
||||||
ErrorOr<void> write_to_file(DeprecatedString const& path);
|
ErrorOr<void> write_to_file(DeprecatedString const& path);
|
||||||
|
ErrorOr<void> write_to_file(NonnullOwnPtr<Core::File> file);
|
||||||
|
|
||||||
~BitmapFont();
|
~BitmapFont();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue