]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
cosmetic fix
[lyx.git] / src / text.C
index 691fe23d4ff8fa3ebb102ff77e76ac0f908045ef..179c6db01de1f03d008b8ebdd2ae716d18e63b32 100644 (file)
@@ -148,7 +148,7 @@ int LyXText::workWidth() const
 }
 
 
-int LyXText::workWidth(Inset const * inset) const
+int LyXText::workWidth(InsetOld const * inset) const
 {
        ParagraphList::iterator par = std::find(ownerParagraphs().begin(),
                                                ownerParagraphs().end(),
@@ -284,14 +284,14 @@ int LyXText::singleWidth(ParagraphList::iterator pit,
        if (pos >= pit->size())
                return 0;
 
-       LyXFont const font = getFont(bv()->buffer(), pit, pos);
+       LyXFont const font = getFont(bv()->buffer(), pit, pos);
 
        // The most common case is handled first (Asger)
        if (IsPrintable(c)) {
                if (font.language()->RightToLeft()) {
-                       if (font.language()->lang() == "arabic" &&
-                           (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
-                            lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
+                       if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
+                            lyxrc.font_norm_type == LyXRC::ISO_10646_1)
+                           && font.language()->lang() == "arabic") {
                                if (Encodings::IsComposeChar_arabic(c))
                                        return 0;
                                else
@@ -301,13 +301,12 @@ int LyXText::singleWidth(ParagraphList::iterator pit,
                                return 0;
                }
                return font_metrics::width(c, font);
-
        }
 
        if (c == Paragraph::META_INSET) {
-               Inset * tmpinset = pit->getInset(pos);
+               InsetOld * tmpinset = pit->getInset(pos);
                if (tmpinset) {
-                       if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
+                       if (tmpinset->lyxCode() == InsetOld::HFILL_CODE) {
                                // Because of the representation as vertical lines
                                return 3;
                        }
@@ -379,9 +378,9 @@ void LyXText::computeBidiTables(Buffer const * buf,
 
        ParagraphList::iterator row_par = row->par();
 
-       Inset * inset = row_par->inInset();
+       InsetOld * inset = row_par->inInset();
        if (inset && inset->owner() &&
-           inset->owner()->lyxCode() == Inset::ERT_CODE) {
+           inset->owner()->lyxCode() == InsetOld::ERT_CODE) {
                bidi_start = -1;
                return;
        }
@@ -534,7 +533,7 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
 
 int LyXText::leftMargin(Row const & row) const
 {
-       Inset * ins;
+       InsetOld * ins;
 
        if (row.pos() < row.par()->size())
                if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
@@ -709,8 +708,8 @@ int LyXText::leftMargin(Row const & row) const
                    && !row.par()->params().noindent()
                        // in tabulars and ert paragraphs are never indented!
                        && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
-                               (row.par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
-                                row.par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
+                               (row.par()->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE &&
+                                row.par()->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
                    && (row.par()->layout() != tclass.defaultLayout() ||
                        bv()->buffer()->params.paragraph_separation ==
                        BufferParams::PARSEP_INDENT)) {
@@ -728,7 +727,7 @@ int LyXText::leftMargin(Row const & row) const
 
 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
 {
-       Inset * ins;
+       InsetOld * ins;
 
        if (row.pos() < row.par()->size())
                if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
@@ -818,6 +817,11 @@ pos_type LyXText::rowBreakPoint(Row const & row) const
        bool fullrow = false;
 
        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) {
                if (pit->isNewline(i)) {
                        point = i;
@@ -839,13 +843,33 @@ pos_type LyXText::rowBreakPoint(Row const & row) const
                                thiswidth = left_margin - x;
                        thiswidth += singleWidth(pit, i, c);
                } 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;
                chunkwidth += thiswidth;
 
-               Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
+               InsetOld * in = pit->isInset(i) ? pit->getInset(i) : 0;
                fullrow = (in && (in->display() || in->needFullRow()));
 
                // break before a character that will fall off
@@ -935,17 +959,45 @@ int LyXText::fill(RowList::iterator row, int paper_width) const
        pos_type const body_pos = pit->beginningOfBody();
        pos_type i = row->pos();
 
-       while (i <= last) {
-               if (body_pos > 0 && i == body_pos) {
-                       w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
-                       if (pit->isLineSeparator(i - 1))
-                               w -= singleWidth(pit, i - 1);
-                       int left_margin = labelEnd(*row);
-                       if (w < left_margin)
-                               w = left_margin;
+       if (! pit->empty() && i <= last) {
+               // We re-use the font resolution for the entire span when possible
+               LyXFont font = getFont(bv()->buffer(), pit, i);
+               lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
+               while (i <= last) {
+                       if (body_pos > 0 && i == body_pos) {
+                               w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
+                               if (pit->isLineSeparator(i - 1))
+                                       w -= singleWidth(pit, i - 1);
+                               int left_margin = labelEnd(*row);
+                               if (w < left_margin)
+                                       w = left_margin;
+                       }
+                       { // Manual inlined an optimised version of the common case of "w += singleWidth(pit, i);"
+                               char const c = pit->getChar(i);
+
+                               if (IsPrintable(c)) {
+                                       if (i > endPosOfFontSpan) {
+                                               // We need to get the next font
+                                               font = getFont(bv()->buffer(), pit, i);
+                                               endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
+                                       }
+                                       if (! font.language()->RightToLeft()) {
+                                               w += font_metrics::width(c, font);
+                                       } else {
+                                               // Fall-back to the normal case
+                                               w += singleWidth(pit, i, c);
+                                               // And flush font cache
+                                               endPosOfFontSpan = 0;
+                                       }
+                               } else {
+                                       // Fall-back to the normal case
+                                       w += singleWidth(pit, i, c);
+                                       // And flush font cache
+                                       endPosOfFontSpan = 0;
+                               }
+                       }
+                       ++i;
                }
-               w += singleWidth(pit, i);
-               ++i;
        }
        if (body_pos > 0 && body_pos > last) {
                w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
@@ -1028,8 +1080,6 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
        float layoutasc = 0;
        float layoutdesc = 0;
        float tmptop = 0;
-       LyXFont tmpfont;
-       Inset * tmpinset = 0;
 
        // ok, let us initialize the maxasc and maxdesc value.
        // This depends in LaTeX of the font of the last character
@@ -1073,29 +1123,59 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
        int maxwidth = 0;
 
        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
                for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
-                       if (pit->isInset(pos)) {
-                               tmpfont = getFont(bv()->buffer(), pit, pos);
-                               tmpinset = pit->getInset(pos);
-                               if (tmpinset) {
+                       // Manual inlined optimised version of common case of "maxwidth += singleWidth(pit, pos);"
+                       char const c = par.getChar(pos);
+
+                       if (IsPrintable(c)) {
+                               if (pos > endPosOfFontSpan) {
+                                       // We need to get the next font
+                                       font = getFont(bv()->buffer(), pit, pos);
+                                       endPosOfFontSpan = par.getEndPosOfFontSpan(pos);
+                               }
+                               if (! font.language()->RightToLeft()) {
+                                       maxwidth += font_metrics::width(c, font);
+                               } else {
+                                       // Fall-back to normal case
+                                       maxwidth += singleWidth(pit, pos, c);
+                                       // And flush font cache
+                                       endPosOfFontSpan = 0;
+                               }
+                       } else {
+                               // Special handling of insets - are any larger?
+                               if (par.isInset(pos)) {
+                                       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);
+                                               //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());
+                                               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;
                                }
-                       } else {
-                               maxwidth += singleWidth(pit, pos);
                        }
                }
        }
@@ -1674,7 +1754,7 @@ void LyXText::insertChar(char c)
        // the display inset stuff
        if (cursorRow()->pos() < cursorRow()->par()->size()
            && cursorRow()->par()->isInset(cursorRow()->pos())) {
-               Inset * inset = cursorRow()->par()->getInset(cursorRow()->pos());
+               InsetOld * inset = cursorRow()->par()->getInset(cursorRow()->pos());
                if (inset && (inset->display() || inset->needFullRow())) {
                        // force a new break
                        cursorRow()->fill(-1); // to force a new break
@@ -1885,17 +1965,17 @@ void LyXText::prepareToPrint(RowList::iterator rit, int & x,
                }
 
                // center displayed insets
-               Inset * inset = 0;
+               InsetOld * inset = 0;
                if (rit->pos() < pit->size()
                    && pit->isInset(rit->pos())
                    && (inset = pit->getInset(rit->pos()))
                    && (inset->display())) // || (inset->scroll() < 0)))
-                   align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
+                   align = (inset->lyxCode() == InsetOld::MATHMACRO_CODE)
                        ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
                // ERT insets should always be LEFT ALIGNED on screen
                inset = pit->inInset();
                if (inset && inset->owner() &&
-                       inset->owner()->lyxCode() == Inset::ERT_CODE)
+                       inset->owner()->lyxCode() == InsetOld::ERT_CODE)
                {
                        align = LYX_ALIGN_LEFT;
                }