]> git.lyx.org Git - features.git/commitdiff
Cleanup: BufferView should not need to be friend of TextMetrics
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 13 Jul 2020 22:08:07 +0000 (00:08 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 13 Jul 2020 22:08:07 +0000 (00:08 +0200)
It did access par_metrics_[] directly because there was no non-const
parMetrics().

This patch adds one and unfriends BufferView. The code is equivalent
since in all these cases, the metrics have just been computed with
redoParagraph().

src/BufferView.cpp
src/TextMetrics.cpp
src/TextMetrics.h

index 24d811c9bd93f77f735a1ee912484bbd393c885b..fe02be5019a3b8565fd98c7d1ce8ec8ecbc1f6c7 100644 (file)
@@ -2788,7 +2788,7 @@ bool BufferView::singleParUpdate()
        // (if this paragraph contains insets etc., rebreaking will
        // recursively descend)
        tm.redoParagraph(bottom_pit);
-       ParagraphMetrics & pm = tm.par_metrics_[bottom_pit];
+       ParagraphMetrics & pm = tm.parMetrics(bottom_pit);
        if (pm.height() != old_dim.height()) {
                // Paragraph height has changed so we cannot proceed to
                // the singlePar optimisation.
@@ -2845,7 +2845,7 @@ void BufferView::updateMetrics(Update::flags & update_flags)
 
        // Rebreak anchor paragraph.
        tm.redoParagraph(d->anchor_pit_);
-       ParagraphMetrics & anchor_pm = tm.par_metrics_[d->anchor_pit_];
+       ParagraphMetrics & anchor_pm = tm.parMetrics(d->anchor_pit_);
 
        // position anchor
        if (d->anchor_pit_ == 0) {
@@ -2872,7 +2872,7 @@ void BufferView::updateMetrics(Update::flags & update_flags)
        pit_type pit1 = d->anchor_pit_ - 1;
        for (; pit1 >= 0 && y1 >= 0; --pit1) {
                tm.redoParagraph(pit1);
-               ParagraphMetrics & pm = tm.par_metrics_[pit1];
+               ParagraphMetrics & pm = tm.parMetrics(pit1);
                y1 -= pm.descent();
                // Save the paragraph position in the cache.
                pm.setPosition(y1);
@@ -2886,7 +2886,7 @@ void BufferView::updateMetrics(Update::flags & update_flags)
        pit_type pit2 = d->anchor_pit_ + 1;
        for (; pit2 < npit && y2 <= height_; ++pit2) {
                tm.redoParagraph(pit2);
-               ParagraphMetrics & pm = tm.par_metrics_[pit2];
+               ParagraphMetrics & pm = tm.parMetrics(pit2);
                y2 += pm.ascent();
                // Save the paragraph position in the cache.
                pm.setPosition(y2);
index 95c9f83ac25a2f75d5e603c761d5d8d37099d691..87f0d33d1245268fa677df5bea2034db5775cc50 100644 (file)
@@ -185,6 +185,12 @@ ParagraphMetrics const & TextMetrics::parMetrics(pit_type pit) const
 }
 
 
+ParagraphMetrics & TextMetrics::parMetrics(pit_type pit)
+{
+       return parMetrics(pit, true);
+}
+
+
 void TextMetrics::newParMetricsDown()
 {
        pair<pit_type, ParagraphMetrics> const & last = *par_metrics_.rbegin();
index 006836fb0a186b0f88795de6a1095a942aaaaf20..353d28926cea72f7e6d1bd45753506d43c40f8b6 100644 (file)
@@ -60,9 +60,11 @@ public:
        ///
        Point const & origin() const { return origin_; }
 
-
        ///
        ParagraphMetrics const & parMetrics(pit_type) const;
+       ///
+       ParagraphMetrics & parMetrics(pit_type);
+
        ///
        void newParMetricsDown();
        ///
@@ -240,7 +242,6 @@ public:
                Dimension & dim) const;
 
 private:
-       friend class BufferView;
 
        /// The BufferView owner.
        BufferView * bv_;