Stashing fonts, start font registry.

This commit is contained in:
2025-12-02 17:18:43 -08:00
parent 49fa7ff8a7
commit 09e4cd7ec6
34 changed files with 111742 additions and 28834 deletions

11881
fonts/B612Mono.h Normal file

File diff suppressed because it is too large Load Diff

5589
fonts/BrassMono.h Normal file

File diff suppressed because it is too large Load Diff

5921
fonts/BrassMonoCode.h Normal file

File diff suppressed because it is too large Load Diff

2
fonts/FiraCode.h Normal file
View File

@@ -0,0 +1,2 @@
#pragma once
namespace kte::Fonts::FiraCode {}

22
fonts/Font.cc Normal file
View File

@@ -0,0 +1,22 @@
#include "Font.h"
#include "imgui.h"
void
Font::Load(const float size) const
{
const ImGuiIO &io = ImGui::GetIO();
io.Fonts->Clear();
const ImFont *font = io.Fonts->AddFontFromMemoryCompressedTTF(
this->data_,
this->size_,
size);
if (!font) {
font = io.Fonts->AddFontDefault();
}
(void) font;
io.Fonts->Build();
}

33
fonts/Font.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include <string>
#include <utility>
#include "BrassMonoCode.h"
namespace kte::Fonts {
static const unsigned int DefaultFontSize = DefaultFontBoldCompressedSize;
static const unsigned int *DefaultFontData = DefaultFontBoldCompressedData;
}
class Font {
public:
Font(std::string name, unsigned int *data, const unsigned int size)
: name_(std::move(name)),
data_(data),
size_(size) {}
std::string Name()
{
return name_;
}
void Load(float size) const;
private:
std::string name_;
unsigned int *data_{nullptr};
unsigned int size_{0};
};

66
fonts/FontRegistry.h Normal file
View File

@@ -0,0 +1,66 @@
#pragma once
#include <cassert>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include "Font.h"
// Forward declaration
// class Font;
class FontRegistry {
public:
// Get the global instance
static FontRegistry &Instance()
{
static FontRegistry instance;
return instance;
}
// Register a font (usually done at startup or static initialization)
void Register(std::unique_ptr<Font> font)
{
std::lock_guard lock(mutex_);
auto name = font->Name();
assert(fonts_.find(name) == fonts_.end() && "Font already registered!");
fonts_[std::move(name)] = std::move(font);
}
// Get a font by name (const access)
const Font *Get(const std::string &name) const
{
std::lock_guard lock(mutex_);
const auto it = fonts_.find(name);
return it != fonts_.end() ? it->second.get() : nullptr;
}
// Convenience: load a font by name and size
bool LoadFont(const std::string &name, const float size) const
{
if (auto *font = Get(name)) {
font->Load(size);
return true;
}
return false;
}
// Check if font exists
bool HasFont(const std::string &name) const
{
std::lock_guard lock(mutex_);
return fonts_.count(name) > 0;
}
private:
FontRegistry() = default;
mutable std::mutex mutex_;
std::unordered_map<std::string, std::unique_ptr<Font> > fonts_;
};

8613
fonts/Go.h Normal file

File diff suppressed because it is too large Load Diff

13674
fonts/IBMPlexMono.h Normal file

File diff suppressed because it is too large Load Diff

5635
fonts/Inconsolata.h Normal file

File diff suppressed because it is too large Load Diff

5740
fonts/InconsolataExpanded.h Normal file

File diff suppressed because it is too large Load Diff

1190
fonts/ShareTech.h Normal file

File diff suppressed because it is too large Load Diff

1887
fonts/Syne.h Normal file

File diff suppressed because it is too large Load Diff