Move some TextMetrics code around.

No change intended.
This commit is contained in:
Jean-Marc Lasgouttes 2019-02-25 11:58:50 +01:00
parent 4de4263f93
commit ab02a907f0
2 changed files with 60 additions and 61 deletions

View 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 pair<pit_type, ParagraphMetrics const *> TextMetrics::first() const
{ {
ParMetricsCache::const_iterator it = par_metrics_.begin(); 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) ParagraphMetrics & TextMetrics::parMetrics(pit_type pit, bool redo)
{ {
ParMetricsCache::iterator pmc_it = par_metrics_.find(pit); 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 TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width,
bool const expand_on_multipars) 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 // y is screen coordinate
pit_type TextMetrics::getPitNearY(int y) 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 int TextMetrics::leftMargin(pit_type pit) const
{ {
return leftMargin(pit, text_->paragraphs()[pit].size()); return leftMargin(pit, text_->paragraphs()[pit].size());

View File

@ -42,11 +42,13 @@ public:
/// ///
bool contains(pit_type pit) const; 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 *> first() const;
/// ///
std::pair<pit_type, ParagraphMetrics const *> last() 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_; } Dimension const & dim() const { return dim_; }
@ -54,15 +56,17 @@ public:
Point const & origin() const { return origin_; } Point const & origin() const { return origin_; }
/// compute text metrics. ///
bool metrics(MetricsInfo & mi, Dimension & dim, int min_width = 0, ParagraphMetrics const & parMetrics(pit_type) const;
bool const expand_on_multipars = true);
/// ///
void newParMetricsDown(); void newParMetricsDown();
/// ///
void newParMetricsUp(); 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 /// The "nodraw" drawing stage for one single paragraph: set the
/// positions of the insets contained this paragraph in metrics /// positions of the insets contained this paragraph in metrics
/// cache. Related to BufferView::updatePosCache. /// cache. Related to BufferView::updatePosCache.
@ -220,11 +224,6 @@ public:
/// ///
void deleteLineForward(Cursor & cur); 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. /// Returns an inset if inset was hit, or 0 if not.
/// \warning This method is not recursive! It will return the /// \warning This method is not recursive! It will return the
/// outermost inset within this Text. /// outermost inset within this Text.