[Mammoth/Teton] Add an OpenFile interface and use it to load a font.

This commit is contained in:
Drew Galbraith 2023-11-22 16:42:42 -08:00
parent 4fd17a59ea
commit 86ce0a68a3
6 changed files with 84 additions and 21 deletions

View file

@ -9,9 +9,9 @@ const uint32_t kMagic = 0x864AB572;
}
Psf::Psf(mmth::OwnedMemoryRegion&& psf_file)
: psf_file_(glcr::Move(psf_file)),
header_(reinterpret_cast<PsfHeader*>(psf_file_.vaddr())) {
Psf::Psf(glcr::StringView path)
: psf_file_(mmth::File::Open(path)),
header_(reinterpret_cast<PsfHeader*>(psf_file_.raw_ptr())) {
EnsureValid();
}

View file

@ -1,6 +1,6 @@
#pragma once
#include <mammoth/util/memory_region.h>
#include <mammoth/file/file.h>
struct PsfHeader {
uint32_t magic; /* magic bytes to identify PSF */
@ -15,7 +15,7 @@ struct PsfHeader {
class Psf {
public:
Psf(mmth::OwnedMemoryRegion&& psf_file);
Psf(glcr::StringView path);
void DumpHeader();
@ -24,12 +24,13 @@ class Psf {
uint32_t height() { return header_->height; }
uint8_t* glyph(uint32_t index) {
return reinterpret_cast<uint8_t*>(psf_file_.vaddr() + header_->headersize +
return reinterpret_cast<uint8_t*>(psf_file_.byte_ptr() +
header_->headersize +
(index * header_->bytesperglyph));
}
private:
mmth::OwnedMemoryRegion psf_file_;
mmth::File psf_file_;
PsfHeader* header_;
void EnsureValid();