Optimise rowBreakPoint and setHeightOfRow as well.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7378 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Asger Ottar Alstrup 2003-07-27 11:16:25 +00:00
parent 330fdeda26
commit 60896529f0
2 changed files with 77 additions and 23 deletions

View File

@ -6,6 +6,8 @@
* text.C (fill): Optimise algorithm to exploit that we can reuse * text.C (fill): Optimise algorithm to exploit that we can reuse
the LyXFont for many characters. the LyXFont for many characters.
(setHeightOfRow): Same thing.
(rowBreakPoint): Same thing.
2003-07-26 Asger Alstrup <alstrup@local> 2003-07-26 Asger Alstrup <alstrup@local>

View File

@ -817,6 +817,11 @@ pos_type LyXText::rowBreakPoint(Row const & row) const
bool fullrow = false; bool fullrow = false;
pos_type i = pos; pos_type i = pos;
// We re-use the font resolution for the entire font span when possible
LyXFont font = getFont(bv()->buffer(), pit, i);
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
for (; i < last; ++i) { for (; i < last; ++i) {
if (pit->isNewline(i)) { if (pit->isNewline(i)) {
point = i; point = i;
@ -838,7 +843,27 @@ pos_type LyXText::rowBreakPoint(Row const & row) const
thiswidth = left_margin - x; thiswidth = left_margin - x;
thiswidth += singleWidth(pit, i, c); thiswidth += singleWidth(pit, i, c);
} else { } else {
thiswidth = singleWidth(pit, i, c); // Manual inlined optimised version of common case of "thiswidth = singleWidth(pit, i, c);"
if (IsPrintable(c)) {
if (pos > endPosOfFontSpan) {
// We need to get the next font
font = getFont(bv()->buffer(), pit, i);
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
}
if (! font.language()->RightToLeft()) {
thiswidth = font_metrics::width(c, font);
} else {
// Fall-back to normal case
thiswidth = singleWidth(pit, i, c);
// And flush font cache
endPosOfFontSpan = 0;
}
} else {
// Fall-back to normal case
thiswidth = singleWidth(pit, i, c);
// And flush font cache
endPosOfFontSpan = 0;
}
} }
x += thiswidth; x += thiswidth;
@ -1098,32 +1123,59 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
int maxwidth = 0; int maxwidth = 0;
if (!pit->empty()) { if (!pit->empty()) {
// We re-use the font resolution for the entire font span when possible
LyXFont font = getFont(bv()->buffer(), pit, rit->pos());
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(rit->pos());
// Optimisation
Paragraph const & par = *pit;
// Check if any insets are larger // Check if any insets are larger
for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) { for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
if (pit->isInset(pos)) { // Manual inlined optimised version of common case of "maxwidth += singleWidth(pit, pos);"
LyXFont const & tmpfont = getFont(bv()->buffer(), pit, pos); char const c = par.getChar(pos);
InsetOld * tmpinset = pit->getInset(pos);
if (tmpinset) { if (IsPrintable(c)) {
#if 1 // this is needed for deep update on initialitation if (pos > endPosOfFontSpan) {
#warning inset->update FIXME // We need to get the next font
//tmpinset->update(bv()); font = getFont(bv()->buffer(), pit, pos);
Dimension dim; endPosOfFontSpan = par.getEndPosOfFontSpan(pos);
MetricsInfo mi(bv(), tmpfont, workWidth()); }
tmpinset->metrics(mi, dim); if (! font.language()->RightToLeft()) {
maxwidth += dim.wid; maxwidth += font_metrics::width(c, font);
maxasc = max(maxasc, dim.asc); } else {
maxdesc = max(maxdesc, dim.des); // Fall-back to normal case
#else maxwidth += singleWidth(pit, pos, c);
maxwidth += tmpinset->width(); // And flush font cache
maxasc = max(maxasc, tmpinset->ascent()); endPosOfFontSpan = 0;
maxdesc = max(maxdesc, tmpinset->descent());
#endif
} }
} else { } else {
// Manual inlined optimised version of common case of "maxwidth += singleWidth(pit, pos);" // Special handling of insets - are any larger?
char const c = pit->getChar(pos); if (par.isInset(pos)) {
maxwidth += singleWidth(pit, pos, c); LyXFont const tmpfont = getFont(bv()->buffer(), pit, pos);
InsetOld const * tmpinset = par.getInset(pos);
if (tmpinset) {
#if 1 // this is needed for deep update on initialitation
#warning inset->update FIXME
//tmpinset->update(bv());
Dimension dim;
MetricsInfo mi(bv(), tmpfont, workWidth());
tmpinset->metrics(mi, dim);
maxwidth += dim.wid;
maxasc = max(maxasc, dim.asc);
maxdesc = max(maxdesc, dim.des);
#else
maxwidth += tmpinset->width();
maxasc = max(maxasc, tmpinset->ascent());
maxdesc = max(maxdesc, tmpinset->descent());
#endif
}
} else {
// Fall-back to normal case
maxwidth += singleWidth(pit, pos, c);
// And flush font cache
endPosOfFontSpan = 0;
}
} }
} }
} }