mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibGfx+Font: Use OutputFileStream instead of BufferStream.
This commit is contained in:
parent
fa43bf92e4
commit
5056d8bb20
Notes:
sideshowbarker
2024-07-19 02:18:47 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/5056d8bb200 Pull-request: https://github.com/SerenityOS/serenity/pull/3561
1 changed files with 12 additions and 27 deletions
|
@ -27,7 +27,6 @@
|
|||
#include "Font.h"
|
||||
#include "Bitmap.h"
|
||||
#include "Emoji.h"
|
||||
#include <AK/BufferStream.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
@ -35,8 +34,7 @@
|
|||
#include <AK/Utf8View.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <AK/kmalloc.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <LibCore/FileStream.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -222,20 +220,6 @@ RefPtr<Font> Font::load_from_file(const StringView& path)
|
|||
|
||||
bool Font::write_to_file(const StringView& path)
|
||||
{
|
||||
int fd;
|
||||
#ifdef __serenity__
|
||||
fd = creat_with_path_length(path.characters_without_null_termination(), path.length(), 0644);
|
||||
#else
|
||||
{
|
||||
String null_terminated_path = path;
|
||||
fd = creat(null_terminated_path.characters(), 0644);
|
||||
}
|
||||
#endif
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
return false;
|
||||
}
|
||||
|
||||
FontFileHeader header;
|
||||
memset(&header, 0, sizeof(FontFileHeader));
|
||||
memcpy(header.magic, "!Fnt", 4);
|
||||
|
@ -250,18 +234,19 @@ bool Font::write_to_file(const StringView& path)
|
|||
size_t bytes_per_glyph = sizeof(unsigned) * m_glyph_height;
|
||||
size_t count = glyph_count_by_type(m_type);
|
||||
|
||||
auto buffer = ByteBuffer::create_uninitialized(sizeof(FontFileHeader) + (count * bytes_per_glyph) + count);
|
||||
BufferStream stream(buffer);
|
||||
auto stream_result = Core::OutputFileStream::open_buffered(path);
|
||||
if (stream_result.is_error())
|
||||
return false;
|
||||
auto& stream = stream_result.value();
|
||||
|
||||
stream << ByteBuffer::wrap(&header, sizeof(FontFileHeader));
|
||||
stream << ByteBuffer::wrap(m_rows, (count * bytes_per_glyph));
|
||||
stream << ByteBuffer::wrap(m_glyph_widths, count);
|
||||
stream << ReadonlyBytes { &header, sizeof(header) };
|
||||
stream << ReadonlyBytes { m_rows, count * bytes_per_glyph };
|
||||
stream << ReadonlyBytes { m_glyph_widths, count };
|
||||
|
||||
stream.flush();
|
||||
if (stream.handle_any_error())
|
||||
return false;
|
||||
|
||||
ASSERT(stream.at_end());
|
||||
ssize_t nwritten = write(fd, buffer.data(), buffer.size());
|
||||
ASSERT(nwritten == (ssize_t)buffer.size());
|
||||
int rc = close(fd);
|
||||
ASSERT(rc == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue