increase max font codepages to 1024

This commit is contained in:
MihailRis
2024-11-13 02:01:51 +03:00
parent a5c9125084
commit 60aa0fbcfc
+20 -12
View File
@@ -32,7 +32,7 @@ static debug::Logger logger("assetload-funcs");
namespace fs = std::filesystem; namespace fs = std::filesystem;
static bool animation( static bool load_animation(
Assets* assets, Assets* assets,
const ResPaths* paths, const ResPaths* paths,
const std::string& atlasName, const std::string& atlasName,
@@ -120,7 +120,7 @@ assetload::postfunc assetload::atlas(
atlas->prepare(); atlas->prepare();
assets->store(std::unique_ptr<Atlas>(atlas), name); assets->store(std::unique_ptr<Atlas>(atlas), name);
for (const auto& file : names) { for (const auto& file : names) {
animation(assets, paths, name, directory, file, atlas); load_animation(assets, paths, name, directory, file, atlas);
} }
}; };
} }
@@ -133,16 +133,26 @@ assetload::postfunc assetload::font(
const std::shared_ptr<AssetCfg>& const std::shared_ptr<AssetCfg>&
) { ) {
auto pages = std::make_shared<std::vector<std::unique_ptr<ImageData>>>(); auto pages = std::make_shared<std::vector<std::unique_ptr<ImageData>>>();
for (size_t i = 0; i <= 4; i++) { for (size_t i = 0; i <= 1024; i++) {
std::string pagefile = filename + "_" + std::to_string(i) + ".png"; std::string pagefile = filename + "_" + std::to_string(i) + ".png";
pagefile = paths->find(pagefile).string(); auto file = paths->find(pagefile);
pages->push_back(imageio::read(pagefile)); if (fs::exists(file)) {
pages->push_back(imageio::read(file.u8string()));
} else if (i == 0) {
throw std::runtime_error("font must have page 0");
} else {
pages->push_back(nullptr);
}
} }
return [=](auto assets) { return [=](auto assets) {
int res = pages->at(0)->getHeight() / 16; int res = pages->at(0)->getHeight() / 16;
std::vector<std::unique_ptr<Texture>> textures; std::vector<std::unique_ptr<Texture>> textures;
for (auto& page : *pages) { for (auto& page : *pages) {
textures.emplace_back(Texture::from(page.get())); if (page == nullptr) {
textures.emplace_back(nullptr);
} else {
textures.emplace_back(Texture::from(page.get()));
}
} }
assets->store( assets->store(
std::make_unique<Font>(std::move(textures), res, 4), name std::make_unique<Font>(std::move(textures), res, 4), name
@@ -326,11 +336,9 @@ static TextureAnimation create_animation(
if (elem.second > 0) { if (elem.second > 0) {
frame.duration = static_cast<float>(elem.second) / 1000.0f; frame.duration = static_cast<float>(elem.second) / 1000.0f;
} }
frame.srcPos = frame.srcPos = glm::ivec2(
glm::ivec2( region.u1 * srcWidth, srcHeight - region.v2 * srcHeight
region.u1 * srcWidth, srcHeight - region.v2 * srcHeight ) - extension;
) -
extension;
animation.addFrame(frame); animation.addFrame(frame);
} }
return animation; return animation;
@@ -348,7 +356,7 @@ inline bool contains(
return false; return false;
} }
static bool animation( static bool load_animation(
Assets* assets, Assets* assets,
const ResPaths* paths, const ResPaths* paths,
const std::string& atlasName, const std::string& atlasName,