]> git.lyx.org Git - features.git/commitdiff
* GuiFontMetrics
authorAbdelrazak Younes <younes@lyx.org>
Fri, 1 Dec 2006 17:23:58 +0000 (17:23 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Fri, 1 Dec 2006 17:23:58 +0000 (17:23 +0000)
  - add constants instead of hard-coded values.
  - add assertions and comments for out of range values.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16126 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiFontMetrics.C
src/frontends/qt4/GuiFontMetrics.h

index a10381096fdf4683098d373359ce2251ce58b01a..d915a6f94ebd61027d1c0c64f3180377cc526ed8 100644 (file)
@@ -24,15 +24,20 @@ using std::string;
 namespace lyx {
 namespace frontend {
 
+namespace {
+// Used for checking initialisation state of the C-ish metrics table.
+const int BadMetrics = -1000;
+}
+
 
 GuiFontMetrics::GuiFontMetrics(QFont const & font)
 : metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false)
 {
 #ifdef USE_LYX_FONTCACHE
- for (int i = 0; i != 65536; ++i) {
-        metrics_cache_[i].width = -1000;
-        metrics_cache_[i].ascent = -1000;
-        metrics_cache_[i].descent = -1000;
+ for (int i = 0; i != MaxCharType; ++i) {
+        metrics_cache_[i].width = BadMetrics;
+        metrics_cache_[i].ascent = BadMetrics;
+        metrics_cache_[i].descent = BadMetrics;
  }
 #endif
 }
@@ -193,8 +198,13 @@ void GuiFontMetrics::fillCache(unsigned short val) const
 
 int GuiFontMetrics::width(char_type c) const
 {
+       // FIXME: The following cast is not a real conversion but it work
+       // for the ucs2 subrange of unicode. Instead of an assertion we should
+       // give the metrics of some special characters that indicates that
+       // its display is not supported.
+       BOOST_ASSERT(c < MaxCharType);
        unsigned short val = static_cast<unsigned short>(c);
-       if (metrics_cache_[val].width == -1000)
+       if (metrics_cache_[val].width == BadMetrics)
                metrics_cache_[val].width = metrics_.width(QChar(val));
 
        return metrics_cache_[val].width;
@@ -203,8 +213,13 @@ int GuiFontMetrics::width(char_type c) const
 
 int GuiFontMetrics::ascent(char_type c) const
 {
+       // FIXME: The following cast is not a real conversion but it work
+       // for the ucs2 subrange of unicode. Instead of an assertion we should
+       // give the metrics of some special characters that indicates that
+       // its display is not supported.
+       BOOST_ASSERT(c < MaxCharType);
        unsigned short val = static_cast<unsigned short>(c);
-       if (metrics_cache_[val].ascent == -1000)
+       if (metrics_cache_[val].ascent == BadMetrics)
                fillCache(val);
 
        return metrics_cache_[val].ascent;
@@ -213,8 +228,13 @@ int GuiFontMetrics::ascent(char_type c) const
 
 int GuiFontMetrics::descent(char_type c) const
 {
+       // FIXME: The following cast is not a real conversion but it work
+       // for the ucs2 subrange of unicode. Instead of an assertion we should
+       // give the metrics of some special characters that indicates that
+       // its display is not supported.
+       BOOST_ASSERT(c < MaxCharType);
        unsigned short val = static_cast<unsigned short>(c);
-       if (metrics_cache_[val].descent == -1000)
+       if (metrics_cache_[val].descent == BadMetrics)
                fillCache(val);
 
        return metrics_cache_[val].descent;
index d310741cc33c00facdd7ce40a4d7d611b93ea3f3..f3c87adc289d5c4e1336c9bb082fd5196062840b 100644 (file)
@@ -27,6 +27,8 @@
 namespace lyx {
 namespace frontend {
 
+size_t const MaxCharType = 65536;
+
 struct CharMetrics
 {
        int width;
@@ -88,7 +90,7 @@ private:
        * this turns out to be too much, we can switch to a \c QHash based
        * solution.
        **/
-       mutable CharMetrics metrics_cache_[65536];
+       mutable CharMetrics metrics_cache_[MaxCharType];
 #endif // USE_LYX_FONTCACHE
 };