TextMetrics::TextMetrics(BufferView * bv, Text * text)
- : bv_(bv), text_(text)
-{
- LBUFERR(bv_);
- max_width_ = bv_->workWidth();
- dim_.wid = max_width_;
- dim_.asc = 10;
- dim_.des = 10;
-}
+ : bv_(bv), text_(text), dim_(bv_->workWidth(), 10, 10),
+ max_width_(dim_.wid), tight_(false)
+{}
bool TextMetrics::contains(pit_type pit) const
}
-bool TextMetrics::metrics(MetricsInfo const & mi, Dimension & dim, int min_width,
- bool const expand_on_multipars)
+bool TextMetrics::metrics(MetricsInfo const & mi, Dimension & dim, int min_width)
{
LBUFERR(mi.base.textwidth > 0);
max_width_ = mi.base.textwidth;
+ tight_ = mi.tight_insets;
// backup old dimension.
Dimension const old_dim = dim_;
// reset dimension.
dim_ = Dimension();
dim_.wid = min_width;
pit_type const npar = text_->paragraphs().size();
- if (npar > 1 && expand_on_multipars)
+ if (npar > 1 && !tight_)
// If there is more than one row, expand the text to
// the full allowable width.
dim_.wid = max_width_;
// environment? I think the answer is: when paragraphs are merged;
// when layout is set; when material is pasted.
if (par.brokenBiblio()) {
- Cursor & cur = const_cast<Cursor &>(bv_->cursor());
+ Cursor & cur = bv_->cursor();
// In some cases, we do not know how to record undo
if (&cur.inset() == &text_->inset())
cur.recordUndo(pit, pit);
// substracted to the available width. The logic here is
// almost the same as in breakRow, remember keep them in sync.
int eop = 0;
- if (lyxrc.paragraph_markers && e.pos + 1 == par.size()
- && size_type(pit + 1) < text_->paragraphs().size()) {
+ if (e.pos + 1 == par.size()
+ && (lyxrc.paragraph_markers || par.lookupChange(par.size()).changed())
+ && size_type(pit + 1) < text_->paragraphs().size()) {
Font f(text_->layoutFont(pit));
// ¶ U+00B6 PILCROW SIGN
eop = theFontMetrics(f).width(char_type(0x00B6));
Font const & font = e.inset->inheritFont() ?
displayFont(pit, e.pos) : bufferfont;
MacroContext mc(&buffer, parPos);
- MetricsInfo mi(bv_, font.fontInfo(), w, mc, e.pos == 0);
+ MetricsInfo mi(bv_, font.fontInfo(), w, mc, e.pos == 0, tight_);
e.inset->metrics(mi, dim);
if (!insetCache.has(e.inset) || insetCache.dim(e.inset) != dim) {
insetCache.add(e.inset, dim);
setRowHeight(row);
row.changed(true);
if ((row_index || row.endpos() < par.size() || row.right_boundary())
- && par.inInset().lyxCode() != CELL_CODE) {
+ && !tight_) {
/* If there is more than one row or the row has been
* broken by a display inset or a newline, expand the text
* to the full allowable width. This setting here is
* needed for the setRowAlignment() below.
- * We do nothing when inside a table cell.
+ * We do nothing when tight insets are requested.
*/
if (dim_.wid < max_width_)
dim_.wid = max_width_;
}
// The space above and below the paragraph.
- int const top = parTopSpacing(pit);
- pm.rows().front().dim().asc += top;
- int const bottom = parBottomSpacing(pit);
- pm.rows().back().dim().des += bottom;
- pm.dim().des += top + bottom;
-
- pm.dim().asc += pm.rows()[0].ascent();
- pm.dim().des -= pm.rows()[0].ascent();
+ int top = parTopSpacing(pit);
+ int bottom = parBottomSpacing(pit);
// 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();
+ top += bv_->topMargin();
+ if (pit + 1 == pit_type(text_->paragraphs().size())) {
+ bottom += bv_->bottomMargin();
}
}
+ // Add the top/bottom space to rows and paragraph metrics
+ pm.rows().front().dim().asc += top;
+ pm.rows().back().dim().des += bottom;
+ pm.dim().des += top + bottom;
+
+ // Move the pm ascent to be the same as the first row ascent
+ pm.dim().asc += pm.rows().front().ascent();
+ pm.dim().des -= pm.rows().front().ascent();
+
changed |= old_dim.height() != pm.dim().height();
return changed;
// We don't have to look at the alignment if the row is already
// larger then the permitted width as then we force the
// LEFT_ALIGN'edness!
- if (int(row.width()) >= max_width_)
+ if (row.width() >= max_width_)
return;
if (nh == 0) {
// The real stopping condition is a few lines below.
while (true) {
// Firstly, check whether there is a bookmark here.
- for (auto const & bp_p : bpl)
- if (bp_p.second == i) {
- Font f = *fi;
- f.fontInfo().setColor(Color_bookmark);
- // ❶ U+2776 DINGBAT NEGATIVE CIRCLED DIGIT ONE
- char_type const ch = 0x2775 + bp_p.first;
- row.addVirtual(i, docstring(1, ch), f, Change());
- }
+ if (lyxrc.bookmarks_visibility == LyXRC::BMK_INLINE)
+ for (auto const & bp_p : bpl)
+ if (bp_p.second == i) {
+ Font f = *fi;
+ f.fontInfo().setColor(Color_bookmark);
+ // ❶ U+2776 DINGBAT NEGATIVE CIRCLED DIGIT ONE
+ char_type const ch = 0x2775 + bp_p.first;
+ row.addVirtual(i, docstring(1, ch), f, Change());
+ }
// The stopping condition is here so that the display of a
// bookmark can take place at paragraph start too.
row.dim().asc = maxasc;
row.dim().des = maxdes;
+
+ // This is useful for selections
+ row.contents_dim() = row.dim();
}
ParagraphMetrics const & pm = it->second;
- if (y < it->second.position() - int(pm.ascent())) {
+ if (y < it->second.position() - pm.ascent()) {
// We are looking for a position that is before the first paragraph in
// the cache (which is in priciple off-screen, that is before the
// visible part.
ParagraphMetrics const & pm_last = par_metrics_[last->first];
- if (y >= last->second.position() + int(pm_last.descent())) {
+ if (y >= last->second.position() + pm_last.descent()) {
// We are looking for a position that is after the last paragraph in
// the cache (which is in priciple off-screen), that is before the
// visible part.
ParagraphMetrics const & pm2 = par_metrics_[it->first];
- if (it->first >= pit && int(it->second.position()) - int(pm2.ascent()) <= y) {
+ if (it->first >= pit && it->second.position() - pm2.ascent() <= y) {
pit = it->first;
yy = it->second.position();
}
{
ParagraphMetrics const & pm = par_metrics_[pit];
- int yy = pm.position() - pm.rows().front().ascent();
+ int yy = pm.position() - pm.ascent();
LBUFERR(!pm.rows().empty());
RowList::const_iterator rit = pm.rows().begin();
RowList::const_iterator rlast = pm.rows().end();
--rit;
y = yy;
}
- } else if (up && yy < y) {
+ } else if (up && yy != y) {
if (rit != rlast) {
y = yy + rit->height();
++rit;
LBUFERR(pm.rows().size());
for (; r < int(pm.rows().size()) - 1; ++r) {
Row const & row = pm.rows()[r];
- if (int(yy + row.height()) > y)
+ if (yy + row.height() > y)
break;
yy += row.height();
}
int TextMetrics::leftMargin(pit_type pit) const
{
- // the + 1 is useful when the paragraph is empty
- return leftMargin(pit, text_->paragraphs()[pit].size() + 1);
+ // FIXME: what is the semantics? It depends on whether the
+ // paragraph is empty!
+ return leftMargin(pit, text_->paragraphs()[pit].size());
}
Paragraph const & par = pars[pit];
LASSERT(pos >= 0, return 0);
// We do not really care whether pos > par.size(), since we do not
- // access the data. It can be actially useful, when querying the
+ // access the data. It can be actually useful, when querying the
// margin without indentation (see leftMargin(pit_type).
Buffer const & buffer = bv_->buffer();
if (text_->isRTL(pit))
swap(pi.leftx, pi.rightx);
+ BookmarksSection::BookmarkPosList bpl =
+ theSession().bookmarks().bookmarksInPar(bv_->buffer().fileName(), pm.par().id());
+
for (size_t i = 0; i != nrows; ++i) {
Row const & row = pm.rows()[i];
// Paint only the insets if the text itself is
// unchanged.
rp.paintOnlyInsets();
+ rp.paintTooLargeMarks(
+ row_x + row.left_x() < bv_->leftMargin(),
+ row_x + row.right_x() > bv_->workWidth() - bv_->rightMargin());
row.changed(false);
y += row.descent();
continue;
if (i == nrows - 1)
rp.paintLast();
rp.paintText();
- rp.paintTooLargeMarks(row_x + row.left_x() < 0,
- row_x + row.right_x() > bv_->workWidth());
+ rp.paintTooLargeMarks(
+ row_x + row.left_x() < bv_->leftMargin(),
+ row_x + row.right_x() > bv_->workWidth() - bv_->rightMargin());
+ // indicate bookmarks presence in margin
+ if (lyxrc.bookmarks_visibility == LyXRC::BMK_MARGIN)
+ for (auto const & bp_p : bpl)
+ if (bp_p.second >= row.pos() && bp_p.second < row.endpos())
+ rp.paintBookmark(bp_p.first);
+
y += row.descent();
#if 0