From: Abdelrazak Younes Date: Sat, 1 Sep 2007 14:49:08 +0000 (+0000) Subject: Re-implement the wide() hack in a clean way (at metrics level): an InsetText will... X-Git-Tag: 1.6.10~8570 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=53299d06f80eee308ddc1f18bf5c85db20345b68;p=features.git Re-implement the wide() hack in a clean way (at metrics level): an InsetText will have automatically occupy the full allowable width if there is more than one paragraph or more more than one row. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19975 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 98fc7256f4..7efa2e9436 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -148,29 +148,37 @@ bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim) { BOOST_ASSERT(mi.base.textwidth); max_width_ = mi.base.textwidth; - dim_.wid = max_width_; - - lyxerr << "Text::metrics: width: " << mi.base.textwidth - << " maxWidth: " << max_width_ << "\nfont: " << mi.base.font << endl; + // backup old dimension. + Dimension const old_dim = dim_; + // reset dimension. + dim_ = Dimension(); + size_t npar = text_->paragraphs().size(); + if (npar > 1) + // If there is more than one row, expand the text to + // the full allowable width. + dim_.wid = max_width_; + + //lyxerr << "Text::metrics: width: " << mi.base.textwidth + // << " maxWidth: " << max_width_ << "\nfont: " << mi.base.font << endl; bool changed = false; - unsigned int h = 0; - unsigned int w = 0; - for (pit_type pit = 0, n = text_->paragraphs().size(); pit != n; ++pit) { + for (pit_type pit = 0; pit != npar; ++pit) { changed |= redoParagraph(pit); ParagraphMetrics const & pm = par_metrics_[pit]; h += pm.height(); - if (w < pm.width()) - w = pm.width(); + if (dim_.wid < pm.width()) + dim_.wid = pm.width(); } - dim.wid = w; - dim.asc = par_metrics_[0].ascent(); - dim.des = h - dim.asc; + dim_.asc = par_metrics_[0].ascent(); + dim_.des = h - dim_.asc; + //lyxerr << "dim_.wid " << dim_.wid << endl; + //lyxerr << "dim_.asc " << dim_.asc << endl; + //lyxerr << "dim_.des " << dim_.des << endl; - changed |= dim_ != dim; - dim_ = dim; + changed |= dim_ != old_dim; + dim = dim_; return changed; } @@ -246,6 +254,12 @@ bool TextMetrics::redoParagraph(pit_type const pit) do { Dimension dim; pos_type end = rowBreakPoint(width, pit, first); + if (row_index || end < par.size()) + // If there is more than one row, expand the text to + // the full allowable width. This setting here is needed + // for the computeRowMetrics below(). + dim_.wid = max_width_; + dim.wid = rowWidth(right_margin, pit, first, end); boost::tie(dim.asc, dim.des) = rowHeight(pit, first, end); if (row_index == pm.rows().size()) @@ -293,6 +307,7 @@ bool TextMetrics::redoParagraph(pit_type const pit) return changed; } + void TextMetrics::computeRowMetrics(pit_type const pit, Row & row) const { @@ -300,6 +315,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit, Paragraph const & par = text_->getPar(pit); double w = dim_.wid - row.width(); + BOOST_ASSERT(w >= 0); //lyxerr << "\ndim_.wid " << dim_.wid << endl; //lyxerr << "row.width() " << row.width() << endl; //lyxerr << "w " << w << endl;