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
|
@ -9,6 +9,8 @@
|
|||
#include "SceneInfo.h"
|
||||
|
||||
#include "SceneText.h"
|
||||
#include "SceneModel.h"
|
||||
#include "Rectangle.h"
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
|
@ -18,6 +20,8 @@ TextNode::TextNode(const std::string& content, const Transform& transform)
|
|||
: MaterialNode(transform)
|
||||
{
|
||||
mTextData.mContent= content;
|
||||
setFillColor(Color(0, 0, 0));
|
||||
setHasStrokeColor(false);
|
||||
}
|
||||
|
||||
TextNode::~TextNode()
|
||||
|
@ -92,15 +96,39 @@ SceneItem* TextNode::getSceneItem(std::size_t idx) const
|
|||
{
|
||||
return mTextItem.get();
|
||||
}
|
||||
else
|
||||
else if (idx == 1)
|
||||
{
|
||||
return 0;
|
||||
if (mNodeBounds)
|
||||
{
|
||||
return mNodeBounds.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return mTextBounds.get();
|
||||
}
|
||||
}
|
||||
else if (idx == 2)
|
||||
{
|
||||
if (mTextBounds)
|
||||
{
|
||||
return mTextBounds.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::size_t TextNode::getNumSceneItems() const
|
||||
{
|
||||
return 1;
|
||||
auto count = 1;
|
||||
if (mNodeBounds)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
if (mTextBounds)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void TextNode::updateLines(FontsManager* fontsManager)
|
||||
|
@ -145,12 +173,58 @@ void TextNode::updateLines(FontsManager* fontsManager)
|
|||
}
|
||||
}
|
||||
|
||||
void TextNode::setRenderNodeBounds(bool render)
|
||||
{
|
||||
mRenderNodeBounds = render;
|
||||
}
|
||||
|
||||
void TextNode::setRenderTextBounds(bool render)
|
||||
{
|
||||
mRenderTextBounds = render;
|
||||
}
|
||||
|
||||
void TextNode::update(SceneInfo* sceneInfo)
|
||||
{
|
||||
if (!mTextItem)
|
||||
{
|
||||
mTextItem = std::make_unique<SceneText>();
|
||||
mTextItem->setName(mName + "_SceneText");
|
||||
|
||||
mContentWidth = sceneInfo->mFontsManager->getFontEngine()->getHorizontalAdvance(mTextData.mFont, mTextData.mContent);
|
||||
mContentHeight = mTextData.mFont.getSize();
|
||||
|
||||
if (mWidth == 1.0 && mHeight == 1.0)
|
||||
{
|
||||
mTextItem->setTextWidth(mContentWidth);
|
||||
mTextItem->setTextHeight(mContentHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
mTextItem->setTextWidth(mWidth);
|
||||
mTextItem->setTextHeight(mHeight);
|
||||
}
|
||||
|
||||
if (mRenderNodeBounds)
|
||||
{
|
||||
auto rect = std::make_unique<ntk::Rectangle>(Point(0.0, 0.0), mWidth, mHeight);
|
||||
mNodeBounds = std::make_unique<SceneModel>();
|
||||
mNodeBounds->updateGeometry(std::move(rect));
|
||||
|
||||
BasicMaterial bounds_material;
|
||||
bounds_material.setStrokeColor(Color(255, 0, 0));
|
||||
mNodeBounds->updateSolidMaterial(bounds_material);
|
||||
}
|
||||
|
||||
if (mRenderTextBounds)
|
||||
{
|
||||
auto rect = std::make_unique<ntk::Rectangle>(Point(0.0, 0.0), mContentWidth, mContentHeight);
|
||||
mTextBounds = std::make_unique<SceneModel>();
|
||||
mTextBounds->updateGeometry(std::move(rect));
|
||||
|
||||
BasicMaterial bounds_material;
|
||||
bounds_material.setStrokeColor(Color(0, 255, 0));
|
||||
mTextBounds->updateSolidMaterial(bounds_material);
|
||||
}
|
||||
}
|
||||
|
||||
if (mTransformIsDirty || mContentIsDirty)
|
||||
|
@ -167,9 +241,16 @@ void TextNode::update(SceneInfo* sceneInfo)
|
|||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
//mTextItem->updateTransform({mLocation});
|
||||
mTextItem->setTextWidth(mWidth);
|
||||
mTextItem->setTextHeight(mHeight);
|
||||
if (mWidth == 1.0 && mHeight == 1.0)
|
||||
{
|
||||
mTextItem->setTextWidth(mContentWidth);
|
||||
mTextItem->setTextHeight(mContentHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
mTextItem->setTextWidth(mWidth);
|
||||
mTextItem->setTextHeight(mHeight);
|
||||
}
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <string>
|
||||
|
||||
class FontsManager;
|
||||
class SceneModel;
|
||||
|
||||
class TextNode : public MaterialNode
|
||||
{
|
||||
|
@ -34,9 +35,11 @@ public:
|
|||
void setHeight(double height);
|
||||
|
||||
void setContent(const std::string& content);
|
||||
|
||||
void setFont(const FontItem& font);
|
||||
|
||||
void setRenderNodeBounds(bool render);
|
||||
void setRenderTextBounds(bool render);
|
||||
|
||||
void update(SceneInfo* sceneInfo) override;
|
||||
private:
|
||||
|
||||
|
@ -49,7 +52,15 @@ private:
|
|||
double mWidth{1};
|
||||
double mHeight{1};
|
||||
|
||||
double mContentWidth{ 1 };
|
||||
double mContentHeight{ 1 };
|
||||
|
||||
std::unique_ptr<SceneText> mTextItem;
|
||||
|
||||
bool mRenderNodeBounds{ false };
|
||||
bool mRenderTextBounds{ false };
|
||||
std::unique_ptr<SceneModel> mNodeBounds;
|
||||
std::unique_ptr<SceneModel> mTextBounds;
|
||||
};
|
||||
|
||||
using TextNodetr = std::unique_ptr<TextNode>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue