]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
FindAdv: Amend b21c8b21: Expand the list for handled latin characters
[lyx.git] / src / TextMetrics.cpp
index 094b80d9c55123fa2bf30ab74c68ad4721319c6b..88ffa6f874bef6aa8f9badab41a9615235081d01 100644 (file)
@@ -130,13 +130,6 @@ bool TextMetrics::contains(pit_type pit) const
 }
 
 
-ParagraphMetrics const & TextMetrics::parMetrics(pit_type pit) const
-{
-       return const_cast<TextMetrics *>(this)->parMetrics(pit, true);
-}
-
-
-
 pair<pit_type, ParagraphMetrics const *> TextMetrics::first() const
 {
        ParMetricsCache::const_iterator it = par_metrics_.begin();
@@ -152,6 +145,30 @@ pair<pit_type, ParagraphMetrics const *> TextMetrics::last() const
 }
 
 
+bool TextMetrics::isLastRow(Row const & row) const
+{
+       ParagraphList const & pars = text_->paragraphs();
+       return row.endpos() >= pars[row.pit()].size()
+               && row.pit() + 1 == pit_type(pars.size());
+}
+
+
+bool TextMetrics::isFirstRow(Row const & row) const
+{
+       return row.pos() == 0 && row.pit() == 0;
+}
+
+
+void TextMetrics::setRowChanged(pit_type pit, pos_type pos)
+{
+       for (auto & pm_pair : par_metrics_)
+               if (pm_pair.first == pit)
+                       for (Row & row : pm_pair.second.rows())
+                               if (row.pos() == pos)
+                                       row.changed(true);
+}
+
+
 ParagraphMetrics & TextMetrics::parMetrics(pit_type pit, bool redo)
 {
        ParMetricsCache::iterator pmc_it = par_metrics_.find(pit);
@@ -165,6 +182,42 @@ ParagraphMetrics & TextMetrics::parMetrics(pit_type pit, bool redo)
 }
 
 
+ParagraphMetrics const & TextMetrics::parMetrics(pit_type pit) const
+{
+       return const_cast<TextMetrics *>(this)->parMetrics(pit, true);
+}
+
+
+void TextMetrics::newParMetricsDown()
+{
+       pair<pit_type, ParagraphMetrics> const & last = *par_metrics_.rbegin();
+       pit_type const pit = last.first + 1;
+       if (pit == int(text_->paragraphs().size()))
+               return;
+
+       // do it and update its position.
+       redoParagraph(pit);
+       par_metrics_[pit].setPosition(last.second.position()
+               + last.second.descent() + par_metrics_[pit].ascent());
+       updatePosCache(pit);
+}
+
+
+void TextMetrics::newParMetricsUp()
+{
+       pair<pit_type, ParagraphMetrics> const & first = *par_metrics_.begin();
+       if (first.first == 0)
+               return;
+
+       pit_type const pit = first.first - 1;
+       // do it and update its position.
+       redoParagraph(pit);
+       par_metrics_[pit].setPosition(first.second.position()
+               - first.second.ascent() - par_metrics_[pit].descent());
+       updatePosCache(pit);
+}
+
+
 bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width,
                          bool const expand_on_multipars)
 {
@@ -512,7 +565,7 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
                // original value was 20px, which is 0.2in at 100dpi
                int const margin = bv_->zoomedPixels(20);
                if (pit == 0) {
-                       pm.rows().front().dimension().asc += margin;
+                       pm.rows().front().dim().asc += margin;
                        /* coverity thinks that we should update pm.dim().asc
                         * below, but all the rows heights are actually counted as
                         * part of the paragraph metric descent see loop above).
@@ -522,16 +575,16 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
                }
                ParagraphList const & pars = text_->paragraphs();
                if (pit + 1 == pit_type(pars.size())) {
-                       pm.rows().back().dimension().des += margin;
+                       pm.rows().back().dim().des += margin;
                        pm.dim().des += margin;
                }
        }
 
        // The space above and below the paragraph.
        int const top = parTopSpacing(pit);
-       pm.rows().front().dimension().asc += top;
+       pm.rows().front().dim().asc += top;
        int const bottom = parBottomSpacing(pit);
-       pm.rows().back().dimension().des += bottom;
+       pm.rows().back().dim().des += bottom;
        pm.dim().des += top + bottom;
 
        pm.dim().asc += pm.rows()[0].ascent();
@@ -654,28 +707,28 @@ void TextMetrics::setRowAlignment(Row & row, int width) const
                        if (!row.setExtraWidth(w) && row.isRTL()) {
                                // Justification failed and the text is RTL: align to the right
                                row.left_margin += w;
-                               row.dimension().wid += w;
+                               row.dim().wid += w;
                        }
                        break;
                case LYX_ALIGN_LEFT:
                        // a displayed inset that is flushed
                        if (Inset const * inset = par.getInset(row.pos())) {
                                row.left_margin += inset->indent(*bv_);
-                               row.dimension().wid += inset->indent(*bv_);
+                               row.dim().wid += inset->indent(*bv_);
                        }
                        break;
                case LYX_ALIGN_RIGHT:
                        if (Inset const * inset = par.getInset(row.pos())) {
                                int const new_w = max(w - inset->indent(*bv_), 0);
                                row.left_margin += new_w;
-                               row.dimension().wid += new_w;
+                               row.dim().wid += new_w;
                        } else {
                                row.left_margin += w;
-                               row.dimension().wid += w;
+                               row.dim().wid += w;
                        }
                        break;
                case LYX_ALIGN_CENTER:
-                       row.dimension().wid += w / 2;
+                       row.dim().wid += w / 2;
                        row.left_margin += w / 2;
                        break;
                case LYX_ALIGN_NONE:
@@ -690,7 +743,7 @@ void TextMetrics::setRowAlignment(Row & row, int width) const
        // Case nh > 0. There are hfill separators.
        hfill = w / nh;
        hfill_rem = w % nh;
-       row.dimension().wid += w;
+       row.dim().wid += w;
        // Set size of hfill insets
        pos_type const endpos = row.endpos();
        pos_type body_pos = par.beginOfBody();
@@ -846,7 +899,7 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const
                swap(row.left_margin, row.right_margin);
        // Remember that the row width takes into account the left_margin
        // but not the right_margin.
-       row.dimension().wid = row.left_margin;
+       row.dim().wid = row.left_margin;
        // the width available for the row.
        int const width = max_width_ - row.right_margin;
 
@@ -1104,8 +1157,8 @@ void TextMetrics::setRowHeight(Row & row) const
 
        // Add some leading (split between before and after)
        int const leading = support::iround(extra_leading * (maxasc + maxdes));
-       row.dimension().asc = int((maxasc + leading - leading / 2) * spacing_val);
-       row.dimension().des = int((maxdes + leading / 2) * spacing_val);
+       row.dim().asc = int((maxasc + leading - leading / 2) * spacing_val);
+       row.dim().des = int((maxdes + leading / 2) * spacing_val);
 }
 
 
@@ -1204,35 +1257,6 @@ pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
 }
 
 
-void TextMetrics::newParMetricsDown()
-{
-       pair<pit_type, ParagraphMetrics> const & last = *par_metrics_.rbegin();
-       pit_type const pit = last.first + 1;
-       if (pit == int(text_->paragraphs().size()))
-               return;
-
-       // do it and update its position.
-       redoParagraph(pit);
-       par_metrics_[pit].setPosition(last.second.position()
-               + last.second.descent() + par_metrics_[pit].ascent());
-       updatePosCache(pit);
-}
-
-
-void TextMetrics::newParMetricsUp()
-{
-       pair<pit_type, ParagraphMetrics> const & first = *par_metrics_.begin();
-       if (first.first == 0)
-               return;
-
-       pit_type const pit = first.first - 1;
-       // do it and update its position.
-       redoParagraph(pit);
-       par_metrics_[pit].setPosition(first.second.position()
-               - first.second.ascent() - par_metrics_[pit].descent());
-       updatePosCache(pit);
-}
-
 // y is screen coordinate
 pit_type TextMetrics::getPitNearY(int y)
 {
@@ -1566,20 +1590,6 @@ void TextMetrics::deleteLineForward(Cursor & cur)
 }
 
 
-bool TextMetrics::isLastRow(Row const & row) const
-{
-       ParagraphList const & pars = text_->paragraphs();
-       return row.endpos() >= pars[row.pit()].size()
-               && row.pit() + 1 == pit_type(pars.size());
-}
-
-
-bool TextMetrics::isFirstRow(Row const & row) const
-{
-       return row.pos() == 0 && row.pit() == 0;
-}
-
-
 int TextMetrics::leftMargin(pit_type pit) const
 {
        return leftMargin(pit, text_->paragraphs()[pit].size());
@@ -1872,12 +1882,8 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                                row.change(row.end_margin_sel, sel_end.pit() > pit);
                }
 
-               // has row changed since last paint?
-               bool row_has_changed = row.changed()
-                       || bv_->hadHorizScrollOffset(text_, pit, row.pos());
-
                // Take this opportunity to spellcheck the row contents.
-               if (row_has_changed && pi.do_spellcheck && lyxrc.spellcheck_continuously) {
+               if (row.changed() && pi.do_spellcheck && lyxrc.spellcheck_continuously) {
                        text_->getPar(pit).spellCheck();
                }
 
@@ -1885,7 +1891,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
 
                // Don't paint the row if a full repaint has not been requested
                // and if it has not changed.
-               if (!pi.full_repaint && !row_has_changed) {
+               if (!pi.full_repaint && !row.changed()) {
                        // Paint only the insets if the text itself is
                        // unchanged.
                        rp.paintOnlyInsets();
@@ -1896,7 +1902,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
 
                // Clear background of this row if paragraph background was not
                // already cleared because of a full repaint.
-               if (!pi.full_repaint && row_has_changed) {
+               if (!pi.full_repaint && row.changed()) {
                        LYXERR(Debug::PAINTING, "Clear rect@("
                               << max(row_x, 0) << ", " << y - row.ascent() << ")="
                               << width() << " x " << row.height());
@@ -1915,13 +1921,13 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                // Instrumentation for testing row cache (see also
                // 12 lines lower):
                if (lyxerr.debugging(Debug::PAINTING)
-                   && (row.selection() || pi.full_repaint || row_has_changed)) {
+                   && (row.selection() || pi.full_repaint || row.changed())) {
                        string const foreword = text_->isMainText() ? "main text redraw "
                                : "inset text redraw: ";
                        LYXERR0(foreword << "pit=" << pit << " row=" << i
                                << (row.selection() ? " row_selection": "")
                                << (pi.full_repaint ? " full_repaint" : "")
-                               << (row_has_changed ? " row_has_changed" : ""));
+                               << (row.changed() ? " row.changed" : ""));
                }
 
                // Backup full_repaint status and force full repaint
@@ -1934,15 +1940,11 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                rp.paintDepthBar();
                if (row.needsChangeBar())
                        rp.paintChangeBar();
-               if (i == 0 && !row.isRTL())
+               if (i == 0)
                        rp.paintFirst();
-               if (i == nrows - 1 && row.isRTL())
+               if (i == nrows - 1)
                        rp.paintLast();
                rp.paintText();
-               if (i == nrows - 1 && !row.isRTL())
-                       rp.paintLast();
-               if (i == 0 && row.isRTL())
-                       rp.paintFirst();
                rp.paintTooLargeMarks(row_x + row.left_x() < 0,
                                      row_x + row.right_x() > bv_->workWidth());
                y += row.descent();
@@ -1987,7 +1989,7 @@ void TextMetrics::completionPosAndDim(Cursor const & cur, int & x, int & y,
        row.pos(wordStart.pos());
        row.endpos(bvcur.pos());
        setRowHeight(row);
-       dim = row.dimension();
+       dim = row.dim();
 
        // get position on screen of the word start and end
        //FIXME: Is it necessary to explicitly set this to false?