commit ac759b4368e2a3477c8ef81ebf749a68280ef3d8
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Sun Mar 6 16:22:53 2016 +0100

    Rewrite setRowHeight using row information
    
    The initial values for maxasc and maxdes (renamed from maxdesc) is obtained 
as a maximum of max ascents/descents of all row elements.
    
    This allows to get rid of Paragraph::highestFontInRange and 
FontList::highestInRange.
    
    Some auxilliary variables declarations are also moved to where they are 
needed.

diff --git a/src/FontList.cpp b/src/FontList.cpp
index e5a86db..1bfab76 100644
--- a/src/FontList.cpp
+++ b/src/FontList.cpp
@@ -180,31 +180,6 @@ void FontList::set(pos_type pos, Font const & font)
 }
 
 
-FontSize FontList::highestInRange(pos_type startpos, pos_type endpos,
-       FontSize def_size) const
-{
-       if (list_.empty())
-               return def_size;
-
-       List::const_iterator end_it = fontIterator(endpos);
-       const_iterator const end = list_.end();
-       if (end_it != end)
-               ++end_it;
-
-       List::const_iterator cit = fontIterator(startpos);
-
-       FontSize maxsize = FONT_SIZE_TINY;
-       for (; cit != end_it; ++cit) {
-               FontSize size = cit->font().fontInfo().size();
-               if (size == FONT_SIZE_INHERIT)
-                       size = def_size;
-               if (size > maxsize && size <= FONT_SIZE_HUGER)
-                       maxsize = size;
-       }
-       return maxsize;
-}
-
-
 void FontList::validate(LaTeXFeatures & features) const
 {
        const_iterator fcit = list_.begin();
diff --git a/src/FontList.h b/src/FontList.h
index 9dfd527..6400f97 100644
--- a/src/FontList.h
+++ b/src/FontList.h
@@ -105,13 +105,6 @@ public:
        ///
        void decreasePosAfterPos(pos_type pos);
 
-       /// Returns the height of the highest font in range
-       FontSize highestInRange(
-               pos_type startpos,
-               pos_type endpos,
-               FontSize def_size
-               ) const;
-
        ///
        void validate(LaTeXFeatures & features) const;
 
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index d6106b3..0fd673e 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1837,14 +1837,6 @@ Font const Paragraph::getLayoutFont
 }
 
 
-/// Returns the height of the highest font in range
-FontSize Paragraph::highestFontInRange
-       (pos_type startpos, pos_type endpos, FontSize def_size) const
-{
-       return d->fontlist_.highestInRange(startpos, endpos, def_size);
-}
-
-
 char_type Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
 {
        char_type c = d->text_[pos];
diff --git a/src/Paragraph.h b/src/Paragraph.h
index 50516d7..b4b8067 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -357,9 +357,6 @@ public:
        char_type getUChar(BufferParams const &, pos_type pos) const;
        /// pos <= size() (there is a dummy font change at the end of each par)
        void setFont(pos_type pos, Font const & font);
-       /// Returns the height of the highest font in range
-       FontSize highestFontInRange(pos_type startpos,
-                                       pos_type endpos, FontSize def_size) 
const;
        ///
        void insert(pos_type pos, docstring const & str,
                    Font const & font, Change const & change);
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 2ce990b..2aad0cc 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -920,85 +920,53 @@ void TextMetrics::setRowHeight(Row & row, pit_type const 
pit,
                                    bool topBottomSpace) const
 {
        Paragraph const & par = text_->getPar(pit);
-       // get the maximum ascent and the maximum descent
-       double layoutasc = 0;
-       double layoutdesc = 0;
-       double const dh = defaultRowHeight();
-
-       // ok, let us initialize the maxasc and maxdesc value.
-       // Only the fontsize count. The other properties
-       // are taken from the layoutfont. Nicer on the screen :)
        Layout const & layout = par.layout();
-
-       // as max get the first character of this row then it can
-       // increase but not decrease the height. Just some point to
-       // start with so we don't have to do the assignment below too
-       // often.
-       Buffer const & buffer = bv_->buffer();
-       Font font = displayFont(pit, row.pos());
-       FontSize const tmpsize = font.fontInfo().size();
-       font.fontInfo() = text_->layoutFont(pit);
-       FontSize const size = font.fontInfo().size();
-       font.fontInfo().setSize(tmpsize);
-
-       FontInfo labelfont = text_->labelFont(par);
-
-       FontMetrics const & lfm = theFontMetrics(labelfont);
-       FontMetrics const & fm = theFontMetrics(font);
-
-       // these are minimum values
        double const spacing_val = layout.spacing.getValue()
                * text_->spacing(par);
-       //lyxerr << "spacing_val = " << spacing_val << endl;
-       int maxasc  = int(fm.maxAscent()  * spacing_val);
-       int maxdesc = int(fm.maxDescent() * spacing_val);
 
-       // insets may be taller
-       CoordCache::Insets const & insetCache = bv_->coordCache().getInsets();
+       // Initial value for ascent (useful if row is empty).
+       Font const font = displayFont(pit, row.pos());
+       FontMetrics const & fm = theFontMetrics(font);
+       int maxasc = int(fm.maxAscent() * spacing_val);
+       int maxdes = int(fm.maxDescent() * spacing_val);
+
+       // Find the ascent/descent of the row contents
        Row::const_iterator cit = row.begin();
        Row::const_iterator cend = row.end();
        for ( ; cit != cend; ++cit) {
                if (cit->inset) {
-                       Dimension const & dim = insetCache.dim(cit->inset);
-                       maxasc  = max(maxasc,  dim.ascent());
-                       maxdesc = max(maxdesc, dim.descent());
+                       maxasc = max(maxasc, cit->dim.ascent());
+                       maxdes = max(maxdes, cit->dim.descent());
+               } else {
+                       FontMetrics const & fm = theFontMetrics(cit->font);
+                       maxasc = max(maxasc, int(fm.maxAscent() * spacing_val));
+                       maxdes = max(maxdes, int(fm.maxDescent() * 
spacing_val));
                }
        }
 
-       // Check if any custom fonts are larger (Asger)
-       // This is not completely correct, but we can live with the small,
-       // cosmetic error for now.
-       int labeladdon = 0;
-
-       FontSize maxsize =
-               par.highestFontInRange(row.pos(), row.endpos(), size);
-       if (maxsize > font.fontInfo().size()) {
-               // use standard paragraph font with the maximal size
-               FontInfo maxfont = font.fontInfo();
-               maxfont.setSize(maxsize);
-               FontMetrics const & maxfontmetrics = theFontMetrics(maxfont);
-               maxasc  = max(maxasc,  maxfontmetrics.maxAscent());
-               maxdesc = max(maxdesc, maxfontmetrics.maxDescent());
-       }
-
-       // This is nicer with box insets:
+       // This is nicer with box insets
        ++maxasc;
-       ++maxdesc;
+       ++maxdes;
 
+       // Now use the layout information.
+       double layoutasc = 0;
+       double layoutdesc = 0;
+       int labeladdon = 0;
        ParagraphList const & pars = text_->paragraphs();
        Inset const & inset = text_->inset();
+       double const dh = defaultRowHeight();
 
        // is it a top line?
        if (row.pos() == 0 && topBottomSpace) {
-               BufferParams const & bufparams = buffer.params();
+               BufferParams const & bufparams = bv_->buffer().params();
                // some parskips VERY EASY IMPLEMENTATION
                if (bufparams.paragraph_separation == 
BufferParams::ParagraphSkipSeparation
                    && !inset.getLayout().parbreakIsNewline()
                    && !par.layout().parbreak_is_newline
                    && pit > 0
                    && ((layout.isParagraph() && par.getDepth() == 0)
-                       || (pars[pit - 1].layout().isParagraph()
-                           && pars[pit - 1].getDepth() == 0))) {
+                           || (pars[pit - 1].layout().isParagraph()
+                                   && pars[pit - 1].getDepth() == 0))) {
                        maxasc += bufparams.getDefSkip().inPixels(*bv_);
                }
 
@@ -1009,6 +977,8 @@ void TextMetrics::setRowHeight(Row & row, pit_type const 
pit,
                if (layout.labelIsAbove()
                    && (!layout.isParagraphGroup() || 
text_->isFirstInSequence(pit))
                    && !par.labelString().empty()) {
+                       FontInfo labelfont = text_->labelFont(par);
+                       FontMetrics const & lfm = theFontMetrics(labelfont);
                        labeladdon = int(
                                  lfm.maxHeight()
                                        * layout.spacing.getValue()
@@ -1071,8 +1041,8 @@ void TextMetrics::setRowHeight(Row & row, pit_type const 
pit,
        }
 
        // incalculate the layout spaces
-       maxasc  += int(layoutasc  * 2 / (2 + pars[pit].getDepth()));
-       maxdesc += int(layoutdesc * 2 / (2 + pars[pit].getDepth()));
+       maxasc += int(layoutasc  * 2 / (2 + pars[pit].getDepth()));
+       maxdes += int(layoutdesc * 2 / (2 + pars[pit].getDepth()));
 
        // FIXME: the correct way is to do the following is to move the
        // following code in another method specially tailored for the
@@ -1084,11 +1054,11 @@ void TextMetrics::setRowHeight(Row & row, pit_type 
const pit,
                if (pit + 1 == pit_type(pars.size()) &&
                    row.endpos() == par.size() &&
                                !(row.endpos() > 0 && 
par.isNewline(row.endpos() - 1)))
-                       maxdesc += 20;
+                       maxdes += 20;
        }
 
        row.dimension().asc = maxasc + labeladdon;
-       row.dimension().des = maxdesc;
+       row.dimension().des = maxdes;
 }
 
 

Reply via email to