mirror of https://github.com/WerWolv/ImHex
impr: Significantly reduce memory usage
This commit is contained in:
parent
b5a3a8b4c2
commit
6febe9982b
|
|
@ -776,7 +776,7 @@ EXPORT_MODULE namespace hex {
|
|||
|
||||
struct MergeFont {
|
||||
std::string name;
|
||||
std::vector<u8> fontData;
|
||||
std::span<const u8> fontData;
|
||||
Offset offset;
|
||||
std::optional<float> fontSizeMultiplier;
|
||||
};
|
||||
|
|
@ -814,7 +814,6 @@ EXPORT_MODULE namespace hex {
|
|||
|
||||
}
|
||||
|
||||
void registerMergeFont(const std::fs::path &path, Offset offset = {}, std::optional<float> fontSizeMultiplier = std::nullopt);
|
||||
void registerMergeFont(const std::string &name, const std::span<const u8> &data, Offset offset = {}, std::optional<float> fontSizeMultiplier = std::nullopt);
|
||||
|
||||
void registerFont(const Font& font);
|
||||
|
|
|
|||
|
|
@ -1176,25 +1176,10 @@ namespace hex {
|
|||
return getFont(m_fontName).regular;
|
||||
}
|
||||
|
||||
void registerMergeFont(const std::fs::path &path, Offset offset, std::optional<float> fontSizeMultiplier) {
|
||||
wolv::io::File fontFile(path, wolv::io::File::Mode::Read);
|
||||
if (!fontFile.isValid()) {
|
||||
log::error("Failed to load font from file '{}'", wolv::util::toUTF8String(path));
|
||||
return;
|
||||
}
|
||||
|
||||
impl::s_fonts->emplace_back(
|
||||
wolv::util::toUTF8String(path.filename()),
|
||||
fontFile.readVector(),
|
||||
offset,
|
||||
fontSizeMultiplier
|
||||
);
|
||||
}
|
||||
|
||||
void registerMergeFont(const std::string &name, const std::span<const u8> &data, Offset offset, std::optional<float> fontSizeMultiplier) {
|
||||
impl::s_fonts->emplace_back(
|
||||
name,
|
||||
std::vector<u8> { data.begin(), data.end() },
|
||||
data,
|
||||
offset,
|
||||
fontSizeMultiplier
|
||||
);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
#include <hex/helpers/default_paths.hpp>
|
||||
#include <hex/helpers/auto_reset.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
|
|
@ -109,13 +110,13 @@ namespace hex::log {
|
|||
#endif
|
||||
}
|
||||
|
||||
static std::vector<LogEntry> s_logEntries;
|
||||
static AutoReset<std::vector<LogEntry>> s_logEntries;
|
||||
const std::vector<LogEntry>& getLogEntries() {
|
||||
return s_logEntries;
|
||||
}
|
||||
|
||||
void addLogEntry(std::string_view project, std::string_view level, std::string message) {
|
||||
s_logEntries.emplace_back(
|
||||
s_logEntries->emplace_back(
|
||||
std::move(project),
|
||||
std::move(level),
|
||||
std::move(message)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <clocale>
|
||||
#include <sstream>
|
||||
#include <hex/helpers/auto_reset.hpp>
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
#include <windows.h>
|
||||
|
|
@ -660,9 +661,9 @@ namespace hex {
|
|||
return s_fileToOpen;
|
||||
}
|
||||
|
||||
static std::map<std::fs::path, std::string> s_fonts;
|
||||
static AutoReset<std::map<std::fs::path, std::string>> s_fonts;
|
||||
extern "C" void registerFont(const char *fontName, const char *fontPath) {
|
||||
s_fonts.emplace(fontPath, fontName);
|
||||
s_fonts->emplace(fontPath, fontName);
|
||||
}
|
||||
|
||||
const std::map<std::fs::path, std::string>& getFonts() {
|
||||
|
|
|
|||
|
|
@ -56,18 +56,17 @@ namespace hex::fonts::loader {
|
|||
}
|
||||
|
||||
{
|
||||
config.FontDataOwnedByAtlas = true;
|
||||
if (const auto fontPath = settings.getFontPath(); !fontPath.empty()) {
|
||||
config.FontDataOwnedByAtlas = true;
|
||||
*imguiFont = atlas->AddFontFromFileTTF(fontPath.string().c_str(), 0.0F, &config);
|
||||
}
|
||||
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
|
||||
if (*imguiFont == nullptr) {
|
||||
if (settings.isPixelPerfectFont()) {
|
||||
auto defaultConfig = config;
|
||||
defaultConfig.SizePixels = 0;
|
||||
*imguiFont = atlas->AddFontDefault(&defaultConfig);
|
||||
atlas->Sources.back().FontDataOwnedByAtlas = false;
|
||||
} else {
|
||||
static auto jetbrainsFont = romfs::get("fonts/JetBrainsMono.ttf");
|
||||
*imguiFont = atlas->AddFontFromMemoryTTF(const_cast<u8 *>(jetbrainsFont.data<u8>()), jetbrainsFont.size(), 0.0F, &config);
|
||||
|
|
@ -75,6 +74,8 @@ namespace hex::fonts::loader {
|
|||
if (*imguiFont == nullptr) {
|
||||
log::error("Failed to load font '{}', using default font instead", name.get());
|
||||
*imguiFont = atlas->AddFontDefault();
|
||||
} else {
|
||||
atlas->Sources.back().FontDataOwnedByAtlas = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -86,6 +87,7 @@ namespace hex::fonts::loader {
|
|||
config.GlyphOffset *= ImHexApi::System::getGlobalScale();
|
||||
config.SizePixels = settings.getFontSize() * extraFont.fontSizeMultiplier.value_or(1);
|
||||
atlas->AddFontFromMemoryTTF(const_cast<u8 *>(extraFont.fontData.data()), extraFont.fontData.size(), 0.0F, &config);
|
||||
atlas->Sources.back().FontDataOwnedByAtlas = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue