Add initial font metrics and equation rendering.
This commit is contained in:
parent
c2027801be
commit
5ddd54dd6d
24 changed files with 868 additions and 63 deletions
|
@ -1,7 +1,83 @@
|
|||
#include "EquationNode.h"
|
||||
|
||||
#include "LatexMathExpression.h"
|
||||
#include "TextNode.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
EquationNode::EquationNode(const Transform& t)
|
||||
: AbstractVisualNode(t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EquationNode::~EquationNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EquationNode::setContent(LatexMathExpression* content)
|
||||
{
|
||||
mContent = content;
|
||||
mContentDirty = true;
|
||||
}
|
||||
|
||||
void EquationNode::update(SceneInfo* sceneInfo)
|
||||
{
|
||||
if (mContentDirty)
|
||||
{
|
||||
createOrUpdateGeometry(sceneInfo);
|
||||
mContentDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void EquationNode::addExpression(const LatexMathExpression* expression)
|
||||
{
|
||||
if (expression->getType() == LatexMathExpression::Type::LINEAR)
|
||||
{
|
||||
MLOG_INFO("Processing linear expr with : " << expression->getExpressions().size() << " children");
|
||||
for (const auto& expression : expression->getExpressions())
|
||||
{
|
||||
addExpression(expression.get());
|
||||
}
|
||||
}
|
||||
else if(expression->getType() == LatexMathExpression::Type::LEAF)
|
||||
{
|
||||
std::string content = "_";
|
||||
for (const auto& symbol : expression->getSymbols())
|
||||
{
|
||||
content += symbol.mUnicode;
|
||||
}
|
||||
MLOG_INFO("Processing leaf expr with content: " << content);
|
||||
auto node = std::make_unique<TextNode>(content, Transform(mTextCursor));
|
||||
node->setWidth(100);
|
||||
node->setFont(mDefaultFont);
|
||||
addChild(node.get());
|
||||
mText.push_back(std::move(node));
|
||||
|
||||
mTextCursor.move(20.0, 0.0);
|
||||
}
|
||||
else if (expression->getType() == LatexMathExpression::Type::FRACTION)
|
||||
{
|
||||
MLOG_INFO("Processing frac expr");
|
||||
if (expression->getExpressions().size() == 2)
|
||||
{
|
||||
auto x_cache = mTextCursor.getX();
|
||||
mTextCursor.move(0.0, -10.0);
|
||||
addExpression(expression->getExpressions()[0].get());
|
||||
|
||||
mTextCursor.move(mTextCursor.getX() - x_cache, 20.0);
|
||||
addExpression(expression->getExpressions()[1].get());
|
||||
|
||||
mTextCursor.move(0.0, -10.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EquationNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
||||
{
|
||||
mChildren.clear();
|
||||
mText.clear();
|
||||
|
||||
addExpression(mContent);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue