mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
LibGfx+Font: Use OutputFileStream instead of BufferStream.
This commit is contained in:
parent
fa43bf92e4
commit
5056d8bb20
1 changed files with 12 additions and 27 deletions
|
@ -27,7 +27,6 @@
|
||||||
#include "Font.h"
|
#include "Font.h"
|
||||||
#include "Bitmap.h"
|
#include "Bitmap.h"
|
||||||
#include "Emoji.h"
|
#include "Emoji.h"
|
||||||
#include <AK/BufferStream.h>
|
|
||||||
#include <AK/MappedFile.h>
|
#include <AK/MappedFile.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
@ -35,8 +34,7 @@
|
||||||
#include <AK/Utf8View.h>
|
#include <AK/Utf8View.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <AK/kmalloc.h>
|
#include <AK/kmalloc.h>
|
||||||
#include <errno.h>
|
#include <LibCore/FileStream.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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)
|
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;
|
FontFileHeader header;
|
||||||
memset(&header, 0, sizeof(FontFileHeader));
|
memset(&header, 0, sizeof(FontFileHeader));
|
||||||
memcpy(header.magic, "!Fnt", 4);
|
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 bytes_per_glyph = sizeof(unsigned) * m_glyph_height;
|
||||||
size_t count = glyph_count_by_type(m_type);
|
size_t count = glyph_count_by_type(m_type);
|
||||||
|
|
||||||
auto buffer = ByteBuffer::create_uninitialized(sizeof(FontFileHeader) + (count * bytes_per_glyph) + count);
|
auto stream_result = Core::OutputFileStream::open_buffered(path);
|
||||||
BufferStream stream(buffer);
|
if (stream_result.is_error())
|
||||||
|
return false;
|
||||||
|
auto& stream = stream_result.value();
|
||||||
|
|
||||||
stream << ByteBuffer::wrap(&header, sizeof(FontFileHeader));
|
stream << ReadonlyBytes { &header, sizeof(header) };
|
||||||
stream << ByteBuffer::wrap(m_rows, (count * bytes_per_glyph));
|
stream << ReadonlyBytes { m_rows, count * bytes_per_glyph };
|
||||||
stream << ByteBuffer::wrap(m_glyph_widths, count);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue