Basic Font integration.

This commit is contained in:
James Grogan 2022-11-15 09:32:28 +00:00
parent ce11c52ae5
commit 72123bc333
36 changed files with 325 additions and 198 deletions

View file

@ -1,5 +1,10 @@
#include "TextNode.h"
#include "Rectangle.h"
#include "FontsManager.h"
#include "IFontEngine.h"
#include "MeshPrimitives.h"
#include "Color.h"
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
@ -55,3 +60,39 @@ void TextNode::setStrokeColor(const Color& color)
{
mStrokeColor = color;
}
void TextNode::update(FontsManager* drawingManager)
{
updateMesh();
updateTexture(drawingManager);
}
void TextNode::updateMesh()
{
double font_height = 16;
double font_width = 16;
double text_width = mContent.size() * font_width;
const auto rect = Rectangle(mLocation, text_width, font_height);
auto mesh = MeshPrimitives::build(rect);
auto color = Color(0, 0, 0, 1.0);
mesh->addConstantFaceVectorAttribute("Color", color.getAsVectorDouble());
mMesh = std::move(mesh);
}
void TextNode::updateTexture(FontsManager* fontsManager)
{
fontsManager->getFontEngine()->loadFontFace("truetype/msttcorefonts/arial.ttf");
auto glyph = fontsManager->getFontEngine()->loadGlyph('A');
if (!glyph)
{
return;
}
mTexture = std::make_unique<Image<unsigned char> >(glyph->getWidth(), glyph->getHeight());
mTexture->setData(glyph->getData());
}