mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 02:15:06 +00:00
AK: Make MappedFile heap-allocated and ref-counted
Let's adapt this class a bit better to how it's actually being used. Instead of having valid/invalid states and storing an error in case it's invalid, a MappedFile is now always valid, and the factory function that creates it will return an OSError if mapping fails.
This commit is contained in:
parent
70fce5c4c7
commit
2f3b901f7f
36 changed files with 184 additions and 199 deletions
|
@ -27,7 +27,6 @@
|
|||
#include "BitmapFont.h"
|
||||
#include "Bitmap.h"
|
||||
#include "Emoji.h"
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Utf32View.h>
|
||||
|
@ -174,15 +173,15 @@ size_t BitmapFont::glyph_count_by_type(FontTypes type)
|
|||
|
||||
RefPtr<BitmapFont> BitmapFont::load_from_file(const StringView& path)
|
||||
{
|
||||
MappedFile mapped_file(path);
|
||||
if (!mapped_file.is_valid())
|
||||
auto file_or_error = MappedFile::map(path);
|
||||
if (file_or_error.is_error())
|
||||
return nullptr;
|
||||
|
||||
auto font = load_from_memory((const u8*)mapped_file.data());
|
||||
auto font = load_from_memory((const u8*)file_or_error.value()->data());
|
||||
if (!font)
|
||||
return nullptr;
|
||||
|
||||
font->m_mapped_file = move(mapped_file);
|
||||
font->m_mapped_file = file_or_error.release_value();
|
||||
return font;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue