]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Fix compiler warning about unused string consts
[lyx.git] / src / TextMetrics.cpp
index f22716435780149ce0b684469753043ba8452c07..f4241181c295e15f440d78a48f05dbf6d7621d5f 100644 (file)
@@ -35,6 +35,7 @@
 #include "TextClass.h"
 #include "VSpace.h"
 
+#include "insets/InsetSeparator.h"
 #include "insets/InsetText.h"
 
 #include "mathed/MacroTable.h"
@@ -621,7 +622,7 @@ LyXAlignment TextMetrics::getAlign(Paragraph const & par, Row const & row) const
        if (Inset const * inset = par.getInset(row.pos())) {
                if (inset->rowFlags() & Display) {
                        if (inset->rowFlags() & AlignLeft)
-                               align = LYX_ALIGN_BLOCK;
+                               align = LYX_ALIGN_LEFT;
                        else if (inset->rowFlags() & AlignRight)
                                align = LYX_ALIGN_RIGHT;
                        else
@@ -916,10 +917,10 @@ Row TextMetrics::tokenizeParagraph(pit_type const pit) const
                        // ⤶ U+2936 ARROW POINTING DOWNWARDS THEN CURVING LEFTWARDS
                        // ¶ U+00B6 PILCROW SIGN
                        char_type const screen_char = (c == 0x2028) ? 0x2936 : 0x00B6;
-                       row.add(i, screen_char, *fi, par.lookupChange(i), i >= body_pos);
+                       row.add(i, screen_char, *fi, par.lookupChange(i));
                } else
                        // row elements before body are unbreakable
-                       row.add(i, c, *fi, par.lookupChange(i), i >= body_pos);
+                       row.add(i, c, *fi, par.lookupChange(i));
 
                // add inline completion width
                // draw logically behind the previous character
@@ -979,7 +980,7 @@ class flexible_const_iterator {
 public:
 
        //
-       flexible_const_iterator operator++() {
+       flexible_const_iterator operator++() {
                if (pile_.empty())
                        ++cit_;
                else
@@ -1059,7 +1060,7 @@ void cleanupRow(Row & row, bool at_end)
        if (!at_end && !row.flushed())
                row.back().rtrim();
        // boundary exists when there was no space at the end of row
-       row.right_boundary(!at_end && row.back().endpos == row.endpos());
+       row.end_boundary(!at_end && row.back().endpos == row.endpos());
        // make sure that the RTL elements are in reverse ordering
        row.reverseRTL();
 }
@@ -1131,7 +1132,9 @@ RowList TextMetrics::breakParagraph(Row const & bigrow) const
                rb.push_back(elt);
                rb.finalizeLast();
                if (rb.width() > width) {
-                       LATTEST(tail.empty());
+                       // Keep the tail for later; this ought to be rare, but play safe.
+                       if (!tail.empty())
+                               fcit.put(tail);
                        // if the row is too large, try to cut at last separator.
                        tail = rb.shortenIfNeeded(width, next_width);
                }
@@ -1202,7 +1205,10 @@ int TextMetrics::parTopSpacing(pit_type const pit) const
            && prevpar.getLabelWidthString() == par.getLabelWidthString()) {
                layoutasc = layout.itemsep * dh;
        } else if (pit != 0 && layout.topsep > 0)
-               layoutasc = layout.topsep * dh;
+               // combine the separation between different layouts (with same depth)
+               layoutasc = max(0.0,
+                       prevpar.getDepth() != par.getDepth() ? layout.topsep
+                       : layout.topsep - prevpar.layout().bottomsep) * dh;
 
        asc += int(layoutasc * 2 / (2 + pars[pit].getDepth()));
 
@@ -1365,7 +1371,7 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x,
                              || inset->lyxCode() == SEPARATOR_CODE))
                        pos = row.back().pos;
                else
-                       boundary = row.right_boundary();
+                       boundary = row.end_boundary();
        }
 
        x += xo - offset;
@@ -1787,11 +1793,13 @@ int TextMetrics::leftMargin(pit_type const pit, pos_type const pos) const
                }
        }
 
-       // This happens after sections or environments in standard classes.
-       // We have to check the previous layout at same depth.
+       // Check for reasons to remove indentation.
+       // First, at document level.
        if (buffer.params().paragraph_separation ==
                        BufferParams::ParagraphSkipSeparation)
                parindent.erase();
+       // This happens after sections or environments in standard classes.
+       // We have to check the previous layout at same depth.
        else if (pit > 0 && pars[pit - 1].getDepth() >= par.getDepth()) {
                pit_type prev = text_->depthHook(pit, par.getDepth());
                if (par.layout() == pars[prev].layout()) {
@@ -1801,6 +1809,15 @@ int TextMetrics::leftMargin(pit_type const pit, pos_type const pos) const
                } else if (pars[prev].layout().nextnoindent)
                        parindent.erase();
        }
+       // The previous paragraph may have ended with a separator inset.
+       if (pit > 0) {
+               Paragraph const & ppar = pars[pit - 1];
+               if (ppar.size() > 0) {
+                       auto * in = dynamic_cast<InsetSeparator const *>(ppar.getInset(ppar.size() - 1));
+                       if (in != nullptr && in->nextnoindent())
+                               parindent.erase();
+               }
+       }
 
        FontInfo const labelfont = text_->labelFont(par);
        FontMetrics const & lfm = theFontMetrics(labelfont);
@@ -1981,7 +1998,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                swap(pi.leftx, pi.rightx);
 
        BookmarksSection::BookmarkPosList bpl =
-               theSession().bookmarks().bookmarksInPar(bv_->buffer().fileName(), pm.par().id());
+               theSession().bookmarks().bookmarksInPar(bv_->buffer().fileName(), pm.id());
 
        for (size_t i = 0; i != nrows; ++i) {
 
@@ -2039,9 +2056,9 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                // already cleared because of a full repaint.
                if (!pi.full_repaint && row.changed()) {
                        LYXERR(Debug::PAINTING, "Clear rect@("
-                              << max(row_x, 0) << ", " << y - row.ascent() << ")="
+                              << x << ", " << y - row.ascent() << ")="
                               << width() << " x " << row.height());
-                       pi.pain.fillRectangle(row_x, y - row.ascent(),
+                       pi.pain.fillRectangle(x, y - row.ascent(),
                                              width(), row.height(), pi.background_color);
                }