John Levon <[EMAIL PROTECTED]> writes:
What is the <list> used for? | +typedef pair<LyXFont, int> MetricPair; | +typedef vector<MetricPair> MetricList; | +typedef map<Uchar, MetricList> CharMetrics; | +CharMetrics char_metrics; | + | +int singlewidth(Uchar val, LyXFont const & f) | +{ | + CharMetrics::iterator it(char_metrics.find(val)); | + if (it != char_metrics.end()) { | + MetricList::const_iterator lit(it->second.begin()); | + MetricList::const_iterator lend(it->second.end()); | + for (; lit < lend; ++lit) { Why "lit < lend"? The idom is "lit != lend". | + if (lit->first == f) | + return lit->second; | + } | + | + int const w = metrics(f).width(QChar(val)); | + MetricList & list(it->second); | + list.push_back(make_pair(f, w)); | + return w; | + } | + | + int const w = metrics(f).width(QChar(val)); | + MetricList list; | + list.push_back(make_pair(f, w)); | + char_metrics[val] = list; | + return w; | +} I have a feeling that the cache is a bit more complex than it needs to be, but I cannot quite put my finger on it... | + | +int width(char const * s, size_t ls, LyXFont const & f) | +{ | + if (f.realShape() == LyXFont::SMALLCAPS_SHAPE) { | + return smallcapswidth(s, ls, f); | + } | + | + Encoding const * encoding(fontencoding(f)); | + | + if (ls == 1) { | + return singlewidth(encoding->ucs(s[0]), f); | + } | + | + QString str; | +#if QT_VERSION >= 300 | + str.setLength(ls); | + for (size_t i = 0; i < ls; ++i) | + str[i] = QChar(encoding->ucs(s[i])); | +#else | + for (size_t i = 0; i < ls; ++i) | + str += QChar(encoding->ucs(s[i])); | +#endif | + | + return metrics(f).width(str, ls); How often is metrics for whole strings wanted? -- Lgb