diff --git a/apps/exam_pop_up_controller.cpp b/apps/exam_pop_up_controller.cpp index 1e80b1462..d938b0aee 100644 --- a/apps/exam_pop_up_controller.cpp +++ b/apps/exam_pop_up_controller.cpp @@ -1,7 +1,7 @@ #include "exam_pop_up_controller.h" +#include "apps_container.h" #include "i18n.h" #include "global_preferences.h" -#include "apps_container.h" #include ExamPopUpController::ExamPopUpController() : @@ -128,7 +128,7 @@ View * ExamPopUpController::ContentView::subviewAtIndex(int index) { void ExamPopUpController::ContentView::layoutSubviews() { KDCoordinate height = bounds().height(); KDCoordinate width = bounds().width(); - KDCoordinate textHeight = KDText::stringSize(" ", KDText::FontSize::Small).height(); + KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height(); m_warningTextView.setFrame(KDRect(0, k_topMargin, width, textHeight)); m_messageTextView1.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+textHeight, width, textHeight)); m_messageTextView2.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+2*textHeight, width, textHeight)); diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index da471ab3c..ffd412e02 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -35,7 +35,7 @@ KDCoordinate ListController::rowHeight(int j) { return k_emptyRowHeight; } KDCoordinate functionSize = function->layout()->size().height(); - return functionSize + k_emptyRowHeight - KDText::stringSize(" ").height(); + return functionSize + k_emptyRowHeight - KDText::charSize().height(); } void ListController::editExpression(Function * function, Ion::Events::Event event) { diff --git a/apps/hardware_test/battery_test_controller.cpp b/apps/hardware_test/battery_test_controller.cpp index 322e0dbd1..6186448e9 100644 --- a/apps/hardware_test/battery_test_controller.cpp +++ b/apps/hardware_test/battery_test_controller.cpp @@ -94,7 +94,7 @@ void BatteryTestController::ContentView::setColor(KDColor color) { void BatteryTestController::ContentView::layoutSubviews() { m_batteryStateView.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height/2)); - KDSize textSize = KDText::stringSize(" ", KDText::FontSize::Small); + KDSize textSize = KDText::charSize(KDText::FontSize::Small); m_batteryLevelView.setFrame(KDRect(0, Ion::Display::Height-2*textSize.height(), Ion::Display::Width, textSize.height())); m_batteryChargingView.setFrame(KDRect(0, Ion::Display::Height-textSize.height(), Ion::Display::Width, textSize.height())); } diff --git a/apps/hardware_test/pop_up_controller.cpp b/apps/hardware_test/pop_up_controller.cpp index fd35efda8..3f53b830b 100644 --- a/apps/hardware_test/pop_up_controller.cpp +++ b/apps/hardware_test/pop_up_controller.cpp @@ -100,7 +100,7 @@ View * PopUpController::ContentView::subviewAtIndex(int index) { void PopUpController::ContentView::layoutSubviews() { KDCoordinate height = bounds().height(); KDCoordinate width = bounds().width(); - KDCoordinate textHeight = KDText::stringSize(" ", KDText::FontSize::Small).height(); + KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height(); m_warningTextView.setFrame(KDRect(0, k_topMargin, width, textHeight)); m_messageTextView1.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+textHeight, width, textHeight)); m_messageTextView2.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+2*textHeight, width, textHeight)); diff --git a/apps/on_boarding/update_controller.cpp b/apps/on_boarding/update_controller.cpp index 2405c6557..72b2a86a5 100644 --- a/apps/on_boarding/update_controller.cpp +++ b/apps/on_boarding/update_controller.cpp @@ -70,7 +70,7 @@ void UpdateController::ContentView::layoutSubviews() { KDCoordinate height = bounds().height(); KDCoordinate width = bounds().width(); KDCoordinate titleHeight = m_titleTextView.minimalSizeForOptimalDisplay().height(); - KDCoordinate textHeight = KDText::stringSize(" ", KDText::FontSize::Small).height(); + KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height(); m_titleTextView.setFrame(KDRect(0, k_titleMargin, width, titleHeight)); m_messageTextView1.setFrame(KDRect(0, k_paragraphHeight, width, textHeight)); m_messageTextView2.setFrame(KDRect(0, k_paragraphHeight+textHeight, width, textHeight)); diff --git a/apps/probability/calculation_controller.cpp b/apps/probability/calculation_controller.cpp index 4ef98cab5..7aff9724a 100644 --- a/apps/probability/calculation_controller.cpp +++ b/apps/probability/calculation_controller.cpp @@ -72,9 +72,9 @@ void CalculationController::ContentView::willDisplayEditableCellAtIndex(int inde void CalculationController::ContentView::layoutSubviews() { markRectAsDirty(bounds()); - KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleHeightMargin; + KDCoordinate titleHeight = KDText::charSize(KDText::FontSize::Small).height()+k_titleHeightMargin; m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight)); - KDSize charSize = KDText::stringSize(" "); + KDSize charSize = KDText::charSize(); KDCoordinate xCoordinate = 0; m_lawCurveView.setFrame(KDRect(0, titleHeight+ImageTableView::k_oneCellHeight, bounds().width(), bounds().height() - ImageTableView::k_oneCellHeight-titleHeight)); KDSize tableSize = m_imageTableView.minimalSizeForOptimalDisplay(); @@ -102,9 +102,9 @@ void CalculationController::ContentView::layoutSubviews() { } void CalculationController::ContentView::drawRect(KDContext * ctx, KDRect rect) const { - KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleHeightMargin; + KDCoordinate titleHeight = KDText::charSize(KDText::FontSize::Small).height()+k_titleHeightMargin; ctx->fillRect(KDRect(0,titleHeight, bounds().width(), ImageTableView::k_oneCellWidth), KDColorWhite); - KDSize charSize = KDText::stringSize(" "); + KDSize charSize = KDText::charSize(); int numberOfCharacters; KDCoordinate xCoordinate = ImageTableView::k_oneCellWidth + k_textWidthMargin; KDCoordinate textFieldWidth = k_largeTextFieldWidth; diff --git a/apps/probability/law_controller.cpp b/apps/probability/law_controller.cpp index 14e3777f2..9b6353214 100644 --- a/apps/probability/law_controller.cpp +++ b/apps/probability/law_controller.cpp @@ -39,7 +39,7 @@ View * LawController::ContentView::subviewAtIndex(int index) { } void LawController::ContentView::layoutSubviews() { - KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleMargin; + KDCoordinate titleHeight = KDText::charSize(KDText::FontSize::Small).height()+k_titleMargin; m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight)); m_selectableTableView->setFrame(KDRect(0, titleHeight, bounds().width(), bounds().height()-titleHeight)); } diff --git a/apps/probability/parameters_controller.cpp b/apps/probability/parameters_controller.cpp index 891aba8f6..6d55c1f40 100644 --- a/apps/probability/parameters_controller.cpp +++ b/apps/probability/parameters_controller.cpp @@ -51,11 +51,11 @@ View * ParametersController::ContentView::subviewAtIndex(int index) { } void ParametersController::ContentView::layoutSubviews() { - KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleMargin; + KDCoordinate titleHeight = KDText::charSize(KDText::FontSize::Small).height()+k_titleMargin; m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight)); KDCoordinate tableHeight = m_selectableTableView->size().height() + Metric::CommonTopMargin + Metric::CommonBottomMargin; m_selectableTableView->setFrame(KDRect(0, titleHeight, bounds().width(), tableHeight)); - KDCoordinate textHeight = KDText::stringSize("", KDText::FontSize::Small).height(); + KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height(); KDCoordinate defOrigin = (titleHeight+tableHeight)/2+(bounds().height()-textHeight)/2; m_secondParameterDefinition.setFrame(KDRectZero); if (m_numberOfParameters == 2) { diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp index ccd3d98e3..cd3758e8f 100644 --- a/apps/sequence/list/list_controller.cpp +++ b/apps/sequence/list/list_controller.cpp @@ -67,7 +67,7 @@ KDCoordinate ListController::rowHeight(int j) { return defaultHeight; } KDCoordinate sequenceSize = layout->size().height(); - return sequenceSize + defaultHeight - KDText::stringSize(" ").height(); + return sequenceSize + defaultHeight - KDText::charSize().height(); } void ListController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { diff --git a/apps/shared/banner_view.cpp b/apps/shared/banner_view.cpp index 27ecd922d..8643b0dcf 100644 --- a/apps/shared/banner_view.cpp +++ b/apps/shared/banner_view.cpp @@ -22,7 +22,7 @@ void BannerView::setMessageAtIndex(I18n::Message text, int index) { } KDSize BannerView::minimalSizeForOptimalDisplay() const { - return KDSize(0, KDText::stringSize(" ", KDText::FontSize::Small).height()*numberOfLines()); + return KDSize(0, KDText::charSize(KDText::FontSize::Small).height()*numberOfLines()); } int BannerView::numberOfSubviews() const { diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index aca0111a4..896ee52b8 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -120,7 +120,7 @@ TextArea::ContentView::ContentView(char * textBuffer, size_t textBufferSize, KDT } KDSize TextArea::ContentView::minimalSizeForOptimalDisplay() const { - KDSize charSize = KDText::stringSize(" ", m_fontSize); + KDSize charSize = KDText::charSize(m_fontSize); Text::Position span = m_text.span(); return KDSize( charSize.width() * span.column(), @@ -132,7 +132,7 @@ KDSize TextArea::ContentView::minimalSizeForOptimalDisplay() const { void TextArea::ContentView::drawRect(KDContext * ctx, KDRect rect) const { ctx->fillRect(rect, m_backgroundColor); - KDSize charSize = KDText::stringSize(" ", m_fontSize); + KDSize charSize = KDText::charSize(m_fontSize); // We want to draw even partially visible characters. So we need to round // down for the top left corner and up for the bottom right one. @@ -197,7 +197,7 @@ KDRect TextArea::TextArea::ContentView::cursorRect() { } KDRect TextArea::TextArea::ContentView::characterFrameAtIndex(size_t index) { - KDSize charSize = KDText::stringSize(" ", m_fontSize); + KDSize charSize = KDText::charSize(m_fontSize); Text::Position p = m_text.positionAtIndex(index); return KDRect( p.column() * charSize.width(), diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index d0b63f9d3..466b26491 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -160,12 +160,12 @@ KDSize TextField::ContentView::minimalSizeForOptimalDisplay() const { } KDCoordinate TextField::ContentView::textHeight() const { - KDSize textSize = KDText::stringSize(" ", m_fontSize); + KDSize textSize = KDText::charSize(m_fontSize); return textSize.height(); } KDCoordinate TextField::ContentView::charWidth() { - KDSize textSize = KDText::stringSize(" ", m_fontSize); + KDSize textSize = KDText::charSize(m_fontSize); return textSize.width(); } diff --git a/kandinsky/include/kandinsky/text.h b/kandinsky/include/kandinsky/text.h index fb18f1d78..91c887123 100644 --- a/kandinsky/include/kandinsky/text.h +++ b/kandinsky/include/kandinsky/text.h @@ -10,6 +10,7 @@ public: Large }; static KDSize stringSize(const char * text, FontSize size = FontSize::Large); + static KDSize charSize(FontSize size = FontSize::Large); }; #endif diff --git a/kandinsky/src/text.cpp b/kandinsky/src/text.cpp index d73ac807d..a4aa3e268 100644 --- a/kandinsky/src/text.cpp +++ b/kandinsky/src/text.cpp @@ -7,8 +7,12 @@ KDSize KDText::stringSize(const char * text, FontSize size) { if (text == nullptr) { return KDSizeZero; } - if (size == FontSize::Large) { - return KDSize(BITMAP_LargeFont_CHARACTER_WIDTH*strlen(text), BITMAP_LargeFont_CHARACTER_HEIGHT); - } - return KDSize(BITMAP_SmallFont_CHARACTER_WIDTH*strlen(text), BITMAP_SmallFont_CHARACTER_HEIGHT); + KDSize cSize = charSize(size); + return KDSize(cSize.width()*strlen(text), cSize.height()); } + +KDSize KDText::charSize(FontSize size) { + if (size == FontSize::Large) { + return KDSize(BITMAP_LargeFont_CHARACTER_WIDTH, BITMAP_LargeFont_CHARACTER_HEIGHT); + } + return KDSize(BITMAP_SmallFont_CHARACTER_WIDTH, BITMAP_SmallFont_CHARACTER_HEIGHT);} diff --git a/poincare/src/layout/fraction_layout.cpp b/poincare/src/layout/fraction_layout.cpp index 407d00fc2..6cc395b82 100644 --- a/poincare/src/layout/fraction_layout.cpp +++ b/poincare/src/layout/fraction_layout.cpp @@ -10,7 +10,7 @@ ExpressionLayout(), m_numerator_layout(numerator_layout), m_denominator_layout(d m_denominator_layout->setParent(this); m_baseline = m_numerator_layout->size().height() + k_fractionLineMargin - + KDText::stringSize(" ").height()/2; + + KDText::charSize().height()/2; } FractionLayout::~FractionLayout() { diff --git a/poincare/src/layout/grid_layout.cpp b/poincare/src/layout/grid_layout.cpp index 91bc2f6f3..b40f7adc5 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::stringSize(" ").height()/2; + m_baseline = height()/2 + KDText::charSize().height()/2; } GridLayout::~GridLayout() { diff --git a/poincare/src/layout/string_layout.cpp b/poincare/src/layout/string_layout.cpp index cec122bca..4cb1de862 100644 --- a/poincare/src/layout/string_layout.cpp +++ b/poincare/src/layout/string_layout.cpp @@ -12,7 +12,7 @@ StringLayout::StringLayout(const char * string, size_t length, KDText::FontSize memcpy(m_string, string, length); m_string[length] = 0; // Height of the font. - m_baseline = KDText::stringSize(" ", m_fontSize).height(); + m_baseline = KDText::charSize(m_fontSize).height(); } StringLayout::~StringLayout() {