- // 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 == BadMetrics)
- metrics_cache_[val].width = metrics_.width(QChar(val));
+ if (!width_cache_.contains(c)) {
+ width_cache_.insert(c, metrics_.width(ucs4_to_qchar(c)));
+ }