mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 13:01:49 +00:00
add vector fonts support
This commit is contained in:
parent
2c81344638
commit
11c3f1c5eb
10 changed files with 212 additions and 34 deletions
|
|
@ -187,6 +187,12 @@ void AssetsLoader::processPreload(
|
|||
config = std::make_shared<ModelCfg>(squashed);
|
||||
break;
|
||||
}
|
||||
case AssetType::FONT: {
|
||||
int size = DEFAULT_FONT_SIZE;
|
||||
map.at("size").get(size);
|
||||
config = std::make_unique<FontCfg>(size);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ struct LayoutCfg : AssetCfg {
|
|||
gui::GUI* gui;
|
||||
scriptenv env;
|
||||
|
||||
LayoutCfg(gui::GUI* gui, scriptenv env) : gui(gui), env(std::move(env)) {
|
||||
}
|
||||
LayoutCfg(gui::GUI* gui, scriptenv env) : gui(gui), env(std::move(env)) {}
|
||||
};
|
||||
|
||||
struct SoundCfg : AssetCfg {
|
||||
|
|
@ -43,6 +42,12 @@ struct SoundCfg : AssetCfg {
|
|||
SoundCfg(bool keepPCM) : keepPCM(keepPCM) {}
|
||||
};
|
||||
|
||||
struct FontCfg : AssetCfg {
|
||||
int size;
|
||||
|
||||
FontCfg(int size) : size(size) {}
|
||||
};
|
||||
|
||||
enum class AtlasType {
|
||||
ATLAS, SEPARATE
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "coders/obj.hpp"
|
||||
#include "coders/vcm.hpp"
|
||||
#include "coders/vec3.hpp"
|
||||
#include "coders/vector_fonts.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "engine/EnginePaths.hpp"
|
||||
|
|
@ -199,8 +200,18 @@ assetload::postfunc assetload::font(
|
|||
const ResPaths& paths,
|
||||
const std::string& filename,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>&
|
||||
const std::shared_ptr<AssetCfg>& config
|
||||
) {
|
||||
auto cfg = std::dynamic_pointer_cast<FontCfg>(config);
|
||||
auto ext = fs::path(filename).extension().string();
|
||||
if (ext == ".ttf" || ext == ".otf") {
|
||||
logger.info() << "loading vector font " << util::quote(filename);
|
||||
return [=](auto assets) {
|
||||
auto font = vector_fonts::load_font(paths.find(filename).string());
|
||||
assets->store(font->createInstance(cfg ? cfg->size : 16), name);
|
||||
};
|
||||
}
|
||||
|
||||
auto pages = std::make_shared<std::vector<std::unique_ptr<ImageData>>>();
|
||||
for (size_t i = 0; i <= 1024; i++) {
|
||||
std::string pagefile = filename + "_" + std::to_string(i) + ".png";
|
||||
|
|
@ -214,20 +225,7 @@ assetload::postfunc assetload::font(
|
|||
}
|
||||
}
|
||||
return [=](auto assets) {
|
||||
int res = pages->at(0)->getHeight() / 16;
|
||||
std::vector<std::unique_ptr<Texture>> textures;
|
||||
for (auto& page : *pages) {
|
||||
if (page == nullptr) {
|
||||
textures.emplace_back(nullptr);
|
||||
} else {
|
||||
auto texture = Texture::from(page.get());
|
||||
texture->setMipMapping(false, true);
|
||||
textures.emplace_back(std::move(texture));
|
||||
}
|
||||
}
|
||||
assets->store(
|
||||
std::make_unique<Font>(std::move(textures), res, 4), name
|
||||
);
|
||||
assets->store(Font::createBitmapFont(std::move(*pages)), name);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue