mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 13:50:28 +01:00
Add baseline for pretty printing.
Change-Id: I77e76cb4b6191992137dd83f366006115ae65661
This commit is contained in:
@@ -13,12 +13,14 @@ class ExpressionLayout {
|
||||
void draw(KDPoint point);
|
||||
KDPoint origin();
|
||||
KDSize size();
|
||||
KDCoordinate baseline();
|
||||
void setParent(ExpressionLayout* parent);
|
||||
protected:
|
||||
virtual void render(KDPoint point) = 0;
|
||||
virtual KDSize computeSize() = 0;
|
||||
virtual ExpressionLayout * child(uint16_t index) = 0;
|
||||
virtual KDPoint positionOfChild(ExpressionLayout * child) = 0;
|
||||
KDCoordinate m_baseline;
|
||||
private:
|
||||
KDPoint absoluteOrigin();
|
||||
//void computeLayout();//ExpressionLayout * parent, uint16_t childIndex);
|
||||
|
||||
@@ -9,6 +9,7 @@ ExponentLayout::ExponentLayout(ExpressionLayout * base_layout, ExpressionLayout
|
||||
ExpressionLayout(), m_base_layout(base_layout), m_exponent_layout(exponent_layout) {
|
||||
m_base_layout->setParent(this);
|
||||
m_exponent_layout->setParent(this);
|
||||
m_baseline = m_exponent_layout->baseline() + m_base_layout->baseline() - EXPONENT_HEIGHT;
|
||||
}
|
||||
|
||||
ExponentLayout::~ExponentLayout() {
|
||||
@@ -44,7 +45,7 @@ KDPoint ExponentLayout::positionOfChild(ExpressionLayout * child) {
|
||||
KDPoint p;
|
||||
if (child == m_base_layout) {
|
||||
p.x = 0;
|
||||
p.y = m_exponent_layout->size().height - EXPONENT_HEIGHT;
|
||||
p.y = m_exponent_layout->baseline() - EXPONENT_HEIGHT;
|
||||
} else if (child == m_exponent_layout) {
|
||||
p.x = m_base_layout->size().width;
|
||||
p.y = 0;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "string_layout.h"
|
||||
|
||||
ExpressionLayout::ExpressionLayout() :
|
||||
m_baseline(0),
|
||||
m_parent(nullptr),
|
||||
m_sized(false),
|
||||
m_positioned(false),
|
||||
@@ -12,6 +13,10 @@ ExpressionLayout::ExpressionLayout() :
|
||||
ExpressionLayout::~ExpressionLayout() {
|
||||
}
|
||||
|
||||
KDCoordinate ExpressionLayout::baseline() {
|
||||
return m_baseline;
|
||||
}
|
||||
|
||||
KDPoint ExpressionLayout::origin() {
|
||||
if (m_parent == nullptr) {
|
||||
return absoluteOrigin();
|
||||
@@ -26,11 +31,6 @@ void ExpressionLayout::draw(KDPoint point) {
|
||||
c->draw(point);
|
||||
}
|
||||
render(KDPointTranslate(absoluteOrigin(), point));
|
||||
#if 0
|
||||
KDPoint topLeft = KDPointTranslate(absoluteOrigin(), point);
|
||||
KDPoint bottomRight = KDPointTranslate(KDPointTranslate(absoluteOrigin(), KDPOINT(size().width, 0 /*size().height*/)), point);
|
||||
KDDrawLine(topLeft, bottomRight);
|
||||
#endif
|
||||
}
|
||||
|
||||
KDPoint ExpressionLayout::absoluteOrigin() {
|
||||
|
||||
@@ -14,6 +14,7 @@ FractionLayout::FractionLayout(ExpressionLayout * numerator_layout, ExpressionLa
|
||||
ExpressionLayout(), m_numerator_layout(numerator_layout), m_denominator_layout(denominator_layout) {
|
||||
m_numerator_layout->setParent(this);
|
||||
m_denominator_layout->setParent(this);
|
||||
m_baseline = m_numerator_layout->size().height + FRACTION_LINE_MARGIN + KDStringSize(" ").height/2;
|
||||
}
|
||||
|
||||
FractionLayout::~FractionLayout() {
|
||||
|
||||
@@ -11,6 +11,9 @@ HorizontalLayout::HorizontalLayout(ExpressionLayout ** children_layouts, int num
|
||||
assert(number_of_children > 0);
|
||||
for (int i=0; i<m_number_of_children; i++) {
|
||||
m_children_layouts[i]->setParent(this);
|
||||
if (m_children_layouts[i]->baseline() > m_baseline) {
|
||||
m_baseline = m_children_layouts[i]->baseline();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,13 +29,18 @@ void HorizontalLayout::render(KDPoint point) { }
|
||||
KDSize HorizontalLayout::computeSize() {
|
||||
KDSize size = (KDSize){.width = 0, .height = 0};
|
||||
int i = 0;
|
||||
KDCoordinate max_under_baseline, max_above_baseline;
|
||||
while (ExpressionLayout * c = child(i++)) {
|
||||
KDSize childSize = c->size();
|
||||
size.width += childSize.width;
|
||||
if (childSize.height > size.height) {
|
||||
size.height = childSize.height;
|
||||
if (childSize.height - c->baseline() > max_under_baseline) {
|
||||
max_under_baseline = childSize.height - c->baseline() ;
|
||||
}
|
||||
if (c->baseline() > max_above_baseline) {
|
||||
max_above_baseline = c->baseline();
|
||||
}
|
||||
}
|
||||
size.height = max_under_baseline + max_above_baseline;
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -59,6 +67,6 @@ KDPoint HorizontalLayout::positionOfChild(ExpressionLayout * child) {
|
||||
assert(previousChild != nullptr);
|
||||
position.x = previousChild->origin().x + previousChild->size().width;
|
||||
}
|
||||
position.y = (size().height - child->size().height)/2;
|
||||
position.y = m_baseline - child->baseline();
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ ExpressionLayout() {
|
||||
m_string = (char *)malloc(sizeof(char)*(length+1));
|
||||
memcpy(m_string, string, (length+1));
|
||||
m_inverse = inverse;
|
||||
// Height of the font.
|
||||
m_baseline = KDStringSize(" ").height;
|
||||
}
|
||||
|
||||
StringLayout::~StringLayout() {
|
||||
|
||||
Reference in New Issue
Block a user