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
This commit is contained in:
Abdelrazak Younes 2007-09-01 14:49:08 +00:00
parent 0d3a630650
commit 53299d06f8

View File

@ -148,29 +148,37 @@ bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim)
{ {
BOOST_ASSERT(mi.base.textwidth); BOOST_ASSERT(mi.base.textwidth);
max_width_ = mi.base.textwidth; max_width_ = mi.base.textwidth;
dim_.wid = max_width_; // 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 //lyxerr << "Text::metrics: width: " << mi.base.textwidth
<< " maxWidth: " << max_width_ << "\nfont: " << mi.base.font << endl; // << " maxWidth: " << max_width_ << "\nfont: " << mi.base.font << endl;
bool changed = false; bool changed = false;
unsigned int h = 0; unsigned int h = 0;
unsigned int w = 0; for (pit_type pit = 0; pit != npar; ++pit) {
for (pit_type pit = 0, n = text_->paragraphs().size(); pit != n; ++pit) {
changed |= redoParagraph(pit); changed |= redoParagraph(pit);
ParagraphMetrics const & pm = par_metrics_[pit]; ParagraphMetrics const & pm = par_metrics_[pit];
h += pm.height(); h += pm.height();
if (w < pm.width()) if (dim_.wid < pm.width())
w = pm.width(); dim_.wid = pm.width();
} }
dim.wid = w; dim_.asc = par_metrics_[0].ascent();
dim.asc = par_metrics_[0].ascent(); dim_.des = h - dim_.asc;
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; changed |= dim_ != old_dim;
dim_ = dim; dim = dim_;
return changed; return changed;
} }
@ -246,6 +254,12 @@ bool TextMetrics::redoParagraph(pit_type const pit)
do { do {
Dimension dim; Dimension dim;
pos_type end = rowBreakPoint(width, pit, first); 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); dim.wid = rowWidth(right_margin, pit, first, end);
boost::tie(dim.asc, dim.des) = rowHeight(pit, first, end); boost::tie(dim.asc, dim.des) = rowHeight(pit, first, end);
if (row_index == pm.rows().size()) if (row_index == pm.rows().size())
@ -293,6 +307,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
return changed; return changed;
} }
void TextMetrics::computeRowMetrics(pit_type const pit, void TextMetrics::computeRowMetrics(pit_type const pit,
Row & row) const Row & row) const
{ {
@ -300,6 +315,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
Paragraph const & par = text_->getPar(pit); Paragraph const & par = text_->getPar(pit);
double w = dim_.wid - row.width(); double w = dim_.wid - row.width();
BOOST_ASSERT(w >= 0);
//lyxerr << "\ndim_.wid " << dim_.wid << endl; //lyxerr << "\ndim_.wid " << dim_.wid << endl;
//lyxerr << "row.width() " << row.width() << endl; //lyxerr << "row.width() " << row.width() << endl;
//lyxerr << "w " << w << endl; //lyxerr << "w " << w << endl;