]> git.lyx.org Git - features.git/commitdiff
Move some TextMetrics code around.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 25 Feb 2019 10:58:50 +0000 (11:58 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 12:39:58 +0000 (14:39 +0200)
No change intended.

src/TextMetrics.cpp
src/TextMetrics.h

index 89f8d92075d5cd99a89a43a37456a921015200f7..28d0d87b0eed8ee82146e1c7d1dc941f1117770f 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,20 @@ 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;
+}
+
+
 ParagraphMetrics & TextMetrics::parMetrics(pit_type pit, bool redo)
 {
        ParMetricsCache::iterator pmc_it = par_metrics_.find(pit);
@@ -165,6 +172,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)
 {
@@ -1204,35 +1247,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 +1580,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());
index 1a3ce0eccab838668d9255d04602ea5fe899ecf4..ba1371fd878409de693d55189e1fdd694faa9ded 100644 (file)
@@ -42,11 +42,13 @@ public:
        ///
        bool contains(pit_type pit) const;
        ///
-       ParagraphMetrics const & parMetrics(pit_type) const;
-       ///
        std::pair<pit_type, ParagraphMetrics const *> first() const;
        ///
        std::pair<pit_type, ParagraphMetrics const *> last() const;
+       /// is this row the last in the text?
+       bool isLastRow(Row const & row) const;
+       /// is this row the first in the text?
+       bool isFirstRow(Row const & row) const;
 
        ///
        Dimension const & dim() const { return dim_; }
@@ -54,15 +56,17 @@ public:
        Point const & origin() const { return origin_; }
 
 
-       /// compute text metrics.
-       bool metrics(MetricsInfo & mi, Dimension & dim, int min_width = 0,
-                    bool const expand_on_multipars = true);
-
+       ///
+       ParagraphMetrics const & parMetrics(pit_type) const;
        ///
        void newParMetricsDown();
        ///
        void newParMetricsUp();
 
+       /// compute text metrics.
+       bool metrics(MetricsInfo & mi, Dimension & dim, int min_width = 0,
+                    bool const expand_on_multipars = true);
+
        /// The "nodraw" drawing stage for one single paragraph: set the
        /// positions of the insets contained this paragraph in metrics
        /// cache. Related to BufferView::updatePosCache.
@@ -220,11 +224,6 @@ public:
        ///
        void deleteLineForward(Cursor & cur);
 
-       /// is this row the last in the text?
-       bool isLastRow(Row const & row) const;
-       /// is this row the first in the text?
-       bool isFirstRow(Row const & row) const;
-
        /// Returns an inset if inset was hit, or 0 if not.
        /// \warning This method is not recursive! It will return the
        /// outermost inset within this Text.