]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Streamlining CollapseStatus stuff
[lyx.git] / src / TextMetrics.cpp
index ba87f122d8a73fc652d51a5eb914f2599aaed25c..fec9111b685c531501e57f1be89df110a5f21c20 100644 (file)
@@ -245,12 +245,9 @@ bool TextMetrics::redoParagraph(pit_type const pit)
 
        // Make sure that if a par ends in newline, there is one more row
        // under it
-       // FIXME this is a dirty trick. Now the _same_ position in the
-       // paragraph occurs in _two_ different rows, and has two different
-       // display positions, leading to weird behaviour when moving up/down.
        if (z > 0 && par.isNewline(z - 1)) {
-               Row row(z - 1);
-               row.endpos(z - 1);
+               Row row(z);
+               row.endpos(z);
                setRowWidth(right_margin, pit, row);
                setHeightOfRow(pit, row);
                pm.rows().push_back(row);
@@ -332,7 +329,7 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
                // The test on par.size() is to catch zero-size pars, which
                // would trigger the assert in Paragraph::getInset().
                //inset = par.size() ? par.getInset(row.pos()) : 0;
-               if (!par.empty()
+               if (row.pos() < par.size()
                    && par.isInset(row.pos()))
                {
                    switch(par.getInset(row.pos())->display()) {
@@ -342,8 +339,11 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
                        case Inset::AlignCenter:
                                align = LYX_ALIGN_CENTER;
                                break;
-                       // other types unchanged (use align)
-                       }
+                        case Inset::Inline:
+                        case Inset::AlignRight:
+                                // unchanged (use align)
+                                break;
+                    }
                }
 
                switch (align) {
@@ -378,7 +378,6 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
                }
        }
 
-       text_->bidi.computeTables(par, buffer, row);
        if (is_rtl) {
                pos_type body_pos = par.beginOfBody();
                pos_type end = row.endpos();
@@ -667,9 +666,12 @@ void TextMetrics::setHeightOfRow(pit_type const pit,
        Font::FONT_SIZE maxsize =
                par.highestFontInRange(row.pos(), pos_end, size);
        if (maxsize > font.size()) {
-               font.setSize(maxsize);
-               maxasc  = max(maxasc,  fontmetrics.maxAscent());
-               maxdesc = max(maxdesc, fontmetrics.maxDescent());
+               // use standard paragraph font with the maximal size
+               Font maxfont = font;
+               maxfont.setSize(maxsize);
+               FontMetrics const & maxfontmetrics = theFontMetrics(maxfont);
+               maxasc  = max(maxasc,  maxfontmetrics.maxAscent());
+               maxdesc = max(maxdesc, maxfontmetrics.maxDescent());
        }
 
        // This is nicer with box insets:
@@ -790,7 +792,8 @@ void TextMetrics::setHeightOfRow(pit_type const pit,
                if (pit == 0 && row.pos() == 0)
                        maxasc += 20;
                if (pit + 1 == pit_type(pars.size()) &&
-                   row.endpos() == par.size())
+                   row.endpos() == par.size() &&
+                               !(row.endpos() > 0 && par.isNewline(row.endpos() - 1)))
                        maxdesc += 20;
        }
 
@@ -814,6 +817,8 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
        x -= xo;
        RowMetrics const r = computeRowMetrics(pit, row);
        Paragraph const & par = text_->getPar(pit);
+       Bidi bidi;
+       bidi.computeTables(par, buffer, row);
 
        pos_type vc = row.pos();
        pos_type end = row.endpos();
@@ -841,7 +846,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
                = theFontMetrics(text_->getLabelFont(buffer, par));
 
        while (vc < end && tmpx <= x) {
-               c = text_->bidi.vis2log(vc);
+               c = bidi.vis2log(vc);
                last_tmpx = tmpx;
                if (body_pos > 0 && c == body_pos - 1) {
                        // FIXME UNICODE
@@ -887,15 +892,15 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
             (!rtl && !left_side && vc == end  && x > tmpx + 5)))
                c = end;
        else if (vc == row.pos()) {
-               c = text_->bidi.vis2log(vc);
-               if (text_->bidi.level(c) % 2 == 1)
+               c = bidi.vis2log(vc);
+               if (bidi.level(c) % 2 == 1)
                        ++c;
        } else {
-               c = text_->bidi.vis2log(vc - 1);
-               bool const rtl = (text_->bidi.level(c) % 2 == 1);
+               c = bidi.vis2log(vc - 1);
+               bool const rtl = (bidi.level(c) % 2 == 1);
                if (left_side == rtl) {
                        ++c;
-                       boundary = text_->bidi.isBoundary(buffer, par, c);
+                       boundary = text_->isRTLBoundary(buffer, par, c);
                }
        }
 
@@ -908,7 +913,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
        // specially, so cursor up/down doesn't get stuck in an air gap -- MV
        // Newline inset, air gap below:
        if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
-               if (text_->bidi.level(end -1) % 2 == 0)
+               if (bidi.level(end -1) % 2 == 0)
                        tmpx -= text_->singleWidth(buffer, par, end - 1);
                else
                        tmpx += text_->singleWidth(buffer, par, end - 1);