More text changes
This commit is contained in:
@@ -8,5 +8,7 @@ target_sources(Editor
|
||||
MaterialLoader.cpp
|
||||
MeshLoader.h
|
||||
MeshLoader.cpp
|
||||
SVGLoader.h
|
||||
SVGLoader.cpp
|
||||
TextureLoader.h
|
||||
TextureLoader.cpp "../../../tests/Engine/UI/Element.cpp")
|
||||
TextureLoader.cpp)
|
||||
@@ -31,45 +31,13 @@ void FontLoader::importAsset(FontImportArgs args) {
|
||||
// in case of the space character there is no bitmap
|
||||
// so we create a single pixel empty texture
|
||||
void FontLoader::import(FontImportArgs args, PFontAsset asset) {
|
||||
FT_Library ft;
|
||||
FT_Error error = FT_Init_FreeType(&ft);
|
||||
assert(!error);
|
||||
FT_Face face;
|
||||
error = FT_New_Face(ft, args.filePath.string().c_str(), 0, &face);
|
||||
assert(!error);
|
||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
||||
for (uint32 c = 0; c < 256; ++c) {
|
||||
if (FT_Load_Char(face, c, FT_LOAD_RENDER | FT_LOAD_COLOR)) {
|
||||
std::cout << "error loading " << (char)c << std::endl;
|
||||
continue;
|
||||
}
|
||||
FontAsset::Glyph& glyph = asset->glyphs[c];
|
||||
glyph.size = IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
|
||||
glyph.bearing = IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top);
|
||||
glyph.advance = face->glyph->advance.x;
|
||||
glyph.textureData.resize(glyph.size.x * glyph.size.y);
|
||||
if (glyph.textureData.size() == 0) {
|
||||
glyph.size.x = 1;
|
||||
glyph.size.y = 1;
|
||||
glyph.textureData.add(0);
|
||||
// load a single transparent pixel, so that we dont have to handle empty textures later
|
||||
} else {
|
||||
std::memcpy(glyph.textureData.data(), face->glyph->bitmap.buffer, glyph.textureData.size());
|
||||
}
|
||||
glyph.texture = graphics->createTexture2D(TextureCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = glyph.textureData.size(),
|
||||
.data = glyph.textureData.data(),
|
||||
},
|
||||
.format = Gfx::SE_FORMAT_R8_UNORM,
|
||||
.width = glyph.size.x,
|
||||
.height = glyph.size.y,
|
||||
.name = "FontGlyph",
|
||||
});
|
||||
}
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(ft);
|
||||
std::ifstream stream(args.filePath.c_str(), std::ios::binary | std::ios::ate);
|
||||
Array<uint8> ttfFile(stream.tellg());
|
||||
stream.seekg(0);
|
||||
stream.read((char*)ttfFile.data(), ttfFile.size());
|
||||
asset->ttfFile = std::move(ttfFile);
|
||||
asset->graphics = graphics;
|
||||
asset->loadFace();
|
||||
|
||||
AssetRegistry::saveAsset(asset, FontAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "SVGLoader.h"
|
||||
#include "Asset/SVGAsset.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include <fstream>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
SVGLoader::SVGLoader(Gfx::PGraphics graphic) {}
|
||||
|
||||
SVGLoader::~SVGLoader() {}
|
||||
|
||||
void SVGLoader::importAsset(SVGImportArgs args) {
|
||||
std::filesystem::path assetPath = args.filePath.filename();
|
||||
assetPath.replace_extension("asset");
|
||||
OSVGAsset asset = new SVGAsset(args.importPath, assetPath.stem().string());
|
||||
asset->setStatus(Asset::Status::Loading);
|
||||
// the registry takes ownership, but we need to edit the reference
|
||||
PSVGAsset ref = asset;
|
||||
AssetRegistry::get().registerSVG(std::move(asset));
|
||||
import(args, ref);
|
||||
}
|
||||
|
||||
void SVGLoader::import(SVGImportArgs args, PSVGAsset asset) {
|
||||
std::ifstream stream(args.filePath.c_str(), std::ios::binary | std::ios::ate);
|
||||
Array<char> svgFile(stream.tellg());
|
||||
stream.seekg(0);
|
||||
stream.read((char*)svgFile.data(), svgFile.size());
|
||||
asset->document = lunasvg::Document::loadFromData(svgFile.data());
|
||||
asset->data = std::move(svgFile);
|
||||
asset->graphics = graphics;
|
||||
|
||||
AssetRegistry::saveAsset(asset, SVGAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
|
||||
|
||||
asset->setStatus(Asset::Status::Ready);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "Containers/List.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(SVGAsset)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
struct SVGImportArgs {
|
||||
std::filesystem::path filePath;
|
||||
std::string importPath;
|
||||
};
|
||||
class SVGLoader {
|
||||
public:
|
||||
SVGLoader(Gfx::PGraphics graphic);
|
||||
~SVGLoader();
|
||||
void importAsset(SVGImportArgs args);
|
||||
|
||||
private:
|
||||
void import(SVGImportArgs args, PSVGAsset asset);
|
||||
Gfx::PGraphics graphics;
|
||||
};
|
||||
DECLARE_REF(SVGLoader)
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user