X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FTextMetrics.cpp;h=88ea65541f044b596ff33fc63aa44020f4b7fd42;hb=89d9334e03c311a4a7585f40ad81880304d174d4;hp=5b16d36ef51ad279e90c3ddba405162085036c1d;hpb=ff7cdf1b74f5c17a966af24dc70d49fc162f007e;p=lyx.git diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 5b16d36ef5..88ea65541f 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -127,15 +127,18 @@ bool TextMetrics::contains(pit_type pit) const } -pit_type TextMetrics::firstPit() const +pair TextMetrics::first() const { - return par_metrics_.begin()->first; + ParMetricsCache::const_iterator it = par_metrics_.begin(); + return make_pair(it->first, &it->second); } -pit_type TextMetrics::lastPit() const +pair TextMetrics::last() const { - return par_metrics_.rbegin()->first; + LBUFERR(!par_metrics_.empty()); + ParMetricsCache::const_reverse_iterator it = par_metrics_.rbegin(); + return make_pair(it->first, &it->second); } @@ -182,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 const & last = *par_metrics_.rbegin(); @@ -281,20 +290,6 @@ int TextMetrics::rightMargin(pit_type const pit) const } -int TextMetrics::topPosition() const -{ - ParagraphMetrics const & firstpm = par_metrics_.begin()->second; - return firstpm.position() - firstpm.ascent(); -} - - -int TextMetrics::bottomPosition() const -{ - ParagraphMetrics const & lastpm = par_metrics_.rbegin()->second; - return lastpm.position() + lastpm.descent(); -} - - void TextMetrics::applyOuterFont(Font & font) const { FontInfo lf(font_.fontInfo()); @@ -568,21 +563,6 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows) if (row_index < pm.rows().size()) pm.rows().resize(row_index); - // FIXME: It might be better to move this in another method - // specially tailored for the main text. - // Top and bottom margin of the document (only at top-level) - if (text_->isMainText()) { - if (pit == 0) { - pm.rows().front().top_padding += bv_->topMargin(); - pm.dim().asc += bv_->topMargin(); - } - ParagraphList const & pars = text_->paragraphs(); - if (pit + 1 == pit_type(pars.size())) { - pm.rows().back().bottom_padding += bv_->bottomMargin(); - pm.dim().des += bv_->bottomMargin(); - } - } - // The space above and below the paragraph. int const top = parTopSpacing(pit); pm.rows().front().dim().asc += top; @@ -593,6 +573,18 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows) pm.dim().asc += pm.rows()[0].ascent(); pm.dim().des -= pm.rows()[0].ascent(); + // Top and bottom margin of the document (only at top-level) + // FIXME: It might be better to move this in another method + // specially tailored for the main text. + if (text_->isMainText()) { + if (pit == 0) + pm.dim().asc += bv_->topMargin(); + ParagraphList const & pars = text_->paragraphs(); + if (pit + 1 == pit_type(pars.size())) { + pm.dim().des += bv_->bottomMargin(); + } + } + changed |= old_dim.height() != pm.dim().height(); return changed; @@ -1153,6 +1145,14 @@ void TextMetrics::setRowHeight(Row & row) const int maxasc = int(fm.maxAscent() * spacing_val); int maxdes = int(fm.maxDescent() * spacing_val); + // Take label string into account (useful if labelfont is large) + if (row.pos() == 0 && layout.labelIsInline()) { + FontInfo const labelfont = text_->labelFont(par); + FontMetrics const & lfm = theFontMetrics(labelfont); + maxasc = max(maxasc, int(lfm.maxAscent() * spacing_val)); + maxdes = max(maxdes, int(lfm.maxDescent() * spacing_val)); + } + // Find the ascent/descent of the row contents for (Row::Element const & e : row) { if (e.inset) { @@ -1337,7 +1337,7 @@ Row const & TextMetrics::getPitAndRowNearY(int & y, pit_type & pit, { ParagraphMetrics const & pm = par_metrics_[pit]; - int yy = pm.position() - pm.ascent(); + int yy = pm.position() - pm.rows().front().ascent(); LBUFERR(!pm.rows().empty()); RowList::const_iterator rit = pm.rows().begin(); RowList::const_iterator rlast = pm.rows().end();