From 15b2b2ec050f23dc09c93c34c389ccba013b118b Mon Sep 17 00:00:00 2001 From: martii Date: Fri, 29 Nov 2013 21:06:36 +0100 Subject: [PATCH] remove widest_number definition and usage, add Font::getMaxDigitWidth() method instead Signed-off-by: M. Liebmann --- src/driver/fontrenderer.cpp | 17 +++++++++++ src/driver/fontrenderer.h | 2 ++ src/gui/channellist.cpp | 2 +- src/gui/components/cc_frm_clock.cpp | 13 ++------- .../components/unmaintained/cc_item_box.cpp | 2 +- src/gui/infoviewer.cpp | 2 +- src/gui/timeosd.cpp | 2 +- src/gui/volumebar.cpp | 2 +- src/gui/widget/menue.cpp | 28 ++++++++++++++----- src/neutrino.h | 2 -- 10 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/driver/fontrenderer.cpp b/src/driver/fontrenderer.cpp index 61cd4c2a3..d7bc09fb3 100644 --- a/src/driver/fontrenderer.cpp +++ b/src/driver/fontrenderer.cpp @@ -230,6 +230,8 @@ Font::Font(FBFontRenderClass *render, FTC_FaceID faceid, const int isize, const //font.image_type |= ftc_image_flag_autohinted; font.flags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT; + maxdigitwidth = 0; + scaler.face_id = font.face_id; scaler.width = isize * 64; scaler.height = isize * 64; @@ -318,6 +320,21 @@ int Font::getDigitOffset(void) return DigitOffset; } +int Font::getMaxDigitWidth(void) +{ + if (maxdigitwidth < 1) { + char b[2]; + b[1] = 0; + for (char c = '0'; c <= '9'; c++) { + *b = c; + int w = getRenderWidth(b, true); + if (w > maxdigitwidth) + maxdigitwidth = w; + } + } + return maxdigitwidth; +} + int UTF8ToUnicode(const char * &text, const bool utf8_encoded) // returns -1 on error { int unicode_value; diff --git a/src/driver/fontrenderer.h b/src/driver/fontrenderer.h index 124de9632..fa1f97ae1 100644 --- a/src/driver/fontrenderer.h +++ b/src/driver/fontrenderer.h @@ -53,6 +53,7 @@ class Font // these are HACKED values, because the font metrics were unusable. int height,DigitHeight,DigitOffset,ascender,descender,upper,lower; int fontwidth; + int maxdigitwidth; inline void paintFontPixel(fb_pixel_t *td, uint8_t fg_trans, uint8_t fg_red, uint8_t fg_green, uint8_t fg_blue, fb_pixel_t bg_col, int faktor, uint8_t index); @@ -71,6 +72,7 @@ class Font int getRenderWidth(const std::string & text, const bool utf8_encoded = false); int getHeight(void); int getDigitHeight(void); + int getMaxDigitWidth(void); int getDigitOffset(void); int getWidth(void); int getSize(){return font.width;} diff --git a/src/gui/channellist.cpp b/src/gui/channellist.cpp index 1f7114828..d09087cd6 100644 --- a/src/gui/channellist.cpp +++ b/src/gui/channellist.cpp @@ -1376,7 +1376,7 @@ int CChannelList::numericZap(int key) return res; } size_t maxchansize = MaxChanNr().size(); - int fw = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNEL_NUM_ZAP]->getRenderWidth(widest_number); + int fw = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNEL_NUM_ZAP]->getMaxDigitWidth(); int sx = maxchansize * fw + (fw/2); int sy = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNEL_NUM_ZAP]->getHeight() + 6; diff --git a/src/gui/components/cc_frm_clock.cpp b/src/gui/components/cc_frm_clock.cpp index cfe2d1363..5ffa37582 100644 --- a/src/gui/components/cc_frm_clock.cpp +++ b/src/gui/components/cc_frm_clock.cpp @@ -151,15 +151,7 @@ void CComponentsFrmClock::initCCLockItems() } } - int minNumWidth = 0, w_tmp; - char b[2]; - b[1] = 0; - for (int i = 0; i < 10; i++) { - b[0] = '0' + i; - w_tmp = (*getClockFont())->getRenderWidth(b, true); - if (w_tmp > minNumWidth) - minNumWidth = w_tmp; - } + int w_tmp; int minSepWidth = (*getClockFont())->getRenderWidth(":", true); w_tmp = (*getClockFont())->getRenderWidth(".", true); if (w_tmp > minSepWidth) @@ -189,14 +181,13 @@ void CComponentsFrmClock::initCCLockItems() char c = stmp.at(0); switch (c) { case '0' ... '9': - wtmp = minNumWidth; + wtmp = (*getClockFont())->getMaxDigitWidth(); break; case '.': case ':': wtmp = minSepWidth; break; default: - b[0] = c; wtmp = (*getClockFont())->getRenderWidth(stmp, true); } diff --git a/src/gui/components/unmaintained/cc_item_box.cpp b/src/gui/components/unmaintained/cc_item_box.cpp index 29140ebc2..4a2175dc7 100644 --- a/src/gui/components/unmaintained/cc_item_box.cpp +++ b/src/gui/components/unmaintained/cc_item_box.cpp @@ -356,7 +356,7 @@ void CComponentsItemBox::calSizeOfElements() digit_h = font_text->getDigitHeight(); digit_offset = font_text->getDigitOffset(); v_element_data[i].height = digit_h + (int)((float)digit_offset*1.5); -// v_element_data[i].width = font_text->getRenderWidth(widest_number)*4 + font->getRenderWidth(":"); +// v_element_data[i].width = font_text->getMaxDigitWidth() + font->getRenderWidth(":"); v_element_data[i].width = font_text->getRenderWidth(timestr); v_element_data[i].element = timestr; } diff --git a/src/gui/infoviewer.cpp b/src/gui/infoviewer.cpp index 20eff23cf..4517a8e0b 100644 --- a/src/gui/infoviewer.cpp +++ b/src/gui/infoviewer.cpp @@ -194,7 +194,7 @@ void CInfoViewer::start () if ( g_settings.infobar_show_channellogo != 3 && g_settings.infobar_show_channellogo != 5 && g_settings.infobar_show_channellogo != 6) /* 3 & 5 & 6 is "default" with sigscales etc. */ { - ChanWidth = 4 * g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_NUMBER]->getRenderWidth(widest_number) + 10; + ChanWidth = 4 * g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_NUMBER]->getMaxDigitWidth() + 10; ChanHeight = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_NUMBER]->getHeight() * 9 / 8; } else diff --git a/src/gui/timeosd.cpp b/src/gui/timeosd.cpp index dedbfc780..c7ea16720 100644 --- a/src/gui/timeosd.cpp +++ b/src/gui/timeosd.cpp @@ -74,7 +74,7 @@ void CTimeOSD::GetDimensions() m_height = 10; m_y = frameBuffer->getScreenY(); m_width = g_Font[TIMEOSD_FONT]->getRenderWidth("00:00:00"); - t1 = g_Font[TIMEOSD_FONT]->getRenderWidth(widest_number); + t1 = g_Font[TIMEOSD_FONT]->getMaxDigitWidth(); m_width += t1; } diff --git a/src/gui/volumebar.cpp b/src/gui/volumebar.cpp index 8578541b0..1a264f139 100644 --- a/src/gui/volumebar.cpp +++ b/src/gui/volumebar.cpp @@ -295,7 +295,7 @@ void CVolumeHelper::initInfoClock(Font** font) } digit_offset = (*clock_font)->getDigitOffset(); digit_h = (*clock_font)->getDigitHeight(); - int t1 = (*clock_font)->getRenderWidth(widest_number); + int t1 = (*clock_font)->getMaxDigitWidth(); int t2 = (*clock_font)->getRenderWidth(":"); clock_dy = digit_h + (int)((float)digit_offset * 1.3); clock_dx = t1*7 + t2*2; diff --git a/src/gui/widget/menue.cpp b/src/gui/widget/menue.cpp index be8e7a9e0..0c991e369 100644 --- a/src/gui/widget/menue.cpp +++ b/src/gui/widget/menue.cpp @@ -1213,15 +1213,29 @@ int CMenuOptionNumberChooser::getWidth(void) const char * l_optionName = (optionString != NULL) ? optionString : g_Locale->getText(optionName); int width = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(l_optionName, true); - char tmp[20], *t; + int _lower_bound = lower_bound; + int _upper_bound = upper_bound; + int m = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getMaxDigitWidth(); - snprintf(tmp, sizeof(tmp), "%d", lower_bound); - for(t = tmp; *t; t++) if (isdigit((int)*t)) *t = *widest_number; - int w1 = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp, true); + int w1 = 0; + if (_lower_bound < 0) { + w1 += g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth("-", true); + lower_bound *= -1; + } + while (_lower_bound > 0) { + w1 += m; + _lower_bound /= 10; + } - snprintf(tmp, sizeof(tmp), "%d", upper_bound); - for(t = tmp; *t; t++) if (isdigit((int)*t)) *t = *widest_number; - int w2 = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp, true); + int w2 = 0; + if (_upper_bound < 0) { + w2 += g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth("-", true); + _upper_bound *= -1; + } + while (_upper_bound > 0) { + w1 += m; + _upper_bound /= 10; + } width += (w1 > w2) ? w1 : w2; diff --git a/src/neutrino.h b/src/neutrino.h index 734405e9b..9bbe88c7f 100644 --- a/src/neutrino.h +++ b/src/neutrino.h @@ -49,8 +49,6 @@ #include -#define widest_number "2" - #define ANNOUNCETIME (1 * 60) /**************************************************************************************