[Mammoth/Teton] Add an OpenFile interface and use it to load a font.
This commit is contained in:
parent
4fd17a59ea
commit
86ce0a68a3
6 changed files with 84 additions and 21 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -25,19 +25,7 @@ uint64_t main(uint64_t init_port) {
|
|||
|
||||
// 2. Parse a font file.
|
||||
|
||||
GetEndpointRequest req;
|
||||
req.set_endpoint_name("victoriafalls");
|
||||
Endpoint resp;
|
||||
check(client.GetEndpoint(req, resp));
|
||||
|
||||
VFSClient vfs(resp.endpoint());
|
||||
|
||||
OpenFileRequest freq;
|
||||
freq.set_path("/default8x16.psfu");
|
||||
OpenFileResponse fresp;
|
||||
check(vfs.OpenFile(freq, fresp));
|
||||
|
||||
Psf psf(mmth::OwnedMemoryRegion::FromCapability(fresp.memory()));
|
||||
Psf psf("/default8x16.psfu");
|
||||
psf.DumpHeader();
|
||||
|
||||
Console console(fbuf, psf);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue