From 7ae6241acd83a26815b48ebb30bfa7dc45477b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 22 Nov 2017 14:38:08 +0100 Subject: [PATCH] [poincare] Fix all layouts: redefine baseline Change-Id: Iff04bf9bee946050721fc095d1617586dc251d6b --- poincare/src/layout/fraction_layout.cpp | 3 +-- poincare/src/layout/grid_layout.cpp | 2 +- poincare/src/layout/product_layout.cpp | 6 +++--- poincare/src/layout/sequence_layout.cpp | 8 ++++---- poincare/src/layout/string_layout.cpp | 4 ++-- poincare/src/layout/sum_layout.cpp | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/poincare/src/layout/fraction_layout.cpp b/poincare/src/layout/fraction_layout.cpp index 44b77435e..e71a263db 100644 --- a/poincare/src/layout/fraction_layout.cpp +++ b/poincare/src/layout/fraction_layout.cpp @@ -9,8 +9,7 @@ ExpressionLayout(), m_numerator_layout(numerator_layout), m_denominator_layout(d m_numerator_layout->setParent(this); m_denominator_layout->setParent(this); m_baseline = m_numerator_layout->size().height() - + k_fractionLineMargin + k_fractionLineHeight - + KDText::charSize().height()/2; + + k_fractionLineMargin + k_fractionLineHeight; } FractionLayout::~FractionLayout() { diff --git a/poincare/src/layout/grid_layout.cpp b/poincare/src/layout/grid_layout.cpp index b40f7adc5..495e4e9c7 100644 --- a/poincare/src/layout/grid_layout.cpp +++ b/poincare/src/layout/grid_layout.cpp @@ -16,7 +16,7 @@ GridLayout::GridLayout(ExpressionLayout ** entryLayouts, int numberOfRows, int n m_entryLayouts[i] = entryLayouts[i]; m_entryLayouts[i]->setParent(this); } - m_baseline = height()/2 + KDText::charSize().height()/2; + m_baseline = (height()+1)/2; } GridLayout::~GridLayout() { diff --git a/poincare/src/layout/product_layout.cpp b/poincare/src/layout/product_layout.cpp index 4699da3c5..cb573cf4b 100644 --- a/poincare/src/layout/product_layout.cpp +++ b/poincare/src/layout/product_layout.cpp @@ -8,13 +8,13 @@ void ProductLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDSize upperBoundSize = m_upperBoundLayout->size(); KDSize lowerBoundSize = m_lowerBoundLayout->size(); ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSize.width()-k_symbolWidth)/2), - p.y() + max(upperBoundSize.height()+k_boundHeightMargin, m_argumentLayout->baseline()-k_symbolHeight), + p.y() + max(upperBoundSize.height()+k_boundHeightMargin, m_argumentLayout->baseline()-(k_symbolHeight+1)/2), k_lineThickness, k_symbolHeight), expressionColor); ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSize.width()-k_symbolWidth)/2), - p.y() + max(upperBoundSize.height()+k_boundHeightMargin, m_argumentLayout->baseline()-k_symbolHeight), + p.y() + max(upperBoundSize.height()+k_boundHeightMargin, m_argumentLayout->baseline()-(k_symbolHeight+1)/2), k_symbolWidth, k_lineThickness), expressionColor); ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSize.width()-k_symbolWidth)/2)+k_symbolWidth, - p.y() + max(upperBoundSize.height()+k_boundHeightMargin, m_argumentLayout->baseline()-k_symbolHeight), + p.y() + max(upperBoundSize.height()+k_boundHeightMargin, m_argumentLayout->baseline()-(k_symbolHeight+1)/2), k_lineThickness, k_symbolHeight), expressionColor); } diff --git a/poincare/src/layout/sequence_layout.cpp b/poincare/src/layout/sequence_layout.cpp index 927d0ee08..52ed5dc95 100644 --- a/poincare/src/layout/sequence_layout.cpp +++ b/poincare/src/layout/sequence_layout.cpp @@ -13,7 +13,7 @@ SequenceLayout::SequenceLayout(ExpressionLayout * lowerBoundLayout, ExpressionLa m_lowerBoundLayout->setParent(this); m_upperBoundLayout->setParent(this); m_argumentLayout->setParent(this); - m_baseline = max(m_upperBoundLayout->size().height()+k_boundHeightMargin+k_symbolHeight, m_argumentLayout->baseline()); + m_baseline = max(m_upperBoundLayout->size().height()+k_boundHeightMargin+(k_symbolHeight+1)/2, m_argumentLayout->baseline()); } SequenceLayout::~SequenceLayout() { @@ -28,7 +28,7 @@ KDSize SequenceLayout::computeSize() { KDSize upperBoundSize = m_upperBoundLayout->size(); return KDSize( max(max(k_symbolWidth, lowerBoundSize.width()), upperBoundSize.width())+k_argumentWidthMargin+argumentSize.width(), - m_baseline + max(k_boundHeightMargin+lowerBoundSize.height(), argumentSize.height() - m_argumentLayout->baseline()) + m_baseline + max(k_symbolHeight/2+k_boundHeightMargin+lowerBoundSize.height(), argumentSize.height() - m_argumentLayout->baseline()) ); } @@ -52,10 +52,10 @@ KDPoint SequenceLayout::positionOfChild(ExpressionLayout * child) { KDCoordinate y = 0; if (child == m_lowerBoundLayout) { x = max(max(0, (k_symbolWidth-lowerBoundSize.width())/2), (upperBoundSize.width()-lowerBoundSize.width())/2); - y = m_baseline + k_boundHeightMargin; + y = m_baseline + k_symbolHeight/2 + k_boundHeightMargin; } else if (child == m_upperBoundLayout) { x = max(max(0, (k_symbolWidth-upperBoundSize.width())/2), (lowerBoundSize.width()-upperBoundSize.width())/2); - y = m_baseline - k_symbolHeight- k_boundHeightMargin-upperBoundSize.height(); + y = m_baseline - (k_symbolHeight+1)/2- k_boundHeightMargin-upperBoundSize.height(); } else if (child == m_argumentLayout) { x = max(max(k_symbolWidth, lowerBoundSize.width()), upperBoundSize.width())+k_argumentWidthMargin; y = m_baseline - m_argumentLayout->baseline(); diff --git a/poincare/src/layout/string_layout.cpp b/poincare/src/layout/string_layout.cpp index 4cb1de862..62bbbb68c 100644 --- a/poincare/src/layout/string_layout.cpp +++ b/poincare/src/layout/string_layout.cpp @@ -11,8 +11,8 @@ StringLayout::StringLayout(const char * string, size_t length, KDText::FontSize m_string = new char[length+1]; memcpy(m_string, string, length); m_string[length] = 0; - // Height of the font. - m_baseline = KDText::charSize(m_fontSize).height(); + // Half height of the font. + m_baseline = (KDText::charSize(m_fontSize).height()+1)/2; } StringLayout::~StringLayout() { diff --git a/poincare/src/layout/sum_layout.cpp b/poincare/src/layout/sum_layout.cpp index 17bb0a995..95c376bee 100644 --- a/poincare/src/layout/sum_layout.cpp +++ b/poincare/src/layout/sum_layout.cpp @@ -27,7 +27,7 @@ void SumLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDCo KDSize lowerBoundSize = m_lowerBoundLayout->size(); KDColor workingBuffer[k_symbolWidth*k_symbolHeight]; KDRect symbolFrame(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSize.width()-k_symbolWidth)/2), - p.y() + max(upperBoundSize.height()+k_boundHeightMargin, m_argumentLayout->baseline()-k_symbolHeight), + p.y() + max(upperBoundSize.height()+k_boundHeightMargin, m_argumentLayout->baseline()-(k_symbolHeight+1)/2), k_symbolWidth, k_symbolHeight); ctx->blendRectWithMask(symbolFrame, expressionColor, (const uint8_t *)symbolPixel, (KDColor *)workingBuffer); }