From 52dc269faecec157ba3e8f037a3fdfbc12300a83 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 1 Dec 2006 23:45:06 +0000 Subject: [PATCH] CharMetrics: use short int instead of int. This halves the memory required for the font metrics cache. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16129 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiFontMetrics.C | 14 ++++++++------ src/frontends/qt4/GuiFontMetrics.h | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index d915a6f94e..165c6459f2 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -26,7 +26,7 @@ namespace frontend { namespace { // Used for checking initialisation state of the C-ish metrics table. -const int BadMetrics = -1000; +const short int BadMetrics = -1000; } @@ -34,7 +34,7 @@ GuiFontMetrics::GuiFontMetrics(QFont const & font) : metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false) { #ifdef USE_LYX_FONTCACHE - for (int i = 0; i != MaxCharType; ++i) { + for (size_t i = 0; i != MaxCharType; ++i) { metrics_cache_[i].width = BadMetrics; metrics_cache_[i].ascent = BadMetrics; metrics_cache_[i].descent = BadMetrics; @@ -188,8 +188,8 @@ int GuiFontMetrics::descent(char_type c) const void GuiFontMetrics::fillCache(unsigned short val) const { QRect const & r = metrics_.boundingRect(QChar(val)); - metrics_cache_[val].descent = r.bottom() + 1; - metrics_cache_[val].ascent = -r.top(); + metrics_cache_[val].descent = static_cast(r.bottom() + 1); + metrics_cache_[val].ascent = static_cast(-r.top()); // We could as well compute the width but this is not really // needed for now as it is done directly in width() below. //metrics_cache_[val].width = metrics_.width(QChar(val)); @@ -204,8 +204,10 @@ int GuiFontMetrics::width(char_type c) const // its display is not supported. BOOST_ASSERT(c < MaxCharType); unsigned short val = static_cast(c); - if (metrics_cache_[val].width == BadMetrics) - metrics_cache_[val].width = metrics_.width(QChar(val)); + if (metrics_cache_[val].width == BadMetrics) { + metrics_cache_[val].width + = static_cast(metrics_.width(QChar(val))); + } return metrics_cache_[val].width; } diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h index f3c87adc28..f7360506ec 100644 --- a/src/frontends/qt4/GuiFontMetrics.h +++ b/src/frontends/qt4/GuiFontMetrics.h @@ -31,9 +31,9 @@ size_t const MaxCharType = 65536; struct CharMetrics { - int width; - int ascent; - int descent; + short int width; + short int ascent; + short int descent; }; -- 2.39.2