get rid of vcpkg and build freetype from sources
This commit is contained in:
@@ -4,12 +4,18 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#if __has_include("msdfgen.h")
|
||||
|
||||
#include "FontAtlasGenerator.hpp"
|
||||
#include "Base/Logger.hpp"
|
||||
#include "Scene/AtlasMetadata.hpp"
|
||||
#define STBI_MSC_SECURE_CRT
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
@@ -91,20 +97,20 @@ namespace OpenVulkano::Scene
|
||||
return;
|
||||
}
|
||||
std::string fileName = outputFile;
|
||||
uint32_t packedFlag = 0;
|
||||
uint32_t packedFlag = packIntoSingleFile;
|
||||
if (packIntoSingleFile)
|
||||
{
|
||||
size_t ext = outputFile.find_last_of('.');
|
||||
if (ext == std::string::npos)
|
||||
if (ext == std::string::npos)
|
||||
{
|
||||
fileName += "_packed";
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
fileName.insert(ext - 1, "_packed");
|
||||
}
|
||||
savePng(m_generator.atlasStorage(), fileName.c_str());
|
||||
packedFlag = 1;
|
||||
const BitmapConstRef<byte, 1>& storage = m_generator.atlasStorage();
|
||||
SavePng(m_generator.atlasStorage(), fileName, 1);
|
||||
}
|
||||
std::fstream fs(fileName.c_str(), std::ios_base::out | std::ios_base::binary | (packedFlag ? std::ios_base::app : std::ios_base::trunc));
|
||||
fs.write(reinterpret_cast<const char*>(&m_meta), sizeof(AtlasMetadata));
|
||||
@@ -207,10 +213,26 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
|
||||
if (pngOutput && !pngOutput->empty())
|
||||
{
|
||||
savePng(m_generator.atlasStorage(), pngOutput->c_str());
|
||||
{
|
||||
SavePng(storage, pngOutput.value(), 1);
|
||||
}
|
||||
destroyFont(font);
|
||||
deinitializeFreetype(ft);
|
||||
}
|
||||
|
||||
void FontAtlasGenerator::SavePng(const BitmapConstRef<byte, 1>& storage, const std::string& output, int channels) const
|
||||
{
|
||||
stbi_flip_vertically_on_write(1);
|
||||
if (std::filesystem::path(output).extension() == ".png")
|
||||
{
|
||||
stbi_write_png(output.c_str(), storage.width, storage.height, channels, storage.pixels,
|
||||
channels * storage.width);
|
||||
}
|
||||
else
|
||||
{
|
||||
stbi_write_png((output + ".png").c_str(), storage.width, storage.height, channels, storage.pixels,
|
||||
channels * storage.width);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __has_include("msdfgen.h")
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <map>
|
||||
@@ -25,6 +27,7 @@ namespace OpenVulkano::Scene
|
||||
class FontAtlasGenerator
|
||||
{
|
||||
public:
|
||||
using SdfGenerator = ImmediateAtlasGenerator<float, 1, sdfGenerator, BitmapAtlasStorage<msdfgen::byte, 1>>;
|
||||
static Charset LoadAllGlyphs(const std::variant<std::string, Array<char>>& data);
|
||||
void GenerateAtlas(const std::string& fontFile, const Charset& charset = Charset::ASCII,
|
||||
const std::optional<std::string>& pngOutput = std::nullopt);
|
||||
@@ -34,13 +37,16 @@ namespace OpenVulkano::Scene
|
||||
const Texture& GetAtlas() const { return m_atlasTex; }
|
||||
std::map<uint32_t, GlyphInfo>& GetGlyphsInfo() { return m_symbols; }
|
||||
AtlasMetadata& GetAtlasMetadata() { return m_meta; }
|
||||
SdfGenerator& GetFontAtlsGenerator() { return m_generator; }
|
||||
private:
|
||||
void Generate(FreetypeHandle* ft, FontHandle* font, const Charset& chset,
|
||||
const std::optional<std::string>& pngOutput);
|
||||
void SavePng(const BitmapConstRef<byte, 1>& storage, const std::string& output, int channels) const;
|
||||
private:
|
||||
ImmediateAtlasGenerator<float, 1, sdfGenerator, BitmapAtlasStorage<msdfgen::byte, 1>> m_generator;
|
||||
SdfGenerator m_generator;
|
||||
Texture m_atlasTex;
|
||||
AtlasMetadata m_meta;
|
||||
std::map<uint32_t, GlyphInfo> m_symbols;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user