Clean up some rendering.
This commit is contained in:
parent
5ddd54dd6d
commit
77ce58c612
6 changed files with 55 additions and 19 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "LatexMathExpression.h"
|
||||
#include "TextNode.h"
|
||||
#include "LineNode.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
|
@ -31,31 +32,37 @@ void EquationNode::update(SceneInfo* sceneInfo)
|
|||
}
|
||||
}
|
||||
|
||||
void EquationNode::addExpression(const LatexMathExpression* expression)
|
||||
void EquationNode::addExpression(SceneInfo* sceneInfo, 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())
|
||||
for (const auto& child : expression->getExpressions())
|
||||
{
|
||||
addExpression(expression.get());
|
||||
addExpression(sceneInfo, child.get());
|
||||
}
|
||||
}
|
||||
else if(expression->getType() == LatexMathExpression::Type::LEAF)
|
||||
{
|
||||
std::string content = "_";
|
||||
std::string content;
|
||||
for (const auto& symbol : expression->getSymbols())
|
||||
{
|
||||
content += symbol.mUnicode;
|
||||
}
|
||||
MLOG_INFO("Processing leaf expr with content: " << content);
|
||||
|
||||
if (content.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MLOG_INFO("Processing leaf expr with content: " << content << " and size " << content.size());
|
||||
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);
|
||||
mTextCursor.move(node->getContentWidth(sceneInfo), 0.0);
|
||||
|
||||
mText.push_back(std::move(node));
|
||||
}
|
||||
else if (expression->getType() == LatexMathExpression::Type::FRACTION)
|
||||
{
|
||||
|
@ -63,13 +70,19 @@ void EquationNode::addExpression(const LatexMathExpression* expression)
|
|||
if (expression->getExpressions().size() == 2)
|
||||
{
|
||||
auto x_cache = mTextCursor.getX();
|
||||
mTextCursor.move(0.0, -10.0);
|
||||
addExpression(expression->getExpressions()[0].get());
|
||||
mTextCursor.move(0.0, -9.0);
|
||||
addExpression(sceneInfo, expression->getExpressions()[0].get());
|
||||
|
||||
mTextCursor.move(mTextCursor.getX() - x_cache, 20.0);
|
||||
addExpression(expression->getExpressions()[1].get());
|
||||
mTextCursor.move(x_cache - mTextCursor.getX(), 16.0);
|
||||
std::vector<Point> end_loc{ { 25.0, 0.0 } };
|
||||
auto dividing_line = std::make_unique<LineNode>(Transform(mTextCursor), end_loc);
|
||||
addChild(dividing_line.get());
|
||||
mLines.push_back(std::move(dividing_line));
|
||||
|
||||
mTextCursor.move(0.0, -10.0);
|
||||
mTextCursor.move(0.0, 2.0);
|
||||
addExpression(sceneInfo, expression->getExpressions()[1].get());
|
||||
|
||||
mTextCursor.move(0.0, -9.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,5 +92,5 @@ void EquationNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|||
mChildren.clear();
|
||||
mText.clear();
|
||||
|
||||
addExpression(mContent);
|
||||
addExpression(sceneInfo, mContent);
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include "FontItem.h"
|
||||
|
||||
class TextNode;
|
||||
class LineNode;
|
||||
class LatexMathExpression;
|
||||
|
||||
class EquationNode : public AbstractVisualNode
|
||||
|
@ -20,10 +21,11 @@ public:
|
|||
protected:
|
||||
void createOrUpdateGeometry(SceneInfo* sceneInfo);
|
||||
|
||||
void addExpression(const LatexMathExpression* expression);
|
||||
void addExpression(SceneInfo* sceneInfo, const LatexMathExpression* expression);
|
||||
|
||||
|
||||
std::vector<std::unique_ptr<TextNode> > mText;
|
||||
std::vector<std::unique_ptr<LineNode> > mLines;
|
||||
|
||||
FontItem mDefaultFont{ "Cambria Math", 14 };
|
||||
//FontItem mDefaultFont{ "Latin Modern Math", 14 };
|
||||
|
|
|
@ -158,7 +158,7 @@ double DirectWriteFontEngine::getHorizontalAdvance(const FontItem& fontItem, con
|
|||
{
|
||||
const auto design_width = metrics[idx].advanceWidth;
|
||||
// https://learn.microsoft.com/en-us/windows/win32/gdi/device-vs--design-units
|
||||
double device_width = (design_width / static_cast<double>(design_per_em)) * (fontItem.getSize() / 72.0) * 96.0 * 0.75;
|
||||
double device_width = (design_width / static_cast<double>(design_per_em)) * (fontItem.getSize() / 72.0) * 96.0 * 0.8;
|
||||
|
||||
MLOG_INFO("Got advance width: " << device_width);
|
||||
//total_advance += std::floor(device_width);
|
||||
|
|
|
@ -54,6 +54,24 @@ double TextNode::getHeight() const
|
|||
return mHeight;
|
||||
}
|
||||
|
||||
double TextNode::getContentWidth(SceneInfo* sceneInfo)
|
||||
{
|
||||
if (mContentWidth == 1.0)
|
||||
{
|
||||
mContentWidth = sceneInfo->mFontsManager->getFontEngine()->getHorizontalAdvance(mTextData.mFont, mTextData.mContent);
|
||||
}
|
||||
return mContentWidth;
|
||||
}
|
||||
|
||||
double TextNode::getContentHeight(SceneInfo* sceneInfo)
|
||||
{
|
||||
if (mContentHeight == 1.0)
|
||||
{
|
||||
mContentHeight = mTextData.mFont.getSize();
|
||||
}
|
||||
return mContentHeight;
|
||||
}
|
||||
|
||||
void TextNode::setWidth(double width)
|
||||
{
|
||||
if (mWidth != width)
|
||||
|
@ -190,8 +208,8 @@ void TextNode::update(SceneInfo* sceneInfo)
|
|||
mTextItem = std::make_unique<SceneText>();
|
||||
mTextItem->setName(mName + "_SceneText");
|
||||
|
||||
mContentWidth = sceneInfo->mFontsManager->getFontEngine()->getHorizontalAdvance(mTextData.mFont, mTextData.mContent);
|
||||
mContentHeight = mTextData.mFont.getSize();
|
||||
getContentWidth(sceneInfo);
|
||||
getContentHeight(sceneInfo);
|
||||
|
||||
if (mWidth == 1.0 && mHeight == 1.0)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,9 @@ public:
|
|||
double getWidth() const;
|
||||
double getHeight() const;
|
||||
|
||||
double getContentWidth(SceneInfo* sceneInfo);
|
||||
double getContentHeight(SceneInfo* sceneInfo);
|
||||
|
||||
void setWidth(double width);
|
||||
void setHeight(double height);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
TEST_CASE(TestLatexConverter, "publishing")
|
||||
{
|
||||
auto expression = std::make_unique<LatexMathExpression>("\\psi = \\frac{\\alpha + \\beta}{c}");
|
||||
auto expression = std::make_unique<LatexMathExpression>("\\psi = \\frac{\\alpha + \\beta}{c + d} + e");
|
||||
|
||||
auto equation_node = std::make_unique<EquationNode>(Point(10, 10));
|
||||
equation_node->setContent(expression.get());
|
||||
|
|
Loading…
Reference in a new issue